fix(agc): keep a pointer's upper half out of the relocated V# value words #19398

Open
muhmuhkuh wants to merge 2 commits from upstream-pr/19398 into main
muhmuhkuh commented 2026-11-13 08:08:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by muhmuhkuh on 2026-11-13T08:08:05Z.


What

The draw relocation lets a user-data word change between draws without a rebuild when the word is the base of a read-only V# held in user data. tagUserValueWords finds such a word by value: it equals the base word of exactly one bound guest buffer descriptor and the two words after it match that descriptor. A move of such a word is accepted in relocateDrawEntry, and only the bound descriptor is patched.

A 64-bit pointer takes two consecutive user words. Its lower word is tagged as relocatable (a base of the SRT walk) or as a callee word (a fetch subroutine pointer, where the code already takes userData[index + 1] as the upper half). Its upper word carries no tag of its own. When the value of that upper word also passed the V# match, it was tagged as a V# value word. A draw whose pointer changed only in its upper half then passed the move check. The copied variant kept its runs at the address under the old upper half, and a callee was keyed by the code under the old upper half. The reused draw was then validated against memory the shader does not read.

tagUserValueWords now leaves the word directly after a relocatable or callee word untagged, as a V# base and as a record count. A move of that word is refused by the existing check and the draw is built again.

This was found by reading the code. No real shader is known to reach it: the upper half of a pointer has to equal the base word of one bound read-only buffer, and the following words have to match that descriptor. The test shows it at the level of the tagging function only, not with a draw.

Limits:

  • Only an upper half in the next user word is covered. A shader that takes the upper half of an address from another user word is not covered.
  • A V# that starts directly after a pointer word whose upper half lives elsewhere is no longer relocated as a value. Such a draw is rebuilt instead of reused. The result stays correct.

Overlap with open PRs: #10193, #13928 and #13929 also change Driver::tagUserValueWords (signature and body). Their tag loop has the same condition without this guard. Whichever PR merges second rebases, and the guard belongs in the function as it stands after the first merge. #5609 changes the relocation runs, not the tags.

Tested

Windows 11 Pro (10.0.26200), NVIDIA GeForce RTX 3080 Ti, driver 610.88, MinGW GCC 15.2 (UCRT, POSIX threads, SEH), Release, validation layer on (ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation). Built on the same machine on upstream main 8f9fbf6c8c3 with the test change only (red), and with the fix on top (green). The files this change touches are the same on 8f9fbf6c8c3 and on the current base 96b9b4cd641; the tests were not repeated on the current base.

  • agc_driver_draw_relocate_user_values: with only the test change it fails with "the user word after a relocated pointer word, the pointer's upper half, was tagged as a V# value (mask 80)". With the fix it passes.
  • The group ^agc_driver_(draw_relocate_user_values|draw_cache_relocation|draw_cache_reuse|mesh_draw_relocation) with the fix: 18 tests (the test above plus agc_driver_draw_cache_relocation, agc_driver_draw_cache_reuse, agc_driver_mesh_draw_relocation and their variants): 18 of 18 pass.
  • VUID: 0 VUID- lines in the logs of the green run. The phrase was not found but was requested by env var VK_INSTANCE_LAYERS: 0 occurrences.
  • Not run: the same tests on #10193, #13928 and #13929 (not built), the full CPU suite, Linux, and the other AGC tests.

