diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 8c32bdb56..1e13fe97a 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -5550,7 +5550,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); ID3D11DeviceContext* deviceCtx = m_deviceCtx; - int64_t elapsed = -bx::getHPCounter(); + int64_t timeBegin = bx::getHPCounter(); int64_t captureElapsed = 0; uint32_t frameQueryIdx = UINT32_MAX; @@ -6442,16 +6442,8 @@ BX_PRAGMA_DIAGNOSTIC_POP(); PIX_ENDEVENT(); - int64_t now = bx::getHPCounter(); - elapsed += now; - - static int64_t last = now; - - Stats& perfStats = _render->m_perfStats; - perfStats.cpuTimeBegin = last; - - int64_t frameTime = now - last; - last = now; + int64_t timeEnd = bx::getHPCounter(); + int64_t frameTime = timeEnd - timeBegin; static int64_t min = frameTime; static int64_t max = frameTime; @@ -6476,7 +6468,9 @@ BX_PRAGMA_DIAGNOSTIC_POP(); const int64_t timerFreq = bx::getHPFrequency(); - perfStats.cpuTimeEnd = now; + Stats& perfStats = _render->m_perfStats; + perfStats.cpuTimeBegin = timeBegin; + perfStats.cpuTimeEnd = timeEnd; perfStats.cpuTimerFreq = timerFreq; const TimerQueryD3D11::Result& result = m_gpuTimer.m_result[BGFX_CONFIG_MAX_VIEWS]; perfStats.gpuTimeBegin = result.m_begin; @@ -6493,12 +6487,13 @@ BX_PRAGMA_DIAGNOSTIC_POP(); m_needPresent = true; TextVideoMem& tvm = m_textVideoMem; - static int64_t next = now; + static int64_t next = timeEnd; - if (now >= next) + if (timeEnd >= next) { - next = now + timerFreq; - double freq = double(bx::getHPFrequency() ); + next = timeEnd + timerFreq; + + double freq = double(timerFreq); double toMs = 1000.0/freq; tvm.clear(); @@ -6555,7 +6550,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); , !!(m_resolution.m_flags&BGFX_RESET_MAXANISOTROPY) ? '\xfe' : ' ' ); - double elapsedCpuMs = double(elapsed)*toMs; + double elapsedCpuMs = double(timeBegin)*toMs; tvm.printf(10, pos++, 0x8e, " Submitted: %5d (draw %5d, compute %4d) / CPU %7.4f [ms] %c GPU %7.4f [ms] (latency %d) " , _render->m_num , statsKeyType[0] diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 2ee380cfe..b9cd464a1 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -5004,7 +5004,7 @@ data.NumQualityLevels = 0; return; } - int64_t elapsed = -bx::getHPCounter(); + int64_t timeBegin = bx::getHPCounter(); int64_t captureElapsed = 0; uint32_t frameQueryIdx = m_gpuTimer.begin(BGFX_CONFIG_MAX_VIEWS); @@ -5685,16 +5685,8 @@ data.NumQualityLevels = 0; } } - int64_t now = bx::getHPCounter(); - elapsed += now; - - static int64_t last = now; - - Stats& perfStats = _render->m_perfStats; - perfStats.cpuTimeBegin = last; - - int64_t frameTime = now - last; - last = now; + int64_t timeEnd = bx::getHPCounter(); + int64_t frameTime = timeEnd - timeBegin; static int64_t min = frameTime; static int64_t max = frameTime; @@ -5726,7 +5718,9 @@ data.NumQualityLevels = 0; const int64_t timerFreq = bx::getHPFrequency(); - perfStats.cpuTimeEnd = now; + Stats& perfStats = _render->m_perfStats; + perfStats.cpuTimeBegin = timeBegin; + perfStats.cpuTimeEnd = timeEnd; perfStats.cpuTimerFreq = timerFreq; const TimerQueryD3D12::Result& result = m_gpuTimer.m_result[BGFX_CONFIG_MAX_VIEWS]; perfStats.gpuTimeBegin = result.m_begin; @@ -5743,12 +5737,13 @@ data.NumQualityLevels = 0; // m_needPresent = true; TextVideoMem& tvm = m_textVideoMem; - static int64_t next = now; + static int64_t next = timeEnd; - if (now >= next) + if (timeEnd >= next) { - next = now + bx::getHPFrequency(); - double freq = double(bx::getHPFrequency() ); + next = timeEnd + timerFreq; + + double freq = double(timerFreq); double toMs = 1000.0 / freq; tvm.clear(); @@ -5840,7 +5835,7 @@ data.NumQualityLevels = 0; , !!(m_resolution.m_flags&BGFX_RESET_MAXANISOTROPY) ? '\xfe' : ' ' ); - double elapsedCpuMs = double(elapsed)*toMs; + double elapsedCpuMs = double(frameTime)*toMs; tvm.printf(10, pos++, 0x8e, " Submitted: %5d (draw %5d, compute %4d) / CPU %7.4f [ms] " , _render->m_num , statsKeyType[0] diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 6472ec378..d81b8e8f7 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -3699,7 +3699,7 @@ namespace bgfx { namespace d3d9 updateResolution(_render->m_resolution); - int64_t elapsed = -bx::getHPCounter(); + int64_t timeBegin = bx::getHPCounter(); int64_t captureElapsed = 0; uint32_t frameQueryIdx = UINT32_MAX; @@ -4345,16 +4345,8 @@ namespace bgfx { namespace d3d9 PIX_ENDEVENT(); - int64_t now = bx::getHPCounter(); - elapsed += now; - - static int64_t last = now; - - Stats& perfStats = _render->m_perfStats; - perfStats.cpuTimeBegin = last; - - int64_t frameTime = now - last; - last = now; + int64_t timeEnd = bx::getHPCounter(); + int64_t frameTime = timeEnd - timeBegin; static int64_t min = frameTime; static int64_t max = frameTime; @@ -4379,7 +4371,9 @@ namespace bgfx { namespace d3d9 const int64_t timerFreq = bx::getHPFrequency(); - perfStats.cpuTimeEnd = now; + Stats& perfStats = _render->m_perfStats; + perfStats.cpuTimeBegin = timeBegin; + perfStats.cpuTimeEnd = timeEnd; perfStats.cpuTimerFreq = timerFreq; const TimerQueryD3D9::Result& result = m_gpuTimer.m_result[BGFX_CONFIG_MAX_VIEWS]; perfStats.gpuTimeBegin = result.m_begin; @@ -4396,11 +4390,11 @@ namespace bgfx { namespace d3d9 m_needPresent = true; TextVideoMem& tvm = m_textVideoMem; - static int64_t next = now; + static int64_t next = timeEnd; - if (now >= next) + if (timeEnd >= next) { - next = now + timerFreq; + next = timeEnd + timerFreq; double freq = double(timerFreq); double toMs = 1000.0/freq; @@ -4434,7 +4428,7 @@ namespace bgfx { namespace d3d9 , !!(m_resolution.m_flags&BGFX_RESET_MAXANISOTROPY) ? '\xfe' : ' ' ); - double elapsedCpuMs = double(elapsed)*toMs; + double elapsedCpuMs = double(frameTime)*toMs; tvm.printf(10, pos++, 0x8e, " Submitted: %5d (draw %5d, compute %4d) / CPU %7.4f [ms] %c GPU %7.4f [ms] (latency %d)" , _render->m_num , statsKeyType[0] diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index b6639513e..50d91988d 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -6524,7 +6524,7 @@ namespace bgfx { namespace gl updateResolution(_render->m_resolution); - int64_t elapsed = -bx::getHPCounter(); + int64_t timeBegin = bx::getHPCounter(); int64_t captureElapsed = 0; uint32_t frameQueryIdx = UINT32_MAX; @@ -7594,16 +7594,8 @@ namespace bgfx { namespace gl } m_glctx.makeCurrent(NULL); - int64_t now = bx::getHPCounter(); - elapsed += now; - - static int64_t last = now; - - Stats& perfStats = _render->m_perfStats; - perfStats.cpuTimeBegin = last; - - int64_t frameTime = now - last; - last = now; + int64_t timeEnd = bx::getHPCounter(); + int64_t frameTime = timeEnd - timeBegin; static int64_t min = frameTime; static int64_t max = frameTime; @@ -7628,7 +7620,9 @@ namespace bgfx { namespace gl const int64_t timerFreq = bx::getHPFrequency(); - perfStats.cpuTimeEnd = now; + Stats& perfStats = _render->m_perfStats; + perfStats.cpuTimeBegin = timeBegin; + perfStats.cpuTimeEnd = timeEnd; perfStats.cpuTimerFreq = timerFreq; const TimerQueryGL::Result& result = m_gpuTimer.m_result[BGFX_CONFIG_MAX_VIEWS]; perfStats.gpuTimeBegin = result.m_begin; @@ -7643,11 +7637,11 @@ namespace bgfx { namespace gl m_needPresent = true; TextVideoMem& tvm = m_textVideoMem; - static int64_t next = now; + static int64_t next = timeEnd; - if (now >= next) + if (timeEnd >= next) { - next = now + timerFreq; + next = timeEnd + timerFreq; double freq = double(timerFreq); double toMs = 1000.0/freq; @@ -7685,7 +7679,7 @@ namespace bgfx { namespace gl , !!(m_resolution.m_flags&BGFX_RESET_MAXANISOTROPY) ? '\xfe' : ' ' ); - double elapsedCpuMs = double(elapsed)*toMs; + double elapsedCpuMs = double(timeBegin)*toMs; tvm.printf(10, pos++, 0x8e, " Submitted: %5d (draw %5d, compute %4d) / CPU %7.4f [ms] %c GPU %7.4f [ms] (latency %d) " , _render->m_num , statsKeyType[0] diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index c4154eed0..703f09462 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -386,7 +386,7 @@ namespace bgfx { namespace mtl if (NULL != NSClassFromString(@"CAMetalLayer") ) { - if (NULL == m_metalLayer) + if (NULL == m_metalLayer) #if BX_PLATFORM_IOS { CAMetalLayer* metalLayer = (CAMetalLayer*)g_platformData.nwh; @@ -3134,7 +3134,7 @@ namespace bgfx { namespace mtl m_commandBuffer = m_cmd.alloc(); } - int64_t elapsed = -bx::getHPCounter(); + int64_t timeBegin = bx::getHPCounter(); int64_t captureElapsed = 0; m_gpuTimer.addHandlers(m_commandBuffer); @@ -3893,16 +3893,8 @@ namespace bgfx { namespace mtl } } - int64_t now = bx::getHPCounter(); - elapsed += now; - - static int64_t last = now; - - Stats& perfStats = _render->m_perfStats; - perfStats.cpuTimeBegin = last; - - int64_t frameTime = now - last; - last = now; + int64_t timeEnd = bx::getHPCounter(); + int64_t frameTime = timeEnd - timeBegin; static int64_t min = frameTime; static int64_t max = frameTime; @@ -3925,7 +3917,9 @@ namespace bgfx { namespace mtl const int64_t timerFreq = bx::getHPFrequency(); - perfStats.cpuTimeEnd = now; + Stats& perfStats = _render->m_perfStats; + perfStats.cpuTimeBegin = timeBegin; + perfStats.cpuTimeEnd = timeEnd; perfStats.cpuTimerFreq = timerFreq; perfStats.gpuTimeBegin = m_gpuTimer.m_begin; perfStats.gpuTimeEnd = m_gpuTimer.m_end; @@ -3941,13 +3935,13 @@ namespace bgfx { namespace mtl TextVideoMem& tvm = m_textVideoMem; - static int64_t next = now; + static int64_t next = timeEnd; - if (now >= next) + if (timeEnd >= next) { - next = now + bx::getHPFrequency(); + next = timeEnd + timerFreq; - double freq = double(bx::getHPFrequency() ); + double freq = double(timerFreq); double toMs = 1000.0/freq; tvm.clear(); diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index a9d0fefc7..a42b710ec 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -3639,7 +3639,7 @@ VK_DESTROY updateResolution(_render->m_resolution); - int64_t elapsed = -bx::getHPCounter(); + int64_t timeBegin = bx::getHPCounter(); int64_t captureElapsed = 0; // m_gpuTimer.begin(m_commandList); @@ -4355,16 +4355,8 @@ BX_UNUSED(currentSamplerStateIdx); // m_batch.end(m_commandList); } - int64_t now = bx::getHPCounter(); - elapsed += now; - - static int64_t last = now; - - Stats& perfStats = _render->m_perfStats; - perfStats.cpuTimeBegin = last; - - int64_t frameTime = now - last; - last = now; + int64_t timeEnd = bx::getHPCounter(); + int64_t frameTime = timeEnd - timeBegin; static int64_t min = frameTime; static int64_t max = frameTime; @@ -4394,7 +4386,9 @@ BX_UNUSED(presentMin, presentMax); const int64_t timerFreq = bx::getHPFrequency(); - perfStats.cpuTimeEnd = now; + Stats& perfStats = _render->m_perfStats; + perfStats.cpuTimeBegin = timeBegin; + perfStats.cpuTimeEnd = timeEnd; perfStats.cpuTimerFreq = timerFreq; // perfStats.gpuTimeBegin = m_gpuTimer.m_begin; // perfStats.gpuTimeEnd = m_gpuTimer.m_end; @@ -4410,12 +4404,13 @@ BX_UNUSED(presentMin, presentMax); // m_needPresent = true; TextVideoMem& tvm = m_textVideoMem; - static int64_t next = now; + static int64_t next = timeEnd; - if (now >= next) + if (timeEnd >= next) { - next = now + bx::getHPFrequency(); - double freq = double(bx::getHPFrequency() ); + next = timeEnd + timerFreq; + + double freq = double(timerFreq); double toMs = 1000.0 / freq; tvm.clear(); @@ -4496,7 +4491,7 @@ BX_UNUSED(presentMin, presentMax); , !!(m_resolution.m_flags&BGFX_RESET_MAXANISOTROPY) ? '\xfe' : ' ' ); - double elapsedCpuMs = double(elapsed)*toMs; + double elapsedCpuMs = double(timeBegin)*toMs; tvm.printf(10, pos++, 0x8e, " Submitted: %5d (draw %5d, compute %4d) / CPU %7.4f [ms] " , _render->m_num , statsKeyType[0]