feat(windows): Gl.* on Windows, through WGL and a driver-filled thunk table

gl_win.ll creates a hidden-window WGL 4.1 core context and carries gl.ll's
float/memory helpers, with ldexp and QueryPerformanceCounter in place of the
libSystem calls. glgen now also writes gl_thunks_win.ll: the same 478 thunks,
calling through pointers that @lgl_win_load fills from wglGetProcAddress (and
opengl32.dll for GL 1.1). ludicc links the pair against opengl32/gdi32/user32
on a Windows target.

Verified: gl_api.ludic and gl_thunks.ll regenerate byte-identically, ludic-dev
test 135/135, selfhost-test 32/32, and headless gl_triangle on an RTX 3070 Ti
matches the macOS frame to within one level per channel.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-13 02:10:36 +03:00
parent 5801005fca
commit cb05721a89
6 changed files with 13177 additions and 301 deletions

View file

@ -204,7 +204,6 @@ entry {
# would fail on a hundred Objective-C symbols rather than say so.
if g_target_win {
if g_windowed { die("ludicc: a windowed build is not available on Windows yet; build with --headless\n") }
if g_uses_gl { die("ludicc: Gl.* is not available on Windows yet\n") }
if g_uses_http { die("ludicc: Http.* is not available on Windows yet\n") }
}
@ -261,10 +260,18 @@ entry {
}
# Gl.* links the OpenGL backend: gl.ll (offscreen contexts, float helpers), the
# generated per-entry-point ABI thunks, and OpenGL.framework. Windowed or not.
# On Windows the same pair is gl_win.ll (a WGL context) and gl_thunks_win.ll (the
# thunks through a table wglGetProcAddress fills), against opengl32/gdi32/user32.
if g_uses_gl {
let gl = join_path(home, "runtime/native/gl.ll")
let glt = join_path(home, "runtime/native/gl_thunks.ll")
cmd = `{cmd} {gl} {glt} -framework OpenGL`
if g_target_win {
let glw = join_path(home, "runtime/native/gl_win.ll")
let gltw = join_path(home, "runtime/native/gl_thunks_win.ll")
cmd = `{cmd} {glw} {gltw} -luser32 -lgdi32 -lopengl32`
} else {
let gl = join_path(home, "runtime/native/gl.ll")
let glt = join_path(home, "runtime/native/gl_thunks.ll")
cmd = `{cmd} {gl} {glt} -framework OpenGL`
}
}
cmd = `{cmd} -o {out}`