diff options
| -rw-r--r-- | src/video_core/macro/macro_jit_x64.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/video_core/macro/macro_jit_x64.cpp b/src/video_core/macro/macro_jit_x64.cpp index dc2b490d4..dc5376501 100644 --- a/src/video_core/macro/macro_jit_x64.cpp +++ b/src/video_core/macro/macro_jit_x64.cpp | |||
| @@ -23,7 +23,8 @@ MICROPROFILE_DEFINE(MacroJitExecute, "GPU", "Execute macro JIT", MP_RGB(255, 255 | |||
| 23 | namespace Tegra { | 23 | namespace Tegra { |
| 24 | namespace { | 24 | namespace { |
| 25 | constexpr Xbyak::Reg64 STATE = Xbyak::util::rbx; | 25 | constexpr Xbyak::Reg64 STATE = Xbyak::util::rbx; |
| 26 | constexpr Xbyak::Reg32 RESULT = Xbyak::util::ebp; | 26 | constexpr Xbyak::Reg32 RESULT = Xbyak::util::r10d; |
| 27 | constexpr Xbyak::Reg64 MAX_PARAMETER = Xbyak::util::r11; | ||
| 27 | constexpr Xbyak::Reg64 PARAMETERS = Xbyak::util::r12; | 28 | constexpr Xbyak::Reg64 PARAMETERS = Xbyak::util::r12; |
| 28 | constexpr Xbyak::Reg32 METHOD_ADDRESS = Xbyak::util::r14d; | 29 | constexpr Xbyak::Reg32 METHOD_ADDRESS = Xbyak::util::r14d; |
| 29 | constexpr Xbyak::Reg64 BRANCH_HOLDER = Xbyak::util::r15; | 30 | constexpr Xbyak::Reg64 BRANCH_HOLDER = Xbyak::util::r15; |
| @@ -31,6 +32,7 @@ constexpr Xbyak::Reg64 BRANCH_HOLDER = Xbyak::util::r15; | |||
| 31 | constexpr std::bitset<32> PERSISTENT_REGISTERS = Common::X64::BuildRegSet({ | 32 | constexpr std::bitset<32> PERSISTENT_REGISTERS = Common::X64::BuildRegSet({ |
| 32 | STATE, | 33 | STATE, |
| 33 | RESULT, | 34 | RESULT, |
| 35 | MAX_PARAMETER, | ||
| 34 | PARAMETERS, | 36 | PARAMETERS, |
| 35 | METHOD_ADDRESS, | 37 | METHOD_ADDRESS, |
| 36 | BRANCH_HOLDER, | 38 | BRANCH_HOLDER, |
| @@ -80,7 +82,7 @@ private: | |||
| 80 | u32 carry_flag{}; | 82 | u32 carry_flag{}; |
| 81 | }; | 83 | }; |
| 82 | static_assert(offsetof(JITState, maxwell3d) == 0, "Maxwell3D is not at 0x0"); | 84 | static_assert(offsetof(JITState, maxwell3d) == 0, "Maxwell3D is not at 0x0"); |
| 83 | using ProgramType = void (*)(JITState*, const u32*); | 85 | using ProgramType = void (*)(JITState*, const u32*, const u32*); |
| 84 | 86 | ||
| 85 | struct OptimizerState { | 87 | struct OptimizerState { |
| 86 | bool can_skip_carry{}; | 88 | bool can_skip_carry{}; |
| @@ -112,7 +114,7 @@ void MacroJITx64Impl::Execute(const std::vector<u32>& parameters, u32 method) { | |||
| 112 | JITState state{}; | 114 | JITState state{}; |
| 113 | state.maxwell3d = &maxwell3d; | 115 | state.maxwell3d = &maxwell3d; |
| 114 | state.registers = {}; | 116 | state.registers = {}; |
| 115 | program(&state, parameters.data()); | 117 | program(&state, parameters.data(), parameters.data() + parameters.size()); |
| 116 | } | 118 | } |
| 117 | 119 | ||
| 118 | void MacroJITx64Impl::Compile_ALU(Macro::Opcode opcode) { | 120 | void MacroJITx64Impl::Compile_ALU(Macro::Opcode opcode) { |
| @@ -488,6 +490,7 @@ void MacroJITx64Impl::Compile() { | |||
| 488 | // JIT state | 490 | // JIT state |
| 489 | mov(STATE, Common::X64::ABI_PARAM1); | 491 | mov(STATE, Common::X64::ABI_PARAM1); |
| 490 | mov(PARAMETERS, Common::X64::ABI_PARAM2); | 492 | mov(PARAMETERS, Common::X64::ABI_PARAM2); |
| 493 | mov(MAX_PARAMETER, Common::X64::ABI_PARAM3); | ||
| 491 | xor_(RESULT, RESULT); | 494 | xor_(RESULT, RESULT); |
| 492 | xor_(METHOD_ADDRESS, METHOD_ADDRESS); | 495 | xor_(METHOD_ADDRESS, METHOD_ADDRESS); |
| 493 | xor_(BRANCH_HOLDER, BRANCH_HOLDER); | 496 | xor_(BRANCH_HOLDER, BRANCH_HOLDER); |
| @@ -598,7 +601,22 @@ bool MacroJITx64Impl::Compile_NextInstruction() { | |||
| 598 | return true; | 601 | return true; |
| 599 | } | 602 | } |
| 600 | 603 | ||
| 604 | static void WarnInvalidParameter(uintptr_t parameter, uintptr_t max_parameter) { | ||
| 605 | LOG_CRITICAL(HW_GPU, | ||
| 606 | "Macro JIT: invalid parameter access 0x{:x} (0x{:x} is the last parameter)", | ||
| 607 | parameter, max_parameter - sizeof(u32)); | ||
| 608 | } | ||
| 609 | |||
| 601 | Xbyak::Reg32 MacroJITx64Impl::Compile_FetchParameter() { | 610 | Xbyak::Reg32 MacroJITx64Impl::Compile_FetchParameter() { |
| 611 | Xbyak::Label parameter_ok{}; | ||
| 612 | cmp(PARAMETERS, MAX_PARAMETER); | ||
| 613 | jb(parameter_ok, T_NEAR); | ||
| 614 | Common::X64::ABI_PushRegistersAndAdjustStack(*this, PersistentCallerSavedRegs(), 0); | ||
| 615 | mov(Common::X64::ABI_PARAM1, PARAMETERS); | ||
| 616 | mov(Common::X64::ABI_PARAM2, MAX_PARAMETER); | ||
| 617 | Common::X64::CallFarFunction(*this, &WarnInvalidParameter); | ||
| 618 | Common::X64::ABI_PopRegistersAndAdjustStack(*this, PersistentCallerSavedRegs(), 0); | ||
| 619 | L(parameter_ok); | ||
| 602 | mov(eax, dword[PARAMETERS]); | 620 | mov(eax, dword[PARAMETERS]); |
| 603 | add(PARAMETERS, sizeof(u32)); | 621 | add(PARAMETERS, sizeof(u32)); |
| 604 | return eax; | 622 | return eax; |