Adds destruction handling for "simple objects" in device.destroy

Simple objects are defined as per https://dawn-review.googlesource.com/c/dawn/+/65864 and include:
- BindGroups
- ComputePipelines
- PipelineLayouts
- RenderPipelines
- Samplers
- ShaderModules
- SwapChains

Bug: dawn:628
Change-Id: I4ad74a2c4a223cf45acdbe6bdd0ec74332c9a14a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/67740
Commit-Queue: Loko Kung <lokokung@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Loko Kung 2021-11-11 00:39:22 +00:00 committed by Dawn LUCI CQ
parent 6b6262dde0
commit 2c67af9853
32 changed files with 75 additions and 16 deletions

View File

@ -205,7 +205,9 @@ namespace dawn_native { namespace d3d12 {
}
}
BindGroup::~BindGroup() {
BindGroup::~BindGroup() = default;
void BindGroup::DestroyApiObjectImpl() {
ToBackend(GetLayout())->DeallocateBindGroup(this, &mCPUViewAllocation);
ASSERT(!mCPUViewAllocation.IsValid());
}

View File

@ -48,6 +48,8 @@ namespace dawn_native { namespace d3d12 {
private:
~BindGroup() override;
void DestroyApiObjectImpl() override;
Ref<SamplerHeapCacheEntry> mSamplerAllocationEntry;
GPUDescriptorHeapAllocation mGPUViewAllocation;

View File

@ -62,7 +62,9 @@ namespace dawn_native { namespace d3d12 {
return {};
}
ComputePipeline::~ComputePipeline() {
ComputePipeline::~ComputePipeline() = default;
void ComputePipeline::DestroyApiObjectImpl() {
ToBackend(GetDevice())->ReferenceUntilUnused(mPipelineState);
}

View File

@ -44,6 +44,9 @@ namespace dawn_native { namespace d3d12 {
private:
~ComputePipeline() override;
void DestroyApiObjectImpl() override;
using ComputePipelineBase::ComputePipelineBase;
ComPtr<ID3D12PipelineState> mPipelineState;
};

View File

@ -417,7 +417,9 @@ namespace dawn_native { namespace d3d12 {
return {};
}
RenderPipeline::~RenderPipeline() {
RenderPipeline::~RenderPipeline() = default;
void RenderPipeline::DestroyApiObjectImpl() {
ToBackend(GetDevice())->ReferenceUntilUnused(mPipelineState);
}

View File

@ -45,6 +45,9 @@ namespace dawn_native { namespace d3d12 {
private:
~RenderPipeline() override;
void DestroyApiObjectImpl() override;
using RenderPipelineBase::RenderPipelineBase;
D3D12_INPUT_LAYOUT_DESC ComputeInputLayout(
std::array<D3D12_INPUT_ELEMENT_DESC, kMaxVertexAttributes>* inputElementDescriptors);

View File

@ -141,7 +141,9 @@ namespace dawn_native { namespace d3d12 {
return swapchain;
}
SwapChain::~SwapChain() {
SwapChain::~SwapChain() = default;
void SwapChain::DestroyApiObjectImpl() {
DetachFromSurface();
}

View File

@ -48,6 +48,8 @@ namespace dawn_native { namespace d3d12 {
private:
~SwapChain() override;
void DestroyApiObjectImpl() override;
using NewSwapChainBase::NewSwapChainBase;
MaybeError Initialize(NewSwapChainBase* previousSwapChain);

View File

@ -30,6 +30,8 @@ namespace dawn_native { namespace metal {
private:
~BindGroup() override;
void DestroyApiObjectImpl() override;
};
}} // namespace dawn_native::metal

View File

@ -22,7 +22,9 @@ namespace dawn_native { namespace metal {
: BindGroupBase(this, device, descriptor) {
}
BindGroup::~BindGroup() {
BindGroup::~BindGroup() = default;
void BindGroup::DestroyApiObjectImpl() {
ToBackend(GetLayout())->DeallocateBindGroup(this);
}

View File

@ -47,6 +47,8 @@ namespace dawn_native { namespace metal {
~SwapChain() override;
private:
void DestroyApiObjectImpl() override;
using NewSwapChainBase::NewSwapChainBase;
MaybeError Initialize(NewSwapChainBase* previousSwapChain);

View File

@ -73,7 +73,9 @@ namespace dawn_native { namespace metal {
return swapchain;
}
SwapChain::~SwapChain() {
SwapChain::~SwapChain() = default;
void SwapChain::DestroyApiObjectImpl() {
DetachFromSurface();
}

View File

@ -50,7 +50,9 @@ namespace dawn_native { namespace opengl {
: BindGroupBase(this, device, descriptor) {
}
BindGroup::~BindGroup() {
BindGroup::~BindGroup() = default;
void BindGroup::DestroyApiObjectImpl() {
ToBackend(GetLayout())->DeallocateBindGroup(this);
}

View File

@ -32,6 +32,8 @@ namespace dawn_native { namespace opengl {
private:
~BindGroup() override;
void DestroyApiObjectImpl() override;
};
}} // namespace dawn_native::opengl

View File

@ -25,7 +25,9 @@ namespace dawn_native { namespace opengl {
return AcquireRef(new ComputePipeline(device, descriptor));
}
ComputePipeline::~ComputePipeline() {
ComputePipeline::~ComputePipeline() = default;
void ComputePipeline::DestroyApiObjectImpl() {
DeleteProgram(ToBackend(GetDevice())->gl);
}

View File

@ -38,6 +38,7 @@ namespace dawn_native { namespace opengl {
private:
using ComputePipelineBase::ComputePipelineBase;
~ComputePipeline() override;
void DestroyApiObjectImpl() override;
};
}} // namespace dawn_native::opengl

View File

@ -234,7 +234,9 @@ namespace dawn_native { namespace opengl {
return {};
}
RenderPipeline::~RenderPipeline() {
RenderPipeline::~RenderPipeline() = default;
void RenderPipeline::DestroyApiObjectImpl() {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl;
gl.DeleteVertexArrays(1, &mVertexArrayObject);
gl.BindVertexArray(0);

View File

@ -43,6 +43,7 @@ namespace dawn_native { namespace opengl {
private:
RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor);
~RenderPipeline() override;
void DestroyApiObjectImpl() override;
void CreateVAOForVertexState();

View File

@ -76,7 +76,9 @@ namespace dawn_native { namespace opengl {
SetupGLSampler(mNonFilteringHandle, descriptor, true);
}
Sampler::~Sampler() {
Sampler::~Sampler() = default;
void Sampler::DestroyApiObjectImpl() {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl;
gl.DeleteSamplers(1, &mFilteringHandle);
gl.DeleteSamplers(1, &mNonFilteringHandle);

View File

@ -32,6 +32,7 @@ namespace dawn_native { namespace opengl {
private:
~Sampler() override;
void DestroyApiObjectImpl() override;
void SetupGLSampler(GLuint sampler, const SamplerDescriptor* descriptor, bool forceNearest);

View File

@ -158,7 +158,9 @@ namespace dawn_native { namespace vulkan {
nullptr);
}
BindGroup::~BindGroup() {
BindGroup::~BindGroup() = default;
void BindGroup::DestroyApiObjectImpl() {
ToBackend(GetLayout())->DeallocateBindGroup(this, &mDescriptorSetAllocation);
}

View File

@ -40,6 +40,8 @@ namespace dawn_native { namespace vulkan {
private:
~BindGroup() override;
void DestroyApiObjectImpl() override;
// The descriptor set in this allocation outlives the BindGroup because it is owned by
// the BindGroupLayout which is referenced by the BindGroup.
DescriptorSetAllocation mDescriptorSetAllocation;

View File

@ -89,7 +89,9 @@ namespace dawn_native { namespace vulkan {
reinterpret_cast<uint64_t&>(mHandle), "Dawn_ComputePipeline", GetLabel());
}
ComputePipeline::~ComputePipeline() {
ComputePipeline::~ComputePipeline() = default;
void ComputePipeline::DestroyApiObjectImpl() {
if (mHandle != VK_NULL_HANDLE) {
ToBackend(GetDevice())->GetFencedDeleter()->DeleteWhenUnused(mHandle);
mHandle = VK_NULL_HANDLE;

View File

@ -42,6 +42,7 @@ namespace dawn_native { namespace vulkan {
private:
~ComputePipeline() override;
void DestroyApiObjectImpl() override;
using ComputePipelineBase::ComputePipelineBase;
VkPipeline mHandle = VK_NULL_HANDLE;

View File

@ -57,7 +57,9 @@ namespace dawn_native { namespace vulkan {
"CreatePipelineLayout");
}
PipelineLayout::~PipelineLayout() {
PipelineLayout::~PipelineLayout() = default;
void PipelineLayout::DestroyApiObjectImpl() {
if (mHandle != VK_NULL_HANDLE) {
ToBackend(GetDevice())->GetFencedDeleter()->DeleteWhenUnused(mHandle);
mHandle = VK_NULL_HANDLE;

View File

@ -34,6 +34,8 @@ namespace dawn_native { namespace vulkan {
private:
~PipelineLayout() override;
void DestroyApiObjectImpl() override;
using PipelineLayoutBase::PipelineLayoutBase;
MaybeError Initialize();

View File

@ -599,7 +599,9 @@ namespace dawn_native { namespace vulkan {
return createInfo;
}
RenderPipeline::~RenderPipeline() {
RenderPipeline::~RenderPipeline() = default;
void RenderPipeline::DestroyApiObjectImpl() {
if (mHandle != VK_NULL_HANDLE) {
ToBackend(GetDevice())->GetFencedDeleter()->DeleteWhenUnused(mHandle);
mHandle = VK_NULL_HANDLE;

View File

@ -41,6 +41,7 @@ namespace dawn_native { namespace vulkan {
private:
~RenderPipeline() override;
void DestroyApiObjectImpl() override;
using RenderPipelineBase::RenderPipelineBase;
struct PipelineVertexInputStateCreateInfoTemporaryAllocations {

View File

@ -105,7 +105,9 @@ namespace dawn_native { namespace vulkan {
"CreateSampler");
}
Sampler::~Sampler() {
Sampler::~Sampler() = default;
void Sampler::DestroyApiObjectImpl() {
if (mHandle != VK_NULL_HANDLE) {
ToBackend(GetDevice())->GetFencedDeleter()->DeleteWhenUnused(mHandle);
mHandle = VK_NULL_HANDLE;

View File

@ -33,6 +33,7 @@ namespace dawn_native { namespace vulkan {
private:
~Sampler() override;
void DestroyApiObjectImpl() override;
using SamplerBase::SamplerBase;
MaybeError Initialize(const SamplerDescriptor* descriptor);

View File

@ -223,7 +223,9 @@ namespace dawn_native { namespace vulkan {
return swapchain;
}
SwapChain::~SwapChain() {
SwapChain::~SwapChain() = default;
void SwapChain::DestroyApiObjectImpl() {
DetachFromSurface();
}

View File

@ -53,6 +53,7 @@ namespace dawn_native { namespace vulkan {
private:
using NewSwapChainBase::NewSwapChainBase;
MaybeError Initialize(NewSwapChainBase* previousSwapChain);
void DestroyApiObjectImpl() override;
struct Config {
// Information that's passed to vulkan swapchain creation.