From 2f1514b90430ccb2d74b3fcaca435c692f159e5d Mon Sep 17 00:00:00 2001 From: aroulin Date: Fri, 21 Aug 2015 12:49:21 +0200 Subject: [PATCH] Shader: implement DPH/DPHI in JIT --- src/video_core/shader/shader_jit_x64.cpp | 37 ++++++++++++++++++++++-- src/video_core/shader/shader_jit_x64.h | 1 + 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/video_core/shader/shader_jit_x64.cpp b/src/video_core/shader/shader_jit_x64.cpp index a1bdd8456..366be3901 100644 --- a/src/video_core/shader/shader_jit_x64.cpp +++ b/src/video_core/shader/shader_jit_x64.cpp @@ -23,7 +23,7 @@ const JitFunction instr_table[64] = { &JitCompiler::Compile_ADD, // add &JitCompiler::Compile_DP3, // dp3 &JitCompiler::Compile_DP4, // dp4 - nullptr, // dph + &JitCompiler::Compile_DPH, // dph nullptr, // unknown &JitCompiler::Compile_EX2, // ex2 &JitCompiler::Compile_LG2, // lg2 @@ -44,7 +44,7 @@ const JitFunction instr_table[64] = { nullptr, // unknown nullptr, // unknown nullptr, // unknown - nullptr, // dphi + &JitCompiler::Compile_DPH, // dphi nullptr, // unknown &JitCompiler::Compile_SGE, // sgei &JitCompiler::Compile_SLT, // slti @@ -347,6 +347,39 @@ void JitCompiler::Compile_DP4(Instruction instr) { Compile_DestEnable(instr, SRC1); } +void JitCompiler::Compile_DPH(Instruction instr) { + if (instr.opcode.Value().EffectiveOpCode() == OpCode::Id::DPHI) { + Compile_SwizzleSrc(instr, 1, instr.common.src1i, SRC1); + Compile_SwizzleSrc(instr, 2, instr.common.src2i, SRC2); + } else { + Compile_SwizzleSrc(instr, 1, instr.common.src1, SRC1); + Compile_SwizzleSrc(instr, 2, instr.common.src2, SRC2); + } + + if (Common::GetCPUCaps().sse4_1) { + // Set 4th component to 1.0 + BLENDPS(SRC1, R(ONE), 0x8); // 0b1000 + DPPS(SRC1, R(SRC2), 0xff); + } else { + // Reverse to set the 4th component to 1.0 + SHUFPS(SRC1, R(SRC1), _MM_SHUFFLE(0, 1, 2, 3)); + MOVSS(SRC1, R(ONE)); + SHUFPS(SRC1, R(SRC1), _MM_SHUFFLE(0, 1, 2, 3)); + + MULPS(SRC1, R(SRC2)); + + MOVAPS(SRC2, R(SRC1)); + SHUFPS(SRC1, R(SRC1), _MM_SHUFFLE(2, 3, 0, 1)); // XYZW -> ZWXY + ADDPS(SRC1, R(SRC2)); + + MOVAPS(SRC2, R(SRC1)); + SHUFPS(SRC1, R(SRC1), _MM_SHUFFLE(0, 1, 2, 3)); // XYZW -> WZYX + ADDPS(SRC1, R(SRC2)); + } + + Compile_DestEnable(instr, SRC1); +} + void JitCompiler::Compile_EX2(Instruction instr) { Compile_SwizzleSrc(instr, 1, instr.common.src1, SRC1); MOVSS(XMM0, R(SRC1)); diff --git a/src/video_core/shader/shader_jit_x64.h b/src/video_core/shader/shader_jit_x64.h index b2aa5293c..fbe19fe93 100644 --- a/src/video_core/shader/shader_jit_x64.h +++ b/src/video_core/shader/shader_jit_x64.h @@ -37,6 +37,7 @@ public: void Compile_ADD(Instruction instr); void Compile_DP3(Instruction instr); void Compile_DP4(Instruction instr); + void Compile_DPH(Instruction instr); void Compile_EX2(Instruction instr); void Compile_LG2(Instruction instr); void Compile_MUL(Instruction instr);