Skip to content

Recompiler: track sampler constants only up to image instructions - #1573

Open
philip-roy-jones wants to merge 1 commit into
xcl-dev:mainfrom
philip-roy-jones:recompiler-sampler-blocks-1269
Open

philip-roy-jones wants to merge 1 commit into
xcl-dev:mainfrom
philip-roy-jones:recompiler-sampler-blocks-1269

Conversation

@philip-roy-jones

@philip-roy-jones philip-roy-jones commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1269. XCL can skip tracking scalar writes in blocks that never read a static sampler descriptor. A descriptor depends only on the writes that precede its image instruction in the same block.

What is in it

Apply pending writes when an image instruction reads the descriptor and discard them at block boundaries. Both the HLSL and direct-DXIL backends use the same helper. The regression test covers consecutive image reads, an unknown overwrite and a branch target.

Tested

  • fcc8247a9455 is a single commit on upstream c160d86ef2ef. It and the independently tested 54d5cd78da13 have the same complete Git tree, 72ad1a0bf8a6. Windows 11 Pro 26200.9974, Ryzen 7 7700X, Radeon RX 580 (31.0.21925.1001), Rust 1.100.0 MSVC, DXC 1.9.2609.5.
  • Release cargo build --release -p xcl on both. Median CPU time to translate 54 retail shaders to HLSL fell from 86.30 ms to 82.76 ms (4.1%) per batch. Each build ran 36 timed batches in alternating groups after warmup, on 18 vertex, 18 pixel and 18 compute programs with four memory windows. All 7,571,624 HLSL bytes and all translation metadata matched, including 45 static descriptors across 26 programs.
  • The direct backend produced byte-identical DXIL and static sampler descriptors for the same 54 shaders (1,953,284 bytes, 45 descriptors). All 54 outputs validated on both builds.
  • On the PR, cargo test -p xcl --lib -- static_samplers --test-threads=1 --nocapture passed with the default backend and again with --locked, XCL_DIRECT_DXIL=1 and XCL_REQUIRE_GPU=wave64. Both modes also passed with --locked on GitHub's merge acee405 with upstream 9039900 and on a clean local merge with upstream 85e3826 (tree 5fd5a66b687d, including Shaders: speed up translated pipeline compiles and add PSO measurements #1524). Each run reported 2 passed, 0 failed, 0 ignored and 0 skipped, including point/linear sampling on the RX 580.
  • cargo build --workspace succeeded on both. cargo test --workspace --no-fail-fast -- --test-threads=4 lost the library process on both. Rerunning every unreported case by name gave 836 reported passes on main and 837 on the PR. Each had the same 21 failed tests, 1 test-process crash and 42 ignored. Both pass counts include 21 explicit hardware skips.
  • The Windows CI command .\scripts\test.ps1 --skip test_title_runs_and_game_folder_is_untouched passed locally on WARP with Windows SDK DXC 1.8.2502.11. It reported 858 passes (including 236 hardware skips), 0 failures, 42 ignored and 1 filtered. The hosted Windows run awaits maintainer approval. Hosted Windows CI
  • nnonno91 independently retested fcc8247 on the Ryzen 7 9800X3D iGPU and RTX 5090. The workspace reported 859 passes, 0 failures and 42 ignored on each adapter, including one skip on AMD and three on NVIDIA. On the same merge tree as acee405, both GPUs passed a sampler probe through both compilers and the direct-DXIL recompiler suite (195 passed, 0 failed, 18 ignored). Independent AMD and NVIDIA report
  • lows78 independently ran the earlier head be200ab on an RTX 4090 and reported 777 passed, 0 failed, 41 ignored. Earlier RTX 4090 report
RX 580 failures and hardware skips on both revisions

Both builds failed the same tests, gpu_cmp_class_f16_preserves_snan, gpu_compute_tg_size_counts_a_partial_last_wave, gpu_ds_swizzle_and_bpermute_zero_inactive_lanes, gpu_f16_defaults_to_round_to_nearest_even, gpu_f32_compares_with_nan, gpu_f64_compares_with_nan, gpu_f64_literal_high_word, gpu_f64_math_random, gpu_f64_roots, gpu_f64_rounding_and_conversions, gpu_float_compares_random, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_ldexp_f32, gpu_ldexp_f64, gpu_mad_nf_f16_rounds_intermediate_in_binary16, gpu_nonfused_mad_and_mac_prevent_fma_contraction, gpu_s_round_mode_controls_f16_rounding_across_modes, gpu_safe_s_barrier_multi_warp_and_early_endpgm, gpu_sdwa_f16_inline_constants, gpu_signed_bfe_arithmetic_shift, gpu_wave32_and_wave64_src_vccz_execz.

Process exit 0xc0000005 in gpu_wave64_ps_whole_wave_reductions.

  • no heap windows (1) — heap_window_out_of_memory_falls_back_to_the_switch_form.
  • no mesh shaders (4) — emitted_ms_primitive_attribute_reaches_the_pixel_shader, emitted_ms_ps_draw_a_triangle, gpu_geometry_mode_es_gs_strip, gpu_mesh_mode_two_passes.
  • no wave32 (15) — approximate_float_unary_ops_are_within_tolerance, derivatives_in_compute_run, doubles_match_cpu, exact_float_unary_ops_match_cpu, float_binary_tertiary_and_half_conversions_match_cpu, groupshared_barrier_and_atomics_run, half_precision_overloads_run, int64_bit_ops_match_cpu, integer_ops_match_cpu, raw_and_structured_buffer_atomics_run, texture_ops_run, typed_buffer_ops_run, uaddc_and_usubb_match_cpu, uav_array_3d_stores_loads_and_texture_atomics_run, wave_ops_match_cpu.
  • no wave32 / wave64 (1) — blocks_are_written_in_reverse_post_order.

Regression run

After pushing fcc8247, I ran scripts/smoke.ps1 -Game Retail -Seconds 60 on both release builds with XCL_ASYNC_PSO=0 and a fresh title data root for each run. All eight runs exited normally with zero crashes or device removals.

Starting DXIL cache and run order Frames, main / PR Peak process commit in MB, main / PR
Empty, main first 414 / 328 12,144 / 12,365
Matched warm cache, PR first 1,672 / 1,666 14,311 / 14,577
Matched warm cache, main first 1,671 / 1,666 14,184 / 14,442
Empty, PR first 394 / 339 12,455 / 12,341

The four warm runs started with byte-identical copies of the same 3,061-file cache. Each copy held both builds' original translated entries for 1,020 shared shader keys with matching DXIL and sampler payloads. The blocks below are from the first matched pair.

With empty caches and main first, the PR showed 79.2% of upstream's frames, below the 80% threshold. Reversing the order, the PR showed 86.0% of upstream's frames and met both thresholds. Both matched warm-cache pairs passed within six frames of main.

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: Radeon RX 580 Series
title: Retail
seconds: 60
exit: 0x0
frames shown: 1672 (PresentX 1672)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14311 MB
xcl-smoke v1
commit: fcc8247a945560f0d288767260324d00204200d8
gpu: Radeon RX 580 Series
title: Retail
seconds: 60
exit: 0x0
frames shown: 1666 (PresentX 1666)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14577 MB
Earlier cache comparisons on the identical source tree

Previous head 54d5cd78da13 and the same upstream parent. Each row is a 60-second main/PR comparison.

Starting DXIL cache and run order Frames, main / PR Peak process commit in MB, main / PR
Empty, main first 395 / 350 12,404 / 12,383
Each build's own warm cache, main first 1,675 / 1,669 14,401 / 18,181
Copy of upstream's warm cache, PR first 1,673 / 1,550 14,386 / 22,039
Both revisions' entries, PR first 1,668 / 1,672 14,457 / 14,539
Both revisions' entries, main first 1,674 / 1,669 14,174 / 14,453

The first warm pair exceeded the 25% peak-commit limit (+26.2%). Using upstream's cache alone also exceeded it. XCL keys its translated entries by compiler source, so the PR had to translate again with that upstream-only cache. For the last two pairs, I verified the cached DXIL and sampler payloads matched for 1,020 shared shader keys, kept the original entries under each build's own key, and gave all four runs byte-identical copies of the resulting cache.

Not tested

Asynchronous PSO creation, gameplay correctness on other GPUs at this head, and game-wide compilation time. The paired shader comparisons cover translation, byte equality and validation. The optional XCL_SAMPLE_* fixtures were unset in the workspace suite.

AI use

OpenAI Codex used GPT-6.2 Astra (gpt-6.2-astra) at maximum reasoning effort (max) to write the optimization and regression test, rebase the patch, run the tests and comparisons and prepare this report.

@lows78

lows78 commented Nov 24, 2026

Copy link
Copy Markdown

Test report for #1573 at be200ab03d6b783e1e575ae693d225a0ba0f529a (clean tree; same file tree as the previous head 11cd98c), on an RTX 4090, to add a full-suite run without failures next to the RX 580 one. I am not a graphics developer: Claude Code ran this on my PC, and I can rerun things if that helps.

Tested

  • NVIDIA GeForce RTX 4090 (driver 621.01, 32-lane waves), Intel Core i9-14900KF, 32 GB RAM, Windows 11 Pro 10.0.26200, rustc 1.99.1 MSVC, DXC 1.8.2502.11, debug. XCL_SAMPLE_* unset.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4, one run per commit:
    • main 9e3831e: 776 passed, 0 failed, 41 ignored
    • this PR be200ab: 777 passed, 0 failed, 41 ignored
    • previous head 11cd98c: 777 passed, 0 failed, 41 ignored
  • SKIPPED, the same three on each: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
  • cargo test -p xcl --lib static_samplers -- --test-threads=4 on 11cd98c, 10 runs: 2 passed, 0 failed in each
  • constant_samplers from main against this PR's, called on the same decoded instructions (temporary test on 11cd98c, not part of the PR): 20,000 random sequences of s_mov_b32/b64, s_movk_i32, s_add_u32, v_mov_b32 and image_sample_lz with random block starts. 152,826 image instructions, 9,007 constant descriptors, all equal. With the PR's known.clear() removed, the same test fails.

Not tested

  • Translation time, retail titles (no smoke.ps1 run) and retail shaders, release builds, AMD, Intel, native wave64
  • The random sequences do not cover other scalar instructions that write SGPRs, or other image instructions

AI use

  • Claude Code, Claude Opus 5.5: ran the builds and tests, wrote the temporary test and this report

@nnonno91

nnonno91 commented Nov 24, 2026 •

Copy link
Copy Markdown

Retest of fcc8247a945560f0d288767260324d00204200d8 on Windows

  • The published head has the same Git tree as 54d5cd7 below. On the clean new head, cargo build --workspace --locked passed and cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-output reported 859 passed, 0 failed, 42 ignored on each adapter. Both runs logged the heap_window_out_of_memory_falls_back_to_the_switch_form skip (heap windows off). The RTX 5090 also skipped gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no native wave64). These skips are included in Cargo's pass count.
  • I also compared current main at 9039900ba3710fda9d791db589d548b1aaeb3cf8 (includes Direct DXIL: memory windows through the descriptor heap (XCL_HEAP_WINDOWS) #1693) with a temporary local merge of this PR into it (tree ef008c6aba0e78b1f58fd40cf7b96cd609388e00). With XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1, cargo test --locked -p xcl --lib gpu::recomp -- --test-threads=4 --show-output reported 194 passed, 0 failed, 18 ignored on main and 195 passed, 0 failed, 18 ignored with the PR on each GPU. The two RTX 5090 wave64 skips were the same on both trees. AMD logged no skips in this filter. The heap-window read/write and no-alias tests passed on both trees.
  • I reran the temporary one-window sampler probe below on both trees and both GPUs with the same command, adapting it to run split wave64 on the RTX 5090. All four invocations passed without skips. Both translators returned the expected point/linear/point values in wave32, AMD native wave64, and NVIDIA split wave64. All six generated HLSL and DXIL file hashes per adapter still matched between main and the local merge.
  • Same Windows, CPU, AMD driver, Rust, and DXC versions as below. The added adapter is an NVIDIA GeForce RTX 5090 (32.0.16.1742). OpenAI Codex (GPT-6 family, exact variant unavailable) adapted the probe, tested the new head and local merge, and updated this report.

Independent AMD check of both compiler paths at 54d5cd78da132668ee8a3be7ff239c83380b7f66 (rebased on c160d86ef2efe3a07e4dfb473e4fa72eafb413c0).

Tested

  • AMD Radeon(TM) Graphics (Ryzen 7 9800X3D integrated GPU, driver 32.0.21042.62), Windows 11 25H2 build 26200.9974, Rust 1.100.0 MSVC, SDK DXC 1.8.2502.11. XCL_ADAPTER='AMD Radeon'. Unoptimized Rust builds, with debug info disabled on the PR.
  • cargo build --workspace --locked passed. cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-output reported 859 passed, 0 failed, 42 ignored. One explicit hardware skip is included in the pass count (heap_window_out_of_memory_falls_back_to_the_switch_form, heap windows off). The bundled title passed.
  • With XCL_REQUIRE_GPU=wave64,mesh, cargo test --locked -p xcl --lib -- static_samplers --test-threads=1 --nocapture gave 2 passed, 0 failed, 0 ignored, 0 skips.
  • cargo test --locked -p xcl --test sampler_reuse_probe -- --exact reused_sampler_registers_match_across_compilers --test-threads=1 --nocapture ran the same temporary fixture at the base and PR (one pass each, no skips). A block with no image wrote to the sampler registers. The next block initialized them and reused those registers for three reads with point, linear, then point filtering. Both the HLSL and direct kernel translators produced exactly the expected two static sampler descriptors. Each generated kernel ran on the GPU in wave32 and native wave64. All four RGBA components per sample matched the expected bits for every lane, including red values 2.0 / 1.5 / 2.0.
  • SHA-256 matched base to PR for all six emitted files (HLSL source, DXC-compiled DXIL, and direct DXIL, for each wave size).

Not tested

Retail shader packs or titles, performance, or direct runtime routing through a title PSO.

AI use

OpenAI Codex (GPT-6 family, exact variant unavailable) wrote the temporary probe, ran the tests, and drafted this report.

Sampler constants only reach an image instruction in the same block. Apply pending scalar writes at each image and discard them at the next block boundary. This skips register analysis on image-free blocks and after the last image in a block.

Release translation of 54 retail VS, PS and CS programs took 81.15 ms against 86.50 ms on main. The generated HLSL and all 45 static sampler descriptors matched.

Assisted-by: Codex (GPT-6.2 Astra, max reasoning effort)
@philip-roy-jones
philip-roy-jones force-pushed the recompiler-sampler-blocks-1269 branch from 54d5cd7 to fcc8247 Compare November 24, 2026 19:45
@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, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026
@Pipodi

Pipodi commented Nov 24, 2026

Copy link
Copy Markdown

Test report for fcc8247: one title run of the retail title, against main on the same machine. This PR does not change where the title stops presenting in its intro, at least on this card and in this setup.

Setup

  • RTX 4090 (driver 617.42), i9-13900K, 32 GB, Windows 11 Pro 26300, release.
  • main 689f2db against 689f2db + this PR (local merge, no conflicts).
  • Each run: 300 s, a new empty XCL_DXIL_CACHE, A pressed at 16 s and then every 15 s, XCL_NETWORK=0, default settings otherwise.
  • One run each.
main 689f2db + fcc8247
exit 0 0
frames shown 1,379 1,363
last 2 s window with presents 74.0 s 72.0 s
presents after it, to 300 s 0 0
skipped draws / dispatches 0 / 0 0 / 0
pipeline builds ≥ 2 s 0 1 (2.9 s, at 126 s)
peak commit 32.3 GB 32.1 GB

Both runs stop presenting at the same point and stay at 0 presents for the rest of the run. With one run each, this shows no change in the stop; it says nothing about the time this PR saves per translation.

Not tested: a warm cache, repeat runs, other GPUs.

AI use: Claude Code. Claude Sonnet 5.5 (a second session) made the two runs; Claude Opus 5.5 checked the counts against the run logs and wrote this report.

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.

6 participants