startup: the 64-bit vector shifts have no lowering (1 of the remaining loading-screen shader refusals) #1810

Closed
opened 2026-11-24 19:09:53 +00:00 by triggered02 · 0 comments
triggered02 commented 2026-11-24 19:09:53 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T19:09:53Z.


Found in the refusal census (#870). 1 refused shader, and the operation had no lowering:

v_lshrrev_b64 v[10:11], 0, 0    -> REFUSED: v_lshrrev_b64

Problem

The 64-bit vector shifts (v_lshlrev_b64, v_lshrrev_b64, v_ashrrev_i64) had no lowering. tools/pixel_aot.py implements them for the pixel AOT path with explicit per-word temporaries; this translator represents registers as single HLSL variables, so the naive version has two traps:

  • a 32-bit HLSL shift by 32 or more is undefined, so sh < 32 and sh >= 32 must be separate cases;
  • an in-place destination (v[10:11] = v[10:11] >> n) must read both original words before writing either.

Fix

Three helpers in the shader preamble take the low and high words by value, mask the count to six bits, and return the result packed as a uint2:

uint2 shr64u(uint lo, uint hi, uint sh) { sh &= 63u; uint sb = sh & 31u, sc = (32u - sb) & 31u;
    uint cy = sb == 0u ? 0u : (hi << sc); uint h = hi >> sb;
    return uint2(sh < 32u ? ((lo >> sb) | cy) : h, sh < 32u ? h : 0u); }

The handler writes both words in one statement, which makes the in-place case safe by construction:

v_lshrrev_b64 v[10:11], 0, 0    -> { uint2 t = shr64u(0u, 0u, 0x00000000u); v10 = t.x; v11 = t.y; }
v_lshlrev_b64 v[10:11], v8, v[8:9] -> { uint2 t = shl64(v8, v9, v8); v10 = t.x; v11 = t.y; }

Sources may be a VGPR pair, an SGPR pair or an integer inline constant; the low word always shifts unsigned and only v_ashrrev_i64 signs the high word.

Test

startup_gfx2hlsl_b64_shift builds VOP3A encodings from the checked-in decoder's layout (prefix 0b110101, opcodes 0x2ff/0x300/0x301, low destination in w0[7:0], count in w1[8:0], value in w1[17:9]), decodes them, then translates. Nine checks: all three shifts use their own helper, both destination words are written, the census form lowers to a zero pair, an inline constant count stays a constant, and the three helpers are in the preamble with the count masked.

dev:     19/21 passed - the 2 failures are pre-existing on main (see below)
release: startup_gfx2hlsl_b64_shift Passed 0.14 s

Fail-first: pointing the right shift at the left-shift helper fails the census form lowers to a zero pair; dropping the high destination write fails the right shift uses the helper and writes both words; removing the count mask fails the helpers mask the count.

Pre-existing failures, not from this PR

startup_gfx2hlsl_mad_preserve_{warp,hardware} fail in this dev tree with Unknown GPU operation or invalid arguments: --raw-uav-dump-sm62 — the build's offscreen_check is stale. Confirmed identical on origin/main (ecc6e6ce) with the same binary, so it is unrelated to this branch. A rebuild should fix it; I did not touch that tool.

What this does not establish

  • That the emitted HLSL compiles or computes the right values — the test compares text; DXC/WARP were not run here.
  • The 24-bit/b32 shift forms and any use of the result in a draw are out of scope.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6589382261 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1817). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T19:09:53Z. --- Found in the refusal census (#870). **1** refused shader, and the operation had no lowering: ``` v_lshrrev_b64 v[10:11], 0, 0 -> REFUSED: v_lshrrev_b64 ``` ## Problem The 64-bit vector shifts (`v_lshlrev_b64`, `v_lshrrev_b64`, `v_ashrrev_i64`) had no lowering. `tools/pixel_aot.py` implements them for the pixel AOT path with explicit per-word temporaries; this translator represents registers as single HLSL variables, so the naive version has two traps: - a 32-bit HLSL shift by 32 or more is undefined, so `sh < 32` and `sh >= 32` must be separate cases; - an in-place destination (`v[10:11] = v[10:11] >> n`) must read both original words before writing either. ## Fix Three helpers in the shader preamble take the low and high words **by value**, mask the count to six bits, and return the result packed as a `uint2`: ```hlsl uint2 shr64u(uint lo, uint hi, uint sh) { sh &= 63u; uint sb = sh & 31u, sc = (32u - sb) & 31u; uint cy = sb == 0u ? 0u : (hi << sc); uint h = hi >> sb; return uint2(sh < 32u ? ((lo >> sb) | cy) : h, sh < 32u ? h : 0u); } ``` The handler writes both words in one statement, which makes the in-place case safe by construction: ``` v_lshrrev_b64 v[10:11], 0, 0 -> { uint2 t = shr64u(0u, 0u, 0x00000000u); v10 = t.x; v11 = t.y; } v_lshlrev_b64 v[10:11], v8, v[8:9] -> { uint2 t = shl64(v8, v9, v8); v10 = t.x; v11 = t.y; } ``` Sources may be a VGPR pair, an SGPR pair or an integer inline constant; the low word always shifts unsigned and only `v_ashrrev_i64` signs the high word. ## Test `startup_gfx2hlsl_b64_shift` builds VOP3A encodings from the checked-in decoder's layout (prefix `0b110101`, opcodes `0x2ff`/`0x300`/`0x301`, low destination in `w0[7:0]`, count in `w1[8:0]`, value in `w1[17:9]`), decodes them, then translates. Nine checks: all three shifts use their own helper, both destination words are written, the census form lowers to a zero pair, an inline constant count stays a constant, and the three helpers are in the preamble with the count masked. ``` dev: 19/21 passed - the 2 failures are pre-existing on main (see below) release: startup_gfx2hlsl_b64_shift Passed 0.14 s ``` Fail-first: pointing the right shift at the left-shift helper fails *the census form lowers to a zero pair*; dropping the high destination write fails *the right shift uses the helper and writes both words*; removing the count mask fails *the helpers mask the count*. ## Pre-existing failures, not from this PR `startup_gfx2hlsl_mad_preserve_{warp,hardware}` fail in this dev tree with `Unknown GPU operation or invalid arguments: --raw-uav-dump-sm62` — the build's `offscreen_check` is stale. **Confirmed identical on `origin/main` (`ecc6e6ce`)** with the same binary, so it is unrelated to this branch. A rebuild should fix it; I did not touch that tool. ## What this does not establish - That the emitted HLSL compiles or computes the right values — the test compares text; DXC/WARP were not run here. - The 24-bit/b32 shift forms and any use of the result in a draw are out of scope. AI-assisted (Claude Code).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#1810
No description provided.