fix(agc): preserve descriptor array ranges in draw snapshots #1831

Merged
yabanana merged 1 commit from upstream-pr/1831 into main 2026-10-10 07:22:09 +00:00
yabanana commented 2026-10-08 20:49:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by yabanana on 2026-10-08T20:49:24Z.


What

A draw snapshot can corrupt storage-buffer array bounds on MoltenVK 1.4.2. Updating a short buffer at array element 1 also changes the shader-visible length of element 0: MoltenVK's auxiliary-size update uses the element index without the write's destination offset (source). In a native macOS integration test, a 128-byte constant buffer replaced an 864-byte vertex buffer's reported length.

Cache each original buffer descriptor when constructing the set. Draw snapshots now rewrite each affected array from element zero, substituting snapshot descriptors and retaining the original handle, offset and range for untouched elements. Unaffected bindings still use the descriptor-set copy. This adds one descriptor-info entry per allocation and writes complete affected arrays.

The regression covers changes to element 0, element 1 and both, with distinct data and ranges. It checks untouched descriptors, unrelated binding copies and resource lifetime through PrepareDrawBindings.

This is independent of the ARM64 compiler work. #1580 changes descriptor limits/layout allocation in the same files; it is not a dependency and does not address these partial-write bounds.

Tested

Current head a2fe737e is rebased onto main at 745b775e, which includes #2099 and resolves the previous missing SPIRV-Headers failure. git range-diff confirms this PR's fix and regression patch are unchanged. Conventions and whitespace checks pass.

  • Earlier focused native ARM64 validation of the descriptor-only test failed on its unmodified base and passed with this patch. Previous head ae1699ac also passed full upstream Linux/Windows CI, including all 488 Linux tests and agc_driver_graphics.

  • On this new base, the production source and regression compile in the focused native harness, but that harness's older native-runtime support archive no longer provides a coherent runtime for changed upstream texture/guest-memory interfaces. Its current-head execution attempt failed before the descriptor assertion. This is not a passing current-head runtime check; full validation is still required.

  • Earlier integration-only MoltenVK 1.4.2 GPU tests passed after the full-array fix. That branch has macOS/shader changes outside this PR and does not substitute for current-head validation.

  • Upstream now runs full Linux/Windows PR builds only through maintainer-authorized workflow_dispatch with a PR number. Please dispatch Build with pr=1831 for this head and run the full graphics regression suite. Skipped full-build jobs do not count as passes.

  • #2151 is also included in this base: the optional hardware-oracle assembler case checks for an AMDGPU-capable Clang before running. The previous Windows relinker failure on amdgcn-amd-amdhsa is therefore addressed by upstream, without a duplicate patch in this PR.

