diff --git a/src/dawn_native/ComputePipeline.cpp b/src/dawn_native/ComputePipeline.cpp index f789235b02..d79d4a066f 100644 --- a/src/dawn_native/ComputePipeline.cpp +++ b/src/dawn_native/ComputePipeline.cpp @@ -46,6 +46,7 @@ namespace dawn_native { {{SingleShaderStage::Compute, descriptor->compute.module, descriptor->compute.entryPoint, descriptor->compute.constantCount, descriptor->compute.constants}}) { + SetContentHash(ComputeContentHash()); } ComputePipelineBase::ComputePipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag) @@ -59,13 +60,21 @@ namespace dawn_native { } } - MaybeError ComputePipelineBase::Initialize() { - return {}; - } - // static ComputePipelineBase* ComputePipelineBase::MakeError(DeviceBase* device) { - return new ComputePipelineBase(device, ObjectBase::kError); + class ErrorComputePipeline final : public ComputePipelineBase { + public: + ErrorComputePipeline(DeviceBase* device) + : ComputePipelineBase(device, ObjectBase::kError) { + } + + MaybeError Initialize() override { + UNREACHABLE(); + return {}; + } + }; + + return new ErrorComputePipeline(device); } ObjectType ComputePipelineBase::GetType() const { diff --git a/src/dawn_native/ComputePipeline.h b/src/dawn_native/ComputePipeline.h index 1c134e65ea..6352c1999b 100644 --- a/src/dawn_native/ComputePipeline.h +++ b/src/dawn_native/ComputePipeline.h @@ -43,11 +43,6 @@ namespace dawn_native { private: ComputePipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag); - - // CreateComputePipelineAsyncTask is declared as a friend of ComputePipelineBase as it - // needs to call the private member function ComputePipelineBase::Initialize(). - friend class CreateComputePipelineAsyncTask; - virtual MaybeError Initialize(); }; } // namespace dawn_native diff --git a/src/dawn_native/CreatePipelineAsyncTask.cpp b/src/dawn_native/CreatePipelineAsyncTask.cpp index 6ada64e21c..f806bb5645 100644 --- a/src/dawn_native/CreatePipelineAsyncTask.cpp +++ b/src/dawn_native/CreatePipelineAsyncTask.cpp @@ -103,11 +103,9 @@ namespace dawn_native { CreateComputePipelineAsyncTask::CreateComputePipelineAsyncTask( Ref nonInitializedComputePipeline, - size_t blueprintHash, WGPUCreateComputePipelineAsyncCallback callback, void* userdata) : mComputePipeline(std::move(nonInitializedComputePipeline)), - mBlueprintHash(blueprintHash), mCallback(callback), mUserdata(userdata) { ASSERT(mComputePipeline != nullptr); @@ -122,7 +120,7 @@ namespace dawn_native { } mComputePipeline->GetDevice()->AddComputePipelineAsyncCallbackTask( - mComputePipeline, errorMessage, mCallback, mUserdata, mBlueprintHash); + mComputePipeline, errorMessage, mCallback, mUserdata); } void CreateComputePipelineAsyncTask::RunAsync( diff --git a/src/dawn_native/CreatePipelineAsyncTask.h b/src/dawn_native/CreatePipelineAsyncTask.h index 6a36ff0a33..3bac477e6a 100644 --- a/src/dawn_native/CreatePipelineAsyncTask.h +++ b/src/dawn_native/CreatePipelineAsyncTask.h @@ -72,7 +72,6 @@ namespace dawn_native { class CreateComputePipelineAsyncTask { public: CreateComputePipelineAsyncTask(Ref nonInitializedComputePipeline, - size_t blueprintHash, WGPUCreateComputePipelineAsyncCallback callback, void* userdata); @@ -82,7 +81,6 @@ namespace dawn_native { private: Ref mComputePipeline; - size_t mBlueprintHash; WGPUCreateComputePipelineAsyncCallback mCallback; void* mUserdata; }; diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp index a867110d95..03fe3b9977 100644 --- a/src/dawn_native/Device.cpp +++ b/src/dawn_native/Device.cpp @@ -678,20 +678,15 @@ namespace dawn_native { return mEmptyBindGroupLayout.Get(); } - std::pair, size_t> DeviceBase::GetCachedComputePipeline( - const ComputePipelineDescriptor* descriptor) { - ComputePipelineBase blueprint(this, descriptor); - - const size_t blueprintHash = blueprint.ComputeContentHash(); - blueprint.SetContentHash(blueprintHash); - - Ref result; - auto iter = mCaches->computePipelines.find(&blueprint); + Ref DeviceBase::GetCachedComputePipeline( + ComputePipelineBase* uninitializedComputePipeline) { + Ref cachedPipeline; + auto iter = mCaches->computePipelines.find(uninitializedComputePipeline); if (iter != mCaches->computePipelines.end()) { - result = *iter; + cachedPipeline = *iter; } - return std::make_pair(result, blueprintHash); + return cachedPipeline; } Ref DeviceBase::GetCachedRenderPipeline( @@ -705,9 +700,7 @@ namespace dawn_native { } Ref DeviceBase::AddOrGetCachedComputePipeline( - Ref computePipeline, - size_t blueprintHash) { - computePipeline->SetContentHash(blueprintHash); + Ref computePipeline) { auto insertion = mCaches->computePipelines.insert(computePipeline.Get()); if (insertion.second) { computePipeline->SetIsCachedReference(); @@ -1226,15 +1219,16 @@ namespace dawn_native { DAWN_TRY_ASSIGN(layoutRef, ValidateLayoutAndGetComputePipelineDescriptorWithDefaults( this, *descriptor, &appliedDescriptor)); - auto pipelineAndBlueprintFromCache = GetCachedComputePipeline(&appliedDescriptor); - if (pipelineAndBlueprintFromCache.first.Get() != nullptr) { - return std::move(pipelineAndBlueprintFromCache.first); + Ref uninitializedComputePipeline = + CreateUninitializedComputePipelineImpl(&appliedDescriptor); + Ref cachedComputePipeline = + GetCachedComputePipeline(uninitializedComputePipeline.Get()); + if (cachedComputePipeline.Get() != nullptr) { + return cachedComputePipeline; } - Ref backendObj; - DAWN_TRY_ASSIGN(backendObj, CreateComputePipelineImpl(&appliedDescriptor)); - size_t blueprintHash = pipelineAndBlueprintFromCache.second; - return AddOrGetCachedComputePipeline(backendObj, blueprintHash); + DAWN_TRY(uninitializedComputePipeline->Initialize()); + return AddOrGetCachedComputePipeline(std::move(uninitializedComputePipeline)); } MaybeError DeviceBase::CreateComputePipelineAsync( @@ -1251,38 +1245,42 @@ namespace dawn_native { DAWN_TRY_ASSIGN(layoutRef, ValidateLayoutAndGetComputePipelineDescriptorWithDefaults( this, *descriptor, &appliedDescriptor)); + Ref uninitializedComputePipeline = + CreateUninitializedComputePipelineImpl(&appliedDescriptor); + // Call the callback directly when we can get a cached compute pipeline object. - auto pipelineAndBlueprintFromCache = GetCachedComputePipeline(&appliedDescriptor); - if (pipelineAndBlueprintFromCache.first.Get() != nullptr) { - Ref result = std::move(pipelineAndBlueprintFromCache.first); + Ref cachedComputePipeline = + GetCachedComputePipeline(uninitializedComputePipeline.Get()); + if (cachedComputePipeline.Get() != nullptr) { callback(WGPUCreatePipelineAsyncStatus_Success, - reinterpret_cast(result.Detach()), "", userdata); + reinterpret_cast(cachedComputePipeline.Detach()), "", + userdata); } else { - // Otherwise we will create the pipeline object in CreateComputePipelineAsyncImpl(), - // where the pipeline object may be created asynchronously and the result will be saved - // to mCreatePipelineAsyncTracker. - const size_t blueprintHash = pipelineAndBlueprintFromCache.second; - CreateComputePipelineAsyncImpl(&appliedDescriptor, blueprintHash, callback, userdata); + // Otherwise we will create the pipeline object in InitializeComputePipelineAsyncImpl(), + // where the pipeline object may be initialized asynchronously and the result will be + // saved to mCreatePipelineAsyncTracker. + InitializeComputePipelineAsyncImpl(std::move(uninitializedComputePipeline), callback, + userdata); } return {}; } - // This function is overwritten with the async version on the backends that supports creating - // compute pipeline asynchronously. - void DeviceBase::CreateComputePipelineAsyncImpl(const ComputePipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateComputePipelineAsyncCallback callback, - void* userdata) { + // This function is overwritten with the async version on the backends that supports + // initializing compute pipelines asynchronously. + void DeviceBase::InitializeComputePipelineAsyncImpl( + Ref computePipeline, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata) { Ref result; std::string errorMessage; - auto resultOrError = CreateComputePipelineImpl(descriptor); - if (resultOrError.IsError()) { - std::unique_ptr error = resultOrError.AcquireError(); + MaybeError maybeError = computePipeline->Initialize(); + if (maybeError.IsError()) { + std::unique_ptr error = maybeError.AcquireError(); errorMessage = error->GetMessage(); } else { - result = AddOrGetCachedComputePipeline(resultOrError.AcquireSuccess(), blueprintHash); + result = AddOrGetCachedComputePipeline(std::move(computePipeline)); } std::unique_ptr callbackTask = @@ -1305,7 +1303,7 @@ namespace dawn_native { std::unique_ptr error = maybeError.AcquireError(); errorMessage = error->GetMessage(); } else { - result = AddOrGetCachedRenderPipeline(renderPipeline); + result = AddOrGetCachedRenderPipeline(std::move(renderPipeline)); } std::unique_ptr callbackTask = @@ -1367,7 +1365,7 @@ namespace dawn_native { this, *descriptor, &appliedDescriptor)); Ref uninitializedRenderPipeline = - CreateUninitializedRenderPipeline(&appliedDescriptor); + CreateUninitializedRenderPipelineImpl(&appliedDescriptor); Ref cachedRenderPipeline = GetCachedRenderPipeline(uninitializedRenderPipeline.Get()); @@ -1395,7 +1393,7 @@ namespace dawn_native { this, *descriptor, &appliedDescriptor)); Ref uninitializedRenderPipeline = - CreateUninitializedRenderPipeline(&appliedDescriptor); + CreateUninitializedRenderPipelineImpl(&appliedDescriptor); // Call the callback directly when we can get a cached render pipeline object. Ref cachedRenderPipeline = @@ -1578,53 +1576,31 @@ namespace dawn_native { return mWorkerTaskPool.get(); } - Ref DeviceBase::CreateUninitializedRenderPipeline( - const RenderPipelineDescriptor* descriptor) { - return CreateUninitializedRenderPipelineImpl(descriptor); - } - void DeviceBase::AddComputePipelineAsyncCallbackTask( Ref pipeline, std::string errorMessage, WGPUCreateComputePipelineAsyncCallback callback, - void* userdata, - size_t blueprintHash) { + void* userdata) { // CreateComputePipelineAsyncWaitableCallbackTask is declared as an internal class as it // needs to call the private member function DeviceBase::AddOrGetCachedComputePipeline(). struct CreateComputePipelineAsyncWaitableCallbackTask final : CreateComputePipelineAsyncCallbackTask { - CreateComputePipelineAsyncWaitableCallbackTask( - Ref pipeline, - std::string errorMessage, - WGPUCreateComputePipelineAsyncCallback callback, - void* userdata, - size_t blueprintHash) - : CreateComputePipelineAsyncCallbackTask(std::move(pipeline), - errorMessage, - callback, - userdata), - mBlueprintHash(blueprintHash) { - } - + using CreateComputePipelineAsyncCallbackTask::CreateComputePipelineAsyncCallbackTask; void Finish() final { // TODO(dawn:529): call AddOrGetCachedComputePipeline() asynchronously in // CreateComputePipelineAsyncTaskImpl::Run() when the front-end pipeline cache is // thread-safe. if (mPipeline.Get() != nullptr) { - mPipeline = mPipeline->GetDevice()->AddOrGetCachedComputePipeline( - mPipeline, mBlueprintHash); + mPipeline = mPipeline->GetDevice()->AddOrGetCachedComputePipeline(mPipeline); } CreateComputePipelineAsyncCallbackTask::Finish(); } - - private: - size_t mBlueprintHash; }; mCallbackTaskManager->AddCallbackTask( std::make_unique( - std::move(pipeline), errorMessage, callback, userdata, blueprintHash)); + std::move(pipeline), errorMessage, callback, userdata)); } void DeviceBase::AddRenderPipelineAsyncCallbackTask( diff --git a/src/dawn_native/Device.h b/src/dawn_native/Device.h index c2969c3ec7..92c1cd3b64 100644 --- a/src/dawn_native/Device.h +++ b/src/dawn_native/Device.h @@ -342,8 +342,7 @@ namespace dawn_native { void AddComputePipelineAsyncCallbackTask(Ref pipeline, std::string errorMessage, WGPUCreateComputePipelineAsyncCallback callback, - void* userdata, - size_t blueprintHash); + void* userdata); void AddRenderPipelineAsyncCallbackTask(Ref pipeline, std::string errorMessage, WGPUCreateRenderPipelineAsyncCallback callback, @@ -376,14 +375,10 @@ namespace dawn_native { PipelineCompatibilityToken pipelineCompatibilityToken) = 0; virtual ResultOrError> CreateBufferImpl( const BufferDescriptor* descriptor) = 0; - virtual ResultOrError> CreateComputePipelineImpl( - const ComputePipelineDescriptor* descriptor) = 0; virtual ResultOrError> CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) = 0; virtual ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) = 0; - virtual Ref CreateUninitializedRenderPipelineImpl( - const RenderPipelineDescriptor* descriptor) = 0; virtual ResultOrError> CreateSamplerImpl( const SamplerDescriptor* descriptor) = 0; virtual ResultOrError> CreateShaderModuleImpl( @@ -401,6 +396,10 @@ namespace dawn_native { virtual ResultOrError> CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) = 0; + virtual Ref CreateUninitializedComputePipelineImpl( + const ComputePipelineDescriptor* descriptor) = 0; + virtual Ref CreateUninitializedRenderPipelineImpl( + const RenderPipelineDescriptor* descriptor) = 0; virtual void SetLabelImpl(); virtual MaybeError TickImpl() = 0; @@ -408,21 +407,18 @@ namespace dawn_native { ResultOrError> CreateEmptyBindGroupLayout(); - std::pair, size_t> GetCachedComputePipeline( - const ComputePipelineDescriptor* descriptor); + Ref GetCachedComputePipeline( + ComputePipelineBase* uninitializedComputePipeline); Ref GetCachedRenderPipeline( RenderPipelineBase* uninitializedRenderPipeline); Ref AddOrGetCachedComputePipeline( - Ref computePipeline, - size_t blueprintHash); + Ref computePipeline); Ref AddOrGetCachedRenderPipeline( Ref renderPipeline); - virtual void CreateComputePipelineAsyncImpl(const ComputePipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateComputePipelineAsyncCallback callback, - void* userdata); - Ref CreateUninitializedRenderPipeline( - const RenderPipelineDescriptor* descriptor); + virtual void InitializeComputePipelineAsyncImpl( + Ref computePipeline, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata); virtual void InitializeRenderPipelineAsyncImpl( Ref renderPipeline, WGPUCreateRenderPipelineAsyncCallback callback, diff --git a/src/dawn_native/Pipeline.h b/src/dawn_native/Pipeline.h index c73d38968e..74442930b4 100644 --- a/src/dawn_native/Pipeline.h +++ b/src/dawn_native/Pipeline.h @@ -66,6 +66,9 @@ namespace dawn_native { // Implementation of the API entrypoint. Do not use in a reentrant manner. BindGroupLayoutBase* APIGetBindGroupLayout(uint32_t groupIndex); + // Initialize() should only be called once by the frontend. + virtual MaybeError Initialize() = 0; + protected: PipelineBase(DeviceBase* device, PipelineLayoutBase* layout, diff --git a/src/dawn_native/RenderPipeline.h b/src/dawn_native/RenderPipeline.h index 464ee5dc2d..b38ec97031 100644 --- a/src/dawn_native/RenderPipeline.h +++ b/src/dawn_native/RenderPipeline.h @@ -105,9 +105,6 @@ namespace dawn_native { bool operator()(const RenderPipelineBase* a, const RenderPipelineBase* b) const; }; - // Initialize() should only be called once by the frontend. - virtual MaybeError Initialize() = 0; - private: RenderPipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag); diff --git a/src/dawn_native/d3d12/ComputePipelineD3D12.cpp b/src/dawn_native/d3d12/ComputePipelineD3D12.cpp index 0925b92cda..29ae08af9d 100644 --- a/src/dawn_native/d3d12/ComputePipelineD3D12.cpp +++ b/src/dawn_native/d3d12/ComputePipelineD3D12.cpp @@ -24,12 +24,10 @@ namespace dawn_native { namespace d3d12 { - ResultOrError> ComputePipeline::Create( + Ref ComputePipeline::CreateUninitialized( Device* device, const ComputePipelineDescriptor* descriptor) { - Ref pipeline = AcquireRef(new ComputePipeline(device, descriptor)); - DAWN_TRY(pipeline->Initialize()); - return pipeline; + return AcquireRef(new ComputePipeline(device, descriptor)); } MaybeError ComputePipeline::Initialize() { @@ -77,14 +75,11 @@ namespace dawn_native { namespace d3d12 { GetLabel()); } - void ComputePipeline::CreateAsync(Device* device, - const ComputePipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateComputePipelineAsyncCallback callback, - void* userdata) { - Ref pipeline = AcquireRef(new ComputePipeline(device, descriptor)); + void ComputePipeline::InitializeAsync(Ref computePipeline, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata) { std::unique_ptr asyncTask = - std::make_unique(pipeline, blueprintHash, callback, + std::make_unique(std::move(computePipeline), callback, userdata); CreateComputePipelineAsyncTask::RunAsync(std::move(asyncTask)); } diff --git a/src/dawn_native/d3d12/ComputePipelineD3D12.h b/src/dawn_native/d3d12/ComputePipelineD3D12.h index d945ee2e38..7c7a02d2c6 100644 --- a/src/dawn_native/d3d12/ComputePipelineD3D12.h +++ b/src/dawn_native/d3d12/ComputePipelineD3D12.h @@ -25,25 +25,24 @@ namespace dawn_native { namespace d3d12 { class ComputePipeline final : public ComputePipelineBase { public: - static ResultOrError> Create( + static Ref CreateUninitialized( Device* device, const ComputePipelineDescriptor* descriptor); - static void CreateAsync(Device* device, - const ComputePipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateComputePipelineAsyncCallback callback, - void* userdata); + static void InitializeAsync(Ref computePipeline, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata); ComputePipeline() = delete; ID3D12PipelineState* GetPipelineState() const; + MaybeError Initialize() override; + // Dawn API void SetLabelImpl() override; private: ~ComputePipeline() override; using ComputePipelineBase::ComputePipelineBase; - MaybeError Initialize() override; ComPtr mPipelineState; }; diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp index 4e019c257f..0c2d34ce33 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.cpp +++ b/src/dawn_native/d3d12/DeviceD3D12.cpp @@ -334,9 +334,9 @@ namespace dawn_native { namespace d3d12 { const CommandBufferDescriptor* descriptor) { return CommandBuffer::Create(encoder, descriptor); } - ResultOrError> Device::CreateComputePipelineImpl( + Ref Device::CreateUninitializedComputePipelineImpl( const ComputePipelineDescriptor* descriptor) { - return ComputePipeline::Create(this, descriptor); + return ComputePipeline::CreateUninitialized(this, descriptor); } ResultOrError> Device::CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) { @@ -376,16 +376,15 @@ namespace dawn_native { namespace d3d12 { 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); + void Device::InitializeComputePipelineAsyncImpl(Ref computePipeline, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata) { + ComputePipeline::InitializeAsync(std::move(computePipeline), callback, userdata); } void Device::InitializeRenderPipelineAsyncImpl(Ref renderPipeline, WGPUCreateRenderPipelineAsyncCallback callback, void* userdata) { - RenderPipeline::InitializeAsync(renderPipeline, callback, userdata); + RenderPipeline::InitializeAsync(std::move(renderPipeline), callback, userdata); } ResultOrError> Device::CreateStagingBuffer(size_t size) { diff --git a/src/dawn_native/d3d12/DeviceD3D12.h b/src/dawn_native/d3d12/DeviceD3D12.h index 03856be6af..0e78cf991c 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.h +++ b/src/dawn_native/d3d12/DeviceD3D12.h @@ -149,14 +149,10 @@ namespace dawn_native { namespace d3d12 { PipelineCompatibilityToken pipelineCompatibilityToken) override; ResultOrError> CreateBufferImpl( const BufferDescriptor* descriptor) override; - ResultOrError> CreateComputePipelineImpl( - const ComputePipelineDescriptor* descriptor) override; ResultOrError> CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) override; ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) override; - Ref CreateUninitializedRenderPipelineImpl( - const RenderPipelineDescriptor* descriptor) override; ResultOrError> CreateSamplerImpl( const SamplerDescriptor* descriptor) override; ResultOrError> CreateShaderModuleImpl( @@ -173,10 +169,13 @@ namespace dawn_native { namespace d3d12 { ResultOrError> CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) override; - void CreateComputePipelineAsyncImpl(const ComputePipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateComputePipelineAsyncCallback callback, - void* userdata) override; + Ref CreateUninitializedComputePipelineImpl( + const ComputePipelineDescriptor* descriptor) override; + Ref CreateUninitializedRenderPipelineImpl( + const RenderPipelineDescriptor* descriptor) override; + void InitializeComputePipelineAsyncImpl(Ref computePipeline, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata) override; void InitializeRenderPipelineAsyncImpl(Ref renderPipeline, WGPUCreateRenderPipelineAsyncCallback callback, void* userdata) override; diff --git a/src/dawn_native/metal/ComputePipelineMTL.h b/src/dawn_native/metal/ComputePipelineMTL.h index 4ecb450030..20b2080ee4 100644 --- a/src/dawn_native/metal/ComputePipelineMTL.h +++ b/src/dawn_native/metal/ComputePipelineMTL.h @@ -27,14 +27,12 @@ namespace dawn_native { namespace metal { class ComputePipeline final : public ComputePipelineBase { public: - static ResultOrError> Create( + static Ref CreateUninitialized( Device* device, const ComputePipelineDescriptor* descriptor); - static void CreateAsync(Device* device, - const ComputePipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateComputePipelineAsyncCallback callback, - void* userdata); + static void InitializeAsync(Ref computePipeline, + 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 8879fb2127..18edc566fb 100644 --- a/src/dawn_native/metal/ComputePipelineMTL.mm +++ b/src/dawn_native/metal/ComputePipelineMTL.mm @@ -21,12 +21,10 @@ namespace dawn_native { namespace metal { // static - ResultOrError> ComputePipeline::Create( + Ref ComputePipeline::CreateUninitialized( Device* device, const ComputePipelineDescriptor* descriptor) { - Ref pipeline = AcquireRef(new ComputePipeline(device, descriptor)); - DAWN_TRY(pipeline->Initialize()); - return pipeline; + return AcquireRef(new ComputePipeline(device, descriptor)); } MaybeError ComputePipeline::Initialize() { @@ -76,14 +74,11 @@ 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)); + void ComputePipeline::InitializeAsync(Ref computePipeline, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata) { std::unique_ptr asyncTask = - std::make_unique(pipeline, blueprintHash, callback, + std::make_unique(std::move(computePipeline), callback, userdata); CreateComputePipelineAsyncTask::RunAsync(std::move(asyncTask)); } diff --git a/src/dawn_native/metal/DeviceMTL.h b/src/dawn_native/metal/DeviceMTL.h index 5d16d8ed01..d7d09a2301 100644 --- a/src/dawn_native/metal/DeviceMTL.h +++ b/src/dawn_native/metal/DeviceMTL.h @@ -89,14 +89,10 @@ namespace dawn_native { namespace metal { ResultOrError> CreateCommandBuffer( CommandEncoder* encoder, const CommandBufferDescriptor* descriptor) override; - ResultOrError> CreateComputePipelineImpl( - const ComputePipelineDescriptor* descriptor) override; ResultOrError> CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) override; ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) override; - Ref CreateUninitializedRenderPipelineImpl( - const RenderPipelineDescriptor* descriptor) override; ResultOrError> CreateSamplerImpl( const SamplerDescriptor* descriptor) override; ResultOrError> CreateShaderModuleImpl( @@ -113,10 +109,13 @@ 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; + Ref CreateUninitializedComputePipelineImpl( + const ComputePipelineDescriptor* descriptor) override; + Ref CreateUninitializedRenderPipelineImpl( + const RenderPipelineDescriptor* descriptor) override; + void InitializeComputePipelineAsyncImpl(Ref computePipeline, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata) override; void InitializeRenderPipelineAsyncImpl(Ref renderPipeline, WGPUCreateRenderPipelineAsyncCallback callback, void* userdata) override; diff --git a/src/dawn_native/metal/DeviceMTL.mm b/src/dawn_native/metal/DeviceMTL.mm index acc351f5d5..10445e5b1d 100644 --- a/src/dawn_native/metal/DeviceMTL.mm +++ b/src/dawn_native/metal/DeviceMTL.mm @@ -243,9 +243,9 @@ namespace dawn_native { namespace metal { const CommandBufferDescriptor* descriptor) { return CommandBuffer::Create(encoder, descriptor); } - ResultOrError> Device::CreateComputePipelineImpl( + Ref Device::CreateUninitializedComputePipelineImpl( const ComputePipelineDescriptor* descriptor) { - return ComputePipeline::Create(this, descriptor); + return ComputePipeline::CreateUninitialized(this, descriptor); } ResultOrError> Device::CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) { @@ -285,16 +285,15 @@ 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); + void Device::InitializeComputePipelineAsyncImpl(Ref computePipeline, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata) { + ComputePipeline::InitializeAsync(std::move(computePipeline), callback, userdata); } void Device::InitializeRenderPipelineAsyncImpl(Ref renderPipeline, WGPUCreateRenderPipelineAsyncCallback callback, void* userdata) { - RenderPipeline::InitializeAsync(renderPipeline, callback, userdata); + RenderPipeline::InitializeAsync(std::move(renderPipeline), callback, userdata); } ResultOrError Device::CheckAndUpdateCompletedSerials() { diff --git a/src/dawn_native/null/DeviceNull.cpp b/src/dawn_native/null/DeviceNull.cpp index 17030dd5b1..44552267f7 100644 --- a/src/dawn_native/null/DeviceNull.cpp +++ b/src/dawn_native/null/DeviceNull.cpp @@ -112,7 +112,7 @@ namespace dawn_native { namespace null { const CommandBufferDescriptor* descriptor) { return AcquireRef(new CommandBuffer(encoder, descriptor)); } - ResultOrError> Device::CreateComputePipelineImpl( + Ref Device::CreateUninitializedComputePipelineImpl( const ComputePipelineDescriptor* descriptor) { return AcquireRef(new ComputePipeline(this, descriptor)); } @@ -371,6 +371,11 @@ namespace dawn_native { namespace null { return {}; } + // ComputePipeline + MaybeError ComputePipeline::Initialize() { + return {}; + } + // RenderPipeline MaybeError RenderPipeline::Initialize() { return {}; diff --git a/src/dawn_native/null/DeviceNull.h b/src/dawn_native/null/DeviceNull.h index 0f2913922f..9e9200c280 100644 --- a/src/dawn_native/null/DeviceNull.h +++ b/src/dawn_native/null/DeviceNull.h @@ -43,7 +43,7 @@ namespace dawn_native { namespace null { class BindGroupLayout; class Buffer; class CommandBuffer; - using ComputePipeline = ComputePipelineBase; + class ComputePipeline; class Device; using PipelineLayout = PipelineLayoutBase; class QuerySet; @@ -129,7 +129,7 @@ namespace dawn_native { namespace null { PipelineCompatibilityToken pipelineCompatibilityToken) override; ResultOrError> CreateBufferImpl( const BufferDescriptor* descriptor) override; - ResultOrError> CreateComputePipelineImpl( + Ref CreateUninitializedComputePipelineImpl( const ComputePipelineDescriptor* descriptor) override; ResultOrError> CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) override; @@ -261,6 +261,13 @@ namespace dawn_native { namespace null { size_t size) override; }; + class ComputePipeline final : public ComputePipelineBase { + public: + using ComputePipelineBase::ComputePipelineBase; + + MaybeError Initialize() override; + }; + class RenderPipeline final : public RenderPipelineBase { public: using RenderPipelineBase::RenderPipelineBase; diff --git a/src/dawn_native/opengl/ComputePipelineGL.cpp b/src/dawn_native/opengl/ComputePipelineGL.cpp index e51e217a8f..086ca7aea0 100644 --- a/src/dawn_native/opengl/ComputePipelineGL.cpp +++ b/src/dawn_native/opengl/ComputePipelineGL.cpp @@ -19,12 +19,10 @@ namespace dawn_native { namespace opengl { // static - ResultOrError> ComputePipeline::Create( + Ref ComputePipeline::CreateUninitialized( Device* device, const ComputePipelineDescriptor* descriptor) { - Ref pipeline = AcquireRef(new ComputePipeline(device, descriptor)); - DAWN_TRY(pipeline->Initialize()); - return pipeline; + return AcquireRef(new ComputePipeline(device, descriptor)); } ComputePipeline::~ComputePipeline() { diff --git a/src/dawn_native/opengl/ComputePipelineGL.h b/src/dawn_native/opengl/ComputePipelineGL.h index dd5c0b3f36..444a28958a 100644 --- a/src/dawn_native/opengl/ComputePipelineGL.h +++ b/src/dawn_native/opengl/ComputePipelineGL.h @@ -27,16 +27,17 @@ namespace dawn_native { namespace opengl { class ComputePipeline final : public ComputePipelineBase, public PipelineGL { public: - static ResultOrError> Create( + static Ref CreateUninitialized( Device* device, const ComputePipelineDescriptor* descriptor); void ApplyNow(); + MaybeError Initialize() override; + private: using ComputePipelineBase::ComputePipelineBase; ~ComputePipeline() override; - MaybeError Initialize() override; }; }} // namespace dawn_native::opengl diff --git a/src/dawn_native/opengl/DeviceGL.cpp b/src/dawn_native/opengl/DeviceGL.cpp index aa2fa18592..08e544c3c4 100644 --- a/src/dawn_native/opengl/DeviceGL.cpp +++ b/src/dawn_native/opengl/DeviceGL.cpp @@ -130,9 +130,9 @@ namespace dawn_native { namespace opengl { const CommandBufferDescriptor* descriptor) { return AcquireRef(new CommandBuffer(encoder, descriptor)); } - ResultOrError> Device::CreateComputePipelineImpl( + Ref Device::CreateUninitializedComputePipelineImpl( const ComputePipelineDescriptor* descriptor) { - return ComputePipeline::Create(this, descriptor); + return ComputePipeline::CreateUninitialized(this, descriptor); } ResultOrError> Device::CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) { diff --git a/src/dawn_native/opengl/DeviceGL.h b/src/dawn_native/opengl/DeviceGL.h index ee2ef46466..b67f748362 100644 --- a/src/dawn_native/opengl/DeviceGL.h +++ b/src/dawn_native/opengl/DeviceGL.h @@ -91,14 +91,10 @@ namespace dawn_native { namespace opengl { PipelineCompatibilityToken pipelineCompatibilityToken) override; ResultOrError> CreateBufferImpl( const BufferDescriptor* descriptor) override; - ResultOrError> CreateComputePipelineImpl( - const ComputePipelineDescriptor* descriptor) override; ResultOrError> CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) override; ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) override; - Ref CreateUninitializedRenderPipelineImpl( - const RenderPipelineDescriptor* descriptor) override; ResultOrError> CreateSamplerImpl( const SamplerDescriptor* descriptor) override; ResultOrError> CreateShaderModuleImpl( @@ -115,6 +111,10 @@ namespace dawn_native { namespace opengl { ResultOrError> CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) override; + Ref CreateUninitializedComputePipelineImpl( + const ComputePipelineDescriptor* descriptor) override; + Ref CreateUninitializedRenderPipelineImpl( + const RenderPipelineDescriptor* descriptor) override; void InitTogglesFromDriver(); ResultOrError CheckAndUpdateCompletedSerials() override; diff --git a/src/dawn_native/vulkan/ComputePipelineVk.cpp b/src/dawn_native/vulkan/ComputePipelineVk.cpp index 649ab5478f..c30f8c2caf 100644 --- a/src/dawn_native/vulkan/ComputePipelineVk.cpp +++ b/src/dawn_native/vulkan/ComputePipelineVk.cpp @@ -25,12 +25,10 @@ namespace dawn_native { namespace vulkan { // static - ResultOrError> ComputePipeline::Create( + Ref ComputePipeline::CreateUninitialized( Device* device, const ComputePipelineDescriptor* descriptor) { - Ref pipeline = AcquireRef(new ComputePipeline(device, descriptor)); - DAWN_TRY(pipeline->Initialize()); - return pipeline; + return AcquireRef(new ComputePipeline(device, descriptor)); } MaybeError ComputePipeline::Initialize() { @@ -102,14 +100,11 @@ namespace dawn_native { namespace vulkan { return mHandle; } - void ComputePipeline::CreateAsync(Device* device, - const ComputePipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateComputePipelineAsyncCallback callback, - void* userdata) { - Ref pipeline = AcquireRef(new ComputePipeline(device, descriptor)); + void ComputePipeline::InitializeAsync(Ref computePipeline, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata) { std::unique_ptr asyncTask = - std::make_unique(pipeline, blueprintHash, callback, + std::make_unique(std::move(computePipeline), callback, userdata); CreateComputePipelineAsyncTask::RunAsync(std::move(asyncTask)); } diff --git a/src/dawn_native/vulkan/ComputePipelineVk.h b/src/dawn_native/vulkan/ComputePipelineVk.h index 72e2716beb..1f2d20db7c 100644 --- a/src/dawn_native/vulkan/ComputePipelineVk.h +++ b/src/dawn_native/vulkan/ComputePipelineVk.h @@ -26,24 +26,23 @@ namespace dawn_native { namespace vulkan { class ComputePipeline final : public ComputePipelineBase { public: - static ResultOrError> Create( + static Ref CreateUninitialized( Device* device, const ComputePipelineDescriptor* descriptor); - static void CreateAsync(Device* device, - const ComputePipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateComputePipelineAsyncCallback callback, - void* userdata); + static void InitializeAsync(Ref computePipeline, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata); VkPipeline GetHandle() const; + MaybeError Initialize() override; + // Dawn API void SetLabelImpl() override; private: ~ComputePipeline() override; using ComputePipelineBase::ComputePipelineBase; - MaybeError Initialize() override; VkPipeline mHandle = VK_NULL_HANDLE; }; diff --git a/src/dawn_native/vulkan/DeviceVk.cpp b/src/dawn_native/vulkan/DeviceVk.cpp index a30a20eaf4..1360d3c76b 100644 --- a/src/dawn_native/vulkan/DeviceVk.cpp +++ b/src/dawn_native/vulkan/DeviceVk.cpp @@ -120,9 +120,9 @@ namespace dawn_native { namespace vulkan { const CommandBufferDescriptor* descriptor) { return CommandBuffer::Create(encoder, descriptor); } - ResultOrError> Device::CreateComputePipelineImpl( + Ref Device::CreateUninitializedComputePipelineImpl( const ComputePipelineDescriptor* descriptor) { - return ComputePipeline::Create(this, descriptor); + return ComputePipeline::CreateUninitialized(this, descriptor); } ResultOrError> Device::CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) { @@ -162,16 +162,15 @@ namespace dawn_native { namespace vulkan { 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); + void Device::InitializeComputePipelineAsyncImpl(Ref computePipeline, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata) { + ComputePipeline::InitializeAsync(std::move(computePipeline), callback, userdata); } void Device::InitializeRenderPipelineAsyncImpl(Ref renderPipeline, WGPUCreateRenderPipelineAsyncCallback callback, void* userdata) { - RenderPipeline::InitializeAsync(renderPipeline, callback, userdata); + RenderPipeline::InitializeAsync(std::move(renderPipeline), callback, userdata); } MaybeError Device::TickImpl() { diff --git a/src/dawn_native/vulkan/DeviceVk.h b/src/dawn_native/vulkan/DeviceVk.h index 3378bc88b5..f77e0b4591 100644 --- a/src/dawn_native/vulkan/DeviceVk.h +++ b/src/dawn_native/vulkan/DeviceVk.h @@ -113,14 +113,10 @@ namespace dawn_native { namespace vulkan { PipelineCompatibilityToken pipelineCompatibilityToken) override; ResultOrError> CreateBufferImpl( const BufferDescriptor* descriptor) override; - ResultOrError> CreateComputePipelineImpl( - const ComputePipelineDescriptor* descriptor) override; ResultOrError> CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) override; ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) override; - Ref CreateUninitializedRenderPipelineImpl( - const RenderPipelineDescriptor* descriptor) override; ResultOrError> CreateSamplerImpl( const SamplerDescriptor* descriptor) override; ResultOrError> CreateShaderModuleImpl( @@ -137,10 +133,13 @@ namespace dawn_native { namespace vulkan { ResultOrError> CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) override; - void CreateComputePipelineAsyncImpl(const ComputePipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateComputePipelineAsyncCallback callback, - void* userdata) override; + Ref CreateUninitializedComputePipelineImpl( + const ComputePipelineDescriptor* descriptor) override; + Ref CreateUninitializedRenderPipelineImpl( + const RenderPipelineDescriptor* descriptor) override; + void InitializeComputePipelineAsyncImpl(Ref computePipeline, + WGPUCreateComputePipelineAsyncCallback callback, + void* userdata) override; void InitializeRenderPipelineAsyncImpl(Ref renderPipeline, WGPUCreateRenderPipelineAsyncCallback callback, void* userdata) override;