Shader capture reads an inaccessible direct-root scalar load skipped by a known branch #8272

Closed
opened 2026-10-20 08:09:34 +00:00 by Amoenus · 0 comments
Amoenus commented 2026-10-20 08:09:34 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-20T08:09:34Z.


Status, 2026-10-21 UTC

Closed after #8295 merged. The upstream correction now covers the known-branch flat-load reachability gap. This records the merge and issue closure; it is not a fresh current-main runtime test or title claim. The original reproducer, proposed fix and validation below retain their recorded source pins.

Summary

Main at 7d876ad3ba9571787faa44759b9ac692e77c3eec rejects a synthetic compute program during resource capture when a scalar branch skips a load through an inaccessible, nonzero direct user-data pointer.

Test-only reproducer on our fork. It extends the existing NestedRequest/verifyGuardedNullPointers fixture with a pointer supplied in user SGPRs s2:s3 and moved to s10:s11. The scalar value is used by an output store.

The program initializes s12, loads a condition from valid memory, compares it with zero, and executes s_cbranch_scc1 at pc 0x28. With condition zero it jumps to pc 0x38, skipping s_load_dword s12, s[10:11], 0 at pc 0x2c and its wait. Decoder assertions verify the moves, compare and branch target.

Reproduction and result

Build agc_shader_memory_tests, then run:

ctest --test-dir <build> -R "^agc_shader_memory$" -V

Three consecutive Windows 11 Enterprise 26200 / WinLibs GCC 15.2.0 Release runs, each under 2 seconds for the test:

Control Result
Mapped pointer, load executes Capture, recompile and SPIR-V validation pass; flattened slot contains the payload
Mapped pointer, load skipped Capture, recompile and SPIR-V validation pass
Inaccessible pointer, load executes Capture rejects it with guest memory is not readable
Same inaccessible pointer, load skipped Capture also throws guest memory is not readable ... +0x4; expected to avoid this dereference

The inaccessible address is a test-owned MEM_RESERVE / PAGE_NOACCESS allocation. The fixture retains its region vectors and user-data array throughout their use. This is CPU capture/compiler validation; no GPU execution or title result is claimed.

Source and expected behavior

AMD RDNA 2 ISA reference, revision 2020-11-30, sections 12.3-12.5 (printed pages 111, 123-124), specifies the move, comparison and conditional PC update used here. The taken branch jumps over the scalar load; this does not rely on EXEC suppressing scalar memory instructions.

In SrtDescriptorEvaluation.cpp, evaluateRuntimeSources evaluates every flattened SRT slot after its descriptor-source walk. The fixture checks that this load's handle is not classified as LoadedFromMemory; the existing nested-pointer poison handling therefore does not cover it.

Related: #479/#759 cover guarded nested reads. #5384 was closed because #5573 fixed the reused fused-program lifetime behind #5099. This fixture builds its own program and does not exercise fusion. #7891 changes branch waits and descriptor-source selection; it does not establish coverage of this scalar-value load.

A correction needs to preserve reachability for these flat reads, or retain their load on the shader execution path, while preserving explicit failure for an invalid read that actually executes. The reproducer commit remains deliberately failing on unmodified main.

Proposed correction and validation

Experimental fix on our fork, rebased onto main 5e7c618699564093531727fbe2feaea5952a5ba1:

  • Record every flat-slot use in its resource control-flow block, including repeated uses.
  • Both the generic evaluator and SRT tape omit only slots whose uses are unreachable under a known clean condition. Unresolved guards remain conservative; invalid taken and unconditional repeated loads remain rejected.
  • Serialize that metadata, validate decoded slot bounds, and advance the cache format from 41 to 42.

At pre-rebase head a0d29666f5352ca35f8205ae2d22f9daf77e277e on main 587bb343e8baf0f9c62bdb04c9dab5eb4b938dc9, the selected targets compiled and 12 final CPU test executions passed: three runs each of shader memory, SRT read patching, shader disk cache and cache-file reading. The new fixture covers original/decoded plans, direct tape execution, compact and IR evaluation, unreadable guards, and an unconditional repeated load. Nonempty flat-slot lists now participate in the existing cache round-trip equality test. SPIR-V Tools is enabled.

Cppcheck and clang-tidy completed for all six changed translation units without parser errors. Findings were reviewed: no new production finding; a new fixed-array address-invalidation warning is a false positive, and existing advisories remain recorded.

All nine changed files are SHA-256-identical after the clean rebase. The test results above retain their original pins. The fork advanced to 8a8f2b157941deb4582808ecf926ff429888b76a with a direct-root device regression and corrected expectations in the existing GPU fixture. The full runtime build and twelve candidate GPU test executions across NVIDIA and AMD passed. The paired test-only control on main 5e7c618699564093531727fbe2feaea5952a5ba1 is complete: on each GPU the existing suite passed three times, and the new regression failed three times at the skipped inaccessible load after its positive controls succeeded. The fix passed both suites three times on each GPU. Across all 24 executions, adapters and actual Khronos device-layer insertion were verified; zero Vulkan validation errors, warnings or VUIDs. The six expected baseline failures demonstrate the bug. Title validation remains pending. Cppcheck and clang-tidy also completed for the new GPU fixture without parser/configuration errors: clang-tidy had no diagnostics, and the single Cppcheck diagnostic concerns an unchanged fixed std::array assignment, which cannot invalidate its storage address.

Upstream implementation: #8295 by @mazen320 adapts the published fix. Its six production files are byte-identical to the original fork implementation; the CPU fixture moves one control earlier. GPU fixtures and scoped validation are shared in this PR comment. Further validation will be coordinated there.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5938250834 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8272). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-20T08:09:34Z. --- <!-- codex-8272-merged-status-v1 --> ### Status, 2026-10-21 UTC **Closed after #8295 merged.** [The upstream correction](https://github.com/boykopovar/AnyPS5/pull/8295) now covers the known-branch flat-load reachability gap. This records the merge and issue closure; it is not a fresh current-main runtime test or title claim. The original reproducer, proposed fix and validation below retain their recorded source pins. <!-- /codex-8272-merged-status-v1 --> ### Summary Main at `7d876ad3ba9571787faa44759b9ac692e77c3eec` rejects a synthetic compute program during resource capture when a scalar branch skips a load through an inaccessible, nonzero direct user-data pointer. [Test-only reproducer on our fork](https://github.com/Amoenus/AnyPS5/commit/5a68457cdd4aeed76026690ab8da3a58953c85a7). It extends the existing `NestedRequest`/`verifyGuardedNullPointers` fixture with a pointer supplied in user SGPRs s2:s3 and moved to s10:s11. The scalar value is used by an output store. The program initializes s12, loads a condition from valid memory, compares it with zero, and executes `s_cbranch_scc1` at pc 0x28. With condition zero it jumps to pc 0x38, skipping `s_load_dword s12, s[10:11], 0` at pc 0x2c and its wait. Decoder assertions verify the moves, compare and branch target. ### Reproduction and result Build `agc_shader_memory_tests`, then run: ```text ctest --test-dir <build> -R "^agc_shader_memory$" -V ``` Three consecutive Windows 11 Enterprise 26200 / WinLibs GCC 15.2.0 Release runs, each under 2 seconds for the test: | Control | Result | | --- | --- | | Mapped pointer, load executes | Capture, recompile and SPIR-V validation pass; flattened slot contains the payload | | Mapped pointer, load skipped | Capture, recompile and SPIR-V validation pass | | Inaccessible pointer, load executes | Capture rejects it with `guest memory is not readable` | | Same inaccessible pointer, load skipped | Capture also throws `guest memory is not readable ... +0x4`; expected to avoid this dereference | The inaccessible address is a test-owned `MEM_RESERVE` / `PAGE_NOACCESS` allocation. The fixture retains its region vectors and user-data array throughout their use. This is CPU capture/compiler validation; no GPU execution or title result is claimed. ### Source and expected behavior [AMD RDNA 2 ISA reference, revision 2020-11-30](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture), sections 12.3-12.5 (printed pages 111, 123-124), specifies the move, comparison and conditional PC update used here. The taken branch jumps over the scalar load; this does not rely on EXEC suppressing scalar memory instructions. In `SrtDescriptorEvaluation.cpp`, `evaluateRuntimeSources` evaluates every flattened SRT slot after its descriptor-source walk. The fixture checks that this load's handle is not classified as `LoadedFromMemory`; the existing nested-pointer poison handling therefore does not cover it. Related: #479/#759 cover guarded nested reads. #5384 was closed because #5573 fixed the reused fused-program lifetime behind #5099. This fixture builds its own program and does not exercise fusion. #7891 changes branch waits and descriptor-source selection; it does not establish coverage of this scalar-value load. A correction needs to preserve reachability for these flat reads, or retain their load on the shader execution path, while preserving explicit failure for an invalid read that actually executes. The reproducer commit remains deliberately failing on unmodified main. ### Proposed correction and validation [Experimental fix on our fork](https://github.com/Amoenus/AnyPS5/commit/56687751f153e26574148869b2da3408b5f1e8a4), rebased onto main `5e7c618699564093531727fbe2feaea5952a5ba1`: - Record every flat-slot use in its resource control-flow block, including repeated uses. - Both the generic evaluator and SRT tape omit only slots whose uses are unreachable under a known clean condition. Unresolved guards remain conservative; invalid taken and unconditional repeated loads remain rejected. - Serialize that metadata, validate decoded slot bounds, and advance the cache format from 41 to 42. At pre-rebase head `a0d29666f5352ca35f8205ae2d22f9daf77e277e` on main `587bb343e8baf0f9c62bdb04c9dab5eb4b938dc9`, the selected targets compiled and 12 final CPU test executions passed: three runs each of shader memory, SRT read patching, shader disk cache and cache-file reading. The new fixture covers original/decoded plans, direct tape execution, compact and IR evaluation, unreadable guards, and an unconditional repeated load. Nonempty flat-slot lists now participate in the existing cache round-trip equality test. SPIR-V Tools is enabled. Cppcheck and clang-tidy completed for all six changed translation units without parser errors. Findings were reviewed: no new production finding; a new fixed-array address-invalidation warning is a false positive, and existing advisories remain recorded. All nine changed files are SHA-256-identical after the clean rebase. The test results above retain their original pins. The fork advanced to [8a8f2b157941deb4582808ecf926ff429888b76a](https://github.com/Amoenus/AnyPS5/commit/8a8f2b157941deb4582808ecf926ff429888b76a) with a direct-root device regression and corrected expectations in the existing GPU fixture. The full runtime build and twelve candidate GPU test executions across NVIDIA and AMD passed. The paired test-only control on main `5e7c618699564093531727fbe2feaea5952a5ba1` is complete: on each GPU the existing suite passed three times, and the new regression failed three times at the skipped inaccessible load after its positive controls succeeded. The fix passed both suites three times on each GPU. Across all 24 executions, adapters and actual Khronos device-layer insertion were verified; zero Vulkan validation errors, warnings or VUIDs. The six expected baseline failures demonstrate the bug. Title validation remains pending. Cppcheck and clang-tidy also completed for the new GPU fixture without parser/configuration errors: clang-tidy had no diagnostics, and the single Cppcheck diagnostic concerns an unchanged fixed `std::array` assignment, which cannot invalidate its storage address. Upstream implementation: #8295 by @mazen320 adapts the published fix. Its six production files are byte-identical to the original fork implementation; the CPU fixture moves one control earlier. GPU fixtures and scoped validation are shared in [this PR comment](https://github.com/boykopovar/AnyPS5/pull/8295#issuecomment-6288035846). Further validation will be coordinated there. AI-assisted: yes.
Sign in to join this conversation.
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
boykopovar/AnyPS5#8272
No description provided.