diff --git a/qrenderdoc/Code/QRDUtils.cpp b/qrenderdoc/Code/QRDUtils.cpp index 3681401f4..f7e584898 100644 --- a/qrenderdoc/Code/QRDUtils.cpp +++ b/qrenderdoc/Code/QRDUtils.cpp @@ -1953,6 +1953,7 @@ public: setLabel(&m_Label); } + void enableCancel() { setCancelButtonText(tr("Cancel")); } void setPercentage(float percent) { setValue(int(maxProgress * percent)); } void setInfinite(bool infinite) { @@ -2299,13 +2300,16 @@ QStringList ParseArgsList(const QString &args) } void ShowProgressDialog(QWidget *window, const QString &labelText, ProgressFinishedMethod finished, - ProgressUpdateMethod update) + ProgressUpdateMethod update, ProgressCancelMethod cancel) { if(finished()) return; RDProgressDialog dialog(labelText, window); + if(cancel) + dialog.enableCancel(); + // if we don't have an update function, set the progress display to be 'infinite spinner' dialog.setInfinite(!update); @@ -2338,6 +2342,9 @@ void ShowProgressDialog(QWidget *window, const QString &labelText, ProgressFinis // to clean itself up tickerSemaphore.tryAcquire(); progressTickerThread.wait(); + + if(cancel && dialog.wasCanceled()) + cancel(); } void UpdateTransferProgress(qint64 xfer, qint64 total, QElapsedTimer *timer, diff --git a/qrenderdoc/Code/QRDUtils.h b/qrenderdoc/Code/QRDUtils.h index 42b54ee76..f512f9021 100644 --- a/qrenderdoc/Code/QRDUtils.h +++ b/qrenderdoc/Code/QRDUtils.h @@ -666,6 +666,7 @@ class QElapsedTimer; typedef std::function ProgressUpdateMethod; typedef std::function ProgressFinishedMethod; +typedef std::function ProgressCancelMethod; QStringList ParseArgsList(const QString &args); bool IsRunningAsAdmin(); @@ -676,7 +677,8 @@ bool RunProcessAsAdmin(const QString &fullExecutablePath, const QStringList &par void RevealFilenameInExternalFileBrowser(const QString &filePath); void ShowProgressDialog(QWidget *window, const QString &labelText, ProgressFinishedMethod finished, - ProgressUpdateMethod update = ProgressUpdateMethod()); + ProgressUpdateMethod update = ProgressUpdateMethod(), + ProgressCancelMethod cancel = ProgressCancelMethod()); void UpdateTransferProgress(qint64 xfer, qint64 total, QElapsedTimer *timer, QProgressBar *progressBar, QLabel *progressLabel, QString progressText); diff --git a/qrenderdoc/Windows/ShaderViewer.cpp b/qrenderdoc/Windows/ShaderViewer.cpp index 9c29af146..9bb3ee32b 100644 --- a/qrenderdoc/Windows/ShaderViewer.cpp +++ b/qrenderdoc/Windows/ShaderViewer.cpp @@ -663,19 +663,43 @@ void ShaderViewer::debugShader(const ShaderBindpointMapping *bind, const ShaderR cacheResources(); - m_Ctx.Replay().AsyncInvoke([this](IReplayController *r) { + m_BackgroundRunning.release(); + + QPointer me(this); + + m_Ctx.Replay().AsyncInvoke([this, me](IReplayController *r) { + if(!me) + return; + rdcarray states = r->ContinueDebug(m_Trace->debugger); bool finished = false; do { + if(!me) + return; + rdcarray nextStates = r->ContinueDebug(m_Trace->debugger); + + QThread::msleep(5000); + + if(!me) + return; + states.append(nextStates); finished = nextStates.empty(); - } while(!finished); + } while(!finished && m_BackgroundRunning.available() == 1); + + if(!me || m_BackgroundRunning.available() != 1) + return; + + m_BackgroundRunning.tryAcquire(1); r->SetFrameEvent(m_Ctx.CurEvent(), true); + if(!me) + return; + GUIInvoke::call(this, [this, states]() { m_States = states; @@ -708,6 +732,18 @@ void ShaderViewer::debugShader(const ShaderBindpointMapping *bind, const ShaderR }); }); + GUIInvoke::defer(this, [this, debugContext]() { + // wait a short while before displaying the progress dialog (which won't show if we're already + // done by the time we reach it) + for(int i = 0; m_BackgroundRunning.available() == 1 && i < 100; i++) + QThread::msleep(5); + + ShowProgressDialog(this, tr("Debugging %1").arg(debugContext), + [this]() { return m_BackgroundRunning.available() == 0; }, NULL, + [this]() { m_BackgroundRunning.acquire(); }); + + }); + m_CurrentStateIdx = 0; QObject::connect(ui->watch, &RDTableWidget::keyPress, this, &ShaderViewer::watch_keyPress); diff --git a/qrenderdoc/Windows/ShaderViewer.h b/qrenderdoc/Windows/ShaderViewer.h index f0e2a1930..c3710f117 100644 --- a/qrenderdoc/Windows/ShaderViewer.h +++ b/qrenderdoc/Windows/ShaderViewer.h @@ -25,6 +25,7 @@ #pragma once #include +#include #include "Code/Interface/QRDInterface.h" namespace Ui @@ -254,6 +255,8 @@ private: size_t m_CurrentStateIdx = 0; rdcarray m_Variables; + QSemaphore m_BackgroundRunning; + rdcarray m_AccessedResources; AccessedResourceView m_AccessedResourceView = AccessedResourceView::SortByResource;