summaryrefslogtreecommitdiffstats
path: root/src/shader_recompiler/backend/spirv/emit_spirv_barriers.cpp
blob: 18f512319be1f925334eb085355ffdd5d093f41c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// 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 {
void EmitMemoryBarrierImpl(EmitContext& ctx, spv::Scope scope) {
    const auto semantics =
        spv::MemorySemanticsMask::AcquireRelease | spv::MemorySemanticsMask::UniformMemory |
        spv::MemorySemanticsMask::WorkgroupMemory | spv::MemorySemanticsMask::AtomicCounterMemory |
        spv::MemorySemanticsMask::ImageMemory;
    ctx.OpMemoryBarrier(ctx.Constant(ctx.U32[1], static_cast<u32>(scope)),
                        ctx.Constant(ctx.U32[1], static_cast<u32>(semantics)));
}

} // Anonymous namespace

void EmitMemoryBarrierWorkgroupLevel(EmitContext& ctx) {
    EmitMemoryBarrierImpl(ctx, spv::Scope::Workgroup);
}

void EmitMemoryBarrierDeviceLevel(EmitContext& ctx) {
    EmitMemoryBarrierImpl(ctx, spv::Scope::Device);
}

void EmitMemoryBarrierSystemLevel(EmitContext& ctx) {
    EmitMemoryBarrierImpl(ctx, spv::Scope::CrossDevice);
}

} // namespace Shader::Backend::SPIRV