|
67 | 67 | return [device newDepthStencilStateWithDescriptor:descriptor];
|
68 | 68 | }
|
69 | 69 |
|
70 |
| -std::future<std::shared_ptr<Pipeline>> PipelineLibraryMTL::GetRenderPipeline( |
| 70 | +PipelineFuture PipelineLibraryMTL::GetRenderPipeline( |
71 | 71 | PipelineDescriptor descriptor) {
|
72 |
| - auto promise = std::make_shared<std::promise<std::shared_ptr<Pipeline>>>(); |
73 |
| - auto future = promise->get_future(); |
74 | 72 | if (auto found = pipelines_.find(descriptor); found != pipelines_.end()) {
|
75 |
| - promise->set_value(nullptr); |
76 |
| - return future; |
| 73 | + return found->second; |
77 | 74 | }
|
78 | 75 |
|
79 |
| - // TODO(csg): There is a bug here where multiple calls to GetRenderPipeline |
80 |
| - // will result in multiple render pipelines of the same descriptor being |
81 |
| - // created till the first instance of the creation invokes its completion |
82 |
| - // callback. |
| 76 | + auto promise = std::make_shared<std::promise<std::shared_ptr<Pipeline>>>(); |
| 77 | + auto future = PipelineFuture{promise->get_future()}; |
| 78 | + |
| 79 | + pipelines_[descriptor] = future; |
83 | 80 |
|
84 | 81 | auto weak_this = weak_from_this();
|
85 | 82 |
|
|
100 | 97 | promise->set_value(nullptr);
|
101 | 98 | return;
|
102 | 99 | }
|
| 100 | + |
103 | 101 | auto new_pipeline = std::shared_ptr<PipelineMTL>(new PipelineMTL(
|
104 | 102 | weak_this,
|
105 | 103 | descriptor, //
|
106 | 104 | render_pipeline_state, //
|
107 | 105 | CreateDepthStencilDescriptor(descriptor, device_) //
|
108 | 106 | ));
|
109 | 107 | promise->set_value(new_pipeline);
|
110 |
| - this->SavePipeline(descriptor, new_pipeline); |
111 | 108 | };
|
112 | 109 | [device_ newRenderPipelineStateWithDescriptor:GetMTLRenderPipelineDescriptor(
|
113 | 110 | descriptor)
|
114 | 111 | completionHandler:completion_handler];
|
115 | 112 | return future;
|
116 | 113 | }
|
117 | 114 |
|
118 |
| -void PipelineLibraryMTL::SavePipeline( |
119 |
| - PipelineDescriptor descriptor, |
120 |
| - std::shared_ptr<const Pipeline> pipeline) { |
121 |
| - pipelines_[descriptor] = std::move(pipeline); |
122 |
| -} |
123 |
| - |
124 | 115 | } // namespace impeller
|
0 commit comments