half_set.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <array>
  5. #include "common/assert.h"
  6. #include "common/common_types.h"
  7. #include "video_core/engines/shader_bytecode.h"
  8. #include "video_core/shader/shader_ir.h"
  9. namespace VideoCommon::Shader {
  10. using Tegra::Shader::Instruction;
  11. using Tegra::Shader::OpCode;
  12. u32 ShaderIR::DecodeHalfSet(BasicBlock& bb, const BasicBlock& code, u32 pc) {
  13. const Instruction instr = {program_code[pc]};
  14. const auto opcode = OpCode::Decode(instr);
  15. UNIMPLEMENTED_IF(instr.hset2.ftz != 0);
  16. // instr.hset2.type_a
  17. // instr.hset2.type_b
  18. Node op_a = GetRegister(instr.gpr8);
  19. Node op_b = [&]() {
  20. switch (opcode->get().GetId()) {
  21. case OpCode::Id::HSET2_R:
  22. return GetRegister(instr.gpr20);
  23. default:
  24. UNREACHABLE();
  25. return Immediate(0);
  26. }
  27. }();
  28. op_a = GetOperandAbsNegHalf(op_a, instr.hset2.abs_a, instr.hset2.negate_a);
  29. op_b = GetOperandAbsNegHalf(op_b, instr.hset2.abs_b, instr.hset2.negate_b);
  30. const Node second_pred = GetPredicate(instr.hset2.pred39, instr.hset2.neg_pred);
  31. MetaHalfArithmetic meta{false, {instr.hset2.type_a, instr.hset2.type_b}};
  32. const Node comparison_pair = GetPredicateComparisonHalf(instr.hset2.cond, meta, op_a, op_b);
  33. const OperationCode combiner = GetPredicateCombiner(instr.hset2.op);
  34. // HSET2 operates on each half float in the pack.
  35. std::array<Node, 2> values;
  36. for (u32 i = 0; i < 2; ++i) {
  37. const u32 raw_value = instr.hset2.bf ? 0x3c00 : 0xffff;
  38. const Node true_value = Immediate(raw_value << (i * 16));
  39. const Node false_value = Immediate(0);
  40. const Node comparison =
  41. Operation(OperationCode::LogicalPick2, comparison_pair, Immediate(i));
  42. const Node predicate = Operation(combiner, comparison, second_pred);
  43. values[i] =
  44. Operation(OperationCode::Select, NO_PRECISE, predicate, true_value, false_value);
  45. }
  46. const Node value = Operation(OperationCode::UBitwiseOr, NO_PRECISE, values[0], values[1]);
  47. SetRegister(bb, instr.gpr0, value);
  48. return pc;
  49. }
  50. } // namespace VideoCommon::Shader