Debian Codegraph @

third_party/spirv-cross/reference/opt/shaders-msl/frag/array-of-texture-swizzle.msl2.argument.discrete.swizzle.frag

raw
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 spvDescriptorSetBuffer0
9 {
10 array<texture2d<float>, 4> uSampler0 [[id(0)]];
11 array<sampler, 4> uSampler0Smplr [[id(4)]];
12 constant uint* spvSwizzleConstants [[id(8)]];
13 };
14
15 struct main0_out
16 {
17 float4 FragColor [[color(0)]];
18 };
19
20 struct main0_in
21 {
22 float2 vUV [[user(locn0)]];
23 };
24
25 template<typename T> struct spvRemoveReference { typedef T type; };
26 template<typename T> struct spvRemoveReference<thread T&> { typedef T type; };
27 template<typename T> struct spvRemoveReference<thread T&&> { typedef T type; };
28 template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type& x)
29 {
30 return static_cast<thread T&&>(x);
31 }
32 template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type&& x)
33 {
34 return static_cast<thread T&&>(x);
35 }
36
37 enum class spvSwizzle : uint
38 {
39 none = 0,
40 zero,
41 one,
42 red,
43 green,
44 blue,
45 alpha
46 };
47
48 template<typename T>
49 inline T spvGetSwizzle(vec<T, 4> x, T c, spvSwizzle s)
50 {
51 switch (s)
52 {
53 case spvSwizzle::none:
54 return c;
55 case spvSwizzle::zero:
56 return 0;
57 case spvSwizzle::one:
58 return 1;
59 case spvSwizzle::red:
60 return x.r;
61 case spvSwizzle::green:
62 return x.g;
63 case spvSwizzle::blue:
64 return x.b;
65 case spvSwizzle::alpha:
66 return x.a;
67 }
68 }
69
70 // Wrapper function that swizzles texture samples and fetches.
71 template<typename T>
72 inline vec<T, 4> spvTextureSwizzle(vec<T, 4> x, uint s)
73 {
74 if (!s)
75 return x;
76 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)));
77 }
78
79 template<typename T>
80 inline T spvTextureSwizzle(T x, uint s)
81 {
82 return spvTextureSwizzle(vec<T, 4>(x, 0, 0, 1), s).x;
83 }
84
85 fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]], constant uint* spvSwizzleConstants [[buffer(30)]], texture2d<float> uSampler1 [[texture(0)]], sampler uSampler1Smplr [[sampler(0)]])
86 {
87 main0_out out = {};
88 constant uint* spvDescriptorSet0_uSampler0Swzl = &spvDescriptorSet0.spvSwizzleConstants[0];
89 constant uint& uSampler1Swzl = spvSwizzleConstants[0];
90 out.FragColor = spvTextureSwizzle(spvDescriptorSet0.uSampler0[2].sample(spvDescriptorSet0.uSampler0Smplr[2], in.vUV), spvDescriptorSet0_uSampler0Swzl[2]);
91 float4 _73 = spvTextureSwizzle(uSampler1.sample(uSampler1Smplr, in.vUV), uSampler1Swzl);
92 out.FragColor += _73;
93 out.FragColor += spvTextureSwizzle(spvDescriptorSet0.uSampler0[1].sample(spvDescriptorSet0.uSampler0Smplr[1], in.vUV), spvDescriptorSet0_uSampler0Swzl[1]);
94 out.FragColor += _73;
95 return out;
96 }
97