Skip to content

Commit 407aa73

Browse files
committed
Reapply "Make use of Iris' new features in mc1.21.9"
This reapplies commit ed4b971.
1 parent 49bf728 commit 407aa73

17 files changed

+78
-107
lines changed

shaders/composite2.csh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ void main() {
225225
bvec2 e = greaterThanEqual(texelFetch(edgeS, texel, 0).rg, vec2(0.5));
226226

227227
if (any(e)) {
228-
immut vec2 view_size = view_size();
228+
immut vec2 view_size = vec2(view_size());
229229
immut vec2 texel_size = 1.0 / view_size;
230230

231231
immut vec2 texel_coord = vec2(texel) + 0.5;

shaders/composite3.csh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ f16vec3 blend_color(f16vec2 blend_weight, vec3 color_0, vec3 color_1) {
2929

3030
void main() {
3131
immut i16vec2 texel = i16vec2(gl_GlobalInvocationID.xy);
32-
immut i8vec2 nbh_pos = i8vec2(gl_LocalInvocationID.xy) + int8_t(1);
32+
immut u8vec2 nbh_pos = u8vec2(gl_LocalInvocationID.xy) + uint8_t(1u);
3333

3434
f16vec3 color;
3535

@@ -111,7 +111,7 @@ void main() {
111111
#include "/lib/nbh/border_cornered.glsl"
112112

113113
if (border_offset != i8vec2(0)) {
114-
immut i8vec2 border_pos = nbh_pos + border_offset;
114+
immut u8vec2 border_pos = u8vec2(i8vec2(nbh_pos) + border_offset);
115115
nbh[border_pos.x][border_pos.y] = offset_color;
116116
}
117117
}
@@ -146,17 +146,17 @@ void main() {
146146
// d e f
147147
// g h i
148148
immut f16vec3[3][3] cas_nbh = f16vec3[3][3](f16vec3[3](
149-
nbh[nbh_pos.x - int8_t(1)][nbh_pos.y - int8_t(1)],
150-
nbh[nbh_pos.x - int8_t(1)][nbh_pos.y],
151-
nbh[nbh_pos.x - int8_t(1)][nbh_pos.y + int8_t(1)]
149+
nbh[nbh_pos.x - uint8_t(1u)][nbh_pos.y - uint8_t(1u)],
150+
nbh[nbh_pos.x - uint8_t(1u)][nbh_pos.y],
151+
nbh[nbh_pos.x - uint8_t(1u)][nbh_pos.y + uint8_t(1u)]
152152
), f16vec3[3](
153-
nbh[nbh_pos.x][nbh_pos.y - int8_t(1)],
153+
nbh[nbh_pos.x][nbh_pos.y - uint8_t(1u)],
154154
color,
155-
nbh[nbh_pos.x][nbh_pos.y + int8_t(1)]
155+
nbh[nbh_pos.x][nbh_pos.y + uint8_t(1u)]
156156
), f16vec3[3](
157-
nbh[nbh_pos.x + int8_t(1)][nbh_pos.y - int8_t(1)],
158-
nbh[nbh_pos.x + int8_t(1)][nbh_pos.y],
159-
nbh[nbh_pos.x + int8_t(1)][nbh_pos.y + int8_t(1)]
157+
nbh[nbh_pos.x + uint8_t(1u)][nbh_pos.y - uint8_t(1u)],
158+
nbh[nbh_pos.x + uint8_t(1u)][nbh_pos.y],
159+
nbh[nbh_pos.x + uint8_t(1u)][nbh_pos.y + uint8_t(1u)]
160160
));
161161

162162
// Soft min. and max.

shaders/deferred1.csh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ uniform layout(rgba16f) restrict image2D colorimg1;
4141
#include "/lib/sm/shadows.glsl"
4242
#include "/lib/srgb.glsl"
4343
#include "/lib/fog.glsl"
44+
// #include "/lib/u16_unpack3.glsl"
4445

4546
#ifdef LIGHT_LEVELS
4647
#include "/lib/llv.glsl"
@@ -232,7 +233,7 @@ void main() {
232233
immut f16vec3 w_rel_light = f16vec3(vec3(
233234
light_data & 511u,
234235
bitfieldExtract(light_data, 9, 9),
235-
bitfieldExtract(light_data, 18, 9)
236+
bitfieldExtract(light_data, 18, 9)
236237
) + offset);
237238
238239
immut float16_t intensity = float16_t(bitfieldExtract(light_data.x, 27, 4));
@@ -257,10 +258,16 @@ void main() {
257258
258259
immut f16vec3 illum = brightness * f16vec3(
259260
(light_color >> uint16_t(6u)) & uint16_t(31u),
260-
light_color & uint16_t(63u),
261-
(light_color >> uint16_t(11u))
261+
light_color & uint16_t(63u),
262+
(light_color >> uint16_t(11u))
262263
);
263264
265+
/*
266+
immut f16vec3 illum = brightness * f16vec3(
267+
u16_unpack3(light_color, u16vec2(6, 5)).grb
268+
);
269+
*/
270+
264271
immut float16_t tex_n_dot_l = dot(w_tex_normal, n_w_rel_light);
265272
266273
float16_t light_diffuse = ind_bl; // Very fake GI.

shaders/gbuffers_clouds.fsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ in VertexData { layout(location = 0, component = 0) flat uint tint; } v;
1919
#include "/lib/prng/pcg.glsl"
2020

2121
void main() {
22-
immut vec3 ndc = fma(vec3(gl_FragCoord.xy / view_size(), gl_FragCoord.z), vec3(2.0), vec3(-1.0));
22+
immut vec3 ndc = fma(vec3(gl_FragCoord.xy / vec2(view_size()), gl_FragCoord.z), vec3(2.0), vec3(-1.0));
2323
immut vec3 pe = mat3(gbufferModelViewInverse) * proj_inv(gbufferProjectionInverse, ndc);
2424
immut vec3 world = pe + gbufferModelViewInverse[3].xyz + cameraPosition;
2525

shaders/gbuffers_line.vsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void main() {
2828
vec3 start_ndc = start_clip.xyz / start_clip.w;
2929
immut vec3 end_ndc = end_clip.xyz / end_clip.w;
3030

31-
immut vec2 view_size = view_size();
31+
immut vec2 view_size = vec2(view_size());
3232
immut vec2 dir_screen = normalize((end_ndc.xy - start_ndc.xy) * view_size);
3333
vec2 offset_ndc = float(LINE_WIDTH) / view_size * vec2(-dir_screen.y, dir_screen.x);
3434

shaders/lib/material/normal.glsl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323

2424
immut float lod = textureQueryLod(source, coord).x;
2525
immut ivec2 half_texels = ivec2(
26-
uvec2(
27-
face_tex_size & 65535u,
28-
face_tex_size >> 16u
29-
) / (2u << uint(ceil(lod))) - 1u
26+
unpackUint2x16(face_tex_size) / (uint16_t(2u) << uint16_t(ceil(lod))) - uint16_t(1u)
3027
);
3128

3229
immut f16vec4 bump = f16vec4(

shaders/lib/nbh/border_cornered.glsl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,24 @@
22
// `offset` is the offset from the thread's location in the work group to the location of the border pixel it's processing.
33

44
{
5-
// TODO: make u8vec2 once it works in Iris
6-
immut i8vec2 local = i8vec2(gl_LocalInvocationID.xy);
7-
immut bool up = local.y == int8_t(gl_WorkGroupSize.y - 1u);
5+
immut u8vec2 local = u8vec2(gl_LocalInvocationID.xy);
6+
immut bool up = local.y == uint8_t(gl_WorkGroupSize.y - 1u);
87

9-
if (local.x == int8_t(0) && !up) { // left && !up
8+
if (local.x == uint8_t(0u) && !up) { // left && !up
109
BORDER_OP(ivec2(-1, 0))
11-
} else if (local.y == int8_t(0)) { // down && !left
10+
} else if (local.y == uint8_t(0u)) { // down && !left
1211
BORDER_OP(ivec2(0, -1))
13-
} else if (local.x == int8_t(gl_WorkGroupSize.x - 1u)) { // right && !down
12+
} else if (local.x == uint8_t(gl_WorkGroupSize.x - 1u)) { // right && !down
1413
BORDER_OP(ivec2(1, 0))
1514
} else if (up) { // up && !right
1615
BORDER_OP(ivec2(0, 1))
17-
} else if (local.x == int8_t(1) && local.y >= int8_t(gl_WorkGroupSize.y - 3u)) { // 1 step inside upper left corner || 1 step above that
16+
} else if (local.x == uint8_t(1u) && local.y >= uint8_t(gl_WorkGroupSize.y - 3u)) { // 1 step inside upper left corner || 1 step above that
1817
BORDER_OP(ivec2(-2, 2))
19-
} else if (local.y == int8_t(1) && local.x <= int8_t(2)) { // 1 step inside lower left corner || 1 step to the right of that
18+
} else if (local.y == uint8_t(1u) && local.x <= uint8_t(2u)) { // 1 step inside lower left corner || 1 step to the right of that
2019
BORDER_OP(ivec2(-2, -2))
21-
} else if (local.x == int8_t(gl_WorkGroupSize.x - 2u) && local.y <= int8_t(2)) { // 1 step inside lower right corner || 1 step below that
20+
} else if (local.x == uint8_t(gl_WorkGroupSize.x - 2u) && local.y <= uint8_t(2u)) { // 1 step inside lower right corner || 1 step below that
2221
BORDER_OP(ivec2(2, -2))
23-
} else if (local.y == int8_t(gl_WorkGroupSize.y - 2u) && local.x >= int8_t(gl_WorkGroupSize.x - 3u)) { // 1 step inside upper right corner || 1 step to the left of that
22+
} else if (local.y == uint8_t(gl_WorkGroupSize.y - 2u) && local.x >= uint8_t(gl_WorkGroupSize.x - 3u)) { // 1 step inside upper right corner || 1 step to the left of that
2423
BORDER_OP(ivec2(2, 2))
2524
} else { NON_BORDER_OP }
2625
}

shaders/lib/nbh/border_cornerless.glsl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@
22
// `offset` is the offset from the thread's location in the work group to the location of the edge pixel it's processing.
33

44
{
5-
// TODO: make u8vec2 once it works in Iris
65
// TODO: check: this may be upside down, not that it matters too much
7-
immut i8vec2 local = i8vec2(gl_LocalInvocationID.xy);
8-
immut bool down = local.y == int8_t(gl_WorkGroupSize.y - 1u);
6+
immut u8vec2 local = u8vec2(gl_LocalInvocationID.xy);
7+
immut bool down = local.y == uint8_t(gl_WorkGroupSize.y - 1u);
98

10-
if (local.x == int8_t(0) && !down) { // left && !down
9+
if (local.x == uint8_t(0u) && !down) { // left && !down
1110
BORDER_OP(ivec2(-1, 0))
12-
} else if (local.y == int8_t(0)) { // up && !left
11+
} else if (local.y == uint8_t(0u)) { // up && !left
1312
BORDER_OP(ivec2(0, -1))
14-
} else if (local.x == int8_t(gl_WorkGroupSize.x - 1u)) { // right && !up
13+
} else if (local.x == uint8_t(gl_WorkGroupSize.x - 1u)) { // right && !up
1514
BORDER_OP(ivec2(1, 0))
1615
} else if (down) { // down && !right
1716
BORDER_OP(ivec2(0, 1))
18-
} else if (local == i8vec2(1, gl_WorkGroupSize.x - 2u)) { // 1 step inside lower left corner
17+
} else if (local == u8vec2(1u, gl_WorkGroupSize.x - 2u)) { // 1 step inside lower left corner
1918
BORDER_OP(ivec2(-2, 1))
20-
} else if (local == i8vec2(1)) { // 1 step inside upper left corner
19+
} else if (local == u8vec2(1u)) { // 1 step inside upper left corner
2120
BORDER_OP(ivec2(-1, -2))
22-
} else if (local == i8vec2(gl_WorkGroupSize.x - 2u, 1)) { // 1 step inside upper right corner
21+
} else if (local == u8vec2(gl_WorkGroupSize.x - 2u, 1u)) { // 1 step inside upper right corner
2322
BORDER_OP(ivec2(2, -1))
24-
} else if (local == i8vec2(gl_WorkGroupSize.xy - 2u)) { // 1 step inside lower right corner
23+
} else if (local == u8vec2(gl_WorkGroupSize.xy - 2u)) { // 1 step inside lower right corner
2524
BORDER_OP(ivec2(1, 2))
2625
} else { NON_BORDER_OP }
2726
}

shaders/lib/u16_unpack3.glsl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#ifdef INT16
22
// Functions for packing and unpacking three values from a `uint16_t`, optimized to execute in just 4 and 2 instructions respectively on RDNA4.
3-
// TODO: use when Iris updates glsl-transformer to 2.0.2
43

54
u16vec3 u16_unpack3(
65
uint16_t data,
@@ -15,7 +14,7 @@
1514
// V_PK_MIN_U16
1615
immut u16vec2 masked_01 = min(
1716
u16vec2(data, shifted_12.x),
18-
uint16_t(1u) << size_01 // This can be calculated at compile time if `size_01` is constant.
17+
(uint16_t(1u) << size_01) - uint16_t(1u) // This can be calculated at compile time if `size_01` is constant.
1918
);
2019

2120
return u16vec3(masked_01, shifted_12.y);
@@ -28,7 +27,7 @@
2827
// V_PK_MIN_U16
2928
immut u16vec2 masked_01 = min(
3029
u16vec2(data.x, data.y),
31-
uint16_t(1u) << size_01 // This can be calculated at compile time if `size_01` is constant.
30+
(uint16_t(1u) << size_01) - uint16_t(1u) // This can be calculated at compile time if `size_01` is constant.
3231
);
3332

3433
// V_PK_LSHLREV_B16

shaders/lib/view_size.glsl

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
uniform int packedView;
22

3-
ivec2 view_size() { return ivec2(
4-
packedView & 65535,
5-
packedView >> 16
6-
); }
3+
u16vec2 view_size() {
4+
immut uint packed_view = uint(packedView);
75

8-
/* waiting on Iris glsl-transformer update
9-
u16vec2 view_size() {
10-
return u16vec2(
11-
packedView, // should be truncated for free by the cast, i think
12-
packedView >> 16
13-
);
14-
}
15-
*/
6+
return unpackUint2x16(packed_view);
7+
}

0 commit comments

Comments
 (0)