From 5f3c3044a591576ac6ec1f0516cf7791f2c7d1cc Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 3 Apr 2023 16:14:45 +0200 Subject: [PATCH] rhi: d3d12: Implement debug markers As usual this is only doing anything when launched with QSG_RHI_PROFILE=1. Otherwise the debugMark* functions are no-ops. Uses the old PIX API (pix.h) since that is what is available in the Windows SDK. This works well with RenderDoc. The strings show up in PIX captures as well although that will warn that the pix.h stuff is deprecated. Unfortunately using the PIX3 API involves headers and libraries not part of the Windows SDK so we do not want to open that can of worms now. Problem is, pix.h may not be present in some SDKs as shown in the CI. So use __has_include and lose the whole feature if the header is not present at build time. Change-Id: I8606d151f75a492071bf0c8d98b16026ff94d45c Reviewed-by: Qt CI Bot Reviewed-by: Andy Nichols --- src/gui/rhi/qrhid3d12.cpp | 41 +++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/gui/rhi/qrhid3d12.cpp b/src/gui/rhi/qrhid3d12.cpp index 20d01db1fa..d80fe8a406 100644 --- a/src/gui/rhi/qrhid3d12.cpp +++ b/src/gui/rhi/qrhid3d12.cpp @@ -14,6 +14,11 @@ #include "cs_mipmap_p.h" +#if __has_include() +#include +#define QRHI_D3D12_HAS_OLD_PIX +#endif + QT_BEGIN_NAMESPACE /* @@ -514,7 +519,11 @@ bool QRhiD3D12::isFeatureSupported(QRhi::Feature feature) const case QRhi::MultisampleRenderBuffer: return true; case QRhi::DebugMarkers: - return false; // ### +#ifdef QRHI_D3D12_HAS_OLD_PIX + return true; +#else + return false; +#endif case QRhi::Timestamps: return false; // ### case QRhi::Instancing: @@ -1261,19 +1270,43 @@ void QRhiD3D12::drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount, void QRhiD3D12::debugMarkBegin(QRhiCommandBuffer *cb, const QByteArray &name) { - Q_UNUSED(cb); + if (!debugMarkers) + return; + + QD3D12CommandBuffer *cbD = QRHI_RES(QD3D12CommandBuffer, cb); +#ifdef QRHI_D3D12_HAS_OLD_PIX + PIXBeginEvent(cbD->cmdList, PIX_COLOR_DEFAULT, reinterpret_cast(QString::fromLatin1(name).utf16())); +#else + Q_UNUSED(cbD); Q_UNUSED(name); +#endif } void QRhiD3D12::debugMarkEnd(QRhiCommandBuffer *cb) { - Q_UNUSED(cb); + if (!debugMarkers) + return; + + QD3D12CommandBuffer *cbD = QRHI_RES(QD3D12CommandBuffer, cb); +#ifdef QRHI_D3D12_HAS_OLD_PIX + PIXEndEvent(cbD->cmdList); +#else + Q_UNUSED(cbD); +#endif } void QRhiD3D12::debugMarkMsg(QRhiCommandBuffer *cb, const QByteArray &msg) { - Q_UNUSED(cb); + if (!debugMarkers) + return; + + QD3D12CommandBuffer *cbD = QRHI_RES(QD3D12CommandBuffer, cb); +#ifdef QRHI_D3D12_HAS_OLD_PIX + PIXSetMarker(cbD->cmdList, PIX_COLOR_DEFAULT, reinterpret_cast(QString::fromLatin1(msg).utf16())); +#else + Q_UNUSED(cbD); Q_UNUSED(msg); +#endif } const QRhiNativeHandles *QRhiD3D12::nativeHandles(QRhiCommandBuffer *cb)