diff options
author | Subv <subv2112@gmail.com> | 2018-04-20 16:09:50 +0200 |
---|---|---|
committer | Subv <subv2112@gmail.com> | 2018-04-21 04:09:33 +0200 |
commit | 0a5e01b710b66b9264ceb469903e8b8f16faf516 (patch) | |
tree | 27aafd787e4ab96dc9a4498016d94da9da03aa2e /src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |
parent | ShaderGen: Register id 255 is special and is hardcoded to return 0 (SR_ZERO). (diff) | |
download | yuzu-0a5e01b710b66b9264ceb469903e8b8f16faf516.tar yuzu-0a5e01b710b66b9264ceb469903e8b8f16faf516.tar.gz yuzu-0a5e01b710b66b9264ceb469903e8b8f16faf516.tar.bz2 yuzu-0a5e01b710b66b9264ceb469903e8b8f16faf516.tar.lz yuzu-0a5e01b710b66b9264ceb469903e8b8f16faf516.tar.xz yuzu-0a5e01b710b66b9264ceb469903e8b8f16faf516.tar.zst yuzu-0a5e01b710b66b9264ceb469903e8b8f16faf516.zip |
Diffstat (limited to 'src/video_core/renderer_opengl/gl_shader_decompiler.cpp')
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 6db0b7d39..2e0203a68 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -279,6 +279,21 @@ private: } /* + * Writes code that assigns a predicate boolean variable. + * @param pred The id of the predicate to write to. + * @param value The expression value to assign to the predicate. + */ + void SetPredicate(u64 pred, const std::string& value) { + using Tegra::Shader::Pred; + // Can't assign to the constant predicate. + ASSERT(pred != static_cast<u64>(Pred::UnusedIndex)); + + std::string variable = 'p' + std::to_string(pred); + shader.AddLine(variable + " = " + value + ';'); + declr_predicates.insert(std::move(variable)); + } + + /* * Returns whether the instruction at the specified offset is a 'sched' instruction. * Sched instructions always appear before a sequence of 3 instructions. */ @@ -468,7 +483,57 @@ private: } break; } + case OpCode::Type::FloatPredicate: { + std::string op_a = instr.fsetp.neg_a ? "-" : ""; + op_a += GetRegister(instr.gpr8); + + if (instr.fsetp.abs_a) { + op_a = "abs(" + op_a + ')'; + } + + std::string op_b{}; + + if (instr.is_b_imm) { + if (instr.fsetp.neg_b) { + // Only the immediate version of fsetp has a neg_b bit. + op_b += '-'; + } + op_b += '(' + GetImmediate19(instr) + ')'; + } else { + if (instr.is_b_gpr) { + op_b += GetRegister(instr.gpr20); + } else { + op_b += GetUniform(instr.uniform); + } + } + + if (instr.fsetp.abs_b) { + op_b = "abs(" + op_b + ')'; + } + using Tegra::Shader::Pred; + ASSERT_MSG(instr.fsetp.pred0 == static_cast<u64>(Pred::UnusedIndex) && + instr.fsetp.pred39 == static_cast<u64>(Pred::UnusedIndex), + "Compound predicates are not implemented"); + + // We can't use the constant predicate as destination. + ASSERT(instr.fsetp.pred3 != static_cast<u64>(Pred::UnusedIndex)); + + using Tegra::Shader::PredCondition; + switch (instr.fsetp.cond) { + case PredCondition::LessThan: + SetPredicate(instr.fsetp.pred3, '(' + op_a + ") < (" + op_b + ')'); + break; + case PredCondition::Equal: + SetPredicate(instr.fsetp.pred3, '(' + op_a + ") == (" + op_b + ')'); + break; + default: + NGLOG_CRITICAL(HW_GPU, "Unhandled predicate condition: {} (a: {}, b: {})", + static_cast<unsigned>(instr.fsetp.cond.Value()), op_a, op_b); + UNREACHABLE(); + } + break; + } default: { switch (instr.opcode.EffectiveOpCode()) { case OpCode::Id::EXIT: { @@ -623,6 +688,12 @@ private: declarations.AddNewLine(); ++const_buffer_layout; } + + declarations.AddNewLine(); + for (const auto& pred : declr_predicates) { + declarations.AddLine("bool " + pred + " = false;"); + } + declarations.AddNewLine(); } private: @@ -636,6 +707,7 @@ private: // Declarations std::set<std::string> declr_register; + std::set<std::string> declr_predicates; std::set<Attribute::Index> declr_input_attribute; std::set<Attribute::Index> declr_output_attribute; std::array<ConstBufferEntry, Maxwell3D::Regs::MaxConstBuffers> declr_const_buffers; |