From aa620c14af0a9bc2bf7784ed096298fc3c8899c3 Mon Sep 17 00:00:00 2001 From: FernandoS27 Date: Mon, 8 Oct 2018 23:34:11 -0400 Subject: Implemented Alpha Testing --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/video_core/renderer_opengl/gl_rasterizer.cpp') diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 3daccf82f..e2a422052 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -323,6 +323,8 @@ void RasterizerOpenGL::SetupShaders(GLenum primitive_mode) { current_texture_bindpoint = SetupTextures(static_cast(stage), shader, primitive_mode, current_texture_bindpoint); + SetupAlphaTesting(shader); + // When VertexA is enabled, we have dual vertex shaders if (program == Maxwell::ShaderProgram::VertexA) { // VertexB was combined with VertexA, so we skip the VertexB iteration @@ -880,6 +882,15 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader, return current_unit + static_cast(entries.size()); } +void RasterizerOpenGL::SetupAlphaTesting(Shader& shader) { + const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; + + glProgramUniform1i(shader->GetProgramHandle(), shader->GetAlphaTestingEnableLocation(), + regs.alpha_test_enabled); + glProgramUniform1f(shader->GetProgramHandle(), shader->GetAlphaTestingRefLocation(), + regs.alpha_test_ref); +} + void RasterizerOpenGL::SyncViewport() { const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; const MathUtil::Rectangle viewport_rect{regs.viewport_transform[0].GetRect()}; -- cgit v1.2.3 From 7b39107e3ae056a857e1780b2123e757b8deab26 Mon Sep 17 00:00:00 2001 From: FernandoS27 Date: Wed, 10 Oct 2018 09:20:13 -0400 Subject: Added Alpha Func --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/video_core/renderer_opengl/gl_rasterizer.cpp') 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, void RasterizerOpenGL::SetupAlphaTesting(Shader& shader) { const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; - glProgramUniform1i(shader->GetProgramHandle(), shader->GetAlphaTestingEnableLocation(), + glProgramUniform1ui(shader->GetProgramHandle(), shader->GetAlphaTestingEnableLocation(), regs.alpha_test_enabled); glProgramUniform1f(shader->GetProgramHandle(), shader->GetAlphaTestingRefLocation(), regs.alpha_test_ref); + + u32 func = static_cast(regs.alpha_test_func); + // Normalize the gl variants of opCompare to be the same as the normal variants + if (func >= 0x200) { + func = func - 0x200 + 1U; + } + + glProgramUniform1ui(shader->GetProgramHandle(), shader->GetAlphaTestingFuncLocation(), func); } void RasterizerOpenGL::SyncViewport() { -- cgit v1.2.3 From bcb5b924fd10183fb8fdbbbbe3ba909f8b9fc346 Mon Sep 17 00:00:00 2001 From: FernandoS27 Date: Wed, 10 Oct 2018 09:45:22 -0400 Subject: Remove SyncAlphaTest and clang format --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/video_core/renderer_opengl/gl_rasterizer.cpp') diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 17860d447..e5fc6e8f5 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -572,8 +572,8 @@ void RasterizerOpenGL::DrawArrays() { SyncBlendState(); SyncLogicOpState(); SyncCullMode(); - SyncAlphaTest(); SyncScissorTest(); + // Alpha Testing is synced on shaders. SyncTransformFeedback(); SyncPointState(); @@ -886,7 +886,7 @@ void RasterizerOpenGL::SetupAlphaTesting(Shader& shader) { const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; glProgramUniform1ui(shader->GetProgramHandle(), shader->GetAlphaTestingEnableLocation(), - regs.alpha_test_enabled); + regs.alpha_test_enabled); glProgramUniform1f(shader->GetProgramHandle(), shader->GetAlphaTestingRefLocation(), regs.alpha_test_ref); @@ -1026,6 +1026,7 @@ void RasterizerOpenGL::SyncLogicOpState() { state.logic_op.operation = MaxwellToGL::LogicOp(regs.logic_op.operation); } +<<<<<<< HEAD void RasterizerOpenGL::SyncAlphaTest() { const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; @@ -1053,6 +1054,8 @@ void RasterizerOpenGL::SyncScissorTest() { } } +======= +>>>>>>> Remove SyncAlphaTest and clang format void RasterizerOpenGL::SyncTransformFeedback() { const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; -- cgit v1.2.3 From 17315cee16df0848ed095ba3bc3fc1460465a682 Mon Sep 17 00:00:00 2001 From: FernandoS27 Date: Wed, 10 Oct 2018 15:06:32 -0400 Subject: Cache uniform locations and restructure the implementation --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 26 ++++-------------------- 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'src/video_core/renderer_opengl/gl_rasterizer.cpp') diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index e5fc6e8f5..0f8227f7b 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -885,18 +885,14 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader, void RasterizerOpenGL::SetupAlphaTesting(Shader& shader) { const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; - glProgramUniform1ui(shader->GetProgramHandle(), shader->GetAlphaTestingEnableLocation(), - regs.alpha_test_enabled); - glProgramUniform1f(shader->GetProgramHandle(), shader->GetAlphaTestingRefLocation(), - regs.alpha_test_ref); - u32 func = static_cast(regs.alpha_test_func); // Normalize the gl variants of opCompare to be the same as the normal variants - if (func >= 0x200) { - func = func - 0x200 + 1U; + u32 op = static_cast(Tegra::Engines::Maxwell3D::Regs::ComparisonOp::Never); + if (func >= op) { + func = func - op + 1U; } - glProgramUniform1ui(shader->GetProgramHandle(), shader->GetAlphaTestingFuncLocation(), func); + shader->SetAlphaTesting(regs.alpha_test_enabled == 1, regs.alpha_test_ref, func); } void RasterizerOpenGL::SyncViewport() { @@ -1026,18 +1022,6 @@ void RasterizerOpenGL::SyncLogicOpState() { state.logic_op.operation = MaxwellToGL::LogicOp(regs.logic_op.operation); } -<<<<<<< HEAD -void RasterizerOpenGL::SyncAlphaTest() { - const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; - - // TODO(Rodrigo): Alpha testing is a legacy OpenGL feature, but it can be - // implemented with a test+discard in fragment shaders. - if (regs.alpha_test_enabled != 0) { - LOG_CRITICAL(Render_OpenGL, "Alpha testing is not implemented"); - UNREACHABLE(); - } -} - void RasterizerOpenGL::SyncScissorTest() { const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; @@ -1054,8 +1038,6 @@ void RasterizerOpenGL::SyncScissorTest() { } } -======= ->>>>>>> Remove SyncAlphaTest and clang format void RasterizerOpenGL::SyncTransformFeedback() { const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; -- cgit v1.2.3 From 59a004f915e84fec4a4fed125661eb486e1de198 Mon Sep 17 00:00:00 2001 From: FernandoS27 Date: Wed, 10 Oct 2018 16:34:15 -0400 Subject: Use standard UBO and fix/stylize the code --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'src/video_core/renderer_opengl/gl_rasterizer.cpp') diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 0f8227f7b..d93681813 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -323,8 +323,6 @@ void RasterizerOpenGL::SetupShaders(GLenum primitive_mode) { current_texture_bindpoint = SetupTextures(static_cast(stage), shader, primitive_mode, current_texture_bindpoint); - SetupAlphaTesting(shader); - // When VertexA is enabled, we have dual vertex shaders if (program == Maxwell::ShaderProgram::VertexA) { // VertexB was combined with VertexA, so we skip the VertexB iteration @@ -882,19 +880,6 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader, return current_unit + static_cast(entries.size()); } -void RasterizerOpenGL::SetupAlphaTesting(Shader& shader) { - const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; - - u32 func = static_cast(regs.alpha_test_func); - // Normalize the gl variants of opCompare to be the same as the normal variants - u32 op = static_cast(Tegra::Engines::Maxwell3D::Regs::ComparisonOp::Never); - if (func >= op) { - func = func - op + 1U; - } - - shader->SetAlphaTesting(regs.alpha_test_enabled == 1, regs.alpha_test_ref, func); -} - void RasterizerOpenGL::SyncViewport() { const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; const MathUtil::Rectangle viewport_rect{regs.viewport_transform[0].GetRect()}; -- cgit v1.2.3 From 8e1239fbc59325f5a9898329af869ae575ec983f Mon Sep 17 00:00:00 2001 From: FernandoS27 Date: Thu, 11 Oct 2018 20:29:11 -0400 Subject: Assert that multiple render targets are not set while alpha testing --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/video_core/renderer_opengl/gl_rasterizer.cpp') diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index d93681813..be51c5215 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -574,6 +574,7 @@ void RasterizerOpenGL::DrawArrays() { // Alpha Testing is synced on shaders. SyncTransformFeedback(); SyncPointState(); + CheckAlphaTests(); // TODO(bunnei): Sync framebuffer_scale uniform here // TODO(bunnei): Sync scissorbox uniform(s) here @@ -1041,4 +1042,15 @@ void RasterizerOpenGL::SyncPointState() { state.point.size = regs.point_size == 0 ? 1 : regs.point_size; } +void RasterizerOpenGL::CheckAlphaTests() { + const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; + + if (regs.alpha_test_enabled != 0 && regs.rt_control.count > 1) { + LOG_CRITICAL( + Render_OpenGL, + "Alpha Testing is enabled with Multiple Render Targets, this behavior is undefined."); + UNREACHABLE(); + } +} + } // namespace OpenGL -- cgit v1.2.3