Skip to content

Recompiler: read shader rodata on sub-dword global/flat loads in HLSL and Direct DXIL - #3607

Merged
throny merged 2 commits into
xcl-dev:mainfrom
Foniass:ready/3368
Dec 1, 2026
Merged

throny merged 2 commits into
xcl-dev:mainfrom
Foniass:ready/3368

Conversation

@Foniass

@Foniass Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Replaces #3368 so it can be merged as is: it carries Kalmarv's commit from #3368 unchanged (same SHA, author kept) plus one test-only commit that fixes the new test's expectation (with several memory windows a code address reads 0 beside the block, in both backends; details in #3368 (comment)). All credit for the fix goes to Kalmarv.

Sub-dword global/flat loads (flat_small) skipped the lookup in the shader's embedded .rodata that dword loads already do, so a shader indexing a byte or 16-bit constant table placed after its program read the wrong bytes. This routes them through the same lookup in HLSL and Direct DXIL.

What is in it

  • crates/xcl/src/gpu/dxil/lower_mem.rs: pass rodata: bool into ld_raw_u32_guarded so flat sub-dword loads (global_load_ubyte, global_load_sbyte, global_load_ushort, global_load_sshort, global_load_short_d16, global_load_short_d16_hi, and the corresponding flat_load_* ops) route their aligned dword reads through rodata_loads before sub-dword shift/merge, while keeping mubuf callers on rodata = false.
  • crates/xcl/src/gpu/recomp/emit.rs: emit an xcl_gload_u32 helper in rodata_loader that combines xcl_gload2(a & ~3u) across aligned and unaligned byte offsets, and use it in flat sub-dword loads whenever shader .rodata is present.
  • crates/xcl/src/gpu/recomp/tests.rs: add subdword_global_loads_read_rodata_in_hlsl_and_direct_dxil, covering HLSL codegen (with and without .rodata), Direct DXIL translation and validation (1-window and 2-window), and GPU execution across all six sub-dword load opcodes, aligned and unaligned 4-byte boundary crossings, .rodata hits, and non-rodata global memory on HLSL and Direct DXIL paths.
  • crates/xcl/src/gpu/recomp/tests.rs (second commit, Tests: expect 0 beside the rodata block with several memory windows): with several memory windows a code address is in no window and reads 0 (the window lookup in emit.rs / lower_window.rs; main's gpu_loads_read_the_constant_data_after_the_program relies on the same rule), so the ushort that straddles the block's start or end takes 0 there, not window 0's decoy word. Before it, the test failed on the HLSL 2-window run ("ushort across the block's start edge", 1024 against 1185) although the loads were right.

Why

Dword-wide global/flat loads (global_load_dword*, flat_load_dword*) already checked embedded shader .rodata (xcl_gload* in HLSL and rodata_loads in Direct DXIL) when reading constant tables placed after the shader program, because on PC those addresses are not backed by the shader binary in VRAM. Sub-dword global/flat loads (flat_small) bypassed that lookup and read ld_raw directly, returning wrong bytes whenever a shader indexed a byte or 16-bit constant table in .rodata (including unaligned 16-bit loads spanning two dwords).

Tested

Run by Foniass on head fb986aecec94a839d72cf5bcaf2d5f26fabf6edc merged into main 6bfb5c5153ccc23517daf30aa1071ddb0fadb53c (clean merge): NVIDIA GeForce RTX 5070 Ti (driver 621.14), AMD Ryzen 7 7800X3D, Windows 11 Pro build 26300, rustc 1.100.0 (0ef1bc386 2026-11-09) (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17, debug tests / release smoke.

  • cargo build --workspace: ok.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 2905 passed, 0 failed, 51 ignored (43 test binaries). subdword_global_loads_read_rodata_in_hlsl_and_direct_dxil passes on all five paths. A first run lost the lib binary to a 0xc0000005 in the NVIDIA driver right after gpu::agility::tests::create_device_sets_dred_first, a crash this machine also has on main; the rerun passed.
  • SKIPPED (28): 22 × no wave64 (the GPU runs wave64 split; lower_dxil, lower, kernel and two recomp::tests GPU comparisons), 2 × no heap windows (heap_window_out_of_memory_falls_back_to_the_switch_form, two_pass_binds_set_the_shared_view_heap), 3 × no D3D12 debug layer (uploads_start_from_each_subresources_state, the title under the debug layer with and without DRED), 1 × pso_measurement_compiles_an_exact_synthetic_record (cannot disable the driver cache without Developer Mode).
  • The new test fails without the fix: with emit.rs and lower_mem.rs at main it stops at "expected xcl_gload_u32 in HLSL"; with only lower_mem.rs at main it fails on the GPU at "Direct DXIL 1-window lane 0 off 0: ubyte" (0 against 5).
  • Earlier, by the author, on 8645f312 (before the rebase): cargo check --workspace --all-targets, the two targeted GPU tests, the full suite (exit 0) and cargo build --release -p xcl on an RTX 5070 Ti (driver 32.0.16.1074), Ryzen 9 9950X, Windows 11 build 26200, rustc 1.99.0; a 150 s smoke run with XCL_DIRECT_DXIL=all, XCL_HEAP_WINDOWS=1, XCL_DRED=1 showed 1587 frames against 1695 on main f0e8fdd5, no device removal, no crash.

Regression run

The same title for 60 s, release builds of main and of this PR's head with no uncommitted changes. Both blocks were made with main's scripts/smoke.ps1: the branch's own copy predates main's fix that hands XCL_PREPARE=0 / XCL_RUN_SECONDS to the process, so with it the title ran without a time limit and was killed.

main:

xcl-smoke v1
commit: 6bfb5c5153ccc23517daf30aa1071ddb0fadb53c
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1517 (PresentX 1517)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 17092 MB

this PR:

xcl-smoke v1
commit: fb986aecec94a839d72cf5bcaf2d5f26fabf6edc
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1612 (PresentX 1612)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17819 MB

Not tested

  • AMD or Intel GPUs and native wave64 hardware (the RTX 5070 Ti runs wave64 split; the 22 no wave64 tests above did not run).
  • Titles beyond the one smoke title; the smoke run does not show whether that title reaches a sub-dword .rodata load.
  • Sub-dword flat_load_* hitting LDS via the flat aperture (unchanged; rodata check only matches the shader binary's .rodata GPU VA range).

AI use

Used an AI coding assistant to audit lower_mem.rs and emit.rs, draft the fix and unit/GPU tests, and run the verification suite. All diffs, test assertions, and hardware results were reviewed and verified locally.

The test fix (second commit), the test run and the smoke pair above were done with Claude Code (Claude Opus 5.5) for Foniass.

🤖 Generated with Claude Code

Kalmarv and others added 2 commits November 30, 2026 18:30
… Direct DXIL

HLSL's xcl_gload_u32 looks up each of the two dwords on its own, as Direct DXIL's rodata_loads does: through xcl_gload2 it decided with the first dword's address only, so a 16-bit load starting 1 byte before a rodata block took its upper byte from memory in HLSL and from the block in Direct DXIL. The test adds 16-bit loads across the block's start and end edges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
subdword_global_loads_read_rodata_in_hlsl_and_direct_dxil expected the
ushort that straddles the start and end of the rodata block to take its
outer byte from window 0's decoy words (BEFORE / AFTER) on the 2-window
and heap-window paths too. With several memory windows an address in the
shader's code range lies in no window, and a load from no window reads 0
(emit.rs's window lookup and lower_window.rs); main's own
gpu_loads_read_the_constant_data_after_the_program relies on the same
rule. So the HLSL 2-window run failed ("ushort across the block's start
edge", 1024 against 1185) although the loads were right.

The check now takes whether the run uses several windows and expects
0 for the byte beside the block then. The 1-window paths keep BEFORE /
AFTER. The test still fails with emit.rs and lower_mem.rs reset to main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 1, 2026
@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: fb986ae

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 1, 2026
@fromthemoonx

fromthemoonx commented Dec 1, 2026 •

Copy link
Copy Markdown

merge-check
base: 6bfb5c5
head: fb986ae
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2905 passed, 0 failed, 51 ignored (base: 2904 passed, 0 failed, 51 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: none
review: read the whole diff (both commits; 3 files, +142 -6). No correctness problem found.

  • Sub-dword flat / global loads now take their aligned dwords through the .rodata lookup, as dword loads already do:
    • Direct DXIL: ld_raw_u32_guarded(.., rodata: true) -> rodata_loads. mubuf keeps false.
    • HLSL: xcl_gload_u32, which looks up each of the two dwords on its own.
  • Kalmarv's commit 6232c2a0 keeps its author; Foniass's test-only commit is on top.
  • gpu::recomp::tests::subdword_global_loads_read_rodata_in_hlsl_and_direct_dxil with XCL_REQUIRE_GPU=mesh on this wave32 GPU: 3 of 3 passed, not skipped.
  • Mutation: Direct DXIL sub-dword path back to rodata: false fails the test in its GPU readback check (tests.rs:5747). Good.
  • Mutation: HLSL back to ld_raw(..).x when .rodata exists fails it at the same check. Good.
  • No retail title on this machine: a title's byte / 16-bit tables were not read here.
    performance: not measured. Sub-dword loads in programs with .rodata gain the same range check that dword loads already pay; programs without .rodata emit the same code as before.
    verdict: safe to merge
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 1, 2026
@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: f07e426
head: fb986ae (same as the claim)
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2905 passed, 0 failed, 51 ignored; 25 SKIPPED lines (no wave64 / heap windows / driver-cache test on this adapter), no test binary ended abnormally
review: none found after reading the whole diff (213 lines). Sub-dword global/flat loads (ubyte/sbyte/ushort/sshort/short_d16/_hi) of unaligned 16-bit values now consult embedded shader rodata in HLSL (new xcl_gload_u32, only emitted/used when rodata is non-empty) and in direct DXIL (ld_raw_u32_guarded gets a rodata flag, true only on the d16 load site; the two store read-modify-write sites keep false). Observation: in lower_mem.rs only one of three call sites passes true, the other two are stores, which is plausible. Test: translate checks (no GPU, HLSL without rodata has no xcl_gload_u32; with rodata it does; direct DXIL translates and validates when DXC exists) run everywhere; the numeric checks run only after gpu_ready(), otherwise the test returns early, so on a machine without a GPU the value checks do not run. Scope: one change plus test; translator sources, so testers re-translate shaders.
performance: translator output changes only for shaders with rodata and sub-dword loads: one extra lookup of two dwords per such load. Shaders without rodata are unchanged (test asserts it for HLSL). Not measured.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300; Claude Code, Claude Sonnet 5.5 ran the build and the suite and read the diff; Claude Opus 5.5 checked this report

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
@throny
throny merged commit 1c8b551 into xcl-dev:main Dec 1, 2026
3 checks passed
@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Merged at the checked head after a combined trial of #3600, #3493, #3608 and #3607 on main f07e426d (RTX 4080 16 GB, cargo test --workspace --no-fail-fast -- --test-threads=4: 2909 passed, 0 failed, 51 ignored, 25 SKIPPED lines). Two merge checks each.

AI use: Claude Code (Claude Opus 5.5).

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

Labels

area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants