From 0e3aa3c8d0b3c2e09afb5e768ed01467605580e6 Mon Sep 17 00:00:00 2001 From: Jiawei Shao Date: Fri, 24 Sep 2021 00:40:59 +0000 Subject: [PATCH] Metal: Support creating render pipeline asynchronously This patch implements the asynchronous path of creating render pipeline on Metal backend. BUG=dawn:529 TEST=dawn_end2end_tests Change-Id: I3f40949f35f6cbc340bebf481bd4e204b12d86c2 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/64880 Reviewed-by: Corentin Wallez Reviewed-by: Austin Eng Commit-Queue: Jiawei Shao --- src/dawn_native/metal/DeviceMTL.h | 4 ++++ src/dawn_native/metal/DeviceMTL.mm | 6 ++++++ src/dawn_native/metal/RenderPipelineMTL.h | 5 +++++ src/dawn_native/metal/RenderPipelineMTL.mm | 13 +++++++++++++ 4 files changed, 28 insertions(+) diff --git a/src/dawn_native/metal/DeviceMTL.h b/src/dawn_native/metal/DeviceMTL.h index 19b900b755..1432aa9219 100644 --- a/src/dawn_native/metal/DeviceMTL.h +++ b/src/dawn_native/metal/DeviceMTL.h @@ -117,6 +117,10 @@ namespace dawn_native { namespace metal { size_t blueprintHash, WGPUCreateComputePipelineAsyncCallback callback, void* userdata) override; + void CreateRenderPipelineAsyncImpl(const RenderPipelineDescriptor* descriptor, + size_t blueprintHash, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata) override; void InitTogglesFromDriver(); void ShutDownImpl() override; diff --git a/src/dawn_native/metal/DeviceMTL.mm b/src/dawn_native/metal/DeviceMTL.mm index 7d199f765c..d900575e6b 100644 --- a/src/dawn_native/metal/DeviceMTL.mm +++ b/src/dawn_native/metal/DeviceMTL.mm @@ -291,6 +291,12 @@ namespace dawn_native { namespace metal { void* userdata) { ComputePipeline::CreateAsync(this, descriptor, blueprintHash, callback, userdata); } + void Device::CreateRenderPipelineAsyncImpl(const RenderPipelineDescriptor* descriptor, + size_t blueprintHash, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata) { + RenderPipeline::CreateAsync(this, descriptor, blueprintHash, callback, userdata); + } ResultOrError Device::CheckAndUpdateCompletedSerials() { uint64_t frontendCompletedSerial{GetCompletedCommandSerial()}; diff --git a/src/dawn_native/metal/RenderPipelineMTL.h b/src/dawn_native/metal/RenderPipelineMTL.h index 1d81072cc8..6f9f9c837a 100644 --- a/src/dawn_native/metal/RenderPipelineMTL.h +++ b/src/dawn_native/metal/RenderPipelineMTL.h @@ -30,6 +30,11 @@ namespace dawn_native { namespace metal { static ResultOrError> Create( Device* device, const RenderPipelineDescriptor* descriptor); + static void CreateAsync(Device* device, + const RenderPipelineDescriptor* descriptor, + size_t blueprintHash, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata); MTLPrimitiveType GetMTLPrimitiveTopology() const; MTLWinding GetMTLFrontFace() const; diff --git a/src/dawn_native/metal/RenderPipelineMTL.mm b/src/dawn_native/metal/RenderPipelineMTL.mm index 818536a1d5..e8d766709d 100644 --- a/src/dawn_native/metal/RenderPipelineMTL.mm +++ b/src/dawn_native/metal/RenderPipelineMTL.mm @@ -14,6 +14,7 @@ #include "dawn_native/metal/RenderPipelineMTL.h" +#include "dawn_native/CreatePipelineAsyncTask.h" #include "dawn_native/VertexFormat.h" #include "dawn_native/metal/DeviceMTL.h" #include "dawn_native/metal/PipelineLayoutMTL.h" @@ -501,4 +502,16 @@ namespace dawn_native { namespace metal { return mtlVertexDescriptor; } + void RenderPipeline::CreateAsync(Device* device, + const RenderPipelineDescriptor* descriptor, + size_t blueprintHash, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata) { + Ref pipeline = AcquireRef(new RenderPipeline(device, descriptor)); + std::unique_ptr asyncTask = + std::make_unique(pipeline, blueprintHash, callback, + userdata); + CreateRenderPipelineAsyncTask::RunAsync(std::move(asyncTask)); + } + }} // namespace dawn_native::metal