Skip to content

recomp/dxil: straddling 16-bit LDS, XCL_SHADER_LOOP_LIMIT, and safe MS barriers - #1976

Open
raylitebull wants to merge 2 commits into
xcl-dev:mainfrom
raylitebull:feat/recomp-ms32kb-lds-and-safe-barrier
Open

raylitebull wants to merge 2 commits into
xcl-dev:mainfrom
raylitebull:feat/recomp-ms32kb-lds-and-safe-barrier

Conversation

@raylitebull

@raylitebull raylitebull commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Stacked on #1975 (extends #1975's 72960386 on c9ee916a with incremental commit 2e7debd8, +401 / -40 across 6 files).

Adds three robustness and correctness improvements across the HLSL recompiler and Direct DXIL translator (both 32 KB passthrough_split deferred to #304 and repeated-PS .zw f16 interpolant packing deferred cleanly to @MacieGx's recomp/f16-packed-interpolants — zero touch on recomp/mod.rs):

  1. Dword-straddling 16-bit LDS reads/writes (lower_mem.rs, emit.rs): splits 16-bit LDS loads/stores (ds_read_{u,i}16, ds_write_b16, ds_*_d16_*) at byte offset (addr & 3) == 3 across (at >> 2) byte 3 and (at + 4) >> 2 byte 0 in both Direct DXIL (lds_read_bits, lds_bits_store) and HLSL (InterlockedAnd / InterlockedOr), while preserving #134 PRELUDE_PIXEL.
  2. Early-exit-safe multi-wave mesh barriers (kernel.rs, lower.rs): replaces Direct DXIL's non-uniform multi-wave mesh barrier fallback error with a bounded groupshared arrival barrier (xcl_bar via safe_barrier_init / safe_barrier_wait / safe_barrier_exit, reusing top 2 dwords of xcl_lds when present so TGSM stays <= 32768 bytes, gated by XCL_SAFE_BARRIER != 0, with VAR_BAR_ALIVE = VAR_BUDGET + 6 disjoint from #2156's VAR_IMG_WRITE = VAR_BUDGET + 8 and both zero-initialized in Init::load).
  3. Configurable XCL_SHADER_LOOP_LIMIT (emit.rs, lower.rs, pso.rs): configurable shader loop limit (default 65536, capped 1 << 24, folded into pso.rs translation identity), plus direct_dxil_mixed_fp16_interp_preserves_half_across_ssa_phi updated to use main's PsAttr.

Part of #1269.

What is in it

  • Incremental commit 2e7debd8 on top of #1975 (72960386): crates/xcl/src/gpu/dxil/kernel.rs, lower.rs, lower_mem.rs, lower_valu.rs, crates/xcl/src/gpu/recomp/emit.rs, pso.rs.
  • Targeted tests: lds_16bit_straddling_dword_boundary_hlsl, direct_dxil_lds_dword_straddling_16bit_validate, direct_dxil_infinite_loop_guarded_by_shader_loop_limit, direct_dxil_mixed_fp16_interp_preserves_half_across_ssa_phi, and direct_dxil_mesh_non_uniform_barrier_guard (including full-32KB-LDS TGSM check).

Tested

  • Toolchain: Windows 11 x64, rustc 1.99.1 (58cf8f9c3 2026-10-13), DXC dxcompiler 1.8.2502.11 / dxil 1.8.2502.11, stacked on #1975 (72960386) over c9ee916a (2e7debd8).
  • cargo check --workspace --tests: passed (0 warnings in touched files).
  • Targeted tests covering #1975 + #1976: 14 passed, 0 failed (0.22s, dxil 1.8.2502.11 validated).

Regression run

  • Standalone scripts/smoke.ps1 pair on 2e7debd8 vs c9ee916a has not been run yet. AMD and NVIDIA reviewers are invited to test on 2e7debd8 vs c9ee916a (including scripts/smoke.ps1, XCL_DIRECT_DXIL=1, and multi-wave mesh / straddling 16-bit LDS workloads) and post results in the comments.

Not tested

  • 60 s scripts/smoke.ps1 pair on 2e7debd8, full cargo test --workspace suite on 2e7debd8, runtime GPU execution across AMD / NVIDIA / Intel hardware, and Linux/Wine/vkd3d-proton.

