mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-02 20:51:45 +00:00
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:
parent
39b4b38f4f
commit
600a26d50a
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user