2021-04-02 19:27:30 +02:00
|
|
|
// 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 {
|
2021-04-17 08:21:03 +02:00
|
|
|
void MemoryBarrier(EmitContext& ctx, spv::Scope scope) {
|
2021-04-04 08:04:48 +02:00
|
|
|
const auto semantics{
|
2021-04-02 19:27:30 +02:00
|
|
|
spv::MemorySemanticsMask::AcquireRelease | spv::MemorySemanticsMask::UniformMemory |
|
|
|
|
spv::MemorySemanticsMask::WorkgroupMemory | spv::MemorySemanticsMask::AtomicCounterMemory |
|
2021-04-04 08:04:48 +02:00
|
|
|
spv::MemorySemanticsMask::ImageMemory};
|
2021-04-02 19:27:30 +02:00
|
|
|
ctx.OpMemoryBarrier(ctx.Constant(ctx.U32[1], static_cast<u32>(scope)),
|
|
|
|
ctx.Constant(ctx.U32[1], static_cast<u32>(semantics)));
|
|
|
|
}
|
2021-04-03 01:48:39 +02:00
|
|
|
} // Anonymous namespace
|
|
|
|
|
2021-04-04 08:04:48 +02:00
|
|
|
void EmitBarrier(EmitContext& ctx) {
|
|
|
|
const auto execution{spv::Scope::Workgroup};
|
|
|
|
const auto memory{spv::Scope::Workgroup};
|
|
|
|
const auto memory_semantics{spv::MemorySemanticsMask::AcquireRelease |
|
|
|
|
spv::MemorySemanticsMask::WorkgroupMemory};
|
|
|
|
ctx.OpControlBarrier(ctx.Constant(ctx.U32[1], static_cast<u32>(execution)),
|
|
|
|
ctx.Constant(ctx.U32[1], static_cast<u32>(memory)),
|
|
|
|
ctx.Constant(ctx.U32[1], static_cast<u32>(memory_semantics)));
|
|
|
|
}
|
|
|
|
|
2021-04-17 08:21:03 +02:00
|
|
|
void EmitWorkgroupMemoryBarrier(EmitContext& ctx) {
|
|
|
|
MemoryBarrier(ctx, spv::Scope::Workgroup);
|
2021-04-03 01:48:39 +02:00
|
|
|
}
|
|
|
|
|
2021-04-17 08:21:03 +02:00
|
|
|
void EmitDeviceMemoryBarrier(EmitContext& ctx) {
|
|
|
|
MemoryBarrier(ctx, spv::Scope::Device);
|
2021-04-03 01:48:39 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 19:27:30 +02:00
|
|
|
} // namespace Shader::Backend::SPIRV
|