Skip to content

[upstream #1043] Recompiler: prune unreferenced memory accessors and prelude helpers - #105

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1043
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1043

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Prune unreferenced HLSL prelude helpers (bvh_intersect, FMT_INFO, st_bytes, dst_sel, ld_raw) and memory accessors (xcl_loadx4, xcl_mStore*, xcl_mInterlocked*) when translating shaders.

Previously, PRELUDE_MEM and the entire mem_accessors switch-case ladder were emitted unconditionally, bloating the emitted HLSL and increasing DXC compile times for shaders that only perform simple loads or do not use raytracing BVH or packed buffer formatting.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: conditionally emit HLSL prelude helpers and memory accessors based on shader body usage.
  • crates/xcl/src/gpu/recomp/tests.rs: add unreferenced_helpers_and_accessors_are_pruned unit test verifying that unreferenced helpers and accessors are omitted from emitted HLSL and that resulting shaders compile cleanly with DXC.

Tested

  • Hardware: NVIDIA GeForce RTX 3060 12 GB, Windows 11, DXC 1.8.2502.11, Rust stable-x86_64-pc-windows-msvc.
  • cargo test --workspace -- --test-threads=4: 736 passed, 0 failed, 41 ignored.
  • SKIPPED GPU tests on this adapter:
    • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64
    • gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64
  • Both single-window and multi-window pruning cases verified in unreferenced_helpers_and_accessors_are_pruned with DXC compilation.

Regression run
We have no retail title; this changes crates/xcl/src/gpu/recomp/emit.rs, so it needs one. Could someone with a title post the xcl-smoke blocks for main and this head?

main:

PR:

Not tested

  • Retail titles (dump not available).
  • AMD RDNA GPU hardware (tested on NVIDIA RTX 3060).

AI use

  • AI-assisted (Antigravity): analyzed unreferenced prelude helpers and memory accessors in emitted HLSL, implemented conditional emission and dead-code pruning, wrote regression unit tests, and verified DXC compilation and full workspace test suite.

Mirror of xcl-dev#1043 (auto-synced, do not edit).

Only emit HLSL prelude helpers (bvh_intersect, FMT_INFO, st_bytes, dst_sel, ld_raw) and memory accessor switches (xcl_mLoad*, xcl_mStore*, atomics, xcl_loadx4) when actually referenced by the translated shader body. This trims dead code from emitted HLSL and lowers DXC compile time on shaders with single or multiple memory windows.
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#1043 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/1043 branch November 25, 2026 00:10
ufoptg pushed a commit that referenced this pull request Nov 27, 2026
After s_wqm the helper pixels of a quad an edge splits are in EXEC, but
ballot() took masks with WaveActiveBallot alone, which leaves helper
lanes out before SM 6.7: v_cndmask gave them the false value,
s_and_saveexec dropped them, derivatives taken across the quad by hand
were wrong along every edge, and a waterfall loop over v_readfirstlane
never removed a helper lane from EXEC (ran into the loop budget).

ballot_px gets each quad's four bits through quad reads and collects
them with four ballots (a helper lane gets the wave's result of a
ballot, but not of WaveActiveBitOr on an RTX 5070 Ti, and it holds its
own copy of EXEC). Masks only read lane by lane (x64_masks liveness, now
also for pixel shaders) take ballot_px_local: one ballot plus the lane's
own bit. The entry EXEC stays the live lanes. HLSL of every other stage
is byte-identical.

Tests: gpu_ps_masks_hold_helper_lanes_on_triangle_edges (384 / 1024
pixels wrong before, 0 after, wave64 and wave32 programs),
gpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ufoptg pushed a commit that referenced this pull request Nov 27, 2026
Pixel shaders: masks hold the helper lanes (#105 item 1)
ufoptg pushed a commit that referenced this pull request Nov 27, 2026
In `crates/xcl/src/gpu/dxil/lanes.rs`, `Lw::ballot` called plain
`WaveActiveBallot` even in pixel shaders (`self.gfx` with `ps: Some(_)`).
Under SM 6.6, `WaveActiveBallot` excludes helper lanes, whereas `Lw::rla`
already uses quad reads for pixel shader helper lanes and the HLSL path
uses `ballot_px` / `quad_bits` + `ballot_px_quad` (PR #134 / #105 item 1).
After `s_wqm_b32`/`s_wqm_b64`, dropping helper-lane bits from compare
masks corrupted `v_cndmask` / `s_and_saveexec` values read via DPP quad
derivatives and caused `v_readfirstlane` waterfall loops to spin until
the loop budget.

Port both parts of #105 item 1 and #134 to the direct DXIL translator:
- Split `Lw::ballot_ps_quad(q)` out of `Lw::ballot_ps(cond)` in
  `crates/xcl/src/gpu/dxil/lanes.rs`: four `WaveActiveBallot` passes
  spread each quad member's bit `p` from live lanes back to bit `4k + p`,
  preserving the wave32-in-wave64 `gfx_half` select, constant-false
  `(0, 0)` short-circuit, and live-lanes-only entry `EXEC` (`setup_pixel`
  calls `gfx_common_init` before setting `self.gfx`). Non-VOPC PS masks
  (such as `v_add_co_u32` carries) route through `ballot_ps` ->
  `ballot_ps_quad`.
- In `crates/xcl/src/gpu/dxil/lower_valu.rs`, evaluate plain pixel-shader
  VOPC compares per quad member (`p in 0..4`) by quad-reading VGPR source
  operands with `QuadReadLaneAt` (leaving SGPRs such as `v_readfirstlane`
  results and constants wave-uniform) and feeding the 4-bit quad mask to
  `Lw::ballot_ps_quad`, avoiding `QuadReadAcross*` on compare predicates
  that crash AMD RDNA2/3/4 `amdxc64` (#134).

Add CPU/DXIL-validator and CI-WARP-safe GPU draw regression tests in
`lanes.rs` (384/1024 wrong pixels pre-fix on RTX 4060 -> 0/1024 post-fix
for both wave64 and wave32 pixel shaders, with zero `dx.op.quadOp` in
VOPC pixel shaders).

Part of xcl-dev#1269

Assisted-by: Google Antigravity (Gemini 4 Neon)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants