issue-0028: ?Protocol = null sentinel-shaped optional protocols

Protocol structs registered via registerProtocolDecl carry a new
is_protocol flag; the ?T paths in sizeOf/typeSizeBytes/toLLVMType
recognise it and lay out ?Protocol as the protocol struct itself
(ctx == null IS the "none" state), matching how ?Closure / ?*T are
sentinel-shaped — no extra storage.

Method dispatch on ?Protocol auto-unwraps in lowerCall's field-access
path; the unwrap is structurally a no-op so we just rebind obj_ty to
the payload type. resolveCallParamTypes extended for optional-protocol
receivers so enum-literal args (gpu.create_texture(.r8, ...)) get the
right target_type and don't silently collapse to tag=0 : s32 — same
issue-0031-class bug closed in Session 66, one type-system layer
deeper.

Library: UIRenderer / UIPipeline / GlyphCache migrated from the verbose
gpu: GPU = ---; has_gpu: bool pattern to gpu: ?GPU = null. set_gpu no
longer maintains a parallel bool flag.

Bundled: dock.sx threads delta_time as a struct field rather than via
a global pointer (cleanup unrelated to issue-0028, committed alongside).

Verified: 85/85 regression tests pass; iOS-sim chess + macOS chess
both render correctly post-migration.
This commit is contained in:
agra
2026-05-18 18:32:55 +03:00
parent f9ecf9d00e
commit 79419b99bd
11 changed files with 117 additions and 93 deletions

View File

@@ -32,11 +32,10 @@ UIRenderer :: struct {
current_texture: u32;
draw_calls: s64;
// GPU protocol backend. When `has_gpu`, the renderer routes shader /
// buffer / texture / draw calls through `gpu` instead of raw GL. The
// chess game sets this on iOS to a boxed `*MetalGPU`.
gpu: GPU = ---;
has_gpu: bool = false;
// GPU protocol backend. When set, the renderer routes shader / buffer /
// texture / draw calls through `gpu` instead of raw GL. The chess game
// sets this on iOS to a boxed `*MetalGPU`.
gpu: ?GPU = null;
mtl_shader: ShaderHandle = 0;
mtl_vbuf: BufferHandle = 0;
// Per-frame byte offset into the Metal vertex buffer. Each flush writes
@@ -56,7 +55,7 @@ UIRenderer :: struct {
self.vertex_count = 0;
self.dpi_scale = 1.0;
if self.has_gpu {
if self.gpu != null {
// ── Metal backend (via GPU protocol) ───────────────────────
// Oversize the GPU buffer enough to hold many sub-batches per
// frame without wrapping. With per-flush offset advance, each
@@ -115,7 +114,7 @@ UIRenderer :: struct {
proj := Mat4.ortho(0.0, width, height, 0.0, -1.0, 1.0);
if self.has_gpu {
if self.gpu != null {
// Reset the per-frame ring offset; this frame's flushes start at 0.
self.mtl_buf_offset = 0;
// Pipeline state + vertex buffer + projection + initial texture.
@@ -251,7 +250,7 @@ UIRenderer :: struct {
case .clip_push: {
self.flush();
dpi := self.dpi_scale;
if self.has_gpu {
if self.gpu != null {
// Metal: pixel coords, top-left origin (no Y flip).
self.gpu.set_scissor(
xx (node.frame.origin.x * dpi),
@@ -272,7 +271,7 @@ UIRenderer :: struct {
}
case .clip_pop: {
self.flush();
if self.has_gpu {
if self.gpu != null {
self.gpu.disable_scissor();
} else {
glDisable(GL_SCISSOR_TEST);
@@ -290,7 +289,7 @@ UIRenderer :: struct {
upload_size : s64 = self.vertex_count * UI_VERTEX_BYTES;
if self.has_gpu {
if self.gpu != null {
// Mirror the GL path: bind current texture before drawing.
// current_texture may have changed since the last flush.
self.gpu.set_texture(0, self.current_texture);