Skip to content

Recompiler: decode only requested components in buffer_load_format_* - #1310

Open
coolpersonnn wants to merge 1 commit into
xcl-dev:mainfrom
coolpersonnn:recomp/format-load-selected-components
Open

coolpersonnn wants to merge 1 commit into
xcl-dev:mainfrom
coolpersonnn:recomp/format-load-selected-components

Conversation

@coolpersonnn

@coolpersonnn coolpersonnn commented Nov 24, 2026 •

Copy link
Copy Markdown

Decode only the format components actually selected by narrow buffer_load_format_* and tbuffer_load_format_* instructions instead of unconditionally calling fmt_comp on all four channels. On format-heavy compute shaders, this cuts emitted HLSL, DXIL binary size, and DXC compile time without altering decoded semantics.

What is in it

  • Add branch-free fmt_sel(uint4 r, uint info, uint sel, bool isint) right after dst_sel in PRELUDE_MEM (crates/xcl/src/gpu/recomp/emit.rs), evaluating format decoding only for channels selected by dst_sel.
  • Update BufKind::FormatLoad (crates/xcl/src/gpu/recomp/emit.rs) to emit fmt_comp (uint4 {t}_c) only when n_comp == 4, and use fmt_sel whenever n_comp < 4 (including d16 loads, binding {t}_s{c} once per component before the 16-bit pack so fmt_sel is not evaluated twice inside select).
  • Add unit/DXC compile coverage (buffer_load_format_decodes_only_requested_components) and a D3D12 GPU test (gpu_buffer_load_format_swizzled_narrow_loads) covering non-identity DST_SEL swizzles, SEL_0/SEL_1/missing channels on float and UINT formats, TBUFFER_LOAD_FORMAT_X, D16_{X,HI_X,XYZ} (including low-half preservation), and out-of-range loads (crates/xcl/src/gpu/recomp/tests.rs).

Tested

  • Rebased head 234ec72 on Ryzen 9 9950X3D, RTX 5090 (621.01), Windows 11 build 26300, rustc 1.100.0 and DXC 1.8.2502.11. .\scripts\test.ps1 with XCL_ADAPTER=nvidia reported 961 passed, 0 failed and 43 ignored. The harness reported 23 GPU skips.
  • Optional XCL_SAMPLE_* fixtures were unset for the rebased suite.
GPU coverage skips on the rebased head
SKIPPED gpu::recomp::lower::tests::a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower::tests::cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower::tests::coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower::tests::the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 arithmetic, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 compares, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu: f64, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer arithmetic, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 rounding, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer carries, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 transcendentals, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 three-source, wave64: no wave64
SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64
SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64
SKIPPED shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required): The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D)
SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows

The original measurements below were taken before this rebase.

  • Hardware & toolchain: NVIDIA GeForce RTX 5090 (driver 32.0.16.2101), AMD Radeon(TM) Graphics (driver 32.0.21045.29003, targeted GPU check), AMD Ryzen 9 9950X3D 16-Core Processor, Windows 11 (NT 10.0.26300.0), rustc 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.8.2502.11.
  • .\scripts\test.ps1 (cargo build --workspace and cargo test --workspace -- --test-threads=4, debug): 753 passed, 0 failed, 41 ignored (709 lib + 44 integration/e2e/oracle; SKIPPED GPU tests on RTX 5090: gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64; XCL_SAMPLE_* unset/skipped).
  • XCL_ADAPTER=radeon: cargo test -p xcl --lib gpu_buffer_load_format_swizzled_narrow_loads (1 passed, 0 failed) and cargo test -p xcl --lib gpu_typed_buffer_loads_and_stores (1 passed, 0 failed).
  • Extracted compute shaders from a retail shader pack (4-window split-wave64, isolated temp caches):
    • 2,809 insts (9 x, 1 xy): DXIL 157184 B -> 141620 B (-9.9%), DXC 1.07 s -> 1.04 s, PSO 1.32 s -> 1.22 s (1 made, 0 refused).
    • 7,305 insts (25 x, 2 xyz): DXIL 489424 B -> 450520 B (-7.9%), DXC 4.13 s -> 4.18 s, PSO 9.00 s -> 8.80 s (1 made, 0 refused).
    • 16,414 insts (37 x, 6 xy, 4 xyz): DXIL 1092324 B -> 1030584 B (-5.7%), DXC 11.16 s -> 10.97 s, PSO 47.42 s -> 49.19 s (1 made, 0 refused).
    • 88,863 insts (3,281 x): DXIL 29750432 B -> 20197536 B (-32.1%), DXC 130.59 s -> 94.61 s (-27.5%), PSO >60.0 s before / >120.0 s after (killed at cap).
  • Note: the main baseline smoke run had a cold shader cache, whereas the PR smoke run executed after caches were warmed.

