Step 3b code is wired across UIRenderer + GlyphCache + UIPipeline +
chess game (gpu_mode = .metal on iOS, MetalGPU bound via the GPU
protocol). macOS GL chess, iOS-sim GLES chess, and iOS-sim Metal
triangle (63-metal-clear.sx) all still render.
iOS-sim Metal chess crashes inside replaceRegion uploading the 1MB
font atlas. Bisecting that crash exposed several sx-language issues
where mid-bisect tracers (NSLog inside if/else branch bodies) didn't
produce output, blocking further investigation.
Filing each finding as examples/issue-NNNN.sx rather than working
around piecemeal:
Bugs:
- 0024 NSLog/foreign-call inside if/else body not producing output
- 0025 C-ABI param coercion incomplete for composites >16B
(combined direct-call abiCoerceParamType TODO + call_indirect
path that doesn't apply C-ABI coercion at all)
- 0026 replaceRegion 1MB upload crash (likely downstream of 0025)
Features needed for step 4 + cleanup:
- 0027 Obj-C block bridge (^{...}) for animateWithDuration:
- 0028 Optional protocol box (?GPU = null) replaces T = ---; has_T: bool
- 0029 destroy_texture/buffer/shader on GPU protocol
- 0030 extern cross-file globals
Library-side: renderer.sx + glyph_cache.sx + pipeline.sx gain a
`gpu: GPU = ---; has_gpu: bool` field pair + branches that route every
GL touchpoint through the protocol when has_gpu. glyph_cache.init
saves/restores those fields around its memset. pipeline.set_gpu()
propagates to renderer + font. Renderer's MSL shader source added as
UI_MSL_SRC using packed_float2/packed_float4 to keep the 12-float
interleaved vertex layout tight (48 bytes).
metal.sx: dual-phase init (init(null, 0, 0) for eager device+queue,
re-init with the layer once UIKit installs the SxMetalView).
setStorageMode:.shared on every texture descriptor to ensure CPU-
writable atlas pixels on Apple Silicon iOS-sim.
Regression suite: 68 passing, 0 failed. WASM chess build currently
broken under step 3b state (silent compiler crash); documented in
CHECKPOINT.md, likely fallout from one of the filed issues (probably
0028 — the verbose protocol-box pattern). Step 3b resumes after
0024-0030 land.
48 lines
2.6 KiB
Plaintext
48 lines
2.6 KiB
Plaintext
// issue-0029: Feature — add explicit destructors to the GPU protocol so
|
|
// resources can be freed without leaking.
|
|
//
|
|
// ── Proposed additions to library/modules/gpu/api.sx ──────────────────────
|
|
//
|
|
// destroy_shader :: (h: ShaderHandle);
|
|
// destroy_buffer :: (h: BufferHandle);
|
|
// destroy_texture :: (h: TextureHandle);
|
|
//
|
|
// ── Why ────────────────────────────────────────────────────────────────────
|
|
//
|
|
// Today, library/modules/ui/glyph_cache.sx's `grow()` method recreates
|
|
// the atlas texture at a larger size but has no way to release the old
|
|
// one — see the comment in metal.sx that explicitly notes the leak. The
|
|
// GL path uses glDeleteTextures(1, @self.texture_id); the GPU protocol
|
|
// has no equivalent yet.
|
|
//
|
|
// ── Implementation notes ──────────────────────────────────────────────────
|
|
//
|
|
// Metal backend: send `release` to the MTLTexture / MTLBuffer /
|
|
// MTLRenderPipelineState (or call CFRelease, since these are
|
|
// CFTypeRef-compatible). Clear the corresponding slot in
|
|
// MetalGPU.textures / buffers / shaders to `null` / 0.
|
|
//
|
|
// GL backend (future): glDeleteTextures / glDeleteBuffers / glDeleteProgram.
|
|
//
|
|
// Handle lifecycle: after destroy, the slot in the backend List is freed.
|
|
// New allocations can take that slot or grow the list. Caller's handles
|
|
// remain valid until destroy. Don't aggressively re-use slots in MVP;
|
|
// keep handles append-only with a `null` marker for destroyed entries
|
|
// (matches the current shape).
|
|
//
|
|
// ── Touch points ──────────────────────────────────────────────────────────
|
|
//
|
|
// library/modules/gpu/api.sx — add 3 protocol method signatures
|
|
// library/modules/gpu/metal.sx — implement them (release + null
|
|
// the slot)
|
|
// library/modules/ui/glyph_cache.sx — call destroy_texture(old_handle)
|
|
// in grow() before creating the
|
|
// new atlas
|
|
//
|
|
// ── Syntax constraint ─────────────────────────────────────────────────────
|
|
//
|
|
// None — straight protocol-method addition.
|
|
|
|
#import "modules/std.sx";
|
|
main :: () -> s32 { 0; }
|