VERY experimental Nintendo Switch 2 emulator
C++
shader_jit_x64: Specify shader main offset at runtime.
bunnei885208150df8
diff --git a/src/video_core/shader/shader.cpp b/src/video_core/shader/shader.cppindex e17368a4ae..b354134882 100644--- a/src/video_core/shader/shader.cpp+++ b/src/video_core/shader/shader.cpp@@ -36,8 +36,7 @@ void Setup(UnitState<false>& state) {#ifdef ARCHITECTURE_x86_64if (VideoCore::g_shader_jit_enabled) {u64 cache_key = (Common::ComputeHash64(&g_state.vs.program_code, sizeof(g_state.vs.program_code)) ^- Common::ComputeHash64(&g_state.vs.swizzle_data, sizeof(g_state.vs.swizzle_data)) ^- g_state.regs.vs.main_offset);+ Common::ComputeHash64(&g_state.vs.swizzle_data, sizeof(g_state.vs.swizzle_data)));auto iter = shader_map.find(cache_key);if (iter != shader_map.end()) {@@ -98,7 +97,7 @@ OutputVertex Run(UnitState<false>& state, const InputVertex& input, int num_attr#ifdef ARCHITECTURE_x86_64if (VideoCore::g_shader_jit_enabled)- jit_shader->Run(&state.registers);+ jit_shader->Run(&state.registers, g_state.regs.vs.main_offset);elseRunInterpreter(state);#elsediff --git a/src/video_core/shader/shader_jit_x64.cpp b/src/video_core/shader/shader_jit_x64.cppindex 3da4e51fa6..cbdc1e40fd 100644--- a/src/video_core/shader/shader_jit_x64.cpp+++ b/src/video_core/shader/shader_jit_x64.cpp@@ -838,9 +838,7 @@ void JitCompiler::Compile() {fixup_branches.clear();// Jump to start of the shader program- if (g_state.regs.vs.main_offset != 0) {- fixup_branches.push_back({ J(true), g_state.regs.vs.main_offset });- }+ JMPptr(R(ABI_PARAM2));// Compile entire programCompile_Block(static_cast<unsigned>(g_state.vs.program_code.size()));diff --git a/src/video_core/shader/shader_jit_x64.h b/src/video_core/shader/shader_jit_x64.hindex 19f9bdb563..1501d13bf9 100644--- a/src/video_core/shader/shader_jit_x64.h+++ b/src/video_core/shader/shader_jit_x64.h@@ -25,8 +25,6 @@ namespace Shader {/// Memory allocated for each compiled shader (64Kb)constexpr size_t MAX_SHADER_SIZE = 1024 * 64;-using CompiledShader = void(void* registers);-/*** This class implements the shader JIT compiler. It recompiles a Pica shader program into x86_64* code that can be executed on the host machine directly.@@ -35,8 +33,8 @@ class JitCompiler : public Gen::XCodeBlock {public:JitCompiler();- void Run(void* registers) const {- program(registers);+ void Run(void* registers, unsigned offset) const {+ program(registers, code_ptr[offset]);}void Compile();@@ -111,6 +109,7 @@ private:/// Branches that need to be fixed up once the entire shader program is compiledstd::vector<std::pair<Gen::FixupBranch, unsigned>> fixup_branches;+ using CompiledShader = void(void* registers, const u8* start_addr);CompiledShader* program = nullptr;};