From 00a2a9c9647177a6e789a6a1a9598c791cf7b860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 13 Jun 2016 16:45:29 -0700 Subject: [PATCH] Fixed GPU timer read-back. --- src/renderer_d3d11.cpp | 4 +++- src/renderer_d3d12.cpp | 4 +++- src/renderer_d3d9.cpp | 4 +++- src/renderer_gl.cpp | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index f8185ed09..b91d18fad 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -5958,12 +5958,14 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { m_gpuTimer.end(); - while (m_gpuTimer.get() ) + do { double toGpuMs = 1000.0 / double(m_gpuTimer.m_frequency); elapsedGpuMs = m_gpuTimer.m_elapsed * toGpuMs; maxGpuElapsed = elapsedGpuMs > maxGpuElapsed ? elapsedGpuMs : maxGpuElapsed; } + while (m_gpuTimer.get() ); + maxGpuLatency = bx::uint32_imax(maxGpuLatency, m_gpuTimer.m_control.available()-1); } diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 3a35feacd..22abdee70 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -5413,12 +5413,14 @@ data.NumQualityLevels = 0; m_gpuTimer.end(m_commandList); - while (m_gpuTimer.get() ) + do { double toGpuMs = 1000.0 / double(m_gpuTimer.m_frequency); elapsedGpuMs = m_gpuTimer.m_elapsed * toGpuMs; maxGpuElapsed = elapsedGpuMs > maxGpuElapsed ? elapsedGpuMs : maxGpuElapsed; } + while (m_gpuTimer.get() ); + maxGpuLatency = bx::uint32_imax(maxGpuLatency, m_gpuTimer.m_control.available()-1); const int64_t timerFreq = bx::getHPFrequency(); diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 84230d317..0744957a0 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -4188,12 +4188,14 @@ namespace bgfx { namespace d3d9 { m_gpuTimer.end(); - while (m_gpuTimer.get() ) + do { double toGpuMs = 1000.0 / double(m_gpuTimer.m_frequency); elapsedGpuMs = m_gpuTimer.m_elapsed * toGpuMs; maxGpuElapsed = elapsedGpuMs > maxGpuElapsed ? elapsedGpuMs : maxGpuElapsed; } + while (m_gpuTimer.get() ); + maxGpuLatency = bx::uint32_imax(maxGpuLatency, m_gpuTimer.m_control.available()-1); } diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 05e3dd66b..28d9a7fe3 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -6791,12 +6791,14 @@ namespace bgfx { namespace gl if (m_timerQuerySupport) { m_gpuTimer.end(); - while (m_gpuTimer.get() ) + do { elapsedGl = m_gpuTimer.m_elapsed; elapsedGpuMs = double(elapsedGl)/1e6; maxGpuElapsed = elapsedGpuMs > maxGpuElapsed ? elapsedGpuMs : maxGpuElapsed; } + while (m_gpuTimer.get() ); + maxGpuLatency = bx::uint32_imax(maxGpuLatency, m_gpuTimer.m_control.available()-1); }