Debian Codegraph @

third_party/spirv-cross/reference/shaders-msl/frag/shader-arithmetic-8bit.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 SSBO
9 {
10 char i8[16];
11 uchar u8[16];
12 };
13
14 struct Push
15 {
16 char i8;
17 uchar u8;
18 };
19
20 struct UBO
21 {
22 char i8;
23 uchar u8;
24 };
25
26 struct main0_out
27 {
28 int4 FragColorInt [[color(0)]];
29 uint4 FragColorUint [[color(1)]];
30 };
31
32 struct main0_in
33 {
34 int4 vColor [[user(locn0)]];
35 };
36
37 static inline __attribute__((always_inline))
38 void packing_int8(device SSBO& ssbo)
39 {
40 short i16 = short(10);
41 int i32 = 20;
42 char2 i8_2 = as_type<char2>(i16);
43 char4 i8_4 = as_type<char4>(i32);
44 i16 = as_type<short>(i8_2);
45 i32 = as_type<int>(i8_4);
46 ssbo.i8[0] = i8_4.x;
47 ssbo.i8[1] = i8_4.y;
48 ssbo.i8[2] = i8_4.z;
49 ssbo.i8[3] = i8_4.w;
50 }
51
52 static inline __attribute__((always_inline))
53 void packing_uint8(device SSBO& ssbo)
54 {
55 ushort u16 = ushort(10);
56 uint u32 = 20u;
57 uchar2 u8_2 = as_type<uchar2>(u16);
58 uchar4 u8_4 = as_type<uchar4>(u32);
59 u16 = as_type<ushort>(u8_2);
60 u32 = as_type<uint>(u8_4);
61 ssbo.u8[0] = u8_4.x;
62 ssbo.u8[1] = u8_4.y;
63 ssbo.u8[2] = u8_4.z;
64 ssbo.u8[3] = u8_4.w;
65 }
66
67 static inline __attribute__((always_inline))
68 void compute_int8(device SSBO& ssbo, thread int4& vColor, constant Push& registers, constant UBO& ubo, thread int4& FragColorInt)
69 {
70 char4 tmp = char4(vColor);
71 tmp += char4(registers.i8);
72 tmp += char4(char(-40));
73 tmp += char4(-50);
74 tmp += char4(char(10), char(20), char(30), char(40));
75 tmp += char4(ssbo.i8[4]);
76 tmp += char4(ubo.i8);
77 FragColorInt = int4(tmp);
78 }
79
80 static inline __attribute__((always_inline))
81 void compute_uint8(device SSBO& ssbo, thread int4& vColor, constant Push& registers, constant UBO& ubo, thread uint4& FragColorUint)
82 {
83 uchar4 tmp = uchar4(char4(vColor));
84 tmp += uchar4(registers.u8);
85 tmp += uchar4(uchar(216));
86 tmp += uchar4(206);
87 tmp += uchar4(uchar(10), uchar(20), uchar(30), uchar(40));
88 tmp += uchar4(ssbo.u8[4]);
89 tmp += uchar4(ubo.u8);
90 FragColorUint = uint4(tmp);
91 }
92
93 fragment main0_out main0(main0_in in [[stage_in]], device SSBO& ssbo [[buffer(0)]], constant Push& registers [[buffer(1)]], constant UBO& ubo [[buffer(2)]])
94 {
95 main0_out out = {};
96 packing_int8(ssbo);
97 packing_uint8(ssbo);
98 compute_int8(ssbo, in.vColor, registers, ubo, out.FragColorInt);
99 compute_uint8(ssbo, in.vColor, registers, ubo, out.FragColorUint);
100 return out;
101 }
102