AI use

  • Antigravity assisted with implementation, rebase onto c9ee916a, trimming, and DXIL/recompiler validation tests; the author reviewed the diff and test output.

@futurepro62

futurepro62 commented Nov 25, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head fed1358 (on its base 80f4819).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 1003 passed, 0 failed, 43 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: from_d3d_supports_16bit_component_types, place_separates_16bit_and_32bit_rows_and_packs_16bit_together, mixed_mode_fixed_row_adopts_row_interp_mode, direct_dxil_vs_compr_and_ps_16bit_inputs_validate, direct_dxil_movrel_const_and_umin_bound_validate, direct_dxil_movrel_masks_m0_low_byte, direct_dxil_packed_f16_vs_ps_and_ms_validate, direct_dxil_mesh_non_uniform_barrier_guard, direct_dxil_lds_dword_straddling_16bit_validate, direct_dxil_infinite_loop_guarded_by_shader_loop_limit, direct_dxil_mixed_fp16_interp_preserves_half_across_ssa_phi, ps_attr_modes_follows_copied_reused_and_joined_interp_regs, m0_bounds_tracks_constants_masks_clamps_and_counted_loops, v_movrel_emits_bounded_switch_cases, vs_compr_param_and_16bit_sig_types_unpack_cleanly, ps_packed_f16_interp_high_bit_and_paired_attrs, vs_and_ms_packed_f16_param_unpack, v_movrel_and_swaprel_mask_m0_low_byte, mesh_passthrough_respects_32kb_align32_and_256_vert_limits, lds_16bit_straddling_dword_boundary_hlsl, fssm_16bit_packed_tables_and_slot_mapping.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 1013 passed, 0 failed, 45 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 80f4819 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests and const_and_null_mask_operands_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@raylitebull
raylitebull force-pushed the feat/recomp-ms32kb-lds-and-safe-barrier branch from fed1358 to 561a6a9 Compare November 25, 2026 00:44
@raylitebull

Copy link
Copy Markdown
Member Author

Stacking note: #1976 is currently stacked on top of #1975 (which carries the f16 signature packing, CFG v_interp modes, and bounded movrel/M0[7:0] changes), while #1976 adds the mesh 32 KB split alignment, straddling 16-bit LDS reads/writes, safe multi-wave MS barriers (distinct from stale/conflicting #1793), and r0 f16 attribute unpacking.

We will rebase #1976 cleanly onto #1975's latest head (and trim down to only the 4 mesh/LDS/safe-barrier additions once #1975 lands) so reviewers see zero duplicated diff.

@raylitebull
raylitebull force-pushed the feat/recomp-ms32kb-lds-and-safe-barrier branch from 561a6a9 to ec13a10 Compare November 25, 2026 01:54
@raylitebull raylitebull changed the title recomp/dxil: align mesh 32KB split, straddling 16-bit LDS, safe MS barriers, and r0 f16 attrs recomp/dxil: straddling 16-bit LDS, r0 f16 attrs, loop limit, and safe MS barriers Nov 25, 2026
@raylitebull

Copy link
Copy Markdown
Member Author

Rebased #1976 cleanly onto ae0518c + #1975 (a85fa25) in commit ec13a10:

  • Trimmed the 32 KB passthrough_split adjustments in emit.rs (deferring cleanly to #304 d3bd51d) and preserved #134's PRELUDE_PIXEL line.
  • Updated the PR title/summary accordingly and kept ec13a10 cleanly stacked atop #1975's a85fa25 (#2008 EXP VM rebase resolved).
  • Pushed ec13a10 for GitHub Actions Build and test and fresh AMD / NVIDIA verification (fidelity_tests, attribute_tests, v_swaprel_b32_uses_the_m0_relative_switch).

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main (crates/xcl/src/gpu/recomp/emit.rs) — needs a rebase before it can be tested.

@JJAutoCompare

Copy link
Copy Markdown

Tested

Independent STOR-WINLAB CPU verification of open PR #1976 at ec13a10753ed792308a90d060093cc3254b6ab08. The checkout was clean and detached at that SHA before and after testing. The prior full-suite report covered an older head.

Windows 11 Enterprise Evaluation 25H2 x64 (26200.9974), Ryzen 7 3800X, Rust and Cargo 1.100.0 (x86_64-pc-windows-msvc), unoptimized test profile with debug info and incremental compilation disabled. Intel Arc A770 driver 32.0.101.9175 was installed. The shader fixture loaded DXC/DXIL 1.9.2609.5. Both selected fixtures ran on the CPU.

cargo test --locked -p xcl --lib gpu::dxil::lower_valu::fidelity_tests::direct_dxil_mixed_fp16_interp_preserves_half_across_ssa_phi -- --exact --nocapture --test-threads=1
cargo test --locked -p xcl --lib gpu::recomp::attribute_tests::fssm_16bit_packed_tables_and_slot_mapping -- --exact --nocapture --test-threads=1

Each exited 0 with 1 passed, 0 failed, 0 ignored, 0 skipped, and 1,082 filtered out (0.04 s and 0.01 s respectively).

  • The mixed-FP16 pixel shader passed DXIL validation and disassembly. The fixture found phi i32, and i32, and the upper-half preservation mask 0xFFFF0000.
  • The FSSM fixture checked packed PS and VS/MS metadata, including hi_register = Some(0) for the same-register r0 case, TEXCOORD0 in slot 0 .xy and TEXCOORD8 in slot 1 .zw. This fixture did not compile a shader.

Not tested

GPU execution or pipeline creation, retail smoke, LDS, loop limits, relative moves, mesh barriers, and the workspace suite.

AI use

T3 Code / Codex (gpt-6.2-sol) inspected and ran the two checked-in fixtures and prepared this report from the logs.

@Toons29

Toons29 commented Nov 25, 2026 •

Copy link
Copy Markdown

Regression run of 1447cf9f on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 1a0bbe3a, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1628 (PresentX 1628)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14561 MB
xcl-smoke v1
commit: 1447cf9f209c69f64b0c31570d37efd5372f2ad0
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1630 (PresentX 1630)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14561 MB

Against the limits in CONTRIBUTING.md: 100 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; both blocks are exactly as printed, and I approved posting this.

IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
@raylitebull
raylitebull force-pushed the feat/recomp-ms32kb-lds-and-safe-barrier branch from ec13a10 to e5ddc4b Compare November 25, 2026 10:38
@raylitebull

Copy link
Copy Markdown
Member Author

Rebased #1976 cleanly onto 568e7db + #1975 (f6289cb) in commit e5ddc4b (resolving #2034 kernel.rs conflict while keeping 32 KB passthrough_split deferred to #304 and #134 PRELUDE_PIXEL preserved).

Pushed e5ddc4b for GitHub Actions Build and test and fresh AMD / NVIDIA verification.

@raylitebull
raylitebull force-pushed the feat/recomp-ms32kb-lds-and-safe-barrier branch from e5ddc4b to adfcc9c Compare November 25, 2026 10:46
@raylitebull

Copy link
Copy Markdown
Member Author

Rebased #1976 cleanly onto 82e63982 + #1975 (1447d7e4) in commit adfcc9cd (#2174 kernel.rs alignment, 32 KB passthrough_split deferred to #304, and #134 PRELUDE_PIXEL preserved).

Verified locally (fidelity_tests: 19 passed, 0 failed, dxil 1.8.2502.11 validated; attribute_tests: 4 passed, 0 failed) and pushed adfcc9cd.

@raylitebull
raylitebull force-pushed the feat/recomp-ms32kb-lds-and-safe-barrier branch from adfcc9c to 1447cf9 Compare November 25, 2026 10:55
@raylitebull

Copy link
Copy Markdown
Member Author

Rebased #1976 cleanly onto 1c17aa55 + #1975 (865350cc) in commit 1447cf9f:

  • Resolved the crates/xcl/src/gpu/dxil/lower.rs conflict cleanly alongside #2156 (03f8e572), keeping VAR_BAR_ALIVE = VAR_BUDGET + 6 and VAR_IMG_WRITE = VAR_BUDGET + 8 (+8..+24) disjoint and zero-initialized in Init::load (while keeping 32 KB passthrough_split deferred to #304 and #134 PRELUDE_PIXEL preserved).
  • Verified locally (cargo check --workspace --tests + fidelity_tests: 19 passed, 0 failed, dxil 1.8.2502.11 validated; attribute_tests: 4 passed, 0 failed) and pushed 1447cf9f.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@raylitebull
raylitebull force-pushed the feat/recomp-ms32kb-lds-and-safe-barrier branch from 1447cf9 to 2e7debd Compare November 25, 2026 18:31
@raylitebull raylitebull changed the title recomp/dxil: straddling 16-bit LDS, r0 f16 attrs, loop limit, and safe MS barriers recomp/dxil: straddling 16-bit LDS, XCL_SHADER_LOOP_LIMIT, and safe MS barriers Nov 25, 2026
@raylitebull

Copy link
Copy Markdown
Member Author

Rescoped and rebased #1976 cleanly onto c9ee916a + #1975 (72960386) in commit 2e7debd8 (+401 / -40 across 6 files):

  • Dropped the repeated-PS .zw f16 hunk (recomp/mod.rs is now untouched — zero overlap with @MacieGx's MacieGx/xcl#recomp/f16-packed-interpolants) and updated direct_dxil_mixed_fp16_interp_preserves_half_across_ssa_phi to use main's PsAttr.
  • Kept #1976 scoped cleanly to straddling 16-bit LDS ((addr & 3) == 3), XCL_SHADER_LOOP_LIMIT, and early-exit-safe Direct-DXIL multi-wave MS barriers (VAR_BAR_ALIVE).
  • Verified locally (cargo check --workspace --tests PASS + 14 passed, 0 failed in 0.22s) and pushed 2e7debd8.

MacieGx added a commit to MacieGx/xcl that referenced this pull request Nov 25, 2026
A retail title's world pixel shaders (xcl-dev#505; 173 of its 362) pack their
float16 interpolants: two components per dword (component c of a
register in dword c / 2, the even one in the low half) and up to two
signature registers per attribute, the second after the dwords the first
one's components take (1 for .xy, 2 for .xyz / .xyzw). The PS reads each
half with v_interp_p2_f16, SRC0 bit 8 choosing the high one.

XCL refused the PS input table of such programs (records [6, reg, mask,
attr, 0, reg2, packed reg, flags]: flag 8 = float16, flag 16 = byte 5
names the second register, byte 6 below byte 1 from the first pair on),
so every attribute, plain ones included, fell back to "the N-th
register" and the ones after a pair read their neighbour. The PS also
converted the raw packed dword as a float, ignored the high bit and
declared the float16 inputs nointerpolation.

Now the table parses, each (dword, half) of a packed attribute maps to
its element and component (f16_registers, ps_f16_slot; a record that
repeats its own register pairs it with the next float16 register no
other attribute names), and the PS reads that component as a float,
interpolated with the attribute's own mode. Both translators (HLSL and
direct DXIL).

The layout was checked on the title's dumped programs: every
v_interp_p2_f16 (dword, half) of 376 of 378 packed attributes in 362 PS
is a declared component (2 read one past a .xy register).

Not covered here: the VS / mesh side still exports the packed dwords
raw (the next commit), so the GPU test feeds the PS from a PC VS that
hands over each component as a float.

xcl-dev#1975 / xcl-dev#1976 parsed the same records with a fixed layout - the second
register always in dwords 2-3, a repeated register paired with itself -
which does not match the title's programs after a .xy register; both
have since dropped their float16 part in favour of this change.

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

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: direct-DXIL safe mesh-barrier state aliases normal LDS. kernel reserves dwords 8190-8191 by lowering lds_top for mesh shader, but lower_mem applies lds_top only when split; non-split Direct-DXIL DS accesses can still address reserved dwords. Full-32KiB LDS shader can overwrite liveness/generation state, corrupt LDS and release/hang barrier. Reserve/remap in non-split path too or use separate storage; add DS access-at-reserved-address plus barrier behavior regression. Current full-32KiB test only validates TGSM size.

@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

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

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants