SPIRV-Cross/reference/shaders-msl/comp/global-invocation-id-writable-ssbo-in-function.comp

32 lines
794 B
Plaintext

#pragma clang diagnostic ignored "-Wmissing-prototypes"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct myBlock
{
int a;
float b[1];
};
// Implementation of the GLSL mod() function, which is slightly different than Metal fmod()
template<typename Tx, typename Ty>
inline Tx mod(Tx x, Ty y)
{
return x - y * floor(x / y);
}
inline float getB(device myBlock& myStorage, thread uint3& gl_GlobalInvocationID)
{
return myStorage.b[gl_GlobalInvocationID.x];
}
kernel void main0(device myBlock& myStorage [[buffer(0)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
{
myStorage.a = (myStorage.a + 1) % 256;
myStorage.b[gl_GlobalInvocationID.x] = mod(getB(myStorage, gl_GlobalInvocationID) + 0.0199999995529651641845703125, 1.0);
}