fix(shader): ignore a runtime V#'s type for scalar buffer loads as RDNA2 does #11254

Merged
Michael-KD merged 1 commit from upstream-pr/11254 into main 2026-10-27 15:28:28 +00:00
Michael-KD commented 2026-10-25 22:47:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Michael-KD on 2026-10-25T22:47:40Z.


What

A scalar buffer load through a V# that is read at run time (gpuDescriptor) recorded an InvalidDescriptor BDA fault when the V#'s TYPE field (word 3, bits 30-31) was nonzero, and the dispatch produced no output. RDNA2 hardware ignores the whole fourth word for scalar loads, so the scalar path no longer treats TYPE as invalid. Vector buffer accesses keep the check.

The snapshot path already zeroed the fourth word for buffers that only scalar loads read (scalarOnly, from aa2abf801b); its debt entry said this followed the ISA guide and had not been measured. The measurement below settles it for RDNA2, and the entry now keeps only what is still open: gfx1013, and a V# with a null base (not run, to avoid a GPU fault on the measuring machine).

  • SpirvRuntimeBuffer.cpp: descriptor() takes invalid as false for ResourceKind::ScalarBuffer.
  • ScalarBufferRuntimeWord3 (new execution test): word 3 comes from a VGPR through v_readfirstlane_b32, which forces the runtime-descriptor path, and nine word 3 values (the usual 0x31016fac, OOB_SELECT 0, FORMAT 0, ADD_TID_ENABLE, TYPE 1, 2 and 3, zero, all ones) must read the in-range dwords and 0 past NUM_RECORDS. It is a new file so that it does not overlap #10337, which edits BufferDescriptorRuntime.cpp.
  • docs/dev/debt/shader.md: the scalar buffer descriptor entry.

Measurement, with the hardware oracle:

  • GPU: AMD Radeon integrated graphics of a Ryzen 7 9800X3D (gfx1036, RDNA2), AMD Windows driver 32.0.21030.31, through HIP/comgr; wave32; IEEE 0, DX10_CLAMP 1, f32 denormals flushed, f16 denormals kept, round to nearest even, FP16_OVFL 0.
  • Kernel: a V# in s[8:11] over a buffer whose dword i is 0xA0000000 | i, then 16 s_buffer_load_dword at offsets 0, 4, 8, 12, 16, 20, 24, 28, 1, 2, 3, 17, 18, 19, 21, 64, or 4 s_buffer_load_dwordx4 at 0, 8, 16, 24.
  • 288 kernels: 8 ranges (stride 0 with 20, 18 and 0 records; stride 8 × 3, 12 × 2, 4 × 5; stride 8 × 3 and stride 0 × 20 with SWIZZLE_ENABLE) × 18 fourth words (0x31016fac, OOB_SELECT 0, 1, 2, TYPE 1, 2, 3, FORMAT 0 with OOB_SELECT 3 and 0, ADD_TID_ENABLE with OOB_SELECT 3 and 0, INDEX_STRIDE 1, 2, 3, RESOURCE_LEVEL 0, DST_SEL 0, zero, all ones) × dword and dwordx4.
  • Result: every kernel matches one model in which the fourth word plays no part: the range is NUM_RECORDS bytes with stride 0 and STRIDE × NUM_RECORDS otherwise, a dword reads 0 unless it lies wholly in the range (18 records: offset 16 reads 0), and the offset is rounded down to a dword. For example, with 20 records, 0x31016fac, 0x01016fac, 0xb1016fac and 0xffffffff all read a0000000-a0000004 at offsets 0-16 and 0 from 20 on.

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release.

ctest --test-dir build -R '^agc_driver_(buffer_descriptor_runtime|scalar_buffer_runtime_word3|scalar_wide_loads)$' -V with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (Vulkan SDK 1.4.363.0, insertion confirmed with VK_LOADER_DEBUG=layer) and ANYPS5_GPU set to each device. The main arm is this branch with the SpirvRuntimeBuffer.cpp change reverted, so that it runs the new test too:

Test main, RTX 5070 Ti main, Radeon iGPU this PR, RTX 5070 Ti this PR, Radeon iGPU
agc_driver_buffer_descriptor_runtime Passed Passed Passed Passed
agc_driver_scalar_wide_loads Passed Passed Passed Passed
agc_driver_scalar_buffer_runtime_word3 Failed Failed Passed Passed

