From 4af974768a45c6520b0bed39f50f0ee20fb81010 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 3 Aug 2022 17:04:33 +0200 Subject: [PATCH] [d3d11] Refactor D3D11UserDefinedAnnotation --- src/d3d11/d3d11_annotation.cpp | 25 +++++++++++-------------- src/d3d11/d3d11_annotation.h | 18 ++++++++++++------ src/d3d11/d3d11_context.cpp | 4 ++-- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/d3d11/d3d11_annotation.cpp b/src/d3d11/d3d11_annotation.cpp index 7c74b7ad3..2eb79d7aa 100644 --- a/src/d3d11/d3d11_annotation.cpp +++ b/src/d3d11/d3d11_annotation.cpp @@ -30,21 +30,18 @@ namespace dxvk { registrationFunction(annotation); } - D3D11UserDefinedAnnotation::D3D11UserDefinedAnnotation(D3D11DeviceContext* ctx) - : m_container(ctx), - m_eventDepth(0) { - if (m_container->IsAnnotationEnabled()) + D3D11UserDefinedAnnotation::D3D11UserDefinedAnnotation( + D3D11DeviceContext* container, + const Rc& dxvkDevice) + : m_container(container), m_eventDepth(0), + m_annotationsEnabled(dxvkDevice->instance()->extensions().extDebugUtils) { + if (m_annotationsEnabled) RegisterUserDefinedAnnotation(this); } - D3D11UserDefinedAnnotation::D3D11UserDefinedAnnotation(const D3D11UserDefinedAnnotation&) - { - if (m_container->IsAnnotationEnabled()) - RegisterUserDefinedAnnotation(this); - } D3D11UserDefinedAnnotation::~D3D11UserDefinedAnnotation() { - if (m_container->IsAnnotationEnabled()) + if (m_annotationsEnabled) RegisterUserDefinedAnnotation(this); } @@ -69,7 +66,7 @@ namespace dxvk { INT STDMETHODCALLTYPE D3D11UserDefinedAnnotation::BeginEvent( D3DCOLOR Color, LPCWSTR Name) { - if (!m_container->IsAnnotationEnabled()) + if (!m_annotationsEnabled) return -1; D3D10DeviceLock lock = m_container->LockContext(); @@ -89,7 +86,7 @@ namespace dxvk { INT STDMETHODCALLTYPE D3D11UserDefinedAnnotation::EndEvent() { - if (!m_container->IsAnnotationEnabled()) + if (!m_annotationsEnabled) return -1; D3D10DeviceLock lock = m_container->LockContext(); @@ -105,7 +102,7 @@ namespace dxvk { void STDMETHODCALLTYPE D3D11UserDefinedAnnotation::SetMarker( D3DCOLOR Color, LPCWSTR Name) { - if (!m_container->IsAnnotationEnabled()) + if (!m_annotationsEnabled) return; D3D10DeviceLock lock = m_container->LockContext(); @@ -123,7 +120,7 @@ namespace dxvk { BOOL STDMETHODCALLTYPE D3D11UserDefinedAnnotation::GetStatus() { - return m_container->IsAnnotationEnabled(); + return m_annotationsEnabled; } } diff --git a/src/d3d11/d3d11_annotation.h b/src/d3d11/d3d11_annotation.h index 06d80af61..8419b92cc 100644 --- a/src/d3d11/d3d11_annotation.h +++ b/src/d3d11/d3d11_annotation.h @@ -1,7 +1,9 @@ #pragma once #include "d3d11_include.h" + #include "../dxvk/dxvk_annotation.h" +#include "../dxvk/dxvk_device.h" namespace dxvk { @@ -11,10 +13,15 @@ namespace dxvk { public: - D3D11UserDefinedAnnotation(D3D11DeviceContext* ctx); - D3D11UserDefinedAnnotation(const D3D11UserDefinedAnnotation&); + D3D11UserDefinedAnnotation( + D3D11DeviceContext* container, + const Rc& dxvkDevice); + ~D3D11UserDefinedAnnotation(); + D3D11UserDefinedAnnotation (const D3D11UserDefinedAnnotation&) = delete; + D3D11UserDefinedAnnotation& operator = (const D3D11UserDefinedAnnotation&) = delete; + ULONG STDMETHODCALLTYPE AddRef(); ULONG STDMETHODCALLTYPE Release(); @@ -37,10 +44,9 @@ namespace dxvk { private: - D3D11DeviceContext* m_container; - - // Stack depth for non-finalized BeginEvent calls - int32_t m_eventDepth; + D3D11DeviceContext* m_container; + int32_t m_eventDepth; + bool m_annotationsEnabled; }; } diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 8aff2312e..9920150cc 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -19,7 +19,7 @@ namespace dxvk { m_multithread(this, false), m_device (Device), m_staging (Device, StagingBufferSize), - m_annotation(this), + m_annotation(this, Device), m_csFlags (CsFlags), m_csChunk (AllocCsChunk()), m_cmdData (nullptr) { @@ -2821,7 +2821,7 @@ namespace dxvk { BOOL STDMETHODCALLTYPE D3D11DeviceContext::IsAnnotationEnabled() { - return m_device->instance()->extensions().extDebugUtils; + return m_annotation.GetStatus(); }