Checklist

  • Based on current main; no other open PR implements this fix
  • One topic per PR; follow-ups go in a new PR
  • No comments added in code
  • No silent stubs or unsupported-path fallbacks added
  • No investigation files, logs or images added to the repository
  • No new third-party code
  • Generic behavior, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4792622431 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1831). Originally posted by [yabanana](https://github.com/yabanana) on 2026-10-08T20:49:24Z. --- ### What A draw snapshot can corrupt storage-buffer array bounds on MoltenVK 1.4.2. Updating a short buffer at array element 1 also changes the shader-visible length of element 0: MoltenVK's auxiliary-size update uses the element index without the write's destination offset ([source](https://github.com/KhronosGroup/MoltenVK/blob/v1.4.2/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm#L1051)). In a native macOS integration test, a 128-byte constant buffer replaced an 864-byte vertex buffer's reported length. Cache each original buffer descriptor when constructing the set. Draw snapshots now rewrite each affected array from element zero, substituting snapshot descriptors and retaining the original handle, offset and range for untouched elements. Unaffected bindings still use the descriptor-set copy. This adds one descriptor-info entry per allocation and writes complete affected arrays. The regression covers changes to element 0, element 1 and both, with distinct data and ranges. It checks untouched descriptors, unrelated binding copies and resource lifetime through `PrepareDrawBindings`. This is independent of the ARM64 compiler work. #1580 changes descriptor limits/layout allocation in the same files; it is not a dependency and does not address these partial-write bounds. ### Tested Current head `a2fe737e` is rebased onto `main` at `745b775e`, which includes #2099 and resolves the previous missing SPIRV-Headers failure. `git range-diff` confirms this PR's fix and regression patch are unchanged. Conventions and whitespace checks pass. - Earlier focused native ARM64 validation of the descriptor-only test failed on its unmodified base and passed with this patch. Previous head `ae1699ac` also passed full upstream Linux/Windows CI, including all 488 Linux tests and `agc_driver_graphics`. - On this new base, the production source and regression compile in the focused native harness, but that harness's older native-runtime support archive no longer provides a coherent runtime for changed upstream texture/guest-memory interfaces. Its current-head execution attempt failed before the descriptor assertion. This is **not** a passing current-head runtime check; full validation is still required. - Earlier integration-only MoltenVK 1.4.2 GPU tests passed after the full-array fix. That branch has macOS/shader changes outside this PR and does not substitute for current-head validation. - Upstream now runs full Linux/Windows PR builds only through maintainer-authorized `workflow_dispatch` with a PR number. Please dispatch Build with `pr=1831` for this head and run the full graphics regression suite. Skipped full-build jobs do not count as passes. - #2151 is also included in this base: the optional hardware-oracle assembler case checks for an AMDGPU-capable Clang before running. The previous Windows relinker failure on `amdgcn-amd-amdhsa` is therefore addressed by upstream, without a duplicate patch in this PR. ### Checklist - [x] Based on current `main`; no other open PR implements this fix - [x] One topic per PR; follow-ups go in a new PR - [x] No comments added in code - [x] No silent stubs or unsupported-path fallbacks added - [x] No investigation files, logs or images added to the repository - [x] No new third-party code - [x] Generic behavior, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
yabanana commented 2026-10-09 08:22:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by yabanana on 2026-10-09T08:22:14Z.


@adriadam10 This fix is now ready for review at 769ce0b4, rebased onto 6cc0503d. The rebase only resolved an appended TechnicalDebt note; the production fix and regression are unchanged. The focused test passes on this head and fails against the unmodified new base. Previous upstream Linux/Windows validation passed, including all 488 Linux tests; fresh validation is running here: https://github.com/boykopovar/AnyPS5/actions/runs/37903648617. Could you review the descriptor-array update and regression?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077238038 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1831#issuecomment-6077238038). Originally posted by [yabanana](https://github.com/yabanana) on 2026-10-09T08:22:14Z. --- @adriadam10 This fix is now ready for review at `769ce0b4`, rebased onto `6cc0503d`. The rebase only resolved an appended TechnicalDebt note; the production fix and regression are unchanged. The focused test passes on this head and fails against the unmodified new base. Previous upstream Linux/Windows validation passed, including all 488 Linux tests; fresh validation is running here: https://github.com/boykopovar/AnyPS5/actions/runs/37903648617. Could you review the descriptor-array update and regression?
yabanana commented 2026-10-09 08:53:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by yabanana on 2026-10-09T08:53:45Z.


The current Windows failure is the upstream missing SPIRV-Headers include path, not the descriptor snapshot change: failed job, VulkanTestDevice.hpp:5:10: fatal error: spirv/unified1/spirv.hpp: No such file or directory while compiling agc_shader_fusion_tests.

I independently reproduced this on both direct consumers (ShaderFusion.cpp and Submit.cpp): the pinned sources fail without the SPIRV header path and pass AppleClang syntax checking with it. #2099 and #2093 contain the same two-target correction. I have documented #2099 as the build prerequisite; once either equivalent fix lands on main, this PR needs a rebase and fresh full CI. No descriptor-code change or duplicate build-fix commit was added.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077690737 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1831#issuecomment-6077690737). Originally posted by [yabanana](https://github.com/yabanana) on 2026-10-09T08:53:45Z. --- The current Windows failure is the upstream missing SPIRV-Headers include path, not the descriptor snapshot change: [failed job](https://github.com/boykopovar/AnyPS5/actions/runs/37903648617/job/113737879059), `VulkanTestDevice.hpp:5:10: fatal error: spirv/unified1/spirv.hpp: No such file or directory` while compiling `agc_shader_fusion_tests`. I independently reproduced this on both direct consumers (`ShaderFusion.cpp` and `Submit.cpp`): the pinned sources fail without the SPIRV header path and pass AppleClang syntax checking with it. #2099 and #2093 contain the same two-target correction. I have documented #2099 as the build prerequisite; once either equivalent fix lands on main, this PR needs a rebase and fresh full CI. No descriptor-code change or duplicate build-fix commit was added.
yabanana commented 2026-10-09 10:16:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by yabanana on 2026-10-09T10:16:37Z.


@adriadam10 Current head a2fe737e is rebased onto main 745b775e, including merged #2099 and #2151. Both previous upstream CI blockers (SPIRV headers and Windows Clang without AMDGPU support) are addressed in this base. The descriptor fix/regression patch is unchanged; the current-head full graphics suite remains unverified by the older native harness. Under the new policy, could you dispatch Build on main with input pr=1831 for full Linux/Windows validation, and review the current head? Skipped full-build jobs are not counted as passes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078911394 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1831#issuecomment-6078911394). Originally posted by [yabanana](https://github.com/yabanana) on 2026-10-09T10:16:37Z. --- @adriadam10 Current head `a2fe737e` is rebased onto main `745b775e`, including merged #2099 and #2151. Both previous upstream CI blockers (SPIRV headers and Windows Clang without AMDGPU support) are addressed in this base. The descriptor fix/regression patch is unchanged; the current-head full graphics suite remains unverified by the older native harness. Under the new policy, could you dispatch **Build** on main with input `pr=1831` for full Linux/Windows validation, and review the current head? Skipped full-build jobs are not counted as passes.
popcoder565 commented 2026-10-09 15:23:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:23:04Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head a2fe737e, merged onto main d70b8998 in one build with 33 other AGC/shader PRs that had no Windows run.

  • This PR's tests pass: agc_driver_graphics. None of them reported skipping a case.
  • Full ctest in that build: 514 of 515. The one failure is #2257's new test, which is registered without the Windows PATH setup.

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083883954 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1831#issuecomment-6083883954). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T15:23:04Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `a2fe737e`, merged onto `main` d70b8998 in one build with 33 other AGC/shader PRs that had no Windows run. - This PR's tests pass: `agc_driver_graphics`. None of them reported skipping a case. - Full ctest in that build: 514 of 515. The one failure is #2257's new test, which is registered without the Windows `PATH` setup. No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
adriadam10 commented 2026-10-10 06:03:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:03:18Z.


Checked the array rewrite in PrepareDrawBindings (untouched elements keep their original handle/offset/range, snapshots substitute only the selected ones) and the new regression: agc_driver_graphics passes on the PR rebased onto main, and the new case fails without the change. Not verified here: the MoltenVK behaviour itself (no macOS).

Added one commit on your branch: rebased onto current main and moved the TechnicalDebt.md line away from the end of its section (it conflicted with the line appended there; end-of-section lines collide with every other PR). Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094467053 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1831#issuecomment-6094467053). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:03:18Z. --- Checked the array rewrite in `PrepareDrawBindings` (untouched elements keep their original handle/offset/range, snapshots substitute only the selected ones) and the new regression: `agc_driver_graphics` passes on the PR rebased onto main, and the new case fails without the change. Not verified here: the MoltenVK behaviour itself (no macOS). Added one commit on your branch: rebased onto current `main` and moved the `TechnicalDebt.md` line away from the end of its section (it conflicted with the line appended there; end-of-section lines collide with every other PR). Merging once CI is green.
adriadam10 commented 2026-10-10 07:15:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T07:15:28Z.


Rebased again onto current main: docs/dev/TechnicalDebt.md conflicted once more with a line added next to ours; both lines are kept. The fix and regression are unchanged, agc_driver_graphics and agc_driver_prepared_graphics pass on the rebased tree. Merging once CI is green. Not verified here: the MoltenVK behaviour itself (no macOS).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095023363 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1831#issuecomment-6095023363). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T07:15:28Z. --- Rebased again onto current `main`: `docs/dev/TechnicalDebt.md` conflicted once more with a line added next to ours; both lines are kept. The fix and regression are unchanged, `agc_driver_graphics` and `agc_driver_prepared_graphics` pass on the rebased tree. Merging once CI is green. Not verified here: the MoltenVK behaviour itself (no macOS).
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!1831
No description provided.