fix(shader): find the shader cache directory on macOS #4019

Merged
ahir061 merged 1 commit from upstream-pr/4019 into main 2026-10-13 03:52:02 +00:00
ahir061 commented 2026-10-11 21:29:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahir061 on 2026-10-11T21:29:33Z.


What

ShaderRecompiler::ShaderCacheDirectory() finds the executable folder on every non-Windows host through std::filesystem::read_symlink("/proc/self/exe", error). macOS has no /proc, so it returns an empty path there. An empty path disables both the shader disk cache (DiskStore never sets its directory, so Enabled() is false) and the Vulkan pipeline cache in PipelineCache.cpp (no load, no saver thread), silently, unless ANYPS5_SHADER_CACHE_DIR is set.

On macOS the executable path now comes from _NSGetExecutablePath (size queried first), resolved with std::filesystem::canonical using the error_code overload, so the default is <real executable folder>/shader_cache, as on Linux. The function keeps its failure behaviour: it returns an empty path and never throws. ANYPS5_NO_SHADER_CACHE and ANYPS5_SHADER_CACHE_DIR are handled first, as before. Linux and Windows are unchanged.

Same /proc/self/exe problem as #4014 (libSceFont and libSceNpEntitlementAccess); this is the shader cache part, independent of it.

Tested

  • MacBook Air M3(Apple silicon), macOS 26.0.1, AppleClang 17.0.0, x86_64 under Rosetta:
    • Before: the existing non-Windows branch, copied exactly into a standalone program, returns an empty path (read_symlink fails with No such file or directory).
    • After: the function extracted from the edited file returns <real folder>/shader_cache when the program is run by full path, through a symlink in another folder and through a relative symlink path. ANYPS5_SHADER_CACHE_DIR=/some/dir returns /some/dir, and ANYPS5_NO_SHADER_CACHE=1 returns an empty path.
    • The assertions of verifyDefaultDirectory in libSceAgcDriver/tests/ShaderDiskCache.cpp, run against both versions: they fail before ("not named shader_cache") and pass after.
    • ShaderDiskCache.cpp compiles for x86_64 macOS with -fsyntax-only -Wall -Wextra and no warnings (with ShaderCacheVersion.hpp generated by the project's ShaderCacheVersion.cmake).
  • tools/check_conventions.py --base upstream/main passes.
  • Not run: the full agc_driver tests, since the full build does not complete on macOS yet; Linux and Windows builds (their code path is unchanged).

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4822501553 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4019). Originally posted by [ahir061](https://github.com/ahir061) on 2026-10-11T21:29:33Z. --- ### What `ShaderRecompiler::ShaderCacheDirectory()` finds the executable folder on every non-Windows host through `std::filesystem::read_symlink("/proc/self/exe", error)`. macOS has no `/proc`, so it returns an empty path there. An empty path disables both the shader disk cache (`DiskStore` never sets its directory, so `Enabled()` is false) and the Vulkan pipeline cache in `PipelineCache.cpp` (no load, no saver thread), silently, unless `ANYPS5_SHADER_CACHE_DIR` is set. On macOS the executable path now comes from `_NSGetExecutablePath` (size queried first), resolved with `std::filesystem::canonical` using the `error_code` overload, so the default is `<real executable folder>/shader_cache`, as on Linux. The function keeps its failure behaviour: it returns an empty path and never throws. `ANYPS5_NO_SHADER_CACHE` and `ANYPS5_SHADER_CACHE_DIR` are handled first, as before. Linux and Windows are unchanged. Same `/proc/self/exe` problem as #4014 (libSceFont and libSceNpEntitlementAccess); this is the shader cache part, independent of it. ### Tested - MacBook Air M3(Apple silicon), macOS 26.0.1, AppleClang 17.0.0, x86_64 under Rosetta: - Before: the existing non-Windows branch, copied exactly into a standalone program, returns an empty path (`read_symlink` fails with No such file or directory). - After: the function extracted from the edited file returns `<real folder>/shader_cache` when the program is run by full path, through a symlink in another folder and through a relative symlink path. `ANYPS5_SHADER_CACHE_DIR=/some/dir` returns `/some/dir`, and `ANYPS5_NO_SHADER_CACHE=1` returns an empty path. - The assertions of `verifyDefaultDirectory` in `libSceAgcDriver/tests/ShaderDiskCache.cpp`, run against both versions: they fail before ("not named shader_cache") and pass after. - `ShaderDiskCache.cpp` compiles for x86_64 macOS with `-fsyntax-only -Wall -Wextra` and no warnings (with `ShaderCacheVersion.hpp` generated by the project's `ShaderCacheVersion.cmake`). - `tools/check_conventions.py --base upstream/main` passes. - Not run: the full `agc_driver` tests, since the full build does not complete on macOS yet; Linux and Windows builds (their code path is unchanged). ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
Dextroid17 commented 2026-10-12 00:29:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T00:29:48Z.


What I could check from here — Linux, static reading; I have no macOS host, so the platform claim itself is not exercised:

  • The default shader cache directory is resolved in one place (ShaderCacheDirectory()) and consumed by both the shader disk cache and the Vulkan pipeline cache (PipelineCache.cpp:34), so one change covers both. That an empty path silently disabled both is what makes this worth merging rather than a cosmetic porting change.
  • The Linux and Windows paths are untouched — the Apple arm is a nested #ifdef __APPLE__ inside the existing non-Windows branch — and a failing resolve still returns an empty path rather than throwing.
  • canonical with the error_code overload is the right choice: _NSGetExecutablePath can hand back a path that is still a symlink, and canonical gives the real folder, which is what read_symlink("/proc/self/exe") already yields on Linux.
  • The size query with a null buffer is dyld behaviour rather than something mach-o/dyld.h documents: Apple's dyld does fill *bufsize when the buffer is null, so the first call works, but the reliance is worth a line in the commit message. If you would rather stay on documented behaviour, the grow-and-retry loop the Windows arm already uses is the pattern.
  • Two caveats from the same class of bug: the macOS result now depends on the working directory in force at first use, because the disk cache resolves its directory lazily out of a function-local static where /proc/self/exe is absolute; and this is not the whole /proc/self/exe story — libc/src/GuestAllocations.cpp:79, libkernel/Module/src/ModuleInfo.cpp:114 and tests/GuestImageAnonymous.cpp:17 still assume it, and #4014 covers only libSceFont and libSceNpEntitlementAccess.

Coverage: on this PR linux and windows are skipped and relinker skips too, while the macOS jobs that do run build the standalone core/libs/tests subprojects. No job that ran compiled this file on any platform, which is why the extraction you ran by hand is the only evidence — a small device-free target for ShaderCacheDirectory() that builds on all three runners would give verifyDefaultDirectory something to run under __APPLE__.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115615348 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4019#issuecomment-6115615348). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-12T00:29:48Z. --- What I could check from here — Linux, static reading; I have no macOS host, so the platform claim itself is not exercised: - The default shader cache directory is resolved in one place (`ShaderCacheDirectory()`) and consumed by both the shader disk cache and the Vulkan pipeline cache (`PipelineCache.cpp:34`), so one change covers both. That an empty path silently disabled both is what makes this worth merging rather than a cosmetic porting change. - The Linux and Windows paths are untouched — the Apple arm is a nested `#ifdef __APPLE__` inside the existing non-Windows branch — and a failing resolve still returns an empty path rather than throwing. - `canonical` with the `error_code` overload is the right choice: `_NSGetExecutablePath` can hand back a path that is still a symlink, and `canonical` gives the real folder, which is what `read_symlink("/proc/self/exe")` already yields on Linux. - The size query with a null buffer is dyld behaviour rather than something `mach-o/dyld.h` documents: Apple's dyld does fill `*bufsize` when the buffer is null, so the first call works, but the reliance is worth a line in the commit message. If you would rather stay on documented behaviour, the grow-and-retry loop the Windows arm already uses is the pattern. - Two caveats from the same class of bug: the macOS result now depends on the working directory in force at first use, because the disk cache resolves its directory lazily out of a function-local static where `/proc/self/exe` is absolute; and this is not the whole `/proc/self/exe` story — `libc/src/GuestAllocations.cpp:79`, `libkernel/Module/src/ModuleInfo.cpp:114` and `tests/GuestImageAnonymous.cpp:17` still assume it, and #4014 covers only `libSceFont` and `libSceNpEntitlementAccess`. Coverage: on this PR `linux` and `windows` are skipped and `relinker` skips too, while the macOS jobs that do run build the standalone `core/libs/tests` subprojects. No job that ran compiled this file on any platform, which is why the extraction you ran by hand is the only evidence — a small device-free target for `ShaderCacheDirectory()` that builds on all three runners would give `verifyDefaultDirectory` something to run under `__APPLE__`. Written with AI assistance.
github-actions[bot] commented 2026-10-12 23:05:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T23:05: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
#3891 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4156 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4396 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4397 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4422 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4423 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4424 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4520 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4521 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4522 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4523 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4566 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4599 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4718 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4740 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4749 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4760 core/shader/recompiler/ShaderDiskCache.cpp L55-56
#4813 core/shader/recompiler/ShaderDiskCache.cpp L55-56
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6134309357 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4019#issuecomment-6134309357). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T23:05: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 | |---|---|---|---| | #3891 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4156 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4396 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4397 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4422 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4423 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4424 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4520 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4521 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4522 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4523 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4566 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4599 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4718 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4740 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4749 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4760 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | | | #4813 | `core/shader/recompiler/ShaderDiskCache.cpp` [L55-56](https://github.com/boykopovar/AnyPS5/blob/6124bf063f6348e4451ad0b9c67f82acec5bc1c2/core/shader/recompiler/ShaderDiskCache.cpp#L55-L56) | | |
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!4019
No description provided.