2017-11-06 02:34:42 +00:00
|
|
|
#pragma clang diagnostic ignored "-Wunused-variable"
|
|
|
|
|
|
|
|
#include <metal_stdlib>
|
|
|
|
#include <simd/simd.h>
|
|
|
|
#include <metal_atomic>
|
|
|
|
|
|
|
|
using namespace metal;
|
|
|
|
|
|
|
|
struct SSBO
|
|
|
|
{
|
|
|
|
float4 in_data[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SSBO2
|
|
|
|
{
|
|
|
|
float4 out_data[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SSBO3
|
|
|
|
{
|
|
|
|
uint counter;
|
|
|
|
};
|
|
|
|
|
2019-09-18 19:56:51 +00:00
|
|
|
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(1u);
|
|
|
|
|
2018-05-25 08:03:46 +00:00
|
|
|
kernel void main0(const device SSBO& _23 [[buffer(0)]], device SSBO2& _45 [[buffer(1)]], device SSBO3& _48 [[buffer(2)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
|
2017-11-06 02:34:42 +00:00
|
|
|
{
|
|
|
|
uint ident = gl_GlobalInvocationID.x;
|
|
|
|
float4 idata = _23.in_data[ident];
|
|
|
|
if (dot(idata, float4(1.0, 5.0, 6.0, 2.0)) > 8.19999980926513671875)
|
|
|
|
{
|
MSL: Handle coherent, volatile, and restrict.
This maps them to their MSL equivalents. I've mapped `Coherent` to
`volatile` since MSL doesn't have anything weaker than `volatile` but
stronger than nothing.
As part of this, I had to remove the implicit `volatile` added for
atomic operation casts. If the buffer is already `coherent` or
`volatile`, then we would add a second `volatile`, which would be
redundant. I think this is OK even when the buffer *doesn't* have
`coherent`: `T *` is implicitly convertible to `volatile T *`, but not
vice-versa. It seems to compile OK at any rate. (Note that the
non-`volatile` overloads of the atomic functions documented in the spec
aren't present in the MSL 2.2 stdlib headers.)
`restrict` is tricky, because in MSL, as in C++, it needs to go *after*
the asterisk or ampersand for the pointer type it's modifying.
Another issue is that, in the `Simple`, `GLSL450`, and `Vulkan` memory
models, `Restrict` is the default (i.e. does not need to be specified);
but MSL likely follows the `OpenCL` model where `Aliased` is the
default. We probably need to implicitly set either `Restrict` or
`Aliased` depending on the module's declared memory model.
2019-07-10 16:17:40 +00:00
|
|
|
uint _52 = atomic_fetch_add_explicit((device atomic_uint*)&_48.counter, 1u, memory_order_relaxed);
|
2017-11-06 02:34:42 +00:00
|
|
|
_45.out_data[_52] = idata;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|