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

Merged
upipibi merged 1 commit from upstream-pr/2156 into main 2026-11-25 10:49:10 +00:00
upipibi commented 2026-11-25 06:28:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-25T06:28:42Z.


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 (#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

<!-- greyfinch-sync:ivall/xcl:issue:6598650925 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2156). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T06:28:42Z. --- `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 (#2046). - Non-GPU lib tests: 957 passed, 0 failed. **Regression run** Run by luckyteagirl on an AMD Radeon RX 6800M ([comment](https://github.com/xcl-dev/xcl/pull/2156#issuecomment-7155732223)), `main` and this head, pasted unedited: ```text 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 ``` ```text 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](https://github.com/xcl-dev/xcl/pull/2156#issuecomment-7155336187)) and AMD RX 6800M (luckyteagirl, [comment](https://github.com/xcl-dev/xcl/pull/2156#issuecomment-7155732223)). - 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](https://claude.com/claude-code)
JJAutoCompare commented 2026-11-25 07:05:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-25T06:57:32Z.


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.
<!-- greyfinch-sync:ivall/xcl:comment:7155336187 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2156#issuecomment-7155336187). Originally posted by [JJAutoCompare](https://github.com/JJAutoCompare) on 2026-11-25T06:57:32Z. --- **Tested** - [xcl-dev/xcl PR #2156](https://github.com/xcl-dev/xcl/pull/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 commented 2026-11-25 07:05:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T07:04:54Z.


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

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7155466524 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2156#issuecomment-7155466524). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T07:04:54Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
luckyteagirl commented 2026-11-25 08:08:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-25T07:19:22Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7155732223 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2156#issuecomment-7155732223). Originally posted by [luckyteagirl](https://github.com/luckyteagirl) on 2026-11-25T07:19:22Z. --- 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. ```text 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 ``` ```text 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.
upstream-sync closed this pull request 2026-11-25 11:08:24 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!2146
No description provided.