fix(shader): share delete access when reading cache entries on Windows #5552

Merged
Sam-mon7 merged 1 commit from upstream-pr/5552 into main 2026-10-14 07:03:26 +00:00
Sam-mon7 commented 2026-10-13 23:42:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Sam-mon7 on 2026-10-13T23:42:46Z.


What

WriteFileAtomically renames its open handle over the published cache entry and closes it afterwards. A reader that opens the entry in that window gets ERROR_SHARING_VIOLATION, because std::ifstream does not share delete access, and the cache reports the entry as gone (the entry holding a prepared shader's SPIR-V is gone). ReadWholeFile now reads through one CreateFileW handle that shares read, write and delete, so a replacement can't switch files mid-read.

Tested

Windows 11, RTX 4070, MinGW GCC 15.2 Release, on main 7a0c838ca.

  • New case in agc_shader_disk_cache: holds the published entry open for DELETE, as the writer does, and reads it. It fails on main (cache reader failed while the published entry retained its rename handle) and passes with this change, 5/5 runs.
  • A standalone harness with the old and new reader code (1,024 replacements, 4 concurrent readers): 357 read and 394 rename failures with the old reader, all error 32, and 0 with the new one.

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
  • Unblocks: none
  • GPUs tested: n/a (shader disk cache file I/O)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4850887521 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5552). Originally posted by [Sam-mon7](https://github.com/Sam-mon7) on 2026-10-13T23:42:46Z. --- ### What `WriteFileAtomically` renames its open handle over the published cache entry and closes it afterwards. A reader that opens the entry in that window gets `ERROR_SHARING_VIOLATION`, because `std::ifstream` does not share delete access, and the cache reports the entry as gone (`the entry holding a prepared shader's SPIR-V is gone`). `ReadWholeFile` now reads through one `CreateFileW` handle that shares read, write and delete, so a replacement can't switch files mid-read. ### Tested Windows 11, RTX 4070, MinGW GCC 15.2 Release, on `main` 7a0c838ca. - New case in `agc_shader_disk_cache`: holds the published entry open for DELETE, as the writer does, and reads it. It fails on `main` (`cache reader failed while the published entry retained its rename handle`) and passes with this change, 5/5 runs. - A standalone harness with the old and new reader code (1,024 replacements, 4 concurrent readers): 357 read and 394 rename failures with the old reader, all error 32, and 0 with the new one. ### Checklist - [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] Unblocks: none - [x] GPUs tested: n/a (shader disk cache file I/O) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
xXPBSXx commented 2026-10-14 03:23:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T03:23:02Z.


Windows test of #5552: Windows 10 (19045), MinGW-w64 GCC 15.2, Release, ninja -j 4, ctest called directly; the ctest logs contain no Selected GPU line. Tree: main 016db923a + merge of PR head af2b86928122695ee4664890cfb9c4fa10a737d2 (local merge 3dbd70e58, no conflict). Logs: rtx5552_*_N.log, rtx5552_result.txt.
1 ctest targets, 3 runs each, exit code 0 in 3 of 3 runs: agc_shader_disk_cache.
Not tested: that the new or changed tests fail without the change (no baseline run), other ctest targets, the AMD GPU unless named above, Linux, a title run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6160157431 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5552#issuecomment-6160157431). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-14T03:23:02Z. --- Windows test of #5552: Windows 10 (19045), MinGW-w64 GCC 15.2, Release, `ninja -j 4`, ctest called directly; the ctest logs contain no `Selected GPU` line. Tree: `main` `016db923a` + merge of PR head `af2b86928122695ee4664890cfb9c4fa10a737d2` (local merge `3dbd70e58`, no conflict). Logs: `rtx5552_*_N.log`, `rtx5552_result.txt`. 1 ctest targets, 3 runs each, exit code 0 in 3 of 3 runs: `agc_shader_disk_cache`. Not tested: that the new or changed tests fail without the change (no baseline run), other ctest targets, the AMD GPU unless named above, Linux, a title run. AI-assisted (Claude Code).
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!5552
No description provided.