When serialising GPU_VIRTUAL_ADDRESS, make sure to store offset as well

This commit is contained in:
baldurk
2016-07-28 11:57:14 +07:00
parent 5110782474
commit 6e5f8ae687
4 changed files with 50 additions and 26 deletions
@@ -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<WrappedID3D12Resource>(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);
}
}
}
+12 -6
View File
@@ -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<ID3D12Resource>(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<ID3D12Resource>(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<ID3D12Resource>(buffer);
if(res)
el.BufferLocation = res->GetGPUVirtualAddress();
el.BufferLocation = res->GetGPUVirtualAddress() + offs;
else
el.BufferLocation = 0;
}
@@ -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)
+9 -9
View File
@@ -473,19 +473,23 @@ public:
static std::map<ResourceId, WrappedID3D12Resource *> 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);