Skip to content

Recompiler: loads through s_getpc_b64 read the constant data after the program - #2229

Open
MacieGx wants to merge 1 commit into
xcl-dev:mainfrom
MacieGx:recomp/getpc-constant-data
Open

MacieGx wants to merge 1 commit into
xcl-dev:mainfrom
MacieGx:recomp/getpc-constant-data

Conversation

@MacieGx

@MacieGx MacieGx commented Nov 25, 2026 •

Copy link
Copy Markdown

Console programs keep constant tables after s_endpgm and read them PC-relative (s_getpc_b64 + s_load_dword* / global_load_dword*). The translation gave s_getpc_b64 the program's offset with high dword 0, so in a title those loads read memory window 0 at a low offset and got zeros. This makes both translators (HLSL and direct DXIL) read the program's own constant data there. Part of #505.

676 of the 26503 shader records of the newer retail title (#505) take such an address. Among them are all postfx_aces LUT bakes (CS_Bake*LUT*): the ACES tone-scale spline coefficients sit after the program, so with zeros every channel came out 1.0 and the 64-cube output LUT the composite pass reads was one constant texel (0.162, 0.162, 0.162, 1). The presented picture was then one flat grey whatever the scene. Others in the list: scattering_transmittance_system, prefilter_env_map, MS_VS_CascadeShadows*, MS_VS_Transform*, rtdirectionalshadows, indirect_diffuse_lighting:CS_ScreenProbes_ActivateProbes, water_*.

What is in it

  • crates/xcl/src/gpu/xbox.rs: Fssm::rodata(program), the data blocks after a program.
  • crates/xcl/src/gpu/recomp/mod.rs, emit.rs: new Options::rodata. The HLSL embeds the blocks as static const uint xcl_rodata[]; s_load and FLAT / GLOBAL dword loads take dwords at a code address inside a block from the table. With several memory windows s_getpc_b64's high dword is CODE_ADDRESS_HI (0xC0DE, above any user-space address), so a code address is not taken for the title's memory at the same low dword; with one window it stays the program's offset as before.
  • crates/xcl/src/gpu/dxil/ (kernel.rs, lower.rs, lower_mem.rs, lower_window.rs, coverage.rs): the same for the direct translator, as an internal constant array of the module (Lw::rodata_loads); with windows s_buffer_load reads it too. kernel::translate_entry_rodata carries the data; the per-lane form has no table and leaves such programs to the per-instruction form. Its TRANSLATOR_VERSION goes from 9 to 10.
  • crates/xcl/src/gpu/recomp/pso.rs, crates/xcl/src/shaders.rs: the data is passed on the compute, VS / PS and mesh paths (HLSL and direct), and by xcl shaders (--precompile, the direct sweep).
  • Tests: gpu::recomp::tests::gpu_loads_read_the_constant_data_after_the_program and gpu::dxil::core_tests::gpu_direct_loads_read_the_constant_data_after_the_program: a program reads its table through s_getpc_b64 + s_load_dword* / global_load_dword* (direct: also s_buffer_load through a V# on it), with one window, two windows in the switch form and with heap windows; the values must equal the table.
  • 400 lines added and 40 removed, 176 of them the two tests.

Tested

  • NVIDIA GeForce RTX 5080 (driver 621.24 = 32.0.16.2124), AMD Ryzen 7 5800X3D, 32 GB, Windows 11 Pro 10.0.26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, release. On 2304774 (this PR, rebased onto main 5478c4a; it merges cleanly into f087b99).
  • cargo test --release -p xcl --lib constant_data_after_the_program: 2 passed, 0 failed (both ran on the GPU, no SKIPPED).
  • cargo build --release --workspace && cargo test --release --workspace --no-fail-fast -- --test-threads=4 on 2304774: 1223 passed, 6 failed, 46 ignored.
    • 4 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3 (CreateComputePipelineState: out of memory (0x8007000E), seeds 70, 545, 1019, 1507); they fail the same way on main (checked on 568e7db: 1150 passed, the same 4 failed, 46 ignored, against 1152 / 4 / 46 for this change there).
    • 2 failures came with the rebase and fail on main c9a5d58 too, run alone: gpu::recomp::pso::shader_cache_tests::rerouted_disk_entries_follow_the_direct_translator (left: 68, right: 1) and hle::d3d12x::device_x::tests::pc_resource_desc_strips_uav_on_unsupported_formats_and_msaa ("format 85 kept"). This change does not touch either.
    • Without --no-fail-fast cargo stops after the xcl lib binary.
  • SKIPPED (the same on main): 18 "no wave64" (recomp::lower::tests ×4, recomp::lower_dxil::tests ×12, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware), 3 "refused by the per-lane form" (lower_dxil::tests), heap_window_out_of_memory_falls_back_to_the_switch_form ("no heap windows"), pso_measurement_compiles_an_exact_synthetic_record (driver cache cannot be disabled without Developer Mode).
  • The newer retail title (Newer retail title (TitleID 7952987A): reaches world loading, then the title's GPU watchdog ("GPU Loc Sig") after ListX #101 stub #505): on main alone it does not reach its world, so the effect was measured on a local branch that adds other open PRs and local work to main (XCL_HEAP_WINDOWS=1, XCL_UMA_SHADOW=1, pipelines precompiled), with this change applied (the same commits before the port to main):
    • output LUT of postfx_aces:CS_BakeACESWithGamutCompressLUT_QuasiLogShaper (64-cube RGBA16F, slice 0 read back): 1 distinct texel of 4096 before, about 3300 after, in two runs;
    • the composite's 2560x1440 R10G10B10A2 target: 2 distinct values before, 27 000–81 000 after;
    • presented world frames: one flat colour (0x262626) before, the scene after (still overexposed: the lighting has other faults).
  • xcl shaders <pack> --direct --hash 56c0cd3b82a00c6e --validate (indirect_diffuse_lighting:CS_ScreenProbes_ActivateProbes): translates in about 1 s and validates, 3.4 MB DXIL with heap windows. On the HLSL path that program is 28 MB of DXIL, so keeping it on the direct translator matters for compile time.

Regression run

main:

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 5080
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 1383 (PresentX 1383)
presents per 2 s (last 3): 35 52 56
device removals: 0
crashes: 0
peak commit: 19703 MB

this PR:

xcl-smoke v1
commit: 23047743c72f180bd142e5802ef0920c97ab30cb
gpu: NVIDIA GeForce RTX 5080
title: 16b5e5d4
seconds: 60
exit: 0x0
frames shown: 1430 (PresentX 1430)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19221 MB

Not tested

  • AMD and Intel GPUs; a debug build.
  • The smoke runs cover the title's first 60 s (logos, intro): its post chain and LUT bakes run only in the world, so they do not reach the changed loads. The world numbers above come from the local branch, not from main.
  • Byte / short global loads, MUBUF buffer_load, the legacy GS path and the per-lane form (XCL_PER_LANE) still read memory at such addresses.
  • A program that writes into its own code region (none found in the pack).

AI use

  • Claude Code. Claude Opus 5.5 coordinated the investigation, ran the title, the tests and the regression runs, reviewed the change and wrote this description. Claude Fable 5.2 subagents found the cause from the shader disassembly and wrote the HLSL and direct DXIL change and their tests; a Claude Opus 5.5 subagent ported them to main and ran the whole suite on this commit and on main.

🤖 Generated with Claude Code

…e program

Console programs keep constant tables after s_endpgm and read them
PC-relative (s_getpc_b64 + s_load_dword* / global_load_dword*). The
translation gave s_getpc_b64 the program offset with high dword 0, so in
a title these loads read memory window 0 at a low offset: zeros. 676 of
the 26503 shader records of a retail title use this, among them all
postfx_aces LUT bakes, whose 64-cube output LUT came out as one constant
texel, so the presented image was flat.

The data blocks after the program (xbox::Fssm::rodata, the new
Options::rodata) now go with the translation:

- HLSL: emit.rs embeds them as `static const uint xcl_rodata[]`, and
  s_load and FLAT / GLOBAL dword loads go through xcl_gload*, which take
  the dwords at a code address inside a block from the table. With
  several memory windows s_getpc_b64's high dword is CODE_ADDRESS_HI
  (0xC0DE, above any user-space address), so a code address is told from
  the title's memory at the same low dword; with one window it is the
  program's offset as before.
- Direct DXIL: the same, as an internal constant array of the module
  (Lw::rodata_loads in lower_window.rs); with windows s_buffer_load reads
  it too. kernel::translate_entry_rodata carries the data. The per-lane
  form (XCL_PER_LANE) has no table and leaves such programs to the
  per-instruction form. TRANSLATOR_VERSION 9 -> 10.
- pso.rs passes the data on the compute, VS / PS and mesh paths (HLSL
  and direct), and `xcl shaders` (precompile, direct sweep) does too.

Not covered: byte / short global loads, MUBUF buffer_load, the legacy
GS path and the per-lane form still read memory at such addresses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MacieGx
MacieGx force-pushed the recomp/getpc-constant-data branch from 039a363 to 2304774 Compare November 25, 2026 11:05
@itsSio

itsSio commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Tested

Independent debug verification on clean 23047743c72f180bd142e5802ef0920c97ab30cb. Windows 11 Pro 26200, x64 MSVC, unoptimized dev/test with debug info off. cargo build --workspace --locked succeeded on both PCs. cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --nocapture exited 101 on both:

GPU / driver CPU, RAM, toolchain Passed / failed / ignored Runtime SKIPPED
RTX 5080 / 32.0.16.1088 Ryzen 7 9800X3D, 32 GiB; Rust 1.97.0, DXC/DXIL 1.9.2609.5 1227 / 2 / 46 25
RTX 2080 SUPER / 32.0.16.1088 Ryzen 5 5600X, 16 GiB; Rust 1.99.1, DXC/DXIL 1.8.2502.11 1227 / 2 / 46 27

Both logged 20 native-wave64 skips, three per-lane f16/f32 refusals, and one skip each for unavailable driver-cache control and heap windows. The RTX 2080 SUPER also logged two missing-D3D12-debug-layer skips.

cargo test -p xcl --lib --locked constant_data_after_the_program -- --test-threads=1 --nocapture: 2 / 0 / 0, no runtime skips, on each of the RTX 5080, RTX 2080 SUPER, and Radeon RDNA2 iGPU (32.0.21043.5001, same Ryzen 7 system and toolchain). Both the HLSL and direct-DXIL constant-table tests passed.

The two workspace failures had identical assertions on both PCs: rerouted_disk_entries_follow_the_direct_translator (68 vs 1), and pc_resource_desc_strips_uav_on_unsupported_formats_and_msaa (format 85, got 28). I ran each on the exact parent 5478c4a7c1ae5adba127c8d27018d7fdbf3a8725 on both PCs using cargo test -p xcl --lib --locked <fully-qualified-name> -- --exact --test-threads=1 --nocapture. All four invocations reproduced the corresponding exact assertion, each 0 / 1 / 0, no skips. These signatures predate this PR; the head workspace results remain red.

Not tested

Retail smoke, title shader samples, full AMD workspace, Intel, release mode, and performance. The parent checks were targeted, not full-workspace runs.

AI use

Ran via Samaritan:

  • OpenCode with OpenAI GPT-6.2 Sol (openai/gpt-6.2-sol): scoped and ran the two-PC head and parent tests, checked logs, and wrote this report. No subagents contributed to this check.

@CharlyRien

Copy link
Copy Markdown

In-title test on an RTX 3090 (32-lane waves), on a different local stack: with this change ported, the presented world frame is no longer flat grey, and the output LUT matches your numbers. One run, with two deviations from the PR that are listed below, so read it as a second data point, not as a test of this head.

Setup

Measured

  • The PR's two tests on this card: gpu::dxil::core_tests::gpu_direct_loads_read_the_constant_data_after_the_program ... ok, gpu::recomp::tests::gpu_loads_read_the_constant_data_after_the_program ... ok, 2 passed; 0 failed.
  • 64-cube RGBA16F output LUT, read back in a world frame: 166 521 distinct texels of 262 144, 3 236 distinct in slice 0 (you report about 3 300 after, 1 before). I have no "before" readback of the LUT on this stack.
  • Presented 3840x2160 frame, sampled every 4th texel, six consecutive dumped frames 126 to 147 s into the run:
    • before (same stack without the port, another run and binary, 152 s): 1 154 distinct values, most common ff3f3836 (12.6 %), flat grey on screen;
    • after: the first three frames are near-white (78 distinct RGB values in one of them), then 4 809, 49 949 and 53 735 distinct values; in the last two an object of the scene is recognisable, blown out, white and teal, with the letterbox bars and a subtitle line.
  • The lit HDR target stays very dark (brightest channel p50 2.6e-6 in one frame), which matches your "still overexposed: the lighting has other faults" and what you describe on Newer retail title (TitleID 7952987A): reaches world loading, then the title's GPU watchdog ("GPU Loc Sig") after ListX #101 stub #505.
  • Depth and G-buffer coverage were also higher than in the "before" run (main depth fully covered in the last frame, against 9 % covered). I cannot attribute that to this change: different run, different frames.

Not tested / not established

  • The current head, and the full change without the two deviations.
  • An A/B on one binary: the "before" is a different binary of the same stack, so the change of the presented frame is attributed to this PR by your explanation and the LUT numbers, not by a controlled pair here.
  • One more run of the same binary died at 129 s with exit code 0xC0000409 before any dump; cause not found, and a local diagnostic of mine is a suspect, so I am not reporting it against this PR.
  • Frame rate, and anything past 147 s: the run was stopped there on purpose. On this stack without the port the device is removed 24 to 64 s into the world (Retail game (retail title, Series X build): GPU device removal after Wait64BitValueX waits with no producer; also watchdog stalls on slow compute pipeline builds #1452); no run with the port went far enough to say whether that changes.

AI use: Claude Code (Claude Fable 5.2 coordinating; a Claude Fable 5.2 agent did the port, the runs and the dumps). I looked at the last dumped frame and checked its log line; the other numbers are from the agent's notes.

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