Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
005293b
Reduce Apple mesh pipeline output memory for Astro Bot (bundle_molten…
Coder787-source Dec 5, 2026
5bc5b86
Reduce Apple mesh pipeline output memory for Astro Bot (patch_moltenv…
Coder787-source Dec 5, 2026
9b67cb7
Reduce Apple mesh pipeline output memory for Astro Bot (test_moltenvk…
Coder787-source Dec 5, 2026
3d4dad4
Reduce Apple mesh pipeline output memory for Astro Bot (pipelineCache…
Coder787-source Dec 5, 2026
1990627
Reduce Apple mesh pipeline output memory for Astro Bot (spirvEmitterF…
Coder787-source Dec 5, 2026
257185c
Reduce Apple mesh pipeline output memory for Astro Bot (spirvEmitterM…
Coder787-source Dec 5, 2026
d0666ad
Update M4 Pro Astro Bot mesh fix: bundle_moltenvk_macos.sh
Coder787-source Dec 5, 2026
27218c3
Update M4 Pro Astro Bot mesh fix: patch_moltenvk_mesh_budget.py
Coder787-source Dec 5, 2026
2fa2b09
Update M4 Pro Astro Bot mesh fix: test_moltenvk_mesh_budget.py
Coder787-source Dec 5, 2026
830db78
Update M4 Pro Astro Bot mesh fix: pipelineCache.cpp
Coder787-source Dec 5, 2026
0716fb8
Update M4 Pro Astro Bot mesh fix: spirvEmitterFlow.cpp
Coder787-source Dec 5, 2026
075d19b
Update M4 Pro Astro Bot mesh fix: spirvEmitterMesh.cpp
Coder787-source Dec 5, 2026
3362603
Update M4 Pro Astro Bot mesh fix: spirvEmitterModule.cpp
Coder787-source Dec 5, 2026
31a61bc
Update M4 Pro Astro Bot mesh fix: ShaderInfoCollection.cpp
Coder787-source Dec 5, 2026
622c33f
Update M4 Pro Astro Bot mesh fix: shader.cpp
Coder787-source Dec 5, 2026
8b2abd6
Update M4 Pro Astro Bot mesh fix: shader metadata
Coder787-source Dec 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 60 additions & 60 deletions scripts/bundle_moltenvk_macos.sh
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
#!/usr/bin/env bash
# Bundle the released fallback and the pinned mesh-capable MoltenVK driver.
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"
: "${RUNNER_TEMP:?RUNNER_TEMP must be set}"
: "${MOLTENVK_VERSION:?MOLTENVK_VERSION must be set}"
: "${MOLTENVK_SHA256:?MOLTENVK_SHA256 must be set}"

archive="$RUNNER_TEMP/MoltenVK-macos.tar"
package="$RUNNER_TEMP/MoltenVK"
curl --fail --location --retry 3 \
--output "$archive" \
"https://github.com/KhronosGroup/MoltenVK/releases/download/$MOLTENVK_VERSION/MoltenVK-macos.tar"
echo "$MOLTENVK_SHA256 $archive" | shasum -a 256 --check
tar -xf "$archive" -C "$RUNNER_TEMP"
install -m 755 \
"$package/MoltenVK/dynamic/dylib/macOS/libMoltenVK.dylib" \
_Build/macos/install/libMoltenVK.dylib
install -m 644 "$package/LICENSE" _Build/macos/install/LICENSE.MoltenVK
codesign --force --sign - --timestamp=none _Build/macos/install/libMoltenVK.dylib

revision=b93bdef3e3a218a2a670c9a25f65682967ebdc85
mesh_dir="$RUNNER_TEMP/MoltenVK-mesh-$revision"
mkdir "$mesh_dir"
git -C "$mesh_dir" init
git -C "$mesh_dir" remote add origin https://github.com/KhronosGroup/MoltenVK.git
git -C "$mesh_dir" fetch --no-tags --depth=1 origin "$revision"
git -C "$mesh_dir" checkout --detach FETCH_HEAD
if [[ "$(git -C "$mesh_dir" rev-parse HEAD)" != "$revision" ]]; then
echo "Unexpected MoltenVK revision" >&2
exit 1
fi
python3 scripts/patch_moltenvk_mesh_budget.py "$mesh_dir"
git -C "$mesh_dir" diff --check
(
cd "$mesh_dir"
./fetchDependencies --macos
make macos
)

install_dir="_Build/macos/install"
app="$install_dir/KytyPlus.app"
frameworks="$app/Contents/Frameworks"
driver="$mesh_dir/Package/Latest/MoltenVK/dynamic/dylib/macOS/libMoltenVK.dylib"
test -f "$driver"
lipo "$driver" -verify_arch x86_64
mv "$install_dir/libMoltenVK.dylib" "$install_dir/libMoltenVK-1.4.2.dylib"
install -m 755 "$driver" "$install_dir/libMoltenVK.dylib"
install -m 644 "$mesh_dir/LICENSE" "$install_dir/LICENSE.MoltenVK-mesh"
codesign --force --sign - --timestamp=none "$install_dir/libMoltenVK.dylib"
mkdir -p "$frameworks"
install -m 755 "$install_dir/libMoltenVK.dylib" "$frameworks/libMoltenVK.dylib"
install -m 755 "$install_dir/libMoltenVK-1.4.2.dylib" "$frameworks/libMoltenVK-1.4.2.dylib"
codesign --force --sign - --options runtime --entitlements src/macos_jit.entitlements "$app/Contents/MacOS/kyty_emulator"
codesign --force --sign - --timestamp=none --preserve-metadata=entitlements,requirements,flags "$app"
codesign --verify --strict "$app/Contents/MacOS/kyty_emulator"
codesign --verify --strict "$frameworks/libMoltenVK.dylib"
codesign --verify --strict "$install_dir/libMoltenVK-1.4.2.dylib"
printf '%s\n' 'MoltenVK mesh PR #2842 b93bdef3e3a218a2a670c9a25f65682967ebdc85; M4 Pro tester verified 12288-byte LDS and first real frame. Upstream development driver; 1.4.2 fallback included.' > "$install_dir/MOLTENVK_VERSION.txt"

#!/usr/bin/env bash
# Bundle the released fallback and the pinned mesh-capable MoltenVK driver.
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"
: "${RUNNER_TEMP:?RUNNER_TEMP must be set}"
: "${MOLTENVK_VERSION:?MOLTENVK_VERSION must be set}"
: "${MOLTENVK_SHA256:?MOLTENVK_SHA256 must be set}"
archive="$RUNNER_TEMP/MoltenVK-macos.tar"
package="$RUNNER_TEMP/MoltenVK"
curl --fail --location --retry 3 \
--output "$archive" \
"https://github.com/KhronosGroup/MoltenVK/releases/download/$MOLTENVK_VERSION/MoltenVK-macos.tar"
echo "$MOLTENVK_SHA256 $archive" | shasum -a 256 --check
tar -xf "$archive" -C "$RUNNER_TEMP"
install -m 755 \
"$package/MoltenVK/dynamic/dylib/macOS/libMoltenVK.dylib" \
_Build/macos/install/libMoltenVK.dylib
install -m 644 "$package/LICENSE" _Build/macos/install/LICENSE.MoltenVK
codesign --force --sign - --timestamp=none _Build/macos/install/libMoltenVK.dylib
revision=b93bdef3e3a218a2a670c9a25f65682967ebdc85
mesh_dir="$RUNNER_TEMP/MoltenVK-mesh-$revision"
mkdir "$mesh_dir"
git -C "$mesh_dir" init
git -C "$mesh_dir" remote add origin https://github.com/KhronosGroup/MoltenVK.git
git -C "$mesh_dir" fetch --no-tags --depth=1 origin "$revision"
git -C "$mesh_dir" checkout --detach FETCH_HEAD
if [[ "$(git -C "$mesh_dir" rev-parse HEAD)" != "$revision" ]]; then
echo "Unexpected MoltenVK revision" >&2
exit 1
fi
python3 scripts/patch_moltenvk_mesh_budget.py "$mesh_dir"
git -C "$mesh_dir" diff --check
(
cd "$mesh_dir"
./fetchDependencies --macos
make macos
)
install_dir="_Build/macos/install"
app="$install_dir/KytyPlus.app"
frameworks="$app/Contents/Frameworks"
driver="$mesh_dir/Package/Latest/MoltenVK/dynamic/dylib/macOS/libMoltenVK.dylib"
test -f "$driver"
lipo "$driver" -verify_arch x86_64
mv "$install_dir/libMoltenVK.dylib" "$install_dir/libMoltenVK-1.4.2.dylib"
install -m 755 "$driver" "$install_dir/libMoltenVK.dylib"
install -m 644 "$mesh_dir/LICENSE" "$install_dir/LICENSE.MoltenVK-mesh"
codesign --force --sign - --timestamp=none "$install_dir/libMoltenVK.dylib"
mkdir -p "$frameworks"
install -m 755 "$install_dir/libMoltenVK.dylib" "$frameworks/libMoltenVK.dylib"
install -m 755 "$install_dir/libMoltenVK-1.4.2.dylib" "$frameworks/libMoltenVK-1.4.2.dylib"
codesign --force --sign - --options runtime --entitlements src/macos_jit.entitlements "$app/Contents/MacOS/kyty_emulator"
codesign --force --sign - --timestamp=none --preserve-metadata=entitlements,requirements,flags "$app"
codesign --verify --strict "$app/Contents/MacOS/kyty_emulator"
codesign --verify --strict "$frameworks/libMoltenVK.dylib"
codesign --verify --strict "$install_dir/libMoltenVK-1.4.2.dylib"
printf '%s\n' 'MoltenVK mesh PR #2842 b93bdef3e3a218a2a670c9a25f65682967ebdc85; 32 KiB profile: 16384-byte LDS, 8184-byte output, 8200-byte staging. Experimental; M4 Pro validation pending. Upstream development driver; 1.4.2 fallback included.' > "$install_dir/MOLTENVK_VERSION.txt"
122 changes: 75 additions & 47 deletions scripts/patch_moltenvk_mesh_budget.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,75 @@
#!/usr/bin/env python3
"""Apply a narrowly scoped experimental MoltenVK mesh-memory budget rebalance."""
import argparse
import hashlib
from pathlib import Path
import subprocess
import sys

REVISION = "b93bdef3e3a218a2a670c9a25f65682967ebdc85"
SOURCE = "MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm"
BLOB = "b6dea714037baea257f7dab2fd3b8edd92fb64e9"
REPLACEMENTS = (
("\t\t\t\tuint32_t meshShared = (lim.maxComputeSharedMemorySize - sizeof(uint32_t[2]) - meshPrims * sizeof(uint32_t[4])) / 2;", "\t\t\t\t// Keep the upstream staging reservation. Rebalance exactly one dword\n\t\t\t\t// from the output budget to LDS on the 32 KiB threadgroup-memory tier.\n\t\t\t\t// Astro Bot requests a full 12 KiB of LDS. The total budget is unchanged.\n\t\t\t\tconst uint32_t meshStaging = sizeof(uint32_t[2]) + meshPrims * sizeof(uint32_t[4]);\n\t\t\t\tconst uint32_t meshBudget = lim.maxComputeSharedMemorySize > meshStaging\n\t\t\t\t\t? lim.maxComputeSharedMemorySize - meshStaging : 0;\n\t\t\t\tuint32_t meshShared = meshBudget / 2;\n\t\t\t\tuint32_t meshOutput = meshShared;\n\t\t\t\tif (lim.maxComputeSharedMemorySize == 32u * KIBI &&\n\t\t\t\t\tmeshShared == 12u * KIBI - sizeof(uint32_t)) {\n\t\t\t\t\tmeshShared += sizeof(uint32_t);\n\t\t\t\t\tmeshOutput -= sizeof(uint32_t);\n\t\t\t\t}"),
("\t\t\t\tmeshProps->maxMeshSharedMemorySize = meshProps->maxMeshOutputMemorySize = meshShared;", "\t\t\t\tmeshProps->maxMeshSharedMemorySize = meshShared;\n\t\t\t\tmeshProps->maxMeshOutputMemorySize = meshOutput;"),
("\t\t\t\tmeshProps->maxMeshPayloadAndSharedMemorySize = meshProps->maxMeshPayloadAndOutputMemorySize = payload + meshShared;", "\t\t\t\tmeshProps->maxMeshPayloadAndSharedMemorySize = payload + meshShared;\n\t\t\t\tmeshProps->maxMeshPayloadAndOutputMemorySize = payload + meshOutput;"),
)

def patched_source(source: str) -> str:
for old, new in REPLACEMENTS:
if source.count(old) != 1:
raise ValueError("Expected exactly one upstream mesh-budget anchor: " + old)
source = source.replace(old, new, 1)
return source

def git_blob(data: bytes) -> str:
return hashlib.sha1(b"blob " + str(len(data)).encode("ascii") + b"\0" + data).hexdigest()

def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("checkout", type=Path)
args = parser.parse_args()
root = args.checkout.resolve()
revision = subprocess.check_output(
["git", "-C", str(root), "rev-parse", "HEAD"], text=True
).strip()
if revision != REVISION:
sys.exit("Refusing to patch a different MoltenVK revision: " + revision)
path = root / SOURCE
source = path.read_bytes()
if git_blob(source) != BLOB:
sys.exit("Refusing to patch a changed MoltenVK source file")
result = patched_source(source.decode("utf-8")).encode("utf-8")
path.write_bytes(result)
print("MoltenVK mesh budget: 32768 - 8200 = 24568 bytes; LDS 12288, output 12280.")

if __name__ == "__main__":
main()
#!/usr/bin/env python3
"""Apply the experimental MoltenVK mesh-memory budget profile for Apple GPUs."""
import argparse
import hashlib
from pathlib import Path
import subprocess
import sys

REVISION = "b93bdef3e3a218a2a670c9a25f65682967ebdc85"
SOURCE = "MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm"
BLOB = "b6dea714037baea257f7dab2fd3b8edd92fb64e9"
OLD_MESH = " uint32_t meshShared = (lim.maxComputeSharedMemorySize - sizeof(uint32_t[2]) - meshPrims * sizeof(uint32_t[4])) / 2;"
NEW_MESH = (
" // Preserve the guest mesh shader's full 16 KiB LDS requirement on 32 KiB Apple GPUs.\n"
" // The remaining 8,184 bytes are available for staged mesh outputs after\n"
" // reserving the two counters and 512 triangle indices.\n"
" const uint32_t meshStaging = sizeof(uint32_t[2]) + meshPrims * sizeof(uint32_t[4]);\n"
" const uint32_t meshBudget = lim.maxComputeSharedMemorySize > meshStaging\n"
" ? lim.maxComputeSharedMemorySize - meshStaging : 0;\n"
" uint32_t meshShared = meshBudget / 2;\n"
" uint32_t meshOutput = meshBudget - meshShared;\n"
" if (lim.maxComputeSharedMemorySize == 32u * KIBI &&\n"
" meshBudget >= 16u * KIBI) {\n"
" meshShared = 16u * KIBI;\n"
" meshOutput = meshBudget - meshShared;\n"
" }"
)
REPLACEMENTS = (
(OLD_MESH, NEW_MESH),
(
" meshProps->maxMeshSharedMemorySize = meshProps->maxMeshOutputMemorySize = meshShared;",
" meshProps->maxMeshSharedMemorySize = meshShared;\n"
" meshProps->maxMeshOutputMemorySize = meshOutput;"
),
(
" meshProps->maxMeshPayloadAndSharedMemorySize = meshProps->maxMeshPayloadAndOutputMemorySize = payload + meshShared;",
" meshProps->maxMeshPayloadAndSharedMemorySize = payload + meshShared;\n"
" meshProps->maxMeshPayloadAndOutputMemorySize = payload + meshOutput;"
),
)


def patched_source(source: str) -> str:
for old, new in REPLACEMENTS:
if source.count(old) != 1:
raise ValueError("Expected exactly one upstream mesh-budget anchor: " + old)
source = source.replace(old, new, 1)
return source


def git_blob(data: bytes) -> str:
return hashlib.sha1(b"blob " + str(len(data)).encode("ascii") + bytes([0]) + data).hexdigest()


def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("checkout", type=Path)
args = parser.parse_args()
root = args.checkout.resolve()
revision = subprocess.check_output(
["git", "-C", str(root), "rev-parse", "HEAD"], text=True
).strip()
if revision != REVISION:
sys.exit("Refusing to patch a different MoltenVK revision: " + revision)
path = root / SOURCE
source = path.read_bytes()
if git_blob(source) != BLOB:
sys.exit("Refusing to patch a changed MoltenVK source file")
result = patched_source(source.decode("utf-8")).encode("utf-8")
path.write_bytes(result)
print("MoltenVK mesh budget: 32768 - 8200 = 24568 bytes; LDS 16384, output 8184.")


if __name__ == "__main__":
main()
Loading
Loading