WIP: 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
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/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
testing wanted
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?
What this is for: the macOS port (#420). Three files did not compile on macOS: two in the renderer
(
gpu/vk/vk_programs.cpp,gpu/vk/vk_shader.cpp), and the debug tools inhost/hos_main.c, which a macOS build leftout, so the executable did not link. This PR gives each an Apple branch. 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, whichthe shader stamp hashes. What is measured: the two renderer files compiled with the renderer's own command, for arm64
and x86_64:
main's fail, this PR's build.tests/test_debug_tools_linux.py, which now also checks macOS, fails onmain'shos_main.cand passes here, in two interleaved runs each. And the full game-free suite on an Apple M4 Max(macOS 26.7.1), compared by test name with
main. Not measured: a game run on this branch; Windows and Linux builds;macOS 14.4; an Intel Mac.
Why
A macOS build of the renderer stopped at two compile errors, and once those were fixed the executable did not link:
Problem
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.What changed
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__).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 (17 entries in all). Before, a guard naming a third platformwould have counted as unknown, so the test could no longer have caught one that dropped
_WIN32or__linux__.Flags and settings
None new. The program life log (
RX_VK_LOG_PROGRAM_LIFE=1) writesmajor_faults unavailableon macOS; the same lineelsewhere is unchanged.
Measurements
main:
5e072fc8c2adadba5ea610148be1c47800ba0cca(2026-11-14)this PR:
mac/renderer-compile@bf85ed4ae0cff08dd6a38df9bcce9c3314d26b39Hardware: 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:
vk_programs.cppandvk_shader.cpp, for arm64 and for x86_64, withnx2/build.py's own renderercommand (
renderer_flags(), plus theLONGSHOT_SHADER_STAMPthe build computes forvk_shader.cpp).main'snx2/build.pyhas no macOS commands, so both sides took them from the build-flags PR (#453), whosegpu/ismain's byte for byte:main's two files on one side, this PR's on the other. A compile is deterministic, so one runper file and architecture.
tests/test_debug_tools_linux.pyfrom this PR, run on this PR's tree and on a copy holdingmain'shost/hos_main.c, interleaved: PR, main, PR, main.main's own version of the test also runs on this PR's tree.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.5e072fc8bf85ed4avk_programs.cpp, arm64 and x86_64RUSAGE_THREADundeclared6d45acdc…, x86_645973bbfe…)vk_shader.cpp, arm64 and x86_64environundeclaredd892778d…, x86_64d19af652…)tests/test_debug_tools_linux.py, runs 1 and 2ok: the 17 debug tools are compiled on Windows, Linux, macOSvk_shader.cpp's shader stamp for this build command changes from0xbc2a6a5c36fef83f(main) to0xcbcf3214c5e45816(this PR): that is the one-time cache rebuild.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__(1665 lines) and with-U_WIN32 -D__linux__ -U__APPLE__(1898 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 checksWindows and Linux only). The same 17 skips.
main, which other macOS pull requestsaddress:
test_appimage_package_retry,test_collect_wide,test_control,test_framegen_resources,test_game_layout,test_low_memory_notice,test_mem_gate,test_mem_gate_children,test_mirror_trim,test_module_ids,test_oot_state_tap,test_pad_layout,test_pcache_header_read,test_pipeline_cache_file,test_pipeline_cache_save,test_pipeline_play_cache,test_prof_symbols,test_program_cache_cleanup,test_program_cache_one_variant.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.
Not tested:
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).Needs other testers:
changes. With
RX_VK_LOG_PROGRAM_LIFE=1, the create lines still endmajor_faults <n>(request to open).Screenshots
Nothing on screen.
Risk and rollback
vk_shader.cppis hashed intoLONGSHOT_SHADER_STAMP(nx2/build.py:1176-1182), so afterupdating, the first start translates the shader programs again, as with any edit to that file. Nothing else changes
off Apple: the preprocessed text is
main's.major_faultsseesunavailableinstead.Reviewer notes
5e072fc8..bf85ed4a: two commits, no dependency.7f40bab2is the renderer's two files;bf85ed4ais thedebug tools and their test.
-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); renaming it was left out.mainatdc390e59(7 commits after this branch's base),git merge-treefinds a conflict inhost/hos_main.c; a rebase before ready resolves it. #370 there moves the stamp's file list tonx2/translator_files.py, which still namesvk_shader.cpp, so the one-time cache rebuild holds on both bases.Issues
See #420.
Checklist
For everyone
type(scope): description).main. Based on5e072fc8;mainhas since moved todc390e59(a conflict named underReviewer notes). Rebased before ready.
python -I -B tests/run_all.pyrun and passing (any failure that also fails onmainis named above). On macOS:525 passed, 17 skipped, and the same 19 failures as
main, named under Testing.request is still to open.
the median reported. For a
fix: the test fails onmainand passes here in two interleaved runs; the compiles failon
mainand build here.third_party/untouched (a new folder with aPROVENANCE.mdinstead).If applicable
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.is
main's. Request to open.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.