From d27279092fd4d9b038e5b9132801eecea27a3248 Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 4 Jun 2018 19:14:23 -0500 Subject: GPU: Take into account predicated exits when performing shader control flow analysis. --- src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/video_core') diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 4cfd6f042..c802532db 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -115,7 +115,16 @@ private: if (const auto opcode = OpCode::Decode(instr)) { switch (opcode->GetId()) { case OpCode::Id::EXIT: { - return exit_method = ExitMethod::AlwaysEnd; + // The EXIT instruction can be predicated, which means that the shader can + // conditionally end on this instruction. We have to consider the case where the + // condition is not met and check the exit method of that other basic block. + using Tegra::Shader::Pred; + if (instr.pred.pred_index == static_cast(Pred::UnusedIndex)) { + return exit_method = ExitMethod::AlwaysEnd; + } else { + ExitMethod not_met = Scan(offset + 1, end, labels); + return exit_method = ParallelExit(ExitMethod::AlwaysEnd, not_met); + } } case OpCode::Id::BRA: { u32 target = offset + instr.bra.GetBranchTarget(); -- cgit v1.2.3 From 6cf6fa28427136dcb1d3897148898bf5ff2591dc Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 4 Jun 2018 19:18:11 -0500 Subject: GPU: Implement predicated exit instructions in the shader programs. --- src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/video_core') diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index c802532db..6391f1ad4 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -1093,9 +1093,6 @@ private: default: { switch (opcode->GetId()) { case OpCode::Id::EXIT: { - ASSERT_MSG(instr.pred.pred_index == static_cast(Pred::UnusedIndex), - "Predicated exits not implemented"); - // Final color output is currently hardcoded to GPR0-3 for fragment shaders if (stage == Maxwell3D::Regs::ShaderStage::Fragment) { shader.AddLine("color.r = " + regs.GetRegisterAsFloat(0) + ';'); @@ -1105,7 +1102,12 @@ private: } shader.AddLine("return true;"); - offset = PROGRAM_END - 1; + if (instr.pred.pred_index == static_cast(Pred::UnusedIndex)) { + // If this is an unconditional exit then just end processing here, otherwise we + // have to account for the possibility of the condition not being met, so + // continue processing the next instruction. + offset = PROGRAM_END - 1; + } break; } case OpCode::Id::KIL: { -- cgit v1.2.3