diff options
| author | 2019-12-29 18:14:40 -0300 | |
|---|---|---|
| committer | 2020-02-28 17:56:42 -0300 | |
| commit | b01dd7d1c86265dd19508ea15e4ff4db31681470 (patch) | |
| tree | 90cf54950dce4a5fd280336c57bc98e627b09d3d /src | |
| parent | gl_state_tracker: Implement dirty flags for clip distances and shaders (diff) | |
| download | yuzu-b01dd7d1c86265dd19508ea15e4ff4db31681470.tar.gz yuzu-b01dd7d1c86265dd19508ea15e4ff4db31681470.tar.xz yuzu-b01dd7d1c86265dd19508ea15e4ff4db31681470.zip | |
gl_state_tracker: Implement dirty flags for blending
Diffstat (limited to 'src')
5 files changed, 67 insertions, 14 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 717f127e9..cedfe5db1 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -458,6 +458,7 @@ void RasterizerOpenGL::Clear() { | |||
| 458 | } | 458 | } |
| 459 | 459 | ||
| 460 | // TODO: Signal state tracker about these changes | 460 | // TODO: Signal state tracker about these changes |
| 461 | state_tracker.NotifyBlend0(); | ||
| 461 | // TODO(Rodrigo): Find out if these changes affect clearing | 462 | // TODO(Rodrigo): Find out if these changes affect clearing |
| 462 | glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); | 463 | glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); |
| 463 | glDisablei(GL_BLEND, 0); | 464 | glDisablei(GL_BLEND, 0); |
| @@ -1102,31 +1103,53 @@ void RasterizerOpenGL::SyncFragmentColorClampState() { | |||
| 1102 | } | 1103 | } |
| 1103 | 1104 | ||
| 1104 | void RasterizerOpenGL::SyncBlendState() { | 1105 | void RasterizerOpenGL::SyncBlendState() { |
| 1105 | auto& maxwell3d = system.GPU().Maxwell3D(); | 1106 | auto& gpu = system.GPU().Maxwell3D(); |
| 1106 | const auto& regs = maxwell3d.regs; | 1107 | auto& flags = gpu.dirty.flags; |
| 1108 | const auto& regs = gpu.regs; | ||
| 1109 | |||
| 1110 | if (flags[Dirty::BlendColor]) { | ||
| 1111 | flags[Dirty::BlendColor] = false; | ||
| 1112 | glBlendColor(regs.blend_color.r, regs.blend_color.g, regs.blend_color.b, | ||
| 1113 | regs.blend_color.a); | ||
| 1114 | } | ||
| 1107 | 1115 | ||
| 1108 | glBlendColor(regs.blend_color.r, regs.blend_color.g, regs.blend_color.b, regs.blend_color.a); | 1116 | // TODO(Rodrigo): Revisit blending, there are several registers we are not reading |
| 1117 | |||
| 1118 | if (!flags[Dirty::BlendStates]) { | ||
| 1119 | return; | ||
| 1120 | } | ||
| 1121 | flags[Dirty::BlendStates] = false; | ||
| 1109 | 1122 | ||
| 1110 | if (!regs.independent_blend_enable) { | 1123 | if (!regs.independent_blend_enable) { |
| 1111 | const auto& src = regs.blend; | 1124 | if (!regs.blend.enable[0]) { |
| 1112 | oglEnable(GL_BLEND, src.enable[0]); | 1125 | glDisable(GL_BLEND); |
| 1113 | if (!src.enable[0]) { | ||
| 1114 | return; | 1126 | return; |
| 1115 | } | 1127 | } |
| 1116 | glBlendFuncSeparate(MaxwellToGL::BlendFunc(src.factor_source_rgb), | 1128 | glEnable(GL_BLEND); |
| 1117 | MaxwellToGL::BlendFunc(src.factor_dest_rgb), | 1129 | glBlendFuncSeparate(MaxwellToGL::BlendFunc(regs.blend.factor_source_rgb), |
| 1118 | MaxwellToGL::BlendFunc(src.factor_source_a), | 1130 | MaxwellToGL::BlendFunc(regs.blend.factor_dest_rgb), |
| 1119 | MaxwellToGL::BlendFunc(src.factor_dest_a)); | 1131 | MaxwellToGL::BlendFunc(regs.blend.factor_source_a), |
| 1120 | glBlendEquationSeparate(MaxwellToGL::BlendEquation(src.equation_rgb), | 1132 | MaxwellToGL::BlendFunc(regs.blend.factor_dest_a)); |
| 1121 | MaxwellToGL::BlendEquation(src.equation_a)); | 1133 | glBlendEquationSeparate(MaxwellToGL::BlendEquation(regs.blend.equation_rgb), |
| 1134 | MaxwellToGL::BlendEquation(regs.blend.equation_a)); | ||
| 1122 | return; | 1135 | return; |
| 1123 | } | 1136 | } |
| 1124 | 1137 | ||
| 1138 | const bool force = flags[Dirty::BlendIndependentEnabled]; | ||
| 1139 | flags[Dirty::BlendIndependentEnabled] = false; | ||
| 1140 | |||
| 1125 | for (std::size_t i = 0; i < Maxwell::NumRenderTargets; ++i) { | 1141 | for (std::size_t i = 0; i < Maxwell::NumRenderTargets; ++i) { |
| 1126 | oglEnablei(GL_BLEND, regs.blend.enable[i], static_cast<GLuint>(i)); | 1142 | if (!force && !flags[Dirty::BlendState0 + i]) { |
| 1143 | continue; | ||
| 1144 | } | ||
| 1145 | flags[Dirty::BlendState0 + i] = false; | ||
| 1146 | |||
| 1127 | if (!regs.blend.enable[i]) { | 1147 | if (!regs.blend.enable[i]) { |
| 1148 | glDisablei(GL_BLEND, static_cast<GLuint>(i)); | ||
| 1128 | continue; | 1149 | continue; |
| 1129 | } | 1150 | } |
| 1151 | glEnablei(GL_BLEND, static_cast<GLuint>(i)); | ||
| 1152 | |||
| 1130 | const auto& src = regs.independent_blend[i]; | 1153 | const auto& src = regs.independent_blend[i]; |
| 1131 | glBlendFuncSeparatei(static_cast<GLuint>(i), MaxwellToGL::BlendFunc(src.factor_source_rgb), | 1154 | glBlendFuncSeparatei(static_cast<GLuint>(i), MaxwellToGL::BlendFunc(src.factor_source_rgb), |
| 1132 | MaxwellToGL::BlendFunc(src.factor_dest_rgb), | 1155 | MaxwellToGL::BlendFunc(src.factor_dest_rgb), |
diff --git a/src/video_core/renderer_opengl/gl_state_tracker.cpp b/src/video_core/renderer_opengl/gl_state_tracker.cpp index bc5942a7f..2da1b65fc 100644 --- a/src/video_core/renderer_opengl/gl_state_tracker.cpp +++ b/src/video_core/renderer_opengl/gl_state_tracker.cpp | |||
| @@ -129,6 +129,21 @@ void SetupDirtyShaders(Tables& tables) { | |||
| 129 | Shaders); | 129 | Shaders); |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | void SetupDirtyBlend(Tables& tables) { | ||
| 133 | FillBlock(tables[0], OFF(blend_color), NUM(blend_color), BlendColor); | ||
| 134 | |||
| 135 | tables[0][OFF(independent_blend_enable)] = BlendIndependentEnabled; | ||
| 136 | |||
| 137 | for (std::size_t i = 0; i < Regs::NumRenderTargets; ++i) { | ||
| 138 | const std::size_t offset = OFF(independent_blend) + i * NUM(independent_blend[0]); | ||
| 139 | FillBlock(tables[0], offset, NUM(independent_blend[0]), BlendState0 + i); | ||
| 140 | |||
| 141 | tables[0][OFF(blend.enable) + i] = static_cast<u8>(BlendState0 + i); | ||
| 142 | } | ||
| 143 | FillBlock(tables[1], OFF(independent_blend), NUM(independent_blend), BlendStates); | ||
| 144 | FillBlock(tables[1], OFF(blend), NUM(blend), BlendStates); | ||
| 145 | } | ||
| 146 | |||
| 132 | void SetupDirtyMisc(Tables& tables) { | 147 | void SetupDirtyMisc(Tables& tables) { |
| 133 | tables[0][OFF(clip_distance_enabled)] = ClipDistances; | 148 | tables[0][OFF(clip_distance_enabled)] = ClipDistances; |
| 134 | } | 149 | } |
| @@ -147,6 +162,7 @@ void StateTracker::Initialize() { | |||
| 147 | SetupDirtyVertexArrays(tables); | 162 | SetupDirtyVertexArrays(tables); |
| 148 | SetupDirtyVertexFormat(tables); | 163 | SetupDirtyVertexFormat(tables); |
| 149 | SetupDirtyShaders(tables); | 164 | SetupDirtyShaders(tables); |
| 165 | SetupDirtyBlend(tables); | ||
| 150 | SetupDirtyMisc(tables); | 166 | SetupDirtyMisc(tables); |
| 151 | 167 | ||
| 152 | auto& store = dirty.on_write_stores; | 168 | auto& store = dirty.on_write_stores; |
diff --git a/src/video_core/renderer_opengl/gl_state_tracker.h b/src/video_core/renderer_opengl/gl_state_tracker.h index 11fdc6de4..a9b470eee 100644 --- a/src/video_core/renderer_opengl/gl_state_tracker.h +++ b/src/video_core/renderer_opengl/gl_state_tracker.h | |||
| @@ -47,8 +47,15 @@ enum : u8 { | |||
| 47 | ColorMask0, | 47 | ColorMask0, |
| 48 | ColorMask7 = ColorMask0 + 7, | 48 | ColorMask7 = ColorMask0 + 7, |
| 49 | 49 | ||
| 50 | BlendColor, | ||
| 51 | BlendIndependentEnabled, | ||
| 52 | BlendStates, | ||
| 53 | BlendState0, | ||
| 54 | BlendState7 = BlendState0 + 7, | ||
| 55 | |||
| 50 | Shaders, | 56 | Shaders, |
| 51 | ClipDistances, | 57 | ClipDistances, |
| 58 | |||
| 52 | CullTestEnable, | 59 | CullTestEnable, |
| 53 | FrontFace, | 60 | FrontFace, |
| 54 | CullFace, | 61 | CullFace, |
| @@ -56,7 +63,6 @@ enum : u8 { | |||
| 56 | DepthTest, | 63 | DepthTest, |
| 57 | StencilTest, | 64 | StencilTest, |
| 58 | ColorMask, | 65 | ColorMask, |
| 59 | BlendState, | ||
| 60 | PolygonOffset, | 66 | PolygonOffset, |
| 61 | 67 | ||
| 62 | Last | 68 | Last |
| @@ -103,6 +109,12 @@ public: | |||
| 103 | flags[OpenGL::Dirty::ColorMask0] = true; | 109 | flags[OpenGL::Dirty::ColorMask0] = true; |
| 104 | } | 110 | } |
| 105 | 111 | ||
| 112 | void NotifyBlend0() { | ||
| 113 | auto& flags = system.GPU().Maxwell3D().dirty.flags; | ||
| 114 | flags[OpenGL::Dirty::BlendStates] = true; | ||
| 115 | flags[OpenGL::Dirty::BlendState0] = true; | ||
| 116 | } | ||
| 117 | |||
| 106 | void NotifyFramebuffer() { | 118 | void NotifyFramebuffer() { |
| 107 | auto& flags = system.GPU().Maxwell3D().dirty.flags; | 119 | auto& flags = system.GPU().Maxwell3D().dirty.flags; |
| 108 | flags[VideoCommon::Dirty::RenderTargets] = true; | 120 | flags[VideoCommon::Dirty::RenderTargets] = true; |
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index a02326b9f..46572eb43 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp | |||
| @@ -520,6 +520,7 @@ void TextureCacheOpenGL::ImageBlit(View& src_view, View& dst_view, | |||
| 520 | 520 | ||
| 521 | // TODO: Signal state tracker about these changes | 521 | // TODO: Signal state tracker about these changes |
| 522 | state_tracker.NotifyScissor0(); | 522 | state_tracker.NotifyScissor0(); |
| 523 | state_tracker.NotifyBlend0(); | ||
| 523 | state_tracker.NotifyFramebuffer(); | 524 | state_tracker.NotifyFramebuffer(); |
| 524 | 525 | ||
| 525 | if (dst_params.srgb_conversion) { | 526 | if (dst_params.srgb_conversion) { |
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index cbe916488..d81c68077 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp | |||
| @@ -580,6 +580,7 @@ void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) { | |||
| 580 | state_tracker.NotifyViewport0(); | 580 | state_tracker.NotifyViewport0(); |
| 581 | state_tracker.NotifyScissor0(); | 581 | state_tracker.NotifyScissor0(); |
| 582 | state_tracker.NotifyColorMask0(); | 582 | state_tracker.NotifyColorMask0(); |
| 583 | state_tracker.NotifyBlend0(); | ||
| 583 | state_tracker.NotifyFramebuffer(); | 584 | state_tracker.NotifyFramebuffer(); |
| 584 | 585 | ||
| 585 | program_manager.UseVertexShader(vertex_program.handle); | 586 | program_manager.UseVertexShader(vertex_program.handle); |