mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-04 17:10:47 +00:00
Pass selected counters back into selection dialog
* This means that each time you open the dialog you don't start with an empty set, instead you start with the set of counters you had previously selected.
This commit is contained in:
@@ -23,16 +23,23 @@
|
||||
******************************************************************************/
|
||||
|
||||
#include "PerformanceCounterSelection.h"
|
||||
#include <QSet>
|
||||
#include "Code/CaptureContext.h"
|
||||
#include "Code/Interface/QRDInterface.h"
|
||||
#include "ui_PerformanceCounterSelection.h"
|
||||
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
|
||||
#define JSON_ID "rdocPerformanceCounterSettings"
|
||||
#define JSON_VER 1
|
||||
|
||||
// specialise this template so we can use QSet<GPUCounter>
|
||||
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<GPUCounter> &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<CounterDescription> 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<CounterDescription> &descriptions)
|
||||
{
|
||||
ui->counterTree->clear();
|
||||
@@ -185,16 +202,33 @@ void PerformanceCounterSelection::SetCounters(const QVector<CounterDescription>
|
||||
}
|
||||
}
|
||||
|
||||
PerformanceCounterSelection::~PerformanceCounterSelection()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QList<GPUCounter> PerformanceCounterSelection::GetSelectedCounters() const
|
||||
{
|
||||
return m_SelectedCounters.keys();
|
||||
}
|
||||
|
||||
void PerformanceCounterSelection::SetSelectedCounters(const QList<GPUCounter> &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<Uuid> selectedCounters;
|
||||
QSet<GPUCounter> 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
|
||||
{
|
||||
|
||||
@@ -39,9 +39,12 @@ class PerformanceCounterSelection : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PerformanceCounterSelection(ICaptureContext &ctx, QWidget *parent = 0);
|
||||
explicit PerformanceCounterSelection(ICaptureContext &ctx,
|
||||
const QList<GPUCounter> &selectedCounters,
|
||||
QWidget *parent = 0);
|
||||
~PerformanceCounterSelection();
|
||||
|
||||
void SetSelectedCounters(const QList<GPUCounter> &counters);
|
||||
QList<GPUCounter> GetSelectedCounters() const;
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -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<GPUCounter> 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<GPUCounter> counters;
|
||||
counters.create(selectedCounters.size());
|
||||
counters.create(m_SelectedCounters.size());
|
||||
|
||||
QMap<GPUCounter, CounterDescription> 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<GPUCounter, int> 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<CounterResult> results = controller->FetchCounters(counters);
|
||||
|
||||
@@ -54,6 +54,8 @@ private slots:
|
||||
private:
|
||||
QString FormatCounterResult(const CounterResult &result, const CounterDescription &description);
|
||||
|
||||
QList<GPUCounter> m_SelectedCounters;
|
||||
|
||||
Ui::PerformanceCounterViewer *ui;
|
||||
ICaptureContext &m_Ctx;
|
||||
void CaptureCounters();
|
||||
|
||||
Reference in New Issue
Block a user