Files
darling-lol/tools/build-riot-metal-runtime.py
T
lucannez64andClaude Opus 5.5 2549e2b654 Report the host GPU name and VRAM from MTLDevice
-[MTLDevice name] returned "Darling Indium Device" for every GPU. It now
returns the selected Vulkan device's name in macOS Metal style: the
trailing driver note in brackets and the (R)/(TM) marks are removed, and
NVIDIA names are unchanged. The name is never replaced with another
vendor's. recommendedMaxWorkingSetSize is the device-local heap size on
discrete GPUs and all heaps on integrated/CPU devices, with the old 1 GiB
as fallback. Both are computed once per device.

hasUnifiedMemory stays YES by default: synchronizeResource:/
synchronizeTexture: are missing and Private buffers created with data
abort in Indium, so reporting NO on discrete GPUs would send apps down
unimplemented paths. DARLING_METAL_HOST_UNIFIED_MEMORY=1 opts in to the
GPU-type answer. DARLING_METAL_GPU_NAME and DARLING_METAL_VRAM_MB
override the name and working set.

The cleaning logic lives in private-include/Metal/MTLDeviceInfo.h and is
covered by the host check tools/test-metal-device-info.cpp. Metal now
links indium_private for the Vulkan properties, and the runtime build
script adds Indium's private headers before compiling MTLDevice.mm.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-17 20:49:42 +02:00

46 lines
3.0 KiB
Python

#!/usr/bin/env python3
"""Build the Metal resource/command bridges and their GPU regression check."""
from pathlib import Path
import shlex
import subprocess
root = Path(__file__).resolve().parent.parent
folder = root / 'build/darling-src/build/src/external/metal'
source = root / 'build/darling-src/src/external/metal/src/Metal'
flags = {}
for line in (folder / 'CMakeFiles/Metal.dir/flags.make').read_text().splitlines():
if line.startswith('CXX_') and ' = ' in line:
key, value = line.split(' = ', 1)
flags[key] = shlex.split(value)
resource_include = subprocess.check_output(['clang++', '-print-resource-dir'], text=True).strip() + '/include'
flags['CXX_INCLUDES'] = [resource_include if value.startswith('/usr/lib/clang/') and value.endswith('/include') else value for value in flags['CXX_INCLUDES']]
# MTLDevice.mm reads Vulkan device properties through Indium's private headers.
flags['CXX_INCLUDES'].append('-I' + str(root / 'build/darling-src/src/external/metal/deps/indium/private-include'))
link = shlex.split((folder / 'CMakeFiles/Metal.dir/link.txt').read_text())
# These objects passed live League validation. Keep the broader resource/queue
# optimization experiment out of the default build after fresh-match stalls.
for name in ('MTLBuffer', 'MTLTexture', 'MTLDevice', 'MTLSamplerDescriptor', 'MTLTextureDescriptor', 'MTLCommandBuffer', 'MTLBlitCommandEncoder', 'MTLDepthStencilDescriptor', 'MTLStencilDescriptor', 'MTLVertexDescriptor', 'MTLRenderPipeline', 'MTLComputeCommandEncoder', 'MTLRenderCommandEncoder', 'MTLArgument', 'MTLLibrary'):
obj = root / f'build/riot-metal-{name}.o'
subprocess.run(['clang++', *flags['CXX_DEFINES'], *flags['CXX_INCLUDES'],
*flags['CXX_FLAGS'], '-O2', '-c', str(source / (name + '.mm')),
'-o', str(obj)], check=True)
original = 'CMakeFiles/Metal.dir/src/Metal/' + name + '.mm.o'
if original in link:
link[link.index(original)] = str(obj)
else:
link.append(str(obj))
link[link.index('-o') + 1] = str(root / 'build/riot-Metal')
subprocess.run(link, cwd=folder, check=True)
obj = root / 'build/riot-metal-sampler-check.o'
subprocess.run(['clang++', *flags['CXX_DEFINES'], *flags['CXX_INCLUDES'],
*flags['CXX_FLAGS'], '-c', str(root / 'tools/riot-metal-sampler-check.mm'),
'-o', str(obj)], check=True)
batch = root / 'build/riot-metal-batch-check.o'
subprocess.run(['clang++', *flags['CXX_DEFINES'], *flags['CXX_INCLUDES'],
*flags['CXX_FLAGS'], '-c', str(root / 'tools/riot-metal-batch-check.mm'),
'-o', str(batch)], check=True)
subprocess.run(['clang++', '-target', 'x86_64-apple-macosx11.0', '-fuse-ld=lld',
'-nostdlib', '-isysroot', '@DARLING_SDK@', str(obj), str(batch),
'-lSystem', '-lc++', '-lobjc', '-framework', 'Foundation',
str(root / 'build/riot-Metal'), str(root / 'build/riot-libindium.dylib'), '-o',
str(root / 'build/riot-metal-sampler-check')], check=True)