test(agc): delete mapped shader cache entries with POSIX semantics on Windows #6415

Merged
GitamarT045T3R merged 1 commit from upstream-pr/6415 into main 2026-10-17 11:28:41 +00:00
GitamarT045T3R commented 2026-10-15 14:27:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-15T14:27:45Z.


What

On Windows 10, agc_shader_disk_cache passes every check and then fails at the end of main with cannot remove the shader cache test directory: Access is denied, leaving %TEMP%\aps5-shader-disk-cache-test-* behind.

The disk cache maps entry files (MapFile in ShaderDiskCache.cpp) and the variants decoded from them keep the view: Load and Persist results stay in the recompiler's source cache for the life of the process. The final std::filesystem::remove_all deletes with DeleteFileW, which refuses a file that still has a mapped view with ERROR_ACCESS_DENIED on Windows 10 22H2 (19045). At cleanup, 18 of the 88 files in the test directory are such entries.

The test now deletes each file with FILE_DISPOSITION_FLAG_DELETE | FILE_DISPOSITION_FLAG_POSIX_SEMANTICS before remove_all removes the directories, the same POSIX semantics WriteFileAtomically already uses to replace entries. The views stay readable after the name is gone. The test still fails when a file cannot be deleted or the directory cannot be removed: a file held open without FILE_SHARE_DELETE makes it fail with the sharing violation. Linux keeps the plain remove_all.

The runtime is unchanged. It never deletes an entry the process maps: housekeeping only removes other source versions' directories unused for 14 days and .tmp. files older than an hour, and replacing a mapped entry already works through WriteFileAtomically.

On this machine, deleting a file mapped the way MapFile maps it (handles closed, view kept):

Call Result
std::filesystem::remove, DeleteFileW ERROR_ACCESS_DENIED
SetFileInformationByHandle(FileDispositionInfo) ERROR_ACCESS_DENIED
FileDispositionInfoEx, DELETE | POSIX_SEMANTICS | FORCE_IMAGE_SECTION_CHECK ERROR_ACCESS_DENIED
FileDispositionInfoEx, DELETE | POSIX_SEMANTICS deleted; the name is gone, the view still reads, the directory can be removed

DeleteFileW already removes an open, unmapped file's name at once here, so it uses POSIX semantics. It fails on mapped files the same way the image-section check does. The Windows CI job runs on windows-latest (a newer Windows Server) and passes this test, presumably because DeleteFileW there accepts mapped data files; this was not checked on that image.

Tested

