Files
reims-util/kext/Makefile
T
Anees Iqbal 5405b2d13b 🆕 Put a guest kext for reims-vgpu's GPU in the OpenCore image
x86-64 macOS guests drive reims-vgpu's GPU through AppleParavirtGPU.kext,
whose setupVersion asks for binary version 6 and turns every later feature
off; arm64 guests ask for 245. ReimsVgpu.kext (kext/), a Lilu plugin,
routes setupVersion to ask for 245 and set its features, and leaves the
driver's own negotiation to a host that does not store it. It also patches
what the x86-64 driver and its Metal plugin hardcode where arm64's ask the
device:

- AppleParavirtResourceHeap::addObject adds a two-plane D32S8 or X32S8
  texture as type 12, as arm64 does, not as type 2, which the host reads as
  one plane and faults on.
- -[AppleParavirtDevice featureProfile] returns 10001, not 10000, adding
  the Mac2 and Common3 families that ANGLE's Metal backend, so
  GPU-accelerated Chrome, needs.
- -[AppleParavirtTexture initTiledWithBuffer:...] no longer refuses
  SkyLight's tiles of a window wider than 2048 px, whose real bytes fit;
  the host accepts them from their real footprint (reims-vgpu's fdf661fee).

The plugin's bytes are patched through UserPatch, since Lilu's own user
patcher is off from macOS 11: it routes _cs_validate_page and rewrites a
page after the kernel has validated its pristine bytes, so code signing
does not notice and no other binary is touched.

The image carries the kext with Lilu 1.7.2's RELEASE build, pinned by
SHA-256 and cached like OpenCore, and loads both on macOS 26 alone (Darwin
25), so every other macOS boots with no kexts, as before. --no-kexts leaves
them out.

A kext builds on a Mac alone, and reims-util builds anywhere, so the built
kext is kept in the repository at kext/ReimsVgpu.kext and included in the
binary. kext/Makefile writes it there, against a DEBUG Lilu.kext and
MacKernelSDK, with the build date Lilu's plugin_start.cpp stamps pinned so
the same sources build the same bytes, and writes kext/sources.sha256,
which a test checks the sources against. The built kext holds Lilu's
plugin_start.cpp, so Lilu's BSD-3-Clause license is kept beside ours.
kext/probes/features.m prints what Metal's device answers in a guest.

Moved from reims-vgpu, where it was ec923f9f9, 4a4a882fb and 2e564d3f8 on
steelbrain/x86-metal-lilu.

Checked on msi-laptop (RTX 5080, macOS 26.6.1 guest): the host stores 245
and the desktop comes up; chrome://gpu reports hardware acceleration; a
clear to a D32S8 target that faulted the host completes. ocvalidate
(OpenCore 1.0.8) finds no issues in the image's config.plist, and the
kexts in the image match the built kext and Lilu's release byte for byte.
Not yet booted from a reims-util image.
2026-10-13 19:10:51 +03:00

74 lines
2.7 KiB
Makefile

# The guest kext: a Lilu plugin that x86-64 macOS guests load through
# OpenCore, beside Lilu, so their AppleParavirtGPU driver negotiates the
# binary version arm64 guests use (src/ReimsVgpu.cpp).
#
# reims-util puts ReimsVgpu.kext in its OpenCore images
# (../src/opencore/mod.rs), and builds anywhere, while the kext builds on a Mac
# alone. So the kext it takes is the one here, built and kept in the
# repository: rebuild it and commit it with any change to its sources.
# sources.sha256 records what it was built from, and reims-util's tests fail
# when that no longer matches.
#
# make LILU=<Lilu.kext> KERNEL_SDK=<MacKernelSDK>
# ReimsVgpu.kext and sources.sha256
# make clean remove build/, the objects
#
# LILU is a DEBUG build of Lilu 1.7.2, whose Contents/Resources holds the
# plugin headers and plugin_start.cpp; the image carries a RELEASE build of the
# same version. KERNEL_SDK is a checkout of acidanthera's MacKernelSDK. Builds
# on a Mac, with Xcode's clang and ld.
LILU ?=
KERNEL_SDK ?=
BUILD = build
NAME = ReimsVgpu
VERSION = 0.1.0
KEXT = $(NAME).kext
BINARY = $(KEXT)/Contents/MacOS/$(NAME)
# The date Lilu's plugin_start.cpp stamps in the kext's version string, from
# __DATE__: fixed, so the same sources build the same bytes.
DATE = 2026-10-13
export SOURCE_DATE_EPOCH := $(shell date -j -u -f '%Y-%m-%d %H:%M:%S' '$(DATE) 00:00:00' +%s)
RESOURCES = $(LILU)/Contents/Resources
FLAGS = -arch x86_64 -mkernel -nostdlib -fno-builtin -fno-stack-protector \
-mno-red-zone -Os -Wall -Wextra -Werror
CXXFLAGS = $(FLAGS) -std=c++17 -fapple-kext -fno-rtti -fno-exceptions \
-DKERNEL -DKERNEL_PRIVATE -DLILU_KEXTPATCH_SUPPORT \
-DPRODUCT_NAME=$(NAME) -DMODULE_VERSION=$(VERSION) \
-isystem $(RESOURCES) -isystem $(KERNEL_SDK)/Headers
OBJECTS = $(BUILD)/obj/$(NAME).o $(BUILD)/obj/UserPatch.o $(BUILD)/obj/plugin_start.o
all: $(BINARY)
check-sdk:
@test -f "$(RESOURCES)/Library/plugin_start.cpp" || \
{ echo "LILU must name a DEBUG Lilu.kext"; exit 1; }
@test -d "$(KERNEL_SDK)/Headers" || \
{ echo "KERNEL_SDK must name a MacKernelSDK checkout"; exit 1; }
$(BUILD)/obj/%.o: src/%.cpp src/UserPatch.hpp Makefile | check-sdk
@mkdir -p $(dir $@)
xcrun clang++ $(CXXFLAGS) -c $< -o $@
$(BUILD)/obj/plugin_start.o: Makefile | check-sdk
@mkdir -p $(dir $@)
xcrun clang++ $(CXXFLAGS) -Wno-unused-parameter \
-c $(RESOURCES)/Library/plugin_start.cpp -o $@
$(BINARY): $(OBJECTS) src/Info.plist
@mkdir -p $(dir $@)
xcrun ld -arch x86_64 -kext -undefined dynamic_lookup $(OBJECTS) -o $@
sed 's/@VERSION@/$(VERSION)/g' src/Info.plist > $(KEXT)/Contents/Info.plist
shasum -a 256 Makefile src/* > sources.sha256
clean:
rm -rf $(BUILD)
.PHONY: all check-sdk clean