Commit 22b94c3e authored by Laszlo Agocs's avatar Laszlo Agocs
Browse files

d3d: implement debug markers and object names

parent 2ee4da2c
......@@ -52,6 +52,14 @@
#include <QRhiD3D11InitParams>
#include "examplewindow.h"
#define PROFILE
#ifdef PROFILE
#include <QRhiProfiler>
#include <QFile>
QFile profOut;
#endif
class D3D11Window : public ExampleWindow
{
public:
......@@ -67,7 +75,16 @@ void D3D11Window::init()
QRhiD3D11InitParams params;
params.enableDebugLayer = true;
params.importExistingDevice = false;
m_r = QRhi::create(QRhi::D3D11, &params);
QRhi::Flags flags = QRhi::EnableDebugMarkers;
#ifdef PROFILE
flags |= QRhi::EnableProfiling;
#endif
m_r = QRhi::create(QRhi::D3D11, &params, flags);
#ifdef PROFILE
m_r->profiler()->setDevice(&profOut);
#endif
//setSampleCount(4); // enable 4x MSAA (except for the render-to-texture pass)
......@@ -79,6 +96,11 @@ int main(int argc, char **argv)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
#ifdef PROFILE
profOut.setFileName("rhiprof.cbor");
profOut.open(QIODevice::WriteOnly);
#endif
D3D11Window w;
w.resize(1280, 720);
w.setTitle(QLatin1String("D3D11"));
......
......@@ -148,6 +148,11 @@ bool QRhiD3D11::create(QRhi::Flags flags)
featureLevel = dev->GetFeatureLevel();
}
if (debugMarkers) {
if (FAILED(context->QueryInterface(IID_ID3DUserDefinedAnnotation, reinterpret_cast<void **>(&annotations))))
annotations = nullptr;
}
nativeHandlesStruct.dev = dev;
nativeHandlesStruct.context = context;
......@@ -158,6 +163,11 @@ void QRhiD3D11::destroy()
{
finishActiveReadbacks();
if (annotations) {
annotations->Release();
annotations = nullptr;
}
if (!importedDevice) {
if (context) {
context->Release();
......@@ -480,28 +490,39 @@ void QRhiD3D11::drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount,
void QRhiD3D11::debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name)
{
if (!debugMarkers)
if (!debugMarkers || !annotations)
return;
Q_UNUSED(cb);
Q_UNUSED(name);
QD3D11CommandBuffer *cbD = QRHI_RES(QD3D11CommandBuffer, cb);
QD3D11CommandBuffer::Command cmd;
cmd.cmd = QD3D11CommandBuffer::Command::DebugMarkBegin;
strncpy(cmd.args.debugMark.s, name.constData(), sizeof(cmd.args.debugMark.s));
cmd.args.debugMark.s[sizeof(cmd.args.debugMark.s) - 1] = '\0';
cbD->commands.append(cmd);
}
void QRhiD3D11::debugMarkEnd(QRhiCommandBuffer *cb)
{
if (!debugMarkers)
if (!debugMarkers || !annotations)
return;
Q_UNUSED(cb);
QD3D11CommandBuffer *cbD = QRHI_RES(QD3D11CommandBuffer, cb);
QD3D11CommandBuffer::Command cmd;
cmd.cmd = QD3D11CommandBuffer::Command::DebugMarkEnd;
cbD->commands.append(cmd);
}
void QRhiD3D11::debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg)
{
if (!debugMarkers)
if (!debugMarkers || !annotations)
return;
Q_UNUSED(cb);
Q_UNUSED(msg);
QD3D11CommandBuffer *cbD = QRHI_RES(QD3D11CommandBuffer, cb);
QD3D11CommandBuffer::Command cmd;
cmd.cmd = QD3D11CommandBuffer::Command::DebugMarkMsg;
strncpy(cmd.args.debugMark.s, msg.constData(), sizeof(cmd.args.debugMark.s));
cmd.args.debugMark.s[sizeof(cmd.args.debugMark.s) - 1] = '\0';
cbD->commands.append(cmd);
}
QRhi::FrameOpResult QRhiD3D11::beginFrame(QRhiSwapChain *swapChain)
......@@ -1393,6 +1414,15 @@ void QRhiD3D11::executeCommandBuffer(QD3D11CommandBuffer *cbD)
case QD3D11CommandBuffer::Command::GenMip:
context->GenerateMips(cmd.args.genMip.tex->srv);
break;
case QD3D11CommandBuffer::Command::DebugMarkBegin:
annotations->BeginEvent(reinterpret_cast<LPCWSTR>(QString::fromLatin1(cmd.args.debugMark.s).utf16()));
break;
case QD3D11CommandBuffer::Command::DebugMarkEnd:
annotations->EndEvent();
break;
case QD3D11CommandBuffer::Command::DebugMarkMsg:
annotations->SetMarker(reinterpret_cast<LPCWSTR>(QString::fromLatin1(cmd.args.debugMark.s).utf16()));
break;
default:
break;
}
......@@ -1457,6 +1487,9 @@ bool QD3D11Buffer::build()
hasPendingDynamicUpdates = false;
}
if (!objectName.isEmpty())
buffer->SetPrivateData(WKPDID_D3DDebugObjectName, objectName.size(), objectName.constData());
QRHI_PROF;
QRHI_PROF_F(newBuffer(this, roundedSize, 1, m_type == Dynamic ? 1 : 0));
......@@ -1515,6 +1548,8 @@ bool QD3D11RenderBuffer::build()
qWarning("Failed to create color renderbuffer: %s", qPrintable(comErrorMessage(hr)));
return false;
}
if (!objectName.isEmpty())
tex->SetPrivateData(WKPDID_D3DDebugObjectName, objectName.size(), objectName.constData());
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
memset(&rtvDesc, 0, sizeof(rtvDesc));
rtvDesc.Format = dxgiFormat; rtvDesc.ViewDimension = desc.SampleDesc.Count > 1 ? D3D11_RTV_DIMENSION_TEXTURE2DMS
......@@ -1534,6 +1569,8 @@ bool QD3D11RenderBuffer::build()
qWarning("Failed to create depth-stencil buffer: %s", qPrintable(comErrorMessage(hr)));
return false;
}
if (!objectName.isEmpty())
tex->SetPrivateData(WKPDID_D3DDebugObjectName, objectName.size(), objectName.constData());
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
memset(&dsvDesc, 0, sizeof(dsvDesc));
dsvDesc.Format = dxgiFormat;
......@@ -1721,6 +1758,9 @@ bool QD3D11Texture::build()
if (!finishBuild())
return false;
if (!objectName.isEmpty())
tex->SetPrivateData(WKPDID_D3DDebugObjectName, objectName.size(), objectName.constData());
owns = true;
return true;
}
......
......@@ -259,7 +259,10 @@ struct QD3D11CommandBuffer : public QRhiCommandBuffer
UpdateSubRes,
CopySubRes,
ResolveSubRes,
GenMip
GenMip,
DebugMarkBegin,
DebugMarkEnd,
DebugMarkMsg
};
enum ClearFlag { Color = 1, Depth = 2, Stencil = 4 };
Cmd cmd;
......@@ -349,6 +352,9 @@ struct QD3D11CommandBuffer : public QRhiCommandBuffer
struct {
QD3D11Texture *tex;
} genMip;
struct {
char s[64];
} debugMark;
} args;
};
......@@ -511,6 +517,7 @@ public:
ID3D11Device *dev = nullptr;
ID3D11DeviceContext1 *context = nullptr;
D3D_FEATURE_LEVEL featureLevel;
ID3DUserDefinedAnnotation *annotations = nullptr;
IDXGIFactory2 *dxgiFactory = nullptr;
QRhiD3D11NativeHandles nativeHandlesStruct;
......
prof report api (fed by a cbor stream)
vk, d3d, gl: tex and other prof
vk, d3d, gl: debug: object names
vk, d3d, gl: debug: markers (begin, end, msg)
vk, gl: debug: object names
vk, gl: debug: markers (begin, end, msg)
max texture size stuff
plainqwindow examples should be reorganized into one (using examplefw)
multiwindow_threaded should demo pulling out the device and importing to another rhi
......@@ -53,6 +53,7 @@ dxc for d3d as an alternative to fxc?
hlsl -> dxc -> spirv -> spirv-cross hmmm...
+++ done
d3d: debug markers, object names
d3d: texture import/export
vk: memalloc stats to prof
mtl: debug: markers (begin, end, msg)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment