diff --git a/src/dawn_native/CreatePipelineAsyncTask.cpp b/src/dawn_native/CreatePipelineAsyncTask.cpp index fae8ad2510..6ada64e21c 100644 --- a/src/dawn_native/CreatePipelineAsyncTask.cpp +++ b/src/dawn_native/CreatePipelineAsyncTask.cpp @@ -141,11 +141,9 @@ namespace dawn_native { CreateRenderPipelineAsyncTask::CreateRenderPipelineAsyncTask( Ref nonInitializedRenderPipeline, - size_t blueprintHash, WGPUCreateRenderPipelineAsyncCallback callback, void* userdata) : mRenderPipeline(std::move(nonInitializedRenderPipeline)), - mBlueprintHash(blueprintHash), mCallback(callback), mUserdata(userdata) { ASSERT(mRenderPipeline != nullptr); @@ -160,7 +158,7 @@ namespace dawn_native { } mRenderPipeline->GetDevice()->AddRenderPipelineAsyncCallbackTask( - mRenderPipeline, errorMessage, mCallback, mUserdata, mBlueprintHash); + mRenderPipeline, errorMessage, mCallback, mUserdata); } void CreateRenderPipelineAsyncTask::RunAsync( diff --git a/src/dawn_native/CreatePipelineAsyncTask.h b/src/dawn_native/CreatePipelineAsyncTask.h index 33e3e95322..6a36ff0a33 100644 --- a/src/dawn_native/CreatePipelineAsyncTask.h +++ b/src/dawn_native/CreatePipelineAsyncTask.h @@ -92,7 +92,6 @@ namespace dawn_native { class CreateRenderPipelineAsyncTask { public: CreateRenderPipelineAsyncTask(Ref nonInitializedRenderPipeline, - size_t blueprintHash, WGPUCreateRenderPipelineAsyncCallback callback, void* userdata); @@ -102,7 +101,6 @@ namespace dawn_native { private: Ref mRenderPipeline; - size_t mBlueprintHash; WGPUCreateRenderPipelineAsyncCallback mCallback; void* mUserdata; }; diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp index 02d243385b..07a24f5c8a 100644 --- a/src/dawn_native/Device.cpp +++ b/src/dawn_native/Device.cpp @@ -670,20 +670,14 @@ namespace dawn_native { return std::make_pair(result, blueprintHash); } - std::pair, size_t> DeviceBase::GetCachedRenderPipeline( - const RenderPipelineDescriptor* descriptor) { - RenderPipelineBase blueprint(this, descriptor); - - const size_t blueprintHash = blueprint.ComputeContentHash(); - blueprint.SetContentHash(blueprintHash); - - Ref result; - auto iter = mCaches->renderPipelines.find(&blueprint); + Ref DeviceBase::GetCachedRenderPipeline( + RenderPipelineBase* uninitializedRenderPipeline) { + Ref cachedPipeline; + auto iter = mCaches->renderPipelines.find(uninitializedRenderPipeline); if (iter != mCaches->renderPipelines.end()) { - result = *iter; + cachedPipeline = *iter; } - - return std::make_pair(result, blueprintHash); + return cachedPipeline; } Ref DeviceBase::AddOrGetCachedComputePipeline( @@ -700,9 +694,7 @@ namespace dawn_native { } Ref DeviceBase::AddOrGetCachedRenderPipeline( - Ref renderPipeline, - size_t blueprintHash) { - renderPipeline->SetContentHash(blueprintHash); + Ref renderPipeline) { auto insertion = mCaches->renderPipelines.insert(renderPipeline.Get()); if (insertion.second) { renderPipeline->SetIsCachedReference(); @@ -1261,20 +1253,20 @@ namespace dawn_native { } // This function is overwritten with the async version on the backends - // that supports creating render pipeline asynchronously - void DeviceBase::CreateRenderPipelineAsyncImpl(const RenderPipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateRenderPipelineAsyncCallback callback, - void* userdata) { + // that supports initializing render pipeline asynchronously + void DeviceBase::InitializeRenderPipelineAsyncImpl( + Ref renderPipeline, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata) { Ref result; std::string errorMessage; - auto resultOrError = CreateRenderPipelineImpl(descriptor); - if (resultOrError.IsError()) { - std::unique_ptr error = resultOrError.AcquireError(); + MaybeError maybeError = renderPipeline->Initialize(); + if (maybeError.IsError()) { + std::unique_ptr error = maybeError.AcquireError(); errorMessage = error->GetMessage(); } else { - result = AddOrGetCachedRenderPipeline(resultOrError.AcquireSuccess(), blueprintHash); + result = AddOrGetCachedRenderPipeline(renderPipeline); } std::unique_ptr callbackTask = @@ -1333,15 +1325,17 @@ namespace dawn_native { DAWN_TRY_ASSIGN(layoutRef, ValidateLayoutAndGetRenderPipelineDescriptorWithDefaults( this, *descriptor, &appliedDescriptor)); - auto pipelineAndBlueprintFromCache = GetCachedRenderPipeline(&appliedDescriptor); - if (pipelineAndBlueprintFromCache.first.Get() != nullptr) { - return std::move(pipelineAndBlueprintFromCache.first); + Ref uninitializedRenderPipeline = + CreateUninitializedRenderPipeline(&appliedDescriptor); + + Ref cachedRenderPipeline = + GetCachedRenderPipeline(uninitializedRenderPipeline.Get()); + if (cachedRenderPipeline != nullptr) { + return cachedRenderPipeline; } - Ref backendObj; - DAWN_TRY_ASSIGN(backendObj, CreateRenderPipelineImpl(&appliedDescriptor)); - size_t blueprintHash = pipelineAndBlueprintFromCache.second; - return AddOrGetCachedRenderPipeline(backendObj, blueprintHash); + DAWN_TRY(uninitializedRenderPipeline->Initialize()); + return AddOrGetCachedRenderPipeline(std::move(uninitializedRenderPipeline)); } MaybeError DeviceBase::CreateRenderPipelineAsync(const RenderPipelineDescriptor* descriptor, @@ -1355,23 +1349,26 @@ namespace dawn_native { // Ref will keep the pipeline layout alive until the end of the function where // the pipeline will take another reference. Ref layoutRef; - RenderPipelineDescriptor descriptorWithPipelineLayout; + RenderPipelineDescriptor appliedDescriptor; DAWN_TRY_ASSIGN(layoutRef, ValidateLayoutAndGetRenderPipelineDescriptorWithDefaults( - this, *descriptor, &descriptorWithPipelineLayout)); + this, *descriptor, &appliedDescriptor)); + + Ref uninitializedRenderPipeline = + CreateUninitializedRenderPipeline(&appliedDescriptor); // Call the callback directly when we can get a cached render pipeline object. - auto pipelineAndBlueprintFromCache = GetCachedRenderPipeline(&descriptorWithPipelineLayout); - if (pipelineAndBlueprintFromCache.first.Get() != nullptr) { - Ref result = std::move(pipelineAndBlueprintFromCache.first); + Ref cachedRenderPipeline = + GetCachedRenderPipeline(uninitializedRenderPipeline.Get()); + if (cachedRenderPipeline != nullptr) { callback(WGPUCreatePipelineAsyncStatus_Success, - reinterpret_cast(result.Detach()), "", userdata); + reinterpret_cast(cachedRenderPipeline.Detach()), "", + userdata); } else { - // Otherwise we will create the pipeline object in CreateRenderPipelineAsyncImpl(), - // where the pipeline object may be created asynchronously and the result will be saved - // to mCreatePipelineAsyncTracker. - const size_t blueprintHash = pipelineAndBlueprintFromCache.second; - CreateRenderPipelineAsyncImpl(&descriptorWithPipelineLayout, blueprintHash, callback, - userdata); + // Otherwise we will create the pipeline object in InitializeRenderPipelineAsyncImpl(), + // where the pipeline object may be initialized asynchronously and the result will be + // saved to mCreatePipelineAsyncTracker. + InitializeRenderPipelineAsyncImpl(std::move(uninitializedRenderPipeline), callback, + userdata); } return {}; @@ -1536,6 +1533,11 @@ namespace dawn_native { return mWorkerTaskPool.get(); } + Ref DeviceBase::CreateUninitializedRenderPipeline( + const RenderPipelineDescriptor* descriptor) { + return CreateUninitializedRenderPipelineImpl(descriptor); + } + void DeviceBase::AddComputePipelineAsyncCallbackTask( Ref pipeline, std::string errorMessage, @@ -1584,44 +1586,28 @@ namespace dawn_native { Ref pipeline, std::string errorMessage, WGPUCreateRenderPipelineAsyncCallback callback, - void* userdata, - size_t blueprintHash) { + void* userdata) { // CreateRenderPipelineAsyncWaitableCallbackTask is declared as an internal class as it // needs to call the private member function DeviceBase::AddOrGetCachedRenderPipeline(). struct CreateRenderPipelineAsyncWaitableCallbackTask final : CreateRenderPipelineAsyncCallbackTask { - CreateRenderPipelineAsyncWaitableCallbackTask( - Ref pipeline, - std::string errorMessage, - WGPUCreateRenderPipelineAsyncCallback callback, - void* userdata, - size_t blueprintHash) - : CreateRenderPipelineAsyncCallbackTask(std::move(pipeline), - errorMessage, - callback, - userdata), - mBlueprintHash(blueprintHash) { - } + using CreateRenderPipelineAsyncCallbackTask::CreateRenderPipelineAsyncCallbackTask; void Finish() final { // TODO(dawn:529): call AddOrGetCachedRenderPipeline() asynchronously in // CreateRenderPipelineAsyncTaskImpl::Run() when the front-end pipeline cache is // thread-safe. if (mPipeline.Get() != nullptr) { - mPipeline = mPipeline->GetDevice()->AddOrGetCachedRenderPipeline( - mPipeline, mBlueprintHash); + mPipeline = mPipeline->GetDevice()->AddOrGetCachedRenderPipeline(mPipeline); } CreateRenderPipelineAsyncCallbackTask::Finish(); } - - private: - size_t mBlueprintHash; }; mCallbackTaskManager->AddCallbackTask( std::make_unique( - std::move(pipeline), errorMessage, callback, userdata, blueprintHash)); + std::move(pipeline), errorMessage, callback, userdata)); } PipelineCompatibilityToken DeviceBase::GetNextPipelineCompatibilityToken() { diff --git a/src/dawn_native/Device.h b/src/dawn_native/Device.h index f3c6209c8e..1f5d0d4e9f 100644 --- a/src/dawn_native/Device.h +++ b/src/dawn_native/Device.h @@ -307,8 +307,7 @@ namespace dawn_native { void AddRenderPipelineAsyncCallbackTask(Ref pipeline, std::string errorMessage, WGPUCreateRenderPipelineAsyncCallback callback, - void* userdata, - size_t blueprintHash); + void* userdata); PipelineCompatibilityToken GetNextPipelineCompatibilityToken(); @@ -339,7 +338,7 @@ namespace dawn_native { const PipelineLayoutDescriptor* descriptor) = 0; virtual ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) = 0; - virtual ResultOrError> CreateRenderPipelineImpl( + virtual Ref CreateUninitializedRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) = 0; virtual ResultOrError> CreateSamplerImpl( const SamplerDescriptor* descriptor) = 0; @@ -367,21 +366,23 @@ namespace dawn_native { std::pair, size_t> GetCachedComputePipeline( const ComputePipelineDescriptor* descriptor); - std::pair, size_t> GetCachedRenderPipeline( - const RenderPipelineDescriptor* descriptor); + Ref GetCachedRenderPipeline( + RenderPipelineBase* uninitializedRenderPipeline); Ref AddOrGetCachedComputePipeline( Ref computePipeline, size_t blueprintHash); - Ref AddOrGetCachedRenderPipeline(Ref renderPipeline, - size_t blueprintHash); + Ref AddOrGetCachedRenderPipeline( + Ref renderPipeline); virtual void CreateComputePipelineAsyncImpl(const ComputePipelineDescriptor* descriptor, size_t blueprintHash, WGPUCreateComputePipelineAsyncCallback callback, void* userdata); - virtual void CreateRenderPipelineAsyncImpl(const RenderPipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateRenderPipelineAsyncCallback callback, - void* userdata); + Ref CreateUninitializedRenderPipeline( + const RenderPipelineDescriptor* descriptor); + virtual void InitializeRenderPipelineAsyncImpl( + Ref renderPipeline, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata); void ApplyToggleOverrides(const DeviceDescriptor* deviceDescriptor); void ApplyExtensions(const DeviceDescriptor* deviceDescriptor); diff --git a/src/dawn_native/RenderPipeline.cpp b/src/dawn_native/RenderPipeline.cpp index a73a401e9f..a6a8078d19 100644 --- a/src/dawn_native/RenderPipeline.cpp +++ b/src/dawn_native/RenderPipeline.cpp @@ -554,6 +554,8 @@ namespace dawn_native { mTargets[i].blend = &mTargetBlend[i]; } } + + SetContentHash(ComputeContentHash()); } RenderPipelineBase::RenderPipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag) @@ -562,7 +564,19 @@ namespace dawn_native { // static RenderPipelineBase* RenderPipelineBase::MakeError(DeviceBase* device) { - return new RenderPipelineBase(device, ObjectBase::kError); + class ErrorRenderPipeline final : public RenderPipelineBase { + public: + ErrorRenderPipeline(DeviceBase* device) + : RenderPipelineBase(device, ObjectBase::kError) { + } + + MaybeError Initialize() override { + UNREACHABLE(); + return {}; + } + }; + + return new ErrorRenderPipeline(device); } ObjectType RenderPipelineBase::GetType() const { @@ -900,7 +914,4 @@ namespace dawn_native { return true; } - MaybeError RenderPipelineBase::Initialize() { - return {}; - } } // namespace dawn_native diff --git a/src/dawn_native/RenderPipeline.h b/src/dawn_native/RenderPipeline.h index 66f3456b17..464ee5dc2d 100644 --- a/src/dawn_native/RenderPipeline.h +++ b/src/dawn_native/RenderPipeline.h @@ -105,15 +105,12 @@ 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); - // CreateRenderPipelineAsyncTask is declared as a friend of RenderPipelineBase as it - // needs to call the private member function RenderPipelineBase::Initialize(). - friend class CreateRenderPipelineAsyncTask; - virtual MaybeError Initialize(); - - // TODO(dawn:529): store all the following members in a FlatRenderPipelineDescriptor object // Vertex state uint32_t mVertexBufferCount; ityp::bitset mAttributeLocationsUsed; diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp index 97d5f10a31..8c3358b65e 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.cpp +++ b/src/dawn_native/d3d12/DeviceD3D12.cpp @@ -346,9 +346,9 @@ namespace dawn_native { namespace d3d12 { const QuerySetDescriptor* descriptor) { return QuerySet::Create(this, descriptor); } - ResultOrError> Device::CreateRenderPipelineImpl( + Ref Device::CreateUninitializedRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) { - return RenderPipeline::Create(this, descriptor); + return RenderPipeline::CreateUninitialized(this, descriptor); } ResultOrError> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) { return Sampler::Create(this, descriptor); @@ -382,11 +382,10 @@ namespace dawn_native { namespace d3d12 { 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); + void Device::InitializeRenderPipelineAsyncImpl(Ref renderPipeline, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata) { + RenderPipeline::InitializeAsync(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 cefa780faf..186e29ee70 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.h +++ b/src/dawn_native/d3d12/DeviceD3D12.h @@ -155,7 +155,7 @@ namespace dawn_native { namespace d3d12 { const PipelineLayoutDescriptor* descriptor) override; ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) override; - ResultOrError> CreateRenderPipelineImpl( + Ref CreateUninitializedRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) override; ResultOrError> CreateSamplerImpl( const SamplerDescriptor* descriptor) override; @@ -177,10 +177,9 @@ namespace dawn_native { namespace d3d12 { size_t blueprintHash, WGPUCreateComputePipelineAsyncCallback callback, void* userdata) override; - void CreateRenderPipelineAsyncImpl(const RenderPipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateRenderPipelineAsyncCallback callback, - void* userdata) override; + void InitializeRenderPipelineAsyncImpl(Ref renderPipeline, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata) override; void ShutDownImpl() override; MaybeError WaitForIdleForDestruction() override; diff --git a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp index c9c63f5f10..ee2fde6b4e 100644 --- a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp +++ b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp @@ -316,12 +316,10 @@ namespace dawn_native { namespace d3d12 { } // anonymous namespace - ResultOrError> RenderPipeline::Create( + Ref RenderPipeline::CreateUninitialized( Device* device, const RenderPipelineDescriptor* descriptor) { - Ref pipeline = AcquireRef(new RenderPipeline(device, descriptor)); - DAWN_TRY(pipeline->Initialize()); - return pipeline; + return AcquireRef(new RenderPipeline(device, descriptor)); } MaybeError RenderPipeline::Initialize() { @@ -472,14 +470,11 @@ namespace dawn_native { namespace d3d12 { return inputLayoutDescriptor; } - void RenderPipeline::CreateAsync(Device* device, - const RenderPipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateRenderPipelineAsyncCallback callback, - void* userdata) { - Ref pipeline = AcquireRef(new RenderPipeline(device, descriptor)); + void RenderPipeline::InitializeAsync(Ref renderPipeline, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata) { std::unique_ptr asyncTask = - std::make_unique(pipeline, blueprintHash, callback, + std::make_unique(std::move(renderPipeline), callback, userdata); CreateRenderPipelineAsyncTask::RunAsync(std::move(asyncTask)); } diff --git a/src/dawn_native/d3d12/RenderPipelineD3D12.h b/src/dawn_native/d3d12/RenderPipelineD3D12.h index 199107f792..be0efef500 100644 --- a/src/dawn_native/d3d12/RenderPipelineD3D12.h +++ b/src/dawn_native/d3d12/RenderPipelineD3D12.h @@ -26,16 +26,15 @@ namespace dawn_native { namespace d3d12 { class RenderPipeline final : public RenderPipelineBase { public: - static ResultOrError> Create( - Device* device, - const RenderPipelineDescriptor* descriptor); - static void CreateAsync(Device* device, - const RenderPipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateRenderPipelineAsyncCallback callback, - void* userdata); + static Ref CreateUninitialized(Device* device, + const RenderPipelineDescriptor* descriptor); + static void InitializeAsync(Ref renderPipeline, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata); RenderPipeline() = delete; + MaybeError Initialize() override; + D3D12_PRIMITIVE_TOPOLOGY GetD3D12PrimitiveTopology() const; ID3D12PipelineState* GetPipelineState() const; @@ -47,7 +46,6 @@ namespace dawn_native { namespace d3d12 { private: ~RenderPipeline() override; using RenderPipelineBase::RenderPipelineBase; - MaybeError Initialize() override; D3D12_INPUT_LAYOUT_DESC ComputeInputLayout( std::array* inputElementDescriptors); diff --git a/src/dawn_native/metal/DeviceMTL.h b/src/dawn_native/metal/DeviceMTL.h index 1432aa9219..e5232cbbfa 100644 --- a/src/dawn_native/metal/DeviceMTL.h +++ b/src/dawn_native/metal/DeviceMTL.h @@ -95,7 +95,7 @@ namespace dawn_native { namespace metal { const PipelineLayoutDescriptor* descriptor) override; ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) override; - ResultOrError> CreateRenderPipelineImpl( + Ref CreateUninitializedRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) override; ResultOrError> CreateSamplerImpl( const SamplerDescriptor* descriptor) override; @@ -117,10 +117,9 @@ 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 InitializeRenderPipelineAsyncImpl(Ref renderPipeline, + 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 d900575e6b..91b09844fe 100644 --- a/src/dawn_native/metal/DeviceMTL.mm +++ b/src/dawn_native/metal/DeviceMTL.mm @@ -255,9 +255,9 @@ namespace dawn_native { namespace metal { const QuerySetDescriptor* descriptor) { return QuerySet::Create(this, descriptor); } - ResultOrError> Device::CreateRenderPipelineImpl( + Ref Device::CreateUninitializedRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) { - return RenderPipeline::Create(this, descriptor); + return RenderPipeline::CreateUninitialized(this, descriptor); } ResultOrError> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) { return Sampler::Create(this, descriptor); @@ -291,11 +291,10 @@ 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); + void Device::InitializeRenderPipelineAsyncImpl(Ref renderPipeline, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata) { + RenderPipeline::InitializeAsync(renderPipeline, callback, userdata); } ResultOrError Device::CheckAndUpdateCompletedSerials() { diff --git a/src/dawn_native/metal/RenderPipelineMTL.h b/src/dawn_native/metal/RenderPipelineMTL.h index 6f9f9c837a..d6bedfaedb 100644 --- a/src/dawn_native/metal/RenderPipelineMTL.h +++ b/src/dawn_native/metal/RenderPipelineMTL.h @@ -27,14 +27,12 @@ namespace dawn_native { namespace metal { class RenderPipeline final : public RenderPipelineBase { public: - static ResultOrError> Create( + static Ref CreateUninitialized( Device* device, const RenderPipelineDescriptor* descriptor); - static void CreateAsync(Device* device, - const RenderPipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateRenderPipelineAsyncCallback callback, - void* userdata); + static void InitializeAsync(Ref renderPipeline, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata); MTLPrimitiveType GetMTLPrimitiveTopology() const; MTLWinding GetMTLFrontFace() const; @@ -50,9 +48,10 @@ namespace dawn_native { namespace metal { wgpu::ShaderStage GetStagesRequiringStorageBufferLength() const; + MaybeError Initialize() override; + private: using RenderPipelineBase::RenderPipelineBase; - MaybeError Initialize() override; MTLVertexDescriptor* MakeVertexDesc(); diff --git a/src/dawn_native/metal/RenderPipelineMTL.mm b/src/dawn_native/metal/RenderPipelineMTL.mm index e8d766709d..1537abfa44 100644 --- a/src/dawn_native/metal/RenderPipelineMTL.mm +++ b/src/dawn_native/metal/RenderPipelineMTL.mm @@ -311,12 +311,10 @@ namespace dawn_native { namespace metal { } // anonymous namespace // static - ResultOrError> RenderPipeline::Create( + Ref RenderPipeline::CreateUninitialized( Device* device, const RenderPipelineDescriptor* descriptor) { - Ref pipeline = AcquireRef(new RenderPipeline(device, descriptor)); - DAWN_TRY(pipeline->Initialize()); - return pipeline; + return AcquireRef(new RenderPipeline(device, descriptor)); } MaybeError RenderPipeline::Initialize() { @@ -502,14 +500,11 @@ 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)); + void RenderPipeline::InitializeAsync(Ref renderPipeline, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata) { std::unique_ptr asyncTask = - std::make_unique(pipeline, blueprintHash, callback, + std::make_unique(std::move(renderPipeline), callback, userdata); CreateRenderPipelineAsyncTask::RunAsync(std::move(asyncTask)); } diff --git a/src/dawn_native/null/DeviceNull.cpp b/src/dawn_native/null/DeviceNull.cpp index d6b4d999b3..5ee1ef0945 100644 --- a/src/dawn_native/null/DeviceNull.cpp +++ b/src/dawn_native/null/DeviceNull.cpp @@ -124,7 +124,7 @@ namespace dawn_native { namespace null { const QuerySetDescriptor* descriptor) { return AcquireRef(new QuerySet(this, descriptor)); } - ResultOrError> Device::CreateRenderPipelineImpl( + Ref Device::CreateUninitializedRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) { return AcquireRef(new RenderPipeline(this, descriptor)); } @@ -359,6 +359,11 @@ namespace dawn_native { namespace null { return {}; } + // RenderPipeline + MaybeError RenderPipeline::Initialize() { + return {}; + } + // SwapChain // static diff --git a/src/dawn_native/null/DeviceNull.h b/src/dawn_native/null/DeviceNull.h index 15bc75953a..834684f87f 100644 --- a/src/dawn_native/null/DeviceNull.h +++ b/src/dawn_native/null/DeviceNull.h @@ -48,7 +48,7 @@ namespace dawn_native { namespace null { using PipelineLayout = PipelineLayoutBase; class QuerySet; class Queue; - using RenderPipeline = RenderPipelineBase; + class RenderPipeline; using Sampler = SamplerBase; class ShaderModule; class SwapChain; @@ -135,7 +135,7 @@ namespace dawn_native { namespace null { const PipelineLayoutDescriptor* descriptor) override; ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) override; - ResultOrError> CreateRenderPipelineImpl( + Ref CreateUninitializedRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) override; ResultOrError> CreateSamplerImpl( const SamplerDescriptor* descriptor) override; @@ -251,6 +251,13 @@ namespace dawn_native { namespace null { size_t size) override; }; + class RenderPipeline final : public RenderPipelineBase { + public: + using RenderPipelineBase::RenderPipelineBase; + + MaybeError Initialize() override; + }; + class ShaderModule final : public ShaderModuleBase { public: using ShaderModuleBase::ShaderModuleBase; diff --git a/src/dawn_native/opengl/DeviceGL.cpp b/src/dawn_native/opengl/DeviceGL.cpp index 827116fc72..ac8be45ba2 100644 --- a/src/dawn_native/opengl/DeviceGL.cpp +++ b/src/dawn_native/opengl/DeviceGL.cpp @@ -142,9 +142,9 @@ namespace dawn_native { namespace opengl { const QuerySetDescriptor* descriptor) { return AcquireRef(new QuerySet(this, descriptor)); } - ResultOrError> Device::CreateRenderPipelineImpl( + Ref Device::CreateUninitializedRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) { - return RenderPipeline::Create(this, descriptor); + return RenderPipeline::CreateUninitialized(this, descriptor); } ResultOrError> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) { return AcquireRef(new Sampler(this, descriptor)); diff --git a/src/dawn_native/opengl/DeviceGL.h b/src/dawn_native/opengl/DeviceGL.h index 2a191fc364..b259647499 100644 --- a/src/dawn_native/opengl/DeviceGL.h +++ b/src/dawn_native/opengl/DeviceGL.h @@ -97,7 +97,7 @@ namespace dawn_native { namespace opengl { const PipelineLayoutDescriptor* descriptor) override; ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) override; - ResultOrError> CreateRenderPipelineImpl( + Ref CreateUninitializedRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) override; ResultOrError> CreateSamplerImpl( const SamplerDescriptor* descriptor) override; diff --git a/src/dawn_native/opengl/RenderPipelineGL.cpp b/src/dawn_native/opengl/RenderPipelineGL.cpp index 5781a3e76b..1b4b5cee74 100644 --- a/src/dawn_native/opengl/RenderPipelineGL.cpp +++ b/src/dawn_native/opengl/RenderPipelineGL.cpp @@ -215,12 +215,10 @@ namespace dawn_native { namespace opengl { } // anonymous namespace // static - ResultOrError> RenderPipeline::Create( + Ref RenderPipeline::CreateUninitialized( Device* device, const RenderPipelineDescriptor* descriptor) { - Ref pipeline = AcquireRef(new RenderPipeline(device, descriptor)); - DAWN_TRY(pipeline->Initialize()); - return pipeline; + return AcquireRef(new RenderPipeline(device, descriptor)); } RenderPipeline::RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor) diff --git a/src/dawn_native/opengl/RenderPipelineGL.h b/src/dawn_native/opengl/RenderPipelineGL.h index 1881fcd6b7..cd3290fa1c 100644 --- a/src/dawn_native/opengl/RenderPipelineGL.h +++ b/src/dawn_native/opengl/RenderPipelineGL.h @@ -29,9 +29,8 @@ namespace dawn_native { namespace opengl { class RenderPipeline final : public RenderPipelineBase, public PipelineGL { public: - static ResultOrError> Create( - Device* device, - const RenderPipelineDescriptor* descriptor); + static Ref CreateUninitialized(Device* device, + const RenderPipelineDescriptor* descriptor); GLenum GetGLPrimitiveTopology() const; ityp::bitset GetAttributesUsingVertexBuffer( @@ -39,10 +38,11 @@ namespace dawn_native { namespace opengl { void ApplyNow(PersistentPipelineState& persistentPipelineState); + MaybeError Initialize() override; + private: RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor); ~RenderPipeline() override; - MaybeError Initialize() override; void CreateVAOForVertexState(); diff --git a/src/dawn_native/vulkan/DeviceVk.cpp b/src/dawn_native/vulkan/DeviceVk.cpp index 0663d789f6..2f879def03 100644 --- a/src/dawn_native/vulkan/DeviceVk.cpp +++ b/src/dawn_native/vulkan/DeviceVk.cpp @@ -132,9 +132,9 @@ namespace dawn_native { namespace vulkan { const QuerySetDescriptor* descriptor) { return QuerySet::Create(this, descriptor); } - ResultOrError> Device::CreateRenderPipelineImpl( + Ref Device::CreateUninitializedRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) { - return RenderPipeline::Create(this, descriptor); + return RenderPipeline::CreateUninitialized(this, descriptor); } ResultOrError> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) { return Sampler::Create(this, descriptor); @@ -168,11 +168,10 @@ namespace dawn_native { namespace vulkan { 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); + void Device::InitializeRenderPipelineAsyncImpl(Ref renderPipeline, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata) { + RenderPipeline::InitializeAsync(renderPipeline, callback, userdata); } MaybeError Device::TickImpl() { diff --git a/src/dawn_native/vulkan/DeviceVk.h b/src/dawn_native/vulkan/DeviceVk.h index 44d9366438..447023f180 100644 --- a/src/dawn_native/vulkan/DeviceVk.h +++ b/src/dawn_native/vulkan/DeviceVk.h @@ -119,7 +119,7 @@ namespace dawn_native { namespace vulkan { const PipelineLayoutDescriptor* descriptor) override; ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) override; - ResultOrError> CreateRenderPipelineImpl( + Ref CreateUninitializedRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) override; ResultOrError> CreateSamplerImpl( const SamplerDescriptor* descriptor) override; @@ -141,10 +141,9 @@ namespace dawn_native { namespace vulkan { size_t blueprintHash, WGPUCreateComputePipelineAsyncCallback callback, void* userdata) override; - void CreateRenderPipelineAsyncImpl(const RenderPipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateRenderPipelineAsyncCallback callback, - void* userdata) override; + void InitializeRenderPipelineAsyncImpl(Ref renderPipeline, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata) override; ResultOrError CreateDevice(VkPhysicalDevice physicalDevice); void GatherQueueFromDevice(); diff --git a/src/dawn_native/vulkan/RenderPipelineVk.cpp b/src/dawn_native/vulkan/RenderPipelineVk.cpp index 5b196eb400..5ad3fd28b1 100644 --- a/src/dawn_native/vulkan/RenderPipelineVk.cpp +++ b/src/dawn_native/vulkan/RenderPipelineVk.cpp @@ -328,12 +328,10 @@ namespace dawn_native { namespace vulkan { } // anonymous namespace // static - ResultOrError> RenderPipeline::Create( + Ref RenderPipeline::CreateUninitialized( Device* device, const RenderPipelineDescriptor* descriptor) { - Ref pipeline = AcquireRef(new RenderPipeline(device, descriptor)); - DAWN_TRY(pipeline->Initialize()); - return pipeline; + return AcquireRef(new RenderPipeline(device, descriptor)); } MaybeError RenderPipeline::Initialize() { @@ -610,14 +608,11 @@ namespace dawn_native { namespace vulkan { return mHandle; } - void RenderPipeline::CreateAsync(Device* device, - const RenderPipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateRenderPipelineAsyncCallback callback, - void* userdata) { - Ref pipeline = AcquireRef(new RenderPipeline(device, descriptor)); + void RenderPipeline::InitializeAsync(Ref renderPipeline, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata) { std::unique_ptr asyncTask = - std::make_unique(pipeline, blueprintHash, callback, + std::make_unique(std::move(renderPipeline), callback, userdata); CreateRenderPipelineAsyncTask::RunAsync(std::move(asyncTask)); } diff --git a/src/dawn_native/vulkan/RenderPipelineVk.h b/src/dawn_native/vulkan/RenderPipelineVk.h index 15f7a9be8d..0efd8680b7 100644 --- a/src/dawn_native/vulkan/RenderPipelineVk.h +++ b/src/dawn_native/vulkan/RenderPipelineVk.h @@ -26,24 +26,22 @@ namespace dawn_native { namespace vulkan { class RenderPipeline final : public RenderPipelineBase { public: - static ResultOrError> Create( - Device* device, - const RenderPipelineDescriptor* descriptor); - static void CreateAsync(Device* device, - const RenderPipelineDescriptor* descriptor, - size_t blueprintHash, - WGPUCreateRenderPipelineAsyncCallback callback, - void* userdata); + static Ref CreateUninitialized(Device* device, + const RenderPipelineDescriptor* descriptor); + static void InitializeAsync(Ref renderPipeline, + WGPUCreateRenderPipelineAsyncCallback callback, + void* userdata); VkPipeline GetHandle() const; + MaybeError Initialize() override; + // Dawn API void SetLabelImpl() override; private: ~RenderPipeline() override; using RenderPipelineBase::RenderPipelineBase; - MaybeError Initialize() override; struct PipelineVertexInputStateCreateInfoTemporaryAllocations { std::array bindings;