metal: pause step 3b pending sx-side fixes (filed 0024-0030)
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.
This commit is contained in:
50
examples/issue-0027.sx
Normal file
50
examples/issue-0027.sx
Normal file
@@ -0,0 +1,50 @@
|
||||
// issue-0027: Feature — support Obj-C blocks (^{...}) so sx code can call
|
||||
// APIs that take a block parameter. Required for step 4 of the Metal port
|
||||
// (keyboard lockstep via `[UIView animateWithDuration:animations:^{...}]`),
|
||||
// and broadly useful for any UIKit/AppKit API.
|
||||
//
|
||||
// ── Proposed surface ──────────────────────────────────────────────────────
|
||||
//
|
||||
// Option A — comptime intrinsic that wraps a sx closure as a block:
|
||||
//
|
||||
// block := objc_block(@my_closure); // returns *void (an id<Block>)
|
||||
// msg_block(view, sel, 0.3, block); // pass like any id arg
|
||||
//
|
||||
// Internals: emit a Block_literal struct constant with the right invoke
|
||||
// fn pointer, isa, flags, descriptor pointer. Approximately what clang
|
||||
// generates for ^{...}.
|
||||
//
|
||||
// Option B — surface-level syntax `^{ ... }` that lowers to Option A
|
||||
// automatically. Cleaner for users; more parser work.
|
||||
//
|
||||
// Recommended: start with Option A (intrinsic). Migrate to Option B once
|
||||
// the codegen path is proven.
|
||||
//
|
||||
// ── Implementation sketch ────────────────────────────────────────────────
|
||||
//
|
||||
// 1. New `library/modules/std/objc_block.sx` defining the Block_literal
|
||||
// struct that mirrors clang's layout (isa, flags, reserved, invoke fn
|
||||
// pointer, descriptor pointer).
|
||||
// 2. `objc_block(fn_or_closure) -> *void` intrinsic that builds the
|
||||
// literal at the call site. Initial implementation can be a
|
||||
// stack-allocated block (_NSConcreteStackBlock); upgrade to
|
||||
// heap-promoted (_Block_copy) once block lifetime exceeds the call.
|
||||
// 3. Link libSystem's symbols `_NSConcreteStackBlock` and
|
||||
// `_NSConcreteGlobalBlock` (auto on iOS; may need `#library "System"`
|
||||
// on macOS).
|
||||
// 4. (Deferred) surface syntax `^{ ... }` — parser hook + lowering
|
||||
// to the intrinsic. Must not clash with bitwise XOR `^`.
|
||||
//
|
||||
// ── References ────────────────────────────────────────────────────────────
|
||||
//
|
||||
// - Apple block ABI spec (clang's "Block Implementation Specification")
|
||||
// - _NSConcreteStackBlock + _NSConcreteGlobalBlock from libSystem
|
||||
//
|
||||
// ── Real-world impact ─────────────────────────────────────────────────────
|
||||
//
|
||||
// Without this, the keyboard inset cannot be animated in lockstep with the
|
||||
// keyboard slide. See library/modules/platform/uikit.sx's
|
||||
// uikit_keyboard_will_change_frame comments for the deferred lockstep work.
|
||||
|
||||
#import "modules/std.sx";
|
||||
main :: () -> s32 { 0; }
|
||||
Reference in New Issue
Block a user