From 6331f959c18aa9b634e97d8a134b39ba5af28d73 Mon Sep 17 00:00:00 2001 From: Loko Kung Date: Wed, 1 Dec 2021 18:54:40 +0000 Subject: [PATCH] Refactors Destroy to be upward calls instead of overriding. - Fixes all class and implementations to call upwards when necessary. - Makes DestroyImpl full virtual at ApiObjectBase. - Fixes mock classes to call default DestroyImpl upwards on mock calls. - Adds back D3D12 optimization for buffer destruction. Bug: dawn:628, dawn:1189 Change-Id: Id2c2c6483dc7ed93daf8e4648af26ac1307e3d90 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/71243 Commit-Queue: Loko Kung Reviewed-by: Austin Eng --- src/dawn_native/BindGroup.cpp | 3 +++ src/dawn_native/BindGroup.h | 1 + src/dawn_native/BindGroupLayout.cpp | 8 +++----- src/dawn_native/BindGroupLayout.h | 2 +- src/dawn_native/Buffer.cpp | 14 +------------- src/dawn_native/Buffer.h | 2 +- src/dawn_native/CommandBuffer.h | 3 +-- src/dawn_native/ComputePassEncoder.cpp | 1 - src/dawn_native/ComputePipeline.cpp | 8 +++----- src/dawn_native/ComputePipeline.h | 2 +- src/dawn_native/ExternalTexture.cpp | 3 +-- src/dawn_native/ExternalTexture.h | 2 +- src/dawn_native/ObjectBase.cpp | 13 ++----------- src/dawn_native/ObjectBase.h | 19 +++++++------------ src/dawn_native/PipelineLayout.cpp | 8 +++----- src/dawn_native/PipelineLayout.h | 2 +- src/dawn_native/QuerySet.cpp | 3 +-- src/dawn_native/QuerySet.h | 2 +- src/dawn_native/Queue.cpp | 3 +++ src/dawn_native/Queue.h | 1 + src/dawn_native/RenderPipeline.cpp | 8 +++----- src/dawn_native/RenderPipeline.h | 2 +- src/dawn_native/Sampler.cpp | 8 +++----- src/dawn_native/Sampler.h | 2 +- src/dawn_native/ShaderModule.cpp | 8 +++----- src/dawn_native/ShaderModule.h | 2 +- src/dawn_native/SwapChain.cpp | 3 +++ src/dawn_native/SwapChain.h | 1 + src/dawn_native/Texture.cpp | 11 ++++------- src/dawn_native/Texture.h | 3 ++- src/dawn_native/d3d12/BindGroupD3D12.cpp | 1 + src/dawn_native/d3d12/BufferD3D12.cpp | 10 ++++++++-- .../d3d12/ComputePipelineD3D12.cpp | 1 + src/dawn_native/d3d12/QuerySetD3D12.cpp | 1 + src/dawn_native/d3d12/RenderPipelineD3D12.cpp | 1 + src/dawn_native/d3d12/SwapChainD3D12.cpp | 1 + src/dawn_native/d3d12/TextureD3D12.cpp | 2 ++ src/dawn_native/metal/BindGroupMTL.mm | 1 + src/dawn_native/metal/BufferMTL.mm | 1 + src/dawn_native/metal/QuerySetMTL.mm | 2 ++ src/dawn_native/metal/SwapChainMTL.mm | 1 + src/dawn_native/metal/TextureMTL.mm | 1 + src/dawn_native/null/DeviceNull.cpp | 4 +--- src/dawn_native/null/DeviceNull.h | 3 --- src/dawn_native/opengl/BindGroupGL.cpp | 1 + src/dawn_native/opengl/BufferGL.cpp | 1 + src/dawn_native/opengl/ComputePipelineGL.cpp | 1 + src/dawn_native/opengl/QuerySetGL.cpp | 3 --- src/dawn_native/opengl/QuerySetGL.h | 2 -- src/dawn_native/opengl/RenderPipelineGL.cpp | 1 + src/dawn_native/opengl/SamplerGL.cpp | 1 + src/dawn_native/opengl/TextureGL.cpp | 2 ++ src/dawn_native/vulkan/BindGroupLayoutVk.cpp | 2 ++ src/dawn_native/vulkan/BindGroupVk.cpp | 1 + src/dawn_native/vulkan/BufferVk.cpp | 2 ++ src/dawn_native/vulkan/ComputePipelineVk.cpp | 2 ++ src/dawn_native/vulkan/PipelineLayoutVk.cpp | 1 + src/dawn_native/vulkan/QuerySetVk.cpp | 1 + src/dawn_native/vulkan/RenderPipelineVk.cpp | 1 + src/dawn_native/vulkan/SamplerVk.cpp | 1 + src/dawn_native/vulkan/ShaderModuleVk.cpp | 1 + src/dawn_native/vulkan/SwapChainVk.cpp | 1 + src/dawn_native/vulkan/TextureVk.cpp | 3 +++ .../unittests/native/DestroyObjectTests.cpp | 4 ++-- .../native/mocks/BindGroupLayoutMock.h | 3 +++ .../unittests/native/mocks/BindGroupMock.h | 3 +++ src/tests/unittests/native/mocks/BufferMock.h | 3 +++ .../native/mocks/CommandBufferMock.h | 3 +++ .../native/mocks/ComputePipelineMock.h | 3 +++ .../native/mocks/ExternalTextureMock.h | 3 +++ .../native/mocks/PipelineLayoutMock.h | 3 +++ .../unittests/native/mocks/QuerySetMock.h | 3 +++ .../native/mocks/RenderPipelineMock.h | 3 +++ .../unittests/native/mocks/SamplerMock.h | 3 +++ .../native/mocks/ShaderModuleMock.cpp | 6 ++++++ .../unittests/native/mocks/ShaderModuleMock.h | 3 +-- .../unittests/native/mocks/SwapChainMock.h | 3 +++ .../unittests/native/mocks/TextureMock.h | 3 +++ 78 files changed, 148 insertions(+), 107 deletions(-) diff --git a/src/dawn_native/BindGroup.cpp b/src/dawn_native/BindGroup.cpp index a92a183e90..d81ffc084d 100644 --- a/src/dawn_native/BindGroup.cpp +++ b/src/dawn_native/BindGroup.cpp @@ -408,6 +408,9 @@ namespace dawn_native { } } + void BindGroupBase::DestroyImpl() { + } + void BindGroupBase::DeleteThis() { // Add another ref to the layout so that if this is the last ref, the layout // is destroyed after the bind group. The bind group is slab-allocated inside diff --git a/src/dawn_native/BindGroup.h b/src/dawn_native/BindGroup.h index 6792d619b9..6b687ce14d 100644 --- a/src/dawn_native/BindGroup.h +++ b/src/dawn_native/BindGroup.h @@ -75,6 +75,7 @@ namespace dawn_native { // Constructor used only for mocking and testing. BindGroupBase(DeviceBase* device); + void DestroyImpl() override; ~BindGroupBase() override; diff --git a/src/dawn_native/BindGroupLayout.cpp b/src/dawn_native/BindGroupLayout.cpp index 3a1fdea7d9..f6687cbd68 100644 --- a/src/dawn_native/BindGroupLayout.cpp +++ b/src/dawn_native/BindGroupLayout.cpp @@ -418,13 +418,11 @@ namespace dawn_native { BindGroupLayoutBase::~BindGroupLayoutBase() = default; - bool BindGroupLayoutBase::Destroy() { - bool wasDestroyed = ApiObjectBase::Destroy(); - if (wasDestroyed && IsCachedReference()) { - // Do not uncache the actual cached object if we are a blueprint or already destroyed. + void BindGroupLayoutBase::DestroyImpl() { + if (IsCachedReference()) { + // Do not uncache the actual cached object if we are a blueprint. GetDevice()->UncacheBindGroupLayout(this); } - return wasDestroyed; } // static diff --git a/src/dawn_native/BindGroupLayout.h b/src/dawn_native/BindGroupLayout.h index 14ca4e29ca..6749adbb18 100644 --- a/src/dawn_native/BindGroupLayout.h +++ b/src/dawn_native/BindGroupLayout.h @@ -53,7 +53,6 @@ namespace dawn_native { static BindGroupLayoutBase* MakeError(DeviceBase* device); - bool Destroy() override; ObjectType GetType() const override; // A map from the BindingNumber to its packed BindingIndex. @@ -118,6 +117,7 @@ namespace dawn_native { protected: // Constructor used only for mocking and testing. BindGroupLayoutBase(DeviceBase* device); + void DestroyImpl() override; template SlabAllocator MakeFrontendBindGroupAllocator(size_t size) { diff --git a/src/dawn_native/Buffer.cpp b/src/dawn_native/Buffer.cpp index 4565df4c9f..929af7a0d2 100644 --- a/src/dawn_native/Buffer.cpp +++ b/src/dawn_native/Buffer.cpp @@ -91,10 +91,6 @@ namespace dawn_native { mFakeMappedData.reset(); } - void DestroyImpl() override { - mFakeMappedData.reset(); - } - std::unique_ptr mFakeMappedData; }; @@ -183,12 +179,7 @@ namespace dawn_native { ASSERT(mState == BufferState::Unmapped || mState == BufferState::Destroyed); } - bool BufferBase::Destroy() { - bool marked = MarkDestroyed(); - if (!marked) { - return false; - } - + void BufferBase::DestroyImpl() { if (mState == BufferState::Mapped) { UnmapInternal(WGPUBufferMapAsyncStatus_DestroyedBeforeCallback); } else if (mState == BufferState::MappedAtCreation) { @@ -198,10 +189,7 @@ namespace dawn_native { UnmapInternal(WGPUBufferMapAsyncStatus_DestroyedBeforeCallback); } } - - DestroyImpl(); mState = BufferState::Destroyed; - return true; } // static diff --git a/src/dawn_native/Buffer.h b/src/dawn_native/Buffer.h index 505c87397c..b794bd522c 100644 --- a/src/dawn_native/Buffer.h +++ b/src/dawn_native/Buffer.h @@ -52,7 +52,6 @@ namespace dawn_native { static BufferBase* MakeError(DeviceBase* device, const BufferDescriptor* descriptor); - bool Destroy() override; ObjectType GetType() const override; uint64_t GetSize() const; @@ -89,6 +88,7 @@ namespace dawn_native { // Constructor used only for mocking and testing. BufferBase(DeviceBase* device, BufferState state); + void DestroyImpl() override; ~BufferBase() override; diff --git a/src/dawn_native/CommandBuffer.h b/src/dawn_native/CommandBuffer.h index b728ddf94c..a8c23a6a9c 100644 --- a/src/dawn_native/CommandBuffer.h +++ b/src/dawn_native/CommandBuffer.h @@ -47,14 +47,13 @@ namespace dawn_native { protected: // Constructor used only for mocking and testing. CommandBufferBase(DeviceBase* device); + void DestroyImpl() override; CommandIterator mCommands; private: CommandBufferBase(DeviceBase* device, ObjectBase::ErrorTag tag); - void DestroyImpl() override; - CommandBufferResourceUsage mResourceUsages; }; diff --git a/src/dawn_native/ComputePassEncoder.cpp b/src/dawn_native/ComputePassEncoder.cpp index 92e5f62822..383186892e 100644 --- a/src/dawn_native/ComputePassEncoder.cpp +++ b/src/dawn_native/ComputePassEncoder.cpp @@ -133,7 +133,6 @@ namespace dawn_native { } void ComputePassEncoder::DestroyImpl() { - ApiObjectBase::DestroyImpl(); // Ensure that the pass has exited. This is done for passes only since validation requires // they exit before destruction while bundles do not. mEncodingContext->EnsurePassExited(this); diff --git a/src/dawn_native/ComputePipeline.cpp b/src/dawn_native/ComputePipeline.cpp index 68bbf165e8..b6c1766aed 100644 --- a/src/dawn_native/ComputePipeline.cpp +++ b/src/dawn_native/ComputePipeline.cpp @@ -60,13 +60,11 @@ namespace dawn_native { ComputePipelineBase::~ComputePipelineBase() = default; - bool ComputePipelineBase::Destroy() { - bool wasDestroyed = ApiObjectBase::Destroy(); - if (wasDestroyed && IsCachedReference()) { - // Do not uncache the actual cached object if we are a blueprint or already destroyed. + void ComputePipelineBase::DestroyImpl() { + if (IsCachedReference()) { + // Do not uncache the actual cached object if we are a blueprint. GetDevice()->UncacheComputePipeline(this); } - return wasDestroyed; } // static diff --git a/src/dawn_native/ComputePipeline.h b/src/dawn_native/ComputePipeline.h index fdeb902491..28d5ed9d6c 100644 --- a/src/dawn_native/ComputePipeline.h +++ b/src/dawn_native/ComputePipeline.h @@ -34,7 +34,6 @@ namespace dawn_native { static ComputePipelineBase* MakeError(DeviceBase* device); - bool Destroy() override; ObjectType GetType() const override; // Functors necessary for the unordered_set-based cache. @@ -45,6 +44,7 @@ namespace dawn_native { protected: // Constructor used only for mocking and testing. ComputePipelineBase(DeviceBase* device); + void DestroyImpl() override; private: ComputePipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag); diff --git a/src/dawn_native/ExternalTexture.cpp b/src/dawn_native/ExternalTexture.cpp index bba9c0b504..14a9e1dbbb 100644 --- a/src/dawn_native/ExternalTexture.cpp +++ b/src/dawn_native/ExternalTexture.cpp @@ -122,9 +122,8 @@ namespace dawn_native { Destroy(); } - bool ExternalTextureBase::Destroy() { + void ExternalTextureBase::DestroyImpl() { mState = ExternalTextureState::Destroyed; - return ApiObjectBase::Destroy(); } // static diff --git a/src/dawn_native/ExternalTexture.h b/src/dawn_native/ExternalTexture.h index 94b8ef2323..e8596fb8e6 100644 --- a/src/dawn_native/ExternalTexture.h +++ b/src/dawn_native/ExternalTexture.h @@ -42,7 +42,6 @@ namespace dawn_native { static ExternalTextureBase* MakeError(DeviceBase* device); - bool Destroy() override; ObjectType GetType() const override; void APIDestroy(); @@ -50,6 +49,7 @@ namespace dawn_native { protected: // Constructor used only for mocking and testing. ExternalTextureBase(DeviceBase* device); + void DestroyImpl() override; private: enum class ExternalTextureState { Alive, Destroyed }; diff --git a/src/dawn_native/ObjectBase.cpp b/src/dawn_native/ObjectBase.cpp index ee87702aa5..c6f091a974 100644 --- a/src/dawn_native/ObjectBase.cpp +++ b/src/dawn_native/ObjectBase.cpp @@ -80,20 +80,11 @@ namespace dawn_native { GetDevice()->TrackObject(this); } - bool ApiObjectBase::MarkDestroyed() { + void ApiObjectBase::Destroy() { const std::lock_guard lock(*GetDevice()->GetObjectListMutex(GetType())); - return RemoveFromList(); - } - - bool ApiObjectBase::Destroy() { - bool marked = MarkDestroyed(); - if (marked) { + if (RemoveFromList()) { DestroyImpl(); } - return marked; - } - - void ApiObjectBase::DestroyImpl() { } } // namespace dawn_native diff --git a/src/dawn_native/ObjectBase.h b/src/dawn_native/ObjectBase.h index c234da03e3..5c91628748 100644 --- a/src/dawn_native/ObjectBase.h +++ b/src/dawn_native/ObjectBase.h @@ -60,12 +60,8 @@ namespace dawn_native { // by the owning device. bool IsAlive() const; - // Allow virtual overriding of actual destroy call in order to allow for re-using of base - // destruction oerations. Classes that override this function should almost always call this - // class's implementation in the override. This needs to be public because it can be called - // from the device owning the object. Returns true iff destruction occurs. Upon any re-calls - // of the function it will return false to indicate no further operations should be taken. - virtual bool Destroy(); + // This needs to be public because it can be called from the device owning the object. + void Destroy(); // Dawn API void APISetLabel(const char* label); @@ -84,12 +80,11 @@ namespace dawn_native { void DeleteThis() override; void TrackInDevice(); - // Thread-safe manner to mark an object as destroyed. Returns true iff the call was the - // "winning" attempt to destroy the object. This is useful when sub-classes may have extra - // pre-destruction steps that need to occur only once, i.e. Buffer needs to be unmapped - // before being destroyed. - bool MarkDestroyed(); - virtual void DestroyImpl(); + // Sub-classes may override this function multiple times. Whenever overriding this function, + // however, users should be sure to call their parent's version in the new override to make + // sure that all destroy functionality is kept. This function is guaranteed to only be + // called once through the exposed Destroy function. + virtual void DestroyImpl() = 0; private: virtual void SetLabelImpl(); diff --git a/src/dawn_native/PipelineLayout.cpp b/src/dawn_native/PipelineLayout.cpp index 153e95342a..2851695c2c 100644 --- a/src/dawn_native/PipelineLayout.cpp +++ b/src/dawn_native/PipelineLayout.cpp @@ -85,13 +85,11 @@ namespace dawn_native { PipelineLayoutBase::~PipelineLayoutBase() = default; - bool PipelineLayoutBase::Destroy() { - bool wasDestroyed = ApiObjectBase::Destroy(); - if (wasDestroyed && IsCachedReference()) { - // Do not uncache the actual cached object if we are a blueprint + void PipelineLayoutBase::DestroyImpl() { + if (IsCachedReference()) { + // Do not uncache the actual cached object if we are a blueprint. GetDevice()->UncachePipelineLayout(this); } - return wasDestroyed; } // static diff --git a/src/dawn_native/PipelineLayout.h b/src/dawn_native/PipelineLayout.h index 1e4d87386c..948b3446a7 100644 --- a/src/dawn_native/PipelineLayout.h +++ b/src/dawn_native/PipelineLayout.h @@ -61,7 +61,6 @@ namespace dawn_native { DeviceBase* device, std::vector stages); - bool Destroy() override; ObjectType GetType() const override; const BindGroupLayoutBase* GetBindGroupLayout(BindGroupIndex group) const; @@ -87,6 +86,7 @@ namespace dawn_native { // Constructor used only for mocking and testing. PipelineLayoutBase(DeviceBase* device); PipelineLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag); + void DestroyImpl() override; BindGroupLayoutArray mBindGroupLayouts; BindGroupLayoutMask mMask; diff --git a/src/dawn_native/QuerySet.cpp b/src/dawn_native/QuerySet.cpp index a46ffc06f9..fbe385629c 100644 --- a/src/dawn_native/QuerySet.cpp +++ b/src/dawn_native/QuerySet.cpp @@ -126,9 +126,8 @@ namespace dawn_native { ASSERT(mState == QuerySetState::Unavailable || mState == QuerySetState::Destroyed); } - bool QuerySetBase::Destroy() { + void QuerySetBase::DestroyImpl() { mState = QuerySetState::Destroyed; - return ApiObjectBase::Destroy(); } // static diff --git a/src/dawn_native/QuerySet.h b/src/dawn_native/QuerySet.h index 08e0b7426e..58ebc1a926 100644 --- a/src/dawn_native/QuerySet.h +++ b/src/dawn_native/QuerySet.h @@ -31,7 +31,6 @@ namespace dawn_native { static QuerySetBase* MakeError(DeviceBase* device); - bool Destroy() override; ObjectType GetType() const override; wgpu::QueryType GetQueryType() const; @@ -50,6 +49,7 @@ namespace dawn_native { // Constructor used only for mocking and testing. QuerySetBase(DeviceBase* device); + void DestroyImpl() override; ~QuerySetBase() override; diff --git a/src/dawn_native/Queue.cpp b/src/dawn_native/Queue.cpp index 644ce17548..44adbcf31f 100644 --- a/src/dawn_native/Queue.cpp +++ b/src/dawn_native/Queue.cpp @@ -173,6 +173,9 @@ namespace dawn_native { ASSERT(mTasksInFlight.Empty()); } + void QueueBase::DestroyImpl() { + } + // static QueueBase* QueueBase::MakeError(DeviceBase* device) { return new ErrorQueue(device); diff --git a/src/dawn_native/Queue.h b/src/dawn_native/Queue.h index 4c76f181c9..204a4ae0a9 100644 --- a/src/dawn_native/Queue.h +++ b/src/dawn_native/Queue.h @@ -69,6 +69,7 @@ namespace dawn_native { protected: QueueBase(DeviceBase* device); QueueBase(DeviceBase* device, ObjectBase::ErrorTag tag); + void DestroyImpl() override; private: MaybeError WriteTextureInternal(const ImageCopyTexture* destination, diff --git a/src/dawn_native/RenderPipeline.cpp b/src/dawn_native/RenderPipeline.cpp index 7e6c1883be..7b0884d54a 100644 --- a/src/dawn_native/RenderPipeline.cpp +++ b/src/dawn_native/RenderPipeline.cpp @@ -683,17 +683,15 @@ namespace dawn_native { RenderPipelineBase::~RenderPipelineBase() = default; - bool RenderPipelineBase::Destroy() { - bool wasDestroyed = ApiObjectBase::Destroy(); - if (wasDestroyed && IsCachedReference()) { - // Do not uncache the actual cached object if we are a blueprint or already destroyed. + void RenderPipelineBase::DestroyImpl() { + if (IsCachedReference()) { + // Do not uncache the actual cached object if we are a blueprint. GetDevice()->UncacheRenderPipeline(this); } // Remove reference to the attachment state so that we don't have lingering references to // it preventing it from being uncached in the device. mAttachmentState = nullptr; - return wasDestroyed; } // static diff --git a/src/dawn_native/RenderPipeline.h b/src/dawn_native/RenderPipeline.h index 083188ebfd..f09ca84760 100644 --- a/src/dawn_native/RenderPipeline.h +++ b/src/dawn_native/RenderPipeline.h @@ -63,7 +63,6 @@ namespace dawn_native { static RenderPipelineBase* MakeError(DeviceBase* device); - bool Destroy() override; ObjectType GetType() const override; const ityp::bitset& @@ -111,6 +110,7 @@ namespace dawn_native { protected: // Constructor used only for mocking and testing. RenderPipelineBase(DeviceBase* device); + void DestroyImpl() override; private: RenderPipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag); diff --git a/src/dawn_native/Sampler.cpp b/src/dawn_native/Sampler.cpp index 4be3cc8d4b..12ab8cb2b2 100644 --- a/src/dawn_native/Sampler.cpp +++ b/src/dawn_native/Sampler.cpp @@ -100,13 +100,11 @@ namespace dawn_native { SamplerBase::~SamplerBase() = default; - bool SamplerBase::Destroy() { - bool wasDestroyed = ApiObjectBase::Destroy(); - if (wasDestroyed && IsCachedReference()) { - // Do not uncache the actual cached object if we are a blueprint or already destroyed. + void SamplerBase::DestroyImpl() { + if (IsCachedReference()) { + // Do not uncache the actual cached object if we are a blueprint. GetDevice()->UncacheSampler(this); } - return wasDestroyed; } // static diff --git a/src/dawn_native/Sampler.h b/src/dawn_native/Sampler.h index 97cc4cca1f..0116d47c9e 100644 --- a/src/dawn_native/Sampler.h +++ b/src/dawn_native/Sampler.h @@ -38,7 +38,6 @@ namespace dawn_native { static SamplerBase* MakeError(DeviceBase* device); - bool Destroy() override; ObjectType GetType() const override; bool IsComparison() const; @@ -58,6 +57,7 @@ namespace dawn_native { protected: // Constructor used only for mocking and testing. SamplerBase(DeviceBase* device); + void DestroyImpl() override; private: SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag); diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp index d1168f5c14..c0e29e8401 100644 --- a/src/dawn_native/ShaderModule.cpp +++ b/src/dawn_native/ShaderModule.cpp @@ -1204,13 +1204,11 @@ namespace dawn_native { ShaderModuleBase::~ShaderModuleBase() = default; - bool ShaderModuleBase::Destroy() { - bool wasDestroyed = ApiObjectBase::Destroy(); - if (wasDestroyed && IsCachedReference()) { - // Do not uncache the actual cached object if we are a blueprint or already destroyed. + void ShaderModuleBase::DestroyImpl() { + if (IsCachedReference()) { + // Do not uncache the actual cached object if we are a blueprint. GetDevice()->UncacheShaderModule(this); } - return wasDestroyed; } // static diff --git a/src/dawn_native/ShaderModule.h b/src/dawn_native/ShaderModule.h index 660f925ffa..4625ae888b 100644 --- a/src/dawn_native/ShaderModule.h +++ b/src/dawn_native/ShaderModule.h @@ -250,7 +250,6 @@ namespace dawn_native { static Ref MakeError(DeviceBase* device); - bool Destroy() override; ObjectType GetType() const override; // Return true iff the program has an entrypoint called `entryPoint`. @@ -279,6 +278,7 @@ namespace dawn_native { protected: // Constructor used only for mocking and testing. ShaderModuleBase(DeviceBase* device); + void DestroyImpl() override; MaybeError InitializeBase(ShaderModuleParseResult* parseResult); diff --git a/src/dawn_native/SwapChain.cpp b/src/dawn_native/SwapChain.cpp index 26617b1a51..20ee991b84 100644 --- a/src/dawn_native/SwapChain.cpp +++ b/src/dawn_native/SwapChain.cpp @@ -125,6 +125,9 @@ namespace dawn_native { SwapChainBase::~SwapChainBase() { } + void SwapChainBase::DestroyImpl() { + } + // static SwapChainBase* SwapChainBase::MakeError(DeviceBase* device) { return new ErrorSwapChain(device); diff --git a/src/dawn_native/SwapChain.h b/src/dawn_native/SwapChain.h index 4a70431c3b..bb88045062 100644 --- a/src/dawn_native/SwapChain.h +++ b/src/dawn_native/SwapChain.h @@ -49,6 +49,7 @@ namespace dawn_native { protected: SwapChainBase(DeviceBase* device, ObjectBase::ErrorTag tag); ~SwapChainBase() override; + void DestroyImpl() override; }; // The base class for implementation-based SwapChains that are deprecated. diff --git a/src/dawn_native/Texture.cpp b/src/dawn_native/Texture.cpp index b3895a2880..97a6a9dd6c 100644 --- a/src/dawn_native/Texture.cpp +++ b/src/dawn_native/Texture.cpp @@ -483,14 +483,8 @@ namespace dawn_native { : ApiObjectBase(device, tag), mFormat(kUnusedFormat) { } - bool TextureBase::Destroy() { - // We need to run the destroy operations prior to setting the state to destroyed so that - // the state is both consistent, and implementations of the destroy that may check the - // state do not skip operations unintentionally. (Example in Vulkan backend, the destroy - // implementation will not be ran if we are already in the Destroyed state.) - bool wasDestroyed = ApiObjectBase::Destroy(); + void TextureBase::DestroyImpl() { mState = TextureState::Destroyed; - return wasDestroyed; } // static @@ -718,6 +712,9 @@ namespace dawn_native { : ApiObjectBase(device, tag), mFormat(kUnusedFormat) { } + void TextureViewBase::DestroyImpl() { + } + // static TextureViewBase* TextureViewBase::MakeError(DeviceBase* device) { return new TextureViewBase(device, ObjectBase::kError); diff --git a/src/dawn_native/Texture.h b/src/dawn_native/Texture.h index dee515bbbd..145d7f3acf 100644 --- a/src/dawn_native/Texture.h +++ b/src/dawn_native/Texture.h @@ -51,7 +51,6 @@ namespace dawn_native { static TextureBase* MakeError(DeviceBase* device); - bool Destroy() override; ObjectType GetType() const override; wgpu::TextureDimension GetDimension() const; @@ -99,6 +98,7 @@ namespace dawn_native { protected: // Constructor used only for mocking and testing. TextureBase(DeviceBase* device, TextureState state); + void DestroyImpl() override; private: TextureBase(DeviceBase* device, ObjectBase::ErrorTag tag); @@ -140,6 +140,7 @@ namespace dawn_native { protected: // Constructor used only for mocking and testing. TextureViewBase(TextureBase* texture); + void DestroyImpl() override; private: TextureViewBase(DeviceBase* device, ObjectBase::ErrorTag tag); diff --git a/src/dawn_native/d3d12/BindGroupD3D12.cpp b/src/dawn_native/d3d12/BindGroupD3D12.cpp index 39dc1d4166..20822408f3 100644 --- a/src/dawn_native/d3d12/BindGroupD3D12.cpp +++ b/src/dawn_native/d3d12/BindGroupD3D12.cpp @@ -222,6 +222,7 @@ namespace dawn_native { namespace d3d12 { BindGroup::~BindGroup() = default; void BindGroup::DestroyImpl() { + BindGroupBase::DestroyImpl(); ToBackend(GetLayout())->DeallocateBindGroup(this, &mCPUViewAllocation); ASSERT(!mCPUViewAllocation.IsValid()); } diff --git a/src/dawn_native/d3d12/BufferD3D12.cpp b/src/dawn_native/d3d12/BufferD3D12.cpp index 7233150238..a0275fe5dd 100644 --- a/src/dawn_native/d3d12/BufferD3D12.cpp +++ b/src/dawn_native/d3d12/BufferD3D12.cpp @@ -379,8 +379,14 @@ namespace dawn_native { namespace d3d12 { } void Buffer::DestroyImpl() { - // TODO(crbug.com/dawn/1189) Reintroduce optimization to skip flushing the writes to the GPU - // memory when we unmap in destruction case since the buffer will be destroyed anyways. + if (mMappedData != nullptr) { + // If the buffer is currently mapped, unmap without flushing the writes to the GPU + // since the buffer cannot be used anymore. UnmapImpl checks mWrittenRange to know + // which parts to flush, so we set it to an empty range to prevent flushes. + mWrittenMappedRange = {0, 0}; + } + BufferBase::DestroyImpl(); + ToBackend(GetDevice())->DeallocateMemory(mResourceAllocation); } diff --git a/src/dawn_native/d3d12/ComputePipelineD3D12.cpp b/src/dawn_native/d3d12/ComputePipelineD3D12.cpp index b6037ddd7b..82579f321a 100644 --- a/src/dawn_native/d3d12/ComputePipelineD3D12.cpp +++ b/src/dawn_native/d3d12/ComputePipelineD3D12.cpp @@ -69,6 +69,7 @@ namespace dawn_native { namespace d3d12 { ComputePipeline::~ComputePipeline() = default; void ComputePipeline::DestroyImpl() { + ComputePipelineBase::DestroyImpl(); ToBackend(GetDevice())->ReferenceUntilUnused(mPipelineState); } diff --git a/src/dawn_native/d3d12/QuerySetD3D12.cpp b/src/dawn_native/d3d12/QuerySetD3D12.cpp index 11ef463150..d6a618086d 100644 --- a/src/dawn_native/d3d12/QuerySetD3D12.cpp +++ b/src/dawn_native/d3d12/QuerySetD3D12.cpp @@ -63,6 +63,7 @@ namespace dawn_native { namespace d3d12 { QuerySet::~QuerySet() = default; void QuerySet::DestroyImpl() { + QuerySetBase::DestroyImpl(); ToBackend(GetDevice())->ReferenceUntilUnused(mQueryHeap); mQueryHeap = nullptr; } diff --git a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp index de90d1d55c..410d36f85d 100644 --- a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp +++ b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp @@ -425,6 +425,7 @@ namespace dawn_native { namespace d3d12 { RenderPipeline::~RenderPipeline() = default; void RenderPipeline::DestroyImpl() { + RenderPipelineBase::DestroyImpl(); ToBackend(GetDevice())->ReferenceUntilUnused(mPipelineState); } diff --git a/src/dawn_native/d3d12/SwapChainD3D12.cpp b/src/dawn_native/d3d12/SwapChainD3D12.cpp index 29a414c1b7..a3f2bad79b 100644 --- a/src/dawn_native/d3d12/SwapChainD3D12.cpp +++ b/src/dawn_native/d3d12/SwapChainD3D12.cpp @@ -144,6 +144,7 @@ namespace dawn_native { namespace d3d12 { SwapChain::~SwapChain() = default; void SwapChain::DestroyImpl() { + SwapChainBase::DestroyImpl(); DetachFromSurface(); } diff --git a/src/dawn_native/d3d12/TextureD3D12.cpp b/src/dawn_native/d3d12/TextureD3D12.cpp index ccfbbd8f96..dfdef5b643 100644 --- a/src/dawn_native/d3d12/TextureD3D12.cpp +++ b/src/dawn_native/d3d12/TextureD3D12.cpp @@ -658,6 +658,8 @@ namespace dawn_native { namespace d3d12 { } void Texture::DestroyImpl() { + TextureBase::DestroyImpl(); + Device* device = ToBackend(GetDevice()); // In PIX's D3D12-only mode, there is no way to determine frame boundaries diff --git a/src/dawn_native/metal/BindGroupMTL.mm b/src/dawn_native/metal/BindGroupMTL.mm index 2d4b3c21b4..bbb5827fa0 100644 --- a/src/dawn_native/metal/BindGroupMTL.mm +++ b/src/dawn_native/metal/BindGroupMTL.mm @@ -25,6 +25,7 @@ namespace dawn_native { namespace metal { BindGroup::~BindGroup() = default; void BindGroup::DestroyImpl() { + BindGroupBase::DestroyImpl(); ToBackend(GetLayout())->DeallocateBindGroup(this); } diff --git a/src/dawn_native/metal/BufferMTL.mm b/src/dawn_native/metal/BufferMTL.mm index f2509eb000..8f44f89a46 100644 --- a/src/dawn_native/metal/BufferMTL.mm +++ b/src/dawn_native/metal/BufferMTL.mm @@ -172,6 +172,7 @@ namespace dawn_native { namespace metal { } void Buffer::DestroyImpl() { + BufferBase::DestroyImpl(); mMtlBuffer = nullptr; } diff --git a/src/dawn_native/metal/QuerySetMTL.mm b/src/dawn_native/metal/QuerySetMTL.mm index 90bca0c617..a8b53afb50 100644 --- a/src/dawn_native/metal/QuerySetMTL.mm +++ b/src/dawn_native/metal/QuerySetMTL.mm @@ -124,6 +124,8 @@ namespace dawn_native { namespace metal { QuerySet::~QuerySet() = default; void QuerySet::DestroyImpl() { + QuerySetBase::DestroyImpl(); + mVisibilityBuffer = nullptr; // mCounterSampleBuffer isn't an NSRef because API_AVAILABLE doesn't work will with diff --git a/src/dawn_native/metal/SwapChainMTL.mm b/src/dawn_native/metal/SwapChainMTL.mm index d61bf50ac4..d932986aad 100644 --- a/src/dawn_native/metal/SwapChainMTL.mm +++ b/src/dawn_native/metal/SwapChainMTL.mm @@ -76,6 +76,7 @@ namespace dawn_native { namespace metal { SwapChain::~SwapChain() = default; void SwapChain::DestroyImpl() { + SwapChainBase::DestroyImpl(); DetachFromSurface(); } diff --git a/src/dawn_native/metal/TextureMTL.mm b/src/dawn_native/metal/TextureMTL.mm index c415a55baf..d8105af704 100644 --- a/src/dawn_native/metal/TextureMTL.mm +++ b/src/dawn_native/metal/TextureMTL.mm @@ -500,6 +500,7 @@ namespace dawn_native { namespace metal { } void Texture::DestroyImpl() { + TextureBase::DestroyImpl(); mMtlTexture = nullptr; } diff --git a/src/dawn_native/null/DeviceNull.cpp b/src/dawn_native/null/DeviceNull.cpp index 0250e4df38..b7146b9147 100644 --- a/src/dawn_native/null/DeviceNull.cpp +++ b/src/dawn_native/null/DeviceNull.cpp @@ -331,6 +331,7 @@ namespace dawn_native { namespace null { } void Buffer::DestroyImpl() { + BufferBase::DestroyImpl(); ToBackend(GetDevice())->DecrementMemoryUsage(GetSize()); } @@ -346,9 +347,6 @@ namespace dawn_native { namespace null { : QuerySetBase(device, descriptor) { } - void QuerySet::DestroyImpl() { - } - // Queue Queue::Queue(Device* device) : QueueBase(device) { diff --git a/src/dawn_native/null/DeviceNull.h b/src/dawn_native/null/DeviceNull.h index c7b6848050..380295bba7 100644 --- a/src/dawn_native/null/DeviceNull.h +++ b/src/dawn_native/null/DeviceNull.h @@ -246,9 +246,6 @@ namespace dawn_native { namespace null { class QuerySet final : public QuerySetBase { public: QuerySet(Device* device, const QuerySetDescriptor* descriptor); - - private: - void DestroyImpl() override; }; class Queue final : public QueueBase { diff --git a/src/dawn_native/opengl/BindGroupGL.cpp b/src/dawn_native/opengl/BindGroupGL.cpp index 70975a9875..b77e0ffc1d 100644 --- a/src/dawn_native/opengl/BindGroupGL.cpp +++ b/src/dawn_native/opengl/BindGroupGL.cpp @@ -53,6 +53,7 @@ namespace dawn_native { namespace opengl { BindGroup::~BindGroup() = default; void BindGroup::DestroyImpl() { + BindGroupBase::DestroyImpl(); ToBackend(GetLayout())->DeallocateBindGroup(this); } diff --git a/src/dawn_native/opengl/BufferGL.cpp b/src/dawn_native/opengl/BufferGL.cpp index dc357a476a..45c5813fba 100644 --- a/src/dawn_native/opengl/BufferGL.cpp +++ b/src/dawn_native/opengl/BufferGL.cpp @@ -175,6 +175,7 @@ namespace dawn_native { namespace opengl { } void Buffer::DestroyImpl() { + BufferBase::DestroyImpl(); ToBackend(GetDevice())->gl.DeleteBuffers(1, &mBuffer); mBuffer = 0; } diff --git a/src/dawn_native/opengl/ComputePipelineGL.cpp b/src/dawn_native/opengl/ComputePipelineGL.cpp index 53dc76792b..2ee7bb88c1 100644 --- a/src/dawn_native/opengl/ComputePipelineGL.cpp +++ b/src/dawn_native/opengl/ComputePipelineGL.cpp @@ -28,6 +28,7 @@ namespace dawn_native { namespace opengl { ComputePipeline::~ComputePipeline() = default; void ComputePipeline::DestroyImpl() { + ComputePipelineBase::DestroyImpl(); DeleteProgram(ToBackend(GetDevice())->gl); } diff --git a/src/dawn_native/opengl/QuerySetGL.cpp b/src/dawn_native/opengl/QuerySetGL.cpp index bf85c465a2..2f712919db 100644 --- a/src/dawn_native/opengl/QuerySetGL.cpp +++ b/src/dawn_native/opengl/QuerySetGL.cpp @@ -24,7 +24,4 @@ namespace dawn_native { namespace opengl { QuerySet::~QuerySet() = default; - void QuerySet::DestroyImpl() { - } - }} // namespace dawn_native::opengl diff --git a/src/dawn_native/opengl/QuerySetGL.h b/src/dawn_native/opengl/QuerySetGL.h index 2a83bdd046..b0a31daff6 100644 --- a/src/dawn_native/opengl/QuerySetGL.h +++ b/src/dawn_native/opengl/QuerySetGL.h @@ -27,8 +27,6 @@ namespace dawn_native { namespace opengl { private: ~QuerySet() override; - - void DestroyImpl() override; }; }} // namespace dawn_native::opengl diff --git a/src/dawn_native/opengl/RenderPipelineGL.cpp b/src/dawn_native/opengl/RenderPipelineGL.cpp index 2f8e372da7..bc8c2c6155 100644 --- a/src/dawn_native/opengl/RenderPipelineGL.cpp +++ b/src/dawn_native/opengl/RenderPipelineGL.cpp @@ -237,6 +237,7 @@ namespace dawn_native { namespace opengl { RenderPipeline::~RenderPipeline() = default; void RenderPipeline::DestroyImpl() { + RenderPipelineBase::DestroyImpl(); const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; gl.DeleteVertexArrays(1, &mVertexArrayObject); gl.BindVertexArray(0); diff --git a/src/dawn_native/opengl/SamplerGL.cpp b/src/dawn_native/opengl/SamplerGL.cpp index 5799ecabd1..b331df301a 100644 --- a/src/dawn_native/opengl/SamplerGL.cpp +++ b/src/dawn_native/opengl/SamplerGL.cpp @@ -79,6 +79,7 @@ namespace dawn_native { namespace opengl { Sampler::~Sampler() = default; void Sampler::DestroyImpl() { + SamplerBase::DestroyImpl(); const OpenGLFunctions& gl = ToBackend(GetDevice())->gl; gl.DeleteSamplers(1, &mFilteringHandle); gl.DeleteSamplers(1, &mNonFilteringHandle); diff --git a/src/dawn_native/opengl/TextureGL.cpp b/src/dawn_native/opengl/TextureGL.cpp index d79822399a..ceb57bd426 100644 --- a/src/dawn_native/opengl/TextureGL.cpp +++ b/src/dawn_native/opengl/TextureGL.cpp @@ -191,6 +191,7 @@ namespace dawn_native { namespace opengl { } void Texture::DestroyImpl() { + TextureBase::DestroyImpl(); if (GetTextureState() == TextureState::OwnedInternal) { ToBackend(GetDevice())->gl.DeleteTextures(1, &mHandle); mHandle = 0; @@ -561,6 +562,7 @@ namespace dawn_native { namespace opengl { } void TextureView::DestroyImpl() { + TextureViewBase::DestroyImpl(); if (mOwnsHandle) { ToBackend(GetDevice())->gl.DeleteTextures(1, &mHandle); } diff --git a/src/dawn_native/vulkan/BindGroupLayoutVk.cpp b/src/dawn_native/vulkan/BindGroupLayoutVk.cpp index d609b780ac..b8d34d74f3 100644 --- a/src/dawn_native/vulkan/BindGroupLayoutVk.cpp +++ b/src/dawn_native/vulkan/BindGroupLayoutVk.cpp @@ -155,6 +155,8 @@ namespace dawn_native { namespace vulkan { BindGroupLayout::~BindGroupLayout() = default; void BindGroupLayout::DestroyImpl() { + BindGroupLayoutBase::DestroyImpl(); + Device* device = ToBackend(GetDevice()); // DescriptorSetLayout aren't used by execution on the GPU and can be deleted at any time, diff --git a/src/dawn_native/vulkan/BindGroupVk.cpp b/src/dawn_native/vulkan/BindGroupVk.cpp index 9173df1f9d..dcfae8ff51 100644 --- a/src/dawn_native/vulkan/BindGroupVk.cpp +++ b/src/dawn_native/vulkan/BindGroupVk.cpp @@ -164,6 +164,7 @@ namespace dawn_native { namespace vulkan { BindGroup::~BindGroup() = default; void BindGroup::DestroyImpl() { + BindGroupBase::DestroyImpl(); ToBackend(GetLayout())->DeallocateBindGroup(this, &mDescriptorSetAllocation); } diff --git a/src/dawn_native/vulkan/BufferVk.cpp b/src/dawn_native/vulkan/BufferVk.cpp index 01ee392f8d..20d9c3ecc1 100644 --- a/src/dawn_native/vulkan/BufferVk.cpp +++ b/src/dawn_native/vulkan/BufferVk.cpp @@ -330,6 +330,8 @@ namespace dawn_native { namespace vulkan { } void Buffer::DestroyImpl() { + BufferBase::DestroyImpl(); + ToBackend(GetDevice())->GetResourceMemoryAllocator()->Deallocate(&mMemoryAllocation); if (mHandle != VK_NULL_HANDLE) { diff --git a/src/dawn_native/vulkan/ComputePipelineVk.cpp b/src/dawn_native/vulkan/ComputePipelineVk.cpp index 6ead4ab3de..77ceba7dee 100644 --- a/src/dawn_native/vulkan/ComputePipelineVk.cpp +++ b/src/dawn_native/vulkan/ComputePipelineVk.cpp @@ -92,6 +92,8 @@ namespace dawn_native { namespace vulkan { ComputePipeline::~ComputePipeline() = default; void ComputePipeline::DestroyImpl() { + ComputePipelineBase::DestroyImpl(); + if (mHandle != VK_NULL_HANDLE) { ToBackend(GetDevice())->GetFencedDeleter()->DeleteWhenUnused(mHandle); mHandle = VK_NULL_HANDLE; diff --git a/src/dawn_native/vulkan/PipelineLayoutVk.cpp b/src/dawn_native/vulkan/PipelineLayoutVk.cpp index 9508d3be94..e41a99b8b9 100644 --- a/src/dawn_native/vulkan/PipelineLayoutVk.cpp +++ b/src/dawn_native/vulkan/PipelineLayoutVk.cpp @@ -65,6 +65,7 @@ namespace dawn_native { namespace vulkan { PipelineLayout::~PipelineLayout() = default; void PipelineLayout::DestroyImpl() { + PipelineLayoutBase::DestroyImpl(); if (mHandle != VK_NULL_HANDLE) { ToBackend(GetDevice())->GetFencedDeleter()->DeleteWhenUnused(mHandle); mHandle = VK_NULL_HANDLE; diff --git a/src/dawn_native/vulkan/QuerySetVk.cpp b/src/dawn_native/vulkan/QuerySetVk.cpp index 706414b1db..01d3a738c5 100644 --- a/src/dawn_native/vulkan/QuerySetVk.cpp +++ b/src/dawn_native/vulkan/QuerySetVk.cpp @@ -102,6 +102,7 @@ namespace dawn_native { namespace vulkan { QuerySet::~QuerySet() = default; void QuerySet::DestroyImpl() { + QuerySetBase::DestroyImpl(); if (mHandle != VK_NULL_HANDLE) { ToBackend(GetDevice())->GetFencedDeleter()->DeleteWhenUnused(mHandle); mHandle = VK_NULL_HANDLE; diff --git a/src/dawn_native/vulkan/RenderPipelineVk.cpp b/src/dawn_native/vulkan/RenderPipelineVk.cpp index 41ef3a0b43..556b582b52 100644 --- a/src/dawn_native/vulkan/RenderPipelineVk.cpp +++ b/src/dawn_native/vulkan/RenderPipelineVk.cpp @@ -602,6 +602,7 @@ namespace dawn_native { namespace vulkan { RenderPipeline::~RenderPipeline() = default; void RenderPipeline::DestroyImpl() { + RenderPipelineBase::DestroyImpl(); if (mHandle != VK_NULL_HANDLE) { ToBackend(GetDevice())->GetFencedDeleter()->DeleteWhenUnused(mHandle); mHandle = VK_NULL_HANDLE; diff --git a/src/dawn_native/vulkan/SamplerVk.cpp b/src/dawn_native/vulkan/SamplerVk.cpp index 78a4c57691..7c43645380 100644 --- a/src/dawn_native/vulkan/SamplerVk.cpp +++ b/src/dawn_native/vulkan/SamplerVk.cpp @@ -112,6 +112,7 @@ namespace dawn_native { namespace vulkan { Sampler::~Sampler() = default; void Sampler::DestroyImpl() { + SamplerBase::DestroyImpl(); if (mHandle != VK_NULL_HANDLE) { ToBackend(GetDevice())->GetFencedDeleter()->DeleteWhenUnused(mHandle); mHandle = VK_NULL_HANDLE; diff --git a/src/dawn_native/vulkan/ShaderModuleVk.cpp b/src/dawn_native/vulkan/ShaderModuleVk.cpp index bd8988065c..45ee439f96 100644 --- a/src/dawn_native/vulkan/ShaderModuleVk.cpp +++ b/src/dawn_native/vulkan/ShaderModuleVk.cpp @@ -100,6 +100,7 @@ namespace dawn_native { namespace vulkan { } void ShaderModule::DestroyImpl() { + ShaderModuleBase::DestroyImpl(); // Remove reference to internal cache to trigger cleanup. mTransformedShaderModuleCache = nullptr; } diff --git a/src/dawn_native/vulkan/SwapChainVk.cpp b/src/dawn_native/vulkan/SwapChainVk.cpp index 642a1d9f3d..04204621b9 100644 --- a/src/dawn_native/vulkan/SwapChainVk.cpp +++ b/src/dawn_native/vulkan/SwapChainVk.cpp @@ -226,6 +226,7 @@ namespace dawn_native { namespace vulkan { SwapChain::~SwapChain() = default; void SwapChain::DestroyImpl() { + SwapChainBase::DestroyImpl(); DetachFromSurface(); } diff --git a/src/dawn_native/vulkan/TextureVk.cpp b/src/dawn_native/vulkan/TextureVk.cpp index 4162615112..2edf724b13 100644 --- a/src/dawn_native/vulkan/TextureVk.cpp +++ b/src/dawn_native/vulkan/TextureVk.cpp @@ -833,6 +833,9 @@ namespace dawn_native { namespace vulkan { // If a signal semaphore exists it should be requested before we delete the texture ASSERT(mSignalSemaphore == VK_NULL_HANDLE); } + // For Vulkan, we currently run the base destruction code after the internal changes because + // of the dependency on the texture state which the base code overwrites too early. + TextureBase::DestroyImpl(); } VkImage Texture::GetHandle() const { diff --git a/src/tests/unittests/native/DestroyObjectTests.cpp b/src/tests/unittests/native/DestroyObjectTests.cpp index fee5ed9366..99acf28005 100644 --- a/src/tests/unittests/native/DestroyObjectTests.cpp +++ b/src/tests/unittests/native/DestroyObjectTests.cpp @@ -168,8 +168,8 @@ namespace dawn_native { namespace { BufferMock bufferMock(&mDevice, BufferBase::BufferState::Mapped); { InSequence seq; - EXPECT_CALL(bufferMock, UnmapImpl).Times(1); EXPECT_CALL(bufferMock, DestroyImpl).Times(1); + EXPECT_CALL(bufferMock, UnmapImpl).Times(1); } EXPECT_TRUE(bufferMock.IsAlive()); @@ -198,8 +198,8 @@ namespace dawn_native { namespace { BufferMock* bufferMock = new BufferMock(&mDevice, BufferBase::BufferState::Mapped); { InSequence seq; - EXPECT_CALL(*bufferMock, UnmapImpl).Times(1); EXPECT_CALL(*bufferMock, DestroyImpl).Times(1); + EXPECT_CALL(*bufferMock, UnmapImpl).Times(1); } { BufferDescriptor desc = {}; diff --git a/src/tests/unittests/native/mocks/BindGroupLayoutMock.h b/src/tests/unittests/native/mocks/BindGroupLayoutMock.h index b4c496240b..56df3749b2 100644 --- a/src/tests/unittests/native/mocks/BindGroupLayoutMock.h +++ b/src/tests/unittests/native/mocks/BindGroupLayoutMock.h @@ -25,6 +25,9 @@ namespace dawn_native { class BindGroupLayoutMock final : public BindGroupLayoutBase { public: BindGroupLayoutMock(DeviceBase* device) : BindGroupLayoutBase(device) { + ON_CALL(*this, DestroyImpl).WillByDefault([this]() { + this->BindGroupLayoutBase::DestroyImpl(); + }); } ~BindGroupLayoutMock() override = default; diff --git a/src/tests/unittests/native/mocks/BindGroupMock.h b/src/tests/unittests/native/mocks/BindGroupMock.h index af79cf65a1..bc5e234051 100644 --- a/src/tests/unittests/native/mocks/BindGroupMock.h +++ b/src/tests/unittests/native/mocks/BindGroupMock.h @@ -25,6 +25,9 @@ namespace dawn_native { class BindGroupMock : public BindGroupBase { public: BindGroupMock(DeviceBase* device) : BindGroupBase(device) { + ON_CALL(*this, DestroyImpl).WillByDefault([this]() { + this->BindGroupBase::DestroyImpl(); + }); } ~BindGroupMock() override = default; diff --git a/src/tests/unittests/native/mocks/BufferMock.h b/src/tests/unittests/native/mocks/BufferMock.h index e576e77a95..4b6685456e 100644 --- a/src/tests/unittests/native/mocks/BufferMock.h +++ b/src/tests/unittests/native/mocks/BufferMock.h @@ -25,6 +25,9 @@ namespace dawn_native { class BufferMock : public BufferBase { public: BufferMock(DeviceBase* device, BufferBase::BufferState state) : BufferBase(device, state) { + ON_CALL(*this, DestroyImpl).WillByDefault([this]() { + this->BufferBase::DestroyImpl(); + }); } ~BufferMock() override = default; diff --git a/src/tests/unittests/native/mocks/CommandBufferMock.h b/src/tests/unittests/native/mocks/CommandBufferMock.h index 52c6034386..88caa23945 100644 --- a/src/tests/unittests/native/mocks/CommandBufferMock.h +++ b/src/tests/unittests/native/mocks/CommandBufferMock.h @@ -25,6 +25,9 @@ namespace dawn_native { class CommandBufferMock : public CommandBufferBase { public: CommandBufferMock(DeviceBase* device) : CommandBufferBase(device) { + ON_CALL(*this, DestroyImpl).WillByDefault([this]() { + this->CommandBufferBase::DestroyImpl(); + }); } ~CommandBufferMock() override = default; diff --git a/src/tests/unittests/native/mocks/ComputePipelineMock.h b/src/tests/unittests/native/mocks/ComputePipelineMock.h index fbf9df63d8..84b6278fe9 100644 --- a/src/tests/unittests/native/mocks/ComputePipelineMock.h +++ b/src/tests/unittests/native/mocks/ComputePipelineMock.h @@ -25,6 +25,9 @@ namespace dawn_native { class ComputePipelineMock : public ComputePipelineBase { public: ComputePipelineMock(DeviceBase* device) : ComputePipelineBase(device) { + ON_CALL(*this, DestroyImpl).WillByDefault([this]() { + this->ComputePipelineBase::DestroyImpl(); + }); } ~ComputePipelineMock() override = default; diff --git a/src/tests/unittests/native/mocks/ExternalTextureMock.h b/src/tests/unittests/native/mocks/ExternalTextureMock.h index b61746cb0d..57c0c9f332 100644 --- a/src/tests/unittests/native/mocks/ExternalTextureMock.h +++ b/src/tests/unittests/native/mocks/ExternalTextureMock.h @@ -25,6 +25,9 @@ namespace dawn_native { class ExternalTextureMock : public ExternalTextureBase { public: ExternalTextureMock(DeviceBase* device) : ExternalTextureBase(device) { + ON_CALL(*this, DestroyImpl).WillByDefault([this]() { + this->ExternalTextureBase::DestroyImpl(); + }); } ~ExternalTextureMock() override = default; diff --git a/src/tests/unittests/native/mocks/PipelineLayoutMock.h b/src/tests/unittests/native/mocks/PipelineLayoutMock.h index 036cffe0b1..c35d5ed259 100644 --- a/src/tests/unittests/native/mocks/PipelineLayoutMock.h +++ b/src/tests/unittests/native/mocks/PipelineLayoutMock.h @@ -25,6 +25,9 @@ namespace dawn_native { class PipelineLayoutMock : public PipelineLayoutBase { public: PipelineLayoutMock(DeviceBase* device) : PipelineLayoutBase(device) { + ON_CALL(*this, DestroyImpl).WillByDefault([this]() { + this->PipelineLayoutBase::DestroyImpl(); + }); } ~PipelineLayoutMock() override = default; diff --git a/src/tests/unittests/native/mocks/QuerySetMock.h b/src/tests/unittests/native/mocks/QuerySetMock.h index faf5f4b66b..1554fff9ae 100644 --- a/src/tests/unittests/native/mocks/QuerySetMock.h +++ b/src/tests/unittests/native/mocks/QuerySetMock.h @@ -25,6 +25,9 @@ namespace dawn_native { class QuerySetMock : public QuerySetBase { public: QuerySetMock(DeviceBase* device) : QuerySetBase(device) { + ON_CALL(*this, DestroyImpl).WillByDefault([this]() { + this->QuerySetBase::DestroyImpl(); + }); } ~QuerySetMock() override = default; diff --git a/src/tests/unittests/native/mocks/RenderPipelineMock.h b/src/tests/unittests/native/mocks/RenderPipelineMock.h index 8cba7708ff..12701c3b05 100644 --- a/src/tests/unittests/native/mocks/RenderPipelineMock.h +++ b/src/tests/unittests/native/mocks/RenderPipelineMock.h @@ -25,6 +25,9 @@ namespace dawn_native { class RenderPipelineMock : public RenderPipelineBase { public: RenderPipelineMock(DeviceBase* device) : RenderPipelineBase(device) { + ON_CALL(*this, DestroyImpl).WillByDefault([this]() { + this->RenderPipelineBase::DestroyImpl(); + }); } ~RenderPipelineMock() override = default; diff --git a/src/tests/unittests/native/mocks/SamplerMock.h b/src/tests/unittests/native/mocks/SamplerMock.h index 7948eaa37e..56df161a27 100644 --- a/src/tests/unittests/native/mocks/SamplerMock.h +++ b/src/tests/unittests/native/mocks/SamplerMock.h @@ -25,6 +25,9 @@ namespace dawn_native { class SamplerMock : public SamplerBase { public: SamplerMock(DeviceBase* device) : SamplerBase(device) { + ON_CALL(*this, DestroyImpl).WillByDefault([this]() { + this->SamplerBase::DestroyImpl(); + }); } ~SamplerMock() override = default; diff --git a/src/tests/unittests/native/mocks/ShaderModuleMock.cpp b/src/tests/unittests/native/mocks/ShaderModuleMock.cpp index 4d0f0f2d20..9b5ab09dff 100644 --- a/src/tests/unittests/native/mocks/ShaderModuleMock.cpp +++ b/src/tests/unittests/native/mocks/ShaderModuleMock.cpp @@ -16,6 +16,12 @@ namespace dawn_native { + ShaderModuleMock::ShaderModuleMock(DeviceBase* device) : ShaderModuleBase(device) { + ON_CALL(*this, DestroyImpl).WillByDefault([this]() { + this->ShaderModuleBase::DestroyImpl(); + }); + } + ResultOrError> ShaderModuleMock::Create(DeviceBase* device, const char* source) { ShaderModuleMock* mock = new ShaderModuleMock(device); diff --git a/src/tests/unittests/native/mocks/ShaderModuleMock.h b/src/tests/unittests/native/mocks/ShaderModuleMock.h index e5e5cc5153..0b3e650058 100644 --- a/src/tests/unittests/native/mocks/ShaderModuleMock.h +++ b/src/tests/unittests/native/mocks/ShaderModuleMock.h @@ -27,8 +27,7 @@ namespace dawn_native { class ShaderModuleMock : public ShaderModuleBase { public: - ShaderModuleMock(DeviceBase* device) : ShaderModuleBase(device) { - } + ShaderModuleMock(DeviceBase* device); ~ShaderModuleMock() override = default; MOCK_METHOD(void, DestroyImpl, (), (override)); diff --git a/src/tests/unittests/native/mocks/SwapChainMock.h b/src/tests/unittests/native/mocks/SwapChainMock.h index c8a3f740f1..233da739ce 100644 --- a/src/tests/unittests/native/mocks/SwapChainMock.h +++ b/src/tests/unittests/native/mocks/SwapChainMock.h @@ -25,6 +25,9 @@ namespace dawn_native { class SwapChainMock : public SwapChainBase { public: SwapChainMock(DeviceBase* device) : SwapChainBase(device) { + ON_CALL(*this, DestroyImpl).WillByDefault([this]() { + this->SwapChainBase::DestroyImpl(); + }); } ~SwapChainMock() override = default; diff --git a/src/tests/unittests/native/mocks/TextureMock.h b/src/tests/unittests/native/mocks/TextureMock.h index 1e2b6a4ed2..95e53bee0b 100644 --- a/src/tests/unittests/native/mocks/TextureMock.h +++ b/src/tests/unittests/native/mocks/TextureMock.h @@ -26,6 +26,9 @@ namespace dawn_native { public: TextureMock(DeviceBase* device, TextureBase::TextureState state) : TextureBase(device, state) { + ON_CALL(*this, DestroyImpl).WillByDefault([this]() { + this->TextureBase::DestroyImpl(); + }); } ~TextureMock() override = default;