diff options
| author | 2019-12-09 21:46:12 -0300 | |
|---|---|---|
| committer | 2019-12-10 16:45:03 -0300 | |
| commit | 425a254fa24d7179124b4544ffeb2b1fe4fa99dc (patch) | |
| tree | ffe458cdf75e70e072eab574051c72d0c4c837dc /src | |
| parent | Merge pull request #3208 from ReinUsesLisp/vk-shader-decompiler (diff) | |
| download | yuzu-425a254fa24d7179124b4544ffeb2b1fe4fa99dc.tar.gz yuzu-425a254fa24d7179124b4544ffeb2b1fe4fa99dc.tar.xz yuzu-425a254fa24d7179124b4544ffeb2b1fe4fa99dc.zip | |
shader: Implement MEMBAR.GL
Implement using memoryBarrier in GLSL and OpMemoryBarrier on SPIR-V.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/engines/shader_bytecode.h | 18 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 7 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_shader_decompiler.cpp | 14 | ||||
| -rw-r--r-- | src/video_core/shader/decode/other.cpp | 6 | ||||
| -rw-r--r-- | src/video_core/shader/node.h | 2 |
5 files changed, 46 insertions, 1 deletions
diff --git a/src/video_core/engines/shader_bytecode.h b/src/video_core/engines/shader_bytecode.h index 7703a76a3..290d929df 100644 --- a/src/video_core/engines/shader_bytecode.h +++ b/src/video_core/engines/shader_bytecode.h | |||
| @@ -384,6 +384,15 @@ enum class IsberdMode : u64 { | |||
| 384 | 384 | ||
| 385 | enum class IsberdShift : u64 { None = 0, U16 = 1, B32 = 2 }; | 385 | enum class IsberdShift : u64 { None = 0, U16 = 1, B32 = 2 }; |
| 386 | 386 | ||
| 387 | enum class MembarType : u64 { | ||
| 388 | CTA = 0, | ||
| 389 | GL = 1, | ||
| 390 | SYS = 2, | ||
| 391 | VC = 3, | ||
| 392 | }; | ||
| 393 | |||
| 394 | enum class MembarUnknown : u64 { Default = 0, IVALLD = 1, IVALLT = 2, IVALLTD = 3 }; | ||
| 395 | |||
| 387 | enum class HalfType : u64 { | 396 | enum class HalfType : u64 { |
| 388 | H0_H1 = 0, | 397 | H0_H1 = 0, |
| 389 | F32 = 1, | 398 | F32 = 1, |
| @@ -1546,6 +1555,11 @@ union Instruction { | |||
| 1546 | } isberd; | 1555 | } isberd; |
| 1547 | 1556 | ||
| 1548 | union { | 1557 | union { |
| 1558 | BitField<8, 2, MembarType> type; | ||
| 1559 | BitField<0, 2, MembarUnknown> unknown; | ||
| 1560 | } membar; | ||
| 1561 | |||
| 1562 | union { | ||
| 1549 | BitField<48, 1, u64> signed_a; | 1563 | BitField<48, 1, u64> signed_a; |
| 1550 | BitField<38, 1, u64> is_byte_chunk_a; | 1564 | BitField<38, 1, u64> is_byte_chunk_a; |
| 1551 | BitField<36, 2, VideoType> type_a; | 1565 | BitField<36, 2, VideoType> type_a; |
| @@ -1669,6 +1683,7 @@ public: | |||
| 1669 | IPA, | 1683 | IPA, |
| 1670 | OUT_R, // Emit vertex/primitive | 1684 | OUT_R, // Emit vertex/primitive |
| 1671 | ISBERD, | 1685 | ISBERD, |
| 1686 | MEMBAR, | ||
| 1672 | VMAD, | 1687 | VMAD, |
| 1673 | VSETP, | 1688 | VSETP, |
| 1674 | FFMA_IMM, // Fused Multiply and Add | 1689 | FFMA_IMM, // Fused Multiply and Add |
| @@ -1930,7 +1945,7 @@ private: | |||
| 1930 | INST("111000100100----", Id::BRA, Type::Flow, "BRA"), | 1945 | INST("111000100100----", Id::BRA, Type::Flow, "BRA"), |
| 1931 | INST("111000100101----", Id::BRX, Type::Flow, "BRX"), | 1946 | INST("111000100101----", Id::BRX, Type::Flow, "BRX"), |
| 1932 | INST("1111000011111---", Id::SYNC, Type::Flow, "SYNC"), | 1947 | INST("1111000011111---", Id::SYNC, Type::Flow, "SYNC"), |
| 1933 | INST("111000110100---", Id::BRK, Type::Flow, "BRK"), | 1948 | INST("111000110100----", Id::BRK, Type::Flow, "BRK"), |
| 1934 | INST("111000110000----", Id::EXIT, Type::Flow, "EXIT"), | 1949 | INST("111000110000----", Id::EXIT, Type::Flow, "EXIT"), |
| 1935 | INST("1111000011110---", Id::DEPBAR, Type::Synch, "DEPBAR"), | 1950 | INST("1111000011110---", Id::DEPBAR, Type::Synch, "DEPBAR"), |
| 1936 | INST("0101000011011---", Id::VOTE, Type::Warp, "VOTE"), | 1951 | INST("0101000011011---", Id::VOTE, Type::Warp, "VOTE"), |
| @@ -1969,6 +1984,7 @@ private: | |||
| 1969 | INST("11100000--------", Id::IPA, Type::Trivial, "IPA"), | 1984 | INST("11100000--------", Id::IPA, Type::Trivial, "IPA"), |
| 1970 | INST("1111101111100---", Id::OUT_R, Type::Trivial, "OUT_R"), | 1985 | INST("1111101111100---", Id::OUT_R, Type::Trivial, "OUT_R"), |
| 1971 | INST("1110111111010---", Id::ISBERD, Type::Trivial, "ISBERD"), | 1986 | INST("1110111111010---", Id::ISBERD, Type::Trivial, "ISBERD"), |
| 1987 | INST("1110111110011---", Id::MEMBAR, Type::Trivial, "MEMBAR"), | ||
| 1972 | INST("01011111--------", Id::VMAD, Type::Video, "VMAD"), | 1988 | INST("01011111--------", Id::VMAD, Type::Video, "VMAD"), |
| 1973 | INST("0101000011110---", Id::VSETP, Type::Video, "VSETP"), | 1989 | INST("0101000011110---", Id::VSETP, Type::Video, "VSETP"), |
| 1974 | INST("0011001-1-------", Id::FFMA_IMM, Type::Ffma, "FFMA_IMM"), | 1990 | INST("0011001-1-------", Id::FFMA_IMM, Type::Ffma, "FFMA_IMM"), |
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 9700c2ebe..fa7049bbe 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |||
| @@ -1992,6 +1992,11 @@ private: | |||
| 1992 | return {fmt::format("readInvocationARB({}, {})", value, index), Type::Float}; | 1992 | return {fmt::format("readInvocationARB({}, {})", value, index), Type::Float}; |
| 1993 | } | 1993 | } |
| 1994 | 1994 | ||
| 1995 | Expression MemoryBarrierGL(Operation) { | ||
| 1996 | code.AddLine("memoryBarrier();"); | ||
| 1997 | return {}; | ||
| 1998 | } | ||
| 1999 | |||
| 1995 | struct Func final { | 2000 | struct Func final { |
| 1996 | Func() = delete; | 2001 | Func() = delete; |
| 1997 | ~Func() = delete; | 2002 | ~Func() = delete; |
| @@ -2173,6 +2178,8 @@ private: | |||
| 2173 | 2178 | ||
| 2174 | &GLSLDecompiler::ThreadId, | 2179 | &GLSLDecompiler::ThreadId, |
| 2175 | &GLSLDecompiler::ShuffleIndexed, | 2180 | &GLSLDecompiler::ShuffleIndexed, |
| 2181 | |||
| 2182 | &GLSLDecompiler::MemoryBarrierGL, | ||
| 2176 | }; | 2183 | }; |
| 2177 | static_assert(operation_decompilers.size() == static_cast<std::size_t>(OperationCode::Amount)); | 2184 | static_assert(operation_decompilers.size() == static_cast<std::size_t>(OperationCode::Amount)); |
| 2178 | 2185 | ||
diff --git a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp index 8ad89b58a..6227bc70b 100644 --- a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp +++ b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp | |||
| @@ -1971,6 +1971,18 @@ private: | |||
| 1971 | return {OpSubgroupReadInvocationKHR(t_float, value, index), Type::Float}; | 1971 | return {OpSubgroupReadInvocationKHR(t_float, value, index), Type::Float}; |
| 1972 | } | 1972 | } |
| 1973 | 1973 | ||
| 1974 | Expression MemoryBarrierGL(Operation) { | ||
| 1975 | const auto scope = spv::Scope::Device; | ||
| 1976 | const auto semantics = | ||
| 1977 | spv::MemorySemanticsMask::AcquireRelease | spv::MemorySemanticsMask::UniformMemory | | ||
| 1978 | spv::MemorySemanticsMask::WorkgroupMemory | | ||
| 1979 | spv::MemorySemanticsMask::AtomicCounterMemory | spv::MemorySemanticsMask::ImageMemory; | ||
| 1980 | |||
| 1981 | OpMemoryBarrier(Constant(t_uint, static_cast<u32>(scope)), | ||
| 1982 | Constant(t_uint, static_cast<u32>(semantics))); | ||
| 1983 | return {}; | ||
| 1984 | } | ||
| 1985 | |||
| 1974 | Id DeclareBuiltIn(spv::BuiltIn builtin, spv::StorageClass storage, Id type, std::string name) { | 1986 | Id DeclareBuiltIn(spv::BuiltIn builtin, spv::StorageClass storage, Id type, std::string name) { |
| 1975 | const Id id = OpVariable(type, storage); | 1987 | const Id id = OpVariable(type, storage); |
| 1976 | Decorate(id, spv::Decoration::BuiltIn, static_cast<u32>(builtin)); | 1988 | Decorate(id, spv::Decoration::BuiltIn, static_cast<u32>(builtin)); |
| @@ -2374,6 +2386,8 @@ private: | |||
| 2374 | 2386 | ||
| 2375 | &SPIRVDecompiler::ThreadId, | 2387 | &SPIRVDecompiler::ThreadId, |
| 2376 | &SPIRVDecompiler::ShuffleIndexed, | 2388 | &SPIRVDecompiler::ShuffleIndexed, |
| 2389 | |||
| 2390 | &SPIRVDecompiler::MemoryBarrierGL, | ||
| 2377 | }; | 2391 | }; |
| 2378 | static_assert(operation_decompilers.size() == static_cast<std::size_t>(OperationCode::Amount)); | 2392 | static_assert(operation_decompilers.size() == static_cast<std::size_t>(OperationCode::Amount)); |
| 2379 | 2393 | ||
diff --git a/src/video_core/shader/decode/other.cpp b/src/video_core/shader/decode/other.cpp index 5c802886b..7321698b2 100644 --- a/src/video_core/shader/decode/other.cpp +++ b/src/video_core/shader/decode/other.cpp | |||
| @@ -257,6 +257,12 @@ u32 ShaderIR::DecodeOther(NodeBlock& bb, u32 pc) { | |||
| 257 | SetRegister(bb, instr.gpr0, GetRegister(instr.gpr8)); | 257 | SetRegister(bb, instr.gpr0, GetRegister(instr.gpr8)); |
| 258 | break; | 258 | break; |
| 259 | } | 259 | } |
| 260 | case OpCode::Id::MEMBAR: { | ||
| 261 | UNIMPLEMENTED_IF(instr.membar.type != Tegra::Shader::MembarType::GL); | ||
| 262 | UNIMPLEMENTED_IF(instr.membar.unknown != Tegra::Shader::MembarUnknown::Default); | ||
| 263 | bb.push_back(Operation(OperationCode::MemoryBarrierGL)); | ||
| 264 | break; | ||
| 265 | } | ||
| 260 | case OpCode::Id::DEPBAR: { | 266 | case OpCode::Id::DEPBAR: { |
| 261 | LOG_DEBUG(HW_GPU, "DEPBAR instruction is stubbed"); | 267 | LOG_DEBUG(HW_GPU, "DEPBAR instruction is stubbed"); |
| 262 | break; | 268 | break; |
diff --git a/src/video_core/shader/node.h b/src/video_core/shader/node.h index 1a4d28ae9..abd40f582 100644 --- a/src/video_core/shader/node.h +++ b/src/video_core/shader/node.h | |||
| @@ -189,6 +189,8 @@ enum class OperationCode { | |||
| 189 | ThreadId, /// () -> uint | 189 | ThreadId, /// () -> uint |
| 190 | ShuffleIndexed, /// (uint value, uint index) -> uint | 190 | ShuffleIndexed, /// (uint value, uint index) -> uint |
| 191 | 191 | ||
| 192 | MemoryBarrierGL, /// () -> void | ||
| 193 | |||
| 192 | Amount, | 194 | Amount, |
| 193 | }; | 195 | }; |
| 194 | 196 | ||