From c9a6df32972372e0ad572d6af54426ba42cabe55 Mon Sep 17 00:00:00 2001 From: Jiawei Shao Date: Wed, 9 Jun 2021 00:42:46 +0000 Subject: [PATCH] Metal: Support creating compute pipeline asynchronously BUG=dawn:529 TEST=dawn_end2end_tests Change-Id: I9427afbb11196c14843c6fb7bf6224afca6d63fc Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/53761 Reviewed-by: Corentin Wallez Reviewed-by: Austin Eng Commit-Queue: Jiawei Shao --- src/dawn_native/metal/ComputePipelineMTL.h | 5 +++++ src/dawn_native/metal/ComputePipelineMTL.mm | 13 +++++++++++++ src/dawn_native/metal/DeviceMTL.h | 4 ++++ src/dawn_native/metal/DeviceMTL.mm | 6 ++++++ 4 files changed, 28 insertions(+) diff --git a/src/dawn_native/metal/ComputePipelineMTL.h b/src/dawn_native/metal/ComputePipelineMTL.h index dde9dc7b5e..09ab23a8d9 100644 --- a/src/dawn_native/metal/ComputePipelineMTL.h +++ b/src/dawn_native/metal/ComputePipelineMTL.h @@ -30,6 +30,11 @@ namespace dawn_native { namespace metal { static ResultOrError> Create( Device* device, const ComputePipelineDescriptor* descriptor); + static void CreateAsync(Device* device, + const ComputePipelineDescriptor* descriptor, + size_t blueprintHash, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata); void Encode(id encoder); MTLSize GetLocalWorkGroupSize() const; diff --git a/src/dawn_native/metal/ComputePipelineMTL.mm b/src/dawn_native/metal/ComputePipelineMTL.mm index 0845abf0c6..b0cdfd9e90 100644 --- a/src/dawn_native/metal/ComputePipelineMTL.mm +++ b/src/dawn_native/metal/ComputePipelineMTL.mm @@ -14,6 +14,7 @@ #include "dawn_native/metal/ComputePipelineMTL.h" +#include "dawn_native/CreatePipelineAsyncTask.h" #include "dawn_native/metal/DeviceMTL.h" #include "dawn_native/metal/ShaderModuleMTL.h" @@ -66,4 +67,16 @@ namespace dawn_native { namespace metal { return mRequiresStorageBufferLength; } + void ComputePipeline::CreateAsync(Device* device, + const ComputePipelineDescriptor* descriptor, + size_t blueprintHash, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata) { + Ref pipeline = AcquireRef(new ComputePipeline(device, descriptor)); + std::unique_ptr asyncTask = + std::make_unique(pipeline, descriptor, blueprintHash, + callback, userdata); + CreateComputePipelineAsyncTask::RunAsync(std::move(asyncTask)); + } + }} // namespace dawn_native::metal diff --git a/src/dawn_native/metal/DeviceMTL.h b/src/dawn_native/metal/DeviceMTL.h index 3749994dc1..72c6443df8 100644 --- a/src/dawn_native/metal/DeviceMTL.h +++ b/src/dawn_native/metal/DeviceMTL.h @@ -112,6 +112,10 @@ namespace dawn_native { namespace metal { ResultOrError> CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) override; + void CreateComputePipelineAsyncImpl(const ComputePipelineDescriptor* descriptor, + size_t blueprintHash, + WGPUCreateComputePipelineAsyncCallback 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 0320887cc5..98b1f77004 100644 --- a/src/dawn_native/metal/DeviceMTL.mm +++ b/src/dawn_native/metal/DeviceMTL.mm @@ -259,6 +259,12 @@ namespace dawn_native { namespace metal { const TextureViewDescriptor* descriptor) { return TextureView::Create(texture, descriptor); } + void Device::CreateComputePipelineAsyncImpl(const ComputePipelineDescriptor* descriptor, + size_t blueprintHash, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata) { + ComputePipeline::CreateAsync(this, descriptor, blueprintHash, callback, userdata); + } ResultOrError Device::CheckAndUpdateCompletedSerials() { uint64_t frontendCompletedSerial{GetCompletedCommandSerial()};