Fix ResourceHeapAllocation Memory Leak

ResourceAllocatorManager::DeallocateMemory was correctly invalidating the
passed in allocation object. However, since the subclass
ResourceHeapAllocation class was not overriding the Invalidate method and
clearing out the D3D12Resource pointer, the resource ended up being tied
to the lifetime of the Texture object instead of being released on Destroy.

In Chromium, this bug was particularly egregious as it meant swap chain
texture cleanup was at the whims of the Javascript garbage collector.

Bug: dawn:242
Change-Id: Ia5856c61c8d3b92a2247a9aaa5f91c5de0a99dcb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/13200
Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Rafael Cintron 2019-11-08 21:47:00 +00:00 committed by Commit Bot service account
parent 39b4b38f4f
commit 600a26d50a
4 changed files with 12 additions and 3 deletions

View File

@ -54,14 +54,14 @@ namespace dawn_native {
uint64_t offset,
ResourceHeapBase* resourceHeap,
uint8_t* mappedPointer = nullptr);
~ResourceMemoryAllocation() = default;
virtual ~ResourceMemoryAllocation() = default;
ResourceHeapBase* GetResourceHeap() const;
uint64_t GetOffset() const;
uint8_t* GetMappedPointer() const;
AllocationInfo GetInfo() const;
void Invalidate();
virtual void Invalidate();
private:
AllocationInfo mInfo;

View File

@ -168,6 +168,8 @@ namespace dawn_native { namespace d3d12 {
// Invalidate the allocation immediately in case one accidentally
// calls DeallocateMemory again using the same allocation.
allocation.Invalidate();
ASSERT(allocation.GetD3D12Resource().Get() == nullptr);
}
void ResourceAllocatorManager::FreeMemory(ResourceHeapAllocation& allocation) {

View File

@ -23,6 +23,11 @@ namespace dawn_native { namespace d3d12 {
: ResourceMemoryAllocation(info, offset, nullptr), mResource(std::move(resource)) {
}
void ResourceHeapAllocation::Invalidate() {
ResourceMemoryAllocation::Invalidate();
mResource.Reset();
}
ComPtr<ID3D12Resource> ResourceHeapAllocation::GetD3D12Resource() const {
return mResource;
}

View File

@ -26,7 +26,9 @@ namespace dawn_native { namespace d3d12 {
ResourceHeapAllocation(const AllocationInfo& info,
uint64_t offset,
ComPtr<ID3D12Resource> resource);
~ResourceHeapAllocation() = default;
~ResourceHeapAllocation() override = default;
void Invalidate() override;
ComPtr<ID3D12Resource> GetD3D12Resource() const;
D3D12_GPU_VIRTUAL_ADDRESS GetGPUPointer() const;