From 4fc21bdbec35ff88ca08d717f28abf5e10eef8a0 Mon Sep 17 00:00:00 2001 From: Pooldead Date: Sat, 5 Dec 2026 23:24:23 +0100 Subject: [PATCH] shaders: e4a9f58e3acfcf7b, project quad lanes that miss the decal box CS_ProjDecalResolve_Scalarized took, for a quad lane in the loop that failed the decal's box test, the registers the pass's head wrote (0, cz, cx, cy, a half of the decal's dword 0xd0 + P) as its texture coordinate for the coarse derivatives. Those are world positions, not coordinates: at render widths that are not a multiple of 128 (3440 x 1440 native, 2288 x 960 under DLSS quality at 3440) the ground showed black 8 x 8 tiles. Now such a lane gives the coordinate projected at its own position for this decal, as c4183d3cbee28e8e (the vectorized resolve) already does. Co-Authored-By: Claude Opus 5.5 --- shaders/replace/e4a9f58e3acfcf7b.compute.hlsl | 68 ++++++++----------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/shaders/replace/e4a9f58e3acfcf7b.compute.hlsl b/shaders/replace/e4a9f58e3acfcf7b.compute.hlsl index ea84d01..5b808d8 100644 --- a/shaders/replace/e4a9f58e3acfcf7b.compute.hlsl +++ b/shaders/replace/e4a9f58e3acfcf7b.compute.hlsl @@ -69,12 +69,12 @@ // console lane holds it in the sample's address registers: // - a lane in the loop that passed the box test (0x1ef8): the coordinate it computed, a function of its // position (published at barrier A) and of the decal's projection, which is the same for every lane; -// - a lane in the loop that failed it (inactive at the sample: EXEC is the passed lanes from 0x1ef8 to -// 0x2c78, so this too rests on the derivatives reading an inactive lane's registers, below): the -// registers the pass's head wrote under the head's EXEC and the body did not write again: v43 = v44 = 0 (0x1d50, 0x1d54; the colour, both two-channel textures and -// the single channel), v53 = 0 and v54 = cz (0x1d28, 0x1ea4; the first mask), v54 = cz and v65 = the -// half at bits 16-31 of the decal's dword 0xd0 + P (0x1e2c; the second mask), v55 = cx and v56 = cy -// (0x1e98, 0x1e8c; the third mask). Each is the same for every lane and is computed here. +// - a lane in the loop that failed it: on the console it is inactive at the sample (EXEC is the passed +// lanes from 0x1ef8 to 0x2c78) and its address registers hold what the pass's head wrote (0, cz, cx, +// cy, a half of the decal's dword 0xd0 + P: world positions, not coordinates). Here, as in +// c4183d3cbee28e8e, the coordinate is computed at that lane's position for this decal, like a lane +// that passed. Taking the head's registers gave black squares on the ground at render widths that +// are not a multiple of 128 (3440 x 1440), most likely through gradients of world-position size. // In a uniform loop every pixel inside the target is in the loop, so the only other quad lanes are // outside the target, which wrote none of these registers: below. // - 0x2e74-0x2f68 (after the loop): ds_swizzle of the turned normal (v19, v20, v18), a result of the pixel's @@ -93,9 +93,7 @@ // ds_swizzle returns an inactive source lane's register as it stands (rather than zero). // - An implicit derivative from a quad lane outside the target: its address registers were never written // by this program; here the reading thread's own coordinate is used in its place. Not verified on the -// console: that the hardware's derivatives read an inactive lane's address registers as they stand -// (the lanes that failed the box test, above, and the lanes outside the target alike), that they are -// coarse, and that a quad is lanes 4k to 4k + 3 with lane 1 at +x and lane 2 at +y. +// console: that they are coarse, and that a quad is lanes 4k to 4k + 3 with lane 1 at +x and lane 2 at +y. // // Arithmetic as the console does it: v_mul_legacy_f32 is mul_legacy (0 times anything is +0), // v_fma_f32 / v_fmac_f32 / v_fma_mix_f32 is mad (a v_fma_mix_f32 with the factor 1.0, at 0x2480, 0x2498, @@ -440,35 +438,29 @@ float box_d2(Box bx, float3 p) return d2; } -// The quad's lanes 0, 1, 2 in a uniform loop, for one decal: how each holds a sample's coordinate. -static const uint Q_OWN = 0u; // outside the target: the reading thread's own coordinate -static const uint Q_FAILED = 1u; // in the loop, failed the box test: the registers the pass's head wrote -static const uint Q_PASSED = 2u; // in the loop, passed it: the coordinate at its u, v -struct QuadUV { uint s0, s1, s2; float2 l0, l1, l2; }; +// The quad's lanes 0, 1, 2 in a uniform loop, for one decal: whether each is in the loop, and its u, v +// there (a lane in the loop, inside the decal's box or not, gives the coordinate at its own position; +// one outside the target gives the reading thread's own coordinate). +struct QuadUV { bool i0, i1, i2; float2 l0, l1, l2; }; -uint quad_state(Box bx, uint j) -{ - if ((lane_flags[j] & LIVE) == 0u) return Q_OWN; - return (1.0f > box_d2(bx, lane_pos[j])) ? Q_PASSED : Q_FAILED; -} -float2 quad_uv(Projection m, uint j, float2 own) { return (lane_flags[j] & LIVE) != 0u ? project(m, lane_pos[j]) : own; } +bool quad_live(uint j) { return (lane_flags[j] & LIVE) != 0u; } +float2 quad_uv(Projection m, uint j, float2 own) { return quad_live(j) ? project(m, lane_pos[j]) : own; } -float2 quad_coord(uint s, float2 uv, float2 own, float2 failed, float2 off, float2 scale) +float2 quad_coord(bool live, float2 uv, float2 own, float2 off, float2 scale) { - return s == Q_PASSED ? coord(uv, off, scale) : (s == Q_FAILED ? failed : own); + return live ? coord(uv, off, scale) : own; } // A sample of a decal texture (descriptor word `w`, the console's heap byte w << 5) at the coordinate the // lane computed from (u, v): with the quad's coarse derivatives in a uniform loop, at level 0 in another. -// `failed` is the coordinate a quad lane that failed the box test holds in the sample's registers. -float4 decal_sample(uint w, float2 uv, float2 off, float2 scale, float2 failed, bool uniform_loop, QuadUV q) +float4 decal_sample(uint w, float2 uv, float2 off, float2 scale, bool uniform_loop, QuadUV q) { Texture2D t = tex(heap_slot(w << 5u)); precise float2 c = coord(uv, off, scale); [branch] if (uniform_loop) { - precise float2 c0 = quad_coord(q.s0, q.l0, c, failed, off, scale); - precise float2 gx = quad_coord(q.s1, q.l1, c, failed, off, scale) - c0; - precise float2 gy = quad_coord(q.s2, q.l2, c, failed, off, scale) - c0; + precise float2 c0 = quad_coord(q.i0, q.l0, c, off, scale); + precise float2 gx = quad_coord(q.i1, q.l1, c, off, scale) - c0; + precise float2 gy = quad_coord(q.i2, q.l2, c, off, scale) - c0; return t.SampleGrad(decal_sampler, c, gx, gy); } return t.SampleLevel(decal_sampler, c, 0.0f); @@ -546,9 +538,9 @@ void apply_decal(Common g, Pixel p, uint d, inout Blend acc) precise float dvy = mad(-R.w, dby, -uv.y); // v51 QuadUV q; - q.s0 = Q_OWN; q.s1 = Q_OWN; q.s2 = Q_OWN; q.l0 = uv; q.l1 = uv; q.l2 = uv; + q.i0 = false; q.i1 = false; q.i2 = false; q.l0 = uv; q.l1 = uv; q.l2 = uv; [branch] if (g.all_in) { - q.s0 = quad_state(bxs, p.quad); q.s1 = quad_state(bxs, p.quad + 1u); q.s2 = quad_state(bxs, p.quad + 2u); + q.i0 = quad_live(p.quad); q.i1 = quad_live(p.quad + 1u); q.i2 = quad_live(p.quad + 2u); q.l0 = quad_uv(pr, p.quad, uv); q.l1 = quad_uv(pr, p.quad + 1u, uv); q.l2 = quad_uv(pr, p.quad + 2u, uv); } @@ -557,8 +549,7 @@ void apply_decal(Common g, Pixel p, uint d, inout Blend acc) uint n93 = w93 & 0xffu, n24 = m24 & 31u; precise float2 off1 = float2(float(n93 & ((1u << n24) - 1u)), float(n93 >> n24)); // v46, v45 precise float2 sc1 = float2(K255 * ubyte(m24, 2u), K255 * ubyte(m24, 3u)); // v48, v47 - const float2 zero2 = float2(0.0f, 0.0f); // v44, v43 of a lane that failed the box test (0x1d50) - precise float4 t1 = decal_sample(m0_.x, uv, off1, sc1, zero2, g.all_in, q); // v45 .. v48 + precise float4 t1 = decal_sample(m0_.x, uv, off1, sc1, g.all_in, q); // v45 .. v48 // 0x21bc-0x2500: two masks, from the material's second texture at three places of an atlas. bool atlas = (ld(s_decals, dr + 0x94u + P) & 1u) == 0u; // s[56:57] @@ -567,12 +558,10 @@ void apply_decal(Common g, Pixel p, uint d, inout Blend acc) precise float ma = t1.w; // v53 if (atlas) { uint b = (w93 >> 8u) & 0xffu; - ma = decal_sample(m16_.x, uv, float2(float(b & mask28), float(b >> n28)), sc2, float2(0.0f, cz), - g.all_in, q).x; + ma = decal_sample(m16_.x, uv, float2(float(b & mask28), float(b >> n28)), sc2, g.all_in, q).x; } uint b2_ = (w93 >> 16u) & 0xffu; - precise float t3 = decal_sample(m16_.x, uv, float2(float(b2_ & mask28), float(b2_ >> n28)), sc2, - float2(cz, f69h), g.all_in, q).x; // v66 + precise float t3 = decal_sample(m16_.x, uv, float2(float(b2_ & mask28), float(b2_ >> n28)), sc2, g.all_in, q).x; // v66 precise float h1 = f16hi(wb0.x), h2 = f16lo(wb0.y); // s84; dword 0xb4 + P, read again at 0x2460 ma = saturate(mul_legacy((-1.0f + h0) + ma, 1.0f / h0)); ma = saturate(mul_legacy(ma - h1, 1.0f / (h2 - h1))); @@ -586,8 +575,7 @@ void apply_decal(Common g, Pixel p, uint d, inout Blend acc) precise float mc = t1.w; // v54 from 0x24fc if (atlas) { uint b = w93 >> 24u; - mc = decal_sample(m16_.x, uv, float2(float(b & mask28), float(b >> n28)), sc2, float2(cx, cy), - g.all_in, q).x; + mc = decal_sample(m16_.x, uv, float2(float(b & mask28), float(b >> n28)), sc2, g.all_in, q).x; } // 0x2648-0x270c. @@ -604,10 +592,10 @@ void apply_decal(Common g, Pixel p, uint d, inout Blend acc) ww = mad(asfloat(ld(s_views, vr + g.mask_off)), f77l, 0.0f); // dword 0xcc + P, read again // 0x2710-0x2814: two two-channel textures. - precise float2 t5 = decal_sample(m0_.z, uv, off1, sc1, zero2, g.all_in, q).xy; // v56, v57 + precise float2 t5 = decal_sample(m0_.z, uv, off1, sc1, g.all_in, q).xy; // v56, v57 precise float s77 = saturate(f16lo(wa0.z) + t5.x); precise float s73 = saturate(f16hi(wa0.z) + t5.y); - precise float2 t6 = decal_sample(m0_.y, uv, off1, sc1, zero2, g.all_in, q).xy; // v58, v59 + precise float2 t6 = decal_sample(m0_.y, uv, off1, sc1, g.all_in, q).xy; // v58, v59 // 0x2868-0x2ac0: the decal's normal in the tangent frame. precise float ny = mad(t6.y, 2.0f, -1.0f); // v59 @@ -710,7 +698,7 @@ void apply_decal(Common g, Pixel p, uint d, inout Blend acc) precise float o87 = mul_legacy(l69, v96); // v48 // 0x2ac4-0x2b9c: a single channel and the weights it gives. - precise float t7 = decal_sample(m16_.y, uv, off1, sc1, zero2, g.all_in, q).x; // v38 + precise float t7 = decal_sample(m16_.y, uv, off1, sc1, g.all_in, q).x; // v38 precise float t7c = 1.0f - t7; precise float w52 = mad(asfloat(0x3f733333u), f70h, 0.0f); precise float w71 = mad(am, f16hi(wc0.y), 0.0f);