Improve accuracy of gpuMicroSec timer on macOS OpenGL

This commit is contained in:
Stephen Saunders 2021-09-17 14:44:30 -04:00
parent cbf17d4f36
commit 0306b6189a
3 changed files with 45 additions and 5 deletions

View file

@ -287,7 +287,7 @@ float idConsoleLocal::DrawFPS( float y )
const uint64 rendererGPUInteractionsTime = commonLocal.GetRendererGpuInteractionsMicroseconds();
const uint64 rendererGPUShaderPassesTime = commonLocal.GetRendererGpuShaderPassMicroseconds();
const uint64 rendererGPUPostProcessingTime = commonLocal.GetRendererGpuPostProcessingMicroseconds();
const int maxTime = 16 * 1000;
const int maxTime = 1000 / com_engineHz_latched * 1000;
#if 1
@ -406,7 +406,7 @@ float idConsoleLocal::DrawFPS( float y )
}
else
{
ImGui::TextColored( colorYellow, "Average FPS %i", fps );
ImGui::TextColored( fps < com_engineHz_latched ? colorRed : colorYellow, "Average FPS %i", fps );
}
ImGui::Spacing();

View file

@ -2270,8 +2270,8 @@ void idRenderBackend::AmbientPass( const drawSurf_t* const* drawSurfs, int numDr
return;
}
renderLog.OpenMainBlock( MRB_AMBIENT_PASS );
renderLog.OpenBlock( "Render_AmbientPass", colorBlue );
renderLog.OpenMainBlock( fillGbuffer ? MRB_FILL_GEOMETRY_BUFFER : MRB_AMBIENT_PASS );
renderLog.OpenBlock( fillGbuffer ? "Fill_GeometryBuffer" : "Render_AmbientPass", colorBlue );
if( fillGbuffer )
{
@ -5850,6 +5850,11 @@ void idRenderBackend::DrawViewInternal( const viewDef_t* _viewDef, const int ste
DBG_RenderDebugTools( drawSurfs, numDrawSurfs );
#if !defined(USE_VULKAN)
// SRS - For OSX OpenGL record the final portion of GPU time while no other elapsed time query is active (after final shader pass and before post processing)
#if defined(__APPLE__)
renderLog.OpenMainBlock( MRB_GPU_TIME );
#endif
// RB: convert back from HDR to LDR range
if( useHDR && !( _viewDef->renderView.rdflags & RDF_IRRADIANCE ) )
@ -5913,6 +5918,11 @@ void idRenderBackend::DrawViewInternal( const viewDef_t* _viewDef, const int ste
{
Bloom( _viewDef );
}
#if defined(__APPLE__)
renderLog.CloseMainBlock();
#endif
#endif
renderLog.CloseBlock();

View file

@ -749,8 +749,38 @@ void idRenderSystemLocal::SwapCommandBuffers_FinishRendering(
// SRS - For OSX OpenGL calculate total rendering time vs direct measurement due to missing GL_TIMESTAMP support in Apple OpenGL 4.1
#if defined(__APPLE__)
backend.pc.gpuMicroSec = backend.pc.gpuDepthMicroSec + backend.pc.gpuScreenSpaceAmbientOcclusionMicroSec + backend.pc.gpuAmbientPassMicroSec + backend.pc.gpuInteractionsMicroSec + backend.pc.gpuShaderPassMicroSec + backend.pc.gpuPostProcessingMicroSec + commonLocal.GetRendererIdleMicroseconds();
// SRS - On OSX gpuMicroSec starts with only a portion of the GPU rendering time, must add additional components for more accurate estimate
backend.pc.gpuMicroSec += backend.pc.gpuDepthMicroSec + backend.pc.gpuScreenSpaceAmbientOcclusionMicroSec + backend.pc.gpuScreenSpaceReflectionsMicroSec + backend.pc.gpuAmbientPassMicroSec + backend.pc.gpuInteractionsMicroSec + backend.pc.gpuShaderPassMicroSec + backend.pc.gpuPostProcessingMicroSec;
// SRS - For OSX elapsed time queries, no need to perform unnecessary calls to glGetQueryObjectui64vEXT since gpuStartNanoseconds will always equal 0
if( glcontext.renderLogMainBlockTimeQueryIssued[ glcontext.frameParity ^ 1 ][ MRB_FILL_GEOMETRY_BUFFER * 2 + 1 ] > 0 )
{
glGetQueryObjectui64vEXT( glcontext.renderLogMainBlockTimeQueryIds[ glcontext.frameParity ^ 1 ][ MRB_FILL_GEOMETRY_BUFFER * 2 + 1], GL_QUERY_RESULT, &gpuEndNanoseconds );
backend.pc.gpuMicroSec += gpuEndNanoseconds / 1000;
}
if( glcontext.renderLogMainBlockTimeQueryIssued[ glcontext.frameParity ^ 1 ][ MRB_FOG_ALL_LIGHTS * 2 + 1 ] > 0 )
{
glGetQueryObjectui64vEXT( glcontext.renderLogMainBlockTimeQueryIds[ glcontext.frameParity ^ 1 ][ MRB_FOG_ALL_LIGHTS * 2 + 1], GL_QUERY_RESULT, &gpuEndNanoseconds );
backend.pc.gpuMicroSec += gpuEndNanoseconds / 1000;
}
if( glcontext.renderLogMainBlockTimeQueryIssued[ glcontext.frameParity ^ 1 ][ MRB_DRAW_SHADER_PASSES_POST * 2 + 1 ] > 0 )
{
glGetQueryObjectui64vEXT( glcontext.renderLogMainBlockTimeQueryIds[ glcontext.frameParity ^ 1 ][ MRB_DRAW_SHADER_PASSES_POST * 2 + 1], GL_QUERY_RESULT, &gpuEndNanoseconds );
backend.pc.gpuMicroSec += gpuEndNanoseconds / 1000;
}
if( glcontext.renderLogMainBlockTimeQueryIssued[ glcontext.frameParity ^ 1 ][ MRB_DRAW_DEBUG_TOOLS * 2 + 1 ] > 0 )
{
glGetQueryObjectui64vEXT( glcontext.renderLogMainBlockTimeQueryIds[ glcontext.frameParity ^ 1 ][ MRB_DRAW_DEBUG_TOOLS * 2 + 1], GL_QUERY_RESULT, &gpuEndNanoseconds );
backend.pc.gpuMicroSec += gpuEndNanoseconds / 1000;
}
if( gpuMicroSec != NULL )
{
*gpuMicroSec = backend.pc.gpuMicroSec;