From 7eded723a986460745ac4abc8b95d59c61de1c4a Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 9 Jul 2015 14:33:55 +0200 Subject: [PATCH] Implement event browser time drawcalls button --- qrenderdoc/Windows/EventBrowser.cpp | 82 +++++++++++++++++++++++++---- qrenderdoc/Windows/EventBrowser.h | 2 + qrenderdoc/Windows/EventBrowser.ui | 12 +++-- 3 files changed, 81 insertions(+), 15 deletions(-) diff --git a/qrenderdoc/Windows/EventBrowser.cpp b/qrenderdoc/Windows/EventBrowser.cpp index 294ff078d..a147d8981 100644 --- a/qrenderdoc/Windows/EventBrowser.cpp +++ b/qrenderdoc/Windows/EventBrowser.cpp @@ -3,6 +3,12 @@ #include "Code/Core.h" +enum { + COL_NAME = 0, + COL_EID = 1, + COL_DURATION = 2, +}; + uint AddDrawcalls(QTreeWidgetItem *parent, const rdctype::array &draws) { uint lastEID = 0; @@ -12,7 +18,7 @@ uint AddDrawcalls(QTreeWidgetItem *parent, const rdctype::array & QTreeWidgetItem *child = new QTreeWidgetItem(parent, QStringList{QString(draws[i].name.elems), QString("%1").arg(draws[i].eventID), "0.0"}); lastEID = AddDrawcalls(child, draws[i].children); if(lastEID == 0) lastEID = draws[i].eventID; - child->setData(0, Qt::UserRole, QVariant(lastEID)); + child->setData(COL_EID, Qt::UserRole, QVariant(lastEID)); } return lastEID; @@ -27,15 +33,15 @@ EventBrowser::EventBrowser(Core *core, QWidget *parent) : m_Core->AddLogViewer(this); - ui->events->header()->resizeSection(1, 80); + ui->events->header()->resizeSection(COL_EID, 80); - ui->events->header()->setSectionResizeMode(0, QHeaderView::Stretch); - ui->events->header()->setSectionResizeMode(1, QHeaderView::Interactive); - ui->events->header()->setSectionResizeMode(2, QHeaderView::Interactive); + ui->events->header()->setSectionResizeMode(COL_NAME, QHeaderView::Stretch); + ui->events->header()->setSectionResizeMode(COL_EID, QHeaderView::Interactive); + ui->events->header()->setSectionResizeMode(COL_DURATION, QHeaderView::Interactive); // we set up the name column first, EID second, so that the name column gets the // expand/collapse widgets. Then we need to put them back in order - ui->events->header()->moveSection(0, 1); + ui->events->header()->moveSection(COL_NAME, COL_EID); // Qt doesn't allow moving the column with the expand/collapse widgets, so this // becomes quickly infuriating to rearrange, just disable until that can be fixed. @@ -52,11 +58,11 @@ void EventBrowser::OnLogfileLoaded() { QTreeWidgetItem *frame = new QTreeWidgetItem((QTreeWidget *)NULL, QStringList{QString("Frame #%1").arg(m_Core->FrameInfo()[0].frameNumber), "", ""}); - QTreeWidgetItem *framestart = new QTreeWidgetItem(frame, QStringList{"Frame Start", "0", "0.0"}); - framestart->setData(0, Qt::UserRole, QVariant(0)); + QTreeWidgetItem *framestart = new QTreeWidgetItem(frame, QStringList{"Frame Start", "0", ""}); + framestart->setData(COL_EID, Qt::UserRole, QVariant(0)); uint lastEID = AddDrawcalls(frame, m_Core->CurDrawcalls(0)); - frame->setData(0, Qt::UserRole, QVariant(lastEID)); + frame->setData(COL_EID, Qt::UserRole, QVariant(lastEID)); ui->events->insertTopLevelItem(0, frame); @@ -81,11 +87,67 @@ void EventBrowser::on_gotoEID_clicked() { } +static void SetDrawcallTimes(QTreeWidgetItem *node, const rdctype::array &results) +{ + if(node == NULL) return; + + // parent nodes take the value of the sum of their children + double duration = 0.0; + + // look up leaf nodes in the dictionary + if(node->childCount() == 0) + { + uint eid = node->data(COL_EID, Qt::UserRole).toUInt(); + + duration = -1.0; + + for(int32_t i=0; i < results.count; i++) + { + if(results[i].eventID == eid) + duration = results[i].value.d; + } + + node->setText(COL_DURATION, duration < 0.0f ? "" : QString::number(duration*1000000.0)); + node->setData(COL_DURATION, Qt::UserRole, QVariant(duration)); + + return; + } + + for(int i = 0; i < node->childCount(); i++) + { + SetDrawcallTimes(node->child(i), results); + + double nd = node->child(i)->data(COL_DURATION, Qt::UserRole).toDouble(); + + if(nd > 0.0) + duration += nd; + } + + node->setText(COL_DURATION, duration < 0.0f ? "" : QString::number(duration*1000000.0)); + node->setData(COL_DURATION, Qt::UserRole, QVariant(duration)); +} + +void EventBrowser::on_timeDraws_clicked() +{ + m_Core->Renderer()->AsyncInvoke([this](IReplayRenderer *r) { + + uint32_t counters[] = { eCounter_EventGPUDuration }; + + rdctype::array results; + r->FetchCounters(m_Core->CurFrame(), 0, ~0U, counters, 1, &results); + + GUIInvoke::blockcall([this,results]() { + SetDrawcallTimes(ui->events->topLevelItem(0), results); + _CrtCheckMemory(); + }); + }); +} + void EventBrowser::on_events_itemSelectionChanged() { if(ui->events->selectedItems().empty()) return; - uint EID = ui->events->selectedItems()[0]->data(0, Qt::UserRole).toUInt(); + uint EID = ui->events->selectedItems()[0]->data(COL_EID, Qt::UserRole).toUInt(); m_Core->SetEventID(this, 0, EID); } diff --git a/qrenderdoc/Windows/EventBrowser.h b/qrenderdoc/Windows/EventBrowser.h index fc631e316..d83c70bfb 100644 --- a/qrenderdoc/Windows/EventBrowser.h +++ b/qrenderdoc/Windows/EventBrowser.h @@ -28,6 +28,8 @@ class EventBrowser : public QFrame, public ILogViewerForm void on_events_itemSelectionChanged(); + void on_timeDraws_clicked(); + private: Ui::EventBrowser *ui; Core *m_Core; diff --git a/qrenderdoc/Windows/EventBrowser.ui b/qrenderdoc/Windows/EventBrowser.ui index 80d80211b..13cad22da 100644 --- a/qrenderdoc/Windows/EventBrowser.ui +++ b/qrenderdoc/Windows/EventBrowser.ui @@ -72,7 +72,7 @@ - + :/Resources/find.png:/Resources/find.png @@ -95,7 +95,7 @@ - + :/Resources/flag_green.png:/Resources/flag_green.png @@ -109,7 +109,7 @@ - + :/Resources/time.png:/Resources/time.png @@ -194,13 +194,15 @@ - Duration + Duration (µs) - + + +