ui: text shader uses raw atlas coverage (no SDF smoothstep)

Two small cleanups in the Metal text path on top of the buffer-offset
fix from cc71d95:

- Drop the SDF-style `smoothstep(0.5 ± ew, alpha)` from the text mode
  branch in UI_MSL_SRC. The glyph atlas stores alpha coverage straight
  from stbtt_MakeGlyphBitmap, not signed distance, so the smoothstep
  was thinning anti-aliased strokes by mapping mid-coverage values
  (0.3–0.7) toward 0/1. Use the sampled value directly as alpha.

- Drop the 16-byte alignment pad on `mtl_buf_offset` in `flush()`. Each
  batch's upload_size is already a multiple of UI_VERTEX_BYTES (48), so
  the running offset stays vertex-aligned without the extra rounding.

- After `font.shape_text` + `font.flush` in `render_text`, re-bind
  `font.texture_id`. If the atlas grew during shaping, the GPU texture
  handle changed; without this rebind the next flush samples the old
  (smaller) atlas which doesn't have the newly-rasterized glyphs.

- Use explicit s64-pointer arithmetic in `metal_update_buffer_at_ios`
  so a future regression in `[*]u8` indexing can't quietly miscompile
  the per-flush write offset.

Text at small sizes still renders dim on dark backgrounds — most glyph
pixels sit in 0.1–0.5 coverage and the linear blend doesn't push them
to bright values — tracked separately as the faint-text follow-up.
This commit is contained in:
agra
2026-05-18 10:26:31 +03:00
parent cc71d9591d
commit b43472e6ab
2 changed files with 29 additions and 12 deletions

View File

@@ -462,8 +462,12 @@ metal_update_buffer_at_ios :: (self: *MetalGPU, handle: u32, data: *void, size_b
msg_o : (*void, *void) -> *void = xx objc_msgSend;
base := msg_o(buf, sel_registerName("contents".ptr));
if base == null { return; }
dst : [*]u8 = xx base;
memcpy(xx @dst[byte_offset], data, size_bytes);
// Add byte_offset via integer arithmetic — `@dst[i]` on `[*]u8`
// already does this, but we keep this form explicit so a future
// pointer-arithmetic regression here can't hide.
base_i : s64 = xx base;
dst_at : *void = xx (base_i + byte_offset);
memcpy(dst_at, data, size_bytes);
}
metal_lookup_buffer :: (self: *MetalGPU, handle: u32) -> *void {