| 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 |
struct spvDescriptorSetBuffer0 |
| 27 |
{ |
| 28 |
device Buffer3* m_9 [[id(0)]]; |
| 29 |
texture2d<float, access::write> img4 [[id(1)]]; |
| 30 |
texture2d<float, access::write> img [[id(2), raster_order_group(0)]]; |
| 31 |
texture2d<float> img3 [[id(3), raster_order_group(0)]]; |
| 32 |
texture2d<uint> img2 [[id(4), raster_order_group(0)]]; |
| 33 |
device atomic_uint* img2_atomic [[id(5), raster_order_group(0)]]; |
| 34 |
volatile device Buffer* m_42 [[id(6), raster_order_group(0)]]; |
| 35 |
device Buffer2* m_52 [[id(7), raster_order_group(0)]]; |
| 36 |
}; |
| 37 |
|
| 38 |
// The required alignment of a linear texture of R32Uint format. |
| 39 |
constant uint spvLinearTextureAlignmentOverride [[function_constant(65535)]]; |
| 40 |
constant uint spvLinearTextureAlignment = is_function_constant_defined(spvLinearTextureAlignmentOverride) ? spvLinearTextureAlignmentOverride : 4; |
| 41 |
// Returns buffer coords corresponding to 2D texture coords for emulating 2D texture atomics |
| 42 |
#define spvImage2DAtomicCoord(tc, tex) (((((tex).get_width() + spvLinearTextureAlignment / 4 - 1) & ~( spvLinearTextureAlignment / 4 - 1)) * (tc).y) + (tc).x) |
| 43 |
|
| 44 |
fragment void main0(constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]]) |
| 45 |
{ |
| 46 |
(*spvDescriptorSet0.m_9).baz = 0; |
| 47 |
spvDescriptorSet0.img4.write(float4(1.0, 0.0, 0.0, 1.0), uint2(int2(1))); |
| 48 |
spvDescriptorSet0.img.write(spvDescriptorSet0.img3.read(uint2(int2(0))), uint2(int2(0))); |
| 49 |
uint _39 = atomic_fetch_add_explicit((device atomic_uint*)&spvDescriptorSet0.img2_atomic[spvImage2DAtomicCoord(int2(0), spvDescriptorSet0.img2)], 1u, memory_order_relaxed); |
| 50 |
(*spvDescriptorSet0.m_42).foo += 42; |
| 51 |
uint _55 = atomic_fetch_and_explicit((volatile device atomic_uint*)&(*spvDescriptorSet0.m_42).bar, (*spvDescriptorSet0.m_52).quux, memory_order_relaxed); |
| 52 |
} |
| 53 |
|