ffma.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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::DecodeFfma(NodeBlock& bb, u32 pc) {
  13. const Instruction instr = {program_code[pc]};
  14. const auto opcode = OpCode::Decode(instr);
  15. UNIMPLEMENTED_IF_MSG(instr.ffma.cc != 0, "FFMA cc not implemented");
  16. DEBUG_ASSERT_MSG(instr.ffma.tab5980_0 == 1, "FFMA tab5980_0({}) not implemented",
  17. instr.ffma.tab5980_0.Value()); // Seems to be 1 by default based on SMO
  18. DEBUG_ASSERT_MSG(instr.ffma.tab5980_1 == 0, "FFMA tab5980_1({}) not implemented",
  19. instr.ffma.tab5980_1.Value());
  20. const Node op_a = GetRegister(instr.gpr8);
  21. auto [op_b, op_c] = [&]() -> std::tuple<Node, Node> {
  22. switch (opcode->get().GetId()) {
  23. case OpCode::Id::FFMA_CR: {
  24. return {GetConstBuffer(instr.cbuf34.index, instr.cbuf34.GetOffset()),
  25. GetRegister(instr.gpr39)};
  26. }
  27. case OpCode::Id::FFMA_RR:
  28. return {GetRegister(instr.gpr20), GetRegister(instr.gpr39)};
  29. case OpCode::Id::FFMA_RC: {
  30. return {GetRegister(instr.gpr39),
  31. GetConstBuffer(instr.cbuf34.index, instr.cbuf34.GetOffset())};
  32. }
  33. case OpCode::Id::FFMA_IMM:
  34. return {GetImmediate19(instr), GetRegister(instr.gpr39)};
  35. default:
  36. UNIMPLEMENTED_MSG("Unhandled FFMA instruction: {}", opcode->get().GetName());
  37. return {Immediate(0), Immediate(0)};
  38. }
  39. }();
  40. op_b = GetOperandAbsNegFloat(op_b, false, instr.ffma.negate_b);
  41. op_c = GetOperandAbsNegFloat(op_c, false, instr.ffma.negate_c);
  42. Node value = Operation(OperationCode::FFma, PRECISE, op_a, op_b, op_c);
  43. value = GetSaturatedFloat(value, instr.alu.saturate_d);
  44. SetInternalFlagsFromFloat(bb, value, instr.generates_cc);
  45. SetRegister(bb, instr.gpr0, value);
  46. return pc;
  47. }
  48. } // namespace VideoCommon::Shader