blob: e5e53b699fa146f96bdc25ac881e1efad3864d68 [file] [log] [blame]
// SPDX-License-Identifier: Apache-2.0 OR MIT OR Unlicense
// Our version of the message passing atomic litmus test.
#version 450
#extension GL_KHR_memory_scope_semantics : enable
#ifdef VKMM
#pragma use_vulkan_memory_model
#define ACQUIRE gl_StorageSemanticsBuffer, gl_SemanticsAcquire
#define RELEASE gl_StorageSemanticsBuffer, gl_SemanticsRelease
#else
#define ACQUIRE 0, 0
#define RELEASE 0, 0
#endif
layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;
struct Element
{
uint data;
uint flag;
};
layout(binding = 0) buffer DataBuf
{
Element data[];
} data_buf;
layout(binding = 1) buffer ControlBuf
{
uint failures;
} control_buf;
uint permute_flag_ix(uint data_ix)
{
return (data_ix * 419u) & 65535u;
}
void main()
{
atomicStore(data_buf.data[gl_GlobalInvocationID.x].data, 1u, gl_ScopeDevice, 0, 0);
#ifndef VKMM
memoryBarrierBuffer();
#endif
uint write_flag_ix = permute_flag_ix(gl_GlobalInvocationID.x);
atomicStore(data_buf.data[write_flag_ix].flag, 1u, gl_ScopeDevice, RELEASE);
uint read_ix = (gl_GlobalInvocationID.x * 4099u) & 65535u;
uint read_flag_ix = permute_flag_ix(read_ix);
uint flag = atomicLoad(data_buf.data[read_flag_ix].flag, gl_ScopeDevice, ACQUIRE);
#ifndef VKMM
memoryBarrierBuffer();
#endif
uint data = atomicLoad(data_buf.data[read_ix].data, gl_ScopeDevice, 0, 0);
if (flag > data)
{
atomicAdd(control_buf.failures, 1u);
}
}