diff --git a/src/d3d9/d3d9_annotation.cpp b/src/d3d9/d3d9_annotation.cpp index d460b0a5..8949d1e3 100644 --- a/src/d3d9/d3d9_annotation.cpp +++ b/src/d3d9/d3d9_annotation.cpp @@ -92,4 +92,83 @@ namespace dxvk { return m_shouldAnnotate ? 1 : 0; } + //////////////////////////// + // D3D9UserDefinedAnnotation + //////////////////////////// + + D3D9UserDefinedAnnotation::D3D9UserDefinedAnnotation(D3D9DeviceEx* device) + : m_container(device) { + D3D9GlobalAnnotationList::Instance().RegisterAnnotator(this); + } + + + D3D9UserDefinedAnnotation::~D3D9UserDefinedAnnotation() { + D3D9GlobalAnnotationList::Instance().UnregisterAnnotator(this); + } + + + ULONG STDMETHODCALLTYPE D3D9UserDefinedAnnotation::AddRef() { + return m_container->AddRef(); + } + + + ULONG STDMETHODCALLTYPE D3D9UserDefinedAnnotation::Release() { + return m_container->Release(); + } + + + HRESULT STDMETHODCALLTYPE D3D9UserDefinedAnnotation::QueryInterface( + REFIID riid, + void** ppvObject) { + return m_container->QueryInterface(riid, ppvObject); + } + + + INT STDMETHODCALLTYPE D3D9UserDefinedAnnotation::BeginEvent( + D3DCOLOR Color, + LPCWSTR Name) { + m_container->EmitCs([color = Color, labelName = dxvk::str::fromws(Name)](DxvkContext *ctx) { + VkDebugUtilsLabelEXT label; + label.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; + label.pNext = nullptr; + label.pLabelName = labelName.c_str(); + DecodeD3DCOLOR(color, label.color); + + ctx->beginDebugLabel(&label); + }); + + // Handled by the global list. + return 0; + } + + + INT STDMETHODCALLTYPE D3D9UserDefinedAnnotation::EndEvent() { + m_container->EmitCs([](DxvkContext *ctx) { + ctx->endDebugLabel(); + }); + + // Handled by the global list. + return 0; + } + + + void STDMETHODCALLTYPE D3D9UserDefinedAnnotation::SetMarker( + D3DCOLOR Color, + LPCWSTR Name) { + m_container->EmitCs([color = Color, labelName = dxvk::str::fromws(Name)](DxvkContext *ctx) { + VkDebugUtilsLabelEXT label; + label.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; + label.pNext = nullptr; + label.pLabelName = labelName.c_str(); + DecodeD3DCOLOR(color, label.color); + + ctx->insertDebugLabel(&label); + }); + } + + + BOOL STDMETHODCALLTYPE D3D9UserDefinedAnnotation::GetStatus() { + return TRUE; + } + } diff --git a/src/d3d9/d3d9_annotation.h b/src/d3d9/d3d9_annotation.h index 32930766..1fdb19fc 100644 --- a/src/d3d9/d3d9_annotation.h +++ b/src/d3d9/d3d9_annotation.h @@ -52,4 +52,37 @@ namespace dxvk { }; + class D3D9UserDefinedAnnotation final : public IDXVKUserDefinedAnnotation { + + public: + + D3D9UserDefinedAnnotation(D3D9DeviceEx* device); + ~D3D9UserDefinedAnnotation(); + + ULONG STDMETHODCALLTYPE AddRef(); + + ULONG STDMETHODCALLTYPE Release(); + + HRESULT STDMETHODCALLTYPE QueryInterface( + REFIID riid, + void** ppvObject); + + INT STDMETHODCALLTYPE BeginEvent( + D3DCOLOR Color, + LPCWSTR Name); + + INT STDMETHODCALLTYPE EndEvent(); + + void STDMETHODCALLTYPE SetMarker( + D3DCOLOR Color, + LPCWSTR Name); + + BOOL STDMETHODCALLTYPE GetStatus(); + + private: + + D3D9DeviceEx* m_container; + + }; + } \ No newline at end of file diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index bcd19015..c57e5739 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -59,6 +59,9 @@ namespace dxvk { if (canSWVP) Logger::info("D3D9DeviceEx: Using extended constant set for software vertex processing."); + if (m_dxvkDevice->instance()->extensions().extDebugUtils) + m_annotation = new D3D9UserDefinedAnnotation(this); + m_initializer = new D3D9Initializer(m_dxvkDevice); m_converter = new D3D9FormatHelper(m_dxvkDevice); @@ -145,6 +148,9 @@ namespace dxvk { Flush(); SynchronizeCsThread(DxvkCsThread::SynchronizeAll); + if (m_annotation) + delete m_annotation; + delete m_initializer; delete m_converter; diff --git a/src/d3d9/d3d9_device.h b/src/d3d9/d3d9_device.h index fe8e972f..cec48291 100644 --- a/src/d3d9/d3d9_device.h +++ b/src/d3d9/d3d9_device.h @@ -41,6 +41,7 @@ namespace dxvk { class D3D9Query; class D3D9StateBlock; class D3D9FormatHelper; + class D3D9UserDefinedAnnotation; enum class D3D9DeviceFlag : uint32_t { DirtyFramebuffer, @@ -98,6 +99,7 @@ namespace dxvk { constexpr static uint32_t NullStreamIdx = caps::MaxStreams; friend class D3D9SwapChainEx; + friend class D3D9UserDefinedAnnotation; public: D3D9DeviceEx( @@ -1253,6 +1255,8 @@ namespace dxvk { D3D9ConstantLayout m_vsLayout; D3D9ConstantLayout m_psLayout; D3D9ConstantSets m_consts[DxsoProgramTypes::Count]; + + D3D9UserDefinedAnnotation* m_annotation = nullptr; D3D9ViewportInfo m_viewportInfo;