Skip to content

Commit f5c7315

Browse files
magciusbaldurk
authored andcommitted
d3d12: Implement ID3D12SharingContract on the ID3D12CommandQueue
https://learn.microsoft.com/en-us/windows/win32/api/d3d12sdklayers/nn-d3d12sdklayers-id3d12sharingcontract says: > You may want to use this interface to enable diagnostic tools to > capture usage patterns that don't use DXGI swap chains for > presentation. If so, you can access this interface via > QueryInterface from a D3D12 command queue. Currently, this is implemented on the ID3D12Device. Implement it on the D3D12CommandQueue as well.
1 parent 1b5543e commit f5c7315

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

renderdoc/driver/d3d12/d3d12_command_queue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class WrappedID3D12CommandQueue : public ID3D12CommandQueue1,
183183

184184
WrappedID3D12DebugCommandQueue m_WrappedDebug;
185185
WrappedID3D12CompatibilityQueue m_WrappedCompat;
186+
WrappedID3D12SharingContract m_SharingContract;
186187

187188
rdcarray<D3D12ResourceRecord *> m_CmdListRecords;
188189
rdcarray<D3D12ResourceRecord *> m_CmdListAllocators;

renderdoc/driver/d3d12/d3d12_commands.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ WrappedID3D12CommandQueue::WrappedID3D12CommandQueue(ID3D12CommandQueue *real,
499499
m_pDevice(device),
500500
m_State(state),
501501
m_WrappedDownlevel(*this),
502-
m_WrappedCompat(*this)
502+
m_WrappedCompat(*this),
503+
m_SharingContract(*m_pDevice)
503504
{
504505
RenderDoc::Inst().RegisterMemoryRegion(this, sizeof(WrappedID3D12CommandQueue));
505506

@@ -513,6 +514,7 @@ WrappedID3D12CommandQueue::WrappedID3D12CommandQueue(ID3D12CommandQueue *real,
513514
m_pReal->QueryInterface(__uuidof(ID3D12CommandQueueDownlevel), (void **)&m_pDownlevel);
514515
m_pReal->QueryInterface(__uuidof(ID3D12CommandQueue1), (void **)&m_pReal1);
515516
m_pReal->QueryInterface(__uuidof(ID3D12CompatibilityQueue), (void **)&m_WrappedCompat.m_pReal);
517+
m_pReal->QueryInterface(__uuidof(ID3D12SharingContract), (void **)&m_SharingContract.m_pReal);
516518
}
517519

518520
if(RenderDoc::Inst().IsReplayApp())
@@ -573,6 +575,7 @@ WrappedID3D12CommandQueue::~WrappedID3D12CommandQueue()
573575
SAFE_RELEASE(m_WrappedCompat.m_pReal);
574576
SAFE_RELEASE(m_WrappedDebug.m_pReal);
575577
SAFE_RELEASE(m_WrappedDebug.m_pReal1);
578+
SAFE_RELEASE(m_SharingContract.m_pReal);
576579
SAFE_RELEASE(m_pReal);
577580
}
578581

@@ -629,6 +632,12 @@ HRESULT STDMETHODCALLTYPE WrappedID3D12CommandQueue::QueryInterface(REFIID riid,
629632
return E_NOINTERFACE;
630633
}
631634
}
635+
else if(riid == __uuidof(ID3D12SharingContract))
636+
{
637+
*ppvObject = (ID3D12SharingContract *)&m_SharingContract;
638+
AddRef();
639+
return S_OK;
640+
}
632641
else if(riid == __uuidof(ID3D12Pageable))
633642
{
634643
*ppvObject = (ID3D12Pageable *)this;

renderdoc/driver/d3d12/d3d12_device.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,25 +301,29 @@ void STDMETHODCALLTYPE WrappedID3D12SharingContract::Present(_In_ ID3D12Resource
301301

302302
m_pDevice.Present(NULL, this, 0, 0);
303303

304-
m_pReal->Present(Unwrap(pResource), Subresource, window);
304+
if(m_pReal != NULL)
305+
m_pReal->Present(Unwrap(pResource), Subresource, window);
305306
}
306307

307308
void STDMETHODCALLTYPE WrappedID3D12SharingContract::SharedFenceSignal(_In_ ID3D12Fence *pFence,
308309
UINT64 FenceValue)
309310
{
310-
m_pReal->SharedFenceSignal(Unwrap(pFence), FenceValue);
311+
if(m_pReal != NULL)
312+
m_pReal->SharedFenceSignal(Unwrap(pFence), FenceValue);
311313
}
312314

313315
void STDMETHODCALLTYPE WrappedID3D12SharingContract::BeginCapturableWork(_In_ REFGUID guid)
314316
{
315317
// undocumented what this does
316-
m_pReal->BeginCapturableWork(guid);
318+
if(m_pReal != NULL)
319+
m_pReal->BeginCapturableWork(guid);
317320
}
318321

319322
void STDMETHODCALLTYPE WrappedID3D12SharingContract::EndCapturableWork(_In_ REFGUID guid)
320323
{
321324
// undocumented what this does
322-
m_pReal->EndCapturableWork(guid);
325+
if(m_pReal != NULL)
326+
m_pReal->EndCapturableWork(guid);
323327
}
324328

325329
HRESULT STDMETHODCALLTYPE WrappedDRED::QueryInterface(REFIID riid, void **ppvObject)
@@ -1990,9 +1994,13 @@ IUnknown *WrappedID3D12Device::WrapSwapchainBuffer(IDXGISwapper *swapper, DXGI_F
19901994
FreeRTV(m_SwapChains[swapper].rtvs[buffer]);
19911995
m_SwapChains[swapper].rtvs[buffer] = rtv;
19921996

1993-
ID3DDevice *swapQ = swapper->GetD3DDevice();
1994-
RDCASSERT(WrappedID3D12CommandQueue::IsAlloc(swapQ));
1995-
m_SwapChains[swapper].queue = (WrappedID3D12CommandQueue *)swapQ;
1997+
ID3DDevice *swapDev = swapper->GetD3DDevice();
1998+
if(WrappedID3D12CommandQueue::IsAlloc(swapDev))
1999+
m_SwapChains[swapper].queue = (WrappedID3D12CommandQueue *)swapDev;
2000+
else if(swapDev == this)
2001+
m_SwapChains[swapper].queue = m_Queue;
2002+
else
2003+
RDCERR("Unexpected swapper D3D device");
19962004
}
19972005

19982006
return pRes;

0 commit comments

Comments
 (0)