From aac77bbd18f2b943b7259d8099241c4ec697b8f4 Mon Sep 17 00:00:00 2001 From: FernandoS27 Date: Sat, 8 Sep 2018 21:54:11 -0400 Subject: Implemented Control Codes --- src/video_core/engines/shader_bytecode.h | 36 ++++++++++++++++++++++ .../renderer_opengl/gl_shader_decompiler.cpp | 15 +++++++++ 2 files changed, 51 insertions(+) (limited to 'src/video_core') diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h index 6e555ea03..12229cf4c 100644 --- a/src/video_core/engines/shader_bytecode.h +++ b/src/video_core/engines/shader_bytecode.h @@ -240,6 +240,41 @@ enum class FlowCondition : u64 { Fcsm_Tr = 0x1C, // TODO(bunnei): What is this used for? }; +enum class ControlCode : u64 { + F = 0, + LT = 1, + EQ = 2, + LE = 3, + GT = 4, + NE = 5, + GE = 6, + Num = 7, + Nan = 8, + LTU = 9, + EQU = 10, + LEU = 11, + GTU = 12, + NEU = 13, + GEU = 14, + // + OFF = 16, + LO = 17, + SFF = 18, + LS = 19, + HI = 20, + SFT = 21, + HS = 22, + OFT = 23, + CSM_TA = 24, + CSM_TR = 25, + CSM_MX = 26, + FCSM_TA = 27, + FCSM_TR = 28, + FCSM_MX = 29, + RLE = 30, + RGT = 31, +}; + enum class PredicateResultMode : u64 { None = 0x0, NotZero = 0x3, @@ -735,6 +770,7 @@ union Instruction { BitField<36, 5, u64> index; } cbuf36; + BitField<47, 1, u64> generates_cc; BitField<61, 1, u64> is_b_imm; BitField<60, 1, u64> is_b_gpr; BitField<59, 1, u64> is_c_gpr; diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 252ff18fc..34f9e57d4 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -351,6 +351,15 @@ public: shader.AddLine(dest + " = " + src + ';'); } + std::string GetControlCode(const Tegra::Shader::ControlCode cc) { + u32 code = static_cast(cc); + return "controlCode_" + std::to_string(code); + } + + void SetControlCode(const Tegra::Shader::ControlCode cc, const std::string& value) { + shader.AddLine(GetControlCode(cc) + " = " + value + ';'); + } + /** * Writes code that does a output attribute assignment to register operation. Output attributes * are stored as floats, so this may require conversion. @@ -414,6 +423,12 @@ public: } declarations.AddNewLine(); + for (u32 cc = 0; cc < 32; cc++) { + Tegra::Shader::ControlCode code = static_cast(cc); + declarations.AddLine("bool " + GetControlCode(code) + " = false;"); + } + declarations.AddNewLine(); + for (const auto element : declr_input_attribute) { // TODO(bunnei): Use proper number of elements for these u32 idx = -- cgit v1.2.3 From e2ac8fb36d0f5540d87148226c4e93de1b6de5d3 Mon Sep 17 00:00:00 2001 From: FernandoS27 Date: Sat, 8 Sep 2018 22:44:20 -0400 Subject: Implemented CSETP --- src/video_core/engines/shader_bytecode.h | 11 +++++ .../renderer_opengl/gl_shader_decompiler.cpp | 52 ++++++++++++++++------ 2 files changed, 49 insertions(+), 14 deletions(-) (limited to 'src/video_core') diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h index 12229cf4c..3c5e9ea96 100644 --- a/src/video_core/engines/shader_bytecode.h +++ b/src/video_core/engines/shader_bytecode.h @@ -580,6 +580,15 @@ union Instruction { BitField<45, 2, PredOperation> op; } pset; + union { + BitField<0, 3, u64> pred0; + BitField<3, 3, u64> pred3; + BitField<8, 5, ControlCode> cc; // flag in cc + BitField<39, 3, u64> pred39; + BitField<42, 1, u64> neg_pred39; + BitField<45, 4, PredOperation> op; // op with pred39 + } csetp; + union { BitField<39, 3, u64> pred39; BitField<42, 1, u64> neg_pred; @@ -895,6 +904,7 @@ public: ISET_IMM, PSETP, PSET, + CSETP, XMAD_IMM, XMAD_CR, XMAD_RC, @@ -1131,6 +1141,7 @@ private: INST("0011011-0101----", Id::ISET_IMM, Type::IntegerSet, "ISET_IMM"), INST("0101000010001---", Id::PSET, Type::PredicateSetRegister, "PSET"), INST("0101000010010---", Id::PSETP, Type::PredicateSetPredicate, "PSETP"), + INST("010100001010----", Id::PSETP, Type::PredicateSetPredicate, "CSETP"), INST("0011011-00------", Id::XMAD_IMM, Type::Xmad, "XMAD_IMM"), INST("0100111---------", Id::XMAD_CR, Type::Xmad, "XMAD_CR"), INST("010100010-------", Id::XMAD_RC, Type::Xmad, "XMAD_RC"), diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 34f9e57d4..158eb2190 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -2267,13 +2267,15 @@ private: break; } case OpCode::Type::PredicateSetPredicate: { - const std::string op_a = - GetPredicateCondition(instr.psetp.pred12, instr.psetp.neg_pred12 != 0); - const std::string op_b = - GetPredicateCondition(instr.psetp.pred29, instr.psetp.neg_pred29 != 0); + switch (opcode->GetId()) { + case OpCode::Id::PSETP: { + const std::string op_a = + GetPredicateCondition(instr.psetp.pred12, instr.psetp.neg_pred12 != 0); + const std::string op_b = + GetPredicateCondition(instr.psetp.pred29, instr.psetp.neg_pred29 != 0); - // We can't use the constant predicate as destination. - ASSERT(instr.psetp.pred3 != static_cast(Pred::UnusedIndex)); + // We can't use the constant predicate as destination. + ASSERT(instr.psetp.pred3 != static_cast(Pred::UnusedIndex)); const std::string second_pred = GetPredicateCondition(instr.psetp.pred39, instr.psetp.neg_pred39 != 0); @@ -2283,15 +2285,37 @@ private: const std::string predicate = '(' + op_a + ") " + GetPredicateCombiner(instr.psetp.cond) + " (" + op_b + ')'; - // Set the primary predicate to the result of Predicate OP SecondPredicate - SetPredicate(instr.psetp.pred3, - '(' + predicate + ") " + combiner + " (" + second_pred + ')'); + // Set the primary predicate to the result of Predicate OP SecondPredicate + SetPredicate(instr.psetp.pred3, + '(' + predicate + ") " + combiner + " (" + second_pred + ')'); - if (instr.psetp.pred0 != static_cast(Pred::UnusedIndex)) { - // Set the secondary predicate to the result of !Predicate OP SecondPredicate, - // if enabled - SetPredicate(instr.psetp.pred0, - "!(" + predicate + ") " + combiner + " (" + second_pred + ')'); + if (instr.psetp.pred0 != static_cast(Pred::UnusedIndex)) { + // Set the secondary predicate to the result of !Predicate OP SecondPredicate, + // if enabled + SetPredicate(instr.psetp.pred0, + "!(" + predicate + ") " + combiner + " (" + second_pred + ')'); + } + break; + } + case OpCode::Id::CSETP: { + std::string pred = + GetPredicateCondition(instr.csetp.pred39, instr.csetp.neg_pred39 != 0); + std::string combiner = GetPredicateCombiner(instr.csetp.op); + std::string controlCode = regs.GetControlCode(instr.csetp.cc); + if (instr.csetp.pred3 != static_cast(Pred::UnusedIndex)) { + SetPredicate(instr.csetp.pred3, + '(' + controlCode + ") " + combiner + " (" + pred + ')'); + } + if (instr.csetp.pred0 != static_cast(Pred::UnusedIndex)) { + SetPredicate(instr.csetp.pred0, + "!(" + controlCode + ") " + combiner + " (" + pred + ')'); + } + break; + } + default: { + LOG_CRITICAL(HW_GPU, "Unhandled predicate instruction: {}", opcode->GetName()); + UNREACHABLE(); + } } break; } -- cgit v1.2.3 From e4bb759c4bfc6916a97c3358085a9394fad5e4dc Mon Sep 17 00:00:00 2001 From: FernandoS27 Date: Sun, 9 Sep 2018 00:46:19 -0400 Subject: Implemented I2I.CC on the NEU control code, used by SMO --- src/video_core/engines/shader_bytecode.h | 2 +- .../renderer_opengl/gl_shader_decompiler.cpp | 30 ++++++++++++---------- 2 files changed, 18 insertions(+), 14 deletions(-) (limited to 'src/video_core') diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h index 3c5e9ea96..b25168600 100644 --- a/src/video_core/engines/shader_bytecode.h +++ b/src/video_core/engines/shader_bytecode.h @@ -1141,7 +1141,7 @@ private: INST("0011011-0101----", Id::ISET_IMM, Type::IntegerSet, "ISET_IMM"), INST("0101000010001---", Id::PSET, Type::PredicateSetRegister, "PSET"), INST("0101000010010---", Id::PSETP, Type::PredicateSetPredicate, "PSETP"), - INST("010100001010----", Id::PSETP, Type::PredicateSetPredicate, "CSETP"), + INST("010100001010----", Id::CSETP, Type::PredicateSetPredicate, "CSETP"), INST("0011011-00------", Id::XMAD_IMM, Type::Xmad, "XMAD_IMM"), INST("0100111---------", Id::XMAD_CR, Type::Xmad, "XMAD_CR"), INST("010100010-------", Id::XMAD_RC, Type::Xmad, "XMAD_RC"), diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 158eb2190..2f1d6de3c 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -351,12 +351,12 @@ public: shader.AddLine(dest + " = " + src + ';'); } - std::string GetControlCode(const Tegra::Shader::ControlCode cc) { - u32 code = static_cast(cc); - return "controlCode_" + std::to_string(code); + std::string GetControlCode(const Tegra::Shader::ControlCode cc) const { + const u32 code = static_cast(cc); + return "controlCode_" + std::to_string(code) + suffix; } - void SetControlCode(const Tegra::Shader::ControlCode cc, const std::string& value) { + void SetControlCode(const Tegra::Shader::ControlCode cc, const std::string& value) const { shader.AddLine(GetControlCode(cc) + " = " + value + ';'); } @@ -424,7 +424,7 @@ public: declarations.AddNewLine(); for (u32 cc = 0; cc < 32; cc++) { - Tegra::Shader::ControlCode code = static_cast(cc); + const Tegra::Shader::ControlCode code = static_cast(cc); declarations.AddLine("bool " + GetControlCode(code) + " = false;"); } declarations.AddNewLine(); @@ -1656,6 +1656,10 @@ private: regs.SetRegisterToInteger(instr.gpr0, instr.conversion.is_output_signed, 0, op_a, 1, 1, instr.alu.saturate_d, 0, instr.conversion.dest_size); + if (instr.generates_cc.Value() != 0) { + const std::string neucondition = "( " + op_a + " != 0 )"; + regs.SetControlCode(Tegra::Shader::ControlCode::NEU, neucondition); + } break; } case OpCode::Id::I2F_R: @@ -2277,13 +2281,13 @@ private: // We can't use the constant predicate as destination. ASSERT(instr.psetp.pred3 != static_cast(Pred::UnusedIndex)); - const std::string second_pred = - GetPredicateCondition(instr.psetp.pred39, instr.psetp.neg_pred39 != 0); + const std::string second_pred = + GetPredicateCondition(instr.psetp.pred39, instr.psetp.neg_pred39 != 0); - const std::string combiner = GetPredicateCombiner(instr.psetp.op); + const std::string combiner = GetPredicateCombiner(instr.psetp.op); - const std::string predicate = - '(' + op_a + ") " + GetPredicateCombiner(instr.psetp.cond) + " (" + op_b + ')'; + const std::string predicate = + '(' + op_a + ") " + GetPredicateCombiner(instr.psetp.cond) + " (" + op_b + ')'; // Set the primary predicate to the result of Predicate OP SecondPredicate SetPredicate(instr.psetp.pred3, @@ -2298,10 +2302,10 @@ private: break; } case OpCode::Id::CSETP: { - std::string pred = + const std::string pred = GetPredicateCondition(instr.csetp.pred39, instr.csetp.neg_pred39 != 0); - std::string combiner = GetPredicateCombiner(instr.csetp.op); - std::string controlCode = regs.GetControlCode(instr.csetp.cc); + const std::string combiner = GetPredicateCombiner(instr.csetp.op); + const std::string controlCode = regs.GetControlCode(instr.csetp.cc); if (instr.csetp.pred3 != static_cast(Pred::UnusedIndex)) { SetPredicate(instr.csetp.pred3, '(' + controlCode + ") " + combiner + " (" + pred + ')'); -- cgit v1.2.3 From 567a5524b9b5d77153f580bf1b548430d368e2f2 Mon Sep 17 00:00:00 2001 From: FernandoS27 Date: Mon, 17 Sep 2018 18:16:06 -0400 Subject: Implemented Internal Flags --- .../renderer_opengl/gl_shader_decompiler.cpp | 48 ++++++++++++++++------ 1 file changed, 35 insertions(+), 13 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 2f1d6de3c..f5425c31e 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -235,6 +235,14 @@ private: const std::string& suffix; }; +enum class InternalFlag : u64 { + ZeroFlag = 0, + CarryFlag = 1, + OverflowFlag = 2, + NaNFlag = 3, + Amount +}; + /** * Used to manage shader registers that are emulated with GLSL. This class keeps track of the state * of all registers (e.g. whether they are currently being used as Floats or Integers), and @@ -328,13 +336,19 @@ public: void SetRegisterToInteger(const Register& reg, bool is_signed, u64 elem, const std::string& value, u64 dest_num_components, u64 value_num_components, bool is_saturated = false, - u64 dest_elem = 0, Register::Size size = Register::Size::Word) { + u64 dest_elem = 0, Register::Size size = Register::Size::Word, + bool sets_cc = false) { ASSERT_MSG(!is_saturated, "Unimplemented"); const std::string func{is_signed ? "intBitsToFloat" : "uintBitsToFloat"}; SetRegister(reg, elem, func + '(' + ConvertIntegerSize(value, size) + ')', dest_num_components, value_num_components, dest_elem); + + if (sets_cc) { + const std::string zero_condition = "( " + ConvertIntegerSize(value, size) + " == 0 )"; + SetInternalFlag(InternalFlag::ZeroFlag, zero_condition); + } } /** @@ -352,12 +366,23 @@ public: } std::string GetControlCode(const Tegra::Shader::ControlCode cc) const { - const u32 code = static_cast(cc); - return "controlCode_" + std::to_string(code) + suffix; + switch (cc) { + case Tegra::Shader::ControlCode::NEU: + return "!(" + GetInternalFlag(InternalFlag::ZeroFlag) + ')'; + default: + LOG_CRITICAL(HW_GPU, "Unimplemented Control Code {}", static_cast(cc)); + UNREACHABLE(); + return "false"; + } } - void SetControlCode(const Tegra::Shader::ControlCode cc, const std::string& value) const { - shader.AddLine(GetControlCode(cc) + " = " + value + ';'); + std::string GetInternalFlag(const InternalFlag ii) const { + const u32 code = static_cast(ii); + return "internalFlag_" + std::to_string(code) + suffix; + } + + void SetInternalFlag(const InternalFlag ii, const std::string& value) const { + shader.AddLine(GetInternalFlag(ii) + " = " + value + ';'); } /** @@ -423,9 +448,9 @@ public: } declarations.AddNewLine(); - for (u32 cc = 0; cc < 32; cc++) { - const Tegra::Shader::ControlCode code = static_cast(cc); - declarations.AddLine("bool " + GetControlCode(code) + " = false;"); + for (u32 ii = 0; ii < static_cast(InternalFlag::Amount); ii++) { + const InternalFlag code = static_cast(ii); + declarations.AddLine("bool " + GetInternalFlag(code) + " = false;"); } declarations.AddNewLine(); @@ -1655,11 +1680,8 @@ private: } regs.SetRegisterToInteger(instr.gpr0, instr.conversion.is_output_signed, 0, op_a, 1, - 1, instr.alu.saturate_d, 0, instr.conversion.dest_size); - if (instr.generates_cc.Value() != 0) { - const std::string neucondition = "( " + op_a + " != 0 )"; - regs.SetControlCode(Tegra::Shader::ControlCode::NEU, neucondition); - } + 1, instr.alu.saturate_d, 0, instr.conversion.dest_size, + instr.generates_cc.Value() != 0); break; } case OpCode::Id::I2F_R: -- cgit v1.2.3