summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2015-10-09 19:32:38 -0400
committerGravatar bunnei2015-10-21 21:54:56 -0400
commit71edb55114af129d6f580e271ad5196043342abe (patch)
tree73cd89075909781d728e92cfe121eee92effe84b /src
parentgl_shader_gen: Rename 'o' to 'attr' in vertex/fragment shaders. (diff)
downloadyuzu-71edb55114af129d6f580e271ad5196043342abe.tar.gz
yuzu-71edb55114af129d6f580e271ad5196043342abe.tar.xz
yuzu-71edb55114af129d6f580e271ad5196043342abe.zip
gl_shader_gen: Require explicit uniform locations.
- Fixes uniform issue on AMD.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp27
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h40
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp23
3 files changed, 34 insertions, 56 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 4f9865230..64639ed26 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -476,20 +476,14 @@ void RasterizerOpenGL::SetShader() {
476 std::unique_ptr<TEVShader> shader = Common::make_unique<TEVShader>(); 476 std::unique_ptr<TEVShader> shader = Common::make_unique<TEVShader>();
477 477
478 shader->shader.Create(GLShader::GenerateVertexShader().c_str(), GLShader::GenerateFragmentShader(config).c_str()); 478 shader->shader.Create(GLShader::GenerateVertexShader().c_str(), GLShader::GenerateFragmentShader(config).c_str());
479 shader->uniform_alphatest_ref = glGetUniformLocation(shader->shader.handle, "alphatest_ref");
480 shader->uniform_tex = glGetUniformLocation(shader->shader.handle, "tex");
481 shader->uniform_tev_combiner_buffer_color = glGetUniformLocation(shader->shader.handle, "tev_combiner_buffer_color");
482 shader->uniform_tev_const_colors = glGetUniformLocation(shader->shader.handle, "const_color");
483 479
484 state.draw.shader_program = shader->shader.handle; 480 state.draw.shader_program = shader->shader.handle;
485 state.Apply(); 481 state.Apply();
486 482
487 // Set the texture samplers to correspond to different texture units 483 // Set the texture samplers to correspond to different texture units
488 if (shader->uniform_tex != -1) { 484 glUniform1i(PicaShader::Uniform::Texture0, 0);
489 glUniform1i(shader->uniform_tex, 0); 485 glUniform1i(PicaShader::Uniform::Texture1, 1);
490 glUniform1i(shader->uniform_tex + 1, 1); 486 glUniform1i(PicaShader::Uniform::Texture2, 2);
491 glUniform1i(shader->uniform_tex + 2, 2);
492 }
493 487
494 current_shader = shader_cache.emplace(config, std::move(shader)).first->second.get(); 488 current_shader = shader_cache.emplace(config, std::move(shader)).first->second.get();
495 } 489 }
@@ -622,8 +616,7 @@ void RasterizerOpenGL::SyncBlendColor() {
622 616
623void RasterizerOpenGL::SyncAlphaTest() { 617void RasterizerOpenGL::SyncAlphaTest() {
624 const auto& regs = Pica::g_state.regs; 618 const auto& regs = Pica::g_state.regs;
625 if (current_shader->uniform_alphatest_ref != -1) 619 glUniform1i(PicaShader::Uniform::AlphaTestRef, regs.output_merger.alpha_test.ref);
626 glUniform1i(current_shader->uniform_alphatest_ref, regs.output_merger.alpha_test.ref);
627} 620}
628 621
629void RasterizerOpenGL::SyncLogicOp() { 622void RasterizerOpenGL::SyncLogicOp() {
@@ -654,17 +647,13 @@ void RasterizerOpenGL::SyncDepthTest() {
654} 647}
655 648
656void RasterizerOpenGL::SyncCombinerColor() { 649void RasterizerOpenGL::SyncCombinerColor() {
657 if (current_shader->uniform_tev_combiner_buffer_color != -1) { 650 auto combiner_color = PicaToGL::ColorRGBA8(Pica::g_state.regs.tev_combiner_buffer_color.raw);
658 auto combiner_color = PicaToGL::ColorRGBA8(Pica::g_state.regs.tev_combiner_buffer_color.raw); 651 glUniform4fv(PicaShader::Uniform::TevCombinerBufferColor, 1, combiner_color.data());
659 glUniform4fv(current_shader->uniform_tev_combiner_buffer_color, 1, combiner_color.data());
660 }
661} 652}
662 653
663void RasterizerOpenGL::SyncTevConstColor(int stage_index, const Pica::Regs::TevStageConfig& tev_stage) { 654void RasterizerOpenGL::SyncTevConstColor(int stage_index, const Pica::Regs::TevStageConfig& tev_stage) {
664 if (current_shader->uniform_tev_const_colors != -1) { 655 auto const_color = PicaToGL::ColorRGBA8(tev_stage.const_color);
665 auto const_color = PicaToGL::ColorRGBA8(tev_stage.const_color); 656 glUniform4fv(PicaShader::Uniform::TevConstColors + stage_index, 1, const_color.data());
666 glUniform4fv(current_shader->uniform_tev_const_colors + stage_index, 1, const_color.data());
667 }
668} 657}
669 658
670void RasterizerOpenGL::SyncDrawState() { 659void RasterizerOpenGL::SyncDrawState() {
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index 484579d82..79c34944a 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -153,36 +153,24 @@ public:
153 /// Notify rasterizer that a 3DS memory region has been changed 153 /// Notify rasterizer that a 3DS memory region has been changed
154 void NotifyFlush(PAddr addr, u32 size) override; 154 void NotifyFlush(PAddr addr, u32 size) override;
155 155
156private: 156 /// OpenGL shader generated for a given Pica register state
157 /// Structure used for managing texture environment states 157 struct PicaShader {
158 struct TEVConfigUniforms { 158 /// OpenGL shader resource
159 GLuint enabled;
160 GLuint color_sources;
161 GLuint alpha_sources;
162 GLuint color_modifiers;
163 GLuint alpha_modifiers;
164 GLuint color_alpha_op;
165 GLuint color_alpha_multiplier;
166 GLuint const_color;
167 GLuint updates_combiner_buffer_color_alpha;
168 };
169
170 struct TEVShader {
171 OGLShader shader; 159 OGLShader shader;
172 160
173 // Hardware fragment shader 161 /// Fragment shader uniforms
174 GLuint uniform_alphatest_ref; 162 enum Uniform : GLuint {
175 GLuint uniform_tex; 163 AlphaTestRef = 0,
176 GLuint uniform_tev_combiner_buffer_color; 164 TevConstColors = 1,
177 GLuint uniform_tev_const_colors; 165 Texture0 = 7,
178 166 Texture1 = 8,
179 TEVShader() = default; 167 Texture2 = 9,
180 TEVShader(TEVShader&& o) : shader(std::move(o.shader)), 168 TevCombinerBufferColor = 10,
181 uniform_alphatest_ref(o.uniform_alphatest_ref), uniform_tex(o.uniform_tex), 169 };
182 uniform_tev_combiner_buffer_color(o.uniform_tev_combiner_buffer_color),
183 uniform_tev_const_colors(o.uniform_tev_const_colors) {}
184 }; 170 };
185 171
172private:
173
186 /// Structure used for storing information about color textures 174 /// Structure used for storing information about color textures
187 struct TextureInfo { 175 struct TextureInfo {
188 OGLTexture texture; 176 OGLTexture texture;
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index 79c690e76..50bb2e3cc 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp
@@ -321,24 +321,25 @@ static void WriteTevStage(std::string& out, const ShaderCacheKey& config, unsign
321 321
322std::string GenerateFragmentShader(const ShaderCacheKey& config) { 322std::string GenerateFragmentShader(const ShaderCacheKey& config) {
323 std::string out = R"( 323 std::string out = R"(
324#version 150 core 324#version 330
325#extension GL_ARB_explicit_uniform_location : require
325 326
326#define NUM_VTX_ATTR 7 327#define NUM_VTX_ATTR 7
327#define NUM_TEV_STAGES 6 328#define NUM_TEV_STAGES 6
328 329
329in vec4 attr[NUM_VTX_ATTR]; 330in vec4 attr[NUM_VTX_ATTR];
330out vec4 color; 331out vec4 color;
332)";
331 333
332uniform int alphatest_ref; 334 using Uniform = RasterizerOpenGL::PicaShader::Uniform;
333uniform vec4 const_color[NUM_TEV_STAGES]; 335 out += "layout(location = " + std::to_string(Uniform::AlphaTestRef) + ") uniform int alphatest_ref;\n";
334uniform sampler2D tex[3]; 336 out += "layout(location = " + std::to_string(Uniform::TevConstColors) + ") uniform vec4 const_color[NUM_TEV_STAGES];\n";
335 337 out += "layout(location = " + std::to_string(Uniform::Texture0) + ") uniform sampler2D tex[3];\n";
336uniform vec4 tev_combiner_buffer_color; 338 out += "layout(location = " + std::to_string(Uniform::TevCombinerBufferColor) + ") uniform vec4 tev_combiner_buffer_color;\n";
337 339
338void main(void) { 340 out += "void main() {\n";
339vec4 g_combiner_buffer = tev_combiner_buffer_color; 341 out += "vec4 combiner_buffer = tev_combiner_buffer_color;\n";
340vec4 g_last_tex_env_out = vec4(0.0, 0.0, 0.0, 0.0); 342 out += "vec4 last_tex_env_out = vec4(0.0);\n";
341)";
342 343
343 // Do not do any sort of processing if it's obvious we're not going to pass the alpha test 344 // Do not do any sort of processing if it's obvious we're not going to pass the alpha test
344 if (config.alpha_test_func == Regs::CompareFunc::Never) { 345 if (config.alpha_test_func == Regs::CompareFunc::Never) {
@@ -362,7 +363,7 @@ vec4 g_last_tex_env_out = vec4(0.0, 0.0, 0.0, 0.0);
362 363
363std::string GenerateVertexShader() { 364std::string GenerateVertexShader() {
364 static const std::string out = R"( 365 static const std::string out = R"(
365#version 150 core 366#version 330
366 367
367#define NUM_VTX_ATTR 7 368#define NUM_VTX_ATTR 7
368 369