Regression run

Main

xcl-smoke v1
commit: c4d37bec1bb4286eb373aea963404a23f13401fa
gpu: NVIDIA GeForce RTX 5090
title: a93b40d7
seconds: 60
exit: 0x0
frames shown: 1082 (PresentX 1082)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15601 MB

PR head

xcl-smoke v1
commit: 234ec72cc5ac3b3d544b4444a26a03b6164694a4
gpu: NVIDIA GeForce RTX 5090
title: a93b40d7
seconds: 60
exit: 0x0
frames shown: 1105 (PresentX 1105)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15434 MB

Not tested

  • CreateComputePipelineState on the 88.9k-instruction compute shader still exceeded the 120 s timeout cap on RTX 5090.
  • Retail gameplay past 60 s, discrete AMD GPUs (only integrated AMD Radeon Graphics was checked on targeted GPU tests), and Linux / Wine.

AI use
Antigravity via T3 Code (Gemini Pro) — inspected crates/xcl/src/gpu/recomp/emit.rs and crates/xcl/src/gpu/recomp/tests.rs, implemented fmt_sel and the narrow BufKind::FormatLoad emission path, wrote unit and GPU tests, ran the test suite, shader benchmarks, and smoke tests, and drafted the commit and PR description.

  • T3 Code / Antigravity resolved the current rebase. Codex (GPT-6 family, exact model variant unavailable) verified the resolution, reran the checks, and updated this description.

@Aniseto

Aniseto commented Nov 24, 2026

Copy link
Copy Markdown

Ran the two new tests on an NVIDIA Blackwell part at c8b5978:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

XCL_ADAPTER=nvidia cargo test -p xcl --lib buffer_load_format
2 passed; 0 failed; 0 ignored      (exit 0)

buffer_load_format_decodes_only_requested_components and gpu_buffer_load_format_swizzled_narrow_loads pass here. The author's run used DXC 1.8.2502.11, so this also covers the newer compiler's code generation for the narrow loads on the same tests.

Not tested: native wave64, RDNA2/RDNA4 and Intel GPUs, Wine, release profile, retail titles.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash 1017 - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 21 ignored. (One run aborted with 0xc0000005 under parallel scheduling; clean on rerun — same flake seen on unmodified main.)

Thanks!

Narrow buffer_load_format_* and tbuffer_load_format_* instructions
previously pre-decoded all four format components into {t}_c via
fmt_comp even when only 1-3 components were selected. On format-heavy
compute shaders (especially wide unrolled kernels), the unused decodes
inflated emitted HLSL, DXIL size, and DXC compile time.

Add a branch-free fmt_sel helper right after dst_sel in PRELUDE_MEM
that routes only the needed format components into dst_sel, and update
BufKind::FormatLoad to use fmt_sel whenever n_comp < 4 (including d16
loads, binding {t}_s{c} once before the 16-bit pack so the format
decode is not evaluated twice).

Measured on 4 extracted compute shaders from a retail shader pack
(split-wave64, isolated caches):
- 2,809 insts (9 x, 1 xy): DXIL 157184 B -> 141620 B (-9.9%), DXC 1.07 s -> 1.04 s
- 7,305 insts (25 x, 2 xyz): DXIL 489424 B -> 450520 B (-7.9%), DXC 4.13 s -> 4.18 s
- 16,414 insts (37 x, 6 xy, 4 xyz): DXIL 1092324 B -> 1030584 B (-5.7%), DXC 11.16 s -> 10.97 s
- 88,863 insts (3,281 x): DXIL 29750432 B -> 20197536 B (-32.1%), DXC 130.59 s -> 94.61 s (-27.5%)

Tests: .\scripts\test.ps1 passed (753 passed, 0 failed, 41 ignored;
2 expected wave64 GPU skips on RTX 5090), plus targeted Radeon GPU
runs for gpu_buffer_load_format_swizzled_narrow_loads and
gpu_typed_buffer_loads_and_stores.

