mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-14 14:01:06 +00:00
Make sure to correctly identify removed buffer in GPUAddress mapping
* When multiple buffers are aliased over the same heap memory, they'll have the same GPU base address. Our mapping needs to ensure it removes the right entry when a resource is released.
This commit is contained in:
@@ -463,7 +463,7 @@ struct GPUAddressRangeTracker
|
||||
std::vector<GPUAddressRange> addresses;
|
||||
Threading::RWLock addressLock;
|
||||
|
||||
void AddTo(GPUAddressRange range)
|
||||
void AddTo(const GPUAddressRange &range)
|
||||
{
|
||||
SCOPED_WRITELOCK(addressLock);
|
||||
auto it = std::lower_bound(addresses.begin(), addresses.end(), range.start);
|
||||
@@ -471,13 +471,27 @@ struct GPUAddressRangeTracker
|
||||
addresses.insert(it, range);
|
||||
}
|
||||
|
||||
void RemoveFrom(D3D12_GPU_VIRTUAL_ADDRESS baseAddr)
|
||||
void RemoveFrom(const GPUAddressRange &range)
|
||||
{
|
||||
SCOPED_WRITELOCK(addressLock);
|
||||
auto it = std::lower_bound(addresses.begin(), addresses.end(), baseAddr);
|
||||
RDCASSERT(it != addresses.end() && baseAddr >= it->start && baseAddr < it->end);
|
||||
{
|
||||
SCOPED_WRITELOCK(addressLock);
|
||||
auto it = std::lower_bound(addresses.begin(), addresses.end(), range.start);
|
||||
|
||||
addresses.erase(it);
|
||||
// there might be multiple buffers with the same range start, find the exact range for this
|
||||
// buffer
|
||||
while(it != addresses.end() && it->start == range.start)
|
||||
{
|
||||
if(it->id == range.id)
|
||||
{
|
||||
addresses.erase(it);
|
||||
return;
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
RDCERR("Couldn't find matching range to remove for %s", ToStr(range.id).c_str());
|
||||
}
|
||||
|
||||
void GetResIDFromAddr(D3D12_GPU_VIRTUAL_ADDRESS addr, ResourceId &id, UINT64 &offs)
|
||||
|
||||
@@ -307,7 +307,14 @@ WrappedID3D12Resource::~WrappedID3D12Resource()
|
||||
|
||||
// assuming only valid for buffers
|
||||
if(m_pReal->GetDesc().Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
|
||||
m_Addresses.RemoveFrom(m_pReal->GetGPUVirtualAddress());
|
||||
{
|
||||
GPUAddressRange range;
|
||||
range.start = m_pReal->GetGPUVirtualAddress();
|
||||
range.end = m_pReal->GetGPUVirtualAddress() + m_pReal->GetDesc().Width;
|
||||
range.id = GetResourceID();
|
||||
|
||||
m_Addresses.RemoveFrom(range);
|
||||
}
|
||||
|
||||
Shutdown();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user