shader_jit_x64.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <nihstro/shader_bytecode.h>
  6. #include "common/x64/emitter.h"
  7. #include "video_core/pica.h"
  8. #include "shader.h"
  9. using nihstro::Instruction;
  10. using nihstro::OpCode;
  11. using nihstro::SwizzlePattern;
  12. namespace Pica {
  13. namespace Shader {
  14. using CompiledShader = void(void* state);
  15. /**
  16. * This class implements the shader JIT compiler. It recompiles a Pica shader program into x86_64
  17. * code that can be executed on the host machine directly.
  18. */
  19. class JitCompiler : public Gen::XCodeBlock {
  20. public:
  21. JitCompiler();
  22. CompiledShader* Compile();
  23. void Clear();
  24. void Compile_ADD(Instruction instr);
  25. void Compile_DP3(Instruction instr);
  26. void Compile_DP4(Instruction instr);
  27. void Compile_MUL(Instruction instr);
  28. void Compile_FLR(Instruction instr);
  29. void Compile_MAX(Instruction instr);
  30. void Compile_MIN(Instruction instr);
  31. void Compile_RCP(Instruction instr);
  32. void Compile_RSQ(Instruction instr);
  33. void Compile_MOVA(Instruction instr);
  34. void Compile_MOV(Instruction instr);
  35. void Compile_SLTI(Instruction instr);
  36. void Compile_NOP(Instruction instr);
  37. void Compile_END(Instruction instr);
  38. void Compile_CALL(Instruction instr);
  39. void Compile_CALLC(Instruction instr);
  40. void Compile_CALLU(Instruction instr);
  41. void Compile_IF(Instruction instr);
  42. void Compile_LOOP(Instruction instr);
  43. void Compile_JMP(Instruction instr);
  44. void Compile_CMP(Instruction instr);
  45. void Compile_MAD(Instruction instr);
  46. private:
  47. void Compile_Block(unsigned stop);
  48. void Compile_NextInstr(unsigned* offset);
  49. void Compile_SwizzleSrc(Instruction instr, unsigned src_num, SourceRegister src_reg, Gen::X64Reg dest);
  50. void Compile_DestEnable(Instruction instr, Gen::X64Reg dest);
  51. void Compile_EvaluateCondition(Instruction instr);
  52. void Compile_UniformCondition(Instruction instr);
  53. /// Pointer to the variable that stores the current Pica code offset. Used to handle nested code blocks.
  54. unsigned* offset_ptr = nullptr;
  55. /// Set to true if currently in a loop, used to check for the existence of nested loops
  56. bool looping = false;
  57. };
  58. } // Shader
  59. } // Pica