feat(runtime): the native window, for a graphics API that makes its own surface

win_native_window / win_native_instance hand a Vulkan swapchain what it is created on: the
HWND and module instance on Windows (VkWin32SurfaceCreateInfoKHR), the game's view on macOS.
Headless builds define both as null (weak on macOS, so a windowed link keeps cocoa.ll's), so
code that asks for them links everywhere and simply finds no window.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-15 10:42:19 +03:00
parent f97d54aa2a
commit 51d82063aa
4 changed files with 48 additions and 0 deletions

View file

@ -1670,3 +1670,16 @@ go:
out:
ret void
}
; ---- the native window, for a graphics API that makes its own surface ------------------
; win32.ll's contract: on macOS the view the game draws in (a Metal-backed layer would hang
; off it); there is no module instance to hand over, so that one is null.
define ptr @win_native_window() {
entry:
%v = load ptr, ptr @W_view
ret ptr %v
}
define ptr @win_native_instance() {
entry:
ret ptr null
}

View file

@ -366,3 +366,13 @@ entry:
%t = add i64 %m, %us
ret i64 %t
}
; headless on macOS: no window, so nothing for a graphics API to make a surface on
define weak ptr @win_native_window() {
entry:
ret ptr null
}
define weak ptr @win_native_instance() {
entry:
ret ptr null
}

View file

@ -42,3 +42,13 @@ define void @win_toggle_fullscreen() {
entry:
ret void
}
; headless: no window, so nothing for a graphics API to make a surface on (win32.ll has the real ones)
define ptr @win_native_window() {
entry:
ret ptr null
}
define ptr @win_native_instance() {
entry:
ret ptr null
}

View file

@ -255,6 +255,21 @@ out:
ret void
}
; ---- the native window, for a graphics API that makes its own surface ------------------
; A Vulkan swapchain is created on the window itself (VkWin32SurfaceCreateInfoKHR takes the
; module instance and the HWND), not through a context this file attaches. Null before
; win_open has made the window; the same names are stubs returning null in a headless build.
define ptr @win_native_window() {
entry:
%h = load ptr, ptr @W_hwnd
ret ptr %h
}
define ptr @win_native_instance() {
entry:
%inst = call ptr @GetModuleHandleA(ptr null)
ret ptr %inst
}
; set (%on != 0) or clear a key's bit in the 256-bit held set
define void @win_held_bit(i32 %k, i32 %on) {
entry: