Skip to content

Recompiler: direct DXIL PS IR cuts (shared float decode, direct quad shuffles, predicate-derived lane masks) - #3501

Merged
Prime1997 merged 4 commits into
xcl-dev:mainfrom
Kalmarv:pr/7-dxil-ps-ir-cuts
Nov 30, 2026
Merged

Prime1997 merged 4 commits into
xcl-dev:mainfrom
Kalmarv:pr/7-dxil-ps-ir-cuts

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Three direct-DXIL pixel-shader IR cuts that reduce DXIL size and cold driver compile times on heavy pixel shaders.

What is in it

  • Share normalized and packed float buffer decode paths (crates/xcl/src/gpu/dxil/, net -54 LOC).\n- Lower pixel quad shuffles and masks directly (crates/xcl/src/gpu/dxil/lanes.rs).\n- Take a lane's own mask bit directly from the predicate that made it (crates/xcl/src/gpu/dxil/lanes.rs, module.rs).

Tested

  • Hardware: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074), AMD Ryzen 9 9950X, Windows 11, DXC 1.9.2609
  • cargo check -p xcl --tests: passed on this exact head against origin/main (91244db94)
  • Heavy pixel shaders cold compile time reduced -17% to -30% on RTX 5070 Ti.
  • Full workspace GPU suite + scripts/smoke.ps1 running now and will be pasted below.

Regression run

main:

xcl-smoke v1
commit: 91244db94d2f402237c6a8e428dbe5da07673c48
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1514 (PresentX 1514)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 15133 MB

PR head:

xcl-smoke v1
commit: 02202839e68b26056f3e8bc114e6ab1a5c50f0f8
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1584 (PresentX 1584)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15317 MB

Not tested

  • AMD / Intel GPUs

AI use

  • Developed and verified with Claude Opus / Gemini coding assistants; all commits reviewed, built, and tested locally on RTX 5070 Ti.