Checklist

  • Based on current main (96b9b4cd64 at posting time)
  • 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
  • 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 3080 Ti, driver 610.88, Windows 11 Pro 10.0.26200
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5292268411 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19398). Originally posted by [muhmuhkuh](https://github.com/muhmuhkuh) on 2026-11-13T08:08:05Z. --- ### What The draw relocation lets a user-data word change between draws without a rebuild when the word is the base of a read-only V# held in user data. `tagUserValueWords` finds such a word by value: it equals the base word of exactly one bound guest buffer descriptor and the two words after it match that descriptor. A move of such a word is accepted in `relocateDrawEntry`, and only the bound descriptor is patched. A 64-bit pointer takes two consecutive user words. Its lower word is tagged as relocatable (a base of the SRT walk) or as a callee word (a fetch subroutine pointer, where the code already takes `userData[index + 1]` as the upper half). Its upper word carries no tag of its own. When the value of that upper word also passed the V# match, it was tagged as a V# value word. A draw whose pointer changed only in its upper half then passed the move check. The copied variant kept its runs at the address under the old upper half, and a callee was keyed by the code under the old upper half. The reused draw was then validated against memory the shader does not read. `tagUserValueWords` now leaves the word directly after a relocatable or callee word untagged, as a V# base and as a record count. A move of that word is refused by the existing check and the draw is built again. This was found by reading the code. No real shader is known to reach it: the upper half of a pointer has to equal the base word of one bound read-only buffer, and the following words have to match that descriptor. The test shows it at the level of the tagging function only, not with a draw. Limits: - Only an upper half in the next user word is covered. A shader that takes the upper half of an address from another user word is not covered. - A V# that starts directly after a pointer word whose upper half lives elsewhere is no longer relocated as a value. Such a draw is rebuilt instead of reused. The result stays correct. Overlap with open PRs: #10193, #13928 and #13929 also change `Driver::tagUserValueWords` (signature and body). Their tag loop has the same condition without this guard. Whichever PR merges second rebases, and the guard belongs in the function as it stands after the first merge. #5609 changes the relocation runs, not the tags. ### Tested Windows 11 Pro (10.0.26200), NVIDIA GeForce RTX 3080 Ti, driver 610.88, MinGW GCC 15.2 (UCRT, POSIX threads, SEH), Release, validation layer on (`ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`). Built on the same machine on upstream main `8f9fbf6c8c3` with the test change only (red), and with the fix on top (green). The files this change touches are the same on `8f9fbf6c8c3` and on the current base `96b9b4cd641`; the tests were not repeated on the current base. - `agc_driver_draw_relocate_user_values`: with only the test change it fails with "the user word after a relocated pointer word, the pointer's upper half, was tagged as a V# value (mask 80)". With the fix it passes. - The group `^agc_driver_(draw_relocate_user_values|draw_cache_relocation|draw_cache_reuse|mesh_draw_relocation)` with the fix: 18 tests (the test above plus `agc_driver_draw_cache_relocation`, `agc_driver_draw_cache_reuse`, `agc_driver_mesh_draw_relocation` and their variants): 18 of 18 pass. - VUID: 0 `VUID-` lines in the logs of the green run. The phrase `was not found but was requested by env var VK_INSTANCE_LAYERS`: 0 occurrences. - Not run: the same tests on #10193, #13928 and #13929 (not built), the full CPU suite, Linux, and the other AGC tests. ### Checklist - [x] Based on current `main` (96b9b4cd641 at posting time) - [x] 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [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 3080 Ti, driver 610.88, Windows 11 Pro 10.0.26200 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-21 04:25:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T04:25:30Z.

Review: APPROVED


Reviewed — looks good

The reviewed change at 257f280d19146bd9e86eeee38565b0fbdff75dd4 prevents pointer upper halves from being tagged as relocatable V# value words, and the inspected code supports merging.

What I ran

Read the prepared diff and both changed files at the pinned head using repo_read.py; no commands or tests were run. The author reports targeted tests passing on an earlier upstream revision, not on this head.

Results

Check Result Note
Source review passed Both changed files read
Tests on this head not run Author's reported runs used an earlier revision

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests were run on this head, and the author reports the test suite was not repeated on the current base. files.json was not available in the prepared review documents; the file listing identifies two changed files, both of which were read. No other files were excluded from review according to the manifest.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6002807697 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19398#pullrequestreview-6002807697). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T04:25:30Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed change at `257f280d19146bd9e86eeee38565b0fbdff75dd4` prevents pointer upper halves from being tagged as relocatable V# value words, and the inspected code supports merging. ## What I ran Read the prepared diff and both changed files at the pinned head using `repo_read.py`; no commands or tests were run. The author reports targeted tests passing on an earlier upstream revision, not on this head. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Both changed files read | | Tests on this head | not run | Author's reported runs used an earlier revision | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests were run on this head, and the author reports the test suite was not repeated on the current base. `files.json` was not available in the prepared review documents; the file listing identifies two changed files, both of which were read. No other files were excluded from review according to the manifest. ## To get this to a good state Nothing is required.
Plyxen commented 2026-12-03 14:03:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T14:03:12Z.

Review: APPROVED


I read the diff at 257f280d19. Windows 11, GCC 15.2, merged into main at 6c6b29320fe together with other open PRs (so not an isolated build), with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 and VK_LAYER_KHRONOS_validation on an RTX 5080 (621.24) and a Radeon iGPU (26.11.2).

  • agc_driver_draw_relocate_user_values: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has a VUID- or SYNC-HAZARD line.
  • Control (the same tree with only this PR's source change taken out): it fails: "the user word after a relocated pointer word, the pointer's upper half, was tagged as a V# value (mask 80)".

Not checked: a title.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6171293436 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19398#pullrequestreview-6171293436). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-12-03T14:03:12Z. **Review:** APPROVED --- I read the diff at `257f280d19`. Windows 11, GCC 15.2, merged into `main` at `6c6b29320fe` together with other open PRs (so not an isolated build), with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1` and `VK_LAYER_KHRONOS_validation` on an RTX 5080 (621.24) and a Radeon iGPU (26.11.2). - `agc_driver_draw_relocate_user_values`: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has a `VUID-` or `SYNC-HAZARD` line. - Control (the same tree with only this PR's source change taken out): it fails: "the user word after a relocated pointer word, the pointer's upper half, was tagged as a V# value (mask 80)". Not checked: a title. AI-assisted: yes (Claude Code)
ligmaSec commented 2026-12-03 22:31:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:31:13Z.

Review: COMMENTED


The trial merge onto c1601e56d5 was clean. The new test checks both relocatable pointer and callee pointer upper halves, and separately checks that a colliding record-count word is left out while the descriptor base stays relocatable. Please keep that last assertion when integrating this with #20130, since a fix that drops the entire descriptor from relocation would otherwise look correct on the two upper-word cases. Paired draw controls are pending.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6179758613 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19398#pullrequestreview-6179758613). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T22:31:13Z. **Review:** COMMENTED --- The trial merge onto `c1601e56d5` was clean. The new test checks both relocatable pointer and callee pointer upper halves, and separately checks that a colliding record-count word is left out while the descriptor base stays relocatable. Please keep that last assertion when integrating this with #20130, since a fix that drops the entire descriptor from relocation would otherwise look correct on the two upper-word cases. Paired draw controls are pending. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/19398:upstream-pr/19398'
git switch 'upstream-pr/19398'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/19398'
git switch 'upstream-pr/19398'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/19398'
git switch 'upstream-pr/19398'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/19398'
git switch 'main'
git merge --squash 'upstream-pr/19398'
git switch 'main'
git merge --ff-only 'upstream-pr/19398'
git switch 'main'
git merge 'upstream-pr/19398'
git push origin 'main'
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!19398
No description provided.