From 6e5f8ae6870370f8a69f08d2091d10a9f59a1002 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 28 Jul 2016 11:57:14 +0700 Subject: [PATCH] When serialising GPU_VIRTUAL_ADDRESS, make sure to store offset as well --- .../driver/d3d12/d3d12_command_list_wrap.cpp | 34 ++++++++++++++++--- renderdoc/driver/d3d12/d3d12_common.cpp | 18 ++++++---- renderdoc/driver/d3d12/d3d12_resources.cpp | 6 ---- renderdoc/driver/d3d12/d3d12_resources.h | 18 +++++----- 4 files changed, 50 insertions(+), 26 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp index 0f716dc14..0e694f743 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp @@ -563,15 +563,23 @@ void WrappedID3D12GraphicsCommandList::SetComputeRootConstantBufferView( bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootConstantBufferView( UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation) { + ResourceId id; + UINT64 offs = 0; + + if(m_State >= WRITING) + WrappedID3D12Resource::GetResIDFromAddr(BufferLocation, id, offs); + SERIALISE_ELEMENT(ResourceId, CommandList, GetResourceID()); SERIALISE_ELEMENT(UINT, idx, RootParameterIndex); - SERIALISE_ELEMENT(ResourceId, buffer, GetResID(BufferLocation)); + SERIALISE_ELEMENT(ResourceId, buffer, id); + SERIALISE_ELEMENT(UINT64, byteOffset, offs); if(m_State <= READING) { WrappedID3D12Resource *pRes = GetResourceManager()->GetLiveAs(buffer); - GetList(CommandList)->SetGraphicsRootConstantBufferView(idx, pRes->GetGPUVirtualAddress()); + GetList(CommandList) + ->SetGraphicsRootConstantBufferView(idx, pRes->GetGPUVirtualAddress() + byteOffset); } return true; @@ -587,8 +595,12 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRootConstantBufferView( SCOPED_SERIALISE_CONTEXT(SET_GFX_ROOT_CBV); Serialise_SetGraphicsRootConstantBufferView(RootParameterIndex, BufferLocation); + ResourceId id; + UINT64 offs = 0; + WrappedID3D12Resource::GetResIDFromAddr(BufferLocation, id, offs); + m_ListRecord->AddChunk(scope.Get()); - m_ListRecord->MarkResourceFrameReferenced(GetResID(BufferLocation), eFrameRef_Read); + m_ListRecord->MarkResourceFrameReferenced(id, eFrameRef_Read); } } @@ -644,7 +656,13 @@ void WrappedID3D12GraphicsCommandList::IASetIndexBuffer(const D3D12_INDEX_BUFFER m_ListRecord->AddChunk(scope.Get()); if(pView) - m_ListRecord->MarkResourceFrameReferenced(GetResID(pView->BufferLocation), eFrameRef_Read); + { + ResourceId id; + UINT64 offs = 0; + WrappedID3D12Resource::GetResIDFromAddr(pView->BufferLocation, id, offs); + + m_ListRecord->MarkResourceFrameReferenced(id, eFrameRef_Read); + } } } @@ -678,7 +696,13 @@ void WrappedID3D12GraphicsCommandList::IASetVertexBuffers(UINT StartSlot, UINT N m_ListRecord->AddChunk(scope.Get()); for(UINT i = 0; i < NumViews; i++) - m_ListRecord->MarkResourceFrameReferenced(GetResID(pViews[i].BufferLocation), eFrameRef_Read); + { + ResourceId id; + UINT64 offs = 0; + WrappedID3D12Resource::GetResIDFromAddr(pViews[i].BufferLocation, id, offs); + + m_ListRecord->MarkResourceFrameReferenced(id, eFrameRef_Read); + } } } diff --git a/renderdoc/driver/d3d12/d3d12_common.cpp b/renderdoc/driver/d3d12/d3d12_common.cpp index 03d11130d..bac2ab8a0 100644 --- a/renderdoc/driver/d3d12/d3d12_common.cpp +++ b/renderdoc/driver/d3d12/d3d12_common.cpp @@ -471,17 +471,19 @@ void Serialiser::Serialise(const char *name, D3D12_VERTEX_BUFFER_VIEW &el) D3D12ResourceManager *rm = (D3D12ResourceManager *)GetUserData(); ResourceId buffer; + UINT64 offs = 0; if(m_Mode == WRITING) - buffer = GetResID(el.BufferLocation); + WrappedID3D12Resource::GetResIDFromAddr(el.BufferLocation, buffer, offs); Serialise("BufferLocation", buffer); + Serialise("BufferLocation_Offset", offs); if(m_Mode == READING) { ID3D12Resource *res = rm->GetLiveAs(buffer); if(res) - el.BufferLocation = res->GetGPUVirtualAddress(); + el.BufferLocation = res->GetGPUVirtualAddress() + offs; else el.BufferLocation = 0; } @@ -498,17 +500,19 @@ void Serialiser::Serialise(const char *name, D3D12_INDEX_BUFFER_VIEW &el) D3D12ResourceManager *rm = (D3D12ResourceManager *)GetUserData(); ResourceId buffer; + UINT64 offs = 0; if(m_Mode == WRITING) - buffer = GetResID(el.BufferLocation); + WrappedID3D12Resource::GetResIDFromAddr(el.BufferLocation, buffer, offs); Serialise("BufferLocation", buffer); + Serialise("BufferLocation_Offset", offs); if(m_Mode == READING) { ID3D12Resource *res = rm->GetLiveAs(buffer); if(res) - el.BufferLocation = res->GetGPUVirtualAddress(); + el.BufferLocation = res->GetGPUVirtualAddress() + offs; else el.BufferLocation = 0; } @@ -525,17 +529,19 @@ void Serialiser::Serialise(const char *name, D3D12_CONSTANT_BUFFER_VIEW_DESC &el D3D12ResourceManager *rm = (D3D12ResourceManager *)GetUserData(); ResourceId buffer; + UINT64 offs = 0; if(m_Mode == WRITING) - buffer = GetResID(el.BufferLocation); + WrappedID3D12Resource::GetResIDFromAddr(el.BufferLocation, buffer, offs); Serialise("BufferLocation", buffer); + Serialise("BufferLocation_Offset", offs); if(m_Mode == READING) { ID3D12Resource *res = rm->GetLiveAs(buffer); if(res) - el.BufferLocation = res->GetGPUVirtualAddress(); + el.BufferLocation = res->GetGPUVirtualAddress() + offs; else el.BufferLocation = 0; } diff --git a/renderdoc/driver/d3d12/d3d12_resources.cpp b/renderdoc/driver/d3d12/d3d12_resources.cpp index afe182f99..950402b83 100644 --- a/renderdoc/driver/d3d12/d3d12_resources.cpp +++ b/renderdoc/driver/d3d12/d3d12_resources.cpp @@ -140,12 +140,6 @@ D3D12ResourceRecord *GetRecord(ID3D12DeviceChild *ptr) return res->GetResourceRecord(); } -template <> -ResourceId GetResID(D3D12_GPU_VIRTUAL_ADDRESS addr) -{ - return WrappedID3D12Resource::GetResIDFromAddr(addr); -} - WrappedID3D12DescriptorHeap::WrappedID3D12DescriptorHeap(ID3D12DescriptorHeap *real, WrappedID3D12Device *device, const D3D12_DESCRIPTOR_HEAP_DESC &desc) diff --git a/renderdoc/driver/d3d12/d3d12_resources.h b/renderdoc/driver/d3d12/d3d12_resources.h index 6b4208fcc..594747cd4 100644 --- a/renderdoc/driver/d3d12/d3d12_resources.h +++ b/renderdoc/driver/d3d12/d3d12_resources.h @@ -473,19 +473,23 @@ public: static std::map m_List; - static ResourceId GetResIDFromAddr(D3D12_GPU_VIRTUAL_ADDRESS addr) + static void GetResIDFromAddr(D3D12_GPU_VIRTUAL_ADDRESS addr, ResourceId &id, UINT64 &offs) { + id = ResourceId(); + offs = 0; + if(m_Addresses.empty()) - return ResourceId(); + return; auto it = std::lower_bound(m_Addresses.begin(), m_Addresses.end(), addr); if(it == m_Addresses.end()) - return ResourceId(); + return; if(addr < it->start || addr >= it->end) - return ResourceId(); + return; - return it->id; + id = it->id; + offs = addr - it->start; } enum @@ -685,7 +689,3 @@ template <> ID3D12DeviceChild *Unwrap(ID3D12DeviceChild *ptr); template <> D3D12ResourceRecord *GetRecord(ID3D12DeviceChild *ptr); - -// specialisations for looking up ID3D12Resource pointer from its D3D12_GPU_VIRTUAL_ADDRESS -template <> -ResourceId GetResID(D3D12_GPU_VIRTUAL_ADDRESS addr); \ No newline at end of file