Skip to content

Commit a093636

Browse files
chinmaygardednfield
authored andcommitted
Make pipelines store pipeline descriptors.
1 parent 531162f commit a093636

File tree

8 files changed

+45
-9
lines changed

8 files changed

+45
-9
lines changed

impeller/renderer/backend/metal/context_mtl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ class ContextMTL final : public Context,
6161
// |Context|
6262
std::shared_ptr<CommandBuffer> CreateRenderCommandBuffer() const override;
6363

64+
// |Context|
65+
std::shared_ptr<CommandBuffer> CreateTransferCommandBuffer() const override;
66+
67+
std::shared_ptr<CommandBuffer> CreateCommandBufferInQueue(
68+
id<MTLCommandQueue> queue) const;
69+
6470
FML_DISALLOW_COPY_AND_ASSIGN(ContextMTL);
6571
};
6672

impeller/renderer/backend/metal/context_mtl.mm

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,20 @@
108108
}
109109

110110
std::shared_ptr<CommandBuffer> ContextMTL::CreateRenderCommandBuffer() const {
111+
return CreateCommandBufferInQueue(render_queue_);
112+
}
113+
114+
std::shared_ptr<CommandBuffer> ContextMTL::CreateTransferCommandBuffer() const {
115+
return CreateCommandBufferInQueue(transfer_queue_);
116+
}
117+
118+
std::shared_ptr<CommandBuffer> ContextMTL::CreateCommandBufferInQueue(
119+
id<MTLCommandQueue> queue) const {
111120
if (!IsValid()) {
112121
return nullptr;
113122
}
114123

115-
auto buffer =
116-
std::shared_ptr<CommandBufferMTL>(new CommandBufferMTL(render_queue_));
124+
auto buffer = std::shared_ptr<CommandBufferMTL>(new CommandBufferMTL(queue));
117125
if (!buffer->IsValid()) {
118126
return nullptr;
119127
}

impeller/renderer/backend/metal/pipeline_library_mtl.mm

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777
return future;
7878
}
7979

80+
// TODO(csg): There is a bug here where multiple calls to GetRenderPipeline
81+
// will result in multiple render pipelines of the same descriptor being
82+
// created till the first instance of the creation invokes its completion
83+
// callback.
84+
8085
auto thiz = shared_from_this();
8186

8287
auto completion_handler =
@@ -88,8 +93,10 @@
8893
promise->set_value(nullptr);
8994
} else {
9095
auto new_pipeline = std::shared_ptr<PipelineMTL>(new PipelineMTL(
91-
render_pipeline_state,
92-
CreateDepthStencilDescriptor(descriptor, device_)));
96+
descriptor, //
97+
render_pipeline_state, //
98+
CreateDepthStencilDescriptor(descriptor, device_) //
99+
));
93100
promise->set_value(new_pipeline);
94101
this->SavePipeline(descriptor, new_pipeline);
95102
}

impeller/renderer/backend/metal/pipeline_mtl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class PipelineMTL final : public Pipeline,
3030
id<MTLDepthStencilState> depth_stencil_state_;
3131
bool is_valid_ = false;
3232

33-
PipelineMTL(id<MTLRenderPipelineState> state,
33+
PipelineMTL(PipelineDescriptor desc,
34+
id<MTLRenderPipelineState> state,
3435
id<MTLDepthStencilState> depth_stencil_state);
3536

3637
// |PipelineMTL|

impeller/renderer/backend/metal/pipeline_mtl.mm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66

77
namespace impeller {
88

9-
PipelineMTL::PipelineMTL(id<MTLRenderPipelineState> state,
9+
PipelineMTL::PipelineMTL(PipelineDescriptor desc,
10+
id<MTLRenderPipelineState> state,
1011
id<MTLDepthStencilState> depth_stencil_state)
11-
: pipeline_state_(state), depth_stencil_state_(depth_stencil_state) {
12+
: Pipeline(std::move(desc)),
13+
pipeline_state_(state),
14+
depth_stencil_state_(depth_stencil_state) {
1215
if (!pipeline_state_) {
1316
return;
1417
}

impeller/renderer/context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class Context {
4343

4444
virtual std::shared_ptr<CommandBuffer> CreateRenderCommandBuffer() const = 0;
4545

46+
virtual std::shared_ptr<CommandBuffer> CreateTransferCommandBuffer()
47+
const = 0;
48+
4649
protected:
4750
Context();
4851

impeller/renderer/pipeline.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace impeller {
1111

12-
Pipeline::Pipeline() = default;
12+
Pipeline::Pipeline(PipelineDescriptor desc) : desc_(std::move(desc)) {}
1313

1414
Pipeline::~Pipeline() = default;
1515

@@ -25,4 +25,8 @@ PipelineFuture CreatePipelineFuture(const Context& context,
2525
return context.GetPipelineLibrary()->GetRenderPipeline(std::move(desc));
2626
}
2727

28+
const PipelineDescriptor& Pipeline::GetDescriptor() const {
29+
return desc_;
30+
}
31+
2832
} // namespace impeller

impeller/renderer/pipeline.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,14 @@ class Pipeline {
4242

4343
virtual bool IsValid() const = 0;
4444

45+
const PipelineDescriptor& GetDescriptor() const;
46+
4547
protected:
46-
Pipeline();
48+
Pipeline(PipelineDescriptor desc);
4749

4850
private:
51+
const PipelineDescriptor desc_;
52+
4953
FML_DISALLOW_COPY_AND_ASSIGN(Pipeline);
5054
};
5155

0 commit comments

Comments
 (0)