ffma.cpp 2.2 KB

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