VERY experimental Nintendo Switch 2 emulator
C++
Shader: implement DPH/DPHI in JIT
aroulinfd789c6858f8
diff --git a/src/video_core/shader/shader_jit_x64.cpp b/src/video_core/shader/shader_jit_x64.cppindex a1bdd8456e..366be3901c 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, // dphnullptr, // unknown&JitCompiler::Compile_EX2, // ex2&JitCompiler::Compile_LG2, // lg2@@ -44,7 +44,7 @@ const JitFunction instr_table[64] = {nullptr, // unknownnullptr, // unknownnullptr, // unknown- nullptr, // dphi+ &JitCompiler::Compile_DPH, // dphinullptr, // 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.hindex b2aa5293c1..fbe19fe933 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);