| 1 |
#pragma clang diagnostic ignored "-Wmissing-prototypes" |
| 2 |
|
| 3 |
#include <metal_stdlib> |
| 4 |
#include <simd/simd.h> |
| 5 |
|
| 6 |
using namespace metal; |
| 7 |
|
| 8 |
struct UBO |
| 9 |
{ |
| 10 |
uint index; |
| 11 |
}; |
| 12 |
|
| 13 |
struct UBO2 |
| 14 |
{ |
| 15 |
uint index2; |
| 16 |
}; |
| 17 |
|
| 18 |
struct spvDescriptorSetBuffer0 |
| 19 |
{ |
| 20 |
array<texture2d<float>, 4> uSampler [[id(0)]]; |
| 21 |
array<sampler, 4> uSamplerSmplr [[id(4)]]; |
| 22 |
constant UBO* uUBO [[id(8)]]; |
| 23 |
constant UBO2* m_50 [[id(9)]]; |
| 24 |
constant uint* spvSwizzleConstants [[id(10)]]; |
| 25 |
}; |
| 26 |
|
| 27 |
struct main0_out |
| 28 |
{ |
| 29 |
float4 FragColor [[color(0)]]; |
| 30 |
}; |
| 31 |
|
| 32 |
struct main0_in |
| 33 |
{ |
| 34 |
float2 vUV [[user(locn0)]]; |
| 35 |
}; |
| 36 |
|
| 37 |
template<typename T> struct spvRemoveReference { typedef T type; }; |
| 38 |
template<typename T> struct spvRemoveReference<thread T&> { typedef T type; }; |
| 39 |
template<typename T> struct spvRemoveReference<thread T&&> { typedef T type; }; |
| 40 |
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type& x) |
| 41 |
{ |
| 42 |
return static_cast<thread T&&>(x); |
| 43 |
} |
| 44 |
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type&& x) |
| 45 |
{ |
| 46 |
return static_cast<thread T&&>(x); |
| 47 |
} |
| 48 |
|
| 49 |
enum class spvSwizzle : uint |
| 50 |
{ |
| 51 |
none = 0, |
| 52 |
zero, |
| 53 |
one, |
| 54 |
red, |
| 55 |
green, |
| 56 |
blue, |
| 57 |
alpha |
| 58 |
}; |
| 59 |
|
| 60 |
template<typename T> |
| 61 |
inline T spvGetSwizzle(vec<T, 4> x, T c, spvSwizzle s) |
| 62 |
{ |
| 63 |
switch (s) |
| 64 |
{ |
| 65 |
case spvSwizzle::none: |
| 66 |
return c; |
| 67 |
case spvSwizzle::zero: |
| 68 |
return 0; |
| 69 |
case spvSwizzle::one: |
| 70 |
return 1; |
| 71 |
case spvSwizzle::red: |
| 72 |
return x.r; |
| 73 |
case spvSwizzle::green: |
| 74 |
return x.g; |
| 75 |
case spvSwizzle::blue: |
| 76 |
return x.b; |
| 77 |
case spvSwizzle::alpha: |
| 78 |
return x.a; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
// Wrapper function that swizzles texture samples and fetches. |
| 83 |
template<typename T> |
| 84 |
inline vec<T, 4> spvTextureSwizzle(vec<T, 4> x, uint s) |
| 85 |
{ |
| 86 |
if (!s) |
| 87 |
return x; |
| 88 |
return vec<T, 4>(spvGetSwizzle(x, x.r, spvSwizzle((s >> 0) & 0xFF)), spvGetSwizzle(x, x.g, spvSwizzle((s >> 8) & 0xFF)), spvGetSwizzle(x, x.b, spvSwizzle((s >> 16) & 0xFF)), spvGetSwizzle(x, x.a, spvSwizzle((s >> 24) & 0xFF))); |
| 89 |
} |
| 90 |
|
| 91 |
template<typename T> |
| 92 |
inline T spvTextureSwizzle(T x, uint s) |
| 93 |
{ |
| 94 |
return spvTextureSwizzle(vec<T, 4>(x, 0, 0, 1), s).x; |
| 95 |
} |
| 96 |
|
| 97 |
fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]], constant uint* spvSwizzleConstants [[buffer(30)]]) |
| 98 |
{ |
| 99 |
main0_out out = {}; |
| 100 |
constant uint* spvDescriptorSet0_uSamplerSwzl = &spvDescriptorSet0.spvSwizzleConstants[0]; |
| 101 |
out.FragColor = spvTextureSwizzle(spvDescriptorSet0.uSampler[(*spvDescriptorSet0.uUBO).index].sample(spvDescriptorSet0.uSamplerSmplr[(*spvDescriptorSet0.uUBO).index], in.vUV), spvDescriptorSet0_uSamplerSwzl[(*spvDescriptorSet0.uUBO).index]); |
| 102 |
out.FragColor += spvTextureSwizzle(spvDescriptorSet0.uSampler[(*spvDescriptorSet0.m_50).index2].sample(spvDescriptorSet0.uSamplerSmplr[(*spvDescriptorSet0.m_50).index2], in.vUV), spvDescriptorSet0_uSamplerSwzl[(*spvDescriptorSet0.m_50).index2]); |
| 103 |
return out; |
| 104 |
} |
| 105 |
|