diff --git a/qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.cpp b/qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.cpp index dc4fdb569..f2d94d10b 100644 --- a/qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.cpp +++ b/qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.cpp @@ -23,16 +23,23 @@ ******************************************************************************/ #include "PerformanceCounterSelection.h" +#include #include "Code/CaptureContext.h" #include "Code/Interface/QRDInterface.h" #include "ui_PerformanceCounterSelection.h" -#include #include #define JSON_ID "rdocPerformanceCounterSettings" #define JSON_VER 1 +// specialise this template so we can use QSet +template <> +inline uint qHash(const GPUCounter &t, uint seed) +{ + return qHash(uint32_t(t), seed); +} + namespace { enum class CounterFamily @@ -80,7 +87,9 @@ QString ToString(CounterFamily family) const int PerformanceCounterSelection::CounterDescriptionRole = Qt::UserRole + 1; const int PerformanceCounterSelection::CounterIdRole = Qt::UserRole + 2; -PerformanceCounterSelection::PerformanceCounterSelection(ICaptureContext &ctx, QWidget *parent) +PerformanceCounterSelection::PerformanceCounterSelection(ICaptureContext &ctx, + const QList &selectedCounters, + QWidget *parent) : QDialog(parent), ui(new Ui::PerformanceCounterSelection), m_Ctx(ctx) { ui->setupUi(this); @@ -123,17 +132,25 @@ PerformanceCounterSelection::PerformanceCounterSelection(ICaptureContext &ctx, Q ui->counterTree->setMouseTracking(true); - ctx.Replay().AsyncInvoke([this](IReplayController *controller) -> void { + ctx.Replay().AsyncInvoke([this, selectedCounters](IReplayController *controller) -> void { QVector counterDescriptions; for(const GPUCounter counter : controller->EnumerateCounters()) { counterDescriptions.append(controller->DescribeCounter(counter)); } - GUIInvoke::call([counterDescriptions, this]() -> void { SetCounters(counterDescriptions); }); + GUIInvoke::call([counterDescriptions, selectedCounters, this]() -> void { + SetCounters(counterDescriptions); + SetSelectedCounters(selectedCounters); + }); }); } +PerformanceCounterSelection::~PerformanceCounterSelection() +{ + delete ui; +} + void PerformanceCounterSelection::SetCounters(const QVector &descriptions) { ui->counterTree->clear(); @@ -185,16 +202,33 @@ void PerformanceCounterSelection::SetCounters(const QVector } } -PerformanceCounterSelection::~PerformanceCounterSelection() -{ - delete ui; -} - QList PerformanceCounterSelection::GetSelectedCounters() const { return m_SelectedCounters.keys(); } +void PerformanceCounterSelection::SetSelectedCounters(const QList &counters) +{ + // We we walk over the complete tree, and toggle everything so it + // matches the settings + QTreeWidgetItemIterator it(ui->counterTree); + while(*it) + { + const QVariant id = (*it)->data(0, Qt::UserRole + 2); + if(id.isValid()) + { + const GPUCounter counter = (GPUCounter)id.toUInt(); + + (*it)->setCheckState(0, counters.contains(counter) ? Qt::Checked : Qt::Unchecked); + } + + // The loop above will uncheck all unknown counters, and not crash if some counter is no + // longer present, or unknown + + ++it; + } +} + void PerformanceCounterSelection::Save() { QString filename = RDDialog::getSaveFileName(this, tr("Save File"), QDir::homePath(), @@ -246,7 +280,7 @@ void PerformanceCounterSelection::Load() { LoadFromJSON(doc, f, JSON_ID, JSON_VER); - std::set selectedCounters; + QSet selectedCounters; QVariantList counters = doc[lit("counters")].toList(); @@ -262,33 +296,13 @@ void PerformanceCounterSelection::Load() uuid.bytes[i] = bytes[i].toUInt(); } - selectedCounters.insert(uuid); + if(!m_UuidToCounter.contains(uuid)) + continue; + + selectedCounters.insert(m_UuidToCounter[uuid]); } - // We we walk over the complete tree, and toggle everything so it - // matches the settings - QTreeWidgetItemIterator it(ui->counterTree); - while(*it) - { - const QVariant id = (*it)->data(0, Qt::UserRole + 2); - if(id.isValid()) - { - const GPUCounter counter = (GPUCounter)id.toUInt(); - - if(!m_CounterToUuid.contains(counter)) - continue; - - (*it)->setCheckState( - 0, (selectedCounters.find(m_CounterToUuid[counter]) != selectedCounters.end()) - ? Qt::Checked - : Qt::Unchecked); - } - - // The loop above will uncheck all unknown counters, and not crash if some counter is no - // longer present, or unknown - - ++it; - } + SetSelectedCounters(selectedCounters.toList()); } else { diff --git a/qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.h b/qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.h index 347eca2d6..85733d5bf 100644 --- a/qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.h +++ b/qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.h @@ -39,9 +39,12 @@ class PerformanceCounterSelection : public QDialog Q_OBJECT public: - explicit PerformanceCounterSelection(ICaptureContext &ctx, QWidget *parent = 0); + explicit PerformanceCounterSelection(ICaptureContext &ctx, + const QList &selectedCounters, + QWidget *parent = 0); ~PerformanceCounterSelection(); + void SetSelectedCounters(const QList &counters); QList GetSelectedCounters() const; public slots: diff --git a/qrenderdoc/Windows/PerformanceCounterViewer.cpp b/qrenderdoc/Windows/PerformanceCounterViewer.cpp index dd4b288c5..0f0a6d407 100644 --- a/qrenderdoc/Windows/PerformanceCounterViewer.cpp +++ b/qrenderdoc/Windows/PerformanceCounterViewer.cpp @@ -109,28 +109,28 @@ void PerformanceCounterViewer::CaptureCounters() if(!m_Ctx.LogLoaded()) return; - PerformanceCounterSelection pcs(m_Ctx, this); + PerformanceCounterSelection pcs(m_Ctx, m_SelectedCounters, this); if(RDDialog::show(&pcs) != QDialog::Accepted) return; - const QList selectedCounters = pcs.GetSelectedCounters(); + m_SelectedCounters = pcs.GetSelectedCounters(); bool done = false; - m_Ctx.Replay().AsyncInvoke([this, selectedCounters, &done](IReplayController *controller) -> void { + m_Ctx.Replay().AsyncInvoke([this, &done](IReplayController *controller) -> void { rdctype::array counters; - counters.create(selectedCounters.size()); + counters.create(m_SelectedCounters.size()); QMap counterDescriptions; - for(int i = 0; i < selectedCounters.size(); ++i) + for(int i = 0; i < m_SelectedCounters.size(); ++i) { - counters[i] = (GPUCounter)selectedCounters[i]; + counters[i] = (GPUCounter)m_SelectedCounters[i]; counterDescriptions.insert(counters[i], controller->DescribeCounter(counters[i])); } QMap counterIndex; - for(int i = 0; i < selectedCounters.size(); ++i) + for(int i = 0; i < m_SelectedCounters.size(); ++i) { - counterIndex.insert((GPUCounter)selectedCounters[i], i); + counterIndex.insert((GPUCounter)m_SelectedCounters[i], i); } const rdctype::array results = controller->FetchCounters(counters); diff --git a/qrenderdoc/Windows/PerformanceCounterViewer.h b/qrenderdoc/Windows/PerformanceCounterViewer.h index dbd700575..945733b11 100644 --- a/qrenderdoc/Windows/PerformanceCounterViewer.h +++ b/qrenderdoc/Windows/PerformanceCounterViewer.h @@ -54,6 +54,8 @@ private slots: private: QString FormatCounterResult(const CounterResult &result, const CounterDescription &description); + QList m_SelectedCounters; + Ui::PerformanceCounterViewer *ui; ICaptureContext &m_Ctx; void CaptureCounters();