summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2019-11-02 23:44:46 -0300
committerGravatar ReinUsesLisp2019-11-07 20:08:41 -0300
commit56e237d1f998a4090afb6763222cd65593b299d7 (patch)
treeb40d10b0b12b210e5b9ddf28324267bf210f9fd7 /src
parentgl_shader_decompiler: Reimplement shuffles with platform agnostic intrinsics (diff)
downloadyuzu-56e237d1f998a4090afb6763222cd65593b299d7.tar.gz
yuzu-56e237d1f998a4090afb6763222cd65593b299d7.tar.xz
yuzu-56e237d1f998a4090afb6763222cd65593b299d7.zip
shader_ir/warp: Implement FSWZADD
Diffstat (limited to 'src')
-rw-r--r--src/video_core/engines/shader_bytecode.h10
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp18
-rw-r--r--src/video_core/renderer_vulkan/vk_shader_decompiler.cpp6
-rw-r--r--src/video_core/shader/decode/warp.cpp9
-rw-r--r--src/video_core/shader/node.h1
5 files changed, 44 insertions, 0 deletions
diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h
index 8f6bc76eb..312617f71 100644
--- a/src/video_core/engines/shader_bytecode.h
+++ b/src/video_core/engines/shader_bytecode.h
@@ -616,6 +616,14 @@ union Instruction {
616 } shfl; 616 } shfl;
617 617
618 union { 618 union {
619 BitField<44, 1, u64> ftz;
620 BitField<39, 2, u64> tab5cb8_2;
621 BitField<38, 1, u64> ndv;
622 BitField<47, 1, u64> cc;
623 BitField<28, 8, u64> swizzle;
624 } fswzadd;
625
626 union {
619 BitField<8, 8, Register> gpr; 627 BitField<8, 8, Register> gpr;
620 BitField<20, 24, s64> offset; 628 BitField<20, 24, s64> offset;
621 } gmem; 629 } gmem;
@@ -1590,6 +1598,7 @@ public:
1590 DEPBAR, 1598 DEPBAR,
1591 VOTE, 1599 VOTE,
1592 SHFL, 1600 SHFL,
1601 FSWZADD,
1593 BFE_C, 1602 BFE_C,
1594 BFE_R, 1603 BFE_R,
1595 BFE_IMM, 1604 BFE_IMM,
@@ -1888,6 +1897,7 @@ private:
1888 INST("1111000011110---", Id::DEPBAR, Type::Synch, "DEPBAR"), 1897 INST("1111000011110---", Id::DEPBAR, Type::Synch, "DEPBAR"),
1889 INST("0101000011011---", Id::VOTE, Type::Warp, "VOTE"), 1898 INST("0101000011011---", Id::VOTE, Type::Warp, "VOTE"),
1890 INST("1110111100010---", Id::SHFL, Type::Warp, "SHFL"), 1899 INST("1110111100010---", Id::SHFL, Type::Warp, "SHFL"),
1900 INST("0101000011111---", Id::FSWZADD, Type::Warp, "FSWZADD"),
1891 INST("1110111111011---", Id::LD_A, Type::Memory, "LD_A"), 1901 INST("1110111111011---", Id::LD_A, Type::Memory, "LD_A"),
1892 INST("1110111101001---", Id::LD_S, Type::Memory, "LD_S"), 1902 INST("1110111101001---", Id::LD_S, Type::Memory, "LD_S"),
1893 INST("1110111101000---", Id::LD_L, Type::Memory, "LD_L"), 1903 INST("1110111101000---", Id::LD_L, Type::Memory, "LD_L"),
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index ca4e6e468..21c137ec5 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -1379,6 +1379,20 @@ private:
1379 return GenerateUnary(operation, "float", Type::Float, type); 1379 return GenerateUnary(operation, "float", Type::Float, type);
1380 } 1380 }
1381 1381
1382 Expression FSwizzleAdd(Operation operation) {
1383 const std::string op_a = VisitOperand(operation, 0).AsFloat();
1384 const std::string op_b = VisitOperand(operation, 1).AsFloat();
1385 const std::string instr_mask = VisitOperand(operation, 2).AsUint();
1386
1387 const std::string mask = code.GenerateTemporary();
1388 code.AddLine("uint {} = {} >> ((gl_SubGroupInvocationARB & 3) << 1);", mask, instr_mask);
1389
1390 const std::string modifier_a = fmt::format("fswzadd_modifiers_a[{} & 3]", mask);
1391 const std::string modifier_b = fmt::format("fswzadd_modifiers_b[{} & 3]", mask);
1392 return {fmt::format("(({} * {}) + ({} * {}))", op_a, modifier_a, op_b, modifier_b),
1393 Type::Float};
1394 }
1395
1382 Expression ICastFloat(Operation operation) { 1396 Expression ICastFloat(Operation operation) {
1383 return GenerateUnary(operation, "int", Type::Int, Type::Float); 1397 return GenerateUnary(operation, "int", Type::Int, Type::Float);
1384 } 1398 }
@@ -1991,6 +2005,7 @@ private:
1991 &GLSLDecompiler::FTrunc, 2005 &GLSLDecompiler::FTrunc,
1992 &GLSLDecompiler::FCastInteger<Type::Int>, 2006 &GLSLDecompiler::FCastInteger<Type::Int>,
1993 &GLSLDecompiler::FCastInteger<Type::Uint>, 2007 &GLSLDecompiler::FCastInteger<Type::Uint>,
2008 &GLSLDecompiler::FSwizzleAdd,
1994 2009
1995 &GLSLDecompiler::Add<Type::Int>, 2010 &GLSLDecompiler::Add<Type::Int>,
1996 &GLSLDecompiler::Mul<Type::Int>, 2011 &GLSLDecompiler::Mul<Type::Int>,
@@ -2460,6 +2475,9 @@ bvec2 HalfFloatNanComparison(bvec2 comparison, vec2 pair1, vec2 pair2) {
2460 bvec2 is_nan2 = isnan(pair2); 2475 bvec2 is_nan2 = isnan(pair2);
2461 return bvec2(comparison.x || is_nan1.x || is_nan2.x, comparison.y || is_nan1.y || is_nan2.y); 2476 return bvec2(comparison.x || is_nan1.x || is_nan2.x, comparison.y || is_nan1.y || is_nan2.y);
2462} 2477}
2478
2479const float fswzadd_modifiers_a[] = float[4](-1.0f, 1.0f, -1.0f, 0.0f );
2480const float fswzadd_modifiers_b[] = float[4](-1.0f, -1.0f, 1.0f, -1.0f );
2463)"; 2481)";
2464} 2482}
2465 2483
diff --git a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
index 383720ea1..2850d5b59 100644
--- a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
+++ b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
@@ -783,6 +783,11 @@ private:
783 return {}; 783 return {};
784 } 784 }
785 785
786 Id FSwizzleAdd(Operation operation) {
787 UNIMPLEMENTED();
788 return {};
789 }
790
786 Id HNegate(Operation operation) { 791 Id HNegate(Operation operation) {
787 UNIMPLEMENTED(); 792 UNIMPLEMENTED();
788 return {}; 793 return {};
@@ -1363,6 +1368,7 @@ private:
1363 &SPIRVDecompiler::Unary<&Module::OpTrunc, Type::Float>, 1368 &SPIRVDecompiler::Unary<&Module::OpTrunc, Type::Float>,
1364 &SPIRVDecompiler::Unary<&Module::OpConvertSToF, Type::Float, Type::Int>, 1369 &SPIRVDecompiler::Unary<&Module::OpConvertSToF, Type::Float, Type::Int>,
1365 &SPIRVDecompiler::Unary<&Module::OpConvertUToF, Type::Float, Type::Uint>, 1370 &SPIRVDecompiler::Unary<&Module::OpConvertUToF, Type::Float, Type::Uint>,
1371 &SPIRVDecompiler::FSwizzleAdd,
1366 1372
1367 &SPIRVDecompiler::Binary<&Module::OpIAdd, Type::Int>, 1373 &SPIRVDecompiler::Binary<&Module::OpIAdd, Type::Int>,
1368 &SPIRVDecompiler::Binary<&Module::OpIMul, Type::Int>, 1374 &SPIRVDecompiler::Binary<&Module::OpIMul, Type::Int>,
diff --git a/src/video_core/shader/decode/warp.cpp b/src/video_core/shader/decode/warp.cpp
index c2875eb2b..d98d0e1dd 100644
--- a/src/video_core/shader/decode/warp.cpp
+++ b/src/video_core/shader/decode/warp.cpp
@@ -94,6 +94,15 @@ u32 ShaderIR::DecodeWarp(NodeBlock& bb, u32 pc) {
94 Operation(OperationCode::ShuffleIndexed, GetRegister(instr.gpr8), src_thread_id)); 94 Operation(OperationCode::ShuffleIndexed, GetRegister(instr.gpr8), src_thread_id));
95 break; 95 break;
96 } 96 }
97 case OpCode::Id::FSWZADD: {
98 UNIMPLEMENTED_IF(instr.fswzadd.ndv);
99
100 Node op_a = GetRegister(instr.gpr8);
101 Node op_b = GetRegister(instr.gpr20);
102 Node mask = Immediate(static_cast<u32>(instr.fswzadd.swizzle));
103 SetRegister(bb, instr.gpr0, Operation(OperationCode::FSwizzleAdd, op_a, op_b, mask));
104 break;
105 }
97 default: 106 default:
98 UNIMPLEMENTED_MSG("Unhandled warp instruction: {}", opcode->get().GetName()); 107 UNIMPLEMENTED_MSG("Unhandled warp instruction: {}", opcode->get().GetName());
99 break; 108 break;
diff --git a/src/video_core/shader/node.h b/src/video_core/shader/node.h
index bd3547e0d..54217e6a4 100644
--- a/src/video_core/shader/node.h
+++ b/src/video_core/shader/node.h
@@ -47,6 +47,7 @@ enum class OperationCode {
47 FTrunc, /// (MetaArithmetic, float a) -> float 47 FTrunc, /// (MetaArithmetic, float a) -> float
48 FCastInteger, /// (MetaArithmetic, int a) -> float 48 FCastInteger, /// (MetaArithmetic, int a) -> float
49 FCastUInteger, /// (MetaArithmetic, uint a) -> float 49 FCastUInteger, /// (MetaArithmetic, uint a) -> float
50 FSwizzleAdd, /// (float a, float b, uint mask) -> float
50 51
51 IAdd, /// (MetaArithmetic, int a, int b) -> int 52 IAdd, /// (MetaArithmetic, int a, int b) -> int
52 IMul, /// (MetaArithmetic, int a, int b) -> int 53 IMul, /// (MetaArithmetic, int a, int b) -> int