Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

MoltenVK: HB_MVK_DEVICE_MEMORY_PERCENT caps the device memory a game is told about (highball#398), and a CI job that builds the engine's x86_64 MoltenVK

Gauthier Piarrette7730d25280a0
diff --git a/.github/workflows/build-moltenvk.yml b/.github/workflows/build-moltenvk.yml
new file mode 100644
index 0000000..a1adbad
--- /dev/null
+++ b/.github/workflows/build-moltenvk.yml
@@ -0,0 +1,60 @@
+# Builds the x86_64 MoltenVK the Intel engines ship (Scripts/build-moltenvk.sh) on a GitHub
+# runner, so a rebuild needs no Mac with gigabytes free. A pull request that touches the patches
+# or the script builds the Wine 11 set as a check; publishing is manual dispatch only. Nothing
+# reaches a player until an engine manifest names the archive this makes.
+name: build-moltenvk
+on:
+ pull_request:
+ paths:
+ - "spike/patches/moltenvk-*.patch"
+ - "Scripts/build-moltenvk.sh"
+ - ".github/workflows/build-moltenvk.yml"
+ workflow_dispatch:
+ inputs:
+ tag:
+ description: "MoltenVK tag"
+ default: "v1.4.2"
+ patches:
+ description: "MVK_PATCHES, in the order they apply"
+ default: "shadow-import linear-fallback shadow-readback device-memory-cap"
+ publish:
+ description: "Upload the archive to the engine-components release"
+ type: boolean
+ default: false
+permissions:
+ contents: write # the optional publish step uploads to a release
+jobs:
+ build:
+ # The shipped 1.4.2 dylib was built against the macOS 26.5 SDK, and MoltenVK turns
+ # Metal features on by the SDK it sees, so this takes the newest Xcode 26 the image has.
+ runs-on: macos-26
+ timeout-minutes: 120
+ steps:
+ - uses: actions/checkout@v4
+ - name: xcode
+ run: |
+ set -euo pipefail
+ ls -d /Applications/Xcode_26*.app
+ sudo xcode-select -s "$(ls -d /Applications/Xcode_26*.app | sort -V | tail -1)"
+ xcodebuild -version
+ - name: build
+ env:
+ MVK_PATCHES: ${{ inputs.patches || 'shadow-import linear-fallback shadow-readback device-memory-cap' }}
+ run: Scripts/build-moltenvk.sh "${{ inputs.tag || 'v1.4.2' }}" "$RUNNER_TEMP/out"
+ - name: sdk and markers
+ run: |
+ set -euo pipefail
+ tar -xzf "$RUNNER_TEMP"/out/moltenvk-*.tar.gz -C "$RUNNER_TEMP"
+ otool -l "$RUNNER_TEMP/libMoltenVK.dylib" | grep -A5 LC_BUILD_VERSION | grep -E "minos|sdk"
+ lipo -archs "$RUNNER_TEMP/libMoltenVK.dylib"
+ strings -a "$RUNNER_TEMP/libMoltenVK.dylib" | grep -o "HIGHBALL [a-z-]*" | sort -u
+ - uses: actions/upload-artifact@v4
+ with:
+ name: moltenvk
+ path: ${{ runner.temp }}/out/*.tar.gz
+ - name: publish
+ if: ${{ github.event_name == 'workflow_dispatch' && inputs.publish }}
+ env:
+ GH_TOKEN: ${{ github.token }}
+ # No --clobber: an archive name already in the release is never replaced.
+ run: gh release upload engine-components "$RUNNER_TEMP"/out/moltenvk-*.tar.gz
diff --git a/Scripts/build-moltenvk.sh b/Scripts/build-moltenvk.sh
index 05911c8..8c9279f 100755
--- a/Scripts/build-moltenvk.sh
+++ b/Scripts/build-moltenvk.sh
@@ -33,6 +33,9 @@ fi
# shadowed memory back to the game's pages when a submission completes, so a 32-bit game's readbacks stop being
# stale; MVK_PATCHES="shadow-import shadow-readback" built moltenvk-1.4.1-shadow-import-1-shadow-readback-1, published
# in the engine-components release and not yet referenced by any engine manifest.
+# device-memory-cap (2026-10-27, highball#398) goes last: HB_MVK_DEVICE_MEMORY_PERCENT caps the device-local heap
+# and its budget at that share of the Mac's memory, so a game that sizes its streaming from them stops growing
+# into swap. Inert unless the variable is set. The .github/workflows/build-moltenvk.yml job runs this script.
read -r -a PATCH_NAMES <<< "${MVK_PATCHES:-shadow-import linear-fallback}"
for NAME_ in "${PATCH_NAMES[@]}"; do
PATCH="$PATCHES/moltenvk-$NAME_.patch"
diff --git a/spike/patches/moltenvk-device-memory-cap.patch b/spike/patches/moltenvk-device-memory-cap.patch
new file mode 100644
index 0000000..0e97c0e
--- /dev/null
+++ b/spike/patches/moltenvk-device-memory-cap.patch
@@ -0,0 +1,56 @@
+diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
+index dab10d9..17201f4 100644
+--- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
++++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
+@@ -3431,9 +3431,31 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope
+ #endif
+ }
+
++// HIGHBALL device-memory-cap: on a Mac the GPU and the CPU share the same RAM, and MoltenVK reports all of
++// it as the device-local heap, with about three quarters of it as the budget. A game that sizes its texture
++// streaming from those numbers keeps adding graphics memory on top of its own until macOS swaps (Red Dead
++// Redemption 2 grew past 19 GB on a 24 GB Mac, highball#398). HB_MVK_DEVICE_MEMORY_PERCENT caps both at that
++// share of the Mac's memory, the way a PC's graphics card has its own smaller VRAM. Allocations themselves are
++// not limited. Unset, or outside 1 to 100, nothing changes.
++static uint64_t mvkHighballDeviceMemoryCap() {
++ static const uint64_t cap = [] {
++ const char* val = getenv("HB_MVK_DEVICE_MEMORY_PERCENT");
++ if ( !val || !*val ) { return (uint64_t)0; }
++ long pct = strtol(val, nullptr, 10);
++ if (pct < 1 || pct > 100) { return (uint64_t)0; }
++ uint64_t sysMem = mvkGetSystemMemorySize();
++ uint64_t capped = sysMem / 100 * (uint64_t)pct;
++ MVKLogWarn("HIGHBALL device-memory-cap: device memory reported as %llu MB, %ld%% of the Mac's %llu MB.",
++ (unsigned long long)(capped / MEBI), pct, (unsigned long long)(sysMem / MEBI));
++ return capped;
++ }();
++ return cap;
++}
++
+ uint64_t MVKPhysicalDevice::getVRAMSize() {
+ if (_hasUnifiedMemory) {
+- return mvkGetSystemMemorySize();
++ uint64_t cap = mvkHighballDeviceMemoryCap();
++ return cap ? std::min<uint64_t>(mvkGetSystemMemorySize(), cap) : mvkGetSystemMemorySize();
+ } else {
+ // There's actually no way to query the total physical VRAM on the device in Metal.
+ // Just default to using the recommended max working set size (i.e. the budget).
+@@ -3443,11 +3465,15 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope
+
+ // If possible, retrieve from the MTLDevice, otherwise from available memory size, or a fixed conservative estimate.
+ uint64_t MVKPhysicalDevice::getRecommendedMaxWorkingSetSize() {
++ uint64_t size;
+ if ( [_mtlDevice respondsToSelector: @selector(recommendedMaxWorkingSetSize)]) {
+- return _mtlDevice.recommendedMaxWorkingSetSize;
++ size = _mtlDevice.recommendedMaxWorkingSetSize;
++ } else {
++ uint64_t freeMem = mvkGetAvailableMemorySize();
++ size = freeMem ? freeMem : 256 * MEBI;
+ }
+- uint64_t freeMem = mvkGetAvailableMemorySize();
+- return freeMem ? freeMem : 256 * MEBI;
++ uint64_t cap = mvkHighballDeviceMemoryCap(); // HIGHBALL device-memory-cap
++ return cap ? std::min<uint64_t>(size, cap) : size;
+ }
+
+ // If possible, retrieve from the MTLDevice, otherwise use the current memory used by this process.