From 50f995851d9bc6f21373f00cf3a42f41b000283d Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Wed, 31 Mar 2021 18:36:32 +0000 Subject: [PATCH] DeviceBase: Make object creation use ResultOrError> This is in preparation for a change that will change all the CreateFooInternal to be CreateFoo so they can be called in a reentrant manner without special refcounting. This also standardizes all the backends (except OpenGL and Null) to use Object::Create that returns a Ref or ResultOrError>, something we wanted to do for a long time. Bug: dawn:723 Change-Id: I9e0baced333ffeb0affbc6a276c9bd9de082263a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/46440 Reviewed-by: Austin Eng Reviewed-by: Stephen White Commit-Queue: Corentin Wallez --- src/dawn_native/CommandEncoder.cpp | 24 +- src/dawn_native/CommandEncoder.h | 3 + src/dawn_native/Device.cpp | 345 ++++++++---------- src/dawn_native/Device.h | 83 +++-- src/dawn_native/PipelineLayout.cpp | 40 +- src/dawn_native/RenderBundleEncoder.cpp | 7 + src/dawn_native/RenderBundleEncoder.h | 5 +- src/dawn_native/d3d12/BindGroupD3D12.cpp | 4 +- src/dawn_native/d3d12/BindGroupD3D12.h | 4 +- .../d3d12/BindGroupLayoutD3D12.cpp | 10 +- src/dawn_native/d3d12/BindGroupLayoutD3D12.h | 8 +- src/dawn_native/d3d12/BufferD3D12.cpp | 7 + src/dawn_native/d3d12/BufferD3D12.h | 8 +- src/dawn_native/d3d12/CommandBufferD3D12.cpp | 6 + src/dawn_native/d3d12/CommandBufferD3D12.h | 5 +- .../d3d12/ComputePipelineD3D12.cpp | 4 +- src/dawn_native/d3d12/ComputePipelineD3D12.h | 5 +- src/dawn_native/d3d12/DeviceD3D12.cpp | 42 +-- src/dawn_native/d3d12/DeviceD3D12.h | 28 +- src/dawn_native/d3d12/PipelineLayoutD3D12.cpp | 4 +- src/dawn_native/d3d12/PipelineLayoutD3D12.h | 5 +- src/dawn_native/d3d12/QuerySetD3D12.cpp | 6 +- src/dawn_native/d3d12/QuerySetD3D12.h | 4 +- src/dawn_native/d3d12/RenderPipelineD3D12.cpp | 4 +- src/dawn_native/d3d12/RenderPipelineD3D12.h | 5 +- src/dawn_native/d3d12/SamplerD3D12.cpp | 5 + src/dawn_native/d3d12/SamplerD3D12.h | 3 +- src/dawn_native/d3d12/ShaderModuleD3D12.cpp | 8 +- src/dawn_native/d3d12/ShaderModuleD3D12.h | 6 +- src/dawn_native/d3d12/SwapChainD3D12.cpp | 5 + src/dawn_native/d3d12/SwapChainD3D12.h | 3 +- src/dawn_native/d3d12/TextureD3D12.cpp | 6 + src/dawn_native/d3d12/TextureD3D12.h | 5 +- src/dawn_native/metal/BindGroupLayoutMTL.h | 7 +- src/dawn_native/metal/BindGroupLayoutMTL.mm | 12 +- src/dawn_native/metal/BindGroupMTL.h | 4 +- src/dawn_native/metal/BindGroupMTL.mm | 2 +- src/dawn_native/metal/CommandBufferMTL.h | 5 +- src/dawn_native/metal/CommandBufferMTL.mm | 6 +- src/dawn_native/metal/ComputePipelineMTL.h | 5 +- src/dawn_native/metal/ComputePipelineMTL.mm | 4 +- src/dawn_native/metal/DeviceMTL.h | 29 +- src/dawn_native/metal/DeviceMTL.mm | 40 +- src/dawn_native/metal/PipelineLayoutMTL.h | 4 +- src/dawn_native/metal/PipelineLayoutMTL.mm | 6 + src/dawn_native/metal/QuerySetMTL.h | 4 +- src/dawn_native/metal/QuerySetMTL.mm | 6 +- src/dawn_native/metal/RenderPipelineMTL.h | 5 +- src/dawn_native/metal/RenderPipelineMTL.mm | 4 +- src/dawn_native/metal/SamplerMTL.h | 3 +- src/dawn_native/metal/SamplerMTL.mm | 5 +- src/dawn_native/metal/ShaderModuleMTL.h | 6 +- src/dawn_native/metal/ShaderModuleMTL.mm | 8 +- src/dawn_native/metal/SwapChainMTL.h | 11 +- src/dawn_native/metal/SwapChainMTL.mm | 18 +- src/dawn_native/metal/TextureMTL.h | 10 +- src/dawn_native/metal/TextureMTL.mm | 12 + src/dawn_native/null/DeviceNull.cpp | 63 ++-- src/dawn_native/null/DeviceNull.h | 36 +- src/dawn_native/opengl/BindGroupGL.cpp | 2 +- src/dawn_native/opengl/BindGroupGL.h | 4 +- src/dawn_native/opengl/BindGroupLayoutGL.cpp | 6 +- src/dawn_native/opengl/BindGroupLayoutGL.h | 2 +- src/dawn_native/opengl/DeviceGL.cpp | 46 +-- src/dawn_native/opengl/DeviceGL.h | 29 +- src/dawn_native/opengl/PipelineGL.cpp | 4 +- src/dawn_native/opengl/ShaderModuleGL.cpp | 8 +- src/dawn_native/opengl/ShaderModuleGL.h | 6 +- src/dawn_native/vulkan/BindGroupLayoutVk.cpp | 9 +- src/dawn_native/vulkan/BindGroupLayoutVk.h | 9 +- src/dawn_native/vulkan/BindGroupVk.cpp | 4 +- src/dawn_native/vulkan/BindGroupVk.h | 4 +- src/dawn_native/vulkan/CommandBufferVk.cpp | 6 +- src/dawn_native/vulkan/CommandBufferVk.h | 4 +- src/dawn_native/vulkan/ComputePipelineVk.cpp | 4 +- src/dawn_native/vulkan/ComputePipelineVk.h | 5 +- src/dawn_native/vulkan/DeviceVk.cpp | 28 +- src/dawn_native/vulkan/DeviceVk.h | 29 +- src/dawn_native/vulkan/PipelineLayoutVk.cpp | 4 +- src/dawn_native/vulkan/PipelineLayoutVk.h | 5 +- src/dawn_native/vulkan/QuerySetVk.cpp | 6 +- src/dawn_native/vulkan/QuerySetVk.h | 4 +- src/dawn_native/vulkan/RenderPipelineVk.cpp | 4 +- src/dawn_native/vulkan/RenderPipelineVk.h | 5 +- src/dawn_native/vulkan/SamplerVk.cpp | 5 +- src/dawn_native/vulkan/SamplerVk.h | 3 +- src/dawn_native/vulkan/ShaderModuleVk.cpp | 11 +- src/dawn_native/vulkan/ShaderModuleVk.h | 6 +- src/dawn_native/vulkan/SwapChainVk.cpp | 17 +- src/dawn_native/vulkan/SwapChainVk.h | 10 +- src/dawn_native/vulkan/TextureVk.cpp | 6 +- src/dawn_native/vulkan/TextureVk.h | 4 +- 92 files changed, 701 insertions(+), 620 deletions(-) diff --git a/src/dawn_native/CommandEncoder.cpp b/src/dawn_native/CommandEncoder.cpp index 743bc7c0f4..99f3013486 100644 --- a/src/dawn_native/CommandEncoder.cpp +++ b/src/dawn_native/CommandEncoder.cpp @@ -897,18 +897,28 @@ namespace dawn_native { } CommandBufferBase* CommandEncoder::APIFinish(const CommandBufferDescriptor* descriptor) { + Ref commandBuffer; + if (GetDevice()->ConsumedError(FinishInternal(descriptor), &commandBuffer)) { + return CommandBufferBase::MakeError(GetDevice()); + } + ASSERT(!IsError()); + return commandBuffer.Detach(); + } + + ResultOrError> CommandEncoder::FinishInternal( + const CommandBufferDescriptor* descriptor) { DeviceBase* device = GetDevice(); + // Even if mEncodingContext.Finish() validation fails, calling it will mutate the internal // state of the encoding context. The internal state is set to finished, and subsequent // calls to encode commands will generate errors. - if (device->ConsumedError(mEncodingContext.Finish()) || - device->ConsumedError(device->ValidateIsAlive()) || - (device->IsValidationEnabled() && - device->ConsumedError(ValidateFinish(mEncodingContext.GetIterator(), - mEncodingContext.GetPassUsages())))) { - return CommandBufferBase::MakeError(device); + DAWN_TRY(mEncodingContext.Finish()); + DAWN_TRY(device->ValidateIsAlive()); + + if (device->IsValidationEnabled()) { + DAWN_TRY( + ValidateFinish(mEncodingContext.GetIterator(), mEncodingContext.GetPassUsages())); } - ASSERT(!IsError()); return device->CreateCommandBuffer(this, descriptor); } diff --git a/src/dawn_native/CommandEncoder.h b/src/dawn_native/CommandEncoder.h index 816651c73b..c422e9830e 100644 --- a/src/dawn_native/CommandEncoder.h +++ b/src/dawn_native/CommandEncoder.h @@ -74,6 +74,9 @@ namespace dawn_native { CommandBufferBase* APIFinish(const CommandBufferDescriptor* descriptor = nullptr); private: + ResultOrError> FinishInternal( + const CommandBufferDescriptor* descriptor); + MaybeError ValidateFinish(CommandIterator* commands, const PerPassUsages& perPassUsages) const; diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp index 669a29869d..8b02f927b0 100644 --- a/src/dawn_native/Device.cpp +++ b/src/dawn_native/Device.cpp @@ -442,18 +442,17 @@ namespace dawn_native { const size_t blueprintHash = blueprint.ComputeContentHash(); blueprint.SetContentHash(blueprintHash); - Ref result = nullptr; + Ref result; auto iter = mCaches->bindGroupLayouts.find(&blueprint); if (iter != mCaches->bindGroupLayouts.end()) { result = *iter; } else { - BindGroupLayoutBase* backendObj; - DAWN_TRY_ASSIGN(backendObj, CreateBindGroupLayoutImpl(descriptor)); - backendObj->SetIsCachedReference(); - backendObj->SetContentHash(blueprintHash); - mCaches->bindGroupLayouts.insert(backendObj); - result = AcquireRef(backendObj); + DAWN_TRY_ASSIGN(result, CreateBindGroupLayoutImpl(descriptor)); + result->SetIsCachedReference(); + result->SetContentHash(blueprintHash); + mCaches->bindGroupLayouts.insert(result.Get()); } + return std::move(result); } @@ -477,25 +476,25 @@ namespace dawn_native { return mEmptyBindGroupLayout.Get(); } - ResultOrError DeviceBase::GetOrCreateComputePipeline( + ResultOrError> DeviceBase::GetOrCreateComputePipeline( const ComputePipelineDescriptor* descriptor) { ComputePipelineBase blueprint(this, descriptor); const size_t blueprintHash = blueprint.ComputeContentHash(); blueprint.SetContentHash(blueprintHash); + Ref result; auto iter = mCaches->computePipelines.find(&blueprint); if (iter != mCaches->computePipelines.end()) { - (*iter)->Reference(); - return *iter; + result = *iter; + } else { + DAWN_TRY_ASSIGN(result, CreateComputePipelineImpl(descriptor)); + result->SetIsCachedReference(); + result->SetContentHash(blueprintHash); + mCaches->computePipelines.insert(result.Get()); } - ComputePipelineBase* backendObj; - DAWN_TRY_ASSIGN(backendObj, CreateComputePipelineImpl(descriptor)); - backendObj->SetIsCachedReference(); - backendObj->SetContentHash(blueprintHash); - mCaches->computePipelines.insert(backendObj); - return backendObj; + return std::move(result); } void DeviceBase::UncacheComputePipeline(ComputePipelineBase* obj) { @@ -504,25 +503,25 @@ namespace dawn_native { ASSERT(removedCount == 1); } - ResultOrError DeviceBase::GetOrCreatePipelineLayout( + ResultOrError> DeviceBase::GetOrCreatePipelineLayout( const PipelineLayoutDescriptor* descriptor) { PipelineLayoutBase blueprint(this, descriptor); const size_t blueprintHash = blueprint.ComputeContentHash(); blueprint.SetContentHash(blueprintHash); + Ref result; auto iter = mCaches->pipelineLayouts.find(&blueprint); if (iter != mCaches->pipelineLayouts.end()) { - (*iter)->Reference(); - return *iter; + result = *iter; + } else { + DAWN_TRY_ASSIGN(result, CreatePipelineLayoutImpl(descriptor)); + result->SetIsCachedReference(); + result->SetContentHash(blueprintHash); + mCaches->pipelineLayouts.insert(result.Get()); } - PipelineLayoutBase* backendObj; - DAWN_TRY_ASSIGN(backendObj, CreatePipelineLayoutImpl(descriptor)); - backendObj->SetIsCachedReference(); - backendObj->SetContentHash(blueprintHash); - mCaches->pipelineLayouts.insert(backendObj); - return backendObj; + return std::move(result); } void DeviceBase::UncachePipelineLayout(PipelineLayoutBase* obj) { @@ -531,25 +530,25 @@ namespace dawn_native { ASSERT(removedCount == 1); } - ResultOrError DeviceBase::GetOrCreateRenderPipeline( + ResultOrError> DeviceBase::GetOrCreateRenderPipeline( const RenderPipelineDescriptor* descriptor) { RenderPipelineBase blueprint(this, descriptor); const size_t blueprintHash = blueprint.ComputeContentHash(); blueprint.SetContentHash(blueprintHash); + Ref result; auto iter = mCaches->renderPipelines.find(&blueprint); if (iter != mCaches->renderPipelines.end()) { - (*iter)->Reference(); - return *iter; + result = *iter; + } else { + DAWN_TRY_ASSIGN(result, CreateRenderPipelineImpl(descriptor)); + result->SetIsCachedReference(); + result->SetContentHash(blueprintHash); + mCaches->renderPipelines.insert(result.Get()); } - RenderPipelineBase* backendObj; - DAWN_TRY_ASSIGN(backendObj, CreateRenderPipelineImpl(descriptor)); - backendObj->SetIsCachedReference(); - backendObj->SetContentHash(blueprintHash); - mCaches->renderPipelines.insert(backendObj); - return backendObj; + return std::move(result); } void DeviceBase::UncacheRenderPipeline(RenderPipelineBase* obj) { @@ -558,25 +557,25 @@ namespace dawn_native { ASSERT(removedCount == 1); } - ResultOrError DeviceBase::GetOrCreateSampler( + ResultOrError> DeviceBase::GetOrCreateSampler( const SamplerDescriptor* descriptor) { SamplerBase blueprint(this, descriptor); const size_t blueprintHash = blueprint.ComputeContentHash(); blueprint.SetContentHash(blueprintHash); + Ref result; auto iter = mCaches->samplers.find(&blueprint); if (iter != mCaches->samplers.end()) { - (*iter)->Reference(); - return *iter; + result = *iter; + } else { + DAWN_TRY_ASSIGN(result, CreateSamplerImpl(descriptor)); + result->SetIsCachedReference(); + result->SetContentHash(blueprintHash); + mCaches->samplers.insert(result.Get()); } - SamplerBase* backendObj; - DAWN_TRY_ASSIGN(backendObj, CreateSamplerImpl(descriptor)); - backendObj->SetIsCachedReference(); - backendObj->SetContentHash(blueprintHash); - mCaches->samplers.insert(backendObj); - return backendObj; + return std::move(result); } void DeviceBase::UncacheSampler(SamplerBase* obj) { @@ -585,7 +584,7 @@ namespace dawn_native { ASSERT(removedCount == 1); } - ResultOrError DeviceBase::GetOrCreateShaderModule( + ResultOrError> DeviceBase::GetOrCreateShaderModule( const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult) { ShaderModuleBase blueprint(this, descriptor); @@ -593,29 +592,29 @@ namespace dawn_native { const size_t blueprintHash = blueprint.ComputeContentHash(); blueprint.SetContentHash(blueprintHash); + Ref result; auto iter = mCaches->shaderModules.find(&blueprint); if (iter != mCaches->shaderModules.end()) { - (*iter)->Reference(); - return *iter; + result = *iter; + } else { + if (parseResult == nullptr) { + // We skip the parse on creation if validation isn't enabled which let's us quickly + // lookup in the cache without validating and parsing. We need the parsed module + // now, so call validate. Most of |ValidateShaderModuleDescriptor| is parsing, but + // we can consider splitting it if additional validation is added. + ASSERT(!IsValidationEnabled()); + ShaderModuleParseResult localParseResult = + ValidateShaderModuleDescriptor(this, descriptor).AcquireSuccess(); + DAWN_TRY_ASSIGN(result, CreateShaderModuleImpl(descriptor, &localParseResult)); + } else { + DAWN_TRY_ASSIGN(result, CreateShaderModuleImpl(descriptor, parseResult)); + } + result->SetIsCachedReference(); + result->SetContentHash(blueprintHash); + mCaches->shaderModules.insert(result.Get()); } - ShaderModuleBase* backendObj; - if (parseResult == nullptr) { - // We skip the parse on creation if validation isn't enabled which let's us quickly - // lookup in the cache without validating and parsing. We need the parsed module now, so - // call validate. Most of |ValidateShaderModuleDescriptor| is parsing, but we can - // consider splitting it if additional validation is added. - ASSERT(!IsValidationEnabled()); - ShaderModuleParseResult localParseResult = - ValidateShaderModuleDescriptor(this, descriptor).AcquireSuccess(); - DAWN_TRY_ASSIGN(backendObj, CreateShaderModuleImpl(descriptor, &localParseResult)); - } else { - DAWN_TRY_ASSIGN(backendObj, CreateShaderModuleImpl(descriptor, parseResult)); - } - backendObj->SetIsCachedReference(); - backendObj->SetContentHash(blueprintHash); - mCaches->shaderModules.insert(backendObj); - return backendObj; + return std::move(result); } void DeviceBase::UncacheShaderModule(ShaderModuleBase* obj) { @@ -665,23 +664,19 @@ namespace dawn_native { // Object creation API methods BindGroupBase* DeviceBase::APICreateBindGroup(const BindGroupDescriptor* descriptor) { - BindGroupBase* result = nullptr; - - if (ConsumedError(CreateBindGroupInternal(&result, descriptor))) { + Ref result; + if (ConsumedError(CreateBindGroupInternal(descriptor), &result)) { return BindGroupBase::MakeError(this); } - - return result; + return result.Detach(); } BindGroupLayoutBase* DeviceBase::APICreateBindGroupLayout( const BindGroupLayoutDescriptor* descriptor) { - BindGroupLayoutBase* result = nullptr; - - if (ConsumedError(CreateBindGroupLayoutInternal(&result, descriptor))) { + Ref result; + if (ConsumedError(CreateBindGroupLayoutInternal(descriptor), &result)) { return BindGroupLayoutBase::MakeError(this); } - - return result; + return result.Detach(); } BufferBase* DeviceBase::APICreateBuffer(const BufferDescriptor* descriptor) { Ref result = nullptr; @@ -689,7 +684,6 @@ namespace dawn_native { ASSERT(result == nullptr); return BufferBase::MakeError(this, descriptor); } - return result.Detach(); } CommandEncoder* DeviceBase::APICreateCommandEncoder( @@ -698,19 +692,15 @@ namespace dawn_native { } ComputePipelineBase* DeviceBase::APICreateComputePipeline( const ComputePipelineDescriptor* descriptor) { - ComputePipelineBase* result = nullptr; - - if (ConsumedError(CreateComputePipelineInternal(&result, descriptor))) { + Ref result; + if (ConsumedError(CreateComputePipelineInternal(descriptor), &result)) { return ComputePipelineBase::MakeError(this); } - - return result; + return result.Detach(); } void DeviceBase::APICreateComputePipelineAsync(const ComputePipelineDescriptor* descriptor, WGPUCreateComputePipelineAsyncCallback callback, void* userdata) { - ComputePipelineBase* result = nullptr; - if (IsToggleEnabled(Toggle::DisallowUnsafeAPIs)) { callback(WGPUCreatePipelineAsyncStatus_Error, nullptr, "CreateComputePipelineAsync is disallowed because it isn't completely " @@ -719,51 +709,45 @@ namespace dawn_native { return; } - MaybeError maybeError = CreateComputePipelineInternal(&result, descriptor); - if (maybeError.IsError()) { - std::unique_ptr error = maybeError.AcquireError(); + ResultOrError> maybeResult = + CreateComputePipelineInternal(descriptor); + if (maybeResult.IsError()) { + std::unique_ptr error = maybeResult.AcquireError(); callback(WGPUCreatePipelineAsyncStatus_Error, nullptr, error->GetMessage().c_str(), userdata); return; } std::unique_ptr request = - std::make_unique(result, callback, userdata); + std::make_unique(maybeResult.AcquireSuccess().Detach(), + callback, userdata); mCreatePipelineAsyncTracker->TrackTask(std::move(request), GetPendingCommandSerial()); } PipelineLayoutBase* DeviceBase::APICreatePipelineLayout( const PipelineLayoutDescriptor* descriptor) { - PipelineLayoutBase* result = nullptr; - - if (ConsumedError(CreatePipelineLayoutInternal(&result, descriptor))) { + Ref result; + if (ConsumedError(CreatePipelineLayoutInternal(descriptor), &result)) { return PipelineLayoutBase::MakeError(this); } - - return result; + return result.Detach(); } QuerySetBase* DeviceBase::APICreateQuerySet(const QuerySetDescriptor* descriptor) { - QuerySetBase* result = nullptr; - - if (ConsumedError(CreateQuerySetInternal(&result, descriptor))) { + Ref result; + if (ConsumedError(CreateQuerySetInternal(descriptor), &result)) { return QuerySetBase::MakeError(this); } - - return result; + return result.Detach(); } SamplerBase* DeviceBase::APICreateSampler(const SamplerDescriptor* descriptor) { - SamplerBase* result = nullptr; - - if (ConsumedError(CreateSamplerInternal(&result, descriptor))) { + Ref result; + if (ConsumedError(CreateSamplerInternal(descriptor), &result)) { return SamplerBase::MakeError(this); } - - return result; + return result.Detach(); } void DeviceBase::APICreateRenderPipelineAsync(const RenderPipelineDescriptor2* descriptor, WGPUCreateRenderPipelineAsyncCallback callback, void* userdata) { - RenderPipelineBase* result = nullptr; - if (IsToggleEnabled(Toggle::DisallowUnsafeAPIs)) { callback(WGPUCreatePipelineAsyncStatus_Error, nullptr, "CreateRenderPipelineAsync is disallowed because it isn't completely " @@ -772,91 +756,79 @@ namespace dawn_native { return; } - MaybeError maybeError = CreateRenderPipelineInternal(&result, descriptor); - if (maybeError.IsError()) { - std::unique_ptr error = maybeError.AcquireError(); + ResultOrError> maybeResult = + CreateRenderPipelineInternal(descriptor); + if (maybeResult.IsError()) { + std::unique_ptr error = maybeResult.AcquireError(); callback(WGPUCreatePipelineAsyncStatus_Error, nullptr, error->GetMessage().c_str(), userdata); return; } std::unique_ptr request = - std::make_unique(result, callback, userdata); + std::make_unique(maybeResult.AcquireSuccess().Detach(), + callback, userdata); mCreatePipelineAsyncTracker->TrackTask(std::move(request), GetPendingCommandSerial()); } RenderBundleEncoder* DeviceBase::APICreateRenderBundleEncoder( const RenderBundleEncoderDescriptor* descriptor) { - RenderBundleEncoder* result = nullptr; - - if (ConsumedError(CreateRenderBundleEncoderInternal(&result, descriptor))) { + Ref result; + if (ConsumedError(CreateRenderBundleEncoderInternal(descriptor), &result)) { return RenderBundleEncoder::MakeError(this); } - - return result; + return result.Detach(); } RenderPipelineBase* DeviceBase::APICreateRenderPipeline( const RenderPipelineDescriptor* descriptor) { - RenderPipelineBase* result = nullptr; - // TODO: Enable this warning once the tests have been converted to either use the new // format or expect the deprecation warning. /*EmitDeprecationWarning( "The format of RenderPipelineDescriptor has changed, and will soon require the " "new structure. Please begin using CreateRenderPipeline2() instead.");*/ - if (ConsumedError(CreateRenderPipelineInternal(&result, descriptor))) { + Ref result; + if (ConsumedError(CreateRenderPipelineInternal(descriptor), &result)) { return RenderPipelineBase::MakeError(this); } - - return result; + return result.Detach(); } RenderPipelineBase* DeviceBase::APICreateRenderPipeline2( const RenderPipelineDescriptor2* descriptor) { - RenderPipelineBase* result = nullptr; - - if (ConsumedError(CreateRenderPipelineInternal(&result, descriptor))) { + Ref result; + if (ConsumedError(CreateRenderPipelineInternal(descriptor), &result)) { return RenderPipelineBase::MakeError(this); } - - return result; + return result.Detach(); } ShaderModuleBase* DeviceBase::APICreateShaderModule(const ShaderModuleDescriptor* descriptor) { - ShaderModuleBase* result = nullptr; - - if (ConsumedError(CreateShaderModuleInternal(&result, descriptor))) { + Ref result; + if (ConsumedError(CreateShaderModuleInternal(descriptor), &result)) { return ShaderModuleBase::MakeError(this); } - - return result; + return result.Detach(); } SwapChainBase* DeviceBase::APICreateSwapChain(Surface* surface, const SwapChainDescriptor* descriptor) { - SwapChainBase* result = nullptr; - - if (ConsumedError(CreateSwapChainInternal(&result, surface, descriptor))) { + Ref result; + if (ConsumedError(CreateSwapChainInternal(surface, descriptor), &result)) { return SwapChainBase::MakeError(this); } - - return result; + return result.Detach(); } TextureBase* DeviceBase::APICreateTexture(const TextureDescriptor* descriptor) { Ref result; - if (ConsumedError(CreateTextureInternal(descriptor), &result)) { return TextureBase::MakeError(this); } - return result.Detach(); } TextureViewBase* DeviceBase::CreateTextureView(TextureBase* texture, const TextureViewDescriptor* descriptor) { - TextureViewBase* result = nullptr; - - if (ConsumedError(CreateTextureViewInternal(&result, texture, descriptor))) { + Ref result; + if (ConsumedError(CreateTextureViewInternal(texture, descriptor), &result)) { return TextureViewBase::MakeError(this); } - - return result; + return result.Detach(); } // For Dawn Wire @@ -971,27 +943,22 @@ namespace dawn_native { // Implementation details of object creation - MaybeError DeviceBase::CreateBindGroupInternal(BindGroupBase** result, - const BindGroupDescriptor* descriptor) { + ResultOrError> DeviceBase::CreateBindGroupInternal( + const BindGroupDescriptor* descriptor) { DAWN_TRY(ValidateIsAlive()); if (IsValidationEnabled()) { DAWN_TRY(ValidateBindGroupDescriptor(this, descriptor)); } - DAWN_TRY_ASSIGN(*result, CreateBindGroupImpl(descriptor)); - return {}; + return CreateBindGroupImpl(descriptor); } - MaybeError DeviceBase::CreateBindGroupLayoutInternal( - BindGroupLayoutBase** result, + ResultOrError> DeviceBase::CreateBindGroupLayoutInternal( const BindGroupLayoutDescriptor* descriptor) { DAWN_TRY(ValidateIsAlive()); if (IsValidationEnabled()) { DAWN_TRY(ValidateBindGroupLayoutDescriptor(this, descriptor)); } - Ref bgl; - DAWN_TRY_ASSIGN(bgl, GetOrCreateBindGroupLayout(descriptor)); - *result = bgl.Detach(); - return {}; + return GetOrCreateBindGroupLayout(descriptor); } ResultOrError> DeviceBase::CreateBufferInternal( @@ -1011,8 +978,7 @@ namespace dawn_native { return std::move(buffer); } - MaybeError DeviceBase::CreateComputePipelineInternal( - ComputePipelineBase** result, + ResultOrError> DeviceBase::CreateComputePipelineInternal( const ComputePipelineDescriptor* descriptor) { DAWN_TRY(ValidateIsAlive()); if (IsValidationEnabled()) { @@ -1032,47 +998,40 @@ namespace dawn_native { descriptorWithDefaultLayout.layout = layoutRef.Get(); - DAWN_TRY_ASSIGN(*result, GetOrCreateComputePipeline(&descriptorWithDefaultLayout)); + return GetOrCreateComputePipeline(&descriptorWithDefaultLayout); } else { - DAWN_TRY_ASSIGN(*result, GetOrCreateComputePipeline(descriptor)); + return GetOrCreateComputePipeline(descriptor); } - return {}; } - MaybeError DeviceBase::CreatePipelineLayoutInternal( - PipelineLayoutBase** result, + ResultOrError> DeviceBase::CreatePipelineLayoutInternal( const PipelineLayoutDescriptor* descriptor) { DAWN_TRY(ValidateIsAlive()); if (IsValidationEnabled()) { DAWN_TRY(ValidatePipelineLayoutDescriptor(this, descriptor)); } - DAWN_TRY_ASSIGN(*result, GetOrCreatePipelineLayout(descriptor)); - return {}; + return GetOrCreatePipelineLayout(descriptor); } - MaybeError DeviceBase::CreateQuerySetInternal(QuerySetBase** result, - const QuerySetDescriptor* descriptor) { + ResultOrError> DeviceBase::CreateQuerySetInternal( + const QuerySetDescriptor* descriptor) { DAWN_TRY(ValidateIsAlive()); if (IsValidationEnabled()) { DAWN_TRY(ValidateQuerySetDescriptor(this, descriptor)); } - DAWN_TRY_ASSIGN(*result, CreateQuerySetImpl(descriptor)); - return {}; + return CreateQuerySetImpl(descriptor); } - MaybeError DeviceBase::CreateRenderBundleEncoderInternal( - RenderBundleEncoder** result, + ResultOrError> DeviceBase::CreateRenderBundleEncoderInternal( const RenderBundleEncoderDescriptor* descriptor) { DAWN_TRY(ValidateIsAlive()); if (IsValidationEnabled()) { DAWN_TRY(ValidateRenderBundleEncoderDescriptor(this, descriptor)); } - *result = new RenderBundleEncoder(this, descriptor); - return {}; + return RenderBundleEncoder::Create(this, descriptor); } - MaybeError DeviceBase::CreateRenderPipelineInternal( - RenderPipelineBase** result, + ResultOrError> DeviceBase::CreateRenderPipelineInternal( const RenderPipelineDescriptor2* descriptor) { DAWN_TRY(ValidateIsAlive()); if (IsValidationEnabled()) { @@ -1164,13 +1123,10 @@ namespace dawn_native { normalizedDescriptor.layout = layoutRef.Get(); } - DAWN_TRY_ASSIGN(*result, GetOrCreateRenderPipeline(&normalizedDescriptor)); - - return {}; + return GetOrCreateRenderPipeline(&normalizedDescriptor); } - MaybeError DeviceBase::CreateRenderPipelineInternal( - RenderPipelineBase** result, + ResultOrError> DeviceBase::CreateRenderPipelineInternal( const RenderPipelineDescriptor* descriptor) { DAWN_TRY(ValidateIsAlive()); @@ -1188,27 +1144,25 @@ namespace dawn_native { PipelineLayoutBase::CreateDefault(this, GetStages(descriptor))); descriptorWithDefaultLayout.layout = layoutRef.Get(); - DAWN_TRY_ASSIGN(*result, GetOrCreateRenderPipeline(&descriptorWithDefaultLayout)); + return GetOrCreateRenderPipeline(&descriptorWithDefaultLayout); } else { - DAWN_TRY_ASSIGN(*result, GetOrCreateRenderPipeline(descriptor)); + return GetOrCreateRenderPipeline(descriptor); } - return {}; } - MaybeError DeviceBase::CreateSamplerInternal(SamplerBase** result, - const SamplerDescriptor* descriptor) { + ResultOrError> DeviceBase::CreateSamplerInternal( + const SamplerDescriptor* descriptor) { const SamplerDescriptor defaultDescriptor = {}; DAWN_TRY(ValidateIsAlive()); descriptor = descriptor != nullptr ? descriptor : &defaultDescriptor; if (IsValidationEnabled()) { DAWN_TRY(ValidateSamplerDescriptor(this, descriptor)); } - DAWN_TRY_ASSIGN(*result, GetOrCreateSampler(descriptor)); - return {}; + return GetOrCreateSampler(descriptor); } - MaybeError DeviceBase::CreateShaderModuleInternal(ShaderModuleBase** result, - const ShaderModuleDescriptor* descriptor) { + ResultOrError> DeviceBase::CreateShaderModuleInternal( + const ShaderModuleDescriptor* descriptor) { DAWN_TRY(ValidateIsAlive()); ShaderModuleParseResult parseResult = {}; @@ -1218,13 +1172,12 @@ namespace dawn_native { parseResultPtr = &parseResult; } - DAWN_TRY_ASSIGN(*result, GetOrCreateShaderModule(descriptor, parseResultPtr)); - return {}; + return GetOrCreateShaderModule(descriptor, parseResultPtr); } - MaybeError DeviceBase::CreateSwapChainInternal(SwapChainBase** result, - Surface* surface, - const SwapChainDescriptor* descriptor) { + ResultOrError> DeviceBase::CreateSwapChainInternal( + Surface* surface, + const SwapChainDescriptor* descriptor) { DAWN_TRY(ValidateIsAlive()); if (IsValidationEnabled()) { DAWN_TRY(ValidateSwapChainDescriptor(this, surface, descriptor)); @@ -1232,26 +1185,25 @@ namespace dawn_native { // TODO(dawn:269): Remove this code path once implementation-based swapchains are removed. if (surface == nullptr) { - DAWN_TRY_ASSIGN(*result, CreateSwapChainImpl(descriptor)); + return CreateSwapChainImpl(descriptor); } else { ASSERT(descriptor->implementation == 0); NewSwapChainBase* previousSwapChain = surface->GetAttachedSwapChain(); - ResultOrError maybeNewSwapChain = + ResultOrError> maybeNewSwapChain = CreateSwapChainImpl(surface, previousSwapChain, descriptor); if (previousSwapChain != nullptr) { previousSwapChain->DetachFromSurface(); } - NewSwapChainBase* newSwapChain = nullptr; + Ref newSwapChain; DAWN_TRY_ASSIGN(newSwapChain, std::move(maybeNewSwapChain)); newSwapChain->SetIsAttached(); - surface->SetAttachedSwapChain(newSwapChain); - *result = newSwapChain; + surface->SetAttachedSwapChain(newSwapChain.Get()); + return newSwapChain; } - return {}; } ResultOrError> DeviceBase::CreateTextureInternal( @@ -1265,17 +1217,16 @@ namespace dawn_native { return CreateTextureImpl(&fixedDescriptor); } - MaybeError DeviceBase::CreateTextureViewInternal(TextureViewBase** result, - TextureBase* texture, - const TextureViewDescriptor* descriptor) { + ResultOrError> DeviceBase::CreateTextureViewInternal( + TextureBase* texture, + const TextureViewDescriptor* descriptor) { DAWN_TRY(ValidateIsAlive()); DAWN_TRY(ValidateObject(texture)); TextureViewDescriptor desc = GetTextureViewDescriptorWithDefaults(texture, descriptor); if (IsValidationEnabled()) { DAWN_TRY(ValidateTextureViewDescriptor(texture, &desc)); } - DAWN_TRY_ASSIGN(*result, CreateTextureViewImpl(texture, &desc)); - return {}; + return CreateTextureViewImpl(texture, &desc); } // Other implementation details diff --git a/src/dawn_native/Device.h b/src/dawn_native/Device.h index 320849f738..7cbffd6644 100644 --- a/src/dawn_native/Device.h +++ b/src/dawn_native/Device.h @@ -81,7 +81,7 @@ namespace dawn_native { // The reference returned has the same lifetime as the device. const Format& GetValidInternalFormat(wgpu::TextureFormat format) const; - virtual CommandBufferBase* CreateCommandBuffer( + virtual ResultOrError> CreateCommandBuffer( CommandEncoder* encoder, const CommandBufferDescriptor* descriptor) = 0; @@ -110,22 +110,22 @@ namespace dawn_native { BindGroupLayoutBase* GetEmptyBindGroupLayout(); - ResultOrError GetOrCreateComputePipeline( + ResultOrError> GetOrCreateComputePipeline( const ComputePipelineDescriptor* descriptor); void UncacheComputePipeline(ComputePipelineBase* obj); - ResultOrError GetOrCreatePipelineLayout( + ResultOrError> GetOrCreatePipelineLayout( const PipelineLayoutDescriptor* descriptor); void UncachePipelineLayout(PipelineLayoutBase* obj); - ResultOrError GetOrCreateRenderPipeline( + ResultOrError> GetOrCreateRenderPipeline( const RenderPipelineDescriptor* descriptor); void UncacheRenderPipeline(RenderPipelineBase* obj); - ResultOrError GetOrCreateSampler(const SamplerDescriptor* descriptor); + ResultOrError> GetOrCreateSampler(const SamplerDescriptor* descriptor); void UncacheSampler(SamplerBase* obj); - ResultOrError GetOrCreateShaderModule( + ResultOrError> GetOrCreateShaderModule( const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult); void UncacheShaderModule(ShaderModuleBase* obj); @@ -259,35 +259,35 @@ namespace dawn_native { void IncrementLastSubmittedCommandSerial(); private: - virtual ResultOrError CreateBindGroupImpl( + virtual ResultOrError> CreateBindGroupImpl( const BindGroupDescriptor* descriptor) = 0; - virtual ResultOrError CreateBindGroupLayoutImpl( + virtual ResultOrError> CreateBindGroupLayoutImpl( const BindGroupLayoutDescriptor* descriptor) = 0; virtual ResultOrError> CreateBufferImpl( const BufferDescriptor* descriptor) = 0; - virtual ResultOrError CreateComputePipelineImpl( + virtual ResultOrError> CreateComputePipelineImpl( const ComputePipelineDescriptor* descriptor) = 0; - virtual ResultOrError CreatePipelineLayoutImpl( + virtual ResultOrError> CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) = 0; - virtual ResultOrError CreateQuerySetImpl( + virtual ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) = 0; - virtual ResultOrError CreateRenderPipelineImpl( + virtual ResultOrError> CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) = 0; - virtual ResultOrError CreateSamplerImpl( + virtual ResultOrError> CreateSamplerImpl( const SamplerDescriptor* descriptor) = 0; - virtual ResultOrError CreateShaderModuleImpl( + virtual ResultOrError> CreateShaderModuleImpl( const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult) = 0; - virtual ResultOrError CreateSwapChainImpl( + virtual ResultOrError> CreateSwapChainImpl( const SwapChainDescriptor* descriptor) = 0; // Note that previousSwapChain may be nullptr, or come from a different backend. - virtual ResultOrError CreateSwapChainImpl( + virtual ResultOrError> CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, const SwapChainDescriptor* descriptor) = 0; virtual ResultOrError> CreateTextureImpl( const TextureDescriptor* descriptor) = 0; - virtual ResultOrError CreateTextureViewImpl( + virtual ResultOrError> CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) = 0; @@ -295,34 +295,33 @@ namespace dawn_native { ResultOrError> CreateEmptyBindGroupLayout(); - MaybeError CreateBindGroupInternal(BindGroupBase** result, - const BindGroupDescriptor* descriptor); - MaybeError CreateBindGroupLayoutInternal(BindGroupLayoutBase** result, - const BindGroupLayoutDescriptor* descriptor); + ResultOrError> CreateBindGroupInternal( + const BindGroupDescriptor* descriptor); + ResultOrError> CreateBindGroupLayoutInternal( + const BindGroupLayoutDescriptor* descriptor); ResultOrError> CreateBufferInternal(const BufferDescriptor* descriptor); - MaybeError CreateComputePipelineInternal(ComputePipelineBase** result, - const ComputePipelineDescriptor* descriptor); - MaybeError CreatePipelineLayoutInternal(PipelineLayoutBase** result, - const PipelineLayoutDescriptor* descriptor); - MaybeError CreateQuerySetInternal(QuerySetBase** result, - const QuerySetDescriptor* descriptor); - MaybeError CreateRenderBundleEncoderInternal( - RenderBundleEncoder** result, + ResultOrError> CreateComputePipelineInternal( + const ComputePipelineDescriptor* descriptor); + ResultOrError> CreatePipelineLayoutInternal( + const PipelineLayoutDescriptor* descriptor); + ResultOrError> CreateQuerySetInternal( + const QuerySetDescriptor* descriptor); + ResultOrError> CreateRenderBundleEncoderInternal( const RenderBundleEncoderDescriptor* descriptor); - MaybeError CreateRenderPipelineInternal(RenderPipelineBase** result, - const RenderPipelineDescriptor2* descriptor); - MaybeError CreateRenderPipelineInternal(RenderPipelineBase** result, - const RenderPipelineDescriptor* descriptor); - MaybeError CreateSamplerInternal(SamplerBase** result, const SamplerDescriptor* descriptor); - MaybeError CreateShaderModuleInternal(ShaderModuleBase** result, - const ShaderModuleDescriptor* descriptor); - MaybeError CreateSwapChainInternal(SwapChainBase** result, - Surface* surface, - const SwapChainDescriptor* descriptor); + ResultOrError> CreateRenderPipelineInternal( + const RenderPipelineDescriptor2* descriptor); + ResultOrError> CreateRenderPipelineInternal( + const RenderPipelineDescriptor* descriptor); + ResultOrError> CreateSamplerInternal(const SamplerDescriptor* descriptor); + ResultOrError> CreateShaderModuleInternal( + const ShaderModuleDescriptor* descriptor); + ResultOrError> CreateSwapChainInternal( + Surface* surface, + const SwapChainDescriptor* descriptor); ResultOrError> CreateTextureInternal(const TextureDescriptor* descriptor); - MaybeError CreateTextureViewInternal(TextureViewBase** result, - TextureBase* texture, - const TextureViewDescriptor* descriptor); + ResultOrError> CreateTextureViewInternal( + TextureBase* texture, + const TextureViewDescriptor* descriptor); void ApplyToggleOverrides(const DeviceDescriptor* deviceDescriptor); void ApplyExtensions(const DeviceDescriptor* deviceDescriptor); diff --git a/src/dawn_native/PipelineLayout.cpp b/src/dawn_native/PipelineLayout.cpp index f2990a45ef..bc659ee320 100644 --- a/src/dawn_native/PipelineLayout.cpp +++ b/src/dawn_native/PipelineLayout.cpp @@ -213,33 +213,27 @@ namespace dawn_native { } // Create the deduced pipeline layout, validating if it is valid. - Ref result = nullptr; - { - ityp::array bgls = {}; - for (BindGroupIndex group(0); group < pipelineBGLCount; ++group) { - bgls[group] = bindGroupLayouts[group].Get(); - } + ityp::array bgls = {}; + for (BindGroupIndex group(0); group < pipelineBGLCount; ++group) { + bgls[group] = bindGroupLayouts[group].Get(); + } - PipelineLayoutDescriptor desc = {}; - desc.bindGroupLayouts = bgls.data(); - desc.bindGroupLayoutCount = static_cast(pipelineBGLCount); + PipelineLayoutDescriptor desc = {}; + desc.bindGroupLayouts = bgls.data(); + desc.bindGroupLayoutCount = static_cast(pipelineBGLCount); - DAWN_TRY(ValidatePipelineLayoutDescriptor(device, &desc)); + DAWN_TRY(ValidatePipelineLayoutDescriptor(device, &desc)); - PipelineLayoutBase* pipelineLayout; - DAWN_TRY_ASSIGN(pipelineLayout, device->GetOrCreatePipelineLayout(&desc)); + Ref result; + DAWN_TRY_ASSIGN(result, device->GetOrCreatePipelineLayout(&desc)); + ASSERT(!result->IsError()); - result = AcquireRef(pipelineLayout); - - ASSERT(!pipelineLayout->IsError()); - - // Sanity check in debug that the pipeline layout is compatible with the current - // pipeline. - for (const StageAndDescriptor& stage : stages) { - const EntryPointMetadata& metadata = stage.module->GetEntryPoint(stage.entryPoint); - ASSERT(ValidateCompatibilityWithPipelineLayout(device, metadata, pipelineLayout) - .IsSuccess()); - } + // Sanity check in debug that the pipeline layout is compatible with the current + // pipeline. + for (const StageAndDescriptor& stage : stages) { + const EntryPointMetadata& metadata = stage.module->GetEntryPoint(stage.entryPoint); + ASSERT(ValidateCompatibilityWithPipelineLayout(device, metadata, result.Get()) + .IsSuccess()); } return std::move(result); diff --git a/src/dawn_native/RenderBundleEncoder.cpp b/src/dawn_native/RenderBundleEncoder.cpp index f466530c04..45647a42ca 100644 --- a/src/dawn_native/RenderBundleEncoder.cpp +++ b/src/dawn_native/RenderBundleEncoder.cpp @@ -90,6 +90,13 @@ namespace dawn_native { mBundleEncodingContext(device, this) { } + // static + Ref RenderBundleEncoder::Create( + DeviceBase* device, + const RenderBundleEncoderDescriptor* descriptor) { + return AcquireRef(new RenderBundleEncoder(device, descriptor)); + } + // static RenderBundleEncoder* RenderBundleEncoder::MakeError(DeviceBase* device) { return new RenderBundleEncoder(device, ObjectBase::kError); diff --git a/src/dawn_native/RenderBundleEncoder.h b/src/dawn_native/RenderBundleEncoder.h index 4b0a1f5a74..27d5de26d2 100644 --- a/src/dawn_native/RenderBundleEncoder.h +++ b/src/dawn_native/RenderBundleEncoder.h @@ -28,8 +28,8 @@ namespace dawn_native { class RenderBundleEncoder final : public RenderEncoderBase { public: - RenderBundleEncoder(DeviceBase* device, const RenderBundleEncoderDescriptor* descriptor); - + static Ref Create(DeviceBase* device, + const RenderBundleEncoderDescriptor* descriptor); static RenderBundleEncoder* MakeError(DeviceBase* device); RenderBundleBase* APIFinish(const RenderBundleDescriptor* descriptor); @@ -37,6 +37,7 @@ namespace dawn_native { CommandIterator AcquireCommands(); private: + RenderBundleEncoder(DeviceBase* device, const RenderBundleEncoderDescriptor* descriptor); RenderBundleEncoder(DeviceBase* device, ErrorTag errorTag); ResultOrError FinishImpl(const RenderBundleDescriptor* descriptor); diff --git a/src/dawn_native/d3d12/BindGroupD3D12.cpp b/src/dawn_native/d3d12/BindGroupD3D12.cpp index 88a54b8f05..75eb734c69 100644 --- a/src/dawn_native/d3d12/BindGroupD3D12.cpp +++ b/src/dawn_native/d3d12/BindGroupD3D12.cpp @@ -25,8 +25,8 @@ namespace dawn_native { namespace d3d12 { // static - ResultOrError BindGroup::Create(Device* device, - const BindGroupDescriptor* descriptor) { + ResultOrError> BindGroup::Create(Device* device, + const BindGroupDescriptor* descriptor) { return ToBackend(descriptor->layout)->AllocateBindGroup(device, descriptor); } diff --git a/src/dawn_native/d3d12/BindGroupD3D12.h b/src/dawn_native/d3d12/BindGroupD3D12.h index a48fc14225..43b54c14dc 100644 --- a/src/dawn_native/d3d12/BindGroupD3D12.h +++ b/src/dawn_native/d3d12/BindGroupD3D12.h @@ -28,8 +28,8 @@ namespace dawn_native { namespace d3d12 { class BindGroup final : public BindGroupBase, public PlacementAllocated { public: - static ResultOrError Create(Device* device, - const BindGroupDescriptor* descriptor); + static ResultOrError> Create(Device* device, + const BindGroupDescriptor* descriptor); BindGroup(Device* device, const BindGroupDescriptor* descriptor, diff --git a/src/dawn_native/d3d12/BindGroupLayoutD3D12.cpp b/src/dawn_native/d3d12/BindGroupLayoutD3D12.cpp index 449a07a5ff..c5151664ee 100644 --- a/src/dawn_native/d3d12/BindGroupLayoutD3D12.cpp +++ b/src/dawn_native/d3d12/BindGroupLayoutD3D12.cpp @@ -56,6 +56,12 @@ namespace dawn_native { namespace d3d12 { } } // anonymous namespace + // static + Ref BindGroupLayout::Create(Device* device, + const BindGroupLayoutDescriptor* descriptor) { + return AcquireRef(new BindGroupLayout(device, descriptor)); + } + BindGroupLayout::BindGroupLayout(Device* device, const BindGroupLayoutDescriptor* descriptor) : BindGroupLayoutBase(device, descriptor), mBindingOffsets(GetBindingCount()), @@ -138,7 +144,7 @@ namespace dawn_native { namespace d3d12 { device->GetSamplerStagingDescriptorAllocator(GetSamplerDescriptorCount()); } - ResultOrError BindGroupLayout::AllocateBindGroup( + ResultOrError> BindGroupLayout::AllocateBindGroup( Device* device, const BindGroupDescriptor* descriptor) { uint32_t viewSizeIncrement = 0; @@ -158,7 +164,7 @@ namespace dawn_native { namespace d3d12 { bindGroup->SetSamplerAllocationEntry(std::move(samplerHeapCacheEntry)); } - return bindGroup.Detach(); + return bindGroup; } void BindGroupLayout::DeallocateBindGroup(BindGroup* bindGroup, diff --git a/src/dawn_native/d3d12/BindGroupLayoutD3D12.h b/src/dawn_native/d3d12/BindGroupLayoutD3D12.h index 6ee462348f..503566643d 100644 --- a/src/dawn_native/d3d12/BindGroupLayoutD3D12.h +++ b/src/dawn_native/d3d12/BindGroupLayoutD3D12.h @@ -30,10 +30,11 @@ namespace dawn_native { namespace d3d12 { class BindGroupLayout final : public BindGroupLayoutBase { public: - BindGroupLayout(Device* device, const BindGroupLayoutDescriptor* descriptor); + static Ref Create(Device* device, + const BindGroupLayoutDescriptor* descriptor); - ResultOrError AllocateBindGroup(Device* device, - const BindGroupDescriptor* descriptor); + ResultOrError> AllocateBindGroup(Device* device, + const BindGroupDescriptor* descriptor); void DeallocateBindGroup(BindGroup* bindGroup, CPUDescriptorHeapAllocation* viewAllocation); enum DescriptorType { @@ -53,6 +54,7 @@ namespace dawn_native { namespace d3d12 { const D3D12_DESCRIPTOR_RANGE* GetSamplerDescriptorRanges() const; private: + BindGroupLayout(Device* device, const BindGroupLayoutDescriptor* descriptor); ~BindGroupLayout() override = default; ityp::stack_vec mBindingOffsets; std::array mDescriptorCounts; diff --git a/src/dawn_native/d3d12/BufferD3D12.cpp b/src/dawn_native/d3d12/BufferD3D12.cpp index 2d445be872..a73eb9b57c 100644 --- a/src/dawn_native/d3d12/BufferD3D12.cpp +++ b/src/dawn_native/d3d12/BufferD3D12.cpp @@ -94,6 +94,13 @@ namespace dawn_native { namespace d3d12 { } } // namespace + // static + ResultOrError> Buffer::Create(Device* device, const BufferDescriptor* descriptor) { + Ref buffer = AcquireRef(new Buffer(device, descriptor)); + DAWN_TRY(buffer->Initialize(descriptor->mappedAtCreation)); + return buffer; + } + Buffer::Buffer(Device* device, const BufferDescriptor* descriptor) : BufferBase(device, descriptor) { } diff --git a/src/dawn_native/d3d12/BufferD3D12.h b/src/dawn_native/d3d12/BufferD3D12.h index 613508fb30..4cd3d512ca 100644 --- a/src/dawn_native/d3d12/BufferD3D12.h +++ b/src/dawn_native/d3d12/BufferD3D12.h @@ -27,9 +27,8 @@ namespace dawn_native { namespace d3d12 { class Buffer final : public BufferBase { public: - Buffer(Device* device, const BufferDescriptor* descriptor); - - MaybeError Initialize(bool mappedAtCreation); + static ResultOrError> Create(Device* device, + const BufferDescriptor* descriptor); ID3D12Resource* GetD3D12Resource() const; D3D12_GPU_VIRTUAL_ADDRESS GetVA() const; @@ -51,7 +50,10 @@ namespace dawn_native { namespace d3d12 { const CopyTextureToBufferCmd* copy); private: + Buffer(Device* device, const BufferDescriptor* descriptor); ~Buffer() override; + + MaybeError Initialize(bool mappedAtCreation); MaybeError MapAsyncImpl(wgpu::MapMode mode, size_t offset, size_t size) override; void UnmapImpl() override; void DestroyImpl() override; diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.cpp b/src/dawn_native/d3d12/CommandBufferD3D12.cpp index bbcbb8421f..33811d8a4a 100644 --- a/src/dawn_native/d3d12/CommandBufferD3D12.cpp +++ b/src/dawn_native/d3d12/CommandBufferD3D12.cpp @@ -588,6 +588,12 @@ namespace dawn_native { namespace d3d12 { } // anonymous namespace + // static + Ref CommandBuffer::Create(CommandEncoder* encoder, + const CommandBufferDescriptor* descriptor) { + return AcquireRef(new CommandBuffer(encoder, descriptor)); + } + CommandBuffer::CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor) : CommandBufferBase(encoder, descriptor) { } diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.h b/src/dawn_native/d3d12/CommandBufferD3D12.h index cf4c4517c2..342f851a99 100644 --- a/src/dawn_native/d3d12/CommandBufferD3D12.h +++ b/src/dawn_native/d3d12/CommandBufferD3D12.h @@ -30,11 +30,14 @@ namespace dawn_native { namespace d3d12 { class CommandBuffer final : public CommandBufferBase { public: - CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor); + static Ref Create(CommandEncoder* encoder, + const CommandBufferDescriptor* descriptor); MaybeError RecordCommands(CommandRecordingContext* commandContext); private: + CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor); + MaybeError RecordComputePass(CommandRecordingContext* commandContext, BindGroupStateTracker* bindingTracker); MaybeError RecordRenderPass(CommandRecordingContext* commandContext, diff --git a/src/dawn_native/d3d12/ComputePipelineD3D12.cpp b/src/dawn_native/d3d12/ComputePipelineD3D12.cpp index 4e457d596d..948722af53 100644 --- a/src/dawn_native/d3d12/ComputePipelineD3D12.cpp +++ b/src/dawn_native/d3d12/ComputePipelineD3D12.cpp @@ -24,12 +24,12 @@ namespace dawn_native { namespace d3d12 { - ResultOrError ComputePipeline::Create( + ResultOrError> ComputePipeline::Create( Device* device, const ComputePipelineDescriptor* descriptor) { Ref pipeline = AcquireRef(new ComputePipeline(device, descriptor)); DAWN_TRY(pipeline->Initialize(descriptor)); - return pipeline.Detach(); + return pipeline; } MaybeError ComputePipeline::Initialize(const ComputePipelineDescriptor* descriptor) { diff --git a/src/dawn_native/d3d12/ComputePipelineD3D12.h b/src/dawn_native/d3d12/ComputePipelineD3D12.h index 7d05f0b3c1..b71ae1a469 100644 --- a/src/dawn_native/d3d12/ComputePipelineD3D12.h +++ b/src/dawn_native/d3d12/ComputePipelineD3D12.h @@ -25,8 +25,9 @@ namespace dawn_native { namespace d3d12 { class ComputePipeline final : public ComputePipelineBase { public: - static ResultOrError Create(Device* device, - const ComputePipelineDescriptor* descriptor); + static ResultOrError> Create( + Device* device, + const ComputePipelineDescriptor* descriptor); ComputePipeline() = delete; ID3D12PipelineState* GetPipelineState() const; diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp index 23f5ac0356..ef0b2d7515 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.cpp +++ b/src/dawn_native/d3d12/DeviceD3D12.cpp @@ -297,51 +297,51 @@ namespace dawn_native { namespace d3d12 { return mPendingCommands.ExecuteCommandList(this); } - ResultOrError Device::CreateBindGroupImpl( + ResultOrError> Device::CreateBindGroupImpl( const BindGroupDescriptor* descriptor) { return BindGroup::Create(this, descriptor); } - ResultOrError Device::CreateBindGroupLayoutImpl( + ResultOrError> Device::CreateBindGroupLayoutImpl( const BindGroupLayoutDescriptor* descriptor) { - return new BindGroupLayout(this, descriptor); + return BindGroupLayout::Create(this, descriptor); } ResultOrError> Device::CreateBufferImpl(const BufferDescriptor* descriptor) { - Ref buffer = AcquireRef(new Buffer(this, descriptor)); - DAWN_TRY(buffer->Initialize(descriptor->mappedAtCreation)); - return std::move(buffer); + return Buffer::Create(this, descriptor); } - CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder, - const CommandBufferDescriptor* descriptor) { - return new CommandBuffer(encoder, descriptor); + ResultOrError> Device::CreateCommandBuffer( + CommandEncoder* encoder, + const CommandBufferDescriptor* descriptor) { + return CommandBuffer::Create(encoder, descriptor); } - ResultOrError Device::CreateComputePipelineImpl( + ResultOrError> Device::CreateComputePipelineImpl( const ComputePipelineDescriptor* descriptor) { return ComputePipeline::Create(this, descriptor); } - ResultOrError Device::CreatePipelineLayoutImpl( + ResultOrError> Device::CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) { return PipelineLayout::Create(this, descriptor); } - ResultOrError Device::CreateQuerySetImpl(const QuerySetDescriptor* descriptor) { + ResultOrError> Device::CreateQuerySetImpl( + const QuerySetDescriptor* descriptor) { return QuerySet::Create(this, descriptor); } - ResultOrError Device::CreateRenderPipelineImpl( + ResultOrError> Device::CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) { return RenderPipeline::Create(this, descriptor); } - ResultOrError Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) { - return new Sampler(this, descriptor); + ResultOrError> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) { + return Sampler::Create(this, descriptor); } - ResultOrError Device::CreateShaderModuleImpl( + ResultOrError> Device::CreateShaderModuleImpl( const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult) { return ShaderModule::Create(this, descriptor, parseResult); } - ResultOrError Device::CreateSwapChainImpl( + ResultOrError> Device::CreateSwapChainImpl( const SwapChainDescriptor* descriptor) { - return new SwapChain(this, descriptor); + return SwapChain::Create(this, descriptor); } - ResultOrError Device::CreateSwapChainImpl( + ResultOrError> Device::CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, const SwapChainDescriptor* descriptor) { @@ -350,10 +350,10 @@ namespace dawn_native { namespace d3d12 { ResultOrError> Device::CreateTextureImpl(const TextureDescriptor* descriptor) { return Texture::Create(this, descriptor); } - ResultOrError Device::CreateTextureViewImpl( + ResultOrError> Device::CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) { - return new TextureView(texture, descriptor); + return TextureView::Create(texture, descriptor); } ResultOrError> Device::CreateStagingBuffer(size_t size) { diff --git a/src/dawn_native/d3d12/DeviceD3D12.h b/src/dawn_native/d3d12/DeviceD3D12.h index 40f029f41c..3867e4129c 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.h +++ b/src/dawn_native/d3d12/DeviceD3D12.h @@ -46,8 +46,9 @@ namespace dawn_native { namespace d3d12 { MaybeError Initialize(); - CommandBufferBase* CreateCommandBuffer(CommandEncoder* encoder, - const CommandBufferDescriptor* descriptor) override; + ResultOrError> CreateCommandBuffer( + CommandEncoder* encoder, + const CommandBufferDescriptor* descriptor) override; MaybeError TickImpl() override; @@ -140,33 +141,34 @@ namespace dawn_native { namespace d3d12 { private: using DeviceBase::DeviceBase; - ResultOrError CreateBindGroupImpl( + ResultOrError> CreateBindGroupImpl( const BindGroupDescriptor* descriptor) override; - ResultOrError CreateBindGroupLayoutImpl( + ResultOrError> CreateBindGroupLayoutImpl( const BindGroupLayoutDescriptor* descriptor) override; ResultOrError> CreateBufferImpl( const BufferDescriptor* descriptor) override; - ResultOrError CreateComputePipelineImpl( + ResultOrError> CreateComputePipelineImpl( const ComputePipelineDescriptor* descriptor) override; - ResultOrError CreatePipelineLayoutImpl( + ResultOrError> CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) override; - ResultOrError CreateQuerySetImpl( + ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) override; - ResultOrError CreateRenderPipelineImpl( + ResultOrError> CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) override; - ResultOrError CreateSamplerImpl(const SamplerDescriptor* descriptor) override; - ResultOrError CreateShaderModuleImpl( + ResultOrError> CreateSamplerImpl( + const SamplerDescriptor* descriptor) override; + ResultOrError> CreateShaderModuleImpl( const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult) override; - ResultOrError CreateSwapChainImpl( + ResultOrError> CreateSwapChainImpl( const SwapChainDescriptor* descriptor) override; - ResultOrError CreateSwapChainImpl( + ResultOrError> CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, const SwapChainDescriptor* descriptor) override; ResultOrError> CreateTextureImpl( const TextureDescriptor* descriptor) override; - ResultOrError CreateTextureViewImpl( + ResultOrError> CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) override; diff --git a/src/dawn_native/d3d12/PipelineLayoutD3D12.cpp b/src/dawn_native/d3d12/PipelineLayoutD3D12.cpp index 93e8bc0d64..913c845ff8 100644 --- a/src/dawn_native/d3d12/PipelineLayoutD3D12.cpp +++ b/src/dawn_native/d3d12/PipelineLayoutD3D12.cpp @@ -54,12 +54,12 @@ namespace dawn_native { namespace d3d12 { } } // anonymous namespace - ResultOrError PipelineLayout::Create( + ResultOrError> PipelineLayout::Create( Device* device, const PipelineLayoutDescriptor* descriptor) { Ref layout = AcquireRef(new PipelineLayout(device, descriptor)); DAWN_TRY(layout->Initialize()); - return layout.Detach(); + return layout; } MaybeError PipelineLayout::Initialize() { diff --git a/src/dawn_native/d3d12/PipelineLayoutD3D12.h b/src/dawn_native/d3d12/PipelineLayoutD3D12.h index 45c4779707..f20923543b 100644 --- a/src/dawn_native/d3d12/PipelineLayoutD3D12.h +++ b/src/dawn_native/d3d12/PipelineLayoutD3D12.h @@ -26,8 +26,9 @@ namespace dawn_native { namespace d3d12 { class PipelineLayout final : public PipelineLayoutBase { public: - static ResultOrError Create(Device* device, - const PipelineLayoutDescriptor* descriptor); + static ResultOrError> Create( + Device* device, + const PipelineLayoutDescriptor* descriptor); uint32_t GetCbvUavSrvRootParameterIndex(BindGroupIndex group) const; uint32_t GetSamplerRootParameterIndex(BindGroupIndex group) const; diff --git a/src/dawn_native/d3d12/QuerySetD3D12.cpp b/src/dawn_native/d3d12/QuerySetD3D12.cpp index 726e6a201a..420c8a3c75 100644 --- a/src/dawn_native/d3d12/QuerySetD3D12.cpp +++ b/src/dawn_native/d3d12/QuerySetD3D12.cpp @@ -33,11 +33,11 @@ namespace dawn_native { namespace d3d12 { } // anonymous namespace // static - ResultOrError QuerySet::Create(Device* device, - const QuerySetDescriptor* descriptor) { + ResultOrError> QuerySet::Create(Device* device, + const QuerySetDescriptor* descriptor) { Ref querySet = AcquireRef(new QuerySet(device, descriptor)); DAWN_TRY(querySet->Initialize()); - return querySet.Detach(); + return querySet; } MaybeError QuerySet::Initialize() { diff --git a/src/dawn_native/d3d12/QuerySetD3D12.h b/src/dawn_native/d3d12/QuerySetD3D12.h index 7b24cceb67..16c49d199e 100644 --- a/src/dawn_native/d3d12/QuerySetD3D12.h +++ b/src/dawn_native/d3d12/QuerySetD3D12.h @@ -24,8 +24,8 @@ namespace dawn_native { namespace d3d12 { class QuerySet : public QuerySetBase { public: - static ResultOrError Create(Device* device, - const QuerySetDescriptor* descriptor); + static ResultOrError> Create(Device* device, + const QuerySetDescriptor* descriptor); ID3D12QueryHeap* GetQueryHeap() const; diff --git a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp index 371e9a7bc3..713d2c16e6 100644 --- a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp +++ b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp @@ -295,12 +295,12 @@ namespace dawn_native { namespace d3d12 { } // anonymous namespace - ResultOrError RenderPipeline::Create( + ResultOrError> RenderPipeline::Create( Device* device, const RenderPipelineDescriptor* descriptor) { Ref pipeline = AcquireRef(new RenderPipeline(device, descriptor)); DAWN_TRY(pipeline->Initialize(descriptor)); - return pipeline.Detach(); + return pipeline; } MaybeError RenderPipeline::Initialize(const RenderPipelineDescriptor* descriptor) { diff --git a/src/dawn_native/d3d12/RenderPipelineD3D12.h b/src/dawn_native/d3d12/RenderPipelineD3D12.h index 7e6e70340a..c99d0a12ff 100644 --- a/src/dawn_native/d3d12/RenderPipelineD3D12.h +++ b/src/dawn_native/d3d12/RenderPipelineD3D12.h @@ -26,8 +26,9 @@ namespace dawn_native { namespace d3d12 { class RenderPipeline final : public RenderPipelineBase { public: - static ResultOrError Create(Device* device, - const RenderPipelineDescriptor* descriptor); + static ResultOrError> Create( + Device* device, + const RenderPipelineDescriptor* descriptor); RenderPipeline() = delete; D3D12_PRIMITIVE_TOPOLOGY GetD3D12PrimitiveTopology() const; diff --git a/src/dawn_native/d3d12/SamplerD3D12.cpp b/src/dawn_native/d3d12/SamplerD3D12.cpp index 7d63e0d297..0671cc428d 100644 --- a/src/dawn_native/d3d12/SamplerD3D12.cpp +++ b/src/dawn_native/d3d12/SamplerD3D12.cpp @@ -32,6 +32,11 @@ namespace dawn_native { namespace d3d12 { } } // namespace + // static + Ref Sampler::Create(Device* device, const SamplerDescriptor* descriptor) { + return AcquireRef(new Sampler(device, descriptor)); + } + Sampler::Sampler(Device* device, const SamplerDescriptor* descriptor) : SamplerBase(device, descriptor) { D3D12_FILTER_TYPE minFilter; diff --git a/src/dawn_native/d3d12/SamplerD3D12.h b/src/dawn_native/d3d12/SamplerD3D12.h index 59a7d8370a..ede374b94b 100644 --- a/src/dawn_native/d3d12/SamplerD3D12.h +++ b/src/dawn_native/d3d12/SamplerD3D12.h @@ -25,11 +25,12 @@ namespace dawn_native { namespace d3d12 { class Sampler final : public SamplerBase { public: - Sampler(Device* device, const SamplerDescriptor* descriptor); + static Ref Create(Device* device, const SamplerDescriptor* descriptor); const D3D12_SAMPLER_DESC& GetSamplerDescriptor() const; private: + Sampler(Device* device, const SamplerDescriptor* descriptor); ~Sampler() override = default; D3D12_SAMPLER_DESC mSamplerDesc = {}; }; diff --git a/src/dawn_native/d3d12/ShaderModuleD3D12.cpp b/src/dawn_native/d3d12/ShaderModuleD3D12.cpp index b6c03fa10f..33ea80b456 100644 --- a/src/dawn_native/d3d12/ShaderModuleD3D12.cpp +++ b/src/dawn_native/d3d12/ShaderModuleD3D12.cpp @@ -172,12 +172,12 @@ namespace dawn_native { namespace d3d12 { } // static - ResultOrError ShaderModule::Create(Device* device, - const ShaderModuleDescriptor* descriptor, - ShaderModuleParseResult* parseResult) { + ResultOrError> ShaderModule::Create(Device* device, + const ShaderModuleDescriptor* descriptor, + ShaderModuleParseResult* parseResult) { Ref module = AcquireRef(new ShaderModule(device, descriptor)); DAWN_TRY(module->Initialize(parseResult)); - return module.Detach(); + return module; } ShaderModule::ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor) diff --git a/src/dawn_native/d3d12/ShaderModuleD3D12.h b/src/dawn_native/d3d12/ShaderModuleD3D12.h index 3cd44e480c..98eed9e5a1 100644 --- a/src/dawn_native/d3d12/ShaderModuleD3D12.h +++ b/src/dawn_native/d3d12/ShaderModuleD3D12.h @@ -45,9 +45,9 @@ namespace dawn_native { namespace d3d12 { class ShaderModule final : public ShaderModuleBase { public: - static ResultOrError Create(Device* device, - const ShaderModuleDescriptor* descriptor, - ShaderModuleParseResult* parseResult); + static ResultOrError> Create(Device* device, + const ShaderModuleDescriptor* descriptor, + ShaderModuleParseResult* parseResult); ResultOrError Compile(const char* entryPointName, SingleShaderStage stage, diff --git a/src/dawn_native/d3d12/SwapChainD3D12.cpp b/src/dawn_native/d3d12/SwapChainD3D12.cpp index 4d890bfa10..8fd4554e7f 100644 --- a/src/dawn_native/d3d12/SwapChainD3D12.cpp +++ b/src/dawn_native/d3d12/SwapChainD3D12.cpp @@ -21,6 +21,11 @@ namespace dawn_native { namespace d3d12 { + // static + Ref SwapChain::Create(Device* device, const SwapChainDescriptor* descriptor) { + return AcquireRef(new SwapChain(device, descriptor)); + } + SwapChain::SwapChain(Device* device, const SwapChainDescriptor* descriptor) : OldSwapChainBase(device, descriptor) { const auto& im = GetImplementation(); diff --git a/src/dawn_native/d3d12/SwapChainD3D12.h b/src/dawn_native/d3d12/SwapChainD3D12.h index 6938e20ada..4083b04a14 100644 --- a/src/dawn_native/d3d12/SwapChainD3D12.h +++ b/src/dawn_native/d3d12/SwapChainD3D12.h @@ -23,9 +23,10 @@ namespace dawn_native { namespace d3d12 { class SwapChain final : public OldSwapChainBase { public: - SwapChain(Device* device, const SwapChainDescriptor* descriptor); + static Ref Create(Device* device, const SwapChainDescriptor* descriptor); protected: + SwapChain(Device* device, const SwapChainDescriptor* descriptor); ~SwapChain() override; TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override; MaybeError OnBeforePresent(TextureViewBase* view) override; diff --git a/src/dawn_native/d3d12/TextureD3D12.cpp b/src/dawn_native/d3d12/TextureD3D12.cpp index ba70e43774..145fff608b 100644 --- a/src/dawn_native/d3d12/TextureD3D12.cpp +++ b/src/dawn_native/d3d12/TextureD3D12.cpp @@ -1017,6 +1017,12 @@ namespace dawn_native { namespace d3d12 { isValidToDecay == other.isValidToDecay; } + // static + Ref TextureView::Create(TextureBase* texture, + const TextureViewDescriptor* descriptor) { + return AcquireRef(new TextureView(texture, descriptor)); + } + TextureView::TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor) : TextureViewBase(texture, descriptor) { mSrvDesc.Format = D3D12TextureFormat(descriptor->format); diff --git a/src/dawn_native/d3d12/TextureD3D12.h b/src/dawn_native/d3d12/TextureD3D12.h index 8c55b3eb88..528dd21698 100644 --- a/src/dawn_native/d3d12/TextureD3D12.h +++ b/src/dawn_native/d3d12/TextureD3D12.h @@ -128,7 +128,8 @@ namespace dawn_native { namespace d3d12 { class TextureView final : public TextureViewBase { public: - TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor); + static Ref Create(TextureBase* texture, + const TextureViewDescriptor* descriptor); DXGI_FORMAT GetD3D12Format() const; @@ -138,6 +139,8 @@ namespace dawn_native { namespace d3d12 { D3D12_UNORDERED_ACCESS_VIEW_DESC GetUAVDescriptor() const; private: + TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor); + D3D12_SHADER_RESOURCE_VIEW_DESC mSrvDesc; }; }} // namespace dawn_native::d3d12 diff --git a/src/dawn_native/metal/BindGroupLayoutMTL.h b/src/dawn_native/metal/BindGroupLayoutMTL.h index c6777db7a7..edd9c35b1c 100644 --- a/src/dawn_native/metal/BindGroupLayoutMTL.h +++ b/src/dawn_native/metal/BindGroupLayoutMTL.h @@ -25,13 +25,16 @@ namespace dawn_native { namespace metal { class BindGroupLayout final : public BindGroupLayoutBase { public: - BindGroupLayout(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor); + static Ref Create(DeviceBase* device, + const BindGroupLayoutDescriptor* descriptor); - BindGroup* AllocateBindGroup(Device* device, const BindGroupDescriptor* descriptor); + Ref AllocateBindGroup(Device* device, const BindGroupDescriptor* descriptor); void DeallocateBindGroup(BindGroup* bindGroup); private: + BindGroupLayout(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor); ~BindGroupLayout() override = default; + SlabAllocator mBindGroupAllocator; }; diff --git a/src/dawn_native/metal/BindGroupLayoutMTL.mm b/src/dawn_native/metal/BindGroupLayoutMTL.mm index 70beb5d537..535979bb83 100644 --- a/src/dawn_native/metal/BindGroupLayoutMTL.mm +++ b/src/dawn_native/metal/BindGroupLayoutMTL.mm @@ -18,15 +18,21 @@ namespace dawn_native { namespace metal { + // static + Ref BindGroupLayout::Create(DeviceBase* device, + const BindGroupLayoutDescriptor* descriptor) { + return AcquireRef(new BindGroupLayout(device, descriptor)); + } + BindGroupLayout::BindGroupLayout(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor) : BindGroupLayoutBase(device, descriptor), mBindGroupAllocator(MakeFrontendBindGroupAllocator(4096)) { } - BindGroup* BindGroupLayout::AllocateBindGroup(Device* device, - const BindGroupDescriptor* descriptor) { - return mBindGroupAllocator.Allocate(device, descriptor); + Ref BindGroupLayout::AllocateBindGroup(Device* device, + const BindGroupDescriptor* descriptor) { + return AcquireRef(mBindGroupAllocator.Allocate(device, descriptor)); } void BindGroupLayout::DeallocateBindGroup(BindGroup* bindGroup) { diff --git a/src/dawn_native/metal/BindGroupMTL.h b/src/dawn_native/metal/BindGroupMTL.h index 791dbf9418..29a3f4e82c 100644 --- a/src/dawn_native/metal/BindGroupMTL.h +++ b/src/dawn_native/metal/BindGroupMTL.h @@ -24,9 +24,9 @@ namespace dawn_native { namespace metal { class BindGroup final : public BindGroupBase, public PlacementAllocated { public: - BindGroup(Device* device, const BindGroupDescriptor* descriptor); + static Ref Create(Device* device, const BindGroupDescriptor* descriptor); - static BindGroup* Create(Device* device, const BindGroupDescriptor* descriptor); + BindGroup(Device* device, const BindGroupDescriptor* descriptor); private: ~BindGroup() override; diff --git a/src/dawn_native/metal/BindGroupMTL.mm b/src/dawn_native/metal/BindGroupMTL.mm index d8bcd515d9..48571ecbb7 100644 --- a/src/dawn_native/metal/BindGroupMTL.mm +++ b/src/dawn_native/metal/BindGroupMTL.mm @@ -27,7 +27,7 @@ namespace dawn_native { namespace metal { } // static - BindGroup* BindGroup::Create(Device* device, const BindGroupDescriptor* descriptor) { + Ref BindGroup::Create(Device* device, const BindGroupDescriptor* descriptor) { return ToBackend(descriptor->layout)->AllocateBindGroup(device, descriptor); } diff --git a/src/dawn_native/metal/CommandBufferMTL.h b/src/dawn_native/metal/CommandBufferMTL.h index 3410e57954..4283a13a2c 100644 --- a/src/dawn_native/metal/CommandBufferMTL.h +++ b/src/dawn_native/metal/CommandBufferMTL.h @@ -31,11 +31,14 @@ namespace dawn_native { namespace metal { class CommandBuffer final : public CommandBufferBase { public: - CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor); + static Ref Create(CommandEncoder* encoder, + const CommandBufferDescriptor* descriptor); MaybeError FillCommands(CommandRecordingContext* commandContext); private: + using CommandBufferBase::CommandBufferBase; + MaybeError EncodeComputePass(CommandRecordingContext* commandContext); MaybeError EncodeRenderPass(CommandRecordingContext* commandContext, MTLRenderPassDescriptor* mtlRenderPass, diff --git a/src/dawn_native/metal/CommandBufferMTL.mm b/src/dawn_native/metal/CommandBufferMTL.mm index 6c2d3565ce..ad6c59a26b 100644 --- a/src/dawn_native/metal/CommandBufferMTL.mm +++ b/src/dawn_native/metal/CommandBufferMTL.mm @@ -544,8 +544,10 @@ namespace dawn_native { namespace metal { } // anonymous namespace - CommandBuffer::CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor) - : CommandBufferBase(encoder, descriptor) { + // static + Ref CommandBuffer::Create(CommandEncoder* encoder, + const CommandBufferDescriptor* descriptor) { + return AcquireRef(new CommandBuffer(encoder, descriptor)); } MaybeError CommandBuffer::FillCommands(CommandRecordingContext* commandContext) { diff --git a/src/dawn_native/metal/ComputePipelineMTL.h b/src/dawn_native/metal/ComputePipelineMTL.h index f9e874d659..3ff70b1809 100644 --- a/src/dawn_native/metal/ComputePipelineMTL.h +++ b/src/dawn_native/metal/ComputePipelineMTL.h @@ -27,8 +27,9 @@ namespace dawn_native { namespace metal { class ComputePipeline final : public ComputePipelineBase { public: - static ResultOrError Create(Device* device, - const ComputePipelineDescriptor* descriptor); + static ResultOrError> Create( + Device* device, + const ComputePipelineDescriptor* descriptor); void Encode(id encoder); MTLSize GetLocalWorkGroupSize() const; diff --git a/src/dawn_native/metal/ComputePipelineMTL.mm b/src/dawn_native/metal/ComputePipelineMTL.mm index 7de57bdf20..0845abf0c6 100644 --- a/src/dawn_native/metal/ComputePipelineMTL.mm +++ b/src/dawn_native/metal/ComputePipelineMTL.mm @@ -20,12 +20,12 @@ namespace dawn_native { namespace metal { // static - ResultOrError ComputePipeline::Create( + ResultOrError> ComputePipeline::Create( Device* device, const ComputePipelineDescriptor* descriptor) { Ref pipeline = AcquireRef(new ComputePipeline(device, descriptor)); DAWN_TRY(pipeline->Initialize(descriptor)); - return pipeline.Detach(); + return pipeline; } MaybeError ComputePipeline::Initialize(const ComputePipelineDescriptor* descriptor) { diff --git a/src/dawn_native/metal/DeviceMTL.h b/src/dawn_native/metal/DeviceMTL.h index f886fcd32d..90ef4fd05c 100644 --- a/src/dawn_native/metal/DeviceMTL.h +++ b/src/dawn_native/metal/DeviceMTL.h @@ -41,9 +41,6 @@ namespace dawn_native { namespace metal { MaybeError Initialize(); - CommandBufferBase* CreateCommandBuffer(CommandEncoder* encoder, - const CommandBufferDescriptor* descriptor) override; - MaybeError TickImpl() override; id GetMTLDevice(); @@ -78,33 +75,37 @@ namespace dawn_native { namespace metal { NSPRef> mtlDevice, const DeviceDescriptor* descriptor); - ResultOrError CreateBindGroupImpl( + ResultOrError> CreateBindGroupImpl( const BindGroupDescriptor* descriptor) override; - ResultOrError CreateBindGroupLayoutImpl( + ResultOrError> CreateBindGroupLayoutImpl( const BindGroupLayoutDescriptor* descriptor) override; ResultOrError> CreateBufferImpl( const BufferDescriptor* descriptor) override; - ResultOrError CreateComputePipelineImpl( + ResultOrError> CreateCommandBuffer( + CommandEncoder* encoder, + const CommandBufferDescriptor* descriptor) override; + ResultOrError> CreateComputePipelineImpl( const ComputePipelineDescriptor* descriptor) override; - ResultOrError CreatePipelineLayoutImpl( + ResultOrError> CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) override; - ResultOrError CreateQuerySetImpl( + ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) override; - ResultOrError CreateRenderPipelineImpl( + ResultOrError> CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) override; - ResultOrError CreateSamplerImpl(const SamplerDescriptor* descriptor) override; - ResultOrError CreateShaderModuleImpl( + ResultOrError> CreateSamplerImpl( + const SamplerDescriptor* descriptor) override; + ResultOrError> CreateShaderModuleImpl( const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult) override; - ResultOrError CreateSwapChainImpl( + ResultOrError> CreateSwapChainImpl( const SwapChainDescriptor* descriptor) override; - ResultOrError CreateSwapChainImpl( + ResultOrError> CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, const SwapChainDescriptor* descriptor) override; ResultOrError> CreateTextureImpl( const TextureDescriptor* descriptor) override; - ResultOrError CreateTextureViewImpl( + ResultOrError> CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) override; diff --git a/src/dawn_native/metal/DeviceMTL.mm b/src/dawn_native/metal/DeviceMTL.mm index 6dcf97d588..85fb511c77 100644 --- a/src/dawn_native/metal/DeviceMTL.mm +++ b/src/dawn_native/metal/DeviceMTL.mm @@ -117,61 +117,63 @@ namespace dawn_native { namespace metal { } } - ResultOrError Device::CreateBindGroupImpl( + ResultOrError> Device::CreateBindGroupImpl( const BindGroupDescriptor* descriptor) { return BindGroup::Create(this, descriptor); } - ResultOrError Device::CreateBindGroupLayoutImpl( + ResultOrError> Device::CreateBindGroupLayoutImpl( const BindGroupLayoutDescriptor* descriptor) { - return new BindGroupLayout(this, descriptor); + return BindGroupLayout::Create(this, descriptor); } ResultOrError> Device::CreateBufferImpl(const BufferDescriptor* descriptor) { return Buffer::Create(this, descriptor); } - CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder, - const CommandBufferDescriptor* descriptor) { - return new CommandBuffer(encoder, descriptor); + ResultOrError> Device::CreateCommandBuffer( + CommandEncoder* encoder, + const CommandBufferDescriptor* descriptor) { + return CommandBuffer::Create(encoder, descriptor); } - ResultOrError Device::CreateComputePipelineImpl( + ResultOrError> Device::CreateComputePipelineImpl( const ComputePipelineDescriptor* descriptor) { return ComputePipeline::Create(this, descriptor); } - ResultOrError Device::CreatePipelineLayoutImpl( + ResultOrError> Device::CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) { - return new PipelineLayout(this, descriptor); + return PipelineLayout::Create(this, descriptor); } - ResultOrError Device::CreateQuerySetImpl(const QuerySetDescriptor* descriptor) { + ResultOrError> Device::CreateQuerySetImpl( + const QuerySetDescriptor* descriptor) { return QuerySet::Create(this, descriptor); } - ResultOrError Device::CreateRenderPipelineImpl( + ResultOrError> Device::CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) { return RenderPipeline::Create(this, descriptor); } - ResultOrError Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) { + ResultOrError> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) { return Sampler::Create(this, descriptor); } - ResultOrError Device::CreateShaderModuleImpl( + ResultOrError> Device::CreateShaderModuleImpl( const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult) { return ShaderModule::Create(this, descriptor, parseResult); } - ResultOrError Device::CreateSwapChainImpl( + ResultOrError> Device::CreateSwapChainImpl( const SwapChainDescriptor* descriptor) { - return new OldSwapChain(this, descriptor); + return OldSwapChain::Create(this, descriptor); } - ResultOrError Device::CreateSwapChainImpl( + ResultOrError> Device::CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, const SwapChainDescriptor* descriptor) { return SwapChain::Create(this, surface, previousSwapChain, descriptor); } ResultOrError> Device::CreateTextureImpl(const TextureDescriptor* descriptor) { - return AcquireRef(new Texture(this, descriptor)); + return Texture::Create(this, descriptor); } - ResultOrError Device::CreateTextureViewImpl( + ResultOrError> Device::CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) { - return new TextureView(texture, descriptor); + return TextureView::Create(texture, descriptor); } ExecutionSerial Device::CheckAndUpdateCompletedSerials() { diff --git a/src/dawn_native/metal/PipelineLayoutMTL.h b/src/dawn_native/metal/PipelineLayoutMTL.h index c3ba537541..0a0347d76d 100644 --- a/src/dawn_native/metal/PipelineLayoutMTL.h +++ b/src/dawn_native/metal/PipelineLayoutMTL.h @@ -42,7 +42,8 @@ namespace dawn_native { namespace metal { class PipelineLayout final : public PipelineLayoutBase { public: - PipelineLayout(Device* device, const PipelineLayoutDescriptor* descriptor); + static Ref Create(Device* device, + const PipelineLayoutDescriptor* descriptor); using BindingIndexInfo = ityp::array mIndexInfo; PerStage mBufferBindingCount; diff --git a/src/dawn_native/metal/PipelineLayoutMTL.mm b/src/dawn_native/metal/PipelineLayoutMTL.mm index 3951ef539a..34ddc44f2f 100644 --- a/src/dawn_native/metal/PipelineLayoutMTL.mm +++ b/src/dawn_native/metal/PipelineLayoutMTL.mm @@ -20,6 +20,12 @@ namespace dawn_native { namespace metal { + // static + Ref PipelineLayout::Create(Device* device, + const PipelineLayoutDescriptor* descriptor) { + return AcquireRef(new PipelineLayout(device, descriptor)); + } + PipelineLayout::PipelineLayout(Device* device, const PipelineLayoutDescriptor* descriptor) : PipelineLayoutBase(device, descriptor) { // Each stage has its own numbering namespace in CompilerMSL. diff --git a/src/dawn_native/metal/QuerySetMTL.h b/src/dawn_native/metal/QuerySetMTL.h index b0f84a6241..a7b1ad7fa3 100644 --- a/src/dawn_native/metal/QuerySetMTL.h +++ b/src/dawn_native/metal/QuerySetMTL.h @@ -27,8 +27,8 @@ namespace dawn_native { namespace metal { class QuerySet final : public QuerySetBase { public: - static ResultOrError Create(Device* device, - const QuerySetDescriptor* descriptor); + static ResultOrError> Create(Device* device, + const QuerySetDescriptor* descriptor); id GetVisibilityBuffer() const; id GetCounterSampleBuffer() const diff --git a/src/dawn_native/metal/QuerySetMTL.mm b/src/dawn_native/metal/QuerySetMTL.mm index 472fdf011b..ad9546d7a6 100644 --- a/src/dawn_native/metal/QuerySetMTL.mm +++ b/src/dawn_native/metal/QuerySetMTL.mm @@ -62,11 +62,11 @@ namespace dawn_native { namespace metal { } // static - ResultOrError QuerySet::Create(Device* device, - const QuerySetDescriptor* descriptor) { + ResultOrError> QuerySet::Create(Device* device, + const QuerySetDescriptor* descriptor) { Ref queryset = AcquireRef(new QuerySet(device, descriptor)); DAWN_TRY(queryset->Initialize()); - return queryset.Detach(); + return queryset; } MaybeError QuerySet::Initialize() { diff --git a/src/dawn_native/metal/RenderPipelineMTL.h b/src/dawn_native/metal/RenderPipelineMTL.h index 9b3372bcf0..43eebec365 100644 --- a/src/dawn_native/metal/RenderPipelineMTL.h +++ b/src/dawn_native/metal/RenderPipelineMTL.h @@ -27,8 +27,9 @@ namespace dawn_native { namespace metal { class RenderPipeline final : public RenderPipelineBase { public: - static ResultOrError Create(Device* device, - const RenderPipelineDescriptor* descriptor); + static ResultOrError> Create( + Device* device, + const RenderPipelineDescriptor* descriptor); MTLPrimitiveType GetMTLPrimitiveTopology() const; MTLWinding GetMTLFrontFace() const; diff --git a/src/dawn_native/metal/RenderPipelineMTL.mm b/src/dawn_native/metal/RenderPipelineMTL.mm index b2f6c8f8da..27f7f3e31a 100644 --- a/src/dawn_native/metal/RenderPipelineMTL.mm +++ b/src/dawn_native/metal/RenderPipelineMTL.mm @@ -310,12 +310,12 @@ namespace dawn_native { namespace metal { } // anonymous namespace // static - ResultOrError RenderPipeline::Create( + ResultOrError> RenderPipeline::Create( Device* device, const RenderPipelineDescriptor* descriptor) { Ref pipeline = AcquireRef(new RenderPipeline(device, descriptor)); DAWN_TRY(pipeline->Initialize(descriptor)); - return pipeline.Detach(); + return pipeline; } MaybeError RenderPipeline::Initialize(const RenderPipelineDescriptor* descriptor) { diff --git a/src/dawn_native/metal/SamplerMTL.h b/src/dawn_native/metal/SamplerMTL.h index 535a0c7e43..98565aedf3 100644 --- a/src/dawn_native/metal/SamplerMTL.h +++ b/src/dawn_native/metal/SamplerMTL.h @@ -27,7 +27,8 @@ namespace dawn_native { namespace metal { class Sampler final : public SamplerBase { public: - static ResultOrError Create(Device* device, const SamplerDescriptor* descriptor); + static ResultOrError> Create(Device* device, + const SamplerDescriptor* descriptor); id GetMTLSamplerState(); diff --git a/src/dawn_native/metal/SamplerMTL.mm b/src/dawn_native/metal/SamplerMTL.mm index 34a5b1fe80..f1c477961f 100644 --- a/src/dawn_native/metal/SamplerMTL.mm +++ b/src/dawn_native/metal/SamplerMTL.mm @@ -51,13 +51,14 @@ namespace dawn_native { namespace metal { } // static - ResultOrError Sampler::Create(Device* device, const SamplerDescriptor* descriptor) { + ResultOrError> Sampler::Create(Device* device, + const SamplerDescriptor* descriptor) { if (descriptor->compare != wgpu::CompareFunction::Undefined && device->IsToggleEnabled(Toggle::MetalDisableSamplerCompare)) { return DAWN_VALIDATION_ERROR("Sampler compare function not supported."); } - return new Sampler(device, descriptor); + return AcquireRef(new Sampler(device, descriptor)); } Sampler::Sampler(Device* device, const SamplerDescriptor* descriptor) diff --git a/src/dawn_native/metal/ShaderModuleMTL.h b/src/dawn_native/metal/ShaderModuleMTL.h index 1a4f549cff..e8bd1a94aa 100644 --- a/src/dawn_native/metal/ShaderModuleMTL.h +++ b/src/dawn_native/metal/ShaderModuleMTL.h @@ -34,9 +34,9 @@ namespace dawn_native { namespace metal { class ShaderModule final : public ShaderModuleBase { public: - static ResultOrError Create(Device* device, - const ShaderModuleDescriptor* descriptor, - ShaderModuleParseResult* parseResult); + static ResultOrError> Create(Device* device, + const ShaderModuleDescriptor* descriptor, + ShaderModuleParseResult* parseResult); struct MetalFunctionData { NSPRef> function; diff --git a/src/dawn_native/metal/ShaderModuleMTL.mm b/src/dawn_native/metal/ShaderModuleMTL.mm index fce4300864..c65e0e8195 100644 --- a/src/dawn_native/metal/ShaderModuleMTL.mm +++ b/src/dawn_native/metal/ShaderModuleMTL.mm @@ -34,12 +34,12 @@ namespace dawn_native { namespace metal { // static - ResultOrError ShaderModule::Create(Device* device, - const ShaderModuleDescriptor* descriptor, - ShaderModuleParseResult* parseResult) { + ResultOrError> ShaderModule::Create(Device* device, + const ShaderModuleDescriptor* descriptor, + ShaderModuleParseResult* parseResult) { Ref module = AcquireRef(new ShaderModule(device, descriptor)); DAWN_TRY(module->Initialize(parseResult)); - return module.Detach(); + return module; } ShaderModule::ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor) diff --git a/src/dawn_native/metal/SwapChainMTL.h b/src/dawn_native/metal/SwapChainMTL.h index 11fad51a4e..6a7216ecb0 100644 --- a/src/dawn_native/metal/SwapChainMTL.h +++ b/src/dawn_native/metal/SwapChainMTL.h @@ -29,9 +29,10 @@ namespace dawn_native { namespace metal { class OldSwapChain final : public OldSwapChainBase { public: - OldSwapChain(Device* device, const SwapChainDescriptor* descriptor); + static Ref Create(Device* deivce, const SwapChainDescriptor* descriptor); protected: + OldSwapChain(Device* device, const SwapChainDescriptor* descriptor); ~OldSwapChain() override; TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override; MaybeError OnBeforePresent(TextureViewBase* view) override; @@ -39,10 +40,10 @@ namespace dawn_native { namespace metal { class SwapChain final : public NewSwapChainBase { public: - static ResultOrError Create(Device* device, - Surface* surface, - NewSwapChainBase* previousSwapChain, - const SwapChainDescriptor* descriptor); + static ResultOrError> Create(Device* device, + Surface* surface, + NewSwapChainBase* previousSwapChain, + const SwapChainDescriptor* descriptor); ~SwapChain() override; private: diff --git a/src/dawn_native/metal/SwapChainMTL.mm b/src/dawn_native/metal/SwapChainMTL.mm index 7653634e90..b878893928 100644 --- a/src/dawn_native/metal/SwapChainMTL.mm +++ b/src/dawn_native/metal/SwapChainMTL.mm @@ -26,6 +26,11 @@ namespace dawn_native { namespace metal { // OldSwapChain + // static + Ref OldSwapChain::Create(Device* device, const SwapChainDescriptor* descriptor) { + return AcquireRef(new OldSwapChain(device, descriptor)); + } + OldSwapChain::OldSwapChain(Device* device, const SwapChainDescriptor* descriptor) : OldSwapChainBase(device, descriptor) { const auto& im = GetImplementation(); @@ -58,14 +63,13 @@ namespace dawn_native { namespace metal { // SwapChain // static - ResultOrError SwapChain::Create(Device* device, - Surface* surface, - NewSwapChainBase* previousSwapChain, - const SwapChainDescriptor* descriptor) { - std::unique_ptr swapchain = - std::make_unique(device, surface, descriptor); + ResultOrError> SwapChain::Create(Device* device, + Surface* surface, + NewSwapChainBase* previousSwapChain, + const SwapChainDescriptor* descriptor) { + Ref swapchain = AcquireRef(new SwapChain(device, surface, descriptor)); DAWN_TRY(swapchain->Initialize(previousSwapChain)); - return swapchain.release(); + return swapchain; } SwapChain::~SwapChain() { diff --git a/src/dawn_native/metal/TextureMTL.h b/src/dawn_native/metal/TextureMTL.h index d578446c92..1265a4ecc3 100644 --- a/src/dawn_native/metal/TextureMTL.h +++ b/src/dawn_native/metal/TextureMTL.h @@ -35,7 +35,9 @@ namespace dawn_native { namespace metal { class Texture final : public TextureBase { public: - Texture(Device* device, const TextureDescriptor* descriptor); + static ResultOrError> Create(Device* device, + const TextureDescriptor* descriptor); + Texture(Device* device, const TextureDescriptor* descriptor, NSPRef> mtlTexture); @@ -49,6 +51,7 @@ namespace dawn_native { namespace metal { void EnsureSubresourceContentInitialized(const SubresourceRange& range); private: + Texture(Device* device, const TextureDescriptor* descriptor); ~Texture() override; void DestroyImpl() override; @@ -60,11 +63,14 @@ namespace dawn_native { namespace metal { class TextureView final : public TextureViewBase { public: - TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor); + static ResultOrError> Create(TextureBase* texture, + const TextureViewDescriptor* descriptor); id GetMTLTexture(); private: + TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor); + NSPRef> mMtlTextureView; }; diff --git a/src/dawn_native/metal/TextureMTL.mm b/src/dawn_native/metal/TextureMTL.mm index 49181747f9..29485ba9be 100644 --- a/src/dawn_native/metal/TextureMTL.mm +++ b/src/dawn_native/metal/TextureMTL.mm @@ -346,6 +346,12 @@ namespace dawn_native { namespace metal { return mtlDescRef; } + // static + ResultOrError> Texture::Create(Device* device, + const TextureDescriptor* descriptor) { + return AcquireRef(new Texture(device, descriptor)); + } + Texture::Texture(Device* device, const TextureDescriptor* descriptor) : TextureBase(device, descriptor, TextureState::OwnedInternal) { NSRef mtlDesc = CreateMetalTextureDescriptor(device, descriptor); @@ -600,6 +606,12 @@ namespace dawn_native { namespace metal { } } + // static + ResultOrError> TextureView::Create(TextureBase* texture, + const TextureViewDescriptor* descriptor) { + return AcquireRef(new TextureView(texture, descriptor)); + } + TextureView::TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor) : TextureViewBase(texture, descriptor) { id mtlTexture = ToBackend(texture)->GetMTLTexture(); diff --git a/src/dawn_native/null/DeviceNull.cpp b/src/dawn_native/null/DeviceNull.cpp index 23dbe2032f..a6ee029f84 100644 --- a/src/dawn_native/null/DeviceNull.cpp +++ b/src/dawn_native/null/DeviceNull.cpp @@ -92,52 +92,54 @@ namespace dawn_native { namespace null { return DeviceBase::Initialize(new Queue(this)); } - ResultOrError Device::CreateBindGroupImpl( + ResultOrError> Device::CreateBindGroupImpl( const BindGroupDescriptor* descriptor) { - return new BindGroup(this, descriptor); + return AcquireRef(new BindGroup(this, descriptor)); } - ResultOrError Device::CreateBindGroupLayoutImpl( + ResultOrError> Device::CreateBindGroupLayoutImpl( const BindGroupLayoutDescriptor* descriptor) { - return new BindGroupLayout(this, descriptor); + return AcquireRef(new BindGroupLayout(this, descriptor)); } ResultOrError> Device::CreateBufferImpl(const BufferDescriptor* descriptor) { DAWN_TRY(IncrementMemoryUsage(descriptor->size)); return AcquireRef(new Buffer(this, descriptor)); } - CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder, - const CommandBufferDescriptor* descriptor) { - return new CommandBuffer(encoder, descriptor); + ResultOrError> Device::CreateCommandBuffer( + CommandEncoder* encoder, + const CommandBufferDescriptor* descriptor) { + return AcquireRef(new CommandBuffer(encoder, descriptor)); } - ResultOrError Device::CreateComputePipelineImpl( + ResultOrError> Device::CreateComputePipelineImpl( const ComputePipelineDescriptor* descriptor) { - return new ComputePipeline(this, descriptor); + return AcquireRef(new ComputePipeline(this, descriptor)); } - ResultOrError Device::CreatePipelineLayoutImpl( + ResultOrError> Device::CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) { - return new PipelineLayout(this, descriptor); + return AcquireRef(new PipelineLayout(this, descriptor)); } - ResultOrError Device::CreateQuerySetImpl(const QuerySetDescriptor* descriptor) { - return new QuerySet(this, descriptor); + ResultOrError> Device::CreateQuerySetImpl( + const QuerySetDescriptor* descriptor) { + return AcquireRef(new QuerySet(this, descriptor)); } - ResultOrError Device::CreateRenderPipelineImpl( + ResultOrError> Device::CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) { - return new RenderPipeline(this, descriptor); + return AcquireRef(new RenderPipeline(this, descriptor)); } - ResultOrError Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) { - return new Sampler(this, descriptor); + ResultOrError> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) { + return AcquireRef(new Sampler(this, descriptor)); } - ResultOrError Device::CreateShaderModuleImpl( + ResultOrError> Device::CreateShaderModuleImpl( const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult) { Ref module = AcquireRef(new ShaderModule(this, descriptor)); DAWN_TRY(module->Initialize(parseResult)); - return module.Detach(); + return module; } - ResultOrError Device::CreateSwapChainImpl( + ResultOrError> Device::CreateSwapChainImpl( const SwapChainDescriptor* descriptor) { - return new OldSwapChain(this, descriptor); + return AcquireRef(new OldSwapChain(this, descriptor)); } - ResultOrError Device::CreateSwapChainImpl( + ResultOrError> Device::CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, const SwapChainDescriptor* descriptor) { @@ -146,10 +148,10 @@ namespace dawn_native { namespace null { ResultOrError> Device::CreateTextureImpl(const TextureDescriptor* descriptor) { return AcquireRef(new Texture(this, descriptor, TextureBase::TextureState::OwnedInternal)); } - ResultOrError Device::CreateTextureViewImpl( + ResultOrError> Device::CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) { - return new TextureView(texture, descriptor); + return AcquireRef(new TextureView(texture, descriptor)); } ResultOrError> Device::CreateStagingBuffer(size_t size) { @@ -355,14 +357,13 @@ namespace dawn_native { namespace null { // SwapChain // static - ResultOrError SwapChain::Create(Device* device, - Surface* surface, - NewSwapChainBase* previousSwapChain, - const SwapChainDescriptor* descriptor) { - std::unique_ptr swapchain = - std::make_unique(device, surface, descriptor); + ResultOrError> SwapChain::Create(Device* device, + Surface* surface, + NewSwapChainBase* previousSwapChain, + const SwapChainDescriptor* descriptor) { + Ref swapchain = AcquireRef(new SwapChain(device, surface, descriptor)); DAWN_TRY(swapchain->Initialize(previousSwapChain)); - return swapchain.release(); + return swapchain; } MaybeError SwapChain::Initialize(NewSwapChainBase* previousSwapChain) { diff --git a/src/dawn_native/null/DeviceNull.h b/src/dawn_native/null/DeviceNull.h index 7cc08df949..75680db3c3 100644 --- a/src/dawn_native/null/DeviceNull.h +++ b/src/dawn_native/null/DeviceNull.h @@ -91,8 +91,9 @@ namespace dawn_native { namespace null { MaybeError Initialize(); - CommandBufferBase* CreateCommandBuffer(CommandEncoder* encoder, - const CommandBufferDescriptor* descriptor) override; + ResultOrError> CreateCommandBuffer( + CommandEncoder* encoder, + const CommandBufferDescriptor* descriptor) override; MaybeError TickImpl() override; @@ -121,33 +122,34 @@ namespace dawn_native { namespace null { private: using DeviceBase::DeviceBase; - ResultOrError CreateBindGroupImpl( + ResultOrError> CreateBindGroupImpl( const BindGroupDescriptor* descriptor) override; - ResultOrError CreateBindGroupLayoutImpl( + ResultOrError> CreateBindGroupLayoutImpl( const BindGroupLayoutDescriptor* descriptor) override; ResultOrError> CreateBufferImpl( const BufferDescriptor* descriptor) override; - ResultOrError CreateComputePipelineImpl( + ResultOrError> CreateComputePipelineImpl( const ComputePipelineDescriptor* descriptor) override; - ResultOrError CreatePipelineLayoutImpl( + ResultOrError> CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) override; - ResultOrError CreateQuerySetImpl( + ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) override; - ResultOrError CreateRenderPipelineImpl( + ResultOrError> CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) override; - ResultOrError CreateSamplerImpl(const SamplerDescriptor* descriptor) override; - ResultOrError CreateShaderModuleImpl( + ResultOrError> CreateSamplerImpl( + const SamplerDescriptor* descriptor) override; + ResultOrError> CreateShaderModuleImpl( const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult) override; - ResultOrError CreateSwapChainImpl( + ResultOrError> CreateSwapChainImpl( const SwapChainDescriptor* descriptor) override; - ResultOrError CreateSwapChainImpl( + ResultOrError> CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, const SwapChainDescriptor* descriptor) override; ResultOrError> CreateTextureImpl( const TextureDescriptor* descriptor) override; - ResultOrError CreateTextureViewImpl( + ResultOrError> CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) override; @@ -254,10 +256,10 @@ namespace dawn_native { namespace null { class SwapChain final : public NewSwapChainBase { public: - static ResultOrError Create(Device* device, - Surface* surface, - NewSwapChainBase* previousSwapChain, - const SwapChainDescriptor* descriptor); + static ResultOrError> Create(Device* device, + Surface* surface, + NewSwapChainBase* previousSwapChain, + const SwapChainDescriptor* descriptor); ~SwapChain() override; private: diff --git a/src/dawn_native/opengl/BindGroupGL.cpp b/src/dawn_native/opengl/BindGroupGL.cpp index 486eb2c51b..721189b9db 100644 --- a/src/dawn_native/opengl/BindGroupGL.cpp +++ b/src/dawn_native/opengl/BindGroupGL.cpp @@ -54,7 +54,7 @@ namespace dawn_native { namespace opengl { } // static - BindGroup* BindGroup::Create(Device* device, const BindGroupDescriptor* descriptor) { + Ref BindGroup::Create(Device* device, const BindGroupDescriptor* descriptor) { return ToBackend(descriptor->layout)->AllocateBindGroup(device, descriptor); } diff --git a/src/dawn_native/opengl/BindGroupGL.h b/src/dawn_native/opengl/BindGroupGL.h index 5544a492dd..0619cf185d 100644 --- a/src/dawn_native/opengl/BindGroupGL.h +++ b/src/dawn_native/opengl/BindGroupGL.h @@ -26,9 +26,9 @@ namespace dawn_native { namespace opengl { class BindGroup final : public BindGroupBase, public PlacementAllocated { public: - BindGroup(Device* device, const BindGroupDescriptor* descriptor); + static Ref Create(Device* device, const BindGroupDescriptor* descriptor); - static BindGroup* Create(Device* device, const BindGroupDescriptor* descriptor); + BindGroup(Device* device, const BindGroupDescriptor* descriptor); private: ~BindGroup() override; diff --git a/src/dawn_native/opengl/BindGroupLayoutGL.cpp b/src/dawn_native/opengl/BindGroupLayoutGL.cpp index 7c098c8700..619e4e62ee 100644 --- a/src/dawn_native/opengl/BindGroupLayoutGL.cpp +++ b/src/dawn_native/opengl/BindGroupLayoutGL.cpp @@ -24,9 +24,9 @@ namespace dawn_native { namespace opengl { mBindGroupAllocator(MakeFrontendBindGroupAllocator(4096)) { } - BindGroup* BindGroupLayout::AllocateBindGroup(Device* device, - const BindGroupDescriptor* descriptor) { - return mBindGroupAllocator.Allocate(device, descriptor); + Ref BindGroupLayout::AllocateBindGroup(Device* device, + const BindGroupDescriptor* descriptor) { + return AcquireRef(mBindGroupAllocator.Allocate(device, descriptor)); } void BindGroupLayout::DeallocateBindGroup(BindGroup* bindGroup) { diff --git a/src/dawn_native/opengl/BindGroupLayoutGL.h b/src/dawn_native/opengl/BindGroupLayoutGL.h index aeba62f54c..edd1dd050b 100644 --- a/src/dawn_native/opengl/BindGroupLayoutGL.h +++ b/src/dawn_native/opengl/BindGroupLayoutGL.h @@ -27,7 +27,7 @@ namespace dawn_native { namespace opengl { public: BindGroupLayout(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor); - BindGroup* AllocateBindGroup(Device* device, const BindGroupDescriptor* descriptor); + Ref AllocateBindGroup(Device* device, const BindGroupDescriptor* descriptor); void DeallocateBindGroup(BindGroup* bindGroup); private: diff --git a/src/dawn_native/opengl/DeviceGL.cpp b/src/dawn_native/opengl/DeviceGL.cpp index ef7be64d3e..994590ec72 100644 --- a/src/dawn_native/opengl/DeviceGL.cpp +++ b/src/dawn_native/opengl/DeviceGL.cpp @@ -110,50 +110,52 @@ namespace dawn_native { namespace opengl { return result; } - ResultOrError Device::CreateBindGroupImpl( + ResultOrError> Device::CreateBindGroupImpl( const BindGroupDescriptor* descriptor) { DAWN_TRY(ValidateGLBindGroupDescriptor(descriptor)); return BindGroup::Create(this, descriptor); } - ResultOrError Device::CreateBindGroupLayoutImpl( + ResultOrError> Device::CreateBindGroupLayoutImpl( const BindGroupLayoutDescriptor* descriptor) { - return new BindGroupLayout(this, descriptor); + return AcquireRef(new BindGroupLayout(this, descriptor)); } ResultOrError> Device::CreateBufferImpl(const BufferDescriptor* descriptor) { return AcquireRef(new Buffer(this, descriptor)); } - CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder, - const CommandBufferDescriptor* descriptor) { - return new CommandBuffer(encoder, descriptor); + ResultOrError> Device::CreateCommandBuffer( + CommandEncoder* encoder, + const CommandBufferDescriptor* descriptor) { + return AcquireRef(new CommandBuffer(encoder, descriptor)); } - ResultOrError Device::CreateComputePipelineImpl( + ResultOrError> Device::CreateComputePipelineImpl( const ComputePipelineDescriptor* descriptor) { - return new ComputePipeline(this, descriptor); + return AcquireRef(new ComputePipeline(this, descriptor)); } - ResultOrError Device::CreatePipelineLayoutImpl( + ResultOrError> Device::CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) { - return new PipelineLayout(this, descriptor); + return AcquireRef(new PipelineLayout(this, descriptor)); } - ResultOrError Device::CreateQuerySetImpl(const QuerySetDescriptor* descriptor) { - return new QuerySet(this, descriptor); + ResultOrError> Device::CreateQuerySetImpl( + const QuerySetDescriptor* descriptor) { + return AcquireRef(new QuerySet(this, descriptor)); } - ResultOrError Device::CreateRenderPipelineImpl( + ResultOrError> Device::CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) { - return new RenderPipeline(this, descriptor); + return AcquireRef(new RenderPipeline(this, descriptor)); } - ResultOrError Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) { - return new Sampler(this, descriptor); + ResultOrError> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) { + return AcquireRef(new Sampler(this, descriptor)); } - ResultOrError Device::CreateShaderModuleImpl( + ResultOrError> Device::CreateShaderModuleImpl( const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult) { return ShaderModule::Create(this, descriptor, parseResult); } - ResultOrError Device::CreateSwapChainImpl( + ResultOrError> Device::CreateSwapChainImpl( const SwapChainDescriptor* descriptor) { - return new SwapChain(this, descriptor); + return AcquireRef(new SwapChain(this, descriptor)); } - ResultOrError Device::CreateSwapChainImpl( + ResultOrError> Device::CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, const SwapChainDescriptor* descriptor) { @@ -162,10 +164,10 @@ namespace dawn_native { namespace opengl { ResultOrError> Device::CreateTextureImpl(const TextureDescriptor* descriptor) { return AcquireRef(new Texture(this, descriptor)); } - ResultOrError Device::CreateTextureViewImpl( + ResultOrError> Device::CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) { - return new TextureView(texture, descriptor); + return AcquireRef(new TextureView(texture, descriptor)); } void Device::SubmitFenceSync() { diff --git a/src/dawn_native/opengl/DeviceGL.h b/src/dawn_native/opengl/DeviceGL.h index f463aff2aa..7069cae2cf 100644 --- a/src/dawn_native/opengl/DeviceGL.h +++ b/src/dawn_native/opengl/DeviceGL.h @@ -49,9 +49,9 @@ namespace dawn_native { namespace opengl { void SubmitFenceSync(); - // Dawn API - CommandBufferBase* CreateCommandBuffer(CommandEncoder* encoder, - const CommandBufferDescriptor* descriptor) override; + ResultOrError> CreateCommandBuffer( + CommandEncoder* encoder, + const CommandBufferDescriptor* descriptor) override; MaybeError TickImpl() override; @@ -77,33 +77,34 @@ namespace dawn_native { namespace opengl { const DeviceDescriptor* descriptor, const OpenGLFunctions& functions); - ResultOrError CreateBindGroupImpl( + ResultOrError> CreateBindGroupImpl( const BindGroupDescriptor* descriptor) override; - ResultOrError CreateBindGroupLayoutImpl( + ResultOrError> CreateBindGroupLayoutImpl( const BindGroupLayoutDescriptor* descriptor) override; ResultOrError> CreateBufferImpl( const BufferDescriptor* descriptor) override; - ResultOrError CreateComputePipelineImpl( + ResultOrError> CreateComputePipelineImpl( const ComputePipelineDescriptor* descriptor) override; - ResultOrError CreatePipelineLayoutImpl( + ResultOrError> CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) override; - ResultOrError CreateQuerySetImpl( + ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) override; - ResultOrError CreateRenderPipelineImpl( + ResultOrError> CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) override; - ResultOrError CreateSamplerImpl(const SamplerDescriptor* descriptor) override; - ResultOrError CreateShaderModuleImpl( + ResultOrError> CreateSamplerImpl( + const SamplerDescriptor* descriptor) override; + ResultOrError> CreateShaderModuleImpl( const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult) override; - ResultOrError CreateSwapChainImpl( + ResultOrError> CreateSwapChainImpl( const SwapChainDescriptor* descriptor) override; - ResultOrError CreateSwapChainImpl( + ResultOrError> CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, const SwapChainDescriptor* descriptor) override; ResultOrError> CreateTextureImpl( const TextureDescriptor* descriptor) override; - ResultOrError CreateTextureViewImpl( + ResultOrError> CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) override; diff --git a/src/dawn_native/opengl/PipelineGL.cpp b/src/dawn_native/opengl/PipelineGL.cpp index c40d25d55f..a0181efafe 100644 --- a/src/dawn_native/opengl/PipelineGL.cpp +++ b/src/dawn_native/opengl/PipelineGL.cpp @@ -99,8 +99,8 @@ namespace dawn_native { namespace opengl { ASSERT(desc.minFilter == wgpu::FilterMode::Nearest); ASSERT(desc.magFilter == wgpu::FilterMode::Nearest); ASSERT(desc.mipmapFilter == wgpu::FilterMode::Nearest); - mDummySampler = AcquireRef( - ToBackend(layout->GetDevice()->GetOrCreateSampler(&desc).AcquireSuccess())); + mDummySampler = + ToBackend(layout->GetDevice()->GetOrCreateSampler(&desc).AcquireSuccess()); } // Link all the shaders together. diff --git a/src/dawn_native/opengl/ShaderModuleGL.cpp b/src/dawn_native/opengl/ShaderModuleGL.cpp index c4d060a696..596984d986 100644 --- a/src/dawn_native/opengl/ShaderModuleGL.cpp +++ b/src/dawn_native/opengl/ShaderModuleGL.cpp @@ -65,12 +65,12 @@ namespace dawn_native { namespace opengl { } // static - ResultOrError ShaderModule::Create(Device* device, - const ShaderModuleDescriptor* descriptor, - ShaderModuleParseResult* parseResult) { + ResultOrError> ShaderModule::Create(Device* device, + const ShaderModuleDescriptor* descriptor, + ShaderModuleParseResult* parseResult) { Ref module = AcquireRef(new ShaderModule(device, descriptor)); DAWN_TRY(module->Initialize(parseResult)); - return module.Detach(); + return module; } ShaderModule::ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor) diff --git a/src/dawn_native/opengl/ShaderModuleGL.h b/src/dawn_native/opengl/ShaderModuleGL.h index 371c415e9a..eebab35e97 100644 --- a/src/dawn_native/opengl/ShaderModuleGL.h +++ b/src/dawn_native/opengl/ShaderModuleGL.h @@ -46,9 +46,9 @@ namespace dawn_native { namespace opengl { class ShaderModule final : public ShaderModuleBase { public: - static ResultOrError Create(Device* device, - const ShaderModuleDescriptor* descriptor, - ShaderModuleParseResult* parseResult); + static ResultOrError> Create(Device* device, + const ShaderModuleDescriptor* descriptor, + ShaderModuleParseResult* parseResult); std::string TranslateToGLSL(const char* entryPointName, SingleShaderStage stage, diff --git a/src/dawn_native/vulkan/BindGroupLayoutVk.cpp b/src/dawn_native/vulkan/BindGroupLayoutVk.cpp index 9bb379bde0..700e850318 100644 --- a/src/dawn_native/vulkan/BindGroupLayoutVk.cpp +++ b/src/dawn_native/vulkan/BindGroupLayoutVk.cpp @@ -74,12 +74,12 @@ namespace dawn_native { namespace vulkan { } // static - ResultOrError BindGroupLayout::Create( + ResultOrError> BindGroupLayout::Create( Device* device, const BindGroupLayoutDescriptor* descriptor) { Ref bgl = AcquireRef(new BindGroupLayout(device, descriptor)); DAWN_TRY(bgl->Initialize()); - return bgl.Detach(); + return bgl; } MaybeError BindGroupLayout::Initialize() { @@ -158,13 +158,14 @@ namespace dawn_native { namespace vulkan { return mHandle; } - ResultOrError BindGroupLayout::AllocateBindGroup( + ResultOrError> BindGroupLayout::AllocateBindGroup( Device* device, const BindGroupDescriptor* descriptor) { DescriptorSetAllocation descriptorSetAllocation; DAWN_TRY_ASSIGN(descriptorSetAllocation, mDescriptorSetAllocator->Allocate()); - return mBindGroupAllocator.Allocate(device, descriptor, descriptorSetAllocation); + return AcquireRef( + mBindGroupAllocator.Allocate(device, descriptor, descriptorSetAllocation)); } void BindGroupLayout::DeallocateBindGroup(BindGroup* bindGroup, diff --git a/src/dawn_native/vulkan/BindGroupLayoutVk.h b/src/dawn_native/vulkan/BindGroupLayoutVk.h index 394cfab162..72f8b698d7 100644 --- a/src/dawn_native/vulkan/BindGroupLayoutVk.h +++ b/src/dawn_native/vulkan/BindGroupLayoutVk.h @@ -45,15 +45,16 @@ namespace dawn_native { namespace vulkan { // expensive syscall. class BindGroupLayout final : public BindGroupLayoutBase { public: - static ResultOrError Create(Device* device, - const BindGroupLayoutDescriptor* descriptor); + static ResultOrError> Create( + Device* device, + const BindGroupLayoutDescriptor* descriptor); BindGroupLayout(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor); VkDescriptorSetLayout GetHandle() const; - ResultOrError AllocateBindGroup(Device* device, - const BindGroupDescriptor* descriptor); + ResultOrError> AllocateBindGroup(Device* device, + const BindGroupDescriptor* descriptor); void DeallocateBindGroup(BindGroup* bindGroup, DescriptorSetAllocation* descriptorSetAllocation); void FinishDeallocation(ExecutionSerial completedSerial); diff --git a/src/dawn_native/vulkan/BindGroupVk.cpp b/src/dawn_native/vulkan/BindGroupVk.cpp index f7dd72f962..07653e8bf5 100644 --- a/src/dawn_native/vulkan/BindGroupVk.cpp +++ b/src/dawn_native/vulkan/BindGroupVk.cpp @@ -27,8 +27,8 @@ namespace dawn_native { namespace vulkan { // static - ResultOrError BindGroup::Create(Device* device, - const BindGroupDescriptor* descriptor) { + ResultOrError> BindGroup::Create(Device* device, + const BindGroupDescriptor* descriptor) { return ToBackend(descriptor->layout)->AllocateBindGroup(device, descriptor); } diff --git a/src/dawn_native/vulkan/BindGroupVk.h b/src/dawn_native/vulkan/BindGroupVk.h index 411c114940..dac780bf0b 100644 --- a/src/dawn_native/vulkan/BindGroupVk.h +++ b/src/dawn_native/vulkan/BindGroupVk.h @@ -28,8 +28,8 @@ namespace dawn_native { namespace vulkan { class BindGroup final : public BindGroupBase, public PlacementAllocated { public: - static ResultOrError Create(Device* device, - const BindGroupDescriptor* descriptor); + static ResultOrError> Create(Device* device, + const BindGroupDescriptor* descriptor); BindGroup(Device* device, const BindGroupDescriptor* descriptor, diff --git a/src/dawn_native/vulkan/CommandBufferVk.cpp b/src/dawn_native/vulkan/CommandBufferVk.cpp index ed2ca188e7..0986db8fc7 100644 --- a/src/dawn_native/vulkan/CommandBufferVk.cpp +++ b/src/dawn_native/vulkan/CommandBufferVk.cpp @@ -433,9 +433,9 @@ namespace dawn_native { namespace vulkan { } // anonymous namespace // static - CommandBuffer* CommandBuffer::Create(CommandEncoder* encoder, - const CommandBufferDescriptor* descriptor) { - return new CommandBuffer(encoder, descriptor); + Ref CommandBuffer::Create(CommandEncoder* encoder, + const CommandBufferDescriptor* descriptor) { + return AcquireRef(new CommandBuffer(encoder, descriptor)); } CommandBuffer::CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor) diff --git a/src/dawn_native/vulkan/CommandBufferVk.h b/src/dawn_native/vulkan/CommandBufferVk.h index c5476d38ad..edc35ff128 100644 --- a/src/dawn_native/vulkan/CommandBufferVk.h +++ b/src/dawn_native/vulkan/CommandBufferVk.h @@ -32,8 +32,8 @@ namespace dawn_native { namespace vulkan { class CommandBuffer final : public CommandBufferBase { public: - static CommandBuffer* Create(CommandEncoder* encoder, - const CommandBufferDescriptor* descriptor); + static Ref Create(CommandEncoder* encoder, + const CommandBufferDescriptor* descriptor); MaybeError RecordCommands(CommandRecordingContext* recordingContext); diff --git a/src/dawn_native/vulkan/ComputePipelineVk.cpp b/src/dawn_native/vulkan/ComputePipelineVk.cpp index b4e1c3016f..a81dee9039 100644 --- a/src/dawn_native/vulkan/ComputePipelineVk.cpp +++ b/src/dawn_native/vulkan/ComputePipelineVk.cpp @@ -24,12 +24,12 @@ namespace dawn_native { namespace vulkan { // static - ResultOrError ComputePipeline::Create( + ResultOrError> ComputePipeline::Create( Device* device, const ComputePipelineDescriptor* descriptor) { Ref pipeline = AcquireRef(new ComputePipeline(device, descriptor)); DAWN_TRY(pipeline->Initialize(descriptor)); - return pipeline.Detach(); + return pipeline; } MaybeError ComputePipeline::Initialize(const ComputePipelineDescriptor* descriptor) { diff --git a/src/dawn_native/vulkan/ComputePipelineVk.h b/src/dawn_native/vulkan/ComputePipelineVk.h index 6aa98a4ef8..bd1fc04279 100644 --- a/src/dawn_native/vulkan/ComputePipelineVk.h +++ b/src/dawn_native/vulkan/ComputePipelineVk.h @@ -26,8 +26,9 @@ namespace dawn_native { namespace vulkan { class ComputePipeline final : public ComputePipelineBase { public: - static ResultOrError Create(Device* device, - const ComputePipelineDescriptor* descriptor); + static ResultOrError> Create( + Device* device, + const ComputePipelineDescriptor* descriptor); VkPipeline GetHandle() const; diff --git a/src/dawn_native/vulkan/DeviceVk.cpp b/src/dawn_native/vulkan/DeviceVk.cpp index 6985c7fd33..aa6d85df5e 100644 --- a/src/dawn_native/vulkan/DeviceVk.cpp +++ b/src/dawn_native/vulkan/DeviceVk.cpp @@ -102,49 +102,51 @@ namespace dawn_native { namespace vulkan { ShutDownBase(); } - ResultOrError Device::CreateBindGroupImpl( + ResultOrError> Device::CreateBindGroupImpl( const BindGroupDescriptor* descriptor) { return BindGroup::Create(this, descriptor); } - ResultOrError Device::CreateBindGroupLayoutImpl( + ResultOrError> Device::CreateBindGroupLayoutImpl( const BindGroupLayoutDescriptor* descriptor) { return BindGroupLayout::Create(this, descriptor); } ResultOrError> Device::CreateBufferImpl(const BufferDescriptor* descriptor) { return Buffer::Create(this, descriptor); } - CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder, - const CommandBufferDescriptor* descriptor) { + ResultOrError> Device::CreateCommandBuffer( + CommandEncoder* encoder, + const CommandBufferDescriptor* descriptor) { return CommandBuffer::Create(encoder, descriptor); } - ResultOrError Device::CreateComputePipelineImpl( + ResultOrError> Device::CreateComputePipelineImpl( const ComputePipelineDescriptor* descriptor) { return ComputePipeline::Create(this, descriptor); } - ResultOrError Device::CreatePipelineLayoutImpl( + ResultOrError> Device::CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) { return PipelineLayout::Create(this, descriptor); } - ResultOrError Device::CreateQuerySetImpl(const QuerySetDescriptor* descriptor) { + ResultOrError> Device::CreateQuerySetImpl( + const QuerySetDescriptor* descriptor) { return QuerySet::Create(this, descriptor); } - ResultOrError Device::CreateRenderPipelineImpl( + ResultOrError> Device::CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) { return RenderPipeline::Create(this, descriptor); } - ResultOrError Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) { + ResultOrError> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) { return Sampler::Create(this, descriptor); } - ResultOrError Device::CreateShaderModuleImpl( + ResultOrError> Device::CreateShaderModuleImpl( const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult) { return ShaderModule::Create(this, descriptor, parseResult); } - ResultOrError Device::CreateSwapChainImpl( + ResultOrError> Device::CreateSwapChainImpl( const SwapChainDescriptor* descriptor) { return OldSwapChain::Create(this, descriptor); } - ResultOrError Device::CreateSwapChainImpl( + ResultOrError> Device::CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, const SwapChainDescriptor* descriptor) { @@ -153,7 +155,7 @@ namespace dawn_native { namespace vulkan { ResultOrError> Device::CreateTextureImpl(const TextureDescriptor* descriptor) { return Texture::Create(this, descriptor); } - ResultOrError Device::CreateTextureViewImpl( + ResultOrError> Device::CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) { return TextureView::Create(texture, descriptor); diff --git a/src/dawn_native/vulkan/DeviceVk.h b/src/dawn_native/vulkan/DeviceVk.h index e28c1b9109..870dc4702b 100644 --- a/src/dawn_native/vulkan/DeviceVk.h +++ b/src/dawn_native/vulkan/DeviceVk.h @@ -77,9 +77,9 @@ namespace dawn_native { namespace vulkan { ExternalImageExportInfoVk* info, std::vector* semaphoreHandle); - // Dawn API - CommandBufferBase* CreateCommandBuffer(CommandEncoder* encoder, - const CommandBufferDescriptor* descriptor) override; + ResultOrError> CreateCommandBuffer( + CommandEncoder* encoder, + const CommandBufferDescriptor* descriptor) override; MaybeError TickImpl() override; @@ -114,33 +114,34 @@ namespace dawn_native { namespace vulkan { private: Device(Adapter* adapter, const DeviceDescriptor* descriptor); - ResultOrError CreateBindGroupImpl( + ResultOrError> CreateBindGroupImpl( const BindGroupDescriptor* descriptor) override; - ResultOrError CreateBindGroupLayoutImpl( + ResultOrError> CreateBindGroupLayoutImpl( const BindGroupLayoutDescriptor* descriptor) override; ResultOrError> CreateBufferImpl( const BufferDescriptor* descriptor) override; - ResultOrError CreateComputePipelineImpl( + ResultOrError> CreateComputePipelineImpl( const ComputePipelineDescriptor* descriptor) override; - ResultOrError CreatePipelineLayoutImpl( + ResultOrError> CreatePipelineLayoutImpl( const PipelineLayoutDescriptor* descriptor) override; - ResultOrError CreateQuerySetImpl( + ResultOrError> CreateQuerySetImpl( const QuerySetDescriptor* descriptor) override; - ResultOrError CreateRenderPipelineImpl( + ResultOrError> CreateRenderPipelineImpl( const RenderPipelineDescriptor* descriptor) override; - ResultOrError CreateSamplerImpl(const SamplerDescriptor* descriptor) override; - ResultOrError CreateShaderModuleImpl( + ResultOrError> CreateSamplerImpl( + const SamplerDescriptor* descriptor) override; + ResultOrError> CreateShaderModuleImpl( const ShaderModuleDescriptor* descriptor, ShaderModuleParseResult* parseResult) override; - ResultOrError CreateSwapChainImpl( + ResultOrError> CreateSwapChainImpl( const SwapChainDescriptor* descriptor) override; - ResultOrError CreateSwapChainImpl( + ResultOrError> CreateSwapChainImpl( Surface* surface, NewSwapChainBase* previousSwapChain, const SwapChainDescriptor* descriptor) override; ResultOrError> CreateTextureImpl( const TextureDescriptor* descriptor) override; - ResultOrError CreateTextureViewImpl( + ResultOrError> CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) override; diff --git a/src/dawn_native/vulkan/PipelineLayoutVk.cpp b/src/dawn_native/vulkan/PipelineLayoutVk.cpp index 80c5aa833e..2aff50d921 100644 --- a/src/dawn_native/vulkan/PipelineLayoutVk.cpp +++ b/src/dawn_native/vulkan/PipelineLayoutVk.cpp @@ -23,12 +23,12 @@ namespace dawn_native { namespace vulkan { // static - ResultOrError PipelineLayout::Create( + ResultOrError> PipelineLayout::Create( Device* device, const PipelineLayoutDescriptor* descriptor) { Ref layout = AcquireRef(new PipelineLayout(device, descriptor)); DAWN_TRY(layout->Initialize()); - return layout.Detach(); + return layout; } MaybeError PipelineLayout::Initialize() { diff --git a/src/dawn_native/vulkan/PipelineLayoutVk.h b/src/dawn_native/vulkan/PipelineLayoutVk.h index fe136e4d0d..c96215f6b7 100644 --- a/src/dawn_native/vulkan/PipelineLayoutVk.h +++ b/src/dawn_native/vulkan/PipelineLayoutVk.h @@ -26,8 +26,9 @@ namespace dawn_native { namespace vulkan { class PipelineLayout final : public PipelineLayoutBase { public: - static ResultOrError Create(Device* device, - const PipelineLayoutDescriptor* descriptor); + static ResultOrError> Create( + Device* device, + const PipelineLayoutDescriptor* descriptor); VkPipelineLayout GetHandle() const; diff --git a/src/dawn_native/vulkan/QuerySetVk.cpp b/src/dawn_native/vulkan/QuerySetVk.cpp index c74ef7c7b8..27f6ab629b 100644 --- a/src/dawn_native/vulkan/QuerySetVk.cpp +++ b/src/dawn_native/vulkan/QuerySetVk.cpp @@ -64,11 +64,11 @@ namespace dawn_native { namespace vulkan { } // anonymous namespace // static - ResultOrError QuerySet::Create(Device* device, - const QuerySetDescriptor* descriptor) { + ResultOrError> QuerySet::Create(Device* device, + const QuerySetDescriptor* descriptor) { Ref queryset = AcquireRef(new QuerySet(device, descriptor)); DAWN_TRY(queryset->Initialize()); - return queryset.Detach(); + return queryset; } MaybeError QuerySet::Initialize() { diff --git a/src/dawn_native/vulkan/QuerySetVk.h b/src/dawn_native/vulkan/QuerySetVk.h index 18cd001290..80e7befa1d 100644 --- a/src/dawn_native/vulkan/QuerySetVk.h +++ b/src/dawn_native/vulkan/QuerySetVk.h @@ -25,8 +25,8 @@ namespace dawn_native { namespace vulkan { class QuerySet final : public QuerySetBase { public: - static ResultOrError Create(Device* device, - const QuerySetDescriptor* descriptor); + static ResultOrError> Create(Device* device, + const QuerySetDescriptor* descriptor); VkQueryPool GetHandle() const; diff --git a/src/dawn_native/vulkan/RenderPipelineVk.cpp b/src/dawn_native/vulkan/RenderPipelineVk.cpp index 2438fde6df..105e640fc5 100644 --- a/src/dawn_native/vulkan/RenderPipelineVk.cpp +++ b/src/dawn_native/vulkan/RenderPipelineVk.cpp @@ -319,12 +319,12 @@ namespace dawn_native { namespace vulkan { } // anonymous namespace // static - ResultOrError RenderPipeline::Create( + ResultOrError> RenderPipeline::Create( Device* device, const RenderPipelineDescriptor* descriptor) { Ref pipeline = AcquireRef(new RenderPipeline(device, descriptor)); DAWN_TRY(pipeline->Initialize(descriptor)); - return pipeline.Detach(); + return pipeline; } MaybeError RenderPipeline::Initialize(const RenderPipelineDescriptor* descriptor) { diff --git a/src/dawn_native/vulkan/RenderPipelineVk.h b/src/dawn_native/vulkan/RenderPipelineVk.h index 4613f322c3..7dfc468187 100644 --- a/src/dawn_native/vulkan/RenderPipelineVk.h +++ b/src/dawn_native/vulkan/RenderPipelineVk.h @@ -26,8 +26,9 @@ namespace dawn_native { namespace vulkan { class RenderPipeline final : public RenderPipelineBase { public: - static ResultOrError Create(Device* device, - const RenderPipelineDescriptor* descriptor); + static ResultOrError> Create( + Device* device, + const RenderPipelineDescriptor* descriptor); VkPipeline GetHandle() const; diff --git a/src/dawn_native/vulkan/SamplerVk.cpp b/src/dawn_native/vulkan/SamplerVk.cpp index 033f7b769a..c5e852b5e9 100644 --- a/src/dawn_native/vulkan/SamplerVk.cpp +++ b/src/dawn_native/vulkan/SamplerVk.cpp @@ -53,10 +53,11 @@ namespace dawn_native { namespace vulkan { } // anonymous namespace // static - ResultOrError Sampler::Create(Device* device, const SamplerDescriptor* descriptor) { + ResultOrError> Sampler::Create(Device* device, + const SamplerDescriptor* descriptor) { Ref sampler = AcquireRef(new Sampler(device, descriptor)); DAWN_TRY(sampler->Initialize(descriptor)); - return sampler.Detach(); + return sampler; } MaybeError Sampler::Initialize(const SamplerDescriptor* descriptor) { diff --git a/src/dawn_native/vulkan/SamplerVk.h b/src/dawn_native/vulkan/SamplerVk.h index 72f7d79b15..ac7b886a3e 100644 --- a/src/dawn_native/vulkan/SamplerVk.h +++ b/src/dawn_native/vulkan/SamplerVk.h @@ -26,7 +26,8 @@ namespace dawn_native { namespace vulkan { class Sampler final : public SamplerBase { public: - static ResultOrError Create(Device* device, const SamplerDescriptor* descriptor); + static ResultOrError> Create(Device* device, + const SamplerDescriptor* descriptor); VkSampler GetHandle() const; diff --git a/src/dawn_native/vulkan/ShaderModuleVk.cpp b/src/dawn_native/vulkan/ShaderModuleVk.cpp index 5fddba2a84..01ed4bf072 100644 --- a/src/dawn_native/vulkan/ShaderModuleVk.cpp +++ b/src/dawn_native/vulkan/ShaderModuleVk.cpp @@ -30,15 +30,12 @@ namespace dawn_native { namespace vulkan { // static - ResultOrError ShaderModule::Create(Device* device, - const ShaderModuleDescriptor* descriptor, - ShaderModuleParseResult* parseResult) { + ResultOrError> ShaderModule::Create(Device* device, + const ShaderModuleDescriptor* descriptor, + ShaderModuleParseResult* parseResult) { Ref module = AcquireRef(new ShaderModule(device, descriptor)); - if (module == nullptr) { - return DAWN_VALIDATION_ERROR("Unable to create ShaderModule"); - } DAWN_TRY(module->Initialize(parseResult)); - return module.Detach(); + return module; } ShaderModule::ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor) diff --git a/src/dawn_native/vulkan/ShaderModuleVk.h b/src/dawn_native/vulkan/ShaderModuleVk.h index 621ab0e939..7c0d8ef841 100644 --- a/src/dawn_native/vulkan/ShaderModuleVk.h +++ b/src/dawn_native/vulkan/ShaderModuleVk.h @@ -26,9 +26,9 @@ namespace dawn_native { namespace vulkan { class ShaderModule final : public ShaderModuleBase { public: - static ResultOrError Create(Device* device, - const ShaderModuleDescriptor* descriptor, - ShaderModuleParseResult* parseResult); + static ResultOrError> Create(Device* device, + const ShaderModuleDescriptor* descriptor, + ShaderModuleParseResult* parseResult); VkShaderModule GetHandle() const; diff --git a/src/dawn_native/vulkan/SwapChainVk.cpp b/src/dawn_native/vulkan/SwapChainVk.cpp index a8cd00e2c3..29c2454d04 100644 --- a/src/dawn_native/vulkan/SwapChainVk.cpp +++ b/src/dawn_native/vulkan/SwapChainVk.cpp @@ -35,8 +35,8 @@ namespace dawn_native { namespace vulkan { // OldSwapChain // static - OldSwapChain* OldSwapChain::Create(Device* device, const SwapChainDescriptor* descriptor) { - return new OldSwapChain(device, descriptor); + Ref OldSwapChain::Create(Device* device, const SwapChainDescriptor* descriptor) { + return AcquireRef(new OldSwapChain(device, descriptor)); } OldSwapChain::OldSwapChain(Device* device, const SwapChainDescriptor* descriptor) @@ -211,14 +211,13 @@ namespace dawn_native { namespace vulkan { } // anonymous namespace // static - ResultOrError SwapChain::Create(Device* device, - Surface* surface, - NewSwapChainBase* previousSwapChain, - const SwapChainDescriptor* descriptor) { - std::unique_ptr swapchain = - std::make_unique(device, surface, descriptor); + ResultOrError> SwapChain::Create(Device* device, + Surface* surface, + NewSwapChainBase* previousSwapChain, + const SwapChainDescriptor* descriptor) { + Ref swapchain = AcquireRef(new SwapChain(device, surface, descriptor)); DAWN_TRY(swapchain->Initialize(previousSwapChain)); - return swapchain.release(); + return swapchain; } SwapChain::~SwapChain() { diff --git a/src/dawn_native/vulkan/SwapChainVk.h b/src/dawn_native/vulkan/SwapChainVk.h index 24c6a5cd7d..2210379090 100644 --- a/src/dawn_native/vulkan/SwapChainVk.h +++ b/src/dawn_native/vulkan/SwapChainVk.h @@ -29,7 +29,7 @@ namespace dawn_native { namespace vulkan { class OldSwapChain : public OldSwapChainBase { public: - static OldSwapChain* Create(Device* device, const SwapChainDescriptor* descriptor); + static Ref Create(Device* device, const SwapChainDescriptor* descriptor); protected: OldSwapChain(Device* device, const SwapChainDescriptor* descriptor); @@ -44,10 +44,10 @@ namespace dawn_native { namespace vulkan { class SwapChain : public NewSwapChainBase { public: - static ResultOrError Create(Device* device, - Surface* surface, - NewSwapChainBase* previousSwapChain, - const SwapChainDescriptor* descriptor); + static ResultOrError> Create(Device* device, + Surface* surface, + NewSwapChainBase* previousSwapChain, + const SwapChainDescriptor* descriptor); ~SwapChain() override; private: diff --git a/src/dawn_native/vulkan/TextureVk.cpp b/src/dawn_native/vulkan/TextureVk.cpp index 28f9499f7e..59e753fd83 100644 --- a/src/dawn_native/vulkan/TextureVk.cpp +++ b/src/dawn_native/vulkan/TextureVk.cpp @@ -1162,11 +1162,11 @@ namespace dawn_native { namespace vulkan { } // static - ResultOrError TextureView::Create(TextureBase* texture, - const TextureViewDescriptor* descriptor) { + ResultOrError> TextureView::Create(TextureBase* texture, + const TextureViewDescriptor* descriptor) { Ref view = AcquireRef(new TextureView(texture, descriptor)); DAWN_TRY(view->Initialize(descriptor)); - return view.Detach(); + return view; } MaybeError TextureView::Initialize(const TextureViewDescriptor* descriptor) { diff --git a/src/dawn_native/vulkan/TextureVk.h b/src/dawn_native/vulkan/TextureVk.h index 9af6701198..013a3b6217 100644 --- a/src/dawn_native/vulkan/TextureVk.h +++ b/src/dawn_native/vulkan/TextureVk.h @@ -167,8 +167,8 @@ namespace dawn_native { namespace vulkan { class TextureView final : public TextureViewBase { public: - static ResultOrError Create(TextureBase* texture, - const TextureViewDescriptor* descriptor); + static ResultOrError> Create(TextureBase* texture, + const TextureViewDescriptor* descriptor); VkImageView GetHandle() const; private: