From fe1238be7a14b98c1698b5f8398b0efe83ade43a Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Tue, 26 Nov 2019 18:30:21 -0300 Subject: gl_rasterizer: Add queued commands counter Keep track of the queued OpenGL commands that can signal a fence if waited on. As a side effect, we avoid calls to glFlush when no commands are queued. --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 13 +++++++++++++ src/video_core/renderer_opengl/gl_rasterizer.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 8d132732a..652db705b 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -541,6 +541,8 @@ void RasterizerOpenGL::Clear() { } else if (use_stencil) { glClearBufferiv(GL_STENCIL, 0, ®s.clear_stencil); } + + ++num_queued_commands; } void RasterizerOpenGL::Draw(bool is_indexed, bool is_instanced) { @@ -641,6 +643,8 @@ void RasterizerOpenGL::Draw(bool is_indexed, bool is_instanced) { glTextureBarrier(); } + ++num_queued_commands; + const GLuint base_instance = static_cast(gpu.regs.vb_base_instance); const GLsizei num_instances = static_cast(is_instanced ? gpu.mme_draw.instance_count : 1); @@ -710,6 +714,7 @@ void RasterizerOpenGL::DispatchCompute(GPUVAddr code_addr) { state.ApplyProgramPipeline(); glDispatchCompute(launch_desc.grid_dim_x, launch_desc.grid_dim_y, launch_desc.grid_dim_z); + ++num_queued_commands; } void RasterizerOpenGL::ResetCounter(VideoCore::QueryType type) { @@ -762,10 +767,18 @@ void RasterizerOpenGL::FlushAndInvalidateRegion(CacheAddr addr, u64 size) { } void RasterizerOpenGL::FlushCommands() { + // Only flush when we have commands queued to OpenGL. + if (num_queued_commands == 0) { + return; + } + num_queued_commands = 0; glFlush(); } void RasterizerOpenGL::TickFrame() { + // Ticking a frame means that buffers will be swapped, calling glFlush implicitly. + num_queued_commands = 0; + buffer_cache.TickFrame(); } diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 32bcaf8c2..a9218db22 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -226,6 +226,9 @@ private: void SetupShaders(GLenum primitive_mode); HostCounter samples_passed{GL_SAMPLES_PASSED}; + + /// Number of commands queued to the OpenGL driver. Reseted on flush. + std::size_t num_queued_commands = 0; }; } // namespace OpenGL -- cgit v1.2.3