Assisted-by: Antigravity via T3 Code (Gemini Pro)
@coolpersonnn
coolpersonnn force-pushed the recomp/format-load-selected-components branch from c8b5978 to 234ec72 Compare November 24, 2026 21:38
@Rednaxeh

Copy link
Copy Markdown
Contributor

A size measurement in favour of this direction, on the largest retail compute program (CS_ScreenProbes_ActivateRays, record 95cc13288a27a96e), HLSL path of main 20cf130 (#1321 in), 4 memory windows, native wave64, DXC 1.9.2602.17 on Windows:

HLSL compiled with DXC time DXIL
-O0 (what XCL uses above 8 MB of HLSL; this program's HLSL is 15.0 MB) 73 s 13 823 000 B, byte-identical to the runtime's
-O1 stopped after 24 min –
-O0, with fmt_comp reduced to return r[c & 3u] (a size probe, not a correct program) 49 s 7 424 736 B

So at -O0 the runtime format decode is 46 % of this program's DXIL: 1 890 typed buffer loads, each decoding its descriptor's format four times (7 561 fmt_comp calls, all with a descriptor-derived info, none constant), and DXC at -O0 folds nothing. The AMD driver (RX 7800 XT, 32.0.32029.2010) refuses this program with E_OUTOFMEMORY after 15–33 s at its current size (#232, #1918). Decoding only the requested components, and decoding info once per load rather than once per component, both act directly on this half; I can rerun the probe on this PR's head if useful.

AI use: Claude Code (Claude Fable 5.1) ran DXC and counted; the export was mine.

@JJAutoCompare

Copy link
Copy Markdown

Tested

Clean PR head 234ec72cc5ac3b3d544b4444a26a03b6164694a4 on Intel Arc A770 (driver 32.0.101.9175), AMD Ryzen 7 3800X, Windows 11 Enterprise Evaluation 25H2 build 26200.9974 x64, Rust 1.100.0 (0ef1bc386, x86_64-pc-windows-msvc), MSVC 14.44.35207, and DXC/DXIL 1.9.2609.5. Cargo used the debug test profile.

$r='L:/XclTooling/pr1310-234ec72c'
$env:Path="$env:USERPROFILE/.cargo/bin;$env:Path"
$env:TEMP="$r/temp"
$env:TMP=$env:TEMP
$env:CARGO_TARGET_DIR="$r/target"
$env:CARGO_BUILD_JOBS='2'
$env:CARGO_INCREMENTAL='0'
$env:XCL_DXIL_CACHE="$r/dxil"
$env:XCL_DXC_DIR="$r/dxc-1.9.2609.5/bin/x64"
$env:XCL_DIRECT_DXIL='0'
cargo test -p xcl --lib -- --exact gpu::recomp::tests::buffer_load_format_decodes_only_requested_components gpu::recomp::tests::buffer_format_d16_packs_and_unpacks_halves gpu::recomp::tests::buffer_format_table_matches_llvm --nocapture --test-threads=1
$env:XCL_ADAPTER='A770'
$env:XCL_REQUIRE_GPU='wave64'
Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned -Force
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test { cargo test -p xcl --lib -- --exact gpu::recomp::tests::gpu_buffer_load_format_swizzled_narrow_loads gpu::recomp::tests::gpu_typed_buffer_loads_and_stores --nocapture --test-threads=1 }
  • CPU/HLSL command exited 0 with 3 passed, 0 failed, 0 ignored. It checked emitted decode counts for one through four components, compiled representative SM 6.6 HLSL and D16 packing, and checked the GFX10 format table against LLVM fixtures.
  • Arc command exited 0 with 2 passed, 0 failed, 0 ignored. The tests checked results across all 64 logical lanes for X/XY/XYZ swizzles, missing components and constant selectors, unaligned SNORM, packed float formats, D16 high-half preservation, and out-of-range loads. A repeat under the same Arc lock returned the same counts.
  • Skips 0 in each command. XCL logged DXC and DXIL 1.9.2609.5 in both runs.

Not tested

Full workspace suite, retail title smoke runs, PR-base comparison, AMD or NVIDIA, native wave64, direct DXIL, release mode, and performance.

AI use

Codex (gpt-6.2-sol) selected and ran the existing tests and wrote this report.

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.

5 participants