summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2019-12-26 03:51:50 -0300
committerGravatar ReinUsesLisp2020-02-28 17:34:43 -0300
commit1bc0da3dea5a8502e63f5c123151328ccb2ba8d6 (patch)
tree5a43fa241e32175df8be44fcb797609e5f75df0c
parentgl_state: Remove stencil test tracking (diff)
downloadyuzu-1bc0da3dea5a8502e63f5c123151328ccb2ba8d6.tar.gz
yuzu-1bc0da3dea5a8502e63f5c123151328ccb2ba8d6.tar.xz
yuzu-1bc0da3dea5a8502e63f5c123151328ccb2ba8d6.zip
gl_state: Remove blend state tracking
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp49
-rw-r--r--src/video_core/renderer_opengl/gl_state.cpp61
-rw-r--r--src/video_core/renderer_opengl/gl_state.h18
-rw-r--r--src/video_core/renderer_opengl/gl_texture_cache.cpp3
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.cpp1
5 files changed, 28 insertions, 104 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 573f14cab..f916f348f 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -442,7 +442,9 @@ void RasterizerOpenGL::Clear() {
442 } 442 }
443 443
444 // TODO: Signal state tracker about these changes 444 // TODO: Signal state tracker about these changes
445 // TODO(Rodrigo): Find out if these changes affect clearing
445 glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); 446 glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
447 glDisablei(GL_BLEND, 0);
446 448
447 UNIMPLEMENTED_IF(regs.clear_flags.viewport); 449 UNIMPLEMENTED_IF(regs.clear_flags.viewport);
448 450
@@ -1049,37 +1051,34 @@ void RasterizerOpenGL::SyncBlendState() {
1049 1051
1050 glBlendColor(regs.blend_color.r, regs.blend_color.g, regs.blend_color.b, regs.blend_color.a); 1052 glBlendColor(regs.blend_color.r, regs.blend_color.g, regs.blend_color.b, regs.blend_color.a);
1051 1053
1052 state.independant_blend.enabled = regs.independent_blend_enable; 1054 if (!regs.independent_blend_enable) {
1053 if (!state.independant_blend.enabled) {
1054 auto& blend = state.blend[0];
1055 const auto& src = regs.blend; 1055 const auto& src = regs.blend;
1056 blend.enabled = src.enable[0] != 0; 1056 oglEnable(GL_BLEND, src.enable[0]);
1057 if (blend.enabled) { 1057 if (!src.enable[0]) {
1058 blend.rgb_equation = MaxwellToGL::BlendEquation(src.equation_rgb); 1058 return;
1059 blend.src_rgb_func = MaxwellToGL::BlendFunc(src.factor_source_rgb);
1060 blend.dst_rgb_func = MaxwellToGL::BlendFunc(src.factor_dest_rgb);
1061 blend.a_equation = MaxwellToGL::BlendEquation(src.equation_a);
1062 blend.src_a_func = MaxwellToGL::BlendFunc(src.factor_source_a);
1063 blend.dst_a_func = MaxwellToGL::BlendFunc(src.factor_dest_a);
1064 }
1065 for (std::size_t i = 1; i < Tegra::Engines::Maxwell3D::Regs::NumRenderTargets; i++) {
1066 state.blend[i].enabled = false;
1067 } 1059 }
1060 glBlendFuncSeparate(MaxwellToGL::BlendFunc(src.factor_source_rgb),
1061 MaxwellToGL::BlendFunc(src.factor_dest_rgb),
1062 MaxwellToGL::BlendFunc(src.factor_source_a),
1063 MaxwellToGL::BlendFunc(src.factor_dest_a));
1064 glBlendEquationSeparate(MaxwellToGL::BlendEquation(src.equation_rgb),
1065 MaxwellToGL::BlendEquation(src.equation_a));
1068 return; 1066 return;
1069 } 1067 }
1070 1068
1071 for (std::size_t i = 0; i < Tegra::Engines::Maxwell3D::Regs::NumRenderTargets; i++) { 1069 for (std::size_t i = 0; i < Maxwell::NumRenderTargets; ++i) {
1072 auto& blend = state.blend[i]; 1070 oglEnablei(GL_BLEND, regs.blend.enable[i], static_cast<GLuint>(i));
1073 const auto& src = regs.independent_blend[i]; 1071 if (!regs.blend.enable[i]) {
1074 blend.enabled = regs.blend.enable[i] != 0;
1075 if (!blend.enabled)
1076 continue; 1072 continue;
1077 blend.rgb_equation = MaxwellToGL::BlendEquation(src.equation_rgb); 1073 }
1078 blend.src_rgb_func = MaxwellToGL::BlendFunc(src.factor_source_rgb); 1074 const auto& src = regs.independent_blend[i];
1079 blend.dst_rgb_func = MaxwellToGL::BlendFunc(src.factor_dest_rgb); 1075 glBlendFuncSeparatei(static_cast<GLuint>(i), MaxwellToGL::BlendFunc(src.factor_source_rgb),
1080 blend.a_equation = MaxwellToGL::BlendEquation(src.equation_a); 1076 MaxwellToGL::BlendFunc(src.factor_dest_rgb),
1081 blend.src_a_func = MaxwellToGL::BlendFunc(src.factor_source_a); 1077 MaxwellToGL::BlendFunc(src.factor_source_a),
1082 blend.dst_a_func = MaxwellToGL::BlendFunc(src.factor_dest_a); 1078 MaxwellToGL::BlendFunc(src.factor_dest_a));
1079 glBlendEquationSeparatei(static_cast<GLuint>(i),
1080 MaxwellToGL::BlendEquation(src.equation_rgb),
1081 MaxwellToGL::BlendEquation(src.equation_a));
1083 } 1082 }
1084} 1083}
1085 1084
diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp
index d62a55b2f..3cdb9b4a0 100644
--- a/src/video_core/renderer_opengl/gl_state.cpp
+++ b/src/video_core/renderer_opengl/gl_state.cpp
@@ -106,66 +106,6 @@ void OpenGLState::ApplyProgramPipeline() {
106 } 106 }
107} 107}
108 108
109void OpenGLState::ApplyGlobalBlending() {
110 const Blend& updated = blend[0];
111 Blend& current = cur_state.blend[0];
112
113 Enable(GL_BLEND, current.enabled, updated.enabled);
114
115 if (current.src_rgb_func != updated.src_rgb_func ||
116 current.dst_rgb_func != updated.dst_rgb_func || current.src_a_func != updated.src_a_func ||
117 current.dst_a_func != updated.dst_a_func) {
118 current.src_rgb_func = updated.src_rgb_func;
119 current.dst_rgb_func = updated.dst_rgb_func;
120 current.src_a_func = updated.src_a_func;
121 current.dst_a_func = updated.dst_a_func;
122 glBlendFuncSeparate(updated.src_rgb_func, updated.dst_rgb_func, updated.src_a_func,
123 updated.dst_a_func);
124 }
125
126 if (current.rgb_equation != updated.rgb_equation || current.a_equation != updated.a_equation) {
127 current.rgb_equation = updated.rgb_equation;
128 current.a_equation = updated.a_equation;
129 glBlendEquationSeparate(updated.rgb_equation, updated.a_equation);
130 }
131}
132
133void OpenGLState::ApplyTargetBlending(std::size_t target, bool force) {
134 const Blend& updated = blend[target];
135 Blend& current = cur_state.blend[target];
136
137 if (current.enabled != updated.enabled || force) {
138 current.enabled = updated.enabled;
139 Enable(GL_BLEND, static_cast<GLuint>(target), updated.enabled);
140 }
141
142 if (UpdateTie(std::tie(current.src_rgb_func, current.dst_rgb_func, current.src_a_func,
143 current.dst_a_func),
144 std::tie(updated.src_rgb_func, updated.dst_rgb_func, updated.src_a_func,
145 updated.dst_a_func))) {
146 glBlendFuncSeparatei(static_cast<GLuint>(target), updated.src_rgb_func,
147 updated.dst_rgb_func, updated.src_a_func, updated.dst_a_func);
148 }
149
150 if (UpdateTie(std::tie(current.rgb_equation, current.a_equation),
151 std::tie(updated.rgb_equation, updated.a_equation))) {
152 glBlendEquationSeparatei(static_cast<GLuint>(target), updated.rgb_equation,
153 updated.a_equation);
154 }
155}
156
157void OpenGLState::ApplyBlending() {
158 if (independant_blend.enabled) {
159 const bool force = independant_blend.enabled != cur_state.independant_blend.enabled;
160 for (std::size_t target = 0; target < Maxwell::NumRenderTargets; ++target) {
161 ApplyTargetBlending(target, force);
162 }
163 } else {
164 ApplyGlobalBlending();
165 }
166 cur_state.independant_blend.enabled = independant_blend.enabled;
167}
168
169void OpenGLState::ApplyRenderBuffer() { 109void OpenGLState::ApplyRenderBuffer() {
170 if (cur_state.renderbuffer != renderbuffer) { 110 if (cur_state.renderbuffer != renderbuffer) {
171 cur_state.renderbuffer = renderbuffer; 111 cur_state.renderbuffer = renderbuffer;
@@ -206,7 +146,6 @@ void OpenGLState::Apply() {
206 ApplyFramebufferState(); 146 ApplyFramebufferState();
207 ApplyShaderProgram(); 147 ApplyShaderProgram();
208 ApplyProgramPipeline(); 148 ApplyProgramPipeline();
209 ApplyBlending();
210 ApplyTextures(); 149 ApplyTextures();
211 ApplySamplers(); 150 ApplySamplers();
212 ApplyImages(); 151 ApplyImages();
diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h
index 18f36da08..29126b80a 100644
--- a/src/video_core/renderer_opengl/gl_state.h
+++ b/src/video_core/renderer_opengl/gl_state.h
@@ -13,21 +13,6 @@ namespace OpenGL {
13 13
14class OpenGLState { 14class OpenGLState {
15public: 15public:
16 struct Blend {
17 bool enabled = false; // GL_BLEND
18 GLenum rgb_equation = GL_FUNC_ADD; // GL_BLEND_EQUATION_RGB
19 GLenum a_equation = GL_FUNC_ADD; // GL_BLEND_EQUATION_ALPHA
20 GLenum src_rgb_func = GL_ONE; // GL_BLEND_SRC_RGB
21 GLenum dst_rgb_func = GL_ZERO; // GL_BLEND_DST_RGB
22 GLenum src_a_func = GL_ONE; // GL_BLEND_SRC_ALPHA
23 GLenum dst_a_func = GL_ZERO; // GL_BLEND_DST_ALPHA
24 };
25 std::array<Blend, Tegra::Engines::Maxwell3D::Regs::NumRenderTargets> blend;
26
27 struct {
28 bool enabled = false;
29 } independant_blend;
30
31 static constexpr std::size_t NumSamplers = 32 * 5; 16 static constexpr std::size_t NumSamplers = 32 * 5;
32 static constexpr std::size_t NumImages = 8 * 5; 17 static constexpr std::size_t NumImages = 8 * 5;
33 std::array<GLuint, NumSamplers> textures = {}; 18 std::array<GLuint, NumSamplers> textures = {};
@@ -56,9 +41,6 @@ public:
56 void ApplyFramebufferState(); 41 void ApplyFramebufferState();
57 void ApplyShaderProgram(); 42 void ApplyShaderProgram();
58 void ApplyProgramPipeline(); 43 void ApplyProgramPipeline();
59 void ApplyTargetBlending(std::size_t target, bool force);
60 void ApplyGlobalBlending();
61 void ApplyBlending();
62 void ApplyTextures(); 44 void ApplyTextures();
63 void ApplySamplers(); 45 void ApplySamplers();
64 void ApplyImages(); 46 void ApplyImages();
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp
index 85d41f826..f7a1ca3a9 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp
@@ -537,8 +537,11 @@ void TextureCacheOpenGL::ImageBlit(View& src_view, View& dst_view,
537 glDisable(GL_FRAMEBUFFER_SRGB); 537 glDisable(GL_FRAMEBUFFER_SRGB);
538 } 538 }
539 // TODO(Rodrigo): Find out if rasterizer discard affects blits 539 // TODO(Rodrigo): Find out if rasterizer discard affects blits
540 // TODO(Rodrigo): Find out if blending affects blits
541 // TODO(Rodrigo): Find out if clip control affects blits
540 glDisable(GL_RASTERIZER_DISCARD); 542 glDisable(GL_RASTERIZER_DISCARD);
541 glDisablei(GL_SCISSOR_TEST, 0); 543 glDisablei(GL_SCISSOR_TEST, 0);
544 glDisablei(GL_BLEND, 0);
542 glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); 545 glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
543 546
544 u32 buffers{}; 547 u32 buffers{};
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp
index fcadc09d9..053d8602b 100644
--- a/src/video_core/renderer_opengl/renderer_opengl.cpp
+++ b/src/video_core/renderer_opengl/renderer_opengl.cpp
@@ -582,6 +582,7 @@ void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) {
582 glDisable(GL_STENCIL_TEST); 582 glDisable(GL_STENCIL_TEST);
583 glDisable(GL_POLYGON_OFFSET_FILL); 583 glDisable(GL_POLYGON_OFFSET_FILL);
584 glDisable(GL_RASTERIZER_DISCARD); 584 glDisable(GL_RASTERIZER_DISCARD);
585 glDisablei(GL_BLEND, 0);
585 glDisablei(GL_SCISSOR_TEST, 0); 586 glDisablei(GL_SCISSOR_TEST, 0);
586 glCullFace(GL_BACK); 587 glCullFace(GL_BACK);
587 glFrontFace(GL_CW); 588 glFrontFace(GL_CW);