From 40a2c57df5459ff965f1ea507bbca0e36ab17c94 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Sun, 29 Dec 2019 22:56:21 -0300 Subject: gl_state_tracker: Implement depth dirty flags --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 20 +++++++++++++++----- src/video_core/renderer_opengl/gl_state_tracker.cpp | 8 ++++++++ src/video_core/renderer_opengl/gl_state_tracker.h | 8 +++++++- src/video_core/renderer_opengl/renderer_opengl.cpp | 1 + 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 6d87b4e29..d747e29ad 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -1024,13 +1024,23 @@ void RasterizerOpenGL::SyncPrimitiveRestart() { } void RasterizerOpenGL::SyncDepthTestState() { - const auto& regs = system.GPU().Maxwell3D().regs; + auto& gpu = system.GPU().Maxwell3D(); + auto& flags = gpu.dirty.flags; - glDepthMask(regs.depth_write_enabled ? GL_TRUE : GL_FALSE); + const auto& regs = gpu.regs; + if (flags[Dirty::DepthMask]) { + flags[Dirty::DepthMask] = false; + glDepthMask(regs.depth_write_enabled ? GL_TRUE : GL_FALSE); + } - oglEnable(GL_DEPTH_TEST, regs.depth_test_enable); - if (regs.depth_test_enable) { - glDepthFunc(MaxwellToGL::ComparisonOp(regs.depth_test_func)); + if (flags[Dirty::DepthTest]) { + flags[Dirty::DepthTest] = false; + if (regs.depth_test_enable) { + glEnable(GL_DEPTH_TEST); + glDepthFunc(MaxwellToGL::ComparisonOp(regs.depth_test_func)); + } else { + glDisable(GL_DEPTH_TEST); + } } } diff --git a/src/video_core/renderer_opengl/gl_state_tracker.cpp b/src/video_core/renderer_opengl/gl_state_tracker.cpp index 05bba5d1d..999440656 100644 --- a/src/video_core/renderer_opengl/gl_state_tracker.cpp +++ b/src/video_core/renderer_opengl/gl_state_tracker.cpp @@ -129,6 +129,13 @@ void SetupDirtyShaders(Tables& tables) { Shaders); } +void SetupDirtyDepthTest(Tables& tables) { + auto& table = tables[0]; + table[OFF(depth_test_enable)] = DepthTest; + table[OFF(depth_write_enabled)] = DepthMask; + table[OFF(depth_test_func)] = DepthTest; +} + void SetupDirtyBlend(Tables& tables) { FillBlock(tables[0], OFF(blend_color), NUM(blend_color), BlendColor); @@ -169,6 +176,7 @@ void StateTracker::Initialize() { SetupDirtyVertexArrays(tables); SetupDirtyVertexFormat(tables); SetupDirtyShaders(tables); + SetupDirtyDepthTest(tables); SetupDirtyBlend(tables); SetupDirtyMisc(tables); diff --git a/src/video_core/renderer_opengl/gl_state_tracker.h b/src/video_core/renderer_opengl/gl_state_tracker.h index 1d854f38e..dd6cfe02a 100644 --- a/src/video_core/renderer_opengl/gl_state_tracker.h +++ b/src/video_core/renderer_opengl/gl_state_tracker.h @@ -58,8 +58,9 @@ enum : u8 { FrontFace, CullTest, - PrimitiveRestart, + DepthMask, DepthTest, + PrimitiveRestart, StencilTest, ColorMask, PolygonOffset, @@ -129,6 +130,11 @@ public: flags[OpenGL::Dirty::CullTest] = true; } + void NotifyDepthTest() { + auto& flags = system.GPU().Maxwell3D().dirty.flags; + flags[OpenGL::Dirty::DepthTest] = true; + } + private: Core::System& system; }; diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index e21d7e7a3..8fa4ecb28 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -584,6 +584,7 @@ void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) { state_tracker.NotifyFramebuffer(); state_tracker.NotifyFrontFace(); state_tracker.NotifyCullTest(); + state_tracker.NotifyDepthTest(); program_manager.UseVertexShader(vertex_program.handle); program_manager.UseGeometryShader(0); -- cgit v1.2.3