summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2015-08-23 17:56:35 -0400
committerGravatar bunnei2015-08-23 17:56:35 -0400
commit83c214f6d8b1434503b6d8219bdac7064b8df2ca (patch)
tree8762cf0a0399b5fff978f098504dc9f918d2b4ee /src
parentMerge pull request #1057 from aroulin/shader-dph-dphi (diff)
parentShader: Use std::sqrt for float instead of sqrt (diff)
downloadyuzu-83c214f6d8b1434503b6d8219bdac7064b8df2ca.tar.gz
yuzu-83c214f6d8b1434503b6d8219bdac7064b8df2ca.tar.xz
yuzu-83c214f6d8b1434503b6d8219bdac7064b8df2ca.zip
Merge pull request #1062 from aroulin/shader-rcp-rsq
Shader: RCP and RSQ computes only the 1st component
Diffstat (limited to 'src')
-rw-r--r--src/common/x64/emitter.cpp1
-rw-r--r--src/common/x64/emitter.h1
-rw-r--r--src/video_core/shader/shader_interpreter.cpp10
-rw-r--r--src/video_core/shader/shader_jit_x64.cpp10
4 files changed, 12 insertions, 10 deletions
diff --git a/src/common/x64/emitter.cpp b/src/common/x64/emitter.cpp
index 749a75b72..939df210e 100644
--- a/src/common/x64/emitter.cpp
+++ b/src/common/x64/emitter.cpp
@@ -1535,6 +1535,7 @@ void XEmitter::MAXSS(X64Reg regOp, const OpArg& arg) {WriteSSEOp(0xF3, sseMAX,
1535void XEmitter::MAXSD(X64Reg regOp, const OpArg& arg) {WriteSSEOp(0xF2, sseMAX, regOp, arg);} 1535void XEmitter::MAXSD(X64Reg regOp, const OpArg& arg) {WriteSSEOp(0xF2, sseMAX, regOp, arg);}
1536void XEmitter::SQRTSS(X64Reg regOp, const OpArg& arg) {WriteSSEOp(0xF3, sseSQRT, regOp, arg);} 1536void XEmitter::SQRTSS(X64Reg regOp, const OpArg& arg) {WriteSSEOp(0xF3, sseSQRT, regOp, arg);}
1537void XEmitter::SQRTSD(X64Reg regOp, const OpArg& arg) {WriteSSEOp(0xF2, sseSQRT, regOp, arg);} 1537void XEmitter::SQRTSD(X64Reg regOp, const OpArg& arg) {WriteSSEOp(0xF2, sseSQRT, regOp, arg);}
1538void XEmitter::RCPSS(X64Reg regOp, const OpArg& arg) {WriteSSEOp(0xF3, sseRCP, regOp, arg);}
1538void XEmitter::RSQRTSS(X64Reg regOp, const OpArg& arg) {WriteSSEOp(0xF3, sseRSQRT, regOp, arg);} 1539void XEmitter::RSQRTSS(X64Reg regOp, const OpArg& arg) {WriteSSEOp(0xF3, sseRSQRT, regOp, arg);}
1539 1540
1540void XEmitter::ADDPS(X64Reg regOp, const OpArg& arg) {WriteSSEOp(0x00, sseADD, regOp, arg);} 1541void XEmitter::ADDPS(X64Reg regOp, const OpArg& arg) {WriteSSEOp(0x00, sseADD, regOp, arg);}
diff --git a/src/common/x64/emitter.h b/src/common/x64/emitter.h
index 3d6eeb564..a49cd2cf1 100644
--- a/src/common/x64/emitter.h
+++ b/src/common/x64/emitter.h
@@ -586,6 +586,7 @@ public:
586 void MAXSD(X64Reg regOp, const OpArg& arg); 586 void MAXSD(X64Reg regOp, const OpArg& arg);
587 void SQRTSS(X64Reg regOp, const OpArg& arg); 587 void SQRTSS(X64Reg regOp, const OpArg& arg);
588 void SQRTSD(X64Reg regOp, const OpArg& arg); 588 void SQRTSD(X64Reg regOp, const OpArg& arg);
589 void RCPSS(X64Reg regOp, const OpArg& arg);
589 void RSQRTSS(X64Reg regOp, const OpArg& arg); 590 void RSQRTSS(X64Reg regOp, const OpArg& arg);
590 591
591 // SSE/SSE2: Floating point bitwise (yes) 592 // SSE/SSE2: Floating point bitwise (yes)
diff --git a/src/video_core/shader/shader_interpreter.cpp b/src/video_core/shader/shader_interpreter.cpp
index 6b83d2c1c..ae5a30441 100644
--- a/src/video_core/shader/shader_interpreter.cpp
+++ b/src/video_core/shader/shader_interpreter.cpp
@@ -228,13 +228,12 @@ void RunInterpreter(UnitState<Debug>& state) {
228 { 228 {
229 Record<DebugDataRecord::SRC1>(state.debug, iteration, src1); 229 Record<DebugDataRecord::SRC1>(state.debug, iteration, src1);
230 Record<DebugDataRecord::DEST_IN>(state.debug, iteration, dest); 230 Record<DebugDataRecord::DEST_IN>(state.debug, iteration, dest);
231 float24 rcp_res = float24::FromFloat32(1.0f / src1[0].ToFloat32());
231 for (int i = 0; i < 4; ++i) { 232 for (int i = 0; i < 4; ++i) {
232 if (!swizzle.DestComponentEnabled(i)) 233 if (!swizzle.DestComponentEnabled(i))
233 continue; 234 continue;
234 235
235 // TODO: Be stable against division by zero! 236 dest[i] = rcp_res;
236 // TODO: I think this might be wrong... we should only use one component here
237 dest[i] = float24::FromFloat32(1.0f / src1[i].ToFloat32());
238 } 237 }
239 Record<DebugDataRecord::DEST_OUT>(state.debug, iteration, dest); 238 Record<DebugDataRecord::DEST_OUT>(state.debug, iteration, dest);
240 break; 239 break;
@@ -245,13 +244,12 @@ void RunInterpreter(UnitState<Debug>& state) {
245 { 244 {
246 Record<DebugDataRecord::SRC1>(state.debug, iteration, src1); 245 Record<DebugDataRecord::SRC1>(state.debug, iteration, src1);
247 Record<DebugDataRecord::DEST_IN>(state.debug, iteration, dest); 246 Record<DebugDataRecord::DEST_IN>(state.debug, iteration, dest);
247 float24 rsq_res = float24::FromFloat32(1.0f / std::sqrt(src1[0].ToFloat32()));
248 for (int i = 0; i < 4; ++i) { 248 for (int i = 0; i < 4; ++i) {
249 if (!swizzle.DestComponentEnabled(i)) 249 if (!swizzle.DestComponentEnabled(i))
250 continue; 250 continue;
251 251
252 // TODO: Be stable against division by zero! 252 dest[i] = rsq_res;
253 // TODO: I think this might be wrong... we should only use one component here
254 dest[i] = float24::FromFloat32(1.0f / sqrt(src1[i].ToFloat32()));
255 } 253 }
256 Record<DebugDataRecord::DEST_OUT>(state.debug, iteration, dest); 254 Record<DebugDataRecord::DEST_OUT>(state.debug, iteration, dest);
257 break; 255 break;
diff --git a/src/video_core/shader/shader_jit_x64.cpp b/src/video_core/shader/shader_jit_x64.cpp
index 366be3901..6865c64e3 100644
--- a/src/video_core/shader/shader_jit_x64.cpp
+++ b/src/video_core/shader/shader_jit_x64.cpp
@@ -529,9 +529,10 @@ void JitCompiler::Compile_MOV(Instruction instr) {
529void JitCompiler::Compile_RCP(Instruction instr) { 529void JitCompiler::Compile_RCP(Instruction instr) {
530 Compile_SwizzleSrc(instr, 1, instr.common.src1, SRC1); 530 Compile_SwizzleSrc(instr, 1, instr.common.src1, SRC1);
531 531
532 // TODO(bunnei): RCPPS is a pretty rough approximation, this might cause problems if Pica 532 // TODO(bunnei): RCPSS is a pretty rough approximation, this might cause problems if Pica
533 // performs this operation more accurately. This should be checked on hardware. 533 // performs this operation more accurately. This should be checked on hardware.
534 RCPPS(SRC1, R(SRC1)); 534 RCPSS(SRC1, R(SRC1));
535 SHUFPS(SRC1, R(SRC1), _MM_SHUFFLE(0, 0, 0, 0)); // XYWZ -> XXXX
535 536
536 Compile_DestEnable(instr, SRC1); 537 Compile_DestEnable(instr, SRC1);
537} 538}
@@ -539,9 +540,10 @@ void JitCompiler::Compile_RCP(Instruction instr) {
539void JitCompiler::Compile_RSQ(Instruction instr) { 540void JitCompiler::Compile_RSQ(Instruction instr) {
540 Compile_SwizzleSrc(instr, 1, instr.common.src1, SRC1); 541 Compile_SwizzleSrc(instr, 1, instr.common.src1, SRC1);
541 542
542 // TODO(bunnei): RSQRTPS is a pretty rough approximation, this might cause problems if Pica 543 // TODO(bunnei): RSQRTSS is a pretty rough approximation, this might cause problems if Pica
543 // performs this operation more accurately. This should be checked on hardware. 544 // performs this operation more accurately. This should be checked on hardware.
544 RSQRTPS(SRC1, R(SRC1)); 545 RSQRTSS(SRC1, R(SRC1));
546 SHUFPS(SRC1, R(SRC1), _MM_SHUFFLE(0, 0, 0, 0)); // XYWZ -> XXXX
545 547
546 Compile_DestEnable(instr, SRC1); 548 Compile_DestEnable(instr, SRC1);
547} 549}