On main the new test fails at the first nonzero TYPE: [gpu] deferred write-back failed: BDA access failed: ... reason=8 (InvalidDescriptor), then scalar buffer runtime word 3 0x71016fac: lane 0 offset 0x4 is 0xdeadbeef, expected 0xa0000001. The four word 3 values before it pass. No log contains was not found but was requested by env var VK_INSTANCE_LAYERS, no log has a VUID- line, and each log names the selected GPU.

Full ctest -j8 with this change: 2393 of 2395 pass. The two failures, agc_host_import_cut_lifetime (#10746) and agc_driver_depth_plane_partial_store (#10664), also fail with the change reverted.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 617.42, Windows 11 Pro 26200; AMD Radeon Graphics (Ryzen 7 9800X3D, gfx1036), Windows driver 32.0.21030.31 (Vulkan driver 2.0.353), Windows 11 Pro 26200
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5009487271 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11254). Originally posted by [Michael-KD](https://github.com/Michael-KD) on 2026-10-25T22:47:40Z. --- ### What A scalar buffer load through a V# that is read at run time (`gpuDescriptor`) recorded an `InvalidDescriptor` BDA fault when the V#'s `TYPE` field (word 3, bits 30-31) was nonzero, and the dispatch produced no output. RDNA2 hardware ignores the whole fourth word for scalar loads, so the scalar path no longer treats `TYPE` as invalid. Vector buffer accesses keep the check. The snapshot path already zeroed the fourth word for buffers that only scalar loads read (`scalarOnly`, from aa2abf801b); its debt entry said this followed the ISA guide and had not been measured. The measurement below settles it for RDNA2, and the entry now keeps only what is still open: gfx1013, and a V# with a null base (not run, to avoid a GPU fault on the measuring machine). - `SpirvRuntimeBuffer.cpp`: `descriptor()` takes `invalid` as false for `ResourceKind::ScalarBuffer`. - `ScalarBufferRuntimeWord3` (new execution test): word 3 comes from a VGPR through `v_readfirstlane_b32`, which forces the runtime-descriptor path, and nine word 3 values (the usual 0x31016fac, `OOB_SELECT` 0, `FORMAT` 0, `ADD_TID_ENABLE`, `TYPE` 1, 2 and 3, zero, all ones) must read the in-range dwords and 0 past `NUM_RECORDS`. It is a new file so that it does not overlap #10337, which edits `BufferDescriptorRuntime.cpp`. - `docs/dev/debt/shader.md`: the scalar buffer descriptor entry. Measurement, with the [hardware oracle](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/HW_ORACLE.md): - GPU: AMD Radeon integrated graphics of a Ryzen 7 9800X3D (gfx1036, RDNA2), AMD Windows driver 32.0.21030.31, through HIP/comgr; wave32; IEEE 0, DX10_CLAMP 1, f32 denormals flushed, f16 denormals kept, round to nearest even, FP16_OVFL 0. - Kernel: a V# in `s[8:11]` over a buffer whose dword i is `0xA0000000 | i`, then 16 `s_buffer_load_dword` at offsets 0, 4, 8, 12, 16, 20, 24, 28, 1, 2, 3, 17, 18, 19, 21, 64, or 4 `s_buffer_load_dwordx4` at 0, 8, 16, 24. - 288 kernels: 8 ranges (stride 0 with 20, 18 and 0 records; stride 8 × 3, 12 × 2, 4 × 5; stride 8 × 3 and stride 0 × 20 with `SWIZZLE_ENABLE`) × 18 fourth words (0x31016fac, `OOB_SELECT` 0, 1, 2, `TYPE` 1, 2, 3, `FORMAT` 0 with `OOB_SELECT` 3 and 0, `ADD_TID_ENABLE` with `OOB_SELECT` 3 and 0, `INDEX_STRIDE` 1, 2, 3, `RESOURCE_LEVEL` 0, `DST_SEL` 0, zero, all ones) × dword and dwordx4. - Result: every kernel matches one model in which the fourth word plays no part: the range is `NUM_RECORDS` bytes with stride 0 and `STRIDE × NUM_RECORDS` otherwise, a dword reads 0 unless it lies wholly in the range (18 records: offset 16 reads 0), and the offset is rounded down to a dword. For example, with 20 records, 0x31016fac, 0x01016fac, 0xb1016fac and 0xffffffff all read `a0000000`-`a0000004` at offsets 0-16 and 0 from 20 on. ### Tested Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. `ctest --test-dir build -R '^agc_driver_(buffer_descriptor_runtime|scalar_buffer_runtime_word3|scalar_wide_loads)$' -V` with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (Vulkan SDK 1.4.363.0, insertion confirmed with `VK_LOADER_DEBUG=layer`) and `ANYPS5_GPU` set to each device. The `main` arm is this branch with the `SpirvRuntimeBuffer.cpp` change reverted, so that it runs the new test too: | Test | `main`, RTX 5070 Ti | `main`, Radeon iGPU | this PR, RTX 5070 Ti | this PR, Radeon iGPU | |---|---|---|---|---| | `agc_driver_buffer_descriptor_runtime` | Passed | Passed | Passed | Passed | | `agc_driver_scalar_wide_loads` | Passed | Passed | Passed | Passed | | `agc_driver_scalar_buffer_runtime_word3` | Failed | Failed | Passed | Passed | On `main` the new test fails at the first nonzero `TYPE`: `[gpu] deferred write-back failed: BDA access failed: ... reason=8` (`InvalidDescriptor`), then `scalar buffer runtime word 3 0x71016fac: lane 0 offset 0x4 is 0xdeadbeef, expected 0xa0000001`. The four word 3 values before it pass. No log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`, no log has a `VUID-` line, and each log names the selected GPU. Full `ctest -j8` with this change: 2393 of 2395 pass. The two failures, `agc_host_import_cut_lifetime` (#10746) and `agc_driver_depth_plane_partial_store` (#10664), also fail with the change reverted. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 617.42, Windows 11 Pro 26200; AMD Radeon Graphics (Ryzen 7 9800X3D, gfx1036), Windows driver 32.0.21030.31 (Vulkan driver 2.0.353), Windows 11 Pro 26200 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-25 22:57:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T22:57:02Z.

Review: APPROVED


Reviewed the exact runtime change and regression test. The change suppresses only the invalid-descriptor fault for scalar-buffer resources; other resource kinds retain the TYPE check. The new test exercises runtime descriptors with zero, nonzero TYPE and all-ones word 3 values, checks in-range and out-of-range reads across lanes, and the report says it fails on main and passes with this change on both listed GPUs. Diff-check and current-base conventions pass. Product CI was skipped; my local full configure could not proceed because the SDL2 submodule is uninitialized in this worktree, so I rely on the reported GPU runs and did not claim a local execution.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645777456 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11254#pullrequestreview-5645777456). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T22:57:02Z. **Review:** APPROVED --- Reviewed the exact runtime change and regression test. The change suppresses only the invalid-descriptor fault for scalar-buffer resources; other resource kinds retain the TYPE check. The new test exercises runtime descriptors with zero, nonzero TYPE and all-ones word 3 values, checks in-range and out-of-range reads across lanes, and the report says it fails on main and passes with this change on both listed GPUs. Diff-check and current-base conventions pass. Product CI was skipped; my local full configure could not proceed because the SDL2 submodule is uninitialized in this worktree, so I rely on the reported GPU runs and did not claim a local execution.
MarcZX10 commented 2026-10-26 00:09:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T00:09:23Z.

Review: DISMISSED


I am updating my earlier approval after checking the current overlap and base. The overlap bot lists open PRs #7922 and #10846. Pairwise git merge-tree of the exact heads is clean with #7922 but conflicts in docs/dev/debt/shader.md with #10846. CONTRIBUTING.md requires the authors to agree how listed overlaps are ordered and to record any prerequisite on the checklist. Please coordinate with both authors and update Depends on if #10846 (or another PR) must land first.

The PR branch is also 42 commits behind current main; please update it to the current base and resolve the documentation overlap before approval. The measured RDNA2 behavior and regression evidence remain useful; this request concerns merge-order coordination and the current-base rule.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5646101284 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11254#pullrequestreview-5646101284). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T00:09:23Z. **Review:** DISMISSED --- I am updating my earlier approval after checking the current overlap and base. The overlap bot lists open PRs #7922 and #10846. Pairwise `git merge-tree` of the exact heads is clean with #7922 but conflicts in `docs/dev/debt/shader.md` with #10846. `CONTRIBUTING.md` requires the authors to agree how listed overlaps are ordered and to record any prerequisite on the checklist. Please coordinate with both authors and update `Depends on` if #10846 (or another PR) must land first. The PR branch is also 42 commits behind current `main`; please update it to the current base and resolve the documentation overlap before approval. The measured RDNA2 behavior and regression evidence remain useful; this request concerns merge-order coordination and the current-base rule.
jotitadev commented 2026-10-27 03:54:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T03:54:48Z.

Review: COMMENTED


Linux run on NVIDIA and lavapipe of head 5abefb16a. The description's runs are Windows (RTX 5070 Ti, Radeon iGPU) and the RADV oracle measurement. Here the new test shows a genuine red/green on both devices.

Tested

Ubuntu 26.04, GCC 15.2.0, Release, ANYPS5_NO_SHADER_CACHE=1, ANYPS5_REQUIRE_VULKAN=1, device chosen with VK_ICD_FILENAMES, -j1. This PR merged onto main cb45ae2dd (no conflicts).

agc_driver_scalar_buffer_runtime_word3, --repeat until-fail:3:

NVIDIA RTX 3070 (595.99.02) lavapipe (Mesa 26.0.3, LLVM 21.1.8)
new test + main's SpirvRuntimeBuffer.cpp fails fails
this PR passes 3/3 passes 3/3

The control fails with the same message on both devices, on the first TYPE 1 word:

AGC graphics: scalar buffer runtime word 3 0x71016fac: lane 0 offset 0x4 is 0xdeadbeef, expected 0xa0000001

agc_driver_buffer_descriptor_runtime and agc_driver_scalar_wide_loads (vector path and wide scalar loads) also pass 3/3 on both.

ctest -R "^agc" without display/flip/lds_atomics64, --timeout 30:

NVIDIA RTX 3070 lavapipe
main cb45ae2dd 1029/1030 1028/1030
this PR 1031/1031 1030/1031

No new failures. On main, NVIDIA's one failure is agc_driver_sgpr_pattern_fill_keys, which passed on later runs. lavapipe fails agc_driver_multisample_retirement on main and with this PR.

GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02, Linux) and lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5662027946 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11254#pullrequestreview-5662027946). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-27T03:54:48Z. **Review:** COMMENTED --- Linux run on NVIDIA and lavapipe of head `5abefb16a`. The description's runs are Windows (RTX 5070 Ti, Radeon iGPU) and the RADV oracle measurement. Here the new test shows a genuine red/green on both devices. ### Tested Ubuntu 26.04, GCC 15.2.0, Release, `ANYPS5_NO_SHADER_CACHE=1`, `ANYPS5_REQUIRE_VULKAN=1`, device chosen with `VK_ICD_FILENAMES`, `-j1`. This PR merged onto `main` `cb45ae2dd` (no conflicts). `agc_driver_scalar_buffer_runtime_word3`, `--repeat until-fail:3`: | | NVIDIA RTX 3070 (595.99.02) | lavapipe (Mesa 26.0.3, LLVM 21.1.8) | |---|---|---| | new test + `main`'s `SpirvRuntimeBuffer.cpp` | fails | fails | | this PR | passes 3/3 | passes 3/3 | The control fails with the same message on both devices, on the first `TYPE` 1 word: ``` AGC graphics: scalar buffer runtime word 3 0x71016fac: lane 0 offset 0x4 is 0xdeadbeef, expected 0xa0000001 ``` `agc_driver_buffer_descriptor_runtime` and `agc_driver_scalar_wide_loads` (vector path and wide scalar loads) also pass 3/3 on both. `ctest -R "^agc"` without display/flip/`lds_atomics64`, `--timeout 30`: | | NVIDIA RTX 3070 | lavapipe | |---|---|---| | `main` `cb45ae2dd` | 1029/1030 | 1028/1030 | | this PR | 1031/1031 | 1030/1031 | No new failures. On `main`, NVIDIA's one failure is `agc_driver_sgpr_pattern_fill_keys`, which passed on later runs. lavapipe fails `agc_driver_multisample_retirement` on `main` and with this PR. GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02, Linux) and lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
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
boykopovar/AnyPS5!11254
No description provided.