yum-mirror/glslang

git clone https://git.yummers.dev/yum-mirror/glslang

Ralph Potterfix 32-bit identity fillers in 16-bit matrix constructorsee3ae468

main
1.8 KiB67 linesraw
1#version 450
2
3#extension GL_EXT_shader_explicit_arithmetic_types_float16 : require
4
5// A 16-bit counterpart to spv.matrix.frag, covering the same matrix operations
6// at half precision. Two deliberate departures from that shader: the version is
7// 450 because the explicit arithmetic types extension is not available at 420,
8// and the operands are converted from a 32-bit input rather than declared as
9// f16 fragment inputs, which would additionally need GL_EXT_shader_16bit_storage.
10
11layout(location = 0) in vec4 src;
12
13layout(location = 0) out vec4 color;
14
15void main()
16{
17    f16mat3x4 m1 = f16mat3x4(float16_t(src.x));
18    f16mat3x4 m2 = f16mat3x4(float16_t(src.y));
19    float16_t f  = float16_t(src.z);
20    f16vec3   v3 = f16vec3(float16_t(src.w));
21    f16vec4   v4 = f16vec4(float16_t(src.x));
22
23    f16mat3x4 sum34;
24    dmat3x4   dm;
25    f16vec3   sum3;
26    f16vec4   sum4;
27
28    sum34 = m1 - m2;
29    sum34 += m1 * f;
30    sum34 += f * m1;
31    sum34 /= matrixCompMult(m1, m2);
32    sum34 += m1 / f;
33    sum34 += f / m1;
34    sum34 += f;
35    sum34 -= f;
36    dm = dmat3x4(sum34);
37    sum34 = f16mat3x4(dm);
38
39    sum3 = v4 * m2;
40    sum4 = m2 * v3;
41
42    f16mat4x3 m43 = transpose(sum34);
43    f16mat4   m4  = m1 * m43;
44
45    sum4 = v4 * m4;
46
47    f16vec4 acc = sum4;
48
49    ++sum34;
50    --sum34;
51
52    sum34 += f16mat3x4(f);
53    sum34 += f16mat3x4(v3, f, v3, f, v3, f);
54
55    acc += sum3 * m43 + sum4;
56
57    acc += f16vec4(m43);
58    acc += f16vec4(f16vec3(f16mat2(f)), 7.2hf);
59
60    // Beyond what spv.matrix.frag covers. Growing a matrix from a smaller one
61    // leaves the trailing diagonal at the identity, and is the only construction
62    // that uses the one filler rather than just the zero filler.
63    f16mat4 grown = f16mat4(f16mat2(f));
64    acc += f16vec4(grown[3][3]);
65
66    color = vec4(acc);
67}