From bd7e691f78d916ed6ae5396b2d646d9b3a053dd7 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 12 Aug 2015 00:00:44 -0400 Subject: x64: Refactor to remove fake interfaces and general cleanups. --- src/video_core/CMakeLists.txt | 10 ++-- src/video_core/shader/shader.cpp | 9 ++- src/video_core/shader/shader_jit.cpp | 36 ------------ src/video_core/shader/shader_jit.h | 85 ----------------------------- src/video_core/shader/shader_jit_fake.cpp | 91 ------------------------------- src/video_core/shader/shader_jit_x64.cpp | 20 +++++-- src/video_core/shader/shader_jit_x64.h | 79 +++++++++++++++++++++++++++ 7 files changed, 103 insertions(+), 227 deletions(-) delete mode 100644 src/video_core/shader/shader_jit.cpp delete mode 100644 src/video_core/shader/shader_jit.h delete mode 100644 src/video_core/shader/shader_jit_fake.cpp create mode 100644 src/video_core/shader/shader_jit_x64.h (limited to 'src/video_core') diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 544ed0297..221abc160 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -13,7 +13,6 @@ set(SRCS rasterizer.cpp shader/shader.cpp shader/shader_interpreter.cpp - shader/shader_jit.cpp utils.cpp video_core.cpp ) @@ -39,17 +38,16 @@ set(HEADERS renderer_base.h shader/shader.h shader/shader_interpreter.h - shader/shader_jit.h utils.h video_core.h ) -if(_M_X86_64) +if(ARCHITECTURE_X64) set(SRCS ${SRCS} shader/shader_jit_x64.cpp) -else() - set(SRCS ${SRCS} - shader/shader_jit_fake.cpp) + + set(HEADERS ${HEADERS} + shader/shader_jit_x64.h) endif() create_directory_groups(${SRCS} ${HEADERS}) diff --git a/src/video_core/shader/shader.cpp b/src/video_core/shader/shader.cpp index fa1f7cafe..f7459e2ad 100644 --- a/src/video_core/shader/shader.cpp +++ b/src/video_core/shader/shader.cpp @@ -15,7 +15,10 @@ #include "shader.h" #include "shader_interpreter.h" -#include "shader_jit.h" + +#ifdef ARCHITECTURE_X64 +#include "shader_jit_x64.h" +#endif // ARCHITECTURE_X64 namespace Pica { @@ -43,7 +46,7 @@ void Setup(UnitState& state) { jit_shader = jit.Compile(); shader_map.emplace(cache_key, jit_shader); } - } +#endif // ARCHITECTURE_X64 } void Shutdown() { @@ -92,7 +95,7 @@ OutputVertex Run(UnitState& state, const InputVertex& input, int num_attributes) RunInterpreter(state); #else RunInterpreter(state); -#endif +#endif // ARCHITECTURE_X64 #if PICA_DUMP_SHADERS DebugUtils::DumpShader(setup.program_code.data(), state.debug.max_offset, setup.swizzle_data.data(), diff --git a/src/video_core/shader/shader_jit.cpp b/src/video_core/shader/shader_jit.cpp deleted file mode 100644 index 69fb7f6be..000000000 --- a/src/video_core/shader/shader_jit.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2015 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include "video_core/pica.h" - -#include "shader.h" -#include "shader_jit.h" - -namespace Pica { - -namespace Shader { - -JitShader::JitShader() : jitted(nullptr) { -} - -void JitShader::DoJit(JitCompiler& jit) { - jitted = jit.Compile(); -} - -void JitShader::Run(UnitState& state) { - if (jitted) - jitted(&state); -} - -JitCompiler::JitCompiler() { - AllocCodeSpace(1024 * 1024 * 4); -} - -void JitCompiler::Clear() { - ClearCodeSpace(); -} - -} // namespace Shader - -} // namespace Pica diff --git a/src/video_core/shader/shader_jit.h b/src/video_core/shader/shader_jit.h deleted file mode 100644 index f05b64a92..000000000 --- a/src/video_core/shader/shader_jit.h +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2015 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include - -#if defined(_M_X86_64) -#include "common/x64_emitter.h" -#else -#include "common/fake_emitter.h" -#endif - -#include "video_core/pica.h" - -#include "shader.h" - -using nihstro::Instruction; -using nihstro::OpCode; -using nihstro::SwizzlePattern; - -namespace Pica { - -namespace Shader { - -using CompiledShader = void(void* state); - -/** - * 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. - */ -class JitCompiler : public Gen::XCodeBlock { -public: - JitCompiler(); - - CompiledShader* Compile(); - - void Clear(); - - void Compile_ADD(Instruction instr); - void Compile_DP3(Instruction instr); - void Compile_DP4(Instruction instr); - void Compile_MUL(Instruction instr); - void Compile_FLR(Instruction instr); - void Compile_MAX(Instruction instr); - void Compile_MIN(Instruction instr); - void Compile_RCP(Instruction instr); - void Compile_RSQ(Instruction instr); - void Compile_MOVA(Instruction instr); - void Compile_MOV(Instruction instr); - void Compile_SLTI(Instruction instr); - void Compile_NOP(Instruction instr); - void Compile_END(Instruction instr); - void Compile_CALL(Instruction instr); - void Compile_CALLC(Instruction instr); - void Compile_CALLU(Instruction instr); - void Compile_IF(Instruction instr); - void Compile_LOOP(Instruction instr); - void Compile_JMP(Instruction instr); - void Compile_CMP(Instruction instr); - void Compile_MAD(Instruction instr); - -private: - void Compile_Block(unsigned stop); - void Compile_NextInstr(unsigned* offset); - -#if defined(_M_X86_64) - void Compile_SwizzleSrc(Instruction instr, unsigned src_num, SourceRegister src_reg, Gen::X64Reg dest); - void Compile_DestEnable(Instruction instr, Gen::X64Reg dest); - - void Compile_EvaluateCondition(Instruction instr); - void Compile_UniformCondition(Instruction instr); -#endif - - /// Pointer to the variable that stores the current Pica code offset. Used to handle nested code blocks. - unsigned* offset_ptr = nullptr; - - bool done = false; - bool looping = false; -}; - -} // Shader - -} // Pica diff --git a/src/video_core/shader/shader_jit_fake.cpp b/src/video_core/shader/shader_jit_fake.cpp deleted file mode 100644 index e1e79b733..000000000 --- a/src/video_core/shader/shader_jit_fake.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2015 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include "common/fake_emitter.h" - -#include "video_core/shader/shader.h" -#include "video_core/shader/shader_jit.h" - -namespace Pica { - -namespace Shader { - -using namespace FakeGen; - -void Jit::Comp_ADD(Instruction instr) { -} - -void Jit::Comp_DP3(Instruction instr) { -} - -void Jit::Comp_DP4(Instruction instr) { -} - -void Jit::Comp_MUL(Instruction instr) { -} - -void Jit::Comp_FLR(Instruction instr) { -} - -void Jit::Comp_MAX(Instruction instr) { -} - -void Jit::Comp_MIN(Instruction instr) { -} - -void Jit::Comp_MOVA(Instruction instr) { -} - -void Jit::Comp_MOV(Instruction instr) { -} - -void Jit::Comp_SLTI(Instruction instr) { -} - -void Jit::Comp_RCP(Instruction instr) { -} - -void Jit::Comp_RSQ(Instruction instr) { -} - -void Jit::Comp_NOP(Instruction instr) { -} - -void Jit::Comp_END(Instruction instr) { -} - -void Jit::Comp_CALL(Instruction instr) { -} - -void Jit::Comp_CALLC(Instruction instr) { -} - -void Jit::Comp_CALLU(Instruction instr) { -} - -void Jit::Comp_CMP(Instruction instr) { -} - -void Jit::Comp_MAD(Instruction instr) { -} - -void Jit::Comp_IF(Instruction instr) { -} - -void Jit::Comp_LOOP(Instruction instr) { -} - -void Jit::Comp_JMP(Instruction instr) { -} - -void Jit::Comp_NextInstr(unsigned* offset) { -} - -CompiledShader Jit::Compile() { - return nullptr; -} - -} // namespace Shader - -} // namespace Pica diff --git a/src/video_core/shader/shader_jit_x64.cpp b/src/video_core/shader/shader_jit_x64.cpp index d69f3a549..1e20a06a7 100644 --- a/src/video_core/shader/shader_jit_x64.cpp +++ b/src/video_core/shader/shader_jit_x64.cpp @@ -4,12 +4,13 @@ #include -#include "common/abi.h" #include "common/cpu_detect.h" -#include "common/x64_emitter.h" + +#include "common/x64/abi.h" +#include "common/x64/emitter.h" #include "shader.h" -#include "shader_jit.h" +#include "shader_jit_x64.h" namespace Pica { @@ -134,7 +135,7 @@ static const u8 NO_DEST_REG_MASK = 0xf; */ void JitCompiler::Compile_SwizzleSrc(Instruction instr, unsigned src_num, SourceRegister src_reg, X64Reg dest) { X64Reg src_ptr; - std::size_t src_offset; + int src_offset; if (src_reg.GetRegisterType() == RegisterType::FloatUniform) { src_ptr = UNIFORMS; @@ -451,7 +452,6 @@ void JitCompiler::Compile_NOP(Instruction instr) { void JitCompiler::Compile_END(Instruction instr) { ABI_PopAllCalleeSavedRegsAndAdjustStack(); RET(); - done = true; } void JitCompiler::Compile_CALL(Instruction instr) { @@ -655,7 +655,7 @@ CompiledShader* JitCompiler::Compile() { MOVAPS(NEGBIT, MDisp(RAX, 0)); looping = false; - done = false; + while (offset < g_state.vs.program_code.size()) { Compile_NextInstr(&offset); } @@ -663,6 +663,14 @@ CompiledShader* JitCompiler::Compile() { return (CompiledShader*)start; } +JitCompiler::JitCompiler() { + AllocCodeSpace(1024 * 1024 * 4); +} + +void JitCompiler::Clear() { + ClearCodeSpace(); +} + } // namespace Shader } // namespace Pica diff --git a/src/video_core/shader/shader_jit_x64.h b/src/video_core/shader/shader_jit_x64.h new file mode 100644 index 000000000..719a24210 --- /dev/null +++ b/src/video_core/shader/shader_jit_x64.h @@ -0,0 +1,79 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include + +#include "common/x64/emitter.h" + +#include "video_core/pica.h" + +#include "shader.h" + +using nihstro::Instruction; +using nihstro::OpCode; +using nihstro::SwizzlePattern; + +namespace Pica { + +namespace Shader { + +using CompiledShader = void(void* state); + +/** + * 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. + */ +class JitCompiler : public Gen::XCodeBlock { +public: + JitCompiler(); + + CompiledShader* Compile(); + + void Clear(); + + void Compile_ADD(Instruction instr); + void Compile_DP3(Instruction instr); + void Compile_DP4(Instruction instr); + void Compile_MUL(Instruction instr); + void Compile_FLR(Instruction instr); + void Compile_MAX(Instruction instr); + void Compile_MIN(Instruction instr); + void Compile_RCP(Instruction instr); + void Compile_RSQ(Instruction instr); + void Compile_MOVA(Instruction instr); + void Compile_MOV(Instruction instr); + void Compile_SLTI(Instruction instr); + void Compile_NOP(Instruction instr); + void Compile_END(Instruction instr); + void Compile_CALL(Instruction instr); + void Compile_CALLC(Instruction instr); + void Compile_CALLU(Instruction instr); + void Compile_IF(Instruction instr); + void Compile_LOOP(Instruction instr); + void Compile_JMP(Instruction instr); + void Compile_CMP(Instruction instr); + void Compile_MAD(Instruction instr); + +private: + void Compile_Block(unsigned stop); + void Compile_NextInstr(unsigned* offset); + + void Compile_SwizzleSrc(Instruction instr, unsigned src_num, SourceRegister src_reg, Gen::X64Reg dest); + void Compile_DestEnable(Instruction instr, Gen::X64Reg dest); + + void Compile_EvaluateCondition(Instruction instr); + void Compile_UniformCondition(Instruction instr); + + /// Pointer to the variable that stores the current Pica code offset. Used to handle nested code blocks. + unsigned* offset_ptr = nullptr; + + /// Set to true if currently in a loop, used to check for the existence of nested loops + bool looping = false; +}; + +} // Shader + +} // Pica -- cgit v1.2.3