Skip to content

Recompiler: an image_load after an image_store of the same image reads the store - #2156

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
upipibi:fix/image-load-after-store
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
upipibi:fix/image-load-after-store

Conversation

@upipibi

@upipibi upipibi commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

image_load reads an image through its SRV (tw0), while image_store and the image atomics write its UAV (tw0 + 1). Within one dispatch the SRV need not see the UAV's writes, so a program that stores a texel and loads it back can read the old value. RDNA2 reads its own writes. On an RTX 3070 the new test reads the old value on all 64 lanes with XCL_DIRECT_DXIL=1. The HLSL path happens to see the write on this driver, but D3D12 doesn't promise it.

What is in it

  • recomp/emit.rs: image_write_srsrcs lists the T# SGPRs a program stores or does image atomics through (at most 16). Each such store or atomic records, per invocation, which image it wrote (xcl_iw{srsrc} = tw0 + 1). A later image_load of the same image reads through the UAV. Every other load, and cube and mip loads (a UAV view is a single mip), stays on the SRV.
  • dxil/lower_image.rs, dxil/lower.rs, dxil/kernel.rs: the same on the direct DXIL path, with 16 per-lane variables (VAR_IMG_WRITE) and a typed UAV load.
  • recomp/runner.rs: the test runner now always creates the SRV of a test texture, as the runtime does. A UAV test texture had none, so its loads read 0.
  • recomp/tests.rs:
    • gpu_image_load_reads_a_store_of_the_same_dispatch: an 8x8 R32_UINT image set to 0xEEEEEEEE. Each lane stores 1000 + lane to its texel, loads the same texel, runs s_barrier, then loads lane ^ 1's texel.
    • image_load_of_a_stored_image_reads_through_the_uav: a codegen test that needs no GPU.

