2018-07-05 12:14:18 +00:00
|
|
|
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
2019-09-17 19:11:19 +00:00
|
|
|
#pragma clang diagnostic ignored "-Wmissing-braces"
|
2018-07-05 12:14:18 +00:00
|
|
|
|
|
|
|
#include <metal_stdlib>
|
|
|
|
#include <simd/simd.h>
|
|
|
|
|
|
|
|
using namespace metal;
|
|
|
|
|
2019-09-17 19:11:19 +00:00
|
|
|
template<typename T, size_t Num>
|
|
|
|
struct spvUnsafeArray
|
2018-07-05 12:14:18 +00:00
|
|
|
{
|
2019-09-17 19:11:19 +00:00
|
|
|
T elements[Num ? Num : 1];
|
|
|
|
|
|
|
|
thread T& operator [] (size_t pos) thread
|
2019-08-27 11:16:16 +00:00
|
|
|
{
|
2019-09-17 19:11:19 +00:00
|
|
|
return elements[pos];
|
2019-08-27 11:16:16 +00:00
|
|
|
}
|
2019-09-17 19:11:19 +00:00
|
|
|
constexpr const thread T& operator [] (size_t pos) const thread
|
2019-08-27 11:16:16 +00:00
|
|
|
{
|
2019-09-17 19:11:19 +00:00
|
|
|
return elements[pos];
|
2019-08-27 11:16:16 +00:00
|
|
|
}
|
2019-09-17 19:11:19 +00:00
|
|
|
|
|
|
|
device T& operator [] (size_t pos) device
|
2019-08-27 11:16:16 +00:00
|
|
|
{
|
2019-09-17 19:11:19 +00:00
|
|
|
return elements[pos];
|
2019-08-27 11:16:16 +00:00
|
|
|
}
|
2019-09-17 19:11:19 +00:00
|
|
|
constexpr const device T& operator [] (size_t pos) const device
|
2019-08-27 11:16:16 +00:00
|
|
|
{
|
2019-09-17 19:11:19 +00:00
|
|
|
return elements[pos];
|
2019-08-27 11:16:16 +00:00
|
|
|
}
|
2019-09-17 19:11:19 +00:00
|
|
|
|
|
|
|
constexpr const constant T& operator [] (size_t pos) const constant
|
2019-08-27 11:16:16 +00:00
|
|
|
{
|
2019-09-17 19:11:19 +00:00
|
|
|
return elements[pos];
|
2019-08-27 11:16:16 +00:00
|
|
|
}
|
2019-09-17 19:11:19 +00:00
|
|
|
|
|
|
|
threadgroup T& operator [] (size_t pos) threadgroup
|
2019-08-27 11:16:16 +00:00
|
|
|
{
|
2019-09-17 19:11:19 +00:00
|
|
|
return elements[pos];
|
2019-08-27 11:16:16 +00:00
|
|
|
}
|
2019-09-17 19:11:19 +00:00
|
|
|
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
|
|
|
|
{
|
|
|
|
return elements[pos];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
constant spvUnsafeArray<float, 16> _16 = spvUnsafeArray<float, 16>({ 1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0 });
|
|
|
|
constant spvUnsafeArray<float4, 4> _60 = spvUnsafeArray<float4, 4>({ float4(0.0), float4(1.0), float4(8.0), float4(5.0) });
|
|
|
|
constant spvUnsafeArray<float4, 4> _104 = spvUnsafeArray<float4, 4>({ float4(20.0), float4(30.0), float4(50.0), float4(60.0) });
|
|
|
|
|
|
|
|
struct main0_out
|
|
|
|
{
|
|
|
|
float FragColor [[color(0)]];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct main0_in
|
|
|
|
{
|
|
|
|
int index [[user(locn0)]];
|
|
|
|
};
|
2018-07-05 12:14:18 +00:00
|
|
|
|
|
|
|
fragment main0_out main0(main0_in in [[stage_in]])
|
|
|
|
{
|
|
|
|
main0_out out = {};
|
|
|
|
out.FragColor = _16[in.index];
|
|
|
|
if (in.index < 10)
|
|
|
|
{
|
|
|
|
out.FragColor += _16[in.index ^ 1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out.FragColor += _16[in.index & 1];
|
|
|
|
}
|
|
|
|
if (in.index > 30)
|
|
|
|
{
|
|
|
|
out.FragColor += _60[in.index & 3].y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out.FragColor += _60[in.index & 1].x;
|
|
|
|
}
|
2019-09-17 19:11:19 +00:00
|
|
|
spvUnsafeArray<float4, 4> foobar = spvUnsafeArray<float4, 4>({ float4(0.0), float4(1.0), float4(8.0), float4(5.0) });
|
2018-07-05 12:14:18 +00:00
|
|
|
if (in.index > 30)
|
|
|
|
{
|
|
|
|
foobar[1].z = 20.0;
|
|
|
|
}
|
|
|
|
out.FragColor += foobar[in.index & 3].z;
|
2019-09-17 19:11:19 +00:00
|
|
|
spvUnsafeArray<float4, 4> baz = spvUnsafeArray<float4, 4>({ float4(0.0), float4(1.0), float4(8.0), float4(5.0) });
|
|
|
|
baz = _104;
|
2018-07-05 12:14:18 +00:00
|
|
|
out.FragColor += baz[in.index & 3].z;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|