mem: implicit-Context platform fixes — chess green on macOS/iOS/Android
Verify-step uncovered three categories of regressions where sx code
calls into the platform's C ABI through fn-pointer types or as a
registered callback. Every site now declares the right convention.
C-side calls INTO sx → callconv(.c) on the sx function:
- platform/android.sx: sx_android_render_thread_entry is the start
routine pthread_create invokes — pthread treats it as a C function.
Also annotate the pthread_create signature so the start-routine fn-
pointer field rejects mismatching sx fns at compile time.
sx code calling typed fn-pointers cast from C symbols → callconv(.c)
on the fn-pointer type:
- opengl.sx: 55 GL fn-ptr globals + load_gl's proc-loader param. GL
trampolines are macOS/iOS/Android system code.
- std/objc.sx: the two typed `objc_msgSend` casts.
- gpu/metal.sx: ~40 typed `objc_msgSend` casts across Metal command
encoder / device / pipeline construction.
The block invoke trampolines (objc_block.sx) call back INTO sx (the
closure trampoline). The typed fn-ptr there stays default-conv so
ctx prepends correctly. Compiler change: a callconv(.c) sx function
now binds `current_ctx_ref` to `&__sx_default_context` at entry (used
to be gated by `isExportedEntryName`). C-callable sx callbacks like
the block invokes don't get their own __sx_ctx param but their bodies
still need a real Context to forward to the closure they delegate to.
Tests: 152/152 example suite + chess green on all 3 platforms.
Screenshots at /tmp/sx-game-{macos,iossim,android}.png.
This commit is contained in:
@@ -25,39 +25,39 @@ GL_LINE :u32: 0x1B01;
|
||||
GL_FILL :u32: 0x1B02;
|
||||
|
||||
// Function pointer variables (mutable, loaded at runtime)
|
||||
glClearColor : (f32, f32, f32, f32) -> void = ---;
|
||||
glClear : (u32) -> void = ---;
|
||||
glEnable : (u32) -> void = ---;
|
||||
glDisable : (u32) -> void = ---;
|
||||
glViewport : (s32, s32, s32, s32) -> void = ---;
|
||||
glFlush : () -> void = ---;
|
||||
glDrawArrays : (u32, s32, s32) -> void = ---;
|
||||
glPolygonMode : (u32, u32) -> void = ---;
|
||||
glLineWidth : (f32) -> void = ---;
|
||||
glCreateShader : (u32) -> u32 = ---;
|
||||
glShaderSource : (u32, s32, *[:0]u8, *s32) -> void = ---;
|
||||
glCompileShader : (u32) -> void = ---;
|
||||
glGetShaderiv : (u32, u32, *s32) -> void = ---;
|
||||
glGetShaderInfoLog : (u32, s32, *s32, [*]u8) -> void = ---;
|
||||
glCreateProgram : () -> u32 = ---;
|
||||
glAttachShader : (u32, u32) -> void = ---;
|
||||
glLinkProgram : (u32) -> void = ---;
|
||||
glGetProgramiv : (u32, u32, *s32) -> void = ---;
|
||||
glGetProgramInfoLog : (u32, s32, *s32, [*]u8) -> void = ---;
|
||||
glUseProgram : (u32) -> void = ---;
|
||||
glDeleteShader : (u32) -> void = ---;
|
||||
glGenVertexArrays : (s32, *u32) -> void = ---;
|
||||
glGenBuffers : (s32, *u32) -> void = ---;
|
||||
glBindVertexArray : (u32) -> void = ---;
|
||||
glBindBuffer : (u32, u32) -> void = ---;
|
||||
glBufferData : (u32, isize, *void, u32) -> void = ---;
|
||||
glVertexAttribPointer : (u32, s32, u32, u8, s32, *void) -> void = ---;
|
||||
glEnableVertexAttribArray : (u32) -> void = ---;
|
||||
glGetUniformLocation : (u32, [*]u8) -> s32 = ---;
|
||||
glUniformMatrix4fv : (s32, s32, u8, [*]f32) -> void = ---;
|
||||
glUniform3f : (s32, f32, f32, f32) -> void = ---;
|
||||
glDepthFunc : (u32) -> void = ---;
|
||||
glUniform1f : (s32, f32) -> void = ---;
|
||||
glClearColor : (f32, f32, f32, f32) -> void callconv(.c) = ---;
|
||||
glClear : (u32) -> void callconv(.c) = ---;
|
||||
glEnable : (u32) -> void callconv(.c) = ---;
|
||||
glDisable : (u32) -> void callconv(.c) = ---;
|
||||
glViewport : (s32, s32, s32, s32) -> void callconv(.c) = ---;
|
||||
glFlush : () -> void callconv(.c) = ---;
|
||||
glDrawArrays : (u32, s32, s32) -> void callconv(.c) = ---;
|
||||
glPolygonMode : (u32, u32) -> void callconv(.c) = ---;
|
||||
glLineWidth : (f32) -> void callconv(.c) = ---;
|
||||
glCreateShader : (u32) -> u32 callconv(.c) = ---;
|
||||
glShaderSource : (u32, s32, *[:0]u8, *s32) -> void callconv(.c) = ---;
|
||||
glCompileShader : (u32) -> void callconv(.c) = ---;
|
||||
glGetShaderiv : (u32, u32, *s32) -> void callconv(.c) = ---;
|
||||
glGetShaderInfoLog : (u32, s32, *s32, [*]u8) -> void callconv(.c) = ---;
|
||||
glCreateProgram : () -> u32 callconv(.c) = ---;
|
||||
glAttachShader : (u32, u32) -> void callconv(.c) = ---;
|
||||
glLinkProgram : (u32) -> void callconv(.c) = ---;
|
||||
glGetProgramiv : (u32, u32, *s32) -> void callconv(.c) = ---;
|
||||
glGetProgramInfoLog : (u32, s32, *s32, [*]u8) -> void callconv(.c) = ---;
|
||||
glUseProgram : (u32) -> void callconv(.c) = ---;
|
||||
glDeleteShader : (u32) -> void callconv(.c) = ---;
|
||||
glGenVertexArrays : (s32, *u32) -> void callconv(.c) = ---;
|
||||
glGenBuffers : (s32, *u32) -> void callconv(.c) = ---;
|
||||
glBindVertexArray : (u32) -> void callconv(.c) = ---;
|
||||
glBindBuffer : (u32, u32) -> void callconv(.c) = ---;
|
||||
glBufferData : (u32, isize, *void, u32) -> void callconv(.c) = ---;
|
||||
glVertexAttribPointer : (u32, s32, u32, u8, s32, *void) -> void callconv(.c) = ---;
|
||||
glEnableVertexAttribArray : (u32) -> void callconv(.c) = ---;
|
||||
glGetUniformLocation : (u32, [*]u8) -> s32 callconv(.c) = ---;
|
||||
glUniformMatrix4fv : (s32, s32, u8, [*]f32) -> void callconv(.c) = ---;
|
||||
glUniform3f : (s32, f32, f32, f32) -> void callconv(.c) = ---;
|
||||
glDepthFunc : (u32) -> void callconv(.c) = ---;
|
||||
glUniform1f : (s32, f32) -> void callconv(.c) = ---;
|
||||
GL_LESS :u32: 0x0201;
|
||||
GL_LEQUAL :u32: 0x0203;
|
||||
GL_SCISSOR_TEST :u32: 0x0C11;
|
||||
@@ -76,27 +76,27 @@ GL_RED :u32: 0x1903;
|
||||
GL_R8 :u32: 0x8229;
|
||||
GL_UNPACK_ALIGNMENT :u32: 0x0CF5;
|
||||
|
||||
glScissor : (s32, s32, s32, s32) -> void = ---;
|
||||
glBufferSubData : (u32, isize, isize, *void) -> void = ---;
|
||||
glGenTextures : (s32, *u32) -> void = ---;
|
||||
glBindTexture : (u32, u32) -> void = ---;
|
||||
glTexImage2D : (u32, s32, s32, s32, s32, s32, u32, u32, *void) -> void = ---;
|
||||
glTexParameteri : (u32, u32, s32) -> void = ---;
|
||||
glBlendFunc : (u32, u32) -> void = ---;
|
||||
glReadPixels : (s32, s32, s32, s32, u32, u32, *void) -> void = ---;
|
||||
glActiveTexture : (u32) -> void = ---;
|
||||
glUniform1i : (s32, s32) -> void = ---;
|
||||
glPixelStorei : (u32, s32) -> void = ---;
|
||||
glTexSubImage2D : (u32, s32, s32, s32, s32, s32, u32, u32, *void) -> void = ---;
|
||||
glDeleteTextures : (s32, *u32) -> void = ---;
|
||||
glScissor : (s32, s32, s32, s32) -> void callconv(.c) = ---;
|
||||
glBufferSubData : (u32, isize, isize, *void) -> void callconv(.c) = ---;
|
||||
glGenTextures : (s32, *u32) -> void callconv(.c) = ---;
|
||||
glBindTexture : (u32, u32) -> void callconv(.c) = ---;
|
||||
glTexImage2D : (u32, s32, s32, s32, s32, s32, u32, u32, *void) -> void callconv(.c) = ---;
|
||||
glTexParameteri : (u32, u32, s32) -> void callconv(.c) = ---;
|
||||
glBlendFunc : (u32, u32) -> void callconv(.c) = ---;
|
||||
glReadPixels : (s32, s32, s32, s32, u32, u32, *void) -> void callconv(.c) = ---;
|
||||
glActiveTexture : (u32) -> void callconv(.c) = ---;
|
||||
glUniform1i : (s32, s32) -> void callconv(.c) = ---;
|
||||
glPixelStorei : (u32, s32) -> void callconv(.c) = ---;
|
||||
glTexSubImage2D : (u32, s32, s32, s32, s32, s32, u32, u32, *void) -> void callconv(.c) = ---;
|
||||
glDeleteTextures : (s32, *u32) -> void callconv(.c) = ---;
|
||||
|
||||
glGenFramebuffers : (s32, *u32) -> void = ---;
|
||||
glGenRenderbuffers : (s32, *u32) -> void = ---;
|
||||
glBindFramebuffer : (u32, u32) -> void = ---;
|
||||
glBindRenderbuffer : (u32, u32) -> void = ---;
|
||||
glFramebufferRenderbuffer : (u32, u32, u32, u32) -> void = ---;
|
||||
glGetRenderbufferParameteriv : (u32, u32, *s32) -> void = ---;
|
||||
glCheckFramebufferStatus : (u32) -> u32 = ---;
|
||||
glGenFramebuffers : (s32, *u32) -> void callconv(.c) = ---;
|
||||
glGenRenderbuffers : (s32, *u32) -> void callconv(.c) = ---;
|
||||
glBindFramebuffer : (u32, u32) -> void callconv(.c) = ---;
|
||||
glBindRenderbuffer : (u32, u32) -> void callconv(.c) = ---;
|
||||
glFramebufferRenderbuffer : (u32, u32, u32, u32) -> void callconv(.c) = ---;
|
||||
glGetRenderbufferParameteriv : (u32, u32, *s32) -> void callconv(.c) = ---;
|
||||
glCheckFramebufferStatus : (u32) -> u32 callconv(.c) = ---;
|
||||
|
||||
GL_TEXTURE_WRAP_S :u32: 0x2802;
|
||||
GL_TEXTURE_WRAP_T :u32: 0x2803;
|
||||
@@ -104,7 +104,7 @@ GL_CLAMP_TO_EDGE :u32: 0x812F;
|
||||
|
||||
// Loader: call once after creating GL context
|
||||
// Pass in a proc loader (e.g. SDL_GL_GetProcAddress)
|
||||
load_gl :: (get_proc: ([*]u8) -> *void) {
|
||||
load_gl :: (get_proc: ([*]u8) -> *void callconv(.c)) {
|
||||
glClearColor = xx get_proc("glClearColor");
|
||||
glClear = xx get_proc("glClear");
|
||||
glEnable = xx get_proc("glEnable");
|
||||
|
||||
Reference in New Issue
Block a user