fix(macos): build vk_programs, vk_shader and the debug tools on Darwin #492
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/upscaling
beanstalk: approved @ 1697603
beanstalk: approved @ 2c5a62e
beanstalk: approved @ 4fd82b7
beanstalk: approved @ 64d6d09
beanstalk: approved @ 6f91fae
beanstalk: approved @ 70a78f9
beanstalk: approved @ 8015c9a
beanstalk: approved @ 8d361dc
beanstalk: approved @ 9d8356e
beanstalk: approved @ abf2227
beanstalk: approved @ d82f202
beanstalk: approved @ e5f1e40
beanstalk: approved @ ee8ab5f
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
testing wanted
ci: approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!492
Loading…
Reference in a new issue
No description provided.
Delete branch "mooki/Longshot:mac/renderer-compile"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type: fix · Risk: low · Tested on: macOS 26.7.1, Apple M4 Max (game-free checks, arm64 and x86_64 compiles; no game run on this branch) · Needs: none
Why
A macOS build stops in three files: two in the renderer (
gpu/vk/vk_programs.cpp,gpu/vk/vk_shader.cpp) do notcompile, and the debug tools in
host/hos_main.care left out of a macOS build, so the executable does not link. ThisPR gives each an Apple branch, part of the macOS port (#420). Windows and Linux compile the same text as before.
Every platform rebuilds its shader caches once after this PR, because it edits
gpu/vk/vk_shader.cpp, which theshader stamp hashes.
vk_programs.cpp: the program life log'sthread_major_faults()asksgetrusage(RUSAGE_THREAD). Darwin has noper-thread fault count at all:
getrusagetakes onlyRUSAGE_SELFandRUSAGE_CHILDREN(sys/resource.h), theper-thread
thread_infoflavours (THREAD_BASIC_INFO,THREAD_EXTENDED_INFO, which isproc_threadinfo) hold runtimes and scheduling but no faults or page-ins, and
task_events_info,proc_taskinfoandrusage_info'sri_pageinscount the whole task.vk_shader.cpp:translator_stampreads_environ, whichhost/posix/windows.hdefines asenviron. Darwin'sheaders do not declare
environfor C++ (onlycrt_externs.h's_NSGetEnviron).hos_main.c: the eight debug-tool regions (cheats, pouch and inventory, clock, teleport and age, flight, lift,free view) are guarded by
#if defined(_WIN32) || defined(__linux__). A macOS build compiles them out, buthost/control.c's game table names seven of their functions.How to reproduce
Seen on: macOS 26.7.1, Apple M4 Max, Apple clang 21.0.0 (Command Line Tools, SDK 27), arm64 and x86_64 (compiles
with the renderer's flags, and this PR's game-free test against
main'shos_main.c); the link error on a macOSintegration build. Only macOS is affected.
Settings and switches: defaults (the renderer's flags from
nx2/build.py'srenderer_flags()).Steps: on a Mac, compile
main'sgpu/vk/vk_programs.cppandgpu/vk/vk_shader.cppwith the renderer's flags forarm64 or x86_64; and run this PR's
python -I -B tests/test_debug_tools_linux.pybesidemain'shost/hos_main.c.Expected: two Mach-O objects, and every debug tool compiled on macOS as on Windows and Linux.
Actual: at
main@6c9edffe, on each architecture:The test exits 1 with 26 lines of the debug tools not compiled on macOS. (The
ldline is from the macOS integrationbranch's link, once the two compile errors were fixed.)
What changed
Each of the three files gets an Apple branch: the life log says
major_faults unavailableon macOS,vk_shader.cppdeclares
environ, and the debug tools' eight guards name__APPLE__too. Windows and Linux preprocess tomain's text;the test now checks the guards for macOS as well.
host/hos_main.cand the Apple branches ofvk_programs.cppandvk_shader.cpp.gpu/vk/vk_programs.cpp(Apple only):thread_major_faults()and its start value are not compiled on Darwin,with a comment giving the reason above. The life log's create line ends
major_faults unavailablethere instead ofmajor_faults <n>. It is one token, so a parser that splits on spaces still finds the key and no number. Neither thetask's page-in count (other threads' disk waits booked to this create call) nor a 0 (which reads as "no faults") is
logged in its place.
gpu/vk/vk_shader.cpp(Apple only): a namespace-scopeextern char** environ;, the declarationvk_menu.cppandvk_bug_report.cppalready use._environkeeps its spelling, whichtests/test_program_stamp_knobs.pylooks for. libdyld exportsenvironon both architectures, so the strict-undefined errorlink of the Vulkan dylib resolves it.host/hos_main.c: the eight guards read#if defined(_WIN32) || defined(__linux__) || defined(__APPLE__).Since #399 the flight readiness guard sits in
hos_oot_player_seen(), which the Skip title screen also asks, so onmacOS that row now stops its presses once the player is seen, as on Windows and Linux.
Every call inside has a macOS provider, nothing is stubbed: the SRW locks (
host/posix/windows.hover the waits PR'sdarwin_wait.c),GetAsyncKeyState,GetForegroundWindowandGetWindowThreadProcessId(win32_posix.c),GetCurrentProcessId,hos_flight_input,hos_free_camera_inputandhos_move_stick_held(nn_hid.c),hos_now_ns,hos_sys_alloc,rx_option_set, and libSystem's math and pthread calls. The#elsestubs stay forthe web build.
tests/test_debug_tools_linux.py: it evaluates each guard for Windows, Linux and now macOS, and also checks theseven functions
host/control.c's game table names, andhos_oot_player_seen()(18 entries in all). Before, a guardnaming a third platform would have counted as unknown, so the test could no longer have caught one that dropped
_WIN32or__linux__. It reads the source as text, so it gives the same answer on every OS.-Wall(the build passes-Wno-everything):-Wlogical-not-parenthesesat!child == bridge_adult(intended: the adult flag compared withthe bridge's) and an unused
oot_item_kinds. Linux and Windows compile the same code today.test_debug_tools_linux.py).6c9edffe..752d8d7b: three commits, no dependency.9fbf09cdis the renderer's two files;05d42dcdis the debug tools and their test;
752d8d7b, new with the rebase, has the test checkhos_oot_player_seen()too.main6c9edffe(2026-11-14). One conflict, inhost/hos_main.c, from #399 (Skip title screen): #399moved
hos_oot_flight_shortcut_ready()'s guarded body into a newhos_oot_player_seen()and made the shortcut callit, where this PR adds
__APPLE__to that guard. Resolved by keeping #399's two functions and adding__APPLE__tothe guard where it now is, so the guards are still eight and all eight name
__APPLE__. Because the shortcut's firststatement is now a plain call, the test would have passed with that guard left without
__APPLE__:752d8d7baddshos_oot_player_seen()to the test's list (with the guard lacking__APPLE__in a scratch copy it fails on macOS;the old list passed). On macOS this also lets the Skip title screen stop at play, as it does on Windows and Linux.
vk_programs.cppandvk_shader.cpprebased without conflict.Measurements
Verdict: fixed, a game-free proof (nothing to time):
main's two renderer files fail to compile for arm64 andx86_64 and this PR's build; the debug-tools test fails on
main'shos_main.cand passes here, in two interleaved runseach; the full suite is unchanged by test name.
Commits: main
6c9edffe5d(2026-11-14); this PRmac/renderer-compile@752d8d7b93.Hardware: Apple M4 Max, 16 cores, 64 GiB, macOS 26.7.1; Apple clang 21.0.0 (Command Line Tools, SDK 27); Python 3.14.10.
No GPU, no game.
Scene: none. Game-free.
Method: compiles:
vk_programs.cppandvk_shader.cpp, for arm64 and for x86_64, with the renderer's flags(
nx2/build.py'srenderer_flags(), written out as one command, with a fixedLONGSHOT_SHADER_STAMPforvk_shader.cpp):main's two files on one side, this PR's on the other. A compile is deterministic, so one run perfile and architecture. (Before the rebase, on
5e072fc8, both sides took the command from the build-flags PR, #453, withthe stamp the build computes; the results were the same.) Test:
tests/test_debug_tools_linux.pyfrom this PR, run onthis PR's tree and on a copy holding
main'shost/hos_main.c, interleaved: PR, main, PR, main.main's own version ofthe test also runs on this PR's tree. Suite:
tests/run_all.py --jobs 6on this PR, compared by test name with amainrun on the same Mac.
How to reproduce:
python -I -B tests/test_debug_tools_linux.py(it readshost/hos_main.cbeside it). For thecompiles, a macOS build with the build-flags PR, or
nx2/build.py'srenderer_flags()on its own.6c9edffe752d8d7bvk_programs.cpp, arm64 and x86_64RUSAGE_THREADundeclaredvk_shader.cpp, arm64 and x86_64environundeclaredtests/test_debug_tools_linux.py, runs 1 and 2ok: the 18 debug tools are compiled on Windows, Linux, macOSvk_shader.cppis still one of the files the shader stamp hashes (nx2/translator_files.pysince #370), so the stampchanges: that is the one-time cache rebuild. (Measured before the rebase with #453's command:
0xbc2a6a5c36fef83fonmain
5e072fc8,0xcbcf3214c5e45816on this PR.)Screenshots: none; nothing on screen.
Flags and settings
None new. The program life log (
RX_VK_LOG_PROGRAM_LIFE=1) writesmajor_faults unavailableon macOS; the same lineelsewhere is unchanged.
Testing
Tested:
The compiles and the test, as above.
main's owntests/test_debug_tools_linux.pyalso passes on this PR'shos_main.c(ok: the 10 debug tools are compiled on Windows and Linux).Windows and Linux see the same text (
unifdef, text only, not a build):unifdef -U__APPLE__of this PR'svk_programs.cppandvk_shader.cppequalsmain's files byte for byte;host/hos_main.cwith-D_WIN32 -U__linux__ -U__APPLE__(1678 lines) and with-U_WIN32 -D__linux__ -U__APPLE__(1920 lines) equalsmain's.The whole suite,
tests/run_all.py --jobs 6, on the same Mac:tests/test_debug_tools_linux.pypasses on both:
main's version checks Windows and Linux only.requests, some are checks main added or changed since
5e072fc8):test_appimage_package_retry,test_appimage_player_build,test_collect_wide,test_control,test_cpm_discovery,test_crash_dialog,test_crash_record,test_env_on,test_game_layout,test_lift_cleanup_error,test_linux_preflight,test_longshot_ctl,test_low_memory_notice,test_make_game_cache,test_mem_gate,test_mem_gate_children,test_mirror_trim,test_oot_state_tap,test_pcache_header_read,test_pipeline_cache_file,test_pipeline_cache_save,test_pipeline_play_cache,test_pipeline_tour,test_prof_symbols,test_program_cache_cleanup,test_program_cache_one_variant,test_readback_late,test_report_run,test_split_giants,test_vk_pgo,test_vram_budget_row,test_walk_key.recorder_sync_test.exe-2026-11-14-180744.ips).
History, not rerun on this branch: when these two commits were first made (
05b5d88f,d26e5f88, on the macOSintegration branch), a replay of a macOS executable link with the new
hos_main.cobject linked with no undefinedsymbol, where it had 7 before. Integration builds that carry them have since built both images and started the game
on macOS (see #420). That speaks for those builds, not for this branch alone.
After the rebase onto main
aa95d35f, at59f750aa(752d8d7bbefore the rebases ontoe090cc48andaa95d35f):Sweep3's checks of this head (the C/C++ it changes compiled, and its own tests run, on arm64 and x86_64 where they
apply) gave the same results as before;
python -I -B tests/run_all.pyon wave S1's merge11a5b4e7, which carriesthis head: 568/22/17 (passed/failed/skipped) against main aa95d35f's 543/33/17 on this Mac, no new failure
(
reports/2026-11-15-rebase-sweep-3.md).Not tested:
major_faults <n>there were not seen; the preprocessed text ismain's).mainplus this PR alone, macOS has no build commands (#453) and lacks theother macOS host PRs.
environper the SDK's.tbd(vk_menu.cpprelies on it already).Must be tested: None: the unifdef comparison shows Windows and Linux compile
main's text byte for byte(
vk_programs.cppandvk_shader.cppwith-U__APPLE__, andhost/hos_main.cfor Windows and for Linux, equalmain's), and the changed test reads the source as text, so its result does not depend on the OS it runs on. The onechange Windows and Linux see is the shader stamp (
vk_shader.cpp's bytes), which only makes the first start translateevery program again. The macOS side is covered under Tested. The same comparison at the rebased head
59f750aaagainstmain
aa95d35fgives the same result.Risks
What could break:
main's.major_faultsseesunavailableinstead.Turning it off: revert the three commits.
Compatibility: every platform:
vk_shader.cppis hashed intoLONGSHOT_SHADER_STAMP(its file list is innx2/translator_files.py, whichnx2/build.pycompiles in), so after updating, the first start translates the shaderprograms again, as with any edit to that file. Saves, the options file and the vk ABI are unchanged.
Issues
See #420.
Checklist
Everyone
type(scope): description) of the status line's type.main: onaa95d35f(#761, 2026-11-15), head59f750aa, without a new conflict; the one with#399 from the
6c9edfferebase stays resolved as in Reviewer notes; this PR's own commits, old → new:9fbf09cd→7ee5fd58,05d42dcd→82b2d660,752d8d7b→59f750aa; the commit names elsewhere in this description are frombefore the rebase.
python -I -B tests/run_all.pypasses (any failure that also fails onmainis named). On macOS: 531 passed, 17skipped, and 32 failures that also fail on main
6c9edffeon this Mac, named under Testing. After the rebase onto mainaa95d35f(head59f750aa): wave S1's merge11a5b4e7, 568/22/17 against main aa95d35f's 543/33/17, no new failure.third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here.tests/test_debug_tools_linux.pynowchecks macOS; the renderer files' proof is the compile above.
tests/that reads changed source updated in this PR, not weakened.bf85ed4ae0752d8d7b93752d8d7b9367ede2434b67ede2434b59f750aa38WIP: fix(macos): build vk_programs, vk_shader and the debug tools on Darwinto fix(macos): build vk_programs, vk_shader and the debug tools on DarwinFolded into #845 (feat(macos): run the host on macOS: build, runtime, control, crash records and the Vulkan loader)
Pull request closed