Tested

  • RTX 3070 (Ampere, driver 616.56), Windows 11, debug, on main 6020a33.
  • main with the new test (and the runner SRV fix): it fails with XCL_DIRECT_DXIL=1 on all 64 lanes, reading 0xEEEEEEEE. It passes with XCL_DIRECT_DXIL=0.
  • This branch: the new test passes on both paths.
  • gpu_ suite (--skip gpu_sparse_vram): 135 passed with XCL_DIRECT_DXIL=0. With 1, 134 passed and 1 failed: gpu_image_get_resinfo_1d_array, which fails on main too (Direct DXIL: image_get_resinfo of a 1D array gives the layers in y #2046).
  • Non-GPU lib tests: 957 passed, 0 failed.

Regression run
Run by luckyteagirl on an AMD Radeon RX 6800M (comment), main and this head, pasted unedited:

xcl-smoke v1
commit: 6020a33b16ba2de25b3aef5947552f2dc1831f09
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 7
exit: 0x0
frames shown: 1 (PresentX 1)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 6952 MB
xcl-smoke v1
commit: ec356bc5c8d41053cbd129c991c6f0e56fa319ed
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 7
exit: 0x0
frames shown: 1 (PresentX 1)
presents per 2 s (last 3): 0 0 1
device removals: 0
crashes: 0
peak commit: 7024 MB

Not tested

  • AMD and Intel on my side. Outside reports at ec356bc: Intel Arc A770 (JJAutoCompare, comment) and AMD RX 6800M (luckyteagirl, comment).
  • Native wave64.
  • A title run that gets past startup: the regression run above shows 1 frame on both trees, so it doesn't reach the image loads this changes. I haven't counted how many shipped programs load an image they also store to in the same dispatch.
  • Reading another lane's store after s_barrier. s_barrier is translated as a group-memory-only barrier (emit.rs:1264, dxil/lower.rs:1005), which doesn't order UAV writes between lanes. This PR covers a lane reading an image it stored to itself. The neighbour read in the test passes on this NVIDIA driver, but D3D12 doesn't guarantee it. That would be a separate change to the barrier.

AI use

  • AI-assisted (Claude Code, Claude Opus 5.5): found while cross-checking RDNA2 behaviour measured in boykopovar/AnyPS5 (#26593), wrote the fix and the tests, and ran the tests above. Synthetic tests only.

🤖 Generated with Claude Code

…s the store

image_load read through the image's SRV (tw0) while image_store and the image
atomics write its UAV (tw0 + 1). Within one dispatch the SRV need not see the
UAV's writes, so a program that stores a texel and loads it back read the old
value; RDNA2 reads its own writes. On an RTX 3070 the new test reads the old
value on 64 of 64 lanes with XCL_DIRECT_DXIL=1 (the HLSL path happens to see
the write on this driver).

Each image store or atomic now records, per invocation, which image (tw0 + 1)
it wrote through each T# SGPR the program stores with; a later image_load of
that same image reads through the UAV. Every other load stays on the SRV.
Cube images and mip loads keep the SRV, since a UAV view is a single mip. Both
paths; the test runner now creates the SRV a UAV test texture needs, as the
runtime does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JJAutoCompare

Copy link
Copy Markdown

Tested

  • xcl-dev/xcl PR #2156 at ec356bc5c8d41053cbd129c991c6f0e56fa319ed. The PR was open at that SHA before and after the run. The assigned worktree remained clean and detached at the SHA after testing.
  • STOR-WINLAB, AMD Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Windows 11 Enterprise Evaluation 25H2 build 26200.9974, Rust and Cargo 1.100.0 on x86_64-pc-windows-msvc, unoptimized test profile with debug info and incremental builds disabled, DXC 1.9.2609.5 (01b62ad4).
  • Prebuilt outside the GPU lock with cargo test -p xcl --lib --no-run --message-format=json. Used CARGO_TARGET_DIR=L:/XclTooling/pr2011-990b9d4-t3-76a0502d/target, CARGO_BUILD_JOBS=2, CARGO_INCREMENTAL=0, CARGO_PROFILE_DEV_DEBUG=0, CARGO_PROFILE_TEST_DEBUG=0, and private TEMP and TMP at L:/XclTooling/pr2156/run-20261125-075425-121/temp. Pinned Cargo's emitted test binary in the run directory. Its SHA-256 stayed 27489121E4B0202DE2D8AA90103CB368FFD439C02E3076C19A75098C83D6B6F6.
  • CPU, outside the lock: & 'L:/XclTooling/pr2156/run-20261125-075425-121/xcl-pr2156-lib-tests.exe' --exact gpu::recomp::tests::image_load_of_a_stored_image_reads_through_the_uav --nocapture --test-threads=1. The HLSL codegen assertions passed for the UAV load after a store and the SRV-only load.
  • Arc, inside & 'L:/XclTooling/Invoke-ArcTest.ps1' -Test { ... }: ran & 'L:/XclTooling/pr2156/run-20261125-075425-121/xcl-pr2156-lib-tests.exe' --exact gpu::recomp::tests::gpu_image_load_reads_a_store_of_the_same_dispatch --nocapture --test-threads=1 twice, with XCL_ADAPTER=A770, XCL_DXC_DIR=%LOCALAPPDATA%/XclTooling/dxc-1.9.2609/bin/x64, and XCL_DIRECT_DXIL=0 (HLSL + DXC) and 1 (direct DXIL). Each run passed the readback checks for all 64 texels of the 8×8 R32_UINT image. Each texel contained 1000 + lane, each lane's immediate load returned its own value, and its load after s_barrier returned 1000 + (lane ^ 1). The neighbor result is specific to this fixture and driver.
  • 3 passed, 0 failed, 0 ignored, 0 explicit skips across the three invocations. Each invocation filtered out 1125 other tests. The wrapper exited 0 and its terminal output confirmed Released the XCL Arc A770 test lock. PowerShell's saved Arc log captures both fixture outputs and exit codes. The wrapper's host messages appeared in the terminal output.
  • Logs: L:/XclTooling/pr2156/run-20261125-075425-121/build.log, L:/XclTooling/pr2156/run-20261125-075425-121/build.jsonl, L:/XclTooling/pr2156/run-20261125-075425-121/cpu.log, and L:/XclTooling/pr2156/run-20261125-075425-121/arc.log.

Not tested

  • Full workspace suite, retail-title smoke, main/base comparison, other adapters, and native wave64.

AI use

  • T3 Code / Codex (gpt-6.2-sol) ran the checked-in fixtures, verified the checkout and logs, and wrote this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent native Windows AMD check of exact PR head ec356bc5c8d41053cbd129c991c6f0e56fa319ed. The PR asks for a paired real-title smoke and lists AMD/native wave64 as untested.

Tested

  • Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M driver 30.0.13002.13003; Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5. Debug tests and release title runs.
  • XCL_ADAPTER=6800M, XCL_REQUIRE_GPU=wave64; cargo test --locked -p xcl --lib -j 2 gpu_image_load_reads_a_store_of_the_same_dispatch -- --test-threads=1 --show-output: 1 passed, 0 failed, 0 ignored, 0 SKIPPED with XCL_DIRECT_DXIL=1, and the same counts with XCL_DIRECT_DXIL=0. The 8x8 R32_UINT fixture checks each lane's store followed by its own load; its neighbor-after-barrier result is driver-specific as the PR notes.
  • image_load_of_a_stored_image_reads_through_the_uav: 1 passed, 0 failed, 0 ignored. cargo build --locked --workspace --release -j 2: passed.

Regression run

Paired guarded seven-second launches of the same owned title with isolated data and DXIL caches, no input. The main commit below has the same runtime source as this PR's 6020a33 base.

xcl-smoke v1
commit: 6020a33b16ba2de25b3aef5947552f2dc1831f09
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 7
exit: 0x0
frames shown: 1 (PresentX 1)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 6952 MB
xcl-smoke v1
commit: ec356bc5c8d41053cbd129c991c6f0e56fa319ed
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 7
exit: 0x0
frames shown: 1 (PresentX 1)
presents per 2 s (last 3): 0 0 1
device removals: 0
crashes: 0
peak commit: 7024 MB

Both launches reached their first frame but logged zero draws and zero dispatches. They are short startup regressions, not evidence that the title uses the image read-after-write path. The focused GPU fixture above exercises that path. I did not run the full workspace suite or a longer title session.

AI-assisted checkout, testing, smoke monitoring, log verification, and report drafting with OpenAI Codex (GPT-6). No game data was uploaded.

@raylitebull
raylitebull merged commit 03f8e57 into xcl-dev:main Nov 25, 2026
2 of 3 checks passed
anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
Brings main to full parity with upstream/main (cdb0891), including:
- World rendering & gameplay: xcl-dev#1991, xcl-dev#1988, xcl-dev#1984, xcl-dev#2028, xcl-dev#2078
- Memory / VRAM / PSO: xcl-dev#1985, xcl-dev#2157, xcl-dev#2178, xcl-dev#2195, xcl-dev#2176, xcl-dev#1996, xcl-dev#1914
- Direct DXIL & shaders: xcl-dev#2120, xcl-dev#2174, xcl-dev#2194, xcl-dev#2207, xcl-dev#1951, xcl-dev#1973, xcl-dev#2156, xcl-dev#2064
- Preserves local Linux/Wine customizations: docs/linux.md, scripts/linux/*,
  in-process Wine XAsync (xgameruntime/api.rs), loader watchdog bypass, and
  Wine MEM_WRITE_WATCH bypass on coherent UMA windows (gpu/uma.rs).

Assisted-by: Antigravity (Gemini 4)
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