Make pipelines store pipeline descriptors.

This commit is contained in:
Chinmay Garde
2021-11-10 11:07:23 -08:00
committed by Dan Field
parent 791a4c34a6
commit 6ab947ca80
8 changed files with 45 additions and 9 deletions

View File

@@ -61,6 +61,12 @@ class ContextMTL final : public Context,
// |Context|
std::shared_ptr<CommandBuffer> CreateRenderCommandBuffer() const override;
// |Context|
std::shared_ptr<CommandBuffer> CreateTransferCommandBuffer() const override;
std::shared_ptr<CommandBuffer> CreateCommandBufferInQueue(
id<MTLCommandQueue> queue) const;
FML_DISALLOW_COPY_AND_ASSIGN(ContextMTL);
};

View File

@@ -108,12 +108,20 @@ std::shared_ptr<SamplerLibrary> ContextMTL::GetSamplerLibrary() const {
}
std::shared_ptr<CommandBuffer> ContextMTL::CreateRenderCommandBuffer() const {
return CreateCommandBufferInQueue(render_queue_);
}
std::shared_ptr<CommandBuffer> ContextMTL::CreateTransferCommandBuffer() const {
return CreateCommandBufferInQueue(transfer_queue_);
}
std::shared_ptr<CommandBuffer> ContextMTL::CreateCommandBufferInQueue(
id<MTLCommandQueue> queue) const {
if (!IsValid()) {
return nullptr;
}
auto buffer =
std::shared_ptr<CommandBufferMTL>(new CommandBufferMTL(render_queue_));
auto buffer = std::shared_ptr<CommandBufferMTL>(new CommandBufferMTL(queue));
if (!buffer->IsValid()) {
return nullptr;
}

View File

@@ -77,6 +77,11 @@ std::future<std::shared_ptr<Pipeline>> PipelineLibraryMTL::GetRenderPipeline(
return future;
}
// TODO(csg): There is a bug here where multiple calls to GetRenderPipeline
// will result in multiple render pipelines of the same descriptor being
// created till the first instance of the creation invokes its completion
// callback.
auto thiz = shared_from_this();
auto completion_handler =
@@ -88,8 +93,10 @@ std::future<std::shared_ptr<Pipeline>> PipelineLibraryMTL::GetRenderPipeline(
promise->set_value(nullptr);
} else {
auto new_pipeline = std::shared_ptr<PipelineMTL>(new PipelineMTL(
render_pipeline_state,
CreateDepthStencilDescriptor(descriptor, device_)));
descriptor, //
render_pipeline_state, //
CreateDepthStencilDescriptor(descriptor, device_) //
));
promise->set_value(new_pipeline);
this->SavePipeline(descriptor, new_pipeline);
}

View File

@@ -30,7 +30,8 @@ class PipelineMTL final : public Pipeline,
id<MTLDepthStencilState> depth_stencil_state_;
bool is_valid_ = false;
PipelineMTL(id<MTLRenderPipelineState> state,
PipelineMTL(PipelineDescriptor desc,
id<MTLRenderPipelineState> state,
id<MTLDepthStencilState> depth_stencil_state);
// |PipelineMTL|

View File

@@ -6,9 +6,12 @@
namespace impeller {
PipelineMTL::PipelineMTL(id<MTLRenderPipelineState> state,
PipelineMTL::PipelineMTL(PipelineDescriptor desc,
id<MTLRenderPipelineState> state,
id<MTLDepthStencilState> depth_stencil_state)
: pipeline_state_(state), depth_stencil_state_(depth_stencil_state) {
: Pipeline(std::move(desc)),
pipeline_state_(state),
depth_stencil_state_(depth_stencil_state) {
if (!pipeline_state_) {
return;
}

View File

@@ -43,6 +43,9 @@ class Context {
virtual std::shared_ptr<CommandBuffer> CreateRenderCommandBuffer() const = 0;
virtual std::shared_ptr<CommandBuffer> CreateTransferCommandBuffer()
const = 0;
protected:
Context();

View File

@@ -9,7 +9,7 @@
namespace impeller {
Pipeline::Pipeline() = default;
Pipeline::Pipeline(PipelineDescriptor desc) : desc_(std::move(desc)) {}
Pipeline::~Pipeline() = default;
@@ -25,4 +25,8 @@ PipelineFuture CreatePipelineFuture(const Context& context,
return context.GetPipelineLibrary()->GetRenderPipeline(std::move(desc));
}
const PipelineDescriptor& Pipeline::GetDescriptor() const {
return desc_;
}
} // namespace impeller

View File

@@ -42,10 +42,14 @@ class Pipeline {
virtual bool IsValid() const = 0;
const PipelineDescriptor& GetDescriptor() const;
protected:
Pipeline();
Pipeline(PipelineDescriptor desc);
private:
const PipelineDescriptor desc_;
FML_DISALLOW_COPY_AND_ASSIGN(Pipeline);
};