@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 30, 2026
Kalmarv and others added 4 commits November 29, 2026 23:10
Direct DXIL tests a lane's EXEC (or VCC) bit by shifting the mask word by
the lane index. For a mask built from a per-lane predicate (a ballot, or a
pixel shader's own/local compare mask) that bit is the predicate itself,
and for an and/or/xor/select of such masks word by word (s_and_saveexec,
s_andn2, EXEC restores) it is the same operation on the operands' bits.
Lw::lanebit now records the predicate of each such ballot and decomposes
those operations, so exec-masked writes test an i1 chain instead of a
shifted ballot word, and ballots read only that way die.

Pixel-shader quad-form compare masks (xcl-dev#134) keep the word test: their own
bit also depends on the other quad lanes' copies of EXEC. The split form
and generic pixel ballots (helper lanes) are unchanged.

Measured on an RTX 5070 Ti: cold driver compile of one graphics pipeline,
one thread, driver cache off, median of 3 in each of three runs. The largest
pixel shader of a format-load-heavy batch went down 4-6% (2.60 s -> 2.51 s in
the last run; DXIL 268 -> 256 KB). Two other pixel shaders that bound the
batch were within noise; most of their exec-select conditions come from
quad-form masks.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Kalmarv
Kalmarv force-pushed the pr/7-dxil-ps-ir-cuts branch from adef6c3 to 0220283 Compare November 30, 2026 04:11
@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Nov 30, 2026
@Prime1997
Prime1997 merged commit 20e806f into xcl-dev:main Nov 30, 2026
4 of 5 checks passed
ArtuArtaza added a commit to ArtuArtaza/xcl that referenced this pull request Nov 30, 2026
…, not through quadOp

A pixel shader's ballots outside compares (`Lw::ballot_ps`: carry masks and the
like) collected their quad's 4 bits through `QuadReadAcrossX/Y/Diagonal`
(`quadOp`). An AMD RDNA2 driver (amdxc64 32.0.21030.2001 and 32.0.21045.29003,
RX 6700 XT) dies with a null read about 1 ms into the pipeline build of a
retail title's pixel shader (record 7381166e806847c9) in which 10 of the 27
such ballots take a value that derives from `WaveReadLaneAt`: the title ends
there at its first world load. Found by taking the pipeline apart: without its
PS it builds, without blending or in the plain wave64 form it does not; with
the ballots below, the same VS and description build in 4.3 s and the run goes
on.

The ballot now reads its quad with 4 `QuadReadLaneAt`, as the compare path
does for the same driver (xcl-dev#134, `lower_valu`): bit `p` is the quad's member
`p`, which is what `own << (lane & 3)` relied on too. Both forms record the
lane's own bit (`note_own_bit`, xcl-dev#3501). `XCL_PS_BALLOT_QUADOP=1` keeps the
`quadOp` form (with `XCL_TRANSLATED_CACHE=0`, a translation on disk keeps its
form).

Tests: `direct_ps_non_vopc_carry_ballot_reads_its_quad_lane_by_lane` (was
`..._uses_quad_op`) checks both forms' DXIL, also with the carry's operand
coming through `v_readfirstlane`, and that `v_cndmask` takes the carry itself;
`gpu_direct_ps_carry_ballot_draws_the_same_lane_by_lane_as_through_quadop`
draws a carry mask, its DPP `ddx` (helper lanes on the triangles' edge) and the
mask's bit of the lane to the right in both forms and compares every pixel. The
test-only form is handed to the translator's thread like `NO_SELECT_FOLD`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CharlyRien

Copy link
Copy Markdown
Contributor

Same report as on #2571 (#2571 (comment)), posted here because it points at this PR's ballot_ps_quad lowering: on an RTX 3090, with #2571's forms switched off, this lowering hangs the GPU in one draw, and #2571 hides the hang at a large frame-rate cost (the drop minimalhipster990 bisected to #2571 on the 4090).

Stack: main 493dbd3 (has #3535) + #3528 (ba8592a) + #3517 (0b4283d) + 42 local commits of ours (memory-window, alias-copy and diagnostic switches; none touches recomp/ps_masks.rs, dxil/kernel.rs, lower.rs, lower_valu.rs or lanes.rs). Run settings as in our earlier reports (16 heap windows, XCL_SPARSE_WINDOWS=4, XCL_GPU_WAIT_TIMEOUT_MS=45000). Fresh shader preparation for each build, warm driver cache. Presents/s from world +20 s to +180 s, one setting per run.

Build (same stack) Runs Result
as is (#2571 forms on, #3501 lowering) 1 0.23 presents/s, never left the intro card in 358 s; no removal
#2571 forms off (local switch: lw.ps_masks left empty in dxil/kernel.rs) 2 device hung at 110-121 s, before the playable scene, same mesh + pixel shader draw both times
#2571 forms off + ballot_ps_quad as before #3501 (4 WaveActiveBallot, local switch in dxil/lanes.rs) 2 no hang, playable scene, 0.66 and 1.41 presents/s
same local stack on main 53e85fb (before #3499, #3501 and #2571) 2 0.71 and 0.88 presents/s

What we read (not measured):

What we deduce: on NVIDIA (wave64 split into two wave32 halves) the #3501 ballot_ps_quad lowering can hang this draw. #2571 replaces most of those compares with its forms, so the hang disappears, but the frame rate drops (0.23 here, against 0.66-1.41 with the #3501 lowering reverted instead). That would also match the 82-87 s DRED-3 hangs reported on the 4090 before #2571. We have not found which instruction hangs, nor checked AMD.

The image in the two no-hang runs is not clean either (bald character and half-dark window, as on our earlier trees, see #505 / #3517), so this is a pace and hang result, not a rendering one.

Hardware: RTX 3090 24 GB (driver 616.56, Resizable BAR off), Ryzen 9 5950X, 32 GB, Windows 11 22631. Not tested: AMD, main without our local commits.

AI use: Claude Code (Claude Opus 5.5) ran the builds, preparations and runs, read the logs and wrote this; Antigravity CLI (Gemini 4 Neon) compared the two DXIL dumps (read-only); checked and posted by me.

ArtuArtaza added a commit to ArtuArtaza/xcl that referenced this pull request Dec 1, 2026
…, not through quadOp

A pixel shader's ballots outside compares (`Lw::ballot_ps`: carry masks and the
like) collected their quad's 4 bits through `QuadReadAcrossX/Y/Diagonal`
(`quadOp`). An AMD RDNA2 driver (amdxc64 32.0.21030.2001 and 32.0.21045.29003,
RX 6700 XT) dies with a null read about 1 ms into the pipeline build of a
retail title's pixel shader (record 7381166e806847c9) in which 10 of the 27
such ballots take a value that derives from `WaveReadLaneAt`: the title ends
there at its first world load. Found by taking the pipeline apart: without its
PS it builds, without blending or in the plain wave64 form it does not; with
the ballots below, the same VS and description build in 4.3 s and the run goes
on.

The ballot now reads its quad with 4 `QuadReadLaneAt`, as the compare path
does for the same driver (xcl-dev#134, `lower_valu`): bit `p` is the quad's member
`p`, which is what `own << (lane & 3)` relied on too. Both forms record the
lane's own bit (`note_own_bit`, xcl-dev#3501). Only tests can ask for the `quadOp`
form: no setting changes the translation outside its cache identity.

Tests: `direct_ps_non_vopc_carry_ballot_reads_its_quad_lane_by_lane` (was
`..._uses_quad_op`) checks both forms' DXIL, also with the carry's operand
coming through `v_readfirstlane`, and that `v_cndmask` takes the carry itself;
`gpu_direct_ps_carry_ballot_draws_the_same_lane_by_lane_as_through_quadop`
draws a carry mask, its DPP `ddx` (helper lanes on the triangles' edge) and the
mask's bit of the lane to the right in both forms and compares every pixel. The
test-only form is handed to the translator's thread like `NO_SELECT_FOLD`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@minimalhipster990

Copy link
Copy Markdown

On an RTX 4090 (driver 621.40, Windows), the in-world slowdown for one pixel shader first appears at a50fa7a. Restoring only the pre-PR body of ballot_ps_quad on top of the complete PR brought this draw back below 0.12 ms in all 12 active pairs tested. This directly tests the function identified in the RTX 3090 report for GPU time on the 4090. The preceding commit, e18e7b2, produces byte-for-byte identical DXIL to the pre-PR baseline for this shader.

A vs B on the same draw Active pairs A median B median Median paired B/A
e18e7b2 vs a50fa7a 13 0.0993 ms 16.0256 ms 169.3×
Complete PR with old ballot_ps_quad vs unchanged complete PR 12 0.0814 ms 17.9420 ms 220.8×

The host was fixed at a07ad1b1 with #3318. Guest dump hashes were bf5a7665d0c6631a (mesh) and af68da74e05dbb3c (pixel, guest wave64 on wave32 hardware). Each pair reused the same real indirect command, geometry, descriptors and depth/stencil tests, with depth/stencil writes disabled in both passes. Each pass started from a private copy of the same six color targets at 2560×1440. GPU timestamps cover the mesh/raster command. The table selects two compute groups and eight mesh groups with PS invocations. B was slower in every pair, in both execution orders. Mesh primitives, clipped primitives and PS invocations matched within every pair in the table.

Color changes too. In the adjacent-commit test, the two active readbacks differed at 360 and 450 texels on target 1 only. In the function-only test, the two active readbacks had 103 and 104 PS invocations respectively. Restoring the old function changed 60/63/40 texels on targets 0/1/2 in the first draw and 56/60/35 in the second. Targets 3–5 matched. A console reference would be needed to decide which output is correct.

The function-only control kept the PR's quad shuffle and predicate changes intact. Both replay processes exited cleanly. The measurements cover this shader's draw time in one save. Whole-game frame rate and the cause of the pre-world hang remain open.

AI use: OpenAI Codex (GPT-6) reconstructed the intermediate trees, ran the builds and GPU replays, checked the logs and readbacks, and drafted this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU needs-1st-check Passes gates; needs first independent merge-check (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants