40void QGraphicsFrameCaptureMetal::setRhi(QRhi *rhi)
45 QRhi::Implementation backend = rhi->backend();
46 const QRhiNativeHandles *nh = rhi->nativeHandles();
49 case QRhi::Implementation::Metal: {
50 const QRhiMetalNativeHandles *mtlnh =
static_cast<
const QRhiMetalNativeHandles *>(nh);
51 if (mtlnh->cmdQueue) {
52 m_captureDescriptor.captureObject = mtlnh->cmdQueue;
53 }
else if (mtlnh->dev) {
54 m_captureDescriptor.captureObject = mtlnh->dev;
56 qCWarning(lcGraphicsFrameCapture) <<
"No valid Metal Device or Metal Command Queue found";
57 m_initialized =
false;
63 qCWarning(lcGraphicsFrameCapture) <<
"Invalid handles were provided. MTLCaptureManager works only with Metal API";
64 m_initialized =
false;
70 if (!m_captureManager) {
71 m_captureManager = MTLCaptureManager.sharedCaptureManager;
72 bool supportDocs = [m_captureManager supportsDestination:MTLCaptureDestinationGPUTraceDocument];
74 m_captureDescriptor.destination = MTLCaptureDestinationGPUTraceDocument;
80void QGraphicsFrameCaptureMetal::startCaptureFrame()
83 qCWarning(lcGraphicsFrameCapture) <<
"Capturing on Metal was not initialized. Starting capturing can not be done.";
88 qCWarning(lcGraphicsFrameCapture) <<
"A frame capture is already in progress,"
89 "will not initiate another one until QGraphicsFrameCapture::endCaptureFrame is called.";
93 updateCaptureFileName();
95 if (![m_captureManager startCaptureWithDescriptor:m_captureDescriptor error:&error]) {
96 QString errorMsg = QString::fromNSString(error.localizedDescription);
97 qCWarning(lcGraphicsFrameCapture,
"Failed to start capture : %s", qPrintable(errorMsg));
101void QGraphicsFrameCaptureMetal::endCaptureFrame()
103 if (!initialized()) {
104 qCWarning(lcGraphicsFrameCapture) <<
"Capturing on Metal was not initialized. End capturing can not be done.";
108 if (!isCapturing()) {
109 qCWarning(lcGraphicsFrameCapture) <<
"A call to QGraphicsFrameCapture::endCaptureFrame can not be done"
110 " without a call to QGraphicsFrameCapture::startCaptureFrame";
114 [m_captureManager stopCapture];
115 m_capturedFilesNames.append(QString::fromNSString(m_traceURL.path));
134void QGraphicsFrameCaptureMetal::openCapture()
136#if defined(Q_OS_MACOS)
137#if !QT_CONFIG(process)
138 qFatal(
"QGraphicsFrameCapture requires QProcess on macOS");
140 if (!initialized()) {
141 qCWarning(lcGraphicsFrameCapture) <<
"Capturing on Metal was not initialized. Can not open XCode with a valid capture.";
146 m_process =
new QProcess();
147 m_process->setProgram(QStringLiteral(
"xed"));
149 args.append(QUrl::fromNSURL(m_traceURL).toLocalFile());
150 m_process->setArguments(args);