Two paint-encoder bugs and two demo-plumbing bugs together
prevented end-to-end rendering. With all four fixed, BungeeTint
and similar COLRv0 fonts now render through the GL demo in their
proper palette colors.
### Paint encoder
1. hb-gpu-paint-fragment.glsl: the LAYER_SOLID op's payload is a
blob-relative texel offset, but the shader was passing it to
hb_gpu_draw() as-is -- which treats its argument as an absolute
atlas offset. Add the glyph's `base` to the payload before the
draw-coverage call so the sub-blob reference resolves inside
the paint blob instead of elsewhere in the atlas.
2. hb-gpu-paint.cc push_clip_glyph callback: was resetting
pending_palette_index to 0. But harfbuzz's COLRv0 paint
emitter calls custom_palette_color BEFORE push_clip_glyph for
each layer, so the index set by custom_palette_color was being
clobbered before the color callback consumed it -- every layer
ended up tagged palette_index=0. Leave pending_palette_index
alone in push_clip_glyph.
### Demo plumbing
3. util/gpu/demo-glstate.cc: demo_glstate_create now glUseProgram's
its program immediately. The palette uniform upload reads
GL_CURRENT_PROGRAM, and glyph upload happens from
demo_buffer_current_line() -- which runs before
demo_view_setup() would have bound the program. Without this,
glGetIntegerv returned 0 and the palette was never uploaded.
4. util/gpu/demo-font.cc: adds lazy demo_font_upload_palette() on
first glyph request. Also tries both "hb_gpu_palette" and
"hb_gpu_palette[0]" for the uniform lookup since drivers
disagree.
### Bonus
util/hb-gpu-encode-all.cc: reports paint-encoded and draw-fallback
counts / sizes / timings separately so you can tell where time
goes in mixed-content fonts.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
util/hb-gpu-encode-all.cc now exercises the paint encoder instead
of the draw encoder directly. Every glyph is routed through
hb_gpu_paint_glyph + hb_gpu_paint_encode; on NULL result (v1
features not yet handled, or fully empty paint tree) it falls
back to hb_gpu_draw_glyph + hb_gpu_draw_encode. Reports paint
encoded count separately from draw-fallback count.
hb_gpu_paint.cc: the color callback now checks the
hb_gpu_draw_glyph return value and skips the layer when the
clip-glyph has no outline, so fallback-synthesized LAYER_SOLIDs
for glyphs like U+0020 don't produce a 1-op blob that the shader
would sample as zero coverage anyway.
Sample run on BungeeTint-Regular.ttf (COLRv0, 2 layers/glyph):
glyphs: 2126
paint: 2126 (all routed through paint)
empty: 0
total: 8347.27 KiB
avg: 3.93 KiB/glyph
max: 10.84 KiB (gid 1005)
paint: 13.10ms (6.2us/glyph)
encode: 0.27ms (0.1us/glyph)
wall: 13.53ms (157185 glyphs/s)
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Bring hb_gpu_draw_encode into line with the rest of the render APIs:
auto-clear on success, and return the computed glyph extents to the
caller via a new out-parameter (nullable).
HB_EXTERN hb_blob_t *
hb_gpu_draw_encode (hb_gpu_draw_t *draw,
hb_glyph_extents_t *extents);
Consumers typically need both the encoded blob and the glyph's
extents to size the quad they'll draw into in the vertex shader;
returning them together removes a redundant trip through the draw
state and lets encode() auto-clear like hb_vector_*_render() and
hb_raster_*_render() do.
Drop hb_gpu_draw_get_extents() from the public API — its only
role was reading extents out of the draw state post-encode, which
the new encode() signature makes redundant. The computation
stays (moved to a static _hb_gpu_draw_get_extents helper) so
encode() can call it before auto-clear wipes the state.
ABI break for anyone who had already wired up against the 14.0.0
hb_gpu_draw_encode signature or hb_gpu_draw_get_extents, but the
library is new/experimental and the two in-tree consumers
(test/api/test-gpu.cc, util/gpu/demo-font.cc, util/hb-gpu-encode-all.cc,
test/fuzzing/hb-gpu-fuzzer.cc) are updated here.
All 240 tests pass.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Useful for profiling — run the encode loop multiple times
and report averaged timing.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Report outline, encode, and wall time with per-glyph rates.
Also restore max blob size reporting.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
recycle_blob stores the blob; encode reuses both the blob object
and its data buffer when the buffer is >= needed and < 2x needed.
Otherwise malloc fresh and replace_buffer on the recycled blob.
hb_blob_t::replace_buffer now skips destroy_user_data when the
new data pointer is the same as the old one (same-buffer reuse).
Add explicit destructor to hb_gpu_draw_t for recycled_blob cleanup.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Encodes all glyphs in a font, reports failures and summary
statistics (encoded/empty/failed counts, total and average sizes).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>