Phase 8 step 3a of the Metal renderer port:
- New library/modules/gpu/ with types.sx (handles + ClearColor +
TextureFormat enum), api.sx (GPU :: protocol { ... } covering the
lifecycle / per-frame / resource / per-draw surface), and metal.sx
(MetalGPU backend implementing the protocol against CAMetalLayer).
Resource handles are 1-based indices into backend List(*void) tables.
MTL aggregates >16 bytes (MTLRegion, MTLScissorRect) pass via *T to
match arm64 Apple's indirect-by-reference ABI; MTLClearColor + CGSize
go through the HFA path as direct fn-pointer casts on objc_msgSend.
- UIKitPlatform got a gpu_mode: GpuMode toggle + sibling SxMetalView
class registration. In metal mode init skips EAGL context, the
did_finish_launching IMP skips the EAGL drawable-properties dict,
layoutSubviews reads the layer's bounds * dpi_scale into pixel_w/h
instead of allocating a GL renderbuffer, and end_frame is a no-op
(the MetalGPU owns its own present).
- examples/63-metal-clear.sx verifies the pipeline end-to-end on iOS
sim — compiles a pass-through MSL shader (packed_float2/packed_float4
to avoid alignment padding), uploads 3 vertices, draws a colored
triangle on a dark-blue clear.
Compiler fixes (filed-and-fixed in this branch):
- inline if X { return E; } followed by a fall-through final expression
no longer emits two terminators into the same basic block. Verified
by examples/83-inline-if-return-fallthrough.sx.
- Top-level type alias Name :: u32; now resolves correctly as the type
annotation on a global variable (was treated as ptr {}, breaking
comparisons + initializers). Verified by examples/84-global-type-alias.sx.
Issue->feature promotion:
- 16 historical examples/issue-NNNN.sx repros now confirmed-fixed and
renamed to focused feature names (67-82). Each gains a
tests/expected/*.txt + .exit pair so the regression suite covers them.
- 5 stale issue repros deleted (subsumed by broader tests).
Regression suite: 68 passing, 0 failed. macOS chess builds + runs; wasm
chess builds; iOS sim GLES chess still renders the full board; iOS sim
Metal demo renders the triangle.
43 lines
1.2 KiB
Plaintext
43 lines
1.2 KiB
Plaintext
// `xx` cast inside an RHS expression assigned to a struct field takes its
|
|
// target type from the field, not from the enclosing function's return type.
|
|
// Covers if-then-else RHS and binary-op RHS variants.
|
|
|
|
#import "modules/std.sx";
|
|
|
|
Foo :: struct {
|
|
pixel_w: s32;
|
|
dpi: f32;
|
|
last_perf: s64;
|
|
delta_time: f32;
|
|
}
|
|
FC :: struct { a: f32; b: f32; c: s32; d: s32; e: f32; f: f32; }
|
|
|
|
// If-then-else RHS in a function whose return type is not f32.
|
|
calc_bool :: (self: *Foo, wf: f32) -> bool {
|
|
self.dpi = if wf > 0.0 then xx self.pixel_w / wf else 1.0;
|
|
true;
|
|
}
|
|
|
|
// Binary-op RHS in a struct-returning function. The xx casts must target f32,
|
|
// not the FC return-struct shape.
|
|
begin :: (self: *Foo, current: s64, freq: s64) -> FC {
|
|
if self.last_perf > 0 {
|
|
self.delta_time = xx (current - self.last_perf) / xx freq;
|
|
}
|
|
FC.{ a = 1.0, b = 2.0, c = 3, d = 4, e = 5.0, f = 6.0 };
|
|
}
|
|
|
|
main :: () -> void {
|
|
f : *Foo = xx malloc(size_of(Foo));
|
|
f.pixel_w = 2880;
|
|
f.dpi = 0.0;
|
|
f.last_perf = 1000;
|
|
f.delta_time = 0.0;
|
|
|
|
_ := calc_bool(f, 1440.0);
|
|
print("dpi={}\n", f.dpi);
|
|
|
|
fc := begin(f, 1500, 1000);
|
|
print("delta={} fc.a={}\n", f.delta_time, fc.a);
|
|
}
|