diff --git a/host/platform/Windows/capture/DXGI/src/d3d12.c b/host/platform/Windows/capture/DXGI/src/d3d12.c index 98cf8128..01d5975b 100644 --- a/host/platform/Windows/capture/DXGI/src/d3d12.c +++ b/host/platform/Windows/capture/DXGI/src/d3d12.c @@ -22,9 +22,11 @@ #include #include +#include #include "common/debug.h" #include "common/option.h" #include "common/windebug.h" +#include "ods_capture.h" #define ALIGN_TO(value, align) (((value) + (align) - 1) & -(align)) @@ -43,6 +45,7 @@ struct D3D12Backend { int copySleep; ID3D12Device * device; + ID3D12InfoQueue1 * debugInfoQueue; ID3D12CommandQueue * commandQueue; ID3D12Resource * src; struct D3D12Texture * texture; @@ -61,6 +64,11 @@ typedef HRESULT (*D3D12CreateDevice_t)( void **ppDevice ); +typedef HRESULT (*D3D12GetDebugInterface_t)( + REFIID riid, + void **ppvDebug +); + static void d3d12_free(); static bool d3d12_create(struct DXGIInterface * intf) @@ -72,6 +80,22 @@ static bool d3d12_create(struct DXGIInterface * intf) if (!d3d12) return false; + if (dxgi->debug) + { + D3D12GetDebugInterface_t D3D12GetDebugInterface = (D3D12GetDebugInterface_t) + GetProcAddress(d3d12, "D3D12GetDebugInterface"); + ID3D12Debug1 * debug; + if (FAILED(status = D3D12GetDebugInterface(&IID_ID3D12Debug1, (void **)&debug))) + DEBUG_WINERROR("D3D12GetDebugInterface", status); + else + { + captureOutputDebugString(); + ID3D12Debug1_EnableDebugLayer(debug); + ID3D12Debug1_SetEnableGPUBasedValidation(debug, TRUE); + ID3D12Debug1_SetEnableSynchronizedCommandQueueValidation(debug, TRUE); + } + } + D3D12CreateDevice_t D3D12CreateDevice = (D3D12CreateDevice_t) GetProcAddress(d3d12, "D3D12CreateDevice"); diff --git a/host/platform/Windows/capture/DXGI/src/dxgi.c b/host/platform/Windows/capture/DXGI/src/dxgi.c index c3511116..cafe3f96 100644 --- a/host/platform/Windows/capture/DXGI/src/dxgi.c +++ b/host/platform/Windows/capture/DXGI/src/dxgi.c @@ -34,9 +34,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -127,6 +127,13 @@ static void dxgi_initOptions(void) .type = OPTION_TYPE_INT, .value.x_int = 5 }, + { + .module = "dxgi", + .name = "debug", + .description = "Enable Direct3D debugging (developers only, massive performance penalty)", + .type = OPTION_TYPE_BOOL, + .value.x_bool = false + }, {0} }; @@ -155,6 +162,7 @@ static bool dxgi_create(CaptureGetPointerBuffer getPointerBufferFn, CapturePostP if (this->maxTextures <= 0) this->maxTextures = 1; + this->debug = option_get_bool("dxgi", "debug"); this->useAcquireLock = option_get_bool("dxgi", "useAcquireLock"); this->dwmFlush = option_get_bool("dxgi", "dwmFlush"); this->disableDamage = option_get_bool("dxgi", "disableDamage"); @@ -199,7 +207,8 @@ static bool dxgi_init(void) lgResetEvent(this->frameEvent); - status = CreateDXGIFactory1(&IID_IDXGIFactory1, (void **)&this->factory); + status = CreateDXGIFactory2(this->debug ? DXGI_CREATE_FACTORY_DEBUG : 0, + &IID_IDXGIFactory1, (void **)&this->factory); if (FAILED(status)) { DEBUG_WINERROR("Failed to create DXGIFactory1", status); @@ -399,6 +408,7 @@ static bool dxgi_init(void) DEBUG_INFO("Feature Level : 0x%x" , this->featureLevel); DEBUG_INFO("Capture Size : %u x %u", this->width, this->height); DEBUG_INFO("AcquireLock : %s" , this->useAcquireLock ? "enabled" : "disabled"); + DEBUG_INFO("Debug mode : %s" , this->debug ? "enabled" : "disabled"); // try to reduce the latency { diff --git a/host/platform/Windows/capture/DXGI/src/dxgi_capture.h b/host/platform/Windows/capture/DXGI/src/dxgi_capture.h index a36027fc..6bb64c71 100644 --- a/host/platform/Windows/capture/DXGI/src/dxgi_capture.h +++ b/host/platform/Windows/capture/DXGI/src/dxgi_capture.h @@ -73,6 +73,7 @@ struct DXGIInterface ID3D11Device * device; ID3D11DeviceContext * deviceContext; LG_Lock deviceContextLock; + bool debug; bool useAcquireLock; bool dwmFlush; bool disableDamage;