Wrap virtual address and descriptor handles, serialise as heap ID + idx

* This lets us track descriptor contents too.
This commit is contained in:
baldurk
2016-07-06 18:58:46 +03:00
parent 9f7dd21f1b
commit 4160f3a776
9 changed files with 492 additions and 57 deletions
@@ -449,13 +449,13 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRootSignature(ID3D12RootSignat
void WrappedID3D12GraphicsCommandList::SetComputeRootDescriptorTable(
UINT RootParameterIndex, D3D12_GPU_DESCRIPTOR_HANDLE BaseDescriptor)
{
m_pReal->SetComputeRootDescriptorTable(RootParameterIndex, BaseDescriptor);
m_pReal->SetComputeRootDescriptorTable(RootParameterIndex, Unwrap(BaseDescriptor));
}
void WrappedID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable(
UINT RootParameterIndex, D3D12_GPU_DESCRIPTOR_HANDLE BaseDescriptor)
{
m_pReal->SetGraphicsRootDescriptorTable(RootParameterIndex, BaseDescriptor);
m_pReal->SetGraphicsRootDescriptorTable(RootParameterIndex, Unwrap(BaseDescriptor));
}
void WrappedID3D12GraphicsCommandList::SetComputeRoot32BitConstant(UINT RootParameterIndex,
@@ -493,18 +493,20 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRoot32BitConstants(UINT RootPa
void WrappedID3D12GraphicsCommandList::SetComputeRootConstantBufferView(
UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation)
{
m_pReal->SetComputeRootConstantBufferView(RootParameterIndex, BufferLocation);
m_pReal->SetComputeRootConstantBufferView(RootParameterIndex, Unwrap(BufferLocation));
}
bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootConstantBufferView(
UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation)
{
SERIALISE_ELEMENT(UINT, idx, RootParameterIndex);
// TODO wrap and serialise buffer location as heap ID + idx
SERIALISE_ELEMENT(ResourceId, buffer, GetResID(BufferLocation));
if(m_State <= READING)
{
m_pReal->SetGraphicsRootConstantBufferView(idx, BufferLocation);
WrappedID3D12Resource *pRes = GetResourceManager()->GetLiveAs<WrappedID3D12Resource>(buffer);
m_pReal->SetGraphicsRootConstantBufferView(idx, pRes->GetGPU());
}
return true;
@@ -513,7 +515,7 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootConstantBufferVi
void WrappedID3D12GraphicsCommandList::SetGraphicsRootConstantBufferView(
UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation)
{
m_pReal->SetGraphicsRootConstantBufferView(RootParameterIndex, BufferLocation);
m_pReal->SetGraphicsRootConstantBufferView(RootParameterIndex, Unwrap(BufferLocation));
if(m_State >= WRITING)
{
@@ -527,25 +529,25 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRootConstantBufferView(
void WrappedID3D12GraphicsCommandList::SetComputeRootShaderResourceView(
UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation)
{
m_pReal->SetComputeRootShaderResourceView(RootParameterIndex, BufferLocation);
m_pReal->SetComputeRootShaderResourceView(RootParameterIndex, Unwrap(BufferLocation));
}
void WrappedID3D12GraphicsCommandList::SetGraphicsRootShaderResourceView(
UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation)
{
m_pReal->SetGraphicsRootShaderResourceView(RootParameterIndex, BufferLocation);
m_pReal->SetGraphicsRootShaderResourceView(RootParameterIndex, Unwrap(BufferLocation));
}
void WrappedID3D12GraphicsCommandList::SetComputeRootUnorderedAccessView(
UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation)
{
m_pReal->SetComputeRootUnorderedAccessView(RootParameterIndex, BufferLocation);
m_pReal->SetComputeRootUnorderedAccessView(RootParameterIndex, Unwrap(BufferLocation));
}
void WrappedID3D12GraphicsCommandList::SetGraphicsRootUnorderedAccessView(
UINT RootParameterIndex, D3D12_GPU_VIRTUAL_ADDRESS BufferLocation)
{
m_pReal->SetGraphicsRootUnorderedAccessView(RootParameterIndex, BufferLocation);
m_pReal->SetGraphicsRootUnorderedAccessView(RootParameterIndex, Unwrap(BufferLocation));
}
bool WrappedID3D12GraphicsCommandList::Serialise_IASetIndexBuffer(const D3D12_INDEX_BUFFER_VIEW *pView)
@@ -566,7 +568,17 @@ bool WrappedID3D12GraphicsCommandList::Serialise_IASetIndexBuffer(const D3D12_IN
void WrappedID3D12GraphicsCommandList::IASetIndexBuffer(const D3D12_INDEX_BUFFER_VIEW *pView)
{
m_pReal->IASetIndexBuffer(pView);
if(pView)
{
D3D12_INDEX_BUFFER_VIEW view = *pView;
view.BufferLocation = Unwrap(view.BufferLocation);
m_pReal->IASetIndexBuffer(&view);
}
else
{
m_pReal->IASetIndexBuffer(pView);
}
if(m_State >= WRITING)
{
@@ -597,7 +609,17 @@ bool WrappedID3D12GraphicsCommandList::Serialise_IASetVertexBuffers(
void WrappedID3D12GraphicsCommandList::IASetVertexBuffers(UINT StartSlot, UINT NumViews,
const D3D12_VERTEX_BUFFER_VIEW *pViews)
{
m_pReal->IASetVertexBuffers(StartSlot, NumViews, pViews);
D3D12_VERTEX_BUFFER_VIEW *unwrapped = new D3D12_VERTEX_BUFFER_VIEW[NumViews];
for(UINT i = 0; i < NumViews; i++)
{
unwrapped[i] = pViews[i];
unwrapped[i].BufferLocation = Unwrap(unwrapped[i].BufferLocation);
}
m_pReal->IASetVertexBuffers(StartSlot, NumViews, unwrapped);
SAFE_DELETE_ARRAY(unwrapped);
if(m_State >= WRITING)
{
@@ -611,7 +633,18 @@ void WrappedID3D12GraphicsCommandList::IASetVertexBuffers(UINT StartSlot, UINT N
void WrappedID3D12GraphicsCommandList::SOSetTargets(UINT StartSlot, UINT NumViews,
const D3D12_STREAM_OUTPUT_BUFFER_VIEW *pViews)
{
m_pReal->SOSetTargets(StartSlot, NumViews, pViews);
D3D12_STREAM_OUTPUT_BUFFER_VIEW *unwrapped = new D3D12_STREAM_OUTPUT_BUFFER_VIEW[NumViews];
for(UINT i = 0; i < NumViews; i++)
{
unwrapped[i] = pViews[i];
unwrapped[i].BufferLocation = Unwrap(unwrapped[i].BufferLocation);
unwrapped[i].BufferFilledSizeLocation = Unwrap(unwrapped[i].BufferFilledSizeLocation);
}
m_pReal->SOSetTargets(StartSlot, NumViews, unwrapped);
SAFE_DELETE_ARRAY(unwrapped);
}
bool WrappedID3D12GraphicsCommandList::Serialise_OMSetRenderTargets(
@@ -621,11 +654,36 @@ bool WrappedID3D12GraphicsCommandList::Serialise_OMSetRenderTargets(
SERIALISE_ELEMENT(UINT, num, NumRenderTargetDescriptors);
SERIALISE_ELEMENT(bool, singlehandle, RTsSingleHandleToDescriptorRange != FALSE);
// TODO unwrap and serialise handles as heaps + idxs
UINT numHandles = singlehandle ? 1U : num;
std::vector<PortableHandle> rts;
if(m_State >= WRITING)
{
rts.resize(numHandles);
// indexing pRenderTargetDescriptors with [i] is fine since if single handle is true,
// i will only ever be 0 (so we do equivalent of *pRenderTargetDescriptors)
for(UINT i = 0; i < numHandles; i++)
rts[i] = ToPortableHandle(pRenderTargetDescriptors[i]);
}
m_pSerialiser->Serialise("pRenderTargetDescriptors", rts);
SERIALISE_ELEMENT(PortableHandle, dsv, pDepthStencilDescriptor
? ToPortableHandle(*pDepthStencilDescriptor)
: PortableHandle(0));
if(m_State <= READING)
{
m_pReal->OMSetRenderTargets(num, NULL, singlehandle ? TRUE : FALSE, NULL);
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = FromPortableHandle(GetResourceManager(), dsv);
D3D12_CPU_DESCRIPTOR_HANDLE *rtHandles = new D3D12_CPU_DESCRIPTOR_HANDLE[numHandles];
for(UINT i = 0; i < numHandles; i++)
rtHandles[i] = FromPortableHandle(GetResourceManager(), rts[i]);
m_pReal->OMSetRenderTargets(num, rtHandles, singlehandle ? TRUE : FALSE,
dsv.heap != ResourceId() ? &dsvHandle : NULL);
}
return true;
@@ -635,8 +693,18 @@ void WrappedID3D12GraphicsCommandList::OMSetRenderTargets(
UINT NumRenderTargetDescriptors, const D3D12_CPU_DESCRIPTOR_HANDLE *pRenderTargetDescriptors,
BOOL RTsSingleHandleToDescriptorRange, const D3D12_CPU_DESCRIPTOR_HANDLE *pDepthStencilDescriptor)
{
m_pReal->OMSetRenderTargets(NumRenderTargetDescriptors, pRenderTargetDescriptors,
RTsSingleHandleToDescriptorRange, pDepthStencilDescriptor);
UINT numHandles = RTsSingleHandleToDescriptorRange ? 1U : NumRenderTargetDescriptors;
D3D12_CPU_DESCRIPTOR_HANDLE *unwrapped = new D3D12_CPU_DESCRIPTOR_HANDLE[numHandles];
for(UINT i = 0; i < numHandles; i++)
unwrapped[i] = Unwrap(pRenderTargetDescriptors[i]);
D3D12_CPU_DESCRIPTOR_HANDLE dsv =
pDepthStencilDescriptor ? Unwrap(*pDepthStencilDescriptor) : D3D12_CPU_DESCRIPTOR_HANDLE();
m_pReal->OMSetRenderTargets(NumRenderTargetDescriptors, unwrapped, RTsSingleHandleToDescriptorRange,
pDepthStencilDescriptor ? &dsv : NULL);
SAFE_DELETE_ARRAY(unwrapped);
if(m_State >= WRITING)
{
@@ -652,14 +720,15 @@ void WrappedID3D12GraphicsCommandList::ClearDepthStencilView(
D3D12_CPU_DESCRIPTOR_HANDLE DepthStencilView, D3D12_CLEAR_FLAGS ClearFlags, FLOAT Depth,
UINT8 Stencil, UINT NumRects, const D3D12_RECT *pRects)
{
m_pReal->ClearDepthStencilView(DepthStencilView, ClearFlags, Depth, Stencil, NumRects, pRects);
m_pReal->ClearDepthStencilView(Unwrap(DepthStencilView), ClearFlags, Depth, Stencil, NumRects,
pRects);
}
bool WrappedID3D12GraphicsCommandList::Serialise_ClearRenderTargetView(
D3D12_CPU_DESCRIPTOR_HANDLE RenderTargetView, const FLOAT ColorRGBA[4], UINT NumRects,
const D3D12_RECT *pRects)
{
// TODO unwrap and serialise handle as heap + idx
SERIALISE_ELEMENT(PortableHandle, rtv, ToPortableHandle(RenderTargetView));
float Color[4] = {0};
@@ -673,6 +742,8 @@ bool WrappedID3D12GraphicsCommandList::Serialise_ClearRenderTargetView(
if(m_State <= READING)
{
RenderTargetView = FromPortableHandle(GetResourceManager(), rtv);
m_pReal->ClearRenderTargetView(RenderTargetView, Color, num, rects);
}
@@ -685,7 +756,7 @@ void WrappedID3D12GraphicsCommandList::ClearRenderTargetView(
D3D12_CPU_DESCRIPTOR_HANDLE RenderTargetView, const FLOAT ColorRGBA[4], UINT NumRects,
const D3D12_RECT *pRects)
{
m_pReal->ClearRenderTargetView(RenderTargetView, ColorRGBA, NumRects, pRects);
m_pReal->ClearRenderTargetView(Unwrap(RenderTargetView), ColorRGBA, NumRects, pRects);
if(m_State >= WRITING)
{
@@ -700,7 +771,7 @@ void WrappedID3D12GraphicsCommandList::ClearUnorderedAccessViewUint(
D3D12_GPU_DESCRIPTOR_HANDLE ViewGPUHandleInCurrentHeap, D3D12_CPU_DESCRIPTOR_HANDLE ViewCPUHandle,
ID3D12Resource *pResource, const UINT Values[4], UINT NumRects, const D3D12_RECT *pRects)
{
m_pReal->ClearUnorderedAccessViewUint(ViewGPUHandleInCurrentHeap, ViewCPUHandle,
m_pReal->ClearUnorderedAccessViewUint(Unwrap(ViewGPUHandleInCurrentHeap), ViewCPUHandle,
Unwrap(pResource), Values, NumRects, pRects);
}
@@ -708,7 +779,7 @@ void WrappedID3D12GraphicsCommandList::ClearUnorderedAccessViewFloat(
D3D12_GPU_DESCRIPTOR_HANDLE ViewGPUHandleInCurrentHeap, D3D12_CPU_DESCRIPTOR_HANDLE ViewCPUHandle,
ID3D12Resource *pResource, const FLOAT Values[4], UINT NumRects, const D3D12_RECT *pRects)
{
m_pReal->ClearUnorderedAccessViewFloat(ViewGPUHandleInCurrentHeap, ViewCPUHandle,
m_pReal->ClearUnorderedAccessViewFloat(Unwrap(ViewGPUHandleInCurrentHeap), ViewCPUHandle,
Unwrap(pResource), Values, NumRects, pRects);
}
+36 -2
View File
@@ -336,7 +336,24 @@ void Serialiser::Serialise(const char *name, D3D12_VERTEX_BUFFER_VIEW &el)
{
ScopedContext scope(this, name, "D3D12_VERTEX_BUFFER_VIEW", 0, true);
// TODO serialise gpu virtual address as heap ID and idx
D3D12ResourceManager *rm = (D3D12ResourceManager *)GetUserData();
ResourceId buffer;
if(m_Mode == WRITING)
buffer = GetResID(el.BufferLocation);
Serialise("BufferLocation", buffer);
if(m_Mode == READING)
{
ID3D12Resource *res = rm->GetLiveAs<ID3D12Resource>(buffer);
if(res)
el.BufferLocation = Unwrap(res->GetGPUVirtualAddress());
else
el.BufferLocation = 0;
}
Serialise("SizeInBytes", el.SizeInBytes);
Serialise("StrideInBytes", el.StrideInBytes);
}
@@ -346,7 +363,24 @@ void Serialiser::Serialise(const char *name, D3D12_INDEX_BUFFER_VIEW &el)
{
ScopedContext scope(this, name, "D3D12_INDEX_BUFFER_VIEW", 0, true);
// TODO serialise gpu virtual address as heap ID and idx
D3D12ResourceManager *rm = (D3D12ResourceManager *)GetUserData();
ResourceId buffer;
if(m_Mode == WRITING)
buffer = GetResID(el.BufferLocation);
Serialise("BufferLocation", buffer);
if(m_Mode == READING)
{
ID3D12Resource *res = rm->GetLiveAs<ID3D12Resource>(buffer);
if(res)
el.BufferLocation = Unwrap(res->GetGPUVirtualAddress());
else
el.BufferLocation = 0;
}
Serialise("SizeInBytes", el.SizeInBytes);
Serialise("Format", el.Format);
}
+4
View File
@@ -163,6 +163,10 @@ WrappedID3D12Device::WrappedID3D12Device(ID3D12Device *realDevice, D3D12InitPara
if(RenderDoc::Inst().GetCrashHandler())
RenderDoc::Inst().GetCrashHandler()->RegisterMemoryRegion(this, sizeof(WrappedID3D12Device));
for(size_t i = 0; i < ARRAY_COUNT(m_DescriptorIncrements); i++)
m_DescriptorIncrements[i] =
realDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE(i));
// refcounters implicitly construct with one reference, but we don't start with any soft
// references.
m_SoftRefCounter.Release();
+7
View File
@@ -240,6 +240,8 @@ private:
map<WrappedIDXGISwapChain3 *, D3D12_CPU_DESCRIPTOR_HANDLE> m_SwapChains;
UINT m_DescriptorIncrements[D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES];
public:
static const int AllocPoolCount = 4;
ALLOCATE_WITH_WRAPPED_POOL(WrappedID3D12Device, AllocPoolCount);
@@ -247,6 +249,11 @@ public:
WrappedID3D12Device(ID3D12Device *realDevice, D3D12InitParams *params);
virtual ~WrappedID3D12Device();
UINT GetDescriptorIncrement(D3D12_DESCRIPTOR_HEAP_TYPE type)
{
return m_DescriptorIncrements[type];
}
////////////////////////////////////////////////////////////////
// non wrapping interface
+42 -16
View File
@@ -363,7 +363,7 @@ bool WrappedID3D12Device::Serialise_CreateDescriptorHeap(
}
else
{
ret = new WrappedID3D12DescriptorHeap(ret, this);
ret = new WrappedID3D12DescriptorHeap(ret, this, Descriptor);
GetResourceManager()->AddLiveResource(Heap, ret);
}
@@ -388,7 +388,8 @@ HRESULT WrappedID3D12Device::CreateDescriptorHeap(const D3D12_DESCRIPTOR_HEAP_DE
{
SCOPED_LOCK(m_D3DLock);
WrappedID3D12DescriptorHeap *wrapped = new WrappedID3D12DescriptorHeap(real, this);
WrappedID3D12DescriptorHeap *wrapped =
new WrappedID3D12DescriptorHeap(real, this, *pDescriptorHeapDesc);
if(m_State >= WRITING)
{
@@ -476,14 +477,24 @@ HRESULT WrappedID3D12Device::CreateRootSignature(UINT nodeMask, const void *pBlo
void WrappedID3D12Device::CreateConstantBufferView(const D3D12_CONSTANT_BUFFER_VIEW_DESC *pDesc,
D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor)
{
return m_pDevice->CreateConstantBufferView(pDesc, DestDescriptor);
GetWrapped(DestDescriptor)->Init(pDesc);
D3D12_CONSTANT_BUFFER_VIEW_DESC desc;
if(pDesc)
{
desc = *pDesc;
desc.BufferLocation = Unwrap(desc.BufferLocation);
}
return m_pDevice->CreateConstantBufferView(pDesc ? &desc : NULL, Unwrap(DestDescriptor));
}
void WrappedID3D12Device::CreateShaderResourceView(ID3D12Resource *pResource,
const D3D12_SHADER_RESOURCE_VIEW_DESC *pDesc,
D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor)
{
return m_pDevice->CreateShaderResourceView(Unwrap(pResource), pDesc, DestDescriptor);
GetWrapped(DestDescriptor)->Init(pResource, pDesc);
return m_pDevice->CreateShaderResourceView(Unwrap(pResource), pDesc, Unwrap(DestDescriptor));
}
void WrappedID3D12Device::CreateUnorderedAccessView(ID3D12Resource *pResource,
@@ -491,29 +502,32 @@ void WrappedID3D12Device::CreateUnorderedAccessView(ID3D12Resource *pResource,
const D3D12_UNORDERED_ACCESS_VIEW_DESC *pDesc,
D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor)
{
GetWrapped(DestDescriptor)->Init(pResource, pCounterResource, pDesc);
return m_pDevice->CreateUnorderedAccessView(Unwrap(pResource), Unwrap(pCounterResource), pDesc,
DestDescriptor);
Unwrap(DestDescriptor));
}
void WrappedID3D12Device::CreateRenderTargetView(ID3D12Resource *pResource,
const D3D12_RENDER_TARGET_VIEW_DESC *pDesc,
D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor)
{
D3D12NOTIMP(__FUNCSIG__);
return m_pDevice->CreateRenderTargetView(Unwrap(pResource), pDesc, DestDescriptor);
GetWrapped(DestDescriptor)->Init(pResource, pDesc);
return m_pDevice->CreateRenderTargetView(Unwrap(pResource), pDesc, Unwrap(DestDescriptor));
}
void WrappedID3D12Device::CreateDepthStencilView(ID3D12Resource *pResource,
const D3D12_DEPTH_STENCIL_VIEW_DESC *pDesc,
D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor)
{
return m_pDevice->CreateDepthStencilView(Unwrap(pResource), pDesc, DestDescriptor);
GetWrapped(DestDescriptor)->Init(pResource, pDesc);
return m_pDevice->CreateDepthStencilView(Unwrap(pResource), pDesc, Unwrap(DestDescriptor));
}
void WrappedID3D12Device::CreateSampler(const D3D12_SAMPLER_DESC *pDesc,
D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor)
{
return m_pDevice->CreateSampler(pDesc, DestDescriptor);
GetWrapped(DestDescriptor)->Init(pDesc);
return m_pDevice->CreateSampler(pDesc, Unwrap(DestDescriptor));
}
bool WrappedID3D12Device::Serialise_CreateCommittedResource(
@@ -707,10 +721,21 @@ void WrappedID3D12Device::CopyDescriptors(
const D3D12_CPU_DESCRIPTOR_HANDLE *pSrcDescriptorRangeStarts,
const UINT *pSrcDescriptorRangeSizes, D3D12_DESCRIPTOR_HEAP_TYPE DescriptorHeapsType)
{
return m_pDevice->CopyDescriptors(NumDestDescriptorRanges, pDestDescriptorRangeStarts,
pDestDescriptorRangeSizes, NumSrcDescriptorRanges,
pSrcDescriptorRangeStarts, pSrcDescriptorRangeSizes,
DescriptorHeapsType);
D3D12_CPU_DESCRIPTOR_HANDLE *dstStarts = new D3D12_CPU_DESCRIPTOR_HANDLE[NumDestDescriptorRanges];
D3D12_CPU_DESCRIPTOR_HANDLE *srcStarts = new D3D12_CPU_DESCRIPTOR_HANDLE[NumSrcDescriptorRanges];
for(UINT i = 0; i < NumDestDescriptorRanges; i++)
dstStarts[i] = Unwrap(pDestDescriptorRangeStarts[i]);
for(UINT i = 0; i < NumDestDescriptorRanges; i++)
srcStarts[i] = Unwrap(pSrcDescriptorRangeStarts[i]);
m_pDevice->CopyDescriptors(NumDestDescriptorRanges, dstStarts, pDestDescriptorRangeSizes,
NumSrcDescriptorRanges, srcStarts, pSrcDescriptorRangeSizes,
DescriptorHeapsType);
SAFE_DELETE_ARRAY(dstStarts);
SAFE_DELETE_ARRAY(srcStarts);
}
void WrappedID3D12Device::CopyDescriptorsSimple(UINT NumDescriptors,
@@ -718,8 +743,8 @@ void WrappedID3D12Device::CopyDescriptorsSimple(UINT NumDescriptors,
D3D12_CPU_DESCRIPTOR_HANDLE SrcDescriptorRangeStart,
D3D12_DESCRIPTOR_HEAP_TYPE DescriptorHeapsType)
{
return m_pDevice->CopyDescriptorsSimple(NumDescriptors, DestDescriptorRangeStart,
SrcDescriptorRangeStart, DescriptorHeapsType);
m_pDevice->CopyDescriptorsSimple(NumDescriptors, Unwrap(DestDescriptorRangeStart),
Unwrap(SrcDescriptorRangeStart), DescriptorHeapsType);
}
HRESULT WrappedID3D12Device::OpenSharedHandle(HANDLE NTHandle, REFIID riid, void **ppvObj)
@@ -801,7 +826,8 @@ HRESULT WrappedID3D12Device::CheckFeatureSupport(D3D12_FEATURE Feature, void *pF
UINT WrappedID3D12Device::GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE DescriptorHeapType)
{
return m_pDevice->GetDescriptorHandleIncrementSize(DescriptorHeapType);
// we essentially intercept this, so it's a fixed size.
return sizeof(D3D12Descriptor);
}
D3D12_RESOURCE_ALLOCATION_INFO WrappedID3D12Device::GetResourceAllocationInfo(
+107
View File
@@ -26,6 +26,113 @@
#include "d3d12_device.h"
#include "d3d12_resources.h"
void D3D12Descriptor::Init(const D3D12_SAMPLER_DESC *pDesc)
{
if(pDesc)
samp.desc = *pDesc;
else
RDCEraseEl(samp.desc);
}
void D3D12Descriptor::Init(const D3D12_CONSTANT_BUFFER_VIEW_DESC *pDesc)
{
nonsamp.type = TypeCBV;
nonsamp.resource = NULL;
if(pDesc)
nonsamp.cbv = *pDesc;
else
RDCEraseEl(nonsamp.cbv);
}
void D3D12Descriptor::Init(ID3D12Resource *pResource, const D3D12_SHADER_RESOURCE_VIEW_DESC *pDesc)
{
nonsamp.type = TypeSRV;
nonsamp.resource = pResource;
if(pDesc)
nonsamp.srv = *pDesc;
else
RDCEraseEl(nonsamp.srv);
}
void D3D12Descriptor::Init(ID3D12Resource *pResource, ID3D12Resource *pCounterResource,
const D3D12_UNORDERED_ACCESS_VIEW_DESC *pDesc)
{
nonsamp.type = TypeUAV;
nonsamp.resource = pResource;
nonsamp.uav.counterResource = pCounterResource;
if(pDesc)
nonsamp.uav.desc.Init(*pDesc);
else
RDCEraseEl(nonsamp.uav.desc);
}
void D3D12Descriptor::Init(ID3D12Resource *pResource, const D3D12_RENDER_TARGET_VIEW_DESC *pDesc)
{
nonsamp.type = TypeRTV;
nonsamp.resource = pResource;
if(pDesc)
nonsamp.rtv = *pDesc;
else
RDCEraseEl(nonsamp.rtv);
}
void D3D12Descriptor::Init(ID3D12Resource *pResource, const D3D12_DEPTH_STENCIL_VIEW_DESC *pDesc)
{
nonsamp.type = TypeDSV;
nonsamp.resource = pResource;
if(pDesc)
nonsamp.dsv = *pDesc;
else
RDCEraseEl(nonsamp.dsv);
}
D3D12_CPU_DESCRIPTOR_HANDLE Unwrap(D3D12_CPU_DESCRIPTOR_HANDLE handle)
{
if(handle.ptr == 0)
return handle;
D3D12Descriptor *desc = GetWrapped(handle);
return desc->samp.heap->GetCPU(desc->samp.idx);
}
D3D12_GPU_DESCRIPTOR_HANDLE Unwrap(D3D12_GPU_DESCRIPTOR_HANDLE handle)
{
if(handle.ptr == 0)
return handle;
D3D12Descriptor *desc = GetWrapped(handle);
return desc->samp.heap->GetGPU(desc->samp.idx);
}
PortableHandle ToPortableHandle(D3D12_CPU_DESCRIPTOR_HANDLE handle)
{
if(handle.ptr == 0)
return PortableHandle(0);
D3D12Descriptor *desc = GetWrapped(handle);
return PortableHandle(GetResID(desc->samp.heap), desc->samp.idx);
}
D3D12_CPU_DESCRIPTOR_HANDLE FromPortableHandle(D3D12ResourceManager *manager, PortableHandle handle)
{
if(handle.heap == ResourceId())
return D3D12_CPU_DESCRIPTOR_HANDLE();
WrappedID3D12DescriptorHeap *heap = manager->GetLiveAs<WrappedID3D12DescriptorHeap>(handle.heap);
if(heap)
return heap->GetCPU(handle.index);
return D3D12_CPU_DESCRIPTOR_HANDLE();
}
string ToStrHelper<false, PortableHandle>::Get(const PortableHandle &el)
{
return StringFormat::Fmt("D3D12_CPU_DESCRIPTOR_HANDLE %s[%u]", ToStr::Get(el.heap).c_str(),
el.index);
}
bool D3D12ResourceManager::SerialisableResource(ResourceId id, D3D12ResourceRecord *record)
{
if(id == m_Device->GetResourceID())
+109 -3
View File
@@ -31,6 +31,73 @@
#include "driver/d3d12/d3d12_common.h"
#include "serialise/serialiser.h"
class WrappedID3D12DescriptorHeap;
// squeeze the descriptor a bit so that the below struct fits in 64 bytes
struct D3D12_UNORDERED_ACCESS_VIEW_DESC_SQUEEZED
{
// pull up and compress down to 1 byte the enums/flags that don't have any larger values
uint8_t Format;
uint8_t ViewDimension;
uint8_t BufferFlags;
// 5 more bytes here - below union is 8-byte aligned
union
{
struct D3D12_BUFFER_UAV_SQUEEZED
{
UINT64 FirstElement;
UINT NumElements;
UINT StructureByteStride;
UINT64 CounterOffsetInBytes;
} Buffer;
D3D12_TEX1D_UAV Texture1D;
D3D12_TEX1D_ARRAY_UAV Texture1DArray;
D3D12_TEX2D_UAV Texture2D;
D3D12_TEX2D_ARRAY_UAV Texture2DArray;
D3D12_TEX3D_UAV Texture3D;
};
void Init(const D3D12_UNORDERED_ACCESS_VIEW_DESC &desc)
{
Format = (uint8_t)desc.Format;
ViewDimension = (uint8_t)desc.ViewDimension;
// all but buffer elements should fit in 4 UINTs, so we can copy the Buffer (minus the flags we
// moved) and still cover them.
RDCCOMPILE_ASSERT(sizeof(Texture1D) <= 4 * sizeof(UINT), "Buffer isn't largest union member!");
RDCCOMPILE_ASSERT(sizeof(Texture1DArray) <= 4 * sizeof(UINT),
"Buffer isn't largest union member!");
RDCCOMPILE_ASSERT(sizeof(Texture2D) <= 4 * sizeof(UINT), "Buffer isn't largest union member!");
RDCCOMPILE_ASSERT(sizeof(Texture2DArray) <= 4 * sizeof(UINT),
"Buffer isn't largest union member!");
RDCCOMPILE_ASSERT(sizeof(Texture3D) <= 4 * sizeof(UINT), "Buffer isn't largest union member!");
Buffer.FirstElement = desc.Buffer.FirstElement;
Buffer.NumElements = desc.Buffer.NumElements;
Buffer.StructureByteStride = desc.Buffer.StructureByteStride;
Buffer.CounterOffsetInBytes = desc.Buffer.CounterOffsetInBytes;
BufferFlags = (uint8_t)desc.Buffer.Flags;
}
D3D12_UNORDERED_ACCESS_VIEW_DESC AsDesc() const
{
D3D12_UNORDERED_ACCESS_VIEW_DESC desc = {};
desc.Format = (DXGI_FORMAT)Format;
desc.ViewDimension = (D3D12_UAV_DIMENSION)ViewDimension;
desc.Buffer.FirstElement = Buffer.FirstElement;
desc.Buffer.NumElements = Buffer.NumElements;
desc.Buffer.StructureByteStride = Buffer.StructureByteStride;
desc.Buffer.CounterOffsetInBytes = Buffer.CounterOffsetInBytes;
desc.Buffer.Flags = (D3D12_BUFFER_UAV_FLAGS)BufferFlags;
return desc;
}
};
struct D3D12Descriptor
{
enum DescriptorType
@@ -55,13 +122,21 @@ struct D3D12Descriptor
return nonsamp.type;
}
void Init(const D3D12_SAMPLER_DESC *pDesc);
void Init(const D3D12_CONSTANT_BUFFER_VIEW_DESC *pDesc);
void Init(ID3D12Resource *pResource, const D3D12_SHADER_RESOURCE_VIEW_DESC *pDesc);
void Init(ID3D12Resource *pResource, ID3D12Resource *pCounterResource,
const D3D12_UNORDERED_ACCESS_VIEW_DESC *pDesc);
void Init(ID3D12Resource *pResource, const D3D12_RENDER_TARGET_VIEW_DESC *pDesc);
void Init(ID3D12Resource *pResource, const D3D12_DEPTH_STENCIL_VIEW_DESC *pDesc);
union
{
// keep the sampler outside as it's the largest descriptor
struct
{
// same location in both structs
ID3D12DescriptorHeap *heap;
WrappedID3D12DescriptorHeap *heap;
uint32_t idx;
D3D12_SAMPLER_DESC desc;
@@ -70,7 +145,7 @@ struct D3D12Descriptor
struct
{
// same location in both structs
ID3D12DescriptorHeap *heap;
WrappedID3D12DescriptorHeap *heap;
uint32_t idx;
// this element overlaps with the D3D12_FILTER in D3D12_SAMPLER_DESC,
@@ -83,7 +158,11 @@ struct D3D12Descriptor
{
D3D12_CONSTANT_BUFFER_VIEW_DESC cbv;
D3D12_SHADER_RESOURCE_VIEW_DESC srv;
D3D12_UNORDERED_ACCESS_VIEW_DESC uav;
struct
{
ID3D12Resource *counterResource;
D3D12_UNORDERED_ACCESS_VIEW_DESC_SQUEEZED desc;
} uav;
D3D12_RENDER_TARGET_VIEW_DESC rtv;
D3D12_DEPTH_STENCIL_VIEW_DESC dsv;
};
@@ -91,6 +170,33 @@ struct D3D12Descriptor
};
};
inline D3D12Descriptor *GetWrapped(D3D12_CPU_DESCRIPTOR_HANDLE handle)
{
return (D3D12Descriptor *)handle.ptr;
}
inline D3D12Descriptor *GetWrapped(D3D12_GPU_DESCRIPTOR_HANDLE handle)
{
return (D3D12Descriptor *)handle.ptr;
}
D3D12_CPU_DESCRIPTOR_HANDLE Unwrap(D3D12_CPU_DESCRIPTOR_HANDLE handle);
D3D12_GPU_DESCRIPTOR_HANDLE Unwrap(D3D12_GPU_DESCRIPTOR_HANDLE handle);
struct PortableHandle
{
PortableHandle() {}
PortableHandle(ResourceId id, uint32_t i) : heap(id), index(i) {}
PortableHandle(uint32_t i) : index(i) {}
ResourceId heap;
uint32_t index;
};
class D3D12ResourceManager;
PortableHandle ToPortableHandle(D3D12_CPU_DESCRIPTOR_HANDLE handle);
D3D12_CPU_DESCRIPTOR_HANDLE FromPortableHandle(D3D12ResourceManager *manager, PortableHandle handle);
struct D3D12ResourceRecord : public ResourceRecord
{
enum
@@ -124,3 +124,50 @@ D3D12ResourceRecord *GetRecord(ID3D12DeviceChild *ptr)
return res->GetResourceRecord();
}
template <>
D3D12_GPU_VIRTUAL_ADDRESS Unwrap(D3D12_GPU_VIRTUAL_ADDRESS addr)
{
if(addr == 0)
return addr;
WrappedID3D12Resource *res = (WrappedID3D12Resource *)addr;
return res->GetGPU();
}
template <>
ResourceId GetResID(D3D12_GPU_VIRTUAL_ADDRESS addr)
{
if(addr == 0)
return ResourceId();
WrappedID3D12Resource *res = (WrappedID3D12Resource *)addr;
return res->GetResourceID();
}
WrappedID3D12DescriptorHeap::WrappedID3D12DescriptorHeap(ID3D12DescriptorHeap *real,
WrappedID3D12Device *device,
const D3D12_DESCRIPTOR_HEAP_DESC &desc)
: WrappedDeviceChild12(real, device)
{
realCPUBase = real->GetCPUDescriptorHandleForHeapStart();
realGPUBase = real->GetGPUDescriptorHandleForHeapStart();
increment = device->GetDescriptorIncrement(desc.Type);
descriptors = new D3D12Descriptor[desc.NumDescriptors];
RDCEraseMem(descriptors, sizeof(D3D12Descriptor) * desc.NumDescriptors);
for(UINT i = 0; i < desc.NumDescriptors; i++)
{
// only need to set this once, it's aliased between samp and nonsamp
descriptors[i].samp.heap = this;
descriptors[i].samp.idx = i;
}
}
WrappedID3D12DescriptorHeap::~WrappedID3D12DescriptorHeap()
{
Shutdown();
SAFE_DELETE_ARRAY(descriptors);
}
+47 -14
View File
@@ -314,8 +314,17 @@ public:
virtual ~WrappedID3D12CommandSignature() { Shutdown(); }
};
struct D3D12Descriptor;
class WrappedID3D12DescriptorHeap : public WrappedDeviceChild12<ID3D12DescriptorHeap>
{
D3D12_CPU_DESCRIPTOR_HANDLE realCPUBase;
D3D12_GPU_DESCRIPTOR_HANDLE realGPUBase;
UINT increment;
D3D12Descriptor *descriptors;
public:
ALLOCATE_WITH_WRAPPED_POOL(WrappedID3D12DescriptorHeap);
@@ -324,23 +333,40 @@ public:
TypeEnum = Resource_DescriptorHeap,
};
WrappedID3D12DescriptorHeap(ID3D12DescriptorHeap *real, WrappedID3D12Device *device)
: WrappedDeviceChild12(real, device)
{
}
virtual ~WrappedID3D12DescriptorHeap() { Shutdown(); }
WrappedID3D12DescriptorHeap(ID3D12DescriptorHeap *real, WrappedID3D12Device *device,
const D3D12_DESCRIPTOR_HEAP_DESC &desc);
virtual ~WrappedID3D12DescriptorHeap();
//////////////////////////////
// implement ID3D12DescriptorHeap
virtual D3D12_DESCRIPTOR_HEAP_DESC STDMETHODCALLTYPE GetDesc() { return m_pReal->GetDesc(); }
virtual D3D12_CPU_DESCRIPTOR_HANDLE STDMETHODCALLTYPE GetCPUDescriptorHandleForHeapStart()
{
return m_pReal->GetCPUDescriptorHandleForHeapStart();
D3D12_CPU_DESCRIPTOR_HANDLE handle;
handle.ptr = (SIZE_T)descriptors;
return handle;
}
virtual D3D12_GPU_DESCRIPTOR_HANDLE STDMETHODCALLTYPE GetGPUDescriptorHandleForHeapStart()
{
return m_pReal->GetGPUDescriptorHandleForHeapStart();
D3D12_GPU_DESCRIPTOR_HANDLE handle;
handle.ptr = (UINT64)descriptors;
return handle;
}
D3D12_CPU_DESCRIPTOR_HANDLE GetCPU(uint32_t idx)
{
D3D12_CPU_DESCRIPTOR_HANDLE handle = realCPUBase;
handle.ptr += idx * increment;
return handle;
}
D3D12_GPU_DESCRIPTOR_HANDLE GetGPU(uint32_t idx)
{
D3D12_GPU_DESCRIPTOR_HANDLE handle = realGPUBase;
handle.ptr += idx * increment;
return handle;
}
};
@@ -464,9 +490,10 @@ public:
virtual D3D12_RESOURCE_DESC STDMETHODCALLTYPE GetDesc() { return m_pReal->GetDesc(); }
virtual D3D12_GPU_VIRTUAL_ADDRESS STDMETHODCALLTYPE GetGPUVirtualAddress()
{
return m_pReal->GetGPUVirtualAddress();
return (D3D12_GPU_VIRTUAL_ADDRESS) this;
}
D3D12_GPU_VIRTUAL_ADDRESS GetGPU() { return m_pReal->GetGPUVirtualAddress(); }
virtual HRESULT STDMETHODCALLTYPE WriteToSubresource(UINT DstSubresource, const D3D12_BOX *pDstBox,
const void *pSrcData, UINT SrcRowPitch,
UINT SrcDepthPitch)
@@ -572,8 +599,8 @@ typename UnwrapHelper<iface>::Outer *GetWrapped(iface *obj)
// or record
TrackedResource *GetTracked(ID3D12DeviceChild *ptr);
template <typename iface>
iface *Unwrap(iface *obj)
template <typename ifaceptr>
ifaceptr Unwrap(ifaceptr obj)
{
if(obj == NULL)
return NULL;
@@ -581,8 +608,8 @@ iface *Unwrap(iface *obj)
return GetWrapped(obj)->GetReal();
}
template <typename iface>
ResourceId GetResID(iface *obj)
template <typename ifaceptr>
ResourceId GetResID(ifaceptr obj)
{
if(obj == NULL)
return ResourceId();
@@ -590,8 +617,8 @@ ResourceId GetResID(iface *obj)
return GetWrapped(obj)->GetResourceID();
}
template <typename iface>
D3D12ResourceRecord *GetRecord(iface *obj)
template <typename ifaceptr>
D3D12ResourceRecord *GetRecord(ifaceptr obj)
{
if(obj == NULL)
return NULL;
@@ -606,3 +633,9 @@ template <>
ID3D12DeviceChild *Unwrap(ID3D12DeviceChild *ptr);
template <>
D3D12ResourceRecord *GetRecord(ID3D12DeviceChild *ptr);
// specialisations for aliasing ID3D12Resource pointer as a D3D12_GPU_VIRTUAL_ADDRESS
template <>
D3D12_GPU_VIRTUAL_ADDRESS Unwrap(D3D12_GPU_VIRTUAL_ADDRESS addr);
template <>
ResourceId GetResID(D3D12_GPU_VIRTUAL_ADDRESS addr);