integer_set.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/common_types.h"
  5. #include "video_core/engines/shader_bytecode.h"
  6. #include "video_core/shader/node_helper.h"
  7. #include "video_core/shader/shader_ir.h"
  8. namespace VideoCommon::Shader {
  9. using Tegra::Shader::Instruction;
  10. using Tegra::Shader::OpCode;
  11. u32 ShaderIR::DecodeIntegerSet(NodeBlock& bb, u32 pc) {
  12. const Instruction instr = {program_code[pc]};
  13. const Node op_a = GetRegister(instr.gpr8);
  14. const Node op_b = [&]() {
  15. if (instr.is_b_imm) {
  16. return Immediate(instr.alu.GetSignedImm20_20());
  17. } else if (instr.is_b_gpr) {
  18. return GetRegister(instr.gpr20);
  19. } else {
  20. return GetConstBuffer(instr.cbuf34.index, instr.cbuf34.GetOffset());
  21. }
  22. }();
  23. // The iset instruction sets a register to 1.0 or -1 (depending on the bf bit) if the condition
  24. // is true, and to 0 otherwise.
  25. const Node second_pred = GetPredicate(instr.iset.pred39, instr.iset.neg_pred != 0);
  26. const Node first_pred =
  27. GetPredicateComparisonInteger(instr.iset.cond, instr.iset.is_signed, op_a, op_b);
  28. const OperationCode combiner = GetPredicateCombiner(instr.iset.op);
  29. const Node predicate = Operation(combiner, first_pred, second_pred);
  30. const Node true_value = instr.iset.bf ? Immediate(1.0f) : Immediate(-1);
  31. const Node false_value = instr.iset.bf ? Immediate(0.0f) : Immediate(0);
  32. const Node value =
  33. Operation(OperationCode::Select, PRECISE, predicate, true_value, false_value);
  34. SetRegister(bb, instr.gpr0, value);
  35. return pc;
  36. }
  37. } // namespace VideoCommon::Shader