summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp10
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp36
2 files changed, 43 insertions, 3 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index e2a422052..17860d447 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -885,10 +885,18 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader,
885void RasterizerOpenGL::SetupAlphaTesting(Shader& shader) { 885void RasterizerOpenGL::SetupAlphaTesting(Shader& shader) {
886 const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; 886 const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
887 887
888 glProgramUniform1i(shader->GetProgramHandle(), shader->GetAlphaTestingEnableLocation(), 888 glProgramUniform1ui(shader->GetProgramHandle(), shader->GetAlphaTestingEnableLocation(),
889 regs.alpha_test_enabled); 889 regs.alpha_test_enabled);
890 glProgramUniform1f(shader->GetProgramHandle(), shader->GetAlphaTestingRefLocation(), 890 glProgramUniform1f(shader->GetProgramHandle(), shader->GetAlphaTestingRefLocation(),
891 regs.alpha_test_ref); 891 regs.alpha_test_ref);
892
893 u32 func = static_cast<u32>(regs.alpha_test_func);
894 // Normalize the gl variants of opCompare to be the same as the normal variants
895 if (func >= 0x200) {
896 func = func - 0x200 + 1U;
897 }
898
899 glProgramUniform1ui(shader->GetProgramHandle(), shader->GetAlphaTestingFuncLocation(), func);
892} 900}
893 901
894void RasterizerOpenGL::SyncViewport() { 902void RasterizerOpenGL::SyncViewport() {
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index e890cfe57..cbf501cc7 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -1280,13 +1280,13 @@ private:
1280 header.ps.IsColorComponentOutputEnabled(render_target, 1) || 1280 header.ps.IsColorComponentOutputEnabled(render_target, 1) ||
1281 header.ps.IsColorComponentOutputEnabled(render_target, 2) || 1281 header.ps.IsColorComponentOutputEnabled(render_target, 2) ||
1282 header.ps.IsColorComponentOutputEnabled(render_target, 3)) { 1282 header.ps.IsColorComponentOutputEnabled(render_target, 3)) {
1283 shader.AddLine(fmt::format("if ({} < alpha_testing_ref) discard;", 1283 shader.AddLine(fmt::format("if (AlphaFunc({}, alpha_testing_ref, alpha_testing_func)) discard;",
1284 regs.GetRegisterAsFloat(current_reg))); 1284 regs.GetRegisterAsFloat(current_reg)));
1285 current_reg += 4; 1285 current_reg += 4;
1286 } 1286 }
1287 } 1287 }
1288 --shader.scope; 1288 --shader.scope;
1289 shader.AddLine("}"); 1289 shader.AddLine('}');
1290 1290
1291 // Write the color outputs using the data in the shader registers, disabled 1291 // Write the color outputs using the data in the shader registers, disabled
1292 // rendertargets/components are skipped in the register assignment. 1292 // rendertargets/components are skipped in the register assignment.
@@ -3505,6 +3505,38 @@ private:
3505 declarations.AddLine("bool " + pred + " = false;"); 3505 declarations.AddLine("bool " + pred + " = false;");
3506 } 3506 }
3507 declarations.AddNewLine(); 3507 declarations.AddNewLine();
3508 GenerateFunctionDeclarations();
3509 }
3510
3511 void GenerateFunctionDeclarations() {
3512 if (stage == Maxwell3D::Regs::ShaderStage::Fragment) {
3513 declarations.AddLine("bool AlphaFunc(in float value, in float ref, in uint func) {");
3514 declarations.scope++;
3515 declarations.AddLine("switch (func) {");
3516 declarations.scope++;
3517 declarations.AddLine("case 1:");
3518 declarations.AddLine("return false;");
3519 declarations.AddLine("case 2:");
3520 declarations.AddLine("return value < ref;");
3521 declarations.AddLine("case 3:");
3522 declarations.AddLine("return value == ref;");
3523 declarations.AddLine("case 4:");
3524 declarations.AddLine("return value <= ref;");
3525 declarations.AddLine("case 5:");
3526 declarations.AddLine("return value > ref;");
3527 declarations.AddLine("case 6:");
3528 declarations.AddLine("return value != ref;");
3529 declarations.AddLine("case 7:");
3530 declarations.AddLine("return value >= ref;");
3531 declarations.AddLine("case 8:");
3532 declarations.AddLine("return true;");
3533 declarations.AddLine("default:");
3534 declarations.AddLine("return false;");
3535 declarations.scope--;
3536 declarations.AddLine('}');
3537 declarations.scope--;
3538 declarations.AddLine('}');
3539 }
3508 } 3540 }
3509 3541
3510private: 3542private: