Skip to content

Recompiler: compute programs follow S# constants across blocks too - #2935

Draft
pvfreis wants to merge 1 commit into
xcl-dev:nvidia-devfrom
pvfreis:recompiler/compute-s-sharp-across-blocks-nvidia-dev
Draft

pvfreis wants to merge 1 commit into
xcl-dev:nvidia-devfrom
pvfreis:recompiler/compute-s-sharp-across-blocks-nvidia-dev

Conversation

@pvfreis

@pvfreis pvfreis commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

In kernel and compute programs, an S# set before a branch and sampled after it falls back to sampler-heap entry 0 (point, wrap, mip 0). 82e4a9b follows S# constants across blocks in vertex and pixel programs only; this extends that to kernel and compute programs, in both translators. Mesh and geometry programs stay block by block. Plan: #2835.

Part of #2835. Overlaps #2572 (this branch's PR, which carries 82e4a9b), #1573 (rewrites the same loop on main) and #811 (on main: sgpr_uses does not see the SGPR an SDWA compare writes, so a constant in it is kept; with this change that reaches compute programs across blocks too).

Draft, opened early so the compute part is not done twice. The two xcl-smoke blocks are not in yet. Test reports on other cards are welcome, AMD in particular.

Why compute was left out, and what we know. fbfac4d followed the constants in every program. 82e4a9b limited that to vertex and pixel programs; its message says compute programs read this way gave ExecuteIndirect 2,055 counts out of range in 75 s on a retail title, and the device hung after 140 s. The cause is still unknown, and this change could bring it back. What we have:

  • This turns on kernel and compute programs only, not the mesh and geometry programs fbfac4d also followed.
  • On one retail title, the main form of this change (before d360233's s_bfm_b32 and 64-bit literal cases) finds the same static samplers in compute programs as fbfac4d's function: no difference in 60 programs, or in the 269 programs of a 1-in-10 sample of its shader pack. With d360233's cases it can find more; that was not counted.
  • One title run on nvidia-dev af2cecc4 (before d360233) with this change, RTX 3060: no out-of-range line from the ExecuteIndirect guard (the log does not show how many it checked) and no device removal. No present after 282 s; our memory guard stopped the run at 450 s. The same tree without the change, one run: no out-of-range line, no device removal, no present after 282 s, stopped at 465 s. One run each, so this does not rule the hang out.
  • On ecc0bb57: 63 counts out of range in one of two runs with this change, none in two runs without it, no device removal (last bullet under Tested). Two runs each, so this neither shows nor rules out that the change causes it.
  • Ruled out on NVIDIA 617.14: a compute PSO reusing a driver blob built for other static samplers. A point and a linear S# give different DXIL in both translators, and the driver refuses a blob made with the other root signature (E_INVALIDARG, both translators).

What is in it (one commit, 26ab11f0)

  • gpu/recomp/mod.rs, gpu/dxil/kernel.rs: follow is on for kernel and compute programs. s_movreld and s_movrelsd_2 (writes to SDST + an offset from M0, a register the operands do not name) forget every known constant, in every program.
  • gpu/dxil/kernel.rs: the direct translator hands constant_samplers every Cfg block's start. Before, a block that is only an s_branch or s_endpgm had none, and constant_samplers takes a block's way on from its last instruction, so s_cbranch X; s_branch Y read as one block lost the way to X and a constant set on one path only could stay. For vertex and pixel programs on the direct path (XCL_DIRECT_DXIL=all) this also follows programs that branch to such a block, which fell back to block by block before.
  • gpu/recomp/tests.rs:
    • 82e4a9b's static_sampler_set_before_a_branch_is_a_constant_after_it now expects the kernel to find the sampler after the branch.
    • Kernel and compute, both translators: an S# set before an if, an if/else, a loop or a divergent branch is the static sampler after it. With other words on one path, an s_load, an s_movreld or s_movrelsd_2 that reaches the S# through M0, or an S# from memory, the program keeps the heap lookup.
    • The branch programs on the GPU (kernel), with heap entry 0 linear.
    • d360233's s_bfm_b32 / 64-bit literal S#, set before a branch in a kernel.
    • Other words set past a lone s_branch (the direct translator's case above): no static sampler, both translators.

Tested

  • RTX 3060 12 GB (driver 617.14, 32-lane waves only), Ryzen 9 5900XT, Windows 11 26300, Rust 1.100.0, debug. cargo test --workspace --locked --offline --no-fail-fast -- --test-threads=4 at 26ab11f0, in a non-interactive session at Low integrity: xcl lib 1699 passed, 2 failed, 28 ignored; across the workspace 7 tests fail. They fail at ecc0bb57 without the change too, in the same session: the two texture_upload overflow tests, split_compute_prefers_the_offline_whole_pipeline (Tests: the thread limit tests of f9bcafd run on a wave32-only GPU #2854), async_compute_pso_registers_real_pso_and_not_standin, two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs, console_ms_in_as_slot_and_ms_with_as_are_refused_cleanly and the e2e test_title_runs_and_game_folder_is_untouched. SKIPPED on this card: the wave64 forms (no wave64), two heap-window tests (no heap windows), three per-lane f16 / conversion forms (refused by the per-lane form).
  • Without the change (these tests on ecc0bb57, same session), four tests fail and the rest is as at the head: s_sharp_set_before_a_branch_is_a_static_sampler_after_it (no static sampler, heap lookup kept), gpu_s_sharp_set_before_a_branch (1.5, heap entry 0 linear, where the S# gives 2), s_sharp_from_s_bfm_and_a_64_bit_literal_move_before_a_branch_is_a_constant_in_a_kernel, and 82e4a9b's test with its kernel check.
  • With the change but without the s_movreld / s_movrelsd_2 line, s_sharp_set_before_a_branch_is_a_static_sampler_after_it fails on exactly those two cases (kernel and compute, both translators: a static sampler where M0 overwrote the S#).
  • With the change but without the block-start line in kernel.rs, the same test fails only on other_words_past_a_lone_branch, direct translator, kernel and compute (a static sampler where one path set other words).
  • Title run: see above (af2cecc4 + the first form of this change, before the rebase; not a smoke block).
  • In-title runs, not smoke blocks: b2a4ef48 (this change without the block-start line in kernel.rs; the runs did not use the direct translator: no XCL_DIRECT_DXIL, and no direct-DXIL fallback in the logs) and its base ecc0bb57, two runs each, RTX 3060, release, XCL_PREPARE=0, XCL_NETWORK=0, empty DXIL cache, stopped at 600 s. All four stop presenting after about 90 to 100 s and go on submitting in batches. One of the two runs with the change logged 63 ExecuteIndirect counts out of range, all within 1 ms at 182 s, at 63 argument addresses: 30 hold one of two float triples (465.0 x 1000.0 x 1 is one), the rest other data that are not counts. The other run with the change and both runs of the base logged none. Each of the four has a late batch of 5 submits (143 to 261 dispatches) like the one the burst came in. No device removal in any. Cause not known. The five compute programs dispatched with those arguments get the same static samplers with and without the change (a decode of 2,682 of the 2,737 compute programs that run used; 459 of them get more static samplers with the change).

Regression run

  • Not yet: the main and head xcl-smoke blocks are not in.

Not tested

AI use

  • Claude Code (Claude Opus 5.5) wrote the change and the tests, ran the tests and the title runs, and wrote this description. Claude Fable 5.2 rechecked it.

🤖 Generated with Claude Code

@ettehn

ettehn commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Independent Windows negative/positive control on RTX 5070 Ti Laptop (621.24), Windows 11 26200.9974, Rust 1.97.1 MSVC, DXC/DXIL 1.8.2502.11, debug, XCL_ADAPTER=NVIDIA and separate XCL caches. cargo test --offline --locked -p xcl -j 4 --lib -- s_sharp static_sampler --test-threads=1 --nocapture at clean b2a4ef48 passed 9/9, no ignores or capability skips. At exact parent ecc0bb57 with only the PR's test-file diff applied, the same command gave 5 passed / 4 failed, with the four failures listed in the PR description.

The GPU negative control returned 1.5 (linear heap entry) on both sides of each tested uniform and divergent branch for both translators. The head passed the corresponding 2.0 point-sampler assertions. The translation-only controls also confirmed heap lookup remains for a descriptor overwritten through s_movreld or s_movrelsd_2. This covers synthetic shaders on a second wave32 NVIDIA generation. It leaves retail ExecuteIndirect, device-removal behavior and AMD untested. OpenAI Codex (6.2sol) assisted with verification.

@SzczepanGrela

Copy link
Copy Markdown

RX 9070 / RADV verification of head b2a4ef48c586fb430ea341df922cb41cf6267a04 against its exact parent ecc0bb57976b1bc94854199ddf4f915fd00e0a59 on nvidia-dev.

Tested

  • RX 9070 16 GB, RADV GFX1201 / Mesa 26.3.1-arch3.5, Ryzen 7 7700, CachyOS kernel 7.3.0-5-cachyos. Windows GNU release test executables built with Rust 1.97.1, run under GE-Proton11-12 / Wine 11.0 Staging. Native DXGI/D3D12 and vkd3d-proton 8293130ebe370b1+, local asserts-disabled build; DXC/DXIL 1.9.2602.17.
  • XCL_ADAPTER='AMD Radeon RX 9070' XCL_REQUIRE_GPU=wave64 XCL_NETWORK=0 XCL_DXC_THREADS=1. Private enabled caches per process. Source copies with production files matching each pinned revision; the parent carries the identical head test file. Local observations export code, shader containers, static-sampler records and raw readbacks before unchanged upstream assertions.

Commands, run through Wine:

<unit.exe> s_sharp static_sampler --nocapture --test-threads=1
<unit.exe> s_sharp static_sampler --nocapture --test-threads=4
Revision Threads 1 Threads 4
Exact parent + head tests 5 passed, 4 failed 5 passed, 4 failed
Head 9 passed, 0 failed 9 passed, 0 failed

No selected tests were ignored or skipped. The parent reproduces the four failures listed in the description. The kernel/compute translation controls keep heap lookup for differing incoming S# words, s_load, both M0-relative writers, and an S# from memory. Captured GPU branch cases select point sampling on the head and the linear heap entry on the parent; same-block controls select point on both.

Additional local fixture:

<unit.exe> gpu::recomp::tests::workflow_sampler_constant_before_branch_baseline --exact --nocapture --test-threads=1

Three fresh processes per revision, 16 cases each: native wave32/wave64, HLSL/direct DXIL, declared point/linear, straight-line/branch. Four scalar moves set S#; the branch only skips one NOP. Heap entry 0 is valid and uses the opposite filter.

Head: 16/16 cases correct in every process. Parent: all eight straight-line controls correct; all eight branch cases select heap entry 0. The parent fixture reports 0 passed / 1 failed after collecting every case; head reports 1 passed / 0 failed.

Across both groups, 160 captured GPU dispatches include 112 with WaveSize=64 metadata. All 34,816 captured RGBA words were checked independently. Head readbacks match the declared filters; the parent has the expected 5,376 differing words. Captures repeat byte-for-byte within each revision, and straight-line shader containers match across revisions.

Not tested

Retail or smoke runs, the reported ExecuteIndirect/device-hang symptom, the full suite, integration onto main, or GPU execution of the translation-only Mode::Compute controls. GPU coverage here uses kernel-mode fixtures.

AI use

OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed the PR diff, added local test-only observations and the extra fixture, ran the paired checks, independently verified captures, and drafted this report. Publication authorized by the account owner.

82e4a9b follows S# constants through branches in vertex and pixel
programs only. In kernel and compute programs a block's start still
forgets them, so a sample after a branch falls back to
SamplerDescriptorHeap[word3 & 0x7FF]. For an S# built in code that is
the border-colour pointer, usually 0: sampler-heap entry 0 (point, wrap,
mip 0).

This turns `follow` on for kernel and compute programs in both
translators (HLSL and direct DXIL), and makes s_movreld and s_movrelsd_2
(writes to SDST + an offset from M0) forget every known constant.
82e4a9b's test now expects a kernel to find the sampler after the
branch.

The direct translator handed constant_samplers the starts of its Cfg
blocks that have instructions left once the branch is taken out, so a
block that is only an s_branch or s_endpgm had none. constant_samplers
takes a block's way on from its last instruction: `s_cbranch X; s_branch
Y` read as one block lost the way to X, and a constant set on only one
path could stay. It now gets every block's start, as the HLSL path does.
For vertex and pixel programs on the direct path (XCL_DIRECT_DXIL=all)
this also follows programs that branch to such a block, which fell back
to block by block before.

Tests: kernel and compute, both translators, an S# set before an if, an
if/else, a loop and a divergent branch is the static sampler; one with
other words on one path, an s_load, an s_movreld or s_movrelsd_2
reaching the S# through M0, or an S# from memory keeps the heap lookup;
the same on the GPU with heap entry 0 linear; d360233's s_bfm / 64-bit
literal S# before a branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pvfreis
pvfreis force-pushed the recompiler/compute-s-sharp-across-blocks-nvidia-dev branch from b2a4ef4 to 26ab11f Compare November 27, 2026 02:53
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.

3 participants