Permalink
Browse files

GLProfiler enhancements

  • Loading branch information...
1 parent 140f983 commit f7f55c18d0c975977e70faf38743f820f282785d @yvt committed Jan 11, 2017
Showing with 66 additions and 11 deletions.
  1. +62 −11 Sources/Draw/GLProfiler.cpp
  2. +2 −0 Sources/Draw/GLSettings.cpp
  3. +2 −0 Sources/Draw/GLSettings.h
@@ -69,18 +69,18 @@ namespace spades {
// can't use vector here; a reference to a vector's element can be invalidated
std::list<Phase> subphases;
- /** Looks up a subphase by its name. */
- std::unordered_map<std::string, std::reference_wrapper<Phase>> subphaseMap;
+ std::list<Phase>::iterator nextSubphaseIterator;
double startWallClockTime;
+ double endWallClockTime;
stmp::optional<std::pair<std::size_t, std::size_t>> queryObjectIndices;
Measurement measurementLatest;
bool measured = false;
stmp::optional<Measurement> measurementSaved;
- Phase(const std::string &name) : name{name} {}
+ Phase(const std::string &name) : name{name}, nextSubphaseIterator{subphases.begin()} {}
};
GLProfiler::GLProfiler(GLRenderer &renderer)
@@ -151,6 +151,7 @@ namespace spades {
void Traverse(Phase &phase) {
phase.measured = false;
phase.queryObjectIndices.reset();
+ phase.nextSubphaseIterator = phase.subphases.begin();
for (Phase &subphase : phase.subphases) {
Traverse(subphase);
}
@@ -191,6 +192,41 @@ namespace spades {
SPADES_MARK_FUNCTION();
Phase &root = *m_root;
+ // Fill gap
+ if (m_settings.r_debugTimingFillGap) {
+ struct Traverser {
+ GLProfiler &self;
+ Traverser(GLProfiler &self) : self{self} {}
+ void Traverse(Phase &phase, stmp::optional<std::pair<Phase&, bool>> base) {
+ if (!phase.queryObjectIndices) {
+ return;
+ }
+ if (base) {
+ auto baseIndices = *(*base).first.queryObjectIndices;
+ (*phase.queryObjectIndices).second = (*base).second ? baseIndices.second : baseIndices.first;
+ }
+ auto it = phase.subphases.begin();
+ while (it != phase.subphases.end() && !it->queryObjectIndices) {
+ ++it;
+ }
+ while (it != phase.subphases.end()) {
+ auto it2 = it; ++it2;
+ while (it2 != phase.subphases.end() && !it2->queryObjectIndices) {
+ ++it2;
+ }
+ if (it2 == phase.subphases.end()) {
+ Traverse(*it, std::pair<Phase&, bool>{phase, true});
+ } else {
+ Traverse(*it, std::pair<Phase&, bool>{*it2, false});
+ }
+ it = it2;
+ }
+ }
+ };
+ Traverser{*this}.Traverse(root, {});
+ // TODO: fill gap for wall clock times
+ }
+
// Collect GPU time information
if (m_settings.r_debugTimingGPUTime) {
if (!m_waitingTimerQueryResult) {
@@ -281,18 +317,23 @@ namespace spades {
Phase &current = GetCurrentPhase();
- // Look up existing Phase object (only when r_debugTimingAverage != 0)
- auto it = current.subphaseMap.find(name);
+ auto it = current.nextSubphaseIterator;
+
+ for (; it != current.subphases.end(); ++it) {
+ if (it->name == name) {
+ break;
+ }
+ }
- if (it == current.subphaseMap.end()) {
+ if (it == current.subphases.end()) {
// Create a new subphase
- auto subphasesIt = current.subphases.emplace(current.subphases.end(), name);
- auto insertResult = current.subphaseMap.emplace(name, std::ref(*subphasesIt));
- SPAssert(insertResult.second);
- it = insertResult.first;
+ it = current.subphases.emplace(current.nextSubphaseIterator, name);
}
- Phase &next = it->second;
+ current.nextSubphaseIterator = it;
+ ++current.nextSubphaseIterator;
+
+ Phase &next = *it;
m_stack.emplace_back(next);
if (next.measured) {
@@ -308,6 +349,10 @@ namespace spades {
void GLProfiler::BeginPhaseInner(Phase &phase) {
SPADES_MARK_FUNCTION_DEBUG();
+ if (m_settings.r_debugTimingFlush) {
+ m_device.Flush();
+ }
+
phase.startWallClockTime = GetWallClockTime();
if (m_settings.r_debugTimingGPUTime) {
@@ -334,8 +379,14 @@ namespace spades {
Phase &current = GetCurrentPhase();
+ if (m_settings.r_debugTimingFlush) {
+ m_device.Flush();
+ }
+
double wallClockTime = GetWallClockTime();
+ current.endWallClockTime = wallClockTime;
+
current.measurementLatest.totalWallClockTime +=
wallClockTime - current.startWallClockTime;
current.measurementLatest.totalNumFrames += 1;
@@ -30,6 +30,8 @@ DEFINE_SPADES_SETTING(r_debugTimingOutputLog, "0");
DEFINE_SPADES_SETTING(r_debugTimingAverage, "1");
DEFINE_SPADES_SETTING(r_debugTimingGPUTime, "1");
DEFINE_SPADES_SETTING(r_debugTimingOutputBarScale, "2");
+DEFINE_SPADES_SETTING(r_debugTimingFlush, "0");
+DEFINE_SPADES_SETTING(r_debugTimingFillGap, "0");
DEFINE_SPADES_SETTING(r_depthOfField, "0");
DEFINE_SPADES_SETTING(r_depthOfFieldMaxCoc, "0.01");
DEFINE_SPADES_SETTING(r_depthPrepass, "1");
@@ -37,6 +37,8 @@ namespace spades {
TypedItemHandle<bool> r_debugTimingAverage { *this, "r_debugTimingAverage" };
TypedItemHandle<bool> r_debugTimingGPUTime { *this, "r_debugTimingGPUTime" };
TypedItemHandle<float> r_debugTimingOutputBarScale { *this, "r_debugTimingOutputBarScale" };
+ TypedItemHandle<bool> r_debugTimingFlush { *this, "r_debugTimingFlush" };
+ TypedItemHandle<bool> r_debugTimingFillGap { *this, "r_debugTimingFillGap" };
TypedItemHandle<int> r_depthOfField { *this, "r_depthOfField" };
TypedItemHandle<float> r_depthOfFieldMaxCoc { *this, "r_depthOfFieldMaxCoc" };
TypedItemHandle<bool> r_depthPrepass { *this, "r_depthPrepass" };

0 comments on commit f7f55c1

Please sign in to comment.