| 1 |
#pragma clang diagnostic ignored "-Wmissing-prototypes" |
| 2 |
#pragma clang diagnostic ignored "-Wunused-variable" |
| 3 |
|
| 4 |
#include <metal_stdlib> |
| 5 |
#include <simd/simd.h> |
| 6 |
#include <metal_atomic> |
| 7 |
|
| 8 |
using namespace metal; |
| 9 |
|
| 10 |
struct Buffer3 |
| 11 |
{ |
| 12 |
int baz; |
| 13 |
}; |
| 14 |
|
| 15 |
struct Buffer |
| 16 |
{ |
| 17 |
int foo; |
| 18 |
uint bar; |
| 19 |
}; |
| 20 |
|
| 21 |
struct Buffer2 |
| 22 |
{ |
| 23 |
uint quux; |
| 24 |
}; |
| 25 |
|
| 26 |
// The required alignment of a linear texture of R32Uint format. |
| 27 |
constant uint spvLinearTextureAlignmentOverride [[function_constant(65535)]]; |
| 28 |
constant uint spvLinearTextureAlignment = is_function_constant_defined(spvLinearTextureAlignmentOverride) ? spvLinearTextureAlignmentOverride : 4; |
| 29 |
// Returns buffer coords corresponding to 2D texture coords for emulating 2D texture atomics |
| 30 |
#define spvImage2DAtomicCoord(tc, tex) (((((tex).get_width() + spvLinearTextureAlignment / 4 - 1) & ~( spvLinearTextureAlignment / 4 - 1)) * (tc).y) + (tc).x) |
| 31 |
|
| 32 |
fragment void main0(device Buffer3& _9 [[buffer(0)]], volatile device Buffer& _42 [[buffer(2), raster_order_group(0)]], device Buffer2& _52 [[buffer(3), raster_order_group(0)]], texture2d<float, access::write> img4 [[texture(0)]], texture2d<float, access::write> img [[texture(1), raster_order_group(0)]], texture2d<float> img3 [[texture(2), raster_order_group(0)]], texture2d<uint> img2 [[texture(3), raster_order_group(0)]], device atomic_uint* img2_atomic [[buffer(1), raster_order_group(0)]]) |
| 33 |
{ |
| 34 |
_9.baz = 0; |
| 35 |
img4.write(float4(1.0, 0.0, 0.0, 1.0), uint2(int2(1))); |
| 36 |
img.write(img3.read(uint2(int2(0))), uint2(int2(0))); |
| 37 |
uint _39 = atomic_fetch_add_explicit((device atomic_uint*)&img2_atomic[spvImage2DAtomicCoord(int2(0), img2)], 1u, memory_order_relaxed); |
| 38 |
_42.foo += 42; |
| 39 |
uint _55 = atomic_fetch_and_explicit((volatile device atomic_uint*)&_42.bar, _52.quux, memory_order_relaxed); |
| 40 |
} |
| 41 |
|