1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-12 13:08:50 +01:00

[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 <okouznetsov@nvidia.com>
This commit is contained in:
Joshua Ashton 2021-04-30 10:32:10 +01:00 committed by Philip Rebohle
parent 937a60c882
commit cf1cee04b8
6 changed files with 46 additions and 6 deletions

View File

@ -6,13 +6,46 @@
namespace dxvk { namespace dxvk {
template <bool Register>
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<RegistrationFunctionType>(::GetProcAddress(d3d9Module,
reinterpret_cast<const char*>(static_cast<uintptr_t>(ordinal))));
if (!registrationFunction) {
Logger::info("Unable to find DXVK_RegisterAnnotation, some annotations may be missed.");
return;
}
registrationFunction(annotation);
}
D3D11UserDefinedAnnotation::D3D11UserDefinedAnnotation(D3D11DeviceContext* ctx) D3D11UserDefinedAnnotation::D3D11UserDefinedAnnotation(D3D11DeviceContext* ctx)
: m_container(ctx), : m_container(ctx),
m_eventDepth(0) { } m_eventDepth(0) {
if (m_container->IsAnnotationEnabled())
RegisterUserDefinedAnnotation<true>(this);
}
D3D11UserDefinedAnnotation::D3D11UserDefinedAnnotation(const D3D11UserDefinedAnnotation&)
{
if (m_container->IsAnnotationEnabled())
RegisterUserDefinedAnnotation<true>(this);
}
D3D11UserDefinedAnnotation::~D3D11UserDefinedAnnotation() { D3D11UserDefinedAnnotation::~D3D11UserDefinedAnnotation() {
if (m_container->IsAnnotationEnabled())
RegisterUserDefinedAnnotation<false>(this);
} }
@ -39,6 +72,8 @@ namespace dxvk {
if (!m_container->IsAnnotationEnabled()) if (!m_container->IsAnnotationEnabled())
return -1; return -1;
D3D10DeviceLock lock = m_container->LockContext();
m_container->EmitCs([color = Color, labelName = dxvk::str::fromws(Name)](DxvkContext *ctx) { m_container->EmitCs([color = Color, labelName = dxvk::str::fromws(Name)](DxvkContext *ctx) {
VkDebugUtilsLabelEXT label; VkDebugUtilsLabelEXT label;
label.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; label.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT;
@ -73,6 +108,8 @@ namespace dxvk {
if (!m_container->IsAnnotationEnabled()) if (!m_container->IsAnnotationEnabled())
return; return;
D3D10DeviceLock lock = m_container->LockContext();
m_container->EmitCs([color = Color, labelName = dxvk::str::fromws(Name)](DxvkContext *ctx) { m_container->EmitCs([color = Color, labelName = dxvk::str::fromws(Name)](DxvkContext *ctx) {
VkDebugUtilsLabelEXT label; VkDebugUtilsLabelEXT label;
label.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; label.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT;

View File

@ -12,6 +12,7 @@ namespace dxvk {
public: public:
D3D11UserDefinedAnnotation(D3D11DeviceContext* ctx); D3D11UserDefinedAnnotation(D3D11DeviceContext* ctx);
D3D11UserDefinedAnnotation(const D3D11UserDefinedAnnotation&);
~D3D11UserDefinedAnnotation(); ~D3D11UserDefinedAnnotation();
ULONG STDMETHODCALLTYPE AddRef(); ULONG STDMETHODCALLTYPE AddRef();

View File

@ -16,10 +16,10 @@ namespace dxvk {
DxvkCsChunkFlags CsFlags) DxvkCsChunkFlags CsFlags)
: D3D11DeviceChild<ID3D11DeviceContext4>(pParent), : D3D11DeviceChild<ID3D11DeviceContext4>(pParent),
m_contextExt(this), m_contextExt(this),
m_annotation(this),
m_multithread(this, false), m_multithread(this, false),
m_device (Device), m_device (Device),
m_staging (Device, StagingBufferSize), m_staging (Device, StagingBufferSize),
m_annotation(this),
m_csFlags (CsFlags), m_csFlags (CsFlags),
m_csChunk (AllocCsChunk()), m_csChunk (AllocCsChunk()),
m_cmdData (nullptr) { m_cmdData (nullptr) {

View File

@ -693,7 +693,6 @@ namespace dxvk {
protected: protected:
D3D11DeviceContextExt m_contextExt; D3D11DeviceContextExt m_contextExt;
D3D11UserDefinedAnnotation m_annotation;
D3D10Multithread m_multithread; D3D10Multithread m_multithread;
Rc<DxvkDevice> m_device; Rc<DxvkDevice> m_device;
@ -701,6 +700,9 @@ namespace dxvk {
DxvkStagingBuffer m_staging; 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; DxvkCsChunkFlags m_csFlags;
DxvkCsChunkRef m_csChunk; DxvkCsChunkRef m_csChunk;

View File

@ -3,7 +3,7 @@
#include "d3d9_interface.h" #include "d3d9_interface.h"
#include "d3d9_shader_validator.h" #include "d3d9_shader_validator.h"
#include "../d3d9/d3d9_annotation.h" #include "d3d9_annotation.h"
class D3DFE_PROCESSVERTICES; class D3DFE_PROCESSVERTICES;
using PSGPERRORID = UINT; using PSGPERRORID = UINT;

View File

@ -39,7 +39,7 @@ d3d9_src = [
'd3d9_swvp_emu.cpp', 'd3d9_swvp_emu.cpp',
'd3d9_format_helpers.cpp', 'd3d9_format_helpers.cpp',
'd3d9_hud.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, d3d9_dll = shared_library('d3d9'+dll_ext, d3d9_src, glsl_generator.process(d3d9_shaders), d3d9_res,