Windows 10 Pro 22H2 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release, BUILD_TESTING=ON, on main 940eba9a2:

  • Before (the test file of main): agc_shader_disk_cache fails with cannot remove the shader cache test directory: Access is denied and leaves its directory in %TEMP%.
  • After: ctest -R '^agc_shader_disk_cache$' --repeat until-fail:5 passes 5 of 5 runs, about 1.6 s each, with no directory left behind.
  • ctest -R 'shader_cache|disk_cache' (shader_cache_file_read, shader_cache_native_paths, agc_shader_disk_cache) passes.
  • python tools/check_conventions.py --base origin/main passes.
  • Not built or tested on Linux or macOS: the new code is inside _WIN32; elsewhere the cleanup is the same remove_all moved into a function.

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 (test cleanup only, no GPU code)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4874871778 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6415). Originally posted by [GitamarT045T3R](https://github.com/GitamarT045T3R) on 2026-10-15T14:27:45Z. --- ### What On Windows 10, `agc_shader_disk_cache` passes every check and then fails at the end of `main` with `cannot remove the shader cache test directory: Access is denied`, leaving `%TEMP%\aps5-shader-disk-cache-test-*` behind. The disk cache maps entry files (`MapFile` in `ShaderDiskCache.cpp`) and the variants decoded from them keep the view: `Load` and `Persist` results stay in the recompiler's source cache for the life of the process. The final `std::filesystem::remove_all` deletes with `DeleteFileW`, which refuses a file that still has a mapped view with `ERROR_ACCESS_DENIED` on Windows 10 22H2 (19045). At cleanup, 18 of the 88 files in the test directory are such entries. The test now deletes each file with `FILE_DISPOSITION_FLAG_DELETE | FILE_DISPOSITION_FLAG_POSIX_SEMANTICS` before `remove_all` removes the directories, the same POSIX semantics `WriteFileAtomically` already uses to replace entries. The views stay readable after the name is gone. The test still fails when a file cannot be deleted or the directory cannot be removed: a file held open without `FILE_SHARE_DELETE` makes it fail with the sharing violation. Linux keeps the plain `remove_all`. The runtime is unchanged. It never deletes an entry the process maps: housekeeping only removes other source versions' directories unused for 14 days and `.tmp.` files older than an hour, and replacing a mapped entry already works through `WriteFileAtomically`. On this machine, deleting a file mapped the way `MapFile` maps it (handles closed, view kept): | Call | Result | | --- | --- | | `std::filesystem::remove`, `DeleteFileW` | `ERROR_ACCESS_DENIED` | | `SetFileInformationByHandle(FileDispositionInfo)` | `ERROR_ACCESS_DENIED` | | `FileDispositionInfoEx`, `DELETE \| POSIX_SEMANTICS \| FORCE_IMAGE_SECTION_CHECK` | `ERROR_ACCESS_DENIED` | | `FileDispositionInfoEx`, `DELETE \| POSIX_SEMANTICS` | deleted; the name is gone, the view still reads, the directory can be removed | `DeleteFileW` already removes an open, unmapped file's name at once here, so it uses POSIX semantics. It fails on mapped files the same way the image-section check does. The Windows CI job runs on `windows-latest` (a newer Windows Server) and passes this test, presumably because `DeleteFileW` there accepts mapped data files; this was not checked on that image. ### Tested Windows 10 Pro 22H2 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release, `BUILD_TESTING=ON`, on `main` `940eba9a2`: - Before (the test file of `main`): `agc_shader_disk_cache` fails with `cannot remove the shader cache test directory: Access is denied` and leaves its directory in `%TEMP%`. - After: `ctest -R '^agc_shader_disk_cache$' --repeat until-fail:5` passes 5 of 5 runs, about 1.6 s each, with no directory left behind. - `ctest -R 'shader_cache|disk_cache'` (`shader_cache_file_read`, `shader_cache_native_paths`, `agc_shader_disk_cache`) passes. - `python tools/check_conventions.py --base origin/main` passes. - Not built or tested on Linux or macOS: the new code is inside `_WIN32`; elsewhere the cleanup is the same `remove_all` moved into a function. ### 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 (test cleanup only, no GPU code) - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-15 14:34:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T14:34:06Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6924 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp L58

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5609 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
PR 6177 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
PR 6235 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
PR 6412 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
PR 6539 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
PR 6946 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
PR 6947 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6194618834 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6415#issuecomment-6194618834). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T14:34:06Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 6924](https://www.github.com/boykopovar/AnyPS5/pull/6924) | `core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp` [L58](https://github.com/boykopovar/AnyPS5/blob/4ffa54c1f3d8a6abeae333e84ca868b2e02914b8/core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp#L58) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5609](https://www.github.com/boykopovar/AnyPS5/pull/5609) | `core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp` | | [PR 6177](https://www.github.com/boykopovar/AnyPS5/pull/6177) | `core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp` | | [PR 6235](https://www.github.com/boykopovar/AnyPS5/pull/6235) | `core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp` | | [PR 6412](https://www.github.com/boykopovar/AnyPS5/pull/6412) | `core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp` | | [PR 6539](https://www.github.com/boykopovar/AnyPS5/pull/6539) | `core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp` | | [PR 6946](https://www.github.com/boykopovar/AnyPS5/pull/6946) | `core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp` | | [PR 6947](https://www.github.com/boykopovar/AnyPS5/pull/6947) | `core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp` |
GitamarT045T3R commented 2026-10-15 14:44:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-15T14:44:33Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4048 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
PR 5315 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
PR 6177 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
PR 6235 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp

I checked the four PRs listed by the overlap bot by hand. None of them overlaps with this one, and none fixes the same failure:

Pull request Change to ShaderDiskCache.cpp Merged with this PR
#4048 one changes(...) line in verifyKeySensitivity no conflict
#5315 verifySpecializationDropsDeadConstants, called from main just above the cleanup this PR replaces no new conflict; it keeps the two conflicts it already has with main (the <set> include and the plan fixtures)
#6177 one changes(...) line in verifyKeySensitivity no conflict
#6235 raw32 integer attachment key checks in verifyKeySensitivity no conflict

How I checked: I merged each PR's version of the file (three-way, from its merge base with main) into main and into this branch. In every case, merging into this branch gave the same result as merging into main plus removeCacheDirectory. This branch also still merges cleanly into main ff23657f3.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6194837916 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6415#issuecomment-6194837916). Originally posted by [GitamarT045T3R](https://github.com/GitamarT045T3R) on 2026-10-15T14:44:33Z. --- > Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. > > Pull request Shared files not compared > [PR 4048](https://www.github.com/boykopovar/AnyPS5/pull/4048) `core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp` > [PR 5315](https://www.github.com/boykopovar/AnyPS5/pull/5315) `core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp` > [PR 6177](https://www.github.com/boykopovar/AnyPS5/pull/6177) `core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp` > [PR 6235](https://www.github.com/boykopovar/AnyPS5/pull/6235) `core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp` I checked the four PRs listed by the overlap bot by hand. None of them overlaps with this one, and none fixes the same failure: | Pull request | Change to `ShaderDiskCache.cpp` | Merged with this PR | |---|---|---| | #4048 | one `changes(...)` line in `verifyKeySensitivity` | no conflict | | #5315 | `verifySpecializationDropsDeadConstants`, called from `main` just above the cleanup this PR replaces | no new conflict; it keeps the two conflicts it already has with `main` (the `<set>` include and the plan fixtures) | | #6177 | one `changes(...)` line in `verifyKeySensitivity` | no conflict | | #6235 | raw32 integer attachment key checks in `verifyKeySensitivity` | no conflict | How I checked: I merged each PR's version of the file (three-way, from its merge base with `main`) into `main` and into this branch. In every case, merging into this branch gave the same result as merging into `main` plus `removeCacheDirectory`. This branch also still merges cleanly into `main` `ff23657f3`.
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!6415
No description provided.