From 3cc460ab34ac6f818b7269428c0dbd0522729648 Mon Sep 17 00:00:00 2001 From: wwylele Date: Tue, 17 Apr 2018 09:35:43 +0300 Subject: [PATCH] shader_jit: change passing ShaderSetup to passing uniforms struct into the program We are going to add private memebers to ShaderSetup, which forbids the usage of offsetof. The JIT program only use the uniform part of the setup, so we can just isolate it. --- src/video_core/shader/shader.h | 24 ++++++++++--------- .../shader/shader_jit_x64_compiler.cpp | 18 +++++++------- .../shader/shader_jit_x64_compiler.h | 2 +- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/video_core/shader/shader.h b/src/video_core/shader/shader.h index dc50727139..8b212100cd 100644 --- a/src/video_core/shader/shader.h +++ b/src/video_core/shader/shader.h @@ -173,27 +173,29 @@ struct GSUnitState : public UnitState { GSEmitter emitter; }; -struct ShaderSetup { - struct { - // The float uniforms are accessed by the shader JIT using SSE instructions, and are - // therefore required to be 16-byte aligned. - alignas(16) Math::Vec4 f[96]; +struct Uniforms { + // The float uniforms are accessed by the shader JIT using SSE instructions, and are + // therefore required to be 16-byte aligned. + alignas(16) Math::Vec4 f[96]; - std::array b; - std::array, 4> i; - } uniforms; + std::array b; + std::array, 4> i; static size_t GetFloatUniformOffset(unsigned index) { - return offsetof(ShaderSetup, uniforms.f) + index * sizeof(Math::Vec4); + return offsetof(Uniforms, f) + index * sizeof(Math::Vec4); } static size_t GetBoolUniformOffset(unsigned index) { - return offsetof(ShaderSetup, uniforms.b) + index * sizeof(bool); + return offsetof(Uniforms, b) + index * sizeof(bool); } static size_t GetIntUniformOffset(unsigned index) { - return offsetof(ShaderSetup, uniforms.i) + index * sizeof(Math::Vec4); + return offsetof(Uniforms, i) + index * sizeof(Math::Vec4); } +}; + +struct ShaderSetup { + Uniforms uniforms; std::array program_code; std::array swizzle_data; diff --git a/src/video_core/shader/shader_jit_x64_compiler.cpp b/src/video_core/shader/shader_jit_x64_compiler.cpp index f497990f13..06c6f52e5a 100644 --- a/src/video_core/shader/shader_jit_x64_compiler.cpp +++ b/src/video_core/shader/shader_jit_x64_compiler.cpp @@ -104,7 +104,7 @@ const JitFunction instr_table[64] = { // purposes, as documented below: /// Pointer to the uniform memory -static const Reg64 SETUP = r9; +static const Reg64 UNIFORMS = r9; /// The two 32-bit VS address offset registers set by the MOVA instruction static const Reg64 ADDROFFS_REG_0 = r10; static const Reg64 ADDROFFS_REG_1 = r11; @@ -139,7 +139,7 @@ static const Xmm NEGBIT = xmm15; // Scratch registers, e.g., SRC1 and SCRATCH, have to be saved on the side if needed static const BitSet32 persistent_regs = BuildRegSet({ // Pointers to register blocks - SETUP, + UNIFORMS, STATE, // Cached registers ADDROFFS_REG_0, @@ -184,8 +184,8 @@ void JitShader::Compile_SwizzleSrc(Instruction instr, unsigned src_num, SourceRe size_t src_offset; if (src_reg.GetRegisterType() == RegisterType::FloatUniform) { - src_ptr = SETUP; - src_offset = ShaderSetup::GetFloatUniformOffset(src_reg.GetIndex()); + src_ptr = UNIFORMS; + src_offset = Uniforms::GetFloatUniformOffset(src_reg.GetIndex()); } else { src_ptr = STATE; src_offset = UnitState::InputOffset(src_reg); @@ -354,8 +354,8 @@ void JitShader::Compile_EvaluateCondition(Instruction instr) { } void JitShader::Compile_UniformCondition(Instruction instr) { - size_t offset = ShaderSetup::GetBoolUniformOffset(instr.flow_control.bool_uniform_id); - cmp(byte[SETUP + offset], 0); + size_t offset = Uniforms::GetBoolUniformOffset(instr.flow_control.bool_uniform_id); + cmp(byte[UNIFORMS + offset], 0); } BitSet32 JitShader::PersistentCallerSavedRegs() { @@ -713,8 +713,8 @@ void JitShader::Compile_LOOP(Instruction instr) { // This decodes the fields from the integer uniform at index instr.flow_control.int_uniform_id. // The Y (LOOPCOUNT_REG) and Z (LOOPINC) component are kept multiplied by 16 (Left shifted by // 4 bits) to be used as an offset into the 16-byte vector registers later - size_t offset = ShaderSetup::GetIntUniformOffset(instr.flow_control.int_uniform_id); - mov(LOOPCOUNT, dword[SETUP + offset]); + size_t offset = Uniforms::GetIntUniformOffset(instr.flow_control.int_uniform_id); + mov(LOOPCOUNT, dword[UNIFORMS + offset]); mov(LOOPCOUNT_REG, LOOPCOUNT); shr(LOOPCOUNT_REG, 4); and_(LOOPCOUNT_REG, 0xFF0); // Y-component is the start @@ -882,7 +882,7 @@ void JitShader::Compile(const std::array* program_ ABI_PushRegistersAndAdjustStack(*this, ABI_ALL_CALLEE_SAVED, 8, 16); mov(qword[rsp + 8], 0xFFFFFFFFFFFFFFFFULL); - mov(SETUP, ABI_PARAM1); + mov(UNIFORMS, ABI_PARAM1); mov(STATE, ABI_PARAM2); // Zero address/loop registers diff --git a/src/video_core/shader/shader_jit_x64_compiler.h b/src/video_core/shader/shader_jit_x64_compiler.h index 93e65fe264..923c34f0d8 100644 --- a/src/video_core/shader/shader_jit_x64_compiler.h +++ b/src/video_core/shader/shader_jit_x64_compiler.h @@ -34,7 +34,7 @@ public: JitShader(); void Run(const ShaderSetup& setup, UnitState& state, unsigned offset) const { - program(&setup, &state, instruction_labels[offset].getAddress()); + program(&setup.uniforms, &state, instruction_labels[offset].getAddress()); } void Compile(const std::array* program_code,