From 449eef4b9bd773c4622fe2684bc02cb263434b6e Mon Sep 17 00:00:00 2001 From: Baldur Karlsson Date: Mon, 12 Mar 2018 14:02:44 +0000 Subject: [PATCH] Implement query for IDXGraphicsAnalysis with DXGIGetDebugInterface1 Closes #897 --- renderdoc/core/core.h | 6 ++ renderdoc/driver/dxgi/dxgi_hooks.cpp | 84 +++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/renderdoc/core/core.h b/renderdoc/core/core.h index 8e66b2c03..7b18d9572 100644 --- a/renderdoc/core/core.h +++ b/renderdoc/core/core.h @@ -503,6 +503,12 @@ public: return dev == m_ActiveWindow.dev && wnd == m_ActiveWindow.wnd; } + void GetActiveWindow(void *&dev, void *&wnd) + { + dev = m_ActiveWindow.dev; + wnd = m_ActiveWindow.wnd; + } + void TriggerCapture(uint32_t numFrames) { m_Cap = numFrames; } uint32_t GetOverlayBits() { return m_Overlay; } void MaskOverlayBits(uint32_t And, uint32_t Or) { m_Overlay = (m_Overlay & And) | Or; } diff --git a/renderdoc/driver/dxgi/dxgi_hooks.cpp b/renderdoc/driver/dxgi/dxgi_hooks.cpp index 22c19300c..eeda79061 100644 --- a/renderdoc/driver/dxgi/dxgi_hooks.cpp +++ b/renderdoc/driver/dxgi/dxgi_hooks.cpp @@ -23,6 +23,7 @@ * THE SOFTWARE. ******************************************************************************/ +#include "core/core.h" #include "hooks/hooks.h" #include "dxgi_wrapped.h" @@ -30,6 +31,45 @@ typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID, void **); typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY2)(UINT, REFIID, void **); +typedef HRESULT(WINAPI *PFN_GET_DEBUG_INTERFACE)(REFIID, void **); +typedef HRESULT(WINAPI *PFN_GET_DEBUG_INTERFACE1)(UINT, REFIID, void **); + +MIDL_INTERFACE("9F251514-9D4D-4902-9D60-18988AB7D4B5") +IDXGraphicsAnalysis : public IUnknown +{ + virtual void STDMETHODCALLTYPE BeginCapture() = 0; + virtual void STDMETHODCALLTYPE EndCapture() = 0; +}; + +struct RenderDocAnalysis : IDXGraphicsAnalysis +{ + // IUnknown boilerplate + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) { return E_NOINTERFACE; } + ULONG STDMETHODCALLTYPE AddRef() + { + InterlockedIncrement(&m_iRefcount); + return m_iRefcount; + } + ULONG STDMETHODCALLTYPE Release() { return InterlockedDecrement(&m_iRefcount); } + unsigned int m_iRefcount = 0; + + // IDXGraphicsAnalysis + void BeginCapture() + { + void *dev = NULL, *wnd = NULL; + RenderDoc::Inst().GetActiveWindow(dev, wnd); + + RenderDoc::Inst().StartFrameCapture(dev, wnd); + } + + void EndCapture() + { + void *dev = NULL, *wnd = NULL; + RenderDoc::Inst().GetActiveWindow(dev, wnd); + + RenderDoc::Inst().EndFrameCapture(dev, wnd); + } +}; class DXGIHook : LibraryHook { @@ -47,8 +87,10 @@ public: success &= CreateDXGIFactory.Initialize("CreateDXGIFactory", DLL_NAME, CreateDXGIFactory_hook); success &= CreateDXGIFactory1.Initialize("CreateDXGIFactory1", DLL_NAME, CreateDXGIFactory1_hook); - // don't mind if this doesn't succeed + // don't mind if these dosn't succeed CreateDXGIFactory2.Initialize("CreateDXGIFactory2", DLL_NAME, CreateDXGIFactory2_hook); + GetDebugInterface.Initialize("DXGIGetDebugInterface", DLL_NAME, DXGIGetDebugInterface_hook); + GetDebugInterface1.Initialize("DXGIGetDebugInterface1", DLL_NAME, DXGIGetDebugInterface1_hook); if(!success) return false; @@ -132,9 +174,13 @@ private: bool m_HasHooks; bool m_EnabledHooks; + RenderDocAnalysis m_RenderDocAnalysis; + Hook CreateDXGIFactory; Hook CreateDXGIFactory1; Hook CreateDXGIFactory2; + Hook GetDebugInterface; + Hook GetDebugInterface1; static HRESULT WINAPI CreateDXGIFactory_hook(__in REFIID riid, __out void **ppFactory) { @@ -171,6 +217,42 @@ private: return ret; } + + static HRESULT WINAPI DXGIGetDebugInterface_hook(REFIID riid, void **ppDebug) + { + if(ppDebug) + *ppDebug = NULL; + + if(riid == __uuidof(IDXGraphicsAnalysis)) + { + dxgihooks.m_RenderDocAnalysis.AddRef(); + *ppDebug = &dxgihooks.m_RenderDocAnalysis; + return S_OK; + } + + if(dxgihooks.GetDebugInterface()) + return dxgihooks.GetDebugInterface()(riid, ppDebug); + else + return E_NOINTERFACE; + } + + static HRESULT WINAPI DXGIGetDebugInterface1_hook(UINT Flags, REFIID riid, void **ppDebug) + { + if(ppDebug) + *ppDebug = NULL; + + if(riid == __uuidof(IDXGraphicsAnalysis)) + { + dxgihooks.m_RenderDocAnalysis.AddRef(); + *ppDebug = &dxgihooks.m_RenderDocAnalysis; + return S_OK; + } + + if(dxgihooks.GetDebugInterface1()) + return dxgihooks.GetDebugInterface1()(Flags, riid, ppDebug); + else + return E_NOINTERFACE; + } }; DXGIHook DXGIHook::dxgihooks;