bfe.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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/assert.h"
  5. #include "common/common_types.h"
  6. #include "video_core/engines/shader_bytecode.h"
  7. #include "video_core/shader/node_helper.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::DecodeBfe(NodeBlock& bb, u32 pc) {
  13. const Instruction instr = {program_code[pc]};
  14. const auto opcode = OpCode::Decode(instr);
  15. Node op_a = GetRegister(instr.gpr8);
  16. Node op_b = [&] {
  17. switch (opcode->get().GetId()) {
  18. case OpCode::Id::BFE_R:
  19. return GetRegister(instr.gpr20);
  20. case OpCode::Id::BFE_C:
  21. return GetConstBuffer(instr.cbuf34.index, instr.cbuf34.GetOffset());
  22. case OpCode::Id::BFE_IMM:
  23. return Immediate(instr.alu.GetSignedImm20_20());
  24. default:
  25. UNREACHABLE();
  26. return Immediate(0);
  27. }
  28. }();
  29. UNIMPLEMENTED_IF_MSG(instr.bfe.rd_cc, "Condition codes in BFE is not implemented");
  30. UNIMPLEMENTED_IF_MSG(instr.bfe.brev, "BREV in BFE is not implemented");
  31. const bool is_signed = instr.bfe.is_signed;
  32. const auto start_position = SignedOperation(OperationCode::IBitfieldExtract, is_signed, op_b,
  33. Immediate(0), Immediate(8));
  34. const auto bits = SignedOperation(OperationCode::IBitfieldExtract, is_signed, op_b,
  35. Immediate(8), Immediate(8));
  36. auto result =
  37. SignedOperation(OperationCode::IBitfieldExtract, is_signed, op_a, start_position, bits);
  38. SetRegister(bb, instr.gpr0, result);
  39. return pc;
  40. }
  41. } // namespace VideoCommon::Shader