From fb0b11903baeaf2ebacea26e077cd220b09e00ce Mon Sep 17 00:00:00 2001 From: Liam Middlebrook Date: Thu, 1 Apr 2021 12:16:44 -0700 Subject: [PATCH] [d3d11] Implement D3D11UserDefinedAnnotation Reviewed-by: Oleg Kuznetsov --- src/d3d11/d3d11_annotation.cpp | 57 ++++++++++++++++++++++++++++------ src/d3d11/d3d11_annotation.h | 10 ++++-- src/d3d11/d3d11_context.cpp | 3 +- src/d3d11/d3d11_context.h | 2 ++ 4 files changed, 57 insertions(+), 15 deletions(-) diff --git a/src/d3d11/d3d11_annotation.cpp b/src/d3d11/d3d11_annotation.cpp index d582efdf6..010acdd81 100644 --- a/src/d3d11/d3d11_annotation.cpp +++ b/src/d3d11/d3d11_annotation.cpp @@ -1,9 +1,12 @@ #include "d3d11_annotation.h" +#include "d3d11_context.h" +#include "d3d11_device.h" namespace dxvk { - D3D11UserDefinedAnnotation::D3D11UserDefinedAnnotation(ID3D11DeviceContext* ctx) - : m_container(ctx) { } + D3D11UserDefinedAnnotation::D3D11UserDefinedAnnotation(D3D11DeviceContext* ctx) + : m_container(ctx), + m_eventDepth(0) { } D3D11UserDefinedAnnotation::~D3D11UserDefinedAnnotation() { @@ -30,26 +33,60 @@ namespace dxvk { INT STDMETHODCALLTYPE D3D11UserDefinedAnnotation::BeginEvent( LPCWSTR Name) { - // Currently not implemented - return -1; + if (!m_container->IsAnnotationEnabled()) + return -1; + + m_container->EmitCs([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(); + label.color[0] = 1.0f; + label.color[1] = 1.0f; + label.color[2] = 1.0f; + label.color[3] = 1.0f; + + ctx->beginDebugLabel(&label); + }); + + return m_eventDepth++; } INT STDMETHODCALLTYPE D3D11UserDefinedAnnotation::EndEvent() { - // Currently not implemented - return -1; + if (!m_container->IsAnnotationEnabled()) + return -1; + + m_container->EmitCs([](DxvkContext *ctx) { + ctx->endDebugLabel(); + }); + + return m_eventDepth--; } void STDMETHODCALLTYPE D3D11UserDefinedAnnotation::SetMarker( LPCWSTR Name) { - // Currently not implemented + if (!m_container->IsAnnotationEnabled()) + return; + + m_container->EmitCs([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(); + label.color[0] = 1.0f; + label.color[1] = 1.0f; + label.color[2] = 1.0f; + label.color[3] = 1.0f; + + ctx->insertDebugLabel(&label); + }); } BOOL STDMETHODCALLTYPE D3D11UserDefinedAnnotation::GetStatus() { - // Currently not implemented - return FALSE; + return m_container->IsAnnotationEnabled(); } -} \ No newline at end of file +} diff --git a/src/d3d11/d3d11_annotation.h b/src/d3d11/d3d11_annotation.h index 41b174ad1..97ee39c4a 100644 --- a/src/d3d11/d3d11_annotation.h +++ b/src/d3d11/d3d11_annotation.h @@ -4,11 +4,13 @@ namespace dxvk { + class D3D11DeviceContext; + class D3D11UserDefinedAnnotation : ID3DUserDefinedAnnotation { public: - D3D11UserDefinedAnnotation(ID3D11DeviceContext* ctx); + D3D11UserDefinedAnnotation(D3D11DeviceContext* ctx); ~D3D11UserDefinedAnnotation(); ULONG STDMETHODCALLTYPE AddRef(); @@ -31,8 +33,10 @@ namespace dxvk { private: - ID3D11DeviceContext* m_container; + D3D11DeviceContext* m_container; + // Stack depth for non-finalized BeginEvent calls + int32_t m_eventDepth; }; -} \ No newline at end of file +} diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 284b63604..b64d14d5b 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -3064,8 +3064,7 @@ namespace dxvk { BOOL STDMETHODCALLTYPE D3D11DeviceContext::IsAnnotationEnabled() { - // Not implemented in the backend - return FALSE; + return m_device->instance()->extensions().extDebugUtils; } diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index de5b82b02..125b0e5d8 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -19,6 +19,8 @@ namespace dxvk { class D3D11DeviceContext : public D3D11DeviceChild { friend class D3D11DeviceContextExt; + // Needed in order to call EmitCs for pushing markers + friend class D3D11UserDefinedAnnotation; public: D3D11DeviceContext(