mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-05 01:20:42 +00:00
86623528bf
* See https://bugreports.qt.io/browse/QTBUG-56382 for more details - creating DXGI swapchains adds a windows hook, and enough windows hooks forces out Qt's internal hook which it relies upon for proper event processing.
271 lines
7.6 KiB
C++
271 lines
7.6 KiB
C++
/******************************************************************************
|
|
* The MIT License (MIT)
|
|
*
|
|
* Copyright (c) 2016 Baldur Karlsson
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
******************************************************************************/
|
|
|
|
#include "CaptureContext.h"
|
|
#include <QApplication>
|
|
#include <QFileInfo>
|
|
#include <QMessageBox>
|
|
#include <QMetaObject>
|
|
#include <QTimer>
|
|
#include "Windows/MainWindow.h"
|
|
|
|
CaptureContext::CaptureContext(QString paramFilename, QString remoteHost, uint32_t remoteIdent,
|
|
bool temp)
|
|
{
|
|
m_LogLoaded = false;
|
|
m_LoadInProgress = false;
|
|
|
|
m_EventID = 0;
|
|
|
|
memset(&m_APIProps, 0, sizeof(m_APIProps));
|
|
|
|
qApp->setApplicationVersion(RENDERDOC_GetVersionString());
|
|
|
|
m_MainWindow = new MainWindow(this);
|
|
m_MainWindow->show();
|
|
|
|
if(!paramFilename.isEmpty())
|
|
{
|
|
QFileInfo fi(paramFilename);
|
|
|
|
if(fi.suffix() == "rdc")
|
|
{
|
|
LoadLogfile(paramFilename, temp);
|
|
}
|
|
}
|
|
}
|
|
|
|
CaptureContext::~CaptureContext()
|
|
{
|
|
m_Renderer.CloseThread();
|
|
delete m_MainWindow;
|
|
}
|
|
|
|
bool CaptureContext::isRunning()
|
|
{
|
|
return m_MainWindow && m_MainWindow->isVisible();
|
|
}
|
|
|
|
void CaptureContext::LoadLogfile(QString logFile, bool temporary)
|
|
{
|
|
LoadLogfile(-1, "", logFile, temporary);
|
|
}
|
|
|
|
void CaptureContext::LoadLogfile(int proxyRenderer, QString replayHost, QString logFile,
|
|
bool temporary)
|
|
{
|
|
m_LogFile = logFile;
|
|
|
|
m_LoadInProgress = true;
|
|
|
|
float loadProgress = 0.0f;
|
|
float postloadProgress = 0.0f;
|
|
|
|
// this function call will block until the log is either loaded, or there's some failure
|
|
m_Renderer.Init(proxyRenderer, replayHost, logFile, &loadProgress);
|
|
|
|
// if the renderer isn't running, we hit a failure case so display an error message
|
|
if(!m_Renderer.IsRunning())
|
|
{
|
|
QString errmsg = "Unknown error message";
|
|
ReplayCreateStatus status = m_Renderer.GetCreateStatus();
|
|
errmsg = status;
|
|
|
|
if(proxyRenderer >= 0)
|
|
QMessageBox::critical(NULL, "Error opening log",
|
|
QString("%1\nFailed to transfer and replay on remote host %2: %3.\n\n"
|
|
"Check diagnostic log in Help menu for more details.")
|
|
.arg(logFile, replayHost, errmsg));
|
|
else
|
|
QMessageBox::critical(NULL, "Error opening log",
|
|
QString("%1\nFailed to open logfile for replay: %1.\n\n"
|
|
"Check diagnostic log in Help menu for more details.")
|
|
.arg(logFile, errmsg));
|
|
|
|
m_LoadInProgress = false;
|
|
|
|
return;
|
|
}
|
|
|
|
m_EventID = 0;
|
|
|
|
// fetch initial data like drawcalls, textures and buffers
|
|
m_Renderer.BlockInvoke([this, &postloadProgress](IReplayRenderer *r) {
|
|
r->GetFrameInfo(&m_FrameInfo);
|
|
|
|
m_APIProps = r->GetAPIProperties();
|
|
|
|
postloadProgress = 0.2f;
|
|
|
|
r->GetDrawcalls(&m_Drawcalls);
|
|
|
|
postloadProgress = 0.4f;
|
|
|
|
r->GetSupportedWindowSystems(&m_WinSystems);
|
|
|
|
#if defined(RENDERDOC_PLATFORM_WIN32)
|
|
m_CurWinSystem = eWindowingSystem_Win32;
|
|
#elif defined(RENDERDOC_PLATFORM_LINUX)
|
|
m_CurWinSystem = eWindowingSystem_Xlib;
|
|
|
|
// prefer XCB, if supported
|
|
for(int32_t i = 0; i < m_WinSystems.count; i++)
|
|
{
|
|
if(m_WinSystems[i] == eWindowingSystem_XCB)
|
|
{
|
|
m_CurWinSystem = eWindowingSystem_XCB;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(m_CurWinSystem == eWindowingSystem_XCB)
|
|
m_XCBConnection = QX11Info::connection();
|
|
else
|
|
m_X11Display = QX11Info::display();
|
|
#endif
|
|
|
|
r->GetBuffers(&m_BufferList);
|
|
for(int i = 0; i < m_BufferList.count; i++)
|
|
m_Buffers[m_BufferList[i].ID] = &m_BufferList[i];
|
|
|
|
postloadProgress = 0.8f;
|
|
|
|
r->GetTextures(&m_TextureList);
|
|
for(int i = 0; i < m_TextureList.count; i++)
|
|
m_Textures[m_TextureList[i].ID] = &m_TextureList[i];
|
|
|
|
postloadProgress = 0.9f;
|
|
|
|
r->GetD3D11PipelineState(&CurD3D11PipelineState);
|
|
r->GetD3D12PipelineState(&CurD3D12PipelineState);
|
|
r->GetGLPipelineState(&CurGLPipelineState);
|
|
r->GetVulkanPipelineState(&CurVulkanPipelineState);
|
|
CurPipelineState.SetStates(m_APIProps, &CurD3D11PipelineState, &CurD3D12PipelineState,
|
|
&CurGLPipelineState, &CurVulkanPipelineState);
|
|
|
|
UnreadMessageCount = 0;
|
|
AddMessages(m_FrameInfo.debugMessages);
|
|
|
|
postloadProgress = 1.0f;
|
|
});
|
|
|
|
QThread::msleep(20);
|
|
|
|
m_LogLoaded = true;
|
|
|
|
QVector<ILogViewerForm *> logviewers(m_LogViewers);
|
|
|
|
GUIInvoke::blockcall([&logviewers]() {
|
|
// notify all the registers log viewers that a log has been loaded
|
|
for(ILogViewerForm *logviewer : logviewers)
|
|
{
|
|
if(logviewer)
|
|
logviewer->OnLogfileLoaded();
|
|
}
|
|
});
|
|
|
|
m_LoadInProgress = false;
|
|
}
|
|
|
|
void CaptureContext::SetEventID(ILogViewerForm *exclude, uint32_t eventID)
|
|
{
|
|
m_EventID = eventID;
|
|
|
|
m_Renderer.BlockInvoke([eventID, this](IReplayRenderer *r) {
|
|
r->SetFrameEvent(eventID, false);
|
|
r->GetD3D11PipelineState(&CurD3D11PipelineState);
|
|
r->GetD3D12PipelineState(&CurD3D12PipelineState);
|
|
r->GetGLPipelineState(&CurGLPipelineState);
|
|
r->GetVulkanPipelineState(&CurVulkanPipelineState);
|
|
CurPipelineState.SetStates(m_APIProps, &CurD3D11PipelineState, &CurD3D12PipelineState,
|
|
&CurGLPipelineState, &CurVulkanPipelineState);
|
|
});
|
|
|
|
for(ILogViewerForm *logviewer : m_LogViewers)
|
|
{
|
|
if(logviewer == exclude)
|
|
continue;
|
|
|
|
logviewer->OnEventSelected(eventID);
|
|
}
|
|
}
|
|
|
|
void *CaptureContext::FillWindowingData(WId widget)
|
|
{
|
|
#if defined(WIN32)
|
|
|
|
return (void *)widget;
|
|
|
|
#elif defined(RENDERDOC_PLATFORM_LINUX)
|
|
|
|
static XCBWindowData xcb = {
|
|
m_XCBConnection, (xcb_window_t)widget,
|
|
};
|
|
|
|
static XlibWindowData xlib = {m_X11Display, (Drawable)widget};
|
|
|
|
if(m_CurWinSystem == eWindowingSystem_XCB)
|
|
return &xcb;
|
|
else
|
|
return &xlib;
|
|
|
|
#else
|
|
|
|
#error "Unknown platform"
|
|
|
|
#endif
|
|
}
|
|
|
|
void GUIInvoke::call(const std::function<void()> &f)
|
|
{
|
|
if(qApp->thread() == QThread::currentThread())
|
|
{
|
|
f();
|
|
return;
|
|
}
|
|
|
|
// TODO: could maybe do away with string compare here via caching
|
|
// invoke->metaObject()->indexOfMethod("doInvoke"); ?
|
|
|
|
GUIInvoke *invoke = new GUIInvoke(f);
|
|
invoke->moveToThread(qApp->thread());
|
|
QMetaObject::invokeMethod(invoke, "doInvoke", Qt::QueuedConnection);
|
|
}
|
|
|
|
void GUIInvoke::blockcall(const std::function<void()> &f)
|
|
{
|
|
if(qApp->thread() == QThread::currentThread())
|
|
{
|
|
f();
|
|
return;
|
|
}
|
|
|
|
// TODO: could maybe do away with string compare here via caching
|
|
// invoke->metaObject()->indexOfMethod("doInvoke"); ?
|
|
|
|
GUIInvoke *invoke = new GUIInvoke(f);
|
|
invoke->moveToThread(qApp->thread());
|
|
QMetaObject::invokeMethod(invoke, "doInvoke", Qt::BlockingQueuedConnection);
|
|
}
|