5#include <QtCore/qcoreapplication.h>
6#include <QtCore/qfile.h>
7#include <QtCore/qlibrary.h>
8#include <QtCore/qmutex.h>
9#include "QtGui/rhi/qrhi.h"
10#include "QtGui/rhi/qrhi_platform.h"
11#include "QtGui/qopenglcontext.h"
19QBasicMutex QGraphicsFrameCaptureRenderDoc::s_frameCaptureMutex;
32 QNativeInterface::QEGLContext *eglItf =
context->nativeInterface<QNativeInterface::QEGLContext>();
34 nctx = eglItf->nativeContext();
37#if QT_CONFIG(xcb_glx_plugin)
38 QNativeInterface::QGLXContext *glxItf =
context->nativeInterface<QNativeInterface::QGLXContext>();
40 nctx = glxItf->nativeContext();
97 : m_nativeHandlesSet(
false)
118 qCWarning(lcGraphicsFrameCapture) <<
"Could not find valid handles for D3D11. Check platform support";
123 const QRhiD3D12NativeHandles *d3d12nh =
static_cast<const QRhiD3D12NativeHandles *
>(nh);
127 qCWarning(lcGraphicsFrameCapture) <<
"Could not find valid handles for D3D12. Check platform support";
133 m_nativeHandle = RENDERDOC_DEVICEPOINTER_FROM_VKINSTANCE(vknh->inst->vkInstance());
136 qCWarning(lcGraphicsFrameCapture) <<
"Could not find valid handles for Vulkan. Check platform support";
146 qCWarning(lcGraphicsFrameCapture) <<
"Could not find valid handles for OpenGL. Check platform support";
151 qCWarning(lcGraphicsFrameCapture) <<
"Invalid handles were provided."
152 " Metal and Null backends are not supported with RenderDoc";
157 m_nativeHandlesSet =
true;
169 qCWarning(lcGraphicsFrameCapture) <<
"RenderDoc was not initialized."
170 " Starting capturing can not be done.";
178 if (s_rdocApi->IsFrameCapturing()) {
179 qCWarning(lcGraphicsFrameCapture) <<
"A frame capture is already in progress, "
180 "will not initiate another one until"
181 " QGraphicsFrameCapture::endCaptureFrame is called.";
185 qCInfo(lcGraphicsFrameCapture) <<
"A frame capture is going to start.";
186 updateCapturePathAndTemplate();
200 qCWarning(lcGraphicsFrameCapture) <<
"RenderDoc was not initialized."
201 " End capturing can not be done.";
209 if (!s_rdocApi->IsFrameCapturing()) {
210 qCWarning(lcGraphicsFrameCapture) <<
"A call to QGraphicsFrameCapture::endCaptureFrame can not be done"
211 " without a call to QGraphicsFrameCapture::startCaptureFrame";
215 qCInfo(lcGraphicsFrameCapture) <<
"A frame capture is going to end.";
219 uint32_t
count = s_rdocApi->GetNumCaptures();
220 uint32_t pathLength = 0;
221 s_rdocApi->GetCapture(
count - 1,
nullptr, &pathLength,
nullptr);
222 if (pathLength > 0) {
223 QVarLengthArray<char>
name(pathLength, 0);
224 s_rdocApi->GetCapture(
count - 1,
name.data(), &pathLength,
nullptr);
230void QGraphicsFrameCaptureRenderDoc::updateCapturePathAndTemplate()
233 qCWarning(lcGraphicsFrameCapture) <<
"RenderDoc was not initialized."
234 " Updating save location can not be done.";
240 s_rdocApi->SetCaptureFilePathTemplate(rdocFilePathTemplate.toUtf8().constData());
248 return s_rdocApi && m_nativeHandlesSet;
254 qCWarning(lcGraphicsFrameCapture) <<
"RenderDoc was not initialized."
255 " Can not query if capturing is in progress or not.";
259 return s_rdocApi->IsFrameCapturing();
265 qCWarning(lcGraphicsFrameCapture) <<
"RenderDoc was not initialized."
266 " Can not open RenderDoc UI tool.";
274 if (s_rdocApi->IsTargetControlConnected())
275 s_rdocApi->ShowReplayUI();
277 s_rdocApi->LaunchReplayUI(1,
nullptr);
280void QGraphicsFrameCaptureRenderDoc::init()
288 pRENDERDOC_GetAPI RENDERDOC_GetAPI = (pRENDERDOC_GetAPI) renderDocLib.resolve(
"RENDERDOC_GetAPI");
289 if (!renderDocLib.isLoaded() || (RENDERDOC_GetAPI ==
nullptr)) {
290 qCWarning(lcGraphicsFrameCapture) << renderDocLib.errorString().toLatin1();
294 int ret = RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_6_0,
static_cast<void **
>(
static_cast<void *
>(&s_rdocApi)));
297 qCWarning(lcGraphicsFrameCapture) <<
"The requested RenderDoc API is invalid or not supported";
301 s_rdocApi->MaskOverlayBits(RENDERDOC_OverlayBits::eRENDERDOC_Overlay_None,
302 RENDERDOC_OverlayBits::eRENDERDOC_Overlay_None);
303 s_rdocApi->SetCaptureKeys(
nullptr, 0);
304 s_rdocApi->SetFocusToggleKeys(
nullptr, 0);
307 s_rdocApi->SetCaptureFilePathTemplate(rdocFilePathTemplate.toUtf8().constData());
QStringList m_capturedFilesNames
The QGraphicsFrameCaptureRenderDoc class provides a way to capture a record of draw calls for differe...
void setRhi(QRhi *rhi) override
bool initialized() const override
Returns true if the API is loaded and can capture frames or not.
void openCapture() override
QGraphicsFrameCaptureRenderDoc()
Creates a new object of this class.
void startCaptureFrame() override
Starts a frame capture using the set native handles provided through QGraphicsFrameCaptureRenderDoc::...
bool isCapturing() const override
void endCaptureFrame() override
Ends a frame capture started by a call to QGraphicsFrameCaptureRenderDoc::startCaptureFrame using the...
\inmodule QtCore \reentrant
Native interface to an NSOpenGLContext on \macos.
\inheaderfile QOpenGLContext
\variable QRhiD3D11InitParams::enableDebugLayer
\variable QRhiGles2InitParams::format
\variable QRhiVulkanInitParams::inst
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Implementation backend() const
Implementation
Describes which graphics API-specific backend gets used by a QRhi instance.
const QRhiNativeHandles * nativeHandles()
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Combined button and popup list for selecting options.
#define Q_LOGGING_CATEGORY(name,...)
#define qCInfo(category,...)
#define qCWarning(category,...)
GLenum GLenum GLsizei count
#define QStringLiteral(str)
\variable QRhiReadbackResult::completed