2018-06-11 14:29:47 +02:00
|
|
|
#include "d3d11_annotation.h"
|
2021-04-01 12:16:44 -07:00
|
|
|
#include "d3d11_context.h"
|
|
|
|
#include "d3d11_device.h"
|
2018-06-11 14:29:47 +02:00
|
|
|
|
2021-04-30 09:04:30 +01:00
|
|
|
#include "../util/util_misc.h"
|
|
|
|
|
2018-06-11 14:29:47 +02:00
|
|
|
namespace dxvk {
|
|
|
|
|
2021-04-30 10:32:10 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-04-01 12:16:44 -07:00
|
|
|
D3D11UserDefinedAnnotation::D3D11UserDefinedAnnotation(D3D11DeviceContext* ctx)
|
|
|
|
: m_container(ctx),
|
2021-04-30 10:32:10 +01:00
|
|
|
m_eventDepth(0) {
|
|
|
|
if (m_container->IsAnnotationEnabled())
|
|
|
|
RegisterUserDefinedAnnotation<true>(this);
|
|
|
|
}
|
2018-06-11 14:29:47 +02:00
|
|
|
|
2021-04-30 10:32:10 +01:00
|
|
|
D3D11UserDefinedAnnotation::D3D11UserDefinedAnnotation(const D3D11UserDefinedAnnotation&)
|
|
|
|
{
|
|
|
|
if (m_container->IsAnnotationEnabled())
|
|
|
|
RegisterUserDefinedAnnotation<true>(this);
|
|
|
|
}
|
2018-06-11 14:29:47 +02:00
|
|
|
|
|
|
|
D3D11UserDefinedAnnotation::~D3D11UserDefinedAnnotation() {
|
2021-04-30 10:32:10 +01:00
|
|
|
if (m_container->IsAnnotationEnabled())
|
|
|
|
RegisterUserDefinedAnnotation<false>(this);
|
2018-06-11 14:29:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE D3D11UserDefinedAnnotation::AddRef() {
|
|
|
|
return m_container->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE D3D11UserDefinedAnnotation::Release() {
|
|
|
|
return m_container->Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE D3D11UserDefinedAnnotation::QueryInterface(
|
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject) {
|
|
|
|
return m_container->QueryInterface(riid, ppvObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INT STDMETHODCALLTYPE D3D11UserDefinedAnnotation::BeginEvent(
|
2021-04-30 09:04:30 +01:00
|
|
|
D3DCOLOR Color,
|
2018-06-11 14:29:47 +02:00
|
|
|
LPCWSTR Name) {
|
2021-04-01 12:16:44 -07:00
|
|
|
if (!m_container->IsAnnotationEnabled())
|
|
|
|
return -1;
|
|
|
|
|
2021-04-30 10:32:10 +01:00
|
|
|
D3D10DeviceLock lock = m_container->LockContext();
|
|
|
|
|
2021-04-30 09:04:30 +01:00
|
|
|
m_container->EmitCs([color = Color, labelName = dxvk::str::fromws(Name)](DxvkContext *ctx) {
|
2021-04-01 12:16:44 -07:00
|
|
|
VkDebugUtilsLabelEXT label;
|
|
|
|
label.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT;
|
|
|
|
label.pNext = nullptr;
|
|
|
|
label.pLabelName = labelName.c_str();
|
2021-04-30 09:04:30 +01:00
|
|
|
DecodeD3DCOLOR(color, label.color);
|
2021-04-01 12:16:44 -07:00
|
|
|
|
|
|
|
ctx->beginDebugLabel(&label);
|
|
|
|
});
|
|
|
|
|
|
|
|
return m_eventDepth++;
|
2018-06-11 14:29:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INT STDMETHODCALLTYPE D3D11UserDefinedAnnotation::EndEvent() {
|
2021-04-01 12:16:44 -07:00
|
|
|
if (!m_container->IsAnnotationEnabled())
|
|
|
|
return -1;
|
|
|
|
|
2021-12-17 17:48:51 +00:00
|
|
|
D3D10DeviceLock lock = m_container->LockContext();
|
|
|
|
|
2021-04-01 12:16:44 -07:00
|
|
|
m_container->EmitCs([](DxvkContext *ctx) {
|
|
|
|
ctx->endDebugLabel();
|
|
|
|
});
|
|
|
|
|
|
|
|
return m_eventDepth--;
|
2018-06-11 14:29:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void STDMETHODCALLTYPE D3D11UserDefinedAnnotation::SetMarker(
|
2021-04-30 09:04:30 +01:00
|
|
|
D3DCOLOR Color,
|
2018-06-11 14:29:47 +02:00
|
|
|
LPCWSTR Name) {
|
2021-04-01 12:16:44 -07:00
|
|
|
if (!m_container->IsAnnotationEnabled())
|
|
|
|
return;
|
|
|
|
|
2021-04-30 10:32:10 +01:00
|
|
|
D3D10DeviceLock lock = m_container->LockContext();
|
|
|
|
|
2021-04-30 09:04:30 +01:00
|
|
|
m_container->EmitCs([color = Color, labelName = dxvk::str::fromws(Name)](DxvkContext *ctx) {
|
2021-04-01 12:16:44 -07:00
|
|
|
VkDebugUtilsLabelEXT label;
|
|
|
|
label.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT;
|
|
|
|
label.pNext = nullptr;
|
|
|
|
label.pLabelName = labelName.c_str();
|
2021-04-30 09:04:30 +01:00
|
|
|
DecodeD3DCOLOR(color, label.color);
|
2021-04-01 12:16:44 -07:00
|
|
|
|
|
|
|
ctx->insertDebugLabel(&label);
|
|
|
|
});
|
2018-06-11 14:29:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL STDMETHODCALLTYPE D3D11UserDefinedAnnotation::GetStatus() {
|
2021-04-01 12:16:44 -07:00
|
|
|
return m_container->IsAnnotationEnabled();
|
2018-06-11 14:29:47 +02:00
|
|
|
}
|
|
|
|
|
2021-04-01 12:16:44 -07:00
|
|
|
}
|