#include "d3d11_annotation.h" #include "d3d11_context_def.h" #include "d3d11_context_imm.h" #include "d3d11_device.h" #include "../util/util_misc.h" #include "../util/util_win32_compat.h" 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); } template D3D11UserDefinedAnnotation::D3D11UserDefinedAnnotation( ContextType* container, const Rc& dxvkDevice) : m_container(container), m_eventDepth(0), m_annotationsEnabled(dxvkDevice->instance()->extensions().extDebugUtils) { if (!IsDeferred && m_annotationsEnabled) RegisterUserDefinedAnnotation(this); } template D3D11UserDefinedAnnotation::~D3D11UserDefinedAnnotation() { if (!IsDeferred && m_annotationsEnabled) RegisterUserDefinedAnnotation(this); } template ULONG STDMETHODCALLTYPE D3D11UserDefinedAnnotation::AddRef() { return m_container->AddRef(); } template ULONG STDMETHODCALLTYPE D3D11UserDefinedAnnotation::Release() { return m_container->Release(); } template HRESULT STDMETHODCALLTYPE D3D11UserDefinedAnnotation::QueryInterface( REFIID riid, void** ppvObject) { return m_container->QueryInterface(riid, ppvObject); } template INT STDMETHODCALLTYPE D3D11UserDefinedAnnotation::BeginEvent( D3DCOLOR Color, LPCWSTR Name) { if (!m_annotationsEnabled) 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; label.pNext = nullptr; label.pLabelName = labelName.c_str(); DecodeD3DCOLOR(color, label.color); ctx->beginDebugLabel(&label); }); return m_eventDepth++; } template INT STDMETHODCALLTYPE D3D11UserDefinedAnnotation::EndEvent() { if (!m_annotationsEnabled) return -1; D3D10DeviceLock lock = m_container->LockContext(); m_container->EmitCs([](DxvkContext *ctx) { ctx->endDebugLabel(); }); return m_eventDepth--; } template void STDMETHODCALLTYPE D3D11UserDefinedAnnotation::SetMarker( D3DCOLOR Color, LPCWSTR Name) { if (!m_annotationsEnabled) 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; label.pNext = nullptr; label.pLabelName = labelName.c_str(); DecodeD3DCOLOR(color, label.color); ctx->insertDebugLabel(&label); }); } template BOOL STDMETHODCALLTYPE D3D11UserDefinedAnnotation::GetStatus() { return m_annotationsEnabled; } template class D3D11UserDefinedAnnotation; template class D3D11UserDefinedAnnotation; }