summaryrefslogtreecommitdiffstats
path: root/src/shader_recompiler/backend
diff options
context:
space:
mode:
authorFernandoS27 <fsahmkow27@gmail.com>2021-04-02 19:27:30 +0200
committerameerj <52414509+ameerj@users.noreply.github.com>2021-07-23 03:51:26 +0200
commit655f7a570a10218ffb2ed175bb7f0b84530ccae0 (patch)
treebb95bc316718bd5c746a0b28084b3548a4aea222 /src/shader_recompiler/backend
parentshader: Improve VOTE.VTG stub (diff)
downloadyuzu-655f7a570a10218ffb2ed175bb7f0b84530ccae0.tar
yuzu-655f7a570a10218ffb2ed175bb7f0b84530ccae0.tar.gz
yuzu-655f7a570a10218ffb2ed175bb7f0b84530ccae0.tar.bz2
yuzu-655f7a570a10218ffb2ed175bb7f0b84530ccae0.tar.lz
yuzu-655f7a570a10218ffb2ed175bb7f0b84530ccae0.tar.xz
yuzu-655f7a570a10218ffb2ed175bb7f0b84530ccae0.tar.zst
yuzu-655f7a570a10218ffb2ed175bb7f0b84530ccae0.zip
Diffstat (limited to 'src/shader_recompiler/backend')
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv.h1
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_barriers.cpp40
2 files changed, 41 insertions, 0 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv.h b/src/shader_recompiler/backend/spirv/emit_spirv.h
index d2eda1f8e..749ad1240 100644
--- a/src/shader_recompiler/backend/spirv/emit_spirv.h
+++ b/src/shader_recompiler/backend/spirv/emit_spirv.h
@@ -28,6 +28,7 @@ void EmitSelectionMerge(EmitContext& ctx, Id merge_label);
void EmitReturn(EmitContext& ctx);
void EmitUnreachable(EmitContext& ctx);
void EmitDemoteToHelperInvocation(EmitContext& ctx, Id continue_label);
+void EmitMemoryBarrier(EmitContext& ctx, IR::Inst* inst);
void EmitPrologue(EmitContext& ctx);
void EmitEpilogue(EmitContext& ctx);
void EmitGetRegister(EmitContext& ctx);
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_barriers.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_barriers.cpp
new file mode 100644
index 000000000..413ac25a0
--- /dev/null
+++ b/src/shader_recompiler/backend/spirv/emit_spirv_barriers.cpp
@@ -0,0 +1,40 @@
+// Copyright 2021 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include "shader_recompiler/backend/spirv/emit_spirv.h"
+#include "shader_recompiler/frontend/ir/modifiers.h"
+
+namespace Shader::Backend::SPIRV {
+namespace {
+spv::Scope MemoryScopeToSpirVScope(IR::MemoryScope scope) {
+ switch (scope) {
+ case IR::MemoryScope::Warp:
+ return spv::Scope::Subgroup;
+ case IR::MemoryScope::Workgroup:
+ return spv::Scope::Workgroup;
+ case IR::MemoryScope::Device:
+ return spv::Scope::Device;
+ case IR::MemoryScope::System:
+ return spv::Scope::CrossDevice;
+ case IR::MemoryScope::DontCare:
+ return spv::Scope::Invocation;
+ default:
+ throw NotImplementedException("Unknown memory scope!");
+ }
+}
+
+} // namespace
+
+void EmitMemoryBarrier(EmitContext& ctx, IR::Inst* inst) {
+ const auto info{inst->Flags<IR::BarrierInstInfo>()};
+ const auto semantics =
+ spv::MemorySemanticsMask::AcquireRelease | spv::MemorySemanticsMask::UniformMemory |
+ spv::MemorySemanticsMask::WorkgroupMemory | spv::MemorySemanticsMask::AtomicCounterMemory |
+ spv::MemorySemanticsMask::ImageMemory;
+ const auto scope = MemoryScopeToSpirVScope(info.scope);
+ ctx.OpMemoryBarrier(ctx.Constant(ctx.U32[1], static_cast<u32>(scope)),
+ ctx.Constant(ctx.U32[1], static_cast<u32>(semantics)));
+}
+
+} // namespace Shader::Backend::SPIRV