From cf1cee04b872a3db06d8504790792b990479e56c Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Fri, 30 Apr 2021 10:32:10 +0100 Subject: [PATCH] [d3d11] Register annotation interfaces with D3D9 Some apps try use the D3DPERF_ functions for debug markers/annotations. This utilizes the DXVK_RegisterAnnotation hidden functions to share the interfaces. Co-authored-by: Oleg Kuznetsov --- src/d3d11/d3d11_annotation.cpp | 41 ++++++++++++++++++++++++++++++++-- src/d3d11/d3d11_annotation.h | 1 + src/d3d11/d3d11_context.cpp | 2 +- src/d3d11/d3d11_context.h | 4 +++- src/d3d9/d3d9_main.cpp | 2 +- src/d3d9/meson.build | 2 +- 6 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/d3d11/d3d11_annotation.cpp b/src/d3d11/d3d11_annotation.cpp index 97d29a10..7c74b7ad 100644 --- a/src/d3d11/d3d11_annotation.cpp +++ b/src/d3d11/d3d11_annotation.cpp @@ -6,13 +6,46 @@ namespace dxvk { + template + static void RegisterUserDefinedAnnotation(IDXVKUserDefinedAnnotation* annotation) { + using RegistrationFunctionType = void(__stdcall *)(IDXVKUserDefinedAnnotation*); + static const int16_t RegisterOrdinal = 28257; + static const int16_t UnregisterOrdinal = 28258; + + HMODULE d3d9Module = ::LoadLibraryA("d3d9.dll"); + if (!d3d9Module) { + Logger::info("Unable to find d3d9, some annotations may be missed."); + return; + } + + const int16_t ordinal = Register ? RegisterOrdinal : UnregisterOrdinal; + auto registrationFunction = reinterpret_cast(::GetProcAddress(d3d9Module, + reinterpret_cast(static_cast(ordinal)))); + + if (!registrationFunction) { + Logger::info("Unable to find DXVK_RegisterAnnotation, some annotations may be missed."); + return; + } + + registrationFunction(annotation); + } + D3D11UserDefinedAnnotation::D3D11UserDefinedAnnotation(D3D11DeviceContext* ctx) : m_container(ctx), - m_eventDepth(0) { } + m_eventDepth(0) { + if (m_container->IsAnnotationEnabled()) + RegisterUserDefinedAnnotation(this); + } + D3D11UserDefinedAnnotation::D3D11UserDefinedAnnotation(const D3D11UserDefinedAnnotation&) + { + if (m_container->IsAnnotationEnabled()) + RegisterUserDefinedAnnotation(this); + } D3D11UserDefinedAnnotation::~D3D11UserDefinedAnnotation() { - + if (m_container->IsAnnotationEnabled()) + RegisterUserDefinedAnnotation(this); } @@ -39,6 +72,8 @@ namespace dxvk { if (!m_container->IsAnnotationEnabled()) return -1; + D3D10DeviceLock lock = m_container->LockContext(); + m_container->EmitCs([color = Color, labelName = dxvk::str::fromws(Name)](DxvkContext *ctx) { VkDebugUtilsLabelEXT label; label.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; @@ -73,6 +108,8 @@ namespace dxvk { if (!m_container->IsAnnotationEnabled()) return; + D3D10DeviceLock lock = m_container->LockContext(); + m_container->EmitCs([color = Color, labelName = dxvk::str::fromws(Name)](DxvkContext *ctx) { VkDebugUtilsLabelEXT label; label.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; diff --git a/src/d3d11/d3d11_annotation.h b/src/d3d11/d3d11_annotation.h index 702abe40..06d80af6 100644 --- a/src/d3d11/d3d11_annotation.h +++ b/src/d3d11/d3d11_annotation.h @@ -12,6 +12,7 @@ namespace dxvk { public: D3D11UserDefinedAnnotation(D3D11DeviceContext* ctx); + D3D11UserDefinedAnnotation(const D3D11UserDefinedAnnotation&); ~D3D11UserDefinedAnnotation(); ULONG STDMETHODCALLTYPE AddRef(); diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index b9b91efb..4a1bf67b 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -16,10 +16,10 @@ namespace dxvk { DxvkCsChunkFlags CsFlags) : D3D11DeviceChild(pParent), m_contextExt(this), - m_annotation(this), m_multithread(this, false), m_device (Device), m_staging (Device, StagingBufferSize), + m_annotation(this), m_csFlags (CsFlags), m_csChunk (AllocCsChunk()), m_cmdData (nullptr) { diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index c63e60e4..3bd60a57 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -693,13 +693,15 @@ namespace dxvk { protected: D3D11DeviceContextExt m_contextExt; - D3D11UserDefinedAnnotation m_annotation; D3D10Multithread m_multithread; Rc m_device; Rc m_updateBuffer; DxvkStagingBuffer m_staging; + + //has to be declared after m_device, as compiler initialize in order of declaration in the class + D3D11UserDefinedAnnotation m_annotation; DxvkCsChunkFlags m_csFlags; DxvkCsChunkRef m_csChunk; diff --git a/src/d3d9/d3d9_main.cpp b/src/d3d9/d3d9_main.cpp index b6e959dd..367dac9c 100644 --- a/src/d3d9/d3d9_main.cpp +++ b/src/d3d9/d3d9_main.cpp @@ -3,7 +3,7 @@ #include "d3d9_interface.h" #include "d3d9_shader_validator.h" -#include "../d3d9/d3d9_annotation.h" +#include "d3d9_annotation.h" class D3DFE_PROCESSVERTICES; using PSGPERRORID = UINT; diff --git a/src/d3d9/meson.build b/src/d3d9/meson.build index 9750cd4c..2cd8951e 100644 --- a/src/d3d9/meson.build +++ b/src/d3d9/meson.build @@ -39,7 +39,7 @@ d3d9_src = [ 'd3d9_swvp_emu.cpp', 'd3d9_format_helpers.cpp', 'd3d9_hud.cpp', - 'd3d9_annotation.cpp', + 'd3d9_annotation.cpp' ] d3d9_dll = shared_library('d3d9'+dll_ext, d3d9_src, glsl_generator.process(d3d9_shaders), d3d9_res,