#pragma clang diagnostic ignored "-Wmissing-prototypes" #include #include using namespace metal; struct spvDescriptorSetBuffer0 { array, 4> uSampler0 [[id(0)]]; array uSampler0Smplr [[id(4)]]; constant uint* spvSwizzleConstants [[id(8)]]; }; struct main0_out { float4 FragColor [[color(0)]]; }; struct main0_in { float2 vUV [[user(locn0)]]; }; enum class spvSwizzle : uint { none = 0, zero, one, red, green, blue, alpha }; template struct spvRemoveReference { typedef T type; }; template struct spvRemoveReference { typedef T type; }; template struct spvRemoveReference { typedef T type; }; template inline constexpr thread T&& spvForward(thread typename spvRemoveReference::type& x) { return static_cast(x); } template inline constexpr thread T&& spvForward(thread typename spvRemoveReference::type&& x) { return static_cast(x); } template inline T spvGetSwizzle(vec x, T c, spvSwizzle s) { switch (s) { case spvSwizzle::none: return c; case spvSwizzle::zero: return 0; case spvSwizzle::one: return 1; case spvSwizzle::red: return x.r; case spvSwizzle::green: return x.g; case spvSwizzle::blue: return x.b; case spvSwizzle::alpha: return x.a; } } // Wrapper function that swizzles texture samples and fetches. template inline vec spvTextureSwizzle(vec x, uint s) { if (!s) return x; return vec(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))); } template inline T spvTextureSwizzle(T x, uint s) { return spvTextureSwizzle(vec(x, 0, 0, 1), s).x; } // Wrapper function that swizzles texture gathers. template inline vec spvGatherSwizzle(sampler s, const thread Tex& t, Ts... params, component c, uint sw) METAL_CONST_ARG(c) { if (sw) { switch (spvSwizzle((sw >> (uint(c) * 8)) & 0xFF)) { case spvSwizzle::none: break; case spvSwizzle::zero: return vec(0, 0, 0, 0); case spvSwizzle::one: return vec(1, 1, 1, 1); case spvSwizzle::red: return t.gather(s, spvForward(params)..., component::x); case spvSwizzle::green: return t.gather(s, spvForward(params)..., component::y); case spvSwizzle::blue: return t.gather(s, spvForward(params)..., component::z); case spvSwizzle::alpha: return t.gather(s, spvForward(params)..., component::w); } } switch (c) { case component::x: return t.gather(s, spvForward(params)..., component::x); case component::y: return t.gather(s, spvForward(params)..., component::y); case component::z: return t.gather(s, spvForward(params)..., component::z); case component::w: return t.gather(s, spvForward(params)..., component::w); } } // Wrapper function that swizzles depth texture gathers. template inline vec spvGatherCompareSwizzle(sampler s, const thread Tex& t, Ts... params, uint sw) { if (sw) { switch (spvSwizzle(sw & 0xFF)) { case spvSwizzle::none: case spvSwizzle::red: break; case spvSwizzle::zero: case spvSwizzle::green: case spvSwizzle::blue: case spvSwizzle::alpha: return vec(0, 0, 0, 0); case spvSwizzle::one: return vec(1, 1, 1, 1); } } return t.gather_compare(s, spvForward(params)...); } fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]], constant uint* spvSwizzleConstants [[buffer(30)]], texture2d uSampler1 [[texture(0)]], sampler uSampler1Smplr [[sampler(0)]]) { main0_out out = {}; constant uint* spvDescriptorSet0_uSampler0Swzl = &spvDescriptorSet0.spvSwizzleConstants[0]; constant uint& uSampler1Swzl = spvSwizzleConstants[0]; out.FragColor = spvTextureSwizzle(spvDescriptorSet0.uSampler0[2].sample(spvDescriptorSet0.uSampler0Smplr[2], in.vUV), spvDescriptorSet0_uSampler0Swzl[2]); out.FragColor += spvTextureSwizzle(uSampler1.sample(uSampler1Smplr, in.vUV), uSampler1Swzl); out.FragColor += spvTextureSwizzle(spvDescriptorSet0.uSampler0[1].sample(spvDescriptorSet0.uSampler0Smplr[1], in.vUV), spvDescriptorSet0_uSampler0Swzl[1]); out.FragColor += spvTextureSwizzle(uSampler1.sample(uSampler1Smplr, in.vUV), uSampler1Swzl); return out; }