startup: lower s_bitreplicate_b64_b32 in gfx2hlsl #3030
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3030"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-27T08:50:44Z.
What this changes
Adds lowering for the 64-bit scalar bit-replicate SOP1 instruction
s_bitreplicate_b64_b32intools/startup/gfx2hlsl.py(already decoded bytools/disasm_rdna2.pyand handled intools/pixel_aot.py).S0twice into the 64-bit destination SGPR pairs[D:D+1](D[2*i] = D[2*i+1] = S0[i]), leavingSCCunchanged.null, inline integers, 32-bit literals, and constant-tracked SGPRs) at translation time without emitting a helper. For dynamic SGPR sources, emits a compactbitreplicate16(uint x)HLSL helper only when used. WhenS0aliases the low word ofD(s[D:D+1], sD), writess(D+1)beforesDso the source is read intact.masks/mask_highon either half ofDor onS0), descriptor-bearing SGPRs, VGPRs, odd or out-of-range SGPR pairs, SGPR-pair sources, floats,m0, andsrc_scc.Tests added
tests/startup_gfx2hlsl_s_bitreplicate_check.py: SOP1 binary decode viaG.decode(), disjoint and aliased (s[4:5], s4ands[4:5], s5) evaluation, constant folding, uniformity tracking, on-demand helper emission/omission, refusal cases, unlowered control, and FXCps_5_1+ DXCps_6_0GPU readback draws (including a negative-control draw).tests/cmake/startup_gfx2hlsl_s_bitreplicate.cmakeandtests/checks/python-linux/startup_gfx2hlsl_s_bitreplicate.txt.Verification
2c234a21(onupstream/main3b6c38a8)10.0.26300.9974), MSVC19.44.35230, Windows SDK10.0.26100.0, FXC + DXC1.9.2602.17, D3D12 debug layer enabled1414:008c, driver10.0.26100.9818) and NVIDIA GeForce RTX 5080 (10de:2c02, driver32.0.16.2124)Results:
ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_bitreplicate'-> 3/3 passed, 0 skipped (debug_errors=0 debug_warnings=0on all draws;startup_tools_lintalso passed)ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_s_bitreplicate'-> 3/3 passed, 0 skippeddocs_links_check.py,bidi_controls_check.py, scalar/arity/null/refusal checks,git diff --check) -> all passedgfx2hlsl.py(breakings[D:D+1], sDalias order, wrong high-half shift, dropping helper gate, droppingmask_highguard, wrong constant fold) -> 5/5 caught (rc=1)Scope: Covers synthetic gfx1013 SOP1 fixtures translated by
gfx2hlsl.pyand run on WARP and RTX 5080; does not establish full-title startup or frame rate.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T10:05:52Z.
Review: COMMENTED
Review of head
335f050a(comment only).Read the diff of
tools/startup/gfx2hlsl.py(75 lines):op_s_bitreplicate_b64_b32(operand checks, lane-mask refusals, constant folding, abitreplicate16HLSL helper emitted once viauses_bitreplicate, and the aliasing order: when S0 is the low word of the destination the high word is written first). The helper's bit-spread constants are the standard 16-to-32 interleave and match the ISA text in the comment.The PR's check has the real thing a lowering needs:
startup_gfx2hlsl_s_bitreplicate_warp/_hardwaredraw the translated shader and compare the readback with a CPU reference, plus a_controlstest.Ran locally (Linux):
python3 -B tests/startup_gfx2hlsl_s_bitreplicate_check.py(controls): ok.0x33333333changed to0x33333332in the constant folder: the controls fail ("const 1 folds").src_reg == dnever true): the controls fail ("aliased s[4:5], s4 (12 cases)").No defect found. It only lacks a Windows receipt on this head:
ctest -R "startup_gfx2hlsl_s_bitreplicate"(dev + release).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T18:15:21Z.
Review: COMMENTED
Review of
8e0cb550da(the change frombf058e96, updated with main; the PR's own diff is unchanged). Comment only.op_s_bitreplicate_b64_b32refuses modifiers, odd or out-of-range destinations, lane masks and non-scalar data, folds constants with the same interleave as the emittedbitreplicate16helper, and writes the high word first when S0 is the low word of the destination, so S0 is read before it is overwritten. SCC is left unchanged. The helper is emitted once per pipeline throughuses_bitreplicate, which is reset with the otheruses_*flags. The check draws the translated shader on WARP and compares with an independent CPU reference. No other open or merged PR lowers this opcode ingfx2hlsl.py.Windows results are in the comment below.
Commands:
git diff origin/main...pull/3030/head(read), plus the Windows commands listed in the comment.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T18:15:22Z.
Windows Server 2025 verification of
8e0cb550da0d3e6275c0ce0272d93e9fb9a8d5af(D3D12 WARP, MSVC 14.44.35207):cmake --build --preset dev --target offscreen_check;ctest --preset dev -R '^startup_gfx2hlsl_': 379/379 passed, includingstartup_gfx2hlsl_s_bitreplicate_controls,_warpand_hardwarecmake --build --preset release --target offscreen_check;ctest --preset release -R '^startup_gfx2hlsl_': 379/379 passedtools/startup/gfx2hlsl.py: all ok;tests/startup_run_sh_check.pyskips (77) on WindowsAI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T20:04:22Z.
Windows Server 2025 re-verification of
5a5746dc4e036bcb6947d78e0785e4959d822b82(the same change, updated with main again; D3D12 WARP, MSVC 14.44.35207):cmake --build --preset dev --target offscreen_check;ctest --preset dev -R '^startup_gfx2hlsl_': 379/379 passed, includingstartup_gfx2hlsl_s_bitreplicate_controls,_warpand_hardwarecmake --build --preset release --target offscreen_check;ctest --preset release -R '^startup_gfx2hlsl_': 379/379 passedtools/startup/gfx2hlsl.py: all ok;tests/startup_run_sh_check.pyskips (77) on WindowsA first run of this head had one release failure in an unrelated test (
startup_gfx2hlsl_v_pk_mul_mad_16_hardware):PermissionErrorwhile renaming a file in the test host's shared DXC compile cache, raised before any shader ran. The rerun above passed.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T20:07:25Z.
Review: CHANGES_REQUESTED
I reviewed
5a5746dcmerged intomain454fc0ed(tree66c61640, clean merge).What I traced.
00ff00ff,0f0f0f0f,33333333,55555555and a finalx | x << 1. The high word isbitreplicate16(s >> 16).s[D:D+1], sD, the high word is written first. Withs[D:D+1], sD+1, the low word is written first, from the source that hasn't been overwritten yet.udsymbols are refused.What I ran. I built
offscreen_checkindevandrelease, then ran:ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^startup_gfx2hlsl_s_bitreplicate'3/3 passed in each preset, with no skips. The draws ran on WARP and an RTX 5090, with
debug_errors=0 debug_warnings=0.Gap: the GPU draws never see source bits 11–14 or 27–30.
_bitreplicate16.GPU_VECTORSkeeps bits 11–14 and 27–30 clear so thatXOR 0x3f800000lands on a normal float.' x &= 0xffffu;'changed to' x &= 0x87ffu;'in the emitted helper only, which drops those 8 source bits.Suggested fix (tested locally). Choose the transport XOR per result word, so that the exponent always reads
0x7fwhatever the bits are:Use
transport(r0)/transport(r1)fromref_bitreplicate(val)in place ofDRAW_TRANSPORT_XOR, both inps_words(val)(fors8/s4ands9/s5) and inraw_exp. Then add vectors such as0x78007800and0xffffffff.With that change:
fxc warp bits_11_14_27_30 expected=3fc00000,… actual=00000000,….A wrong result can still land on a NaN or a denormal, but either way it differs from the expected normal value, so the comparison still catches it.
Verdict: request changes on
5a5746dc, for the fixture gap only. The lowering itself looks right to me.Environment: NVIDIA GeForce RTX 5090, driver 32.0.16.1088; WARP 10.0.26100.9818; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10; debug layer on.
CI:
Build and test on Windowspasses on5a5746dc. There are no review threads.This reply was AI-assisted.