From 92f48ea54b777d9f0a62027cec05195acb11b71e Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 12 Dec 2018 15:05:55 +0000 Subject: [PATCH] Implement ID3D11Multithread support for automatic locking * Unfortunately ID3D11Multithread::SetMultithreadProtected adds an auto-locking thread safe mode for all D3D functions, so we have to add a check for it and a lock to every context function. This will add a small amount of overhead even when the mode isn't enabled, but it shouldn't be significant. --- renderdoc/common/threading.h | 17 +- renderdoc/driver/d3d11/d3d11_context.cpp | 4 +- .../driver/d3d11/d3d11_context1_wrap.cpp | 38 ++++ .../driver/d3d11/d3d11_context2_wrap.cpp | 7 + .../driver/d3d11/d3d11_context3_wrap.cpp | 1 + renderdoc/driver/d3d11/d3d11_context_wrap.cpp | 208 ++++++++++++++++++ renderdoc/driver/d3d11/d3d11_device.cpp | 84 +++++-- renderdoc/driver/d3d11/d3d11_device.h | 47 ++-- renderdoc/driver/d3d11/d3d11_resources.h | 5 + renderdoc/driver/dxgi/dxgi_wrapped.cpp | 5 + renderdoc/driver/dxgi/dxgi_wrapped.h | 1 + 11 files changed, 361 insertions(+), 56 deletions(-) diff --git a/renderdoc/common/threading.h b/renderdoc/common/threading.h index 59c8ff459..716509c07 100644 --- a/renderdoc/common/threading.h +++ b/renderdoc/common/threading.h @@ -32,8 +32,17 @@ namespace Threading class ScopedLock { public: - ScopedLock(CriticalSection &cs) : m_CS(&cs) { m_CS->Lock(); } - ~ScopedLock() { m_CS->Unlock(); } + ScopedLock(CriticalSection *cs) : m_CS(cs) + { + if(m_CS) + m_CS->Lock(); + } + ~ScopedLock() + { + if(m_CS) + m_CS->Unlock(); + } + private: CriticalSection *m_CS; }; @@ -82,7 +91,9 @@ private: }; }; -#define SCOPED_LOCK(cs) Threading::ScopedLock CONCAT(scopedlock, __LINE__)(cs); +#define SCOPED_LOCK(cs) Threading::ScopedLock CONCAT(scopedlock, __LINE__)(&cs); +#define SCOPED_LOCK_OPTIONAL(cs, cond) \ + Threading::ScopedLock CONCAT(scopedlock, __LINE__)(cond ? &cs : NULL); #define SCOPED_READLOCK(rw) Threading::ScopedReadLock CONCAT(scopedlock, __LINE__)(rw); #define SCOPED_WRITELOCK(rw) Threading::ScopedWriteLock CONCAT(scopedlock, __LINE__)(rw); diff --git a/renderdoc/driver/d3d11/d3d11_context.cpp b/renderdoc/driver/d3d11/d3d11_context.cpp index f80907df6..00cf7b1af 100644 --- a/renderdoc/driver/d3d11/d3d11_context.cpp +++ b/renderdoc/driver/d3d11/d3d11_context.cpp @@ -1402,8 +1402,8 @@ HRESULT STDMETHODCALLTYPE WrappedID3D11DeviceContext::QueryInterface(REFIID riid } else if(riid == __uuidof(ID3D11Multithread)) { - RDCWARN("ID3D11Multithread is not supported"); - return E_NOINTERFACE; + // forward to the device as the lock is shared amongst all things + return m_pDevice->QueryInterface(riid, ppvObject); } else if(riid == __uuidof(ID3DUserDefinedAnnotation)) { diff --git a/renderdoc/driver/d3d11/d3d11_context1_wrap.cpp b/renderdoc/driver/d3d11/d3d11_context1_wrap.cpp index b16de8cb6..5dbf90b37 100644 --- a/renderdoc/driver/d3d11/d3d11_context1_wrap.cpp +++ b/renderdoc/driver/d3d11/d3d11_context1_wrap.cpp @@ -360,6 +360,8 @@ void WrappedID3D11DeviceContext::UpdateSubresource1(ID3D11Resource *pDstResource if(m_pRealContext1 == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -444,6 +446,8 @@ void WrappedID3D11DeviceContext::CopySubresourceRegion1(ID3D11Resource *pDstReso if(m_pRealContext1 == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -553,6 +557,8 @@ void WrappedID3D11DeviceContext::ClearView(ID3D11View *pView, const FLOAT Color[ if(m_pRealContext1 == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); if(pView == NULL) @@ -667,6 +673,8 @@ void WrappedID3D11DeviceContext::VSSetConstantBuffers1(UINT StartSlot, UINT NumB const UINT *pFirstConstant, const UINT *pNumConstants) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -796,6 +804,8 @@ void WrappedID3D11DeviceContext::HSSetConstantBuffers1(UINT StartSlot, UINT NumB const UINT *pFirstConstant, const UINT *pNumConstants) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -925,6 +935,8 @@ void WrappedID3D11DeviceContext::DSSetConstantBuffers1(UINT StartSlot, UINT NumB const UINT *pFirstConstant, const UINT *pNumConstants) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -1054,6 +1066,8 @@ void WrappedID3D11DeviceContext::GSSetConstantBuffers1(UINT StartSlot, UINT NumB const UINT *pFirstConstant, const UINT *pNumConstants) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -1183,6 +1197,8 @@ void WrappedID3D11DeviceContext::PSSetConstantBuffers1(UINT StartSlot, UINT NumB const UINT *pFirstConstant, const UINT *pNumConstants) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -1312,6 +1328,8 @@ void WrappedID3D11DeviceContext::CSSetConstantBuffers1(UINT StartSlot, UINT NumB const UINT *pFirstConstant, const UINT *pNumConstants) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -1384,6 +1402,8 @@ void WrappedID3D11DeviceContext::VSGetConstantBuffers1(UINT StartSlot, UINT NumB ID3D11Buffer **ppConstantBuffers, UINT *pFirstConstant, UINT *pNumConstants) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + if(m_pRealContext1 == NULL || !m_SetCBuffer1) { VSGetConstantBuffers(StartSlot, NumBuffers, ppConstantBuffers); @@ -1425,6 +1445,8 @@ void WrappedID3D11DeviceContext::HSGetConstantBuffers1(UINT StartSlot, UINT NumB ID3D11Buffer **ppConstantBuffers, UINT *pFirstConstant, UINT *pNumConstants) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + if(m_pRealContext1 == NULL || !m_SetCBuffer1) { HSGetConstantBuffers(StartSlot, NumBuffers, ppConstantBuffers); @@ -1466,6 +1488,8 @@ void WrappedID3D11DeviceContext::DSGetConstantBuffers1(UINT StartSlot, UINT NumB ID3D11Buffer **ppConstantBuffers, UINT *pFirstConstant, UINT *pNumConstants) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + if(m_pRealContext1 == NULL || !m_SetCBuffer1) { DSGetConstantBuffers(StartSlot, NumBuffers, ppConstantBuffers); @@ -1507,6 +1531,8 @@ void WrappedID3D11DeviceContext::GSGetConstantBuffers1(UINT StartSlot, UINT NumB ID3D11Buffer **ppConstantBuffers, UINT *pFirstConstant, UINT *pNumConstants) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + if(m_pRealContext1 == NULL || !m_SetCBuffer1) { GSGetConstantBuffers(StartSlot, NumBuffers, ppConstantBuffers); @@ -1548,6 +1574,8 @@ void WrappedID3D11DeviceContext::PSGetConstantBuffers1(UINT StartSlot, UINT NumB ID3D11Buffer **ppConstantBuffers, UINT *pFirstConstant, UINT *pNumConstants) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + if(m_pRealContext1 == NULL || !m_SetCBuffer1) { PSGetConstantBuffers(StartSlot, NumBuffers, ppConstantBuffers); @@ -1589,6 +1617,8 @@ void WrappedID3D11DeviceContext::CSGetConstantBuffers1(UINT StartSlot, UINT NumB ID3D11Buffer **ppConstantBuffers, UINT *pFirstConstant, UINT *pNumConstants) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + if(m_pRealContext1 == NULL || !m_SetCBuffer1) { CSGetConstantBuffers(StartSlot, NumBuffers, ppConstantBuffers); @@ -1676,6 +1706,8 @@ void WrappedID3D11DeviceContext::DiscardResource(ID3D11Resource *pResource) if(m_pRealContext1 == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); if(pResource == NULL) @@ -1799,6 +1831,8 @@ void WrappedID3D11DeviceContext::DiscardView(ID3D11View *pResourceView) if(m_pRealContext1 == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); if(pResourceView == NULL) @@ -1936,6 +1970,8 @@ void WrappedID3D11DeviceContext::DiscardView1(ID3D11View *pResourceView, const D if(m_pRealContext1 == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); if(pResourceView == NULL) @@ -2028,6 +2064,8 @@ void WrappedID3D11DeviceContext::SwapDeviceContextState(ID3DDeviceContextState * if(m_pRealContext1 == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3DDeviceContextState *prev = NULL; SERIALISE_TIME_CALL(m_pRealContext1->SwapDeviceContextState( diff --git a/renderdoc/driver/d3d11/d3d11_context2_wrap.cpp b/renderdoc/driver/d3d11/d3d11_context2_wrap.cpp index 2fadbfd1a..93816c30d 100644 --- a/renderdoc/driver/d3d11/d3d11_context2_wrap.cpp +++ b/renderdoc/driver/d3d11/d3d11_context2_wrap.cpp @@ -23,6 +23,7 @@ ******************************************************************************/ #include "d3d11_context.h" +#include "d3d11_device.h" ///////////////////////////////// // implement ID3D11DeviceContext2 @@ -126,15 +127,21 @@ BOOL WrappedID3D11DeviceContext::IsAnnotationEnabled() void WrappedID3D11DeviceContext::SetMarkerInt(LPCWSTR pLabel, INT Data) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + SetMarker(0, pLabel); } void WrappedID3D11DeviceContext::BeginEventInt(LPCWSTR pLabel, INT Data) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + PushMarker(0, pLabel); } void WrappedID3D11DeviceContext::EndEvent() { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + PopMarker(); } diff --git a/renderdoc/driver/d3d11/d3d11_context3_wrap.cpp b/renderdoc/driver/d3d11/d3d11_context3_wrap.cpp index b804d017c..3e6d253cd 100644 --- a/renderdoc/driver/d3d11/d3d11_context3_wrap.cpp +++ b/renderdoc/driver/d3d11/d3d11_context3_wrap.cpp @@ -23,6 +23,7 @@ ******************************************************************************/ #include "d3d11_context.h" +#include "d3d11_device.h" #include "d3d11_resources.h" ///////////////////////////////// diff --git a/renderdoc/driver/d3d11/d3d11_context_wrap.cpp b/renderdoc/driver/d3d11/d3d11_context_wrap.cpp index 906114b79..0e34a7637 100644 --- a/renderdoc/driver/d3d11/d3d11_context_wrap.cpp +++ b/renderdoc/driver/d3d11/d3d11_context_wrap.cpp @@ -274,6 +274,8 @@ void WrappedID3D11DeviceContext::IAGetInputLayout(ID3D11InputLayout **ppInputLay { if(ppInputLayout) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11InputLayout *real = NULL; m_pRealContext->IAGetInputLayout(&real); @@ -289,6 +291,8 @@ void WrappedID3D11DeviceContext::IAGetVertexBuffers(UINT StartSlot, UINT NumBuff ID3D11Buffer **ppVertexBuffers, UINT *pStrides, UINT *pOffsets) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11Buffer *real[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT] = {0}; m_pRealContext->IAGetVertexBuffers(StartSlot, NumBuffers, real, pStrides, pOffsets); @@ -314,6 +318,8 @@ void WrappedID3D11DeviceContext::IAGetIndexBuffer(ID3D11Buffer **pIndexBuffer, D { if(pIndexBuffer) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11Buffer *real = NULL; m_pRealContext->IAGetIndexBuffer(&real, Format, Offset); @@ -332,6 +338,8 @@ void WrappedID3D11DeviceContext::IAGetIndexBuffer(ID3D11Buffer **pIndexBuffer, D void WrappedID3D11DeviceContext::IAGetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY *pTopology) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + m_pRealContext->IAGetPrimitiveTopology(pTopology); if(pTopology) RDCASSERT(*pTopology == m_CurrentPipelineState->IA.Topo); @@ -357,6 +365,8 @@ bool WrappedID3D11DeviceContext::Serialise_IASetPrimitiveTopology(SerialiserType void WrappedID3D11DeviceContext::IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY Topology) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -400,6 +410,8 @@ bool WrappedID3D11DeviceContext::Serialise_IASetInputLayout(SerialiserType &ser, void WrappedID3D11DeviceContext::IASetInputLayout(ID3D11InputLayout *pInputLayout) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -465,6 +477,8 @@ void WrappedID3D11DeviceContext::IASetVertexBuffers(UINT StartSlot, UINT NumBuff ID3D11Buffer *const *ppVertexBuffers, const UINT *pStrides, const UINT *pOffsets) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -528,6 +542,8 @@ bool WrappedID3D11DeviceContext::Serialise_IASetIndexBuffer(SerialiserType &ser, void WrappedID3D11DeviceContext::IASetIndexBuffer(ID3D11Buffer *pIndexBuffer, DXGI_FORMAT Format, UINT Offset) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -563,6 +579,8 @@ void WrappedID3D11DeviceContext::VSGetConstantBuffers(UINT StartSlot, UINT NumBu { if(ppConstantBuffers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11Buffer *real[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT] = {0}; m_pRealContext->VSGetConstantBuffers(StartSlot, NumBuffers, real); @@ -582,6 +600,8 @@ void WrappedID3D11DeviceContext::VSGetShaderResources(UINT StartSlot, UINT NumVi { if(ppShaderResourceViews) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11ShaderResourceView *real[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT] = {0}; m_pRealContext->VSGetShaderResources(StartSlot, NumViews, real); @@ -602,6 +622,8 @@ void WrappedID3D11DeviceContext::VSGetSamplers(UINT StartSlot, UINT NumSamplers, { if(ppSamplers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11SamplerState *real[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT] = {0}; m_pRealContext->VSGetSamplers(StartSlot, NumSamplers, real); @@ -623,6 +645,8 @@ void WrappedID3D11DeviceContext::VSGetShader(ID3D11VertexShader **ppVertexShader if(ppVertexShader == NULL && ppClassInstances == NULL && pNumClassInstances == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11ClassInstance *realInsts[D3D11_SHADER_MAX_INTERFACES] = {0}; UINT numInsts = 0; ID3D11VertexShader *realShader = NULL; @@ -695,6 +719,8 @@ bool WrappedID3D11DeviceContext::Serialise_VSSetConstantBuffers(SerialiserType & void WrappedID3D11DeviceContext::VSSetConstantBuffers(UINT StartSlot, UINT NumBuffers, ID3D11Buffer *const *ppConstantBuffers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -763,6 +789,8 @@ bool WrappedID3D11DeviceContext::Serialise_VSSetShaderResources( void WrappedID3D11DeviceContext::VSSetShaderResources( UINT StartSlot, UINT NumViews, ID3D11ShaderResourceView *const *ppShaderResourceViews) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -830,6 +858,8 @@ bool WrappedID3D11DeviceContext::Serialise_VSSetSamplers(SerialiserType &ser, UI void WrappedID3D11DeviceContext::VSSetSamplers(UINT StartSlot, UINT NumSamplers, ID3D11SamplerState *const *ppSamplers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -900,6 +930,8 @@ void WrappedID3D11DeviceContext::VSSetShader(ID3D11VertexShader *pVertexShader, ID3D11ClassInstance *const *ppClassInstances, UINT NumClassInstances) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -942,6 +974,8 @@ void WrappedID3D11DeviceContext::HSGetConstantBuffers(UINT StartSlot, UINT NumBu { if(ppConstantBuffers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11Buffer *real[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT] = {0}; m_pRealContext->HSGetConstantBuffers(StartSlot, NumBuffers, real); @@ -961,6 +995,8 @@ void WrappedID3D11DeviceContext::HSGetShaderResources(UINT StartSlot, UINT NumVi { if(ppShaderResourceViews) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11ShaderResourceView *real[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT] = {0}; m_pRealContext->HSGetShaderResources(StartSlot, NumViews, real); @@ -981,6 +1017,8 @@ void WrappedID3D11DeviceContext::HSGetSamplers(UINT StartSlot, UINT NumSamplers, { if(ppSamplers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11SamplerState *real[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT] = {0}; m_pRealContext->HSGetSamplers(StartSlot, NumSamplers, real); @@ -1002,6 +1040,8 @@ void WrappedID3D11DeviceContext::HSGetShader(ID3D11HullShader **ppHullShader, if(ppHullShader == NULL && ppClassInstances == NULL && pNumClassInstances == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11ClassInstance *realInsts[D3D11_SHADER_MAX_INTERFACES] = {0}; UINT numInsts = 0; ID3D11HullShader *realShader = NULL; @@ -1074,6 +1114,8 @@ bool WrappedID3D11DeviceContext::Serialise_HSSetConstantBuffers(SerialiserType & void WrappedID3D11DeviceContext::HSSetConstantBuffers(UINT StartSlot, UINT NumBuffers, ID3D11Buffer *const *ppConstantBuffers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -1142,6 +1184,8 @@ bool WrappedID3D11DeviceContext::Serialise_HSSetShaderResources( void WrappedID3D11DeviceContext::HSSetShaderResources( UINT StartSlot, UINT NumViews, ID3D11ShaderResourceView *const *ppShaderResourceViews) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -1209,6 +1253,8 @@ bool WrappedID3D11DeviceContext::Serialise_HSSetSamplers(SerialiserType &ser, UI void WrappedID3D11DeviceContext::HSSetSamplers(UINT StartSlot, UINT NumSamplers, ID3D11SamplerState *const *ppSamplers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -1278,6 +1324,8 @@ void WrappedID3D11DeviceContext::HSSetShader(ID3D11HullShader *pHullShader, ID3D11ClassInstance *const *ppClassInstances, UINT NumClassInstances) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -1320,6 +1368,8 @@ void WrappedID3D11DeviceContext::DSGetConstantBuffers(UINT StartSlot, UINT NumBu { if(ppConstantBuffers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11Buffer *real[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT] = {0}; m_pRealContext->DSGetConstantBuffers(StartSlot, NumBuffers, real); @@ -1339,6 +1389,8 @@ void WrappedID3D11DeviceContext::DSGetShaderResources(UINT StartSlot, UINT NumVi { if(ppShaderResourceViews) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11ShaderResourceView *real[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT] = {0}; m_pRealContext->DSGetShaderResources(StartSlot, NumViews, real); @@ -1359,6 +1411,8 @@ void WrappedID3D11DeviceContext::DSGetSamplers(UINT StartSlot, UINT NumSamplers, { if(ppSamplers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11SamplerState *real[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT] = {0}; m_pRealContext->DSGetSamplers(StartSlot, NumSamplers, real); @@ -1380,6 +1434,8 @@ void WrappedID3D11DeviceContext::DSGetShader(ID3D11DomainShader **ppDomainShader if(ppDomainShader == NULL && ppClassInstances == NULL && pNumClassInstances == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11ClassInstance *realInsts[D3D11_SHADER_MAX_INTERFACES] = {0}; UINT numInsts = 0; ID3D11DomainShader *realShader = NULL; @@ -1452,6 +1508,8 @@ bool WrappedID3D11DeviceContext::Serialise_DSSetConstantBuffers(SerialiserType & void WrappedID3D11DeviceContext::DSSetConstantBuffers(UINT StartSlot, UINT NumBuffers, ID3D11Buffer *const *ppConstantBuffers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -1520,6 +1578,8 @@ bool WrappedID3D11DeviceContext::Serialise_DSSetShaderResources( void WrappedID3D11DeviceContext::DSSetShaderResources( UINT StartSlot, UINT NumViews, ID3D11ShaderResourceView *const *ppShaderResourceViews) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -1587,6 +1647,8 @@ bool WrappedID3D11DeviceContext::Serialise_DSSetSamplers(SerialiserType &ser, UI void WrappedID3D11DeviceContext::DSSetSamplers(UINT StartSlot, UINT NumSamplers, ID3D11SamplerState *const *ppSamplers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -1657,6 +1719,8 @@ void WrappedID3D11DeviceContext::DSSetShader(ID3D11DomainShader *pDomainShader, ID3D11ClassInstance *const *ppClassInstances, UINT NumClassInstances) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -1699,6 +1763,8 @@ void WrappedID3D11DeviceContext::GSGetConstantBuffers(UINT StartSlot, UINT NumBu { if(ppConstantBuffers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11Buffer *real[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT] = {0}; m_pRealContext->GSGetConstantBuffers(StartSlot, NumBuffers, real); @@ -1718,6 +1784,8 @@ void WrappedID3D11DeviceContext::GSGetShaderResources(UINT StartSlot, UINT NumVi { if(ppShaderResourceViews) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11ShaderResourceView *real[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT] = {0}; m_pRealContext->GSGetShaderResources(StartSlot, NumViews, real); @@ -1738,6 +1806,8 @@ void WrappedID3D11DeviceContext::GSGetSamplers(UINT StartSlot, UINT NumSamplers, { if(ppSamplers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11SamplerState *real[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT] = {0}; m_pRealContext->GSGetSamplers(StartSlot, NumSamplers, real); @@ -1759,6 +1829,8 @@ void WrappedID3D11DeviceContext::GSGetShader(ID3D11GeometryShader **ppGeometrySh if(ppGeometryShader == NULL && ppClassInstances == NULL && pNumClassInstances == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11ClassInstance *realInsts[D3D11_SHADER_MAX_INTERFACES] = {0}; UINT numInsts = 0; ID3D11GeometryShader *realShader = NULL; @@ -1832,6 +1904,8 @@ bool WrappedID3D11DeviceContext::Serialise_GSSetConstantBuffers(SerialiserType & void WrappedID3D11DeviceContext::GSSetConstantBuffers(UINT StartSlot, UINT NumBuffers, ID3D11Buffer *const *ppConstantBuffers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -1900,6 +1974,8 @@ bool WrappedID3D11DeviceContext::Serialise_GSSetShaderResources( void WrappedID3D11DeviceContext::GSSetShaderResources( UINT StartSlot, UINT NumViews, ID3D11ShaderResourceView *const *ppShaderResourceViews) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -1967,6 +2043,8 @@ bool WrappedID3D11DeviceContext::Serialise_GSSetSamplers(SerialiserType &ser, UI void WrappedID3D11DeviceContext::GSSetSamplers(UINT StartSlot, UINT NumSamplers, ID3D11SamplerState *const *ppSamplers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -2037,6 +2115,8 @@ void WrappedID3D11DeviceContext::GSSetShader(ID3D11GeometryShader *pShader, ID3D11ClassInstance *const *ppClassInstances, UINT NumClassInstances) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -2078,6 +2158,8 @@ void WrappedID3D11DeviceContext::SOGetTargets(UINT NumBuffers, ID3D11Buffer **pp { if(ppSOTargets) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11Buffer *real[D3D11_SO_BUFFER_SLOT_COUNT] = {0}; m_pRealContext->SOGetTargets(NumBuffers, real); @@ -2177,6 +2259,8 @@ bool WrappedID3D11DeviceContext::Serialise_SOSetTargets(SerialiserType &ser, UIN void WrappedID3D11DeviceContext::SOSetTargets(UINT NumBuffers, ID3D11Buffer *const *ppSOTargets, const UINT *pOffsets) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -2283,6 +2367,8 @@ void WrappedID3D11DeviceContext::SOSetTargets(UINT NumBuffers, ID3D11Buffer *con void WrappedID3D11DeviceContext::RSGetViewports(UINT *pNumViewports, D3D11_VIEWPORT *pViewports) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + m_pRealContext->RSGetViewports(pNumViewports, pViewports); if(pViewports) @@ -2292,6 +2378,8 @@ void WrappedID3D11DeviceContext::RSGetViewports(UINT *pNumViewports, D3D11_VIEWP void WrappedID3D11DeviceContext::RSGetScissorRects(UINT *pNumRects, D3D11_RECT *pRects) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + m_pRealContext->RSGetScissorRects(pNumRects, pRects); if(pRects) @@ -2303,6 +2391,8 @@ void WrappedID3D11DeviceContext::RSGetState(ID3D11RasterizerState **ppRasterizer { if(ppRasterizerState) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11RasterizerState *real = NULL; m_pRealContext->RSGetState(&real); @@ -2347,6 +2437,8 @@ bool WrappedID3D11DeviceContext::Serialise_RSSetViewports(SerialiserType &ser, U void WrappedID3D11DeviceContext::RSSetViewports(UINT NumViewports, const D3D11_VIEWPORT *pViewports) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -2393,6 +2485,8 @@ bool WrappedID3D11DeviceContext::Serialise_RSSetScissorRects(SerialiserType &ser void WrappedID3D11DeviceContext::RSSetScissorRects(UINT NumRects, const D3D11_RECT *pRects) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -2437,6 +2531,8 @@ bool WrappedID3D11DeviceContext::Serialise_RSSetState(SerialiserType &ser, void WrappedID3D11DeviceContext::RSSetState(ID3D11RasterizerState *pRasterizerState) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -2470,6 +2566,8 @@ void WrappedID3D11DeviceContext::PSGetConstantBuffers(UINT StartSlot, UINT NumBu { if(ppConstantBuffers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11Buffer *real[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT] = {0}; m_pRealContext->PSGetConstantBuffers(StartSlot, NumBuffers, real); @@ -2489,6 +2587,8 @@ void WrappedID3D11DeviceContext::PSGetShaderResources(UINT StartSlot, UINT NumVi { if(ppShaderResourceViews) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11ShaderResourceView *real[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT] = {0}; m_pRealContext->PSGetShaderResources(StartSlot, NumViews, real); @@ -2509,6 +2609,8 @@ void WrappedID3D11DeviceContext::PSGetSamplers(UINT StartSlot, UINT NumSamplers, { if(ppSamplers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11SamplerState *real[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT] = {0}; m_pRealContext->PSGetSamplers(StartSlot, NumSamplers, real); @@ -2530,6 +2632,8 @@ void WrappedID3D11DeviceContext::PSGetShader(ID3D11PixelShader **ppPixelShader, if(ppPixelShader == NULL && ppClassInstances == NULL && pNumClassInstances == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11ClassInstance *realInsts[D3D11_SHADER_MAX_INTERFACES] = {0}; UINT numInsts = 0; ID3D11PixelShader *realShader = NULL; @@ -2602,6 +2706,8 @@ bool WrappedID3D11DeviceContext::Serialise_PSSetConstantBuffers(SerialiserType & void WrappedID3D11DeviceContext::PSSetConstantBuffers(UINT StartSlot, UINT NumBuffers, ID3D11Buffer *const *ppConstantBuffers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -2670,6 +2776,8 @@ bool WrappedID3D11DeviceContext::Serialise_PSSetShaderResources( void WrappedID3D11DeviceContext::PSSetShaderResources( UINT StartSlot, UINT NumViews, ID3D11ShaderResourceView *const *ppShaderResourceViews) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -2737,6 +2845,8 @@ bool WrappedID3D11DeviceContext::Serialise_PSSetSamplers(SerialiserType &ser, UI void WrappedID3D11DeviceContext::PSSetSamplers(UINT StartSlot, UINT NumSamplers, ID3D11SamplerState *const *ppSamplers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -2807,6 +2917,8 @@ void WrappedID3D11DeviceContext::PSSetShader(ID3D11PixelShader *pPixelShader, ID3D11ClassInstance *const *ppClassInstances, UINT NumClassInstances) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -2851,6 +2963,8 @@ void WrappedID3D11DeviceContext::OMGetRenderTargets(UINT NumViews, if(ppRenderTargetViews == NULL && ppDepthStencilView == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11RenderTargetView *rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT] = {0}; ID3D11DepthStencilView *dsv = NULL; m_pRealContext->OMGetRenderTargets(NumViews, rtv, &dsv); @@ -2889,6 +3003,8 @@ void WrappedID3D11DeviceContext::OMGetRenderTargetsAndUnorderedAccessViews( if(ppRenderTargetViews == NULL && ppDepthStencilView == NULL && ppUnorderedAccessViews == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11RenderTargetView *rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT] = {0}; ID3D11UnorderedAccessView *uav[D3D11_1_UAV_SLOT_COUNT] = {0}; ID3D11DepthStencilView *dsv = NULL; @@ -2939,6 +3055,8 @@ void WrappedID3D11DeviceContext::OMGetRenderTargetsAndUnorderedAccessViews( void WrappedID3D11DeviceContext::OMGetBlendState(ID3D11BlendState **ppBlendState, FLOAT BlendFactor[4], UINT *pSampleMask) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11BlendState *real = NULL; m_pRealContext->OMGetBlendState(&real, BlendFactor, pSampleMask); @@ -2968,6 +3086,8 @@ void WrappedID3D11DeviceContext::OMGetBlendState(ID3D11BlendState **ppBlendState void WrappedID3D11DeviceContext::OMGetDepthStencilState(ID3D11DepthStencilState **ppDepthStencilState, UINT *pStencilRef) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11DepthStencilState *real = NULL; m_pRealContext->OMGetDepthStencilState(&real, pStencilRef); @@ -3041,6 +3161,8 @@ void WrappedID3D11DeviceContext::OMSetRenderTargets(UINT NumViews, ID3D11RenderTargetView *const *ppRenderTargetViews, ID3D11DepthStencilView *pDepthStencilView) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -3332,6 +3454,8 @@ void WrappedID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews( ID3D11DepthStencilView *pDepthStencilView, UINT UAVStartSlot, UINT NumUAVs, ID3D11UnorderedAccessView *const *ppUnorderedAccessViews, const UINT *pUAVInitialCounts) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -3551,6 +3675,8 @@ bool WrappedID3D11DeviceContext::Serialise_OMSetBlendState(SerialiserType &ser, void WrappedID3D11DeviceContext::OMSetBlendState(ID3D11BlendState *pBlendState, const FLOAT BlendFactor[4], UINT SampleMask) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -3610,6 +3736,8 @@ bool WrappedID3D11DeviceContext::Serialise_OMSetDepthStencilState( void WrappedID3D11DeviceContext::OMSetDepthStencilState(ID3D11DepthStencilState *pDepthStencilState, UINT StencilRef) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -3717,6 +3845,8 @@ void WrappedID3D11DeviceContext::DrawIndexedInstanced(UINT IndexCountPerInstance UINT StartIndexLocation, INT BaseVertexLocation, UINT StartInstanceLocation) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); MarkAPIActive(); @@ -3787,6 +3917,8 @@ bool WrappedID3D11DeviceContext::Serialise_DrawInstanced(SerialiserType &ser, void WrappedID3D11DeviceContext::DrawInstanced(UINT VertexCountPerInstance, UINT InstanceCount, UINT StartVertexLocation, UINT StartInstanceLocation) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); MarkAPIActive(); @@ -3852,6 +3984,8 @@ bool WrappedID3D11DeviceContext::Serialise_DrawIndexed(SerialiserType &ser, UINT void WrappedID3D11DeviceContext::DrawIndexed(UINT IndexCount, UINT StartIndexLocation, INT BaseVertexLocation) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); MarkAPIActive(); @@ -3911,6 +4045,8 @@ bool WrappedID3D11DeviceContext::Serialise_Draw(SerialiserType &ser, UINT Vertex void WrappedID3D11DeviceContext::Draw(UINT VertexCount, UINT StartVertexLocation) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); MarkAPIActive(); @@ -4022,6 +4158,8 @@ bool WrappedID3D11DeviceContext::Serialise_DrawAuto(SerialiserType &ser) void WrappedID3D11DeviceContext::DrawAuto() { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); MarkAPIActive(); @@ -4147,6 +4285,8 @@ bool WrappedID3D11DeviceContext::Serialise_DrawIndexedInstancedIndirect(Serialis void WrappedID3D11DeviceContext::DrawIndexedInstancedIndirect(ID3D11Buffer *pBufferForArgs, UINT AlignedByteOffsetForArgs) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); MarkAPIActive(); @@ -4273,6 +4413,8 @@ bool WrappedID3D11DeviceContext::Serialise_DrawInstancedIndirect(SerialiserType void WrappedID3D11DeviceContext::DrawInstancedIndirect(ID3D11Buffer *pBufferForArgs, UINT AlignedByteOffsetForArgs) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); MarkAPIActive(); @@ -4308,6 +4450,8 @@ void WrappedID3D11DeviceContext::CSGetConstantBuffers(UINT StartSlot, UINT NumBu { if(ppConstantBuffers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11Buffer *real[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT] = {0}; m_pRealContext->CSGetConstantBuffers(StartSlot, NumBuffers, real); @@ -4327,6 +4471,8 @@ void WrappedID3D11DeviceContext::CSGetShaderResources(UINT StartSlot, UINT NumVi { if(ppShaderResourceViews) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11ShaderResourceView *real[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT] = {0}; m_pRealContext->CSGetShaderResources(StartSlot, NumViews, real); @@ -4347,6 +4493,8 @@ void WrappedID3D11DeviceContext::CSGetUnorderedAccessViews( { if(ppUnorderedAccessViews) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11UnorderedAccessView *real[D3D11_1_UAV_SLOT_COUNT] = {0}; m_pRealContext->CSGetUnorderedAccessViews(StartSlot, NumUAVs, real); @@ -4367,6 +4515,8 @@ void WrappedID3D11DeviceContext::CSGetSamplers(UINT StartSlot, UINT NumSamplers, { if(ppSamplers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11SamplerState *real[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT] = {0}; m_pRealContext->CSGetSamplers(StartSlot, NumSamplers, real); @@ -4388,6 +4538,8 @@ void WrappedID3D11DeviceContext::CSGetShader(ID3D11ComputeShader **ppComputeShad if(ppComputeShader == NULL && ppClassInstances == NULL && pNumClassInstances == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11ClassInstance *realInsts[D3D11_SHADER_MAX_INTERFACES] = {0}; UINT numInsts = 0; ID3D11ComputeShader *realShader = NULL; @@ -4460,6 +4612,8 @@ bool WrappedID3D11DeviceContext::Serialise_CSSetConstantBuffers(SerialiserType & void WrappedID3D11DeviceContext::CSSetConstantBuffers(UINT StartSlot, UINT NumBuffers, ID3D11Buffer *const *ppConstantBuffers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -4528,6 +4682,8 @@ bool WrappedID3D11DeviceContext::Serialise_CSSetShaderResources( void WrappedID3D11DeviceContext::CSSetShaderResources( UINT StartSlot, UINT NumViews, ID3D11ShaderResourceView *const *ppShaderResourceViews) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -4598,6 +4754,8 @@ void WrappedID3D11DeviceContext::CSSetUnorderedAccessViews( UINT StartSlot, UINT NumUAVs, ID3D11UnorderedAccessView *const *ppUnorderedAccessViews, const UINT *pUAVInitialCounts) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -4675,6 +4833,8 @@ bool WrappedID3D11DeviceContext::Serialise_CSSetSamplers(SerialiserType &ser, UI void WrappedID3D11DeviceContext::CSSetSamplers(UINT StartSlot, UINT NumSamplers, ID3D11SamplerState *const *ppSamplers) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -4745,6 +4905,8 @@ void WrappedID3D11DeviceContext::CSSetShader(ID3D11ComputeShader *pComputeShader ID3D11ClassInstance *const *ppClassInstances, UINT NumClassInstances) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -4839,6 +5001,8 @@ bool WrappedID3D11DeviceContext::Serialise_Dispatch(SerialiserType &ser, UINT Th void WrappedID3D11DeviceContext::Dispatch(UINT ThreadGroupCountX, UINT ThreadGroupCountY, UINT ThreadGroupCountZ) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); MarkAPIActive(); @@ -4958,6 +5122,8 @@ bool WrappedID3D11DeviceContext::Serialise_DispatchIndirect(SerialiserType &ser, void WrappedID3D11DeviceContext::DispatchIndirect(ID3D11Buffer *pBufferForArgs, UINT AlignedByteOffsetForArgs) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); MarkAPIActive(); @@ -5067,6 +5233,8 @@ bool WrappedID3D11DeviceContext::Serialise_PostExecuteCommandList(SerialiserType void WrappedID3D11DeviceContext::ExecuteCommandList(ID3D11CommandList *pCommandList, BOOL RestoreContextState) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -5208,6 +5376,8 @@ HRESULT WrappedID3D11DeviceContext::FinishCommandList(BOOL RestoreDeferredContex return DXGI_ERROR_INVALID_CALL; } + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); ID3D11CommandList *real = NULL; @@ -5364,6 +5534,8 @@ bool WrappedID3D11DeviceContext::Serialise_Flush(SerialiserType &ser) void WrappedID3D11DeviceContext::Flush() { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + m_EmptyCommandList = false; SERIALISE_TIME_CALL(m_pRealContext->Flush()); @@ -5456,6 +5628,8 @@ void WrappedID3D11DeviceContext::CopySubresourceRegion(ID3D11Resource *pDstResou UINT DstZ, ID3D11Resource *pSrcResource, UINT SrcSubresource, const D3D11_BOX *pSrcBox) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -5599,6 +5773,8 @@ bool WrappedID3D11DeviceContext::Serialise_CopyResource(SerialiserType &ser, void WrappedID3D11DeviceContext::CopyResource(ID3D11Resource *pDstResource, ID3D11Resource *pSrcResource) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -5711,6 +5887,8 @@ void WrappedID3D11DeviceContext::UpdateSubresource(ID3D11Resource *pDstResource, const D3D11_BOX *pDstBox, const void *pSrcData, UINT SrcRowPitch, UINT SrcDepthPitch) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -6037,6 +6215,8 @@ void WrappedID3D11DeviceContext::CopyStructureCount(ID3D11Buffer *pDstBuffer, UINT DstAlignedByteOffset, ID3D11UnorderedAccessView *pSrcView) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -6148,6 +6328,8 @@ void WrappedID3D11DeviceContext::ResolveSubresource(ID3D11Resource *pDstResource UINT DstSubresource, ID3D11Resource *pSrcResource, UINT SrcSubresource, DXGI_FORMAT Format) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -6223,6 +6405,8 @@ bool WrappedID3D11DeviceContext::Serialise_GenerateMips(SerialiserType &ser, void WrappedID3D11DeviceContext::GenerateMips(ID3D11ShaderResourceView *pShaderResourceView) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -6276,6 +6460,8 @@ bool WrappedID3D11DeviceContext::Serialise_ClearState(SerialiserType &ser) void WrappedID3D11DeviceContext::ClearState() { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + m_EmptyCommandList = false; SERIALISE_TIME_CALL(m_pRealContext->ClearState()); @@ -6348,6 +6534,8 @@ void WrappedID3D11DeviceContext::ClearRenderTargetView(ID3D11RenderTargetView *p if(pRenderTargetView == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + m_EmptyCommandList = false; SERIALISE_TIME_CALL(m_pRealContext->ClearRenderTargetView( @@ -6426,6 +6614,8 @@ bool WrappedID3D11DeviceContext::Serialise_ClearUnorderedAccessViewUint( void WrappedID3D11DeviceContext::ClearUnorderedAccessViewUint( ID3D11UnorderedAccessView *pUnorderedAccessView, const UINT Values[4]) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + m_EmptyCommandList = false; SERIALISE_TIME_CALL(m_pRealContext->ClearUnorderedAccessViewUint( @@ -6504,6 +6694,8 @@ bool WrappedID3D11DeviceContext::Serialise_ClearUnorderedAccessViewFloat( void WrappedID3D11DeviceContext::ClearUnorderedAccessViewFloat( ID3D11UnorderedAccessView *pUnorderedAccessView, const FLOAT Values[4]) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + m_EmptyCommandList = false; SERIALISE_TIME_CALL(m_pRealContext->ClearUnorderedAccessViewFloat( @@ -6595,6 +6787,8 @@ void WrappedID3D11DeviceContext::ClearDepthStencilView(ID3D11DepthStencilView *p if(pDepthStencilView == NULL) return; + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + m_EmptyCommandList = false; SERIALISE_TIME_CALL(m_pRealContext->ClearDepthStencilView( @@ -6656,6 +6850,8 @@ bool WrappedID3D11DeviceContext::Serialise_Begin(SerialiserType &ser, ID3D11Asyn void WrappedID3D11DeviceContext::Begin(ID3D11Asynchronous *pAsync) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11Asynchronous *unwrapped = NULL; ResourceId id; @@ -6722,6 +6918,8 @@ bool WrappedID3D11DeviceContext::Serialise_End(SerialiserType &ser, ID3D11Asynch void WrappedID3D11DeviceContext::End(ID3D11Asynchronous *pAsync) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11Asynchronous *unwrapped = NULL; ResourceId id; @@ -6763,6 +6961,8 @@ void WrappedID3D11DeviceContext::End(ID3D11Asynchronous *pAsync) HRESULT WrappedID3D11DeviceContext::GetData(ID3D11Asynchronous *pAsync, void *pData, UINT DataSize, UINT GetDataFlags) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + ID3D11Asynchronous *unwrapped = NULL; if(WrappedID3D11Query1::IsAlloc(pAsync)) @@ -6806,6 +7006,8 @@ bool WrappedID3D11DeviceContext::Serialise_SetPredication(SerialiserType &ser, void WrappedID3D11DeviceContext::SetPredication(ID3D11Predicate *pPredicate, BOOL PredicateValue) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + m_EmptyCommandList = false; m_CurrentPipelineState->ChangeRefRead(m_CurrentPipelineState->Predicate, pPredicate); @@ -6861,6 +7063,8 @@ bool WrappedID3D11DeviceContext::Serialise_SetResourceMinLOD(SerialiserType &ser void WrappedID3D11DeviceContext::SetResourceMinLOD(ID3D11Resource *pResource, FLOAT MinLOD) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + m_EmptyCommandList = false; SERIALISE_TIME_CALL(m_pRealContext->SetResourceMinLOD( @@ -7343,6 +7547,8 @@ HRESULT WrappedID3D11DeviceContext::Map(ID3D11Resource *pResource, UINT Subresou D3D11_MAP MapType, UINT MapFlags, D3D11_MAPPED_SUBRESOURCE *pMappedResource) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; @@ -7696,6 +7902,8 @@ bool WrappedID3D11DeviceContext::Serialise_Unmap(SerialiserType &ser, ID3D11Reso void WrappedID3D11DeviceContext::Unmap(ID3D11Resource *pResource, UINT Subresource) { + SCOPED_LOCK_OPTIONAL(m_pDevice->D3DLock(), m_pDevice->D3DThreadSafe()); + DrainAnnotationQueue(); m_EmptyCommandList = false; diff --git a/renderdoc/driver/d3d11/d3d11_device.cpp b/renderdoc/driver/d3d11/d3d11_device.cpp index 20070c901..d5d54dde5 100644 --- a/renderdoc/driver/d3d11/d3d11_device.cpp +++ b/renderdoc/driver/d3d11/d3d11_device.cpp @@ -96,9 +96,9 @@ WrappedID3D11Device::WrappedID3D11Device(ID3D11Device *realDevice, D3D11InitPara m_Alive = true; m_DummyInfoQueue.m_pDevice = this; - m_DummyD3D10Multithread.m_pDevice = this; m_DummyDebug.m_pDevice = this; m_WrappedDebug.m_pDevice = this; + m_WrappedMultithread.m_pDevice = this; m_FrameCounter = 0; m_FailedFrame = 0; @@ -192,6 +192,7 @@ WrappedID3D11Device::WrappedID3D11Device(ID3D11Device *realDevice, D3D11InitPara { realDevice->QueryInterface(__uuidof(ID3D11InfoQueue), (void **)&m_pInfoQueue); realDevice->QueryInterface(__uuidof(ID3D11Debug), (void **)&m_WrappedDebug.m_pDebug); + realDevice->QueryInterface(__uuidof(ID3D11Multithread), (void **)&m_WrappedMultithread.m_pReal); } // useful for marking regions during replay for self-captures @@ -311,6 +312,7 @@ WrappedID3D11Device::~WrappedID3D11Device() SAFE_DELETE(m_ResourceManager); SAFE_RELEASE(m_pInfoQueue); + SAFE_RELEASE(m_WrappedMultithread.m_pReal); SAFE_RELEASE(m_WrappedDebug.m_pDebug); SAFE_RELEASE(m_pDevice); @@ -344,18 +346,6 @@ void WrappedID3D11Device::CheckForDeath() } } -ULONG STDMETHODCALLTYPE DummyID3D10Multithread::AddRef() -{ - m_pDevice->AddRef(); - return 1; -} - -ULONG STDMETHODCALLTYPE DummyID3D10Multithread::Release() -{ - m_pDevice->Release(); - return 1; -} - ULONG STDMETHODCALLTYPE DummyID3D11InfoQueue::AddRef() { m_pDevice->AddRef(); @@ -385,6 +375,65 @@ ULONG STDMETHODCALLTYPE DummyID3D11Debug::Release() return 1; } +HRESULT STDMETHODCALLTYPE WrappedD3D11Multithread::QueryInterface(REFIID riid, void **ppvObject) +{ + if(riid == __uuidof(IUnknown)) + { + *ppvObject = (IUnknown *)this; + AddRef(); + return S_OK; + } + if(riid == __uuidof(ID3D11Multithread)) + { + *ppvObject = (ID3D11Multithread *)this; + AddRef(); + return S_OK; + } + return E_NOINTERFACE; +} + +ULONG STDMETHODCALLTYPE WrappedD3D11Multithread::AddRef() +{ + m_pDevice->AddRef(); + return 1; +} + +ULONG STDMETHODCALLTYPE WrappedD3D11Multithread::Release() +{ + m_pDevice->Release(); + return 1; +} + +void STDMETHODCALLTYPE WrappedD3D11Multithread::Enter() +{ + m_pDevice->D3DLock().Lock(); + if(m_pReal) + m_pReal->Enter(); +} + +void STDMETHODCALLTYPE WrappedD3D11Multithread::Leave() +{ + if(m_pReal) + m_pReal->Leave(); + m_pDevice->D3DLock().Unlock(); +} + +BOOL STDMETHODCALLTYPE WrappedD3D11Multithread::SetMultithreadProtected(BOOL bMTProtect) +{ + bool old = m_pDevice->D3DThreadSafe(); + m_pDevice->SetD3DThreadSafe(bMTProtect == TRUE); + if(m_pReal) + m_pReal->SetMultithreadProtected(bMTProtect); + // TODO - unclear if m_MultithreadProtected just enables Enter/Leave to work, or if it enables + // auto-thread safety on all D3D interfaces + return old ? TRUE : FALSE; +} + +BOOL STDMETHODCALLTYPE WrappedD3D11Multithread::GetMultithreadProtected() +{ + return m_pDevice->D3DThreadSafe() ? TRUE : FALSE; +} + HRESULT STDMETHODCALLTYPE WrappedID3D11Debug::QueryInterface(REFIID riid, void **ppvObject) { if(riid == __uuidof(ID3D11InfoQueue) || riid == __uuidof(ID3D11Debug) || @@ -607,13 +656,10 @@ HRESULT WrappedID3D11Device::QueryInterface(REFIID riid, void **ppvObject) return E_NOINTERFACE; } } - else if(riid == __uuidof(ID3D10Multithread)) + else if(riid == __uuidof(ID3D11Multithread)) { - RDCWARN( - "Returning a dummy ID3D10Multithread that does nothing. This ID3D10Multithread will not " - "work!"); - *ppvObject = (ID3D10Multithread *)&m_DummyD3D10Multithread; - m_DummyD3D10Multithread.AddRef(); + AddRef(); + *ppvObject = (ID3D11Multithread *)&m_WrappedMultithread; return S_OK; } else if(riid == ID3D11ShaderTraceFactory_uuid) diff --git a/renderdoc/driver/d3d11/d3d11_device.h b/renderdoc/driver/d3d11/d3d11_device.h index 5152c35f3..443ee2f33 100644 --- a/renderdoc/driver/d3d11/d3d11_device.h +++ b/renderdoc/driver/d3d11/d3d11_device.h @@ -74,45 +74,23 @@ class WrappedID3D11Device; class WrappedID3D11DeviceContext; class WrappedShader; -// declare this here as we don't want to pull in the whole D3D10 headers -MIDL_INTERFACE("9B7E4E00-342C-4106-A19F-4F2704F689F0") -ID3D10Multithread : public IUnknown +struct WrappedD3D11Multithread : public ID3D11Multithread { -public: - virtual void STDMETHODCALLTYPE Enter(void) = 0; + WrappedID3D11Device *m_pDevice = NULL; + ID3D11Multithread *m_pReal = NULL; - virtual void STDMETHODCALLTYPE Leave(void) = 0; - - virtual BOOL STDMETHODCALLTYPE SetMultithreadProtected( - /* [annotation] */ - _In_ BOOL bMTProtect) = 0; - - virtual BOOL STDMETHODCALLTYPE GetMultithreadProtected(void) = 0; -}; - -struct DummyID3D10Multithread : public ID3D10Multithread -{ - WrappedID3D11Device *m_pDevice; - - DummyID3D10Multithread() : m_pDevice(NULL) {} ////////////////////////////// // implement IUnknown - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) { return E_NOINTERFACE; } + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); ULONG STDMETHODCALLTYPE AddRef(); ULONG STDMETHODCALLTYPE Release(); ////////////////////////////// - // implement ID3D10Multithread - virtual void STDMETHODCALLTYPE Enter(void) { return; } - virtual void STDMETHODCALLTYPE Leave(void) { return; } - virtual BOOL STDMETHODCALLTYPE SetMultithreadProtected( - /* [annotation] */ - _In_ BOOL bMTProtect) - { - return TRUE; - } - - virtual BOOL STDMETHODCALLTYPE GetMultithreadProtected(void) { return TRUE; } + // implement ID3D11Multithread + virtual void STDMETHODCALLTYPE Enter(); + virtual void STDMETHODCALLTYPE Leave(); + virtual BOOL STDMETHODCALLTYPE SetMultithreadProtected(BOOL bMTProtect); + virtual BOOL STDMETHODCALLTYPE GetMultithreadProtected(); }; // We can pass through all calls to ID3D11Debug without intercepting, this @@ -316,7 +294,7 @@ private: D3D11Replay m_Replay; - DummyID3D10Multithread m_DummyD3D10Multithread; + WrappedD3D11Multithread m_WrappedMultithread; DummyID3D11InfoQueue m_DummyInfoQueue; DummyID3D11Debug m_DummyDebug; WrappedID3D11Debug m_WrappedDebug; @@ -356,6 +334,9 @@ private: // protects wrapped resource creation and serialiser access Threading::CriticalSection m_D3DLock; + // behaviour that can be enabled by ID3D11Multithread, to auto-lock all context functions + bool m_D3DThreadSafe = false; + WriteSerialiser m_ScratchSerialiser; std::set m_StringDB; @@ -436,6 +417,8 @@ public: D3D11DebugManager *GetDebugManager() { return m_DebugManager; } D3D11Replay *GetReplay() { return &m_Replay; } Threading::CriticalSection &D3DLock() { return m_D3DLock; } + bool D3DThreadSafe() const { return m_D3DThreadSafe; } + void SetD3DThreadSafe(bool safe) { m_D3DThreadSafe = safe; } WrappedID3D11DeviceContext *GetImmediateContext() { return m_pImmediateContext; } size_t GetNumDeferredContexts() { return m_DeferredContexts.size(); } void AddDeferredContext(WrappedID3D11DeviceContext *defctx); diff --git a/renderdoc/driver/d3d11/d3d11_resources.h b/renderdoc/driver/d3d11/d3d11_resources.h index 1dc8736fe..82b47b414 100644 --- a/renderdoc/driver/d3d11/d3d11_resources.h +++ b/renderdoc/driver/d3d11/d3d11_resources.h @@ -179,6 +179,11 @@ public: AddRef(); return S_OK; } + if(riid == __uuidof(ID3D11Multithread)) + { + // forward to the device as the lock is shared amongst all things + return m_pDevice->QueryInterface(riid, ppvObject); + } // for DXGI object queries, just make a new throw-away WrappedDXGIObject // and return. diff --git a/renderdoc/driver/dxgi/dxgi_wrapped.cpp b/renderdoc/driver/dxgi/dxgi_wrapped.cpp index 912725fd9..1536304a9 100644 --- a/renderdoc/driver/dxgi/dxgi_wrapped.cpp +++ b/renderdoc/driver/dxgi/dxgi_wrapped.cpp @@ -784,6 +784,11 @@ HRESULT STDMETHODCALLTYPE WrappedIDXGIDevice4::QueryInterface(REFIID riid, void *ppvObject = m_pD3DDevice->GetDeviceInterface(riid); return S_OK; } + else if(riid == __uuidof(ID3D11Multithread)) + { + // forward to the device as the lock is shared amongst all things + return m_pD3DDevice->QueryInterface(riid, ppvObject); + } else if(riid == __uuidof(IDXGIDevice)) { AddRef(); diff --git a/renderdoc/driver/dxgi/dxgi_wrapped.h b/renderdoc/driver/dxgi/dxgi_wrapped.h index 549494b04..9d7a90c64 100644 --- a/renderdoc/driver/dxgi/dxgi_wrapped.h +++ b/renderdoc/driver/dxgi/dxgi_wrapped.h @@ -34,6 +34,7 @@ MIDL_INTERFACE("dc8e63f3-d12b-4952-b47b-5e45026a862d") ID3D11Resource; MIDL_INTERFACE("db6f6ddb-ac77-4e88-8253-819df9bbf140") ID3D11Device; MIDL_INTERFACE("696442be-a72e-4059-bc79-5b5c98040fad") ID3D12Resource; MIDL_INTERFACE("189819f1-1db6-4b57-be54-1821339b85f7") ID3D12Device; +MIDL_INTERFACE("9B7E4E00-342C-4106-A19F-4F2704F689F0") ID3D11Multithread; class RefCountDXGIObject : public IDXGIObject {