From 4be61013a1e26414b37abb35e82b48600c05628b Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Wed, 17 Jul 2019 17:00:06 -0400 Subject: [PATCH] GL_State: Feedback and fixes --- src/video_core/engines/maxwell_3d.h | 8 +++++++- src/video_core/renderer_opengl/gl_rasterizer.cpp | 10 +++++----- src/video_core/renderer_opengl/gl_state.h | 16 ++++++++-------- .../renderer_opengl/renderer_opengl.cpp | 7 +++++++ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h index 6bf8d0603..42feb0345 100644 --- a/src/video_core/engines/maxwell_3d.h +++ b/src/video_core/engines/maxwell_3d.h @@ -1129,24 +1129,30 @@ public: union { struct { bool null_dirty; + // Vertex Attributes bool vertex_attrib_format; + // Vertex Arrays std::array vertex_array; bool vertex_array_buffers; + // Vertex Instances std::array vertex_instance; bool vertex_instances; + // Render Targets std::array render_target; bool depth_buffer; bool render_settings; + // Shaders bool shaders; - // State + + // Rasterizer State bool viewport; bool clip_coefficient; bool cull_mode; diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 2e974c98a..d1ae8a7c5 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -1059,7 +1059,7 @@ void RasterizerOpenGL::SyncStencilTestState() { state.stencil.back.action_depth_fail = GL_KEEP; state.stencil.back.action_depth_pass = GL_KEEP; } - state.MarkDirtyStencilState(true); + state.MarkDirtyStencilState(); maxwell3d.dirty.stencil_test = false; } @@ -1081,7 +1081,7 @@ void RasterizerOpenGL::SyncColorMask() { dest.alpha_enabled = (source.A == 0) ? GL_FALSE : GL_TRUE; } - state.MarkDirtyColorMask(true); + state.MarkDirtyColorMask(); maxwell3d.dirty.color_mask = false; } @@ -1125,7 +1125,7 @@ void RasterizerOpenGL::SyncBlendState() { state.blend[i].enabled = false; } maxwell3d.dirty.blend_state = false; - state.MarkDirtyBlendState(true); + state.MarkDirtyBlendState(); return; } @@ -1143,7 +1143,7 @@ void RasterizerOpenGL::SyncBlendState() { blend.dst_a_func = MaxwellToGL::BlendFunc(src.factor_dest_a); } - state.MarkDirtyBlendState(true); + state.MarkDirtyBlendState(); maxwell3d.dirty.blend_state = false; } @@ -1209,7 +1209,7 @@ void RasterizerOpenGL::SyncPolygonOffset() { state.polygon_offset.factor = regs.polygon_offset_factor; state.polygon_offset.clamp = regs.polygon_offset_clamp; - state.MarkDirtyPolygonOffset(true); + state.MarkDirtyPolygonOffset(); maxwell3d.dirty.polygon_offset = false; } diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h index 6a85d15b1..fdf9a8a12 100644 --- a/src/video_core/renderer_opengl/gl_state.h +++ b/src/video_core/renderer_opengl/gl_state.h @@ -238,20 +238,20 @@ public: /// Viewport does not affects glClearBuffer so emulate viewport using scissor test void EmulateViewportWithScissor(); - void MarkDirtyBlendState(const bool is_dirty) { - dirty.blend_state = is_dirty; + void MarkDirtyBlendState() { + dirty.blend_state = true; } - void MarkDirtyStencilState(const bool is_dirty) { - dirty.stencil_state = is_dirty; + void MarkDirtyStencilState() { + dirty.stencil_state = true; } - void MarkDirtyPolygonOffset(const bool is_dirty) { - dirty.polygon_offset = is_dirty; + void MarkDirtyPolygonOffset() { + dirty.polygon_offset = true; } - void MarkDirtyColorMask(const bool is_dirty) { - dirty.color_mask = is_dirty; + void MarkDirtyColorMask() { + dirty.color_mask = true; } void AllDirty() { diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 9ecdddb0d..a05cef3b9 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -108,6 +108,7 @@ void RendererOpenGL::SwapBuffers( // Maintain the rasterizer's state as a priority OpenGLState prev_state = OpenGLState::GetCurState(); + state.AllDirty(); state.Apply(); if (framebuffer) { @@ -140,6 +141,7 @@ void RendererOpenGL::SwapBuffers( system.GetPerfStats().BeginSystemFrame(); // Restore the rasterizer state + prev_state.AllDirty(); prev_state.Apply(); } @@ -206,6 +208,7 @@ void RendererOpenGL::InitOpenGLObjects() { // Link shaders and get variable locations shader.CreateFromSource(vertex_shader, nullptr, fragment_shader); state.draw.shader_program = shader.handle; + state.AllDirty(); state.Apply(); uniform_modelview_matrix = glGetUniformLocation(shader.handle, "modelview_matrix"); uniform_color_texture = glGetUniformLocation(shader.handle, "color_texture"); @@ -338,12 +341,14 @@ void RendererOpenGL::DrawScreenTriangles(const ScreenInfo& screen_info, float x, // Workaround brigthness problems in SMO by enabling sRGB in the final output // if it has been used in the frame. Needed because of this bug in QT: QTBUG-50987 state.framebuffer_srgb.enabled = OpenGLState::GetsRGBUsed(); + state.AllDirty(); state.Apply(); glNamedBufferSubData(vertex_buffer.handle, 0, sizeof(vertices), vertices.data()); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // Restore default state state.framebuffer_srgb.enabled = false; state.texture_units[0].texture = 0; + state.AllDirty(); state.Apply(); // Clear sRGB state for the next frame OpenGLState::ClearsRGBUsed(); @@ -388,6 +393,7 @@ void RendererOpenGL::CaptureScreenshot() { GLuint old_read_fb = state.draw.read_framebuffer; GLuint old_draw_fb = state.draw.draw_framebuffer; state.draw.read_framebuffer = state.draw.draw_framebuffer = screenshot_framebuffer.handle; + state.AllDirty(); state.Apply(); Layout::FramebufferLayout layout{renderer_settings.screenshot_framebuffer_layout}; @@ -407,6 +413,7 @@ void RendererOpenGL::CaptureScreenshot() { screenshot_framebuffer.Release(); state.draw.read_framebuffer = old_read_fb; state.draw.draw_framebuffer = old_draw_fb; + state.AllDirty(); state.Apply(); glDeleteRenderbuffers(1, &renderbuffer);