Commit Graph
21052 Commits
Author SHA1 Message Date
Behdad Esfahbod 5ce5be6bd2 [gpu] hb_gpu_paint: encode radial gradients as LAYER_GRADIENT
Same shape as linear: emit LAYER_GRADIENT with subtype=1 and a
gradient-params sub-blob.  Radial just uses two param texels
(c0:x,y,r0 and c1:x,y,r1) before the stops instead of one.

Shader side: add _hb_gpu_sample_radial in all four languages.
Solves the COLRv1 two-circle radial quadratic
|P - C0 - t*(C1-C0)|^2 = (r0 + t*(r1-r0))^2 for t, picking the
larger root when the interpolated radius stays non-negative,
falling through to the smaller root otherwise, and degenerating to
a linear solve when the quadratic coefficient is near zero.  Same
matching of hb_raster_paint's radial formulation.

Also extracted the color-stop walk (formerly inlined in
_hb_gpu_sample_linear) into _hb_gpu_eval_stops so both subtypes
share it; the per-subtype stops_base differs by one texel.

Sweep still uses the first-stop solid placeholder.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 20:52:56 -06:00
Behdad Esfahbod 6cf5e1a858 [gpu] hb_gpu_paint: encode linear gradients as LAYER_GRADIENT
The linear_gradient callback now emits a real LAYER_GRADIENT op
instead of falling back to a flat first-stop solid.  Per-layer op
layout:

  texel 0: (op_type=1, subtype=0, clip_payload_hi, clip_payload_lo)
  texel 1: (grad_payload_hi, grad_payload_lo, extend_mode, stop_count)

Both payloads are sub_blob indices that hb_gpu_paint_encode()
patches to absolute atlas offsets.  The clip payload is the
existing Slug draw blob for the layer's clip glyph; the gradient
payload is a fresh sub-blob laid out as:

  texel 0 : (lx0, ly0, lx1, ly1)  -- 2-point axis in font units,
            reduced from COLRv1's 3-point anchors the same way
            hb_raster_paint's reduce_anchors does it
  texels 1..N : color stops, 2 texels each
    texel a: (offset_q15, flags, _, _)  flags bit 0 = is_foreground
    texel b: (r_q15, g_q15, b_q15, a_q15)

All four paint fragment shaders (GLSL/MSL/HLSL/WGSL) grew a
_hb_gpu_sample_linear helper that projects the fragment onto the
axis, applies the COLRv1 extend mode, and walks stops to find the
enclosing segment.

Refactored the existing LAYER_SOLID emission body into
emit_clip_sub_blob + hb_gpu_paint_emit_solid so the gradient path
can share the clip-outline encode and extents accumulation.  The
LAYER_GRADIENT encode-time patching walks both payload slots.

Radial and sweep callbacks still fall back to the first-stop solid
placeholder; they'll be replaced next.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 19:31:04 -06:00
Behdad Esfahbod 62a8a3a26c [util/gpu] Drop sRGB framebuffer mode; always gamma 2.2
The paint encoder bakes sRGB-encoded font palette values directly
(quantizing 0..255 to 0..32767 without decoding), so the shader
writes sRGB-ish values.  With GL_FRAMEBUFFER_SRGB enabled the
driver then applied linear->sRGB encoding on store, giving a
double-encoded, washed-out result -- most visible on mid-tone
gradients.

The cleanest fix is to stop pretending we're doing linear-space
compositing: drop the sRGB framebuffer mode entirely and always
apply the classic 2.2 gamma exponent for coverage correction
(flipped to 1/2.2 in dark mode to match the existing light/dark
logic).  Removed pieces:

 - demo_view_t::gamma_mode enum, demo_view_set_gamma_mode,
   demo_view_cycle_gamma, and the `g` keybinding + help line
 - demo_renderer_t::set_srgb virtual + every backend override
 - GLFW_SRGB_CAPABLE hint in gpu-output.hh
 - Metal swapchain MTLPixelFormatBGRA8Unorm_sRGB -> BGRA8Unorm

Replaced with demo_view_update_gamma, called on setup() and after
the dark-mode toggle.  Shader side stays the same (only alpha gets
the gamma curve, as before).

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 19:30:45 -06:00
Behdad Esfahbod 1fbbb0a627 [gpu] hb_gpu_paint: emit LAYER_SOLID from gradients using first stop
Register linear/radial/sweep gradient callbacks that read just the
first color stop from the color line and emit a LAYER_SOLID op with
that stop's color.  Previously these callbacks were unregistered,
so every gradient-filled layer silently produced no op -- Noto
COLRv1 emoji lost their face/body fills entirely.

Factor the LAYER_SOLID emission body out of hb_gpu_paint_color
into hb_gpu_paint_emit_solid so the color and gradient callbacks
share it.  Reading one stop (count=1) drives the usual
custom_palette_color / foreground resolution path exactly once,
so palette overrides and is_foreground still apply.

This is a placeholder until real gradient ops land; it just makes
gradient-heavy fonts render with sensible flat colors instead of
missing layers.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 18:48:23 -06:00
Behdad Esfahbod 087fd84a49 [util/gpu] Drop renderer palette plumbing, forward to hb_gpu_paint
Colors are now baked into encoded blobs (see prior commit), so
nothing needs to upload or bind a palette buffer.  Remove
demo_renderer_t::set_palette from all backends (GL, Metal, D3D11,
WebGPU), the hb_gpu_palette GL uniform plumbing in demo-glstate,
the Metal/D3D11 palette buffers, and the WebGPU storage buffer +
bind-group entry.  demo_font_get_palette is also gone.

Replace with new demo_font accessors that forward to the encoder:

  demo_font_set_palette
  demo_font_set_foreground
  demo_font_clear_custom_palette_colors
  demo_font_set_custom_palette_color

Each invalidates the glyph cache because colors are baked into
the atlas entries.  gpu-output.hh now forwards view-option
--font-palette / --custom-palette through these.

Web demos stop allocating / uploading the palette buffer; the
WGSL fragment shader drops its third bind-group slot.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 18:45:12 -06:00
Behdad Esfahbod e66500fd8e [gpu] hb_gpu_paint: bake resolved color into blob, drop palette binding
Add a raster-style configuration surface to hb_gpu_paint_t:

  hb_gpu_paint_set_foreground / hb_gpu_paint_get_foreground
  hb_gpu_paint_set_palette    / hb_gpu_paint_get_palette
  hb_gpu_paint_clear_custom_palette_colors
  hb_gpu_paint_set_custom_palette_color

hb_gpu_paint_glyph now passes paint->palette and paint->foreground
through to hb_font_paint_glyph, and the custom-palette-color
callback consults the user's overrides map (same pattern as
hb_raster_paint_t) before letting harfbuzz fall back to the font's
own palette.

With that in place, the color() callback can bake the already-
resolved RGBA into the encoded op directly, quantized as signed
Q15 in the existing second texel, instead of recording a palette
index and trusting the shader to look it up.  The is_foreground
flag stays in the op so a runtime foreground-color change (e.g.
dark-mode toggle) still works without re-encoding.

Shader side: drop the hb_gpu_palette uniform/storage binding and
its HB_GPU_PALETTE_SIZE knob from all four paint-fragment shaders
(GLSL / MSL / WGSL / HLSL); read the per-layer color straight out
of the blob texel.  This removes a per-backend binding slot and
the 256-entry uniform-array size ceiling that blocked fonts like
Noto-COLRv1 (~6200 entries).

Trade-off: changing the palette selection or overrides invalidates
previously encoded blobs and requires re-encoding.  In practice
palette switches are rare, and the rendering hot path gets
simpler.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 18:44:58 -06:00
Behdad Esfahbod 585154aa10 [util/gpu] Web demos: fix URL-param handling for ?font= and ?text=
rebuild_buffer did free(current_text); strdup(text); but was often
called with text == current_text (from web_load_font's
"custom_text ? current_text : default").  Strdup of freed memory
shaped garbage and made multi-char strings look like 1 char.  Fix:
strdup first, then free.

The WebGL rebuild_buffer also called demo_view_display itself,
which runs fine from a main loop tick but not from a fetch
promise's microtask (the canvas back-buffer doesn't swap).  Drop
it: demo_view_reset sets needs_redraw=true, and the next
main_loop_iter renders inside a proper rAF tick.

Emscripten allocates argv on the JS stack, which is unwound when
main returns.  WebGPU's init is async and reads arg_text/arg_font
after main returns, so those pointers were dangling -- early null
bytes in freed stack memory made the emoji URL shape to 1 glyph.
strdup them in main so they survive.

Finally, forward ?font= to argv as --font= (already done for
?text=) so the C side's "skip initial default-font glyph upload
when a font fetch is pending" path actually triggers.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 18:12:47 -06:00
Behdad Esfahbod 736d59bf72 [util/gpu] demo-font: tolerate NULL paint encode
hb_gpu_paint_encode returns NULL when the glyph uses unsupported
paint features (e.g. COLRv1 gradients/transforms) or emits zero
ops.  Treat that as an empty glyph instead of die()-ing the whole
app, so fonts mixing supported and unsupported paint still render
their supported parts.

Zero-init hb_ext so the empty-glyph extents are well-defined, and
skip recycle_blob when blob is NULL.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 18:12:23 -06:00
Behdad Esfahbod b616298d73 [util/gpu] Web demos: skip default-font upload when ?font= pending; preserve URL on backend switch; reflect custom text in URL
Three small UX improvements to the web demos.

### Skip default-font upload when ?font= is pending

When ?font= is set, the async fetch replaces the font later.  main
was still populating the atlas with the default font's glyphs for
the initial text, just to throw them away when _web_load_font ran
its own rebuild_buffer.  Gate demo_buffer_add_text() on !arg_font
so the buffer stays empty until the real font lands.

### WebGPU ready signal

WebGPU's init_demo is async (awaits adapter/device), so
onRuntimeInitialized fires before the demo is usable; calling
_web_load_font from the ?font= fetch at that point tripped a wasm
indirect-call signature mismatch.  init_demo now EM_ASMs a
window._webDemoReady() hook at its tail; the shell installs
_webDemoReady = startFontFetch when running the WebGPU build and
starts the fetch immediately for WebGL.

### URL ergonomics

* Backend-selector change now carries location.search across the
  navigation -- ?text= and ?font= survive the WebGL <-> WebGPU
  switch.
* The text-edit modal's Apply button updates history.replaceState
  with a ?text= param so the typed text is copy/pasteable.  Skips
  the update when the text is unchanged from what was open.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 17:10:31 -06:00
Behdad Esfahbod c85b453e90 [util/gpu] Web demos: URL ?text= and ?font=; wider default font
Two user-visible features plus a font swap.

### URL parameters

Forwards ?text= and ?font= from the query string into the C main
as --text=... and --font=... via Module.arguments, so the initial
text is applied before the first rendered frame (no flash of
default demo text).  ?font= is still fetched asynchronously on
the JS side; once loaded, the text is re-applied to the new font.

If neither parameter is present, behaviour is unchanged: the
baked-in default text renders in the baked-in default font.

Data URLs (?font=data:font/ttf;base64,...) work naturally via
fetch().  Remote URLs need CORS; raw.githubusercontent.com and
jsdelivr both work, github.com/.../raw/... does not.

### Wider default font

The baked-in default-font.hh was a narrow subset that didn't
include uppercase Latin, so `?text=Hello` shaped to .notdef for
H and W.  Re-subset Parastoo-Regular.ttf via hb-subset with:

    --unicodes='U+0020-007E,U+0600-06FF,U+FB50-FDFF,U+FE70-FEFF'

covering printable ASCII plus the Arabic block and the two
Arabic presentation-forms blocks.

Font size:
    source Parastoo-Regular.ttf     109152
    new subset                       49940

Wasm size impact (webgl build, Oz+lto):
    before  443628  181597 gz
    after   466657  196209 gz
    delta   +23029  +14612 gz

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 17:03:53 -06:00
Behdad Esfahbod 44a0fb1cd5 [util/gpu] Respect view-options: foreground, background, palette, custom-palette
Wires view_options_t into gpu_output_t so hb-gpu picks up the
same foreground/background/palette flags the rest of the tools
use:

  --foreground=#RRGGBB[AA]
  --background=#RRGGBB[AA]
  --font-palette=N
  --custom-palette=N=#RRGGBB[,N=#RRGGBB,...]

After demo_view_setup() the gpu main loop now:

1. Fetches the active palette from the face via
   demo_font_get_palette(font, view.palette, ...) -- palette index
   out of range falls back to 0.
2. Overlays each view.custom_palette_entries entry on top of that
   palette (clamped to 256 entries).
3. Uploads via renderer->set_palette().  Web demos and the
   headless WebGPU path do the same, with palette_index=0 (they
   don't yet plumb --font-palette).
4. Calls renderer->set_foreground / _background from the
   post-parsed view-options colours.  Defaults match the demo's
   prior LIGHT mode, so no-op when the user passes no flags; the
   dark-mode toggle (b key) still mutates renderer state
   independently.

Other view-options flags (--rainbow, --stroke, --line-space,
--margin, --logical/--ink, --show-extents, --font-extents)
appear in --help-view for familiarity but currently no-op in
hb-gpu; they're inherited wholesale from view_options_t and the
gpu path just doesn't wire them.

demo_font_get_palette() now takes a palette_index parameter so
callers can ask for non-zero palettes (e.g. dark-mode palettes in
fonts that ship them).  Web demos pass 0 for now.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 16:28:09 -06:00
Behdad Esfahbod cf3d69bc54 [util/gpu] Cross-backend palette upload via demo_renderer_t::set_palette
Reorganises the palette-upload plumbing so every backend handles
it uniformly and the hacky atlas-backend palette callback goes
away.

Before: demo_font_upload_palette in demo-font.cc mixed a GL
glUniform4fv direct call with a detour through an extra
demo_atlas_backend_t.upload_palette callback used by the Metal
renderer.  demo-font and demo-atlas both knew about palettes.

After:

* demo_font_get_palette (font, out, capacity) just reports the
  active palette as RGBA floats; demo-font no longer touches GL
  state or the atlas for palettes.

* demo_renderer_t gains a virtual set_palette (rgba, count).
  Default is a no-op.  Backends override:
   - demo-renderer-gl.cc -> demo_glstate_set_palette() ->
     glUniform4fv.
   - demo-metal.mm -> memcpy into the MTLBuffer's contents.
   - demo-renderer-d3d11.cc -> ID3D11DeviceContext::UpdateSubresource
     (palette buffer switched from IMMUTABLE to DEFAULT).
   - hb-gpu-web-webgpu.cc -> wgpuQueueWriteBuffer on the palette
     storage buffer.

* Callers invoke renderer->set_palette (palette, n) right after
  demo_font_create:
   - util/gpu-output.hh (desktop demo: GL / Metal / D3D11).
   - util/gpu/web/hb-gpu-web.cc (WebGL).
   - util/gpu/web/hb-gpu-web-webgpu.cc (WebGPU).

* The extra upload_palette field on demo_atlas_backend_t is
  removed along with demo_atlas_upload_palette / _is_external --
  atlas is back to being about glyph data only.

COLRv0 rendering now works with proper palette colours through
every backend that implements set_palette (WebGL, WebGPU, and
Metal/D3D11 once tested).

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 16:19:13 -06:00
Behdad Esfahbod 9aec34108b [gpu] Fix Metal segfault: route palette upload through atlas backend
The Metal path creates a GLFW window with GLFW_NO_API (no GL
context), but demo_font_upload_palette() unconditionally called
glGetIntegerv(), causing a segfault on the first glyph lookup.

Split palette upload into GL and external-backend paths:

- Extract demo_font_get_palette() to read CPAL colors into a
  float array, shared by both paths.
- GL path (demo_font_upload_palette_gl) uploads via glUniform4fv
  as before.
- External-backend path uploads via a new upload_palette callback
  in demo_atlas_backend_t.
- Metal renderer implements the callback, writing palette data
  directly to its paletteBuffer.

This fixes the --metal crash and enables proper COLRv0 palette
color rendering on Metal.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 15:59:29 -06:00
Behdad Esfahbod dfd5d5b3cb [gpu] Paint: port to HLSL/WGSL; add _hb_gpu_draw_impl; fix WGSL
This commit unblocks end-to-end paint rendering on the WebGPU
demo, adds the HLSL port, and avoids losing MSAA or stem
darkening along the way.

### Shared: _hb_gpu_draw_impl

hb_gpu_draw internally did fwidth(renderCoord) + MSAA.  That works
fine in the single-call-per-fragment case but not when called from
inside a non-uniform branch (e.g. an op-stream LAYER_SOLID
conditional in the paint fragment shader) -- WGSL rejects fwidth
from non-uniform control flow.

Factor the MSAA-aware body into _hb_gpu_draw_impl, which takes a
caller-supplied pixelsPerEm.  hb_gpu_draw is now a thin wrapper
that computes pixelsPerEm via fwidth and delegates.  The paint
fragment shader in every language now computes pixelsPerEm once
at the top of hb_gpu_paint and calls _hb_gpu_draw_impl per layer
-- MSAA preserved, no redundant fwidth calls per layer.

In WGSL, _hb_gpu_draw_impl also inlines the ppem computation from
pixelsPerEm rather than recurring into hb_gpu_ppem (which itself
calls fwidth).

### Paint shaders

- hb-gpu-paint-fragment.hlsl (new): HLSL transcription.  Assumes
  a caller-declared StructuredBuffer<float4> hb_gpu_palette at
  register(t1).
- hb-gpu-paint-fragment.wgsl: switched from hb_gpu_draw to
  _hb_gpu_draw_impl; comment updated.
- hb-gpu-paint-fragment.msl, .glsl: same switch, cached
  pixelsPerEm at entry.

hb_gpu_paint_shader_source() now returns content for all four
languages.

### Demos

- util/gpu/demo-fragment.glsl: restores stem darkening (dropped in
  the first paint wiring commit); applies to the premultiplied
  RGBA by scaling both colour and alpha.  The desktop GL demo
  regenerates demo-fragment-glsl.hh from this source.
- util/gpu/web/hb-gpu-web-webgpu.cc: WGSL fs_main concatenates the
  paint source, binds a zero-filled palette storage buffer at
  @group(0) @binding(2), and restores stem darkening.  fwidth
  hoisted outside the stem-darkening conditional so WGSL's
  derivative-uniformity rule is happy.
- util/gpu/demo-renderer-d3d11.cc: HLSL ps_main switches to
  hb_gpu_paint.  Adds a second StructuredBuffer<float4>
  hb_gpu_palette at t1, zero-filled for now, bound alongside the
  atlas SRV.

### Misc

- perf/benchmark-gpu.cc: fix stale reset/encode(draw) calls.

Measured build (local Emscripten):
  WebGL   index.wasm  : 443638  181640 gz
  WebGPU  webgpu.wasm : 461626  188400 gz

COLRv0 rendering (BungeeTint, Noto Color Emoji, etc.) now works
end-to-end on WebGL and WebGPU with the correct palette.  Metal
and D3D11 demos should likewise compile against the new shader
flow; real palette upload cross-backend remains a TODO.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 15:52:21 -06:00
Behdad Esfahbod d5f07d72d0 [gpu] Port paint fragment shader to WGSL; wire WebGPU demo
WGSL transcription of the paint interpreter.  Takes the atlas and
palette as explicit storage-buffer pointer parameters (matching
the WGSL draw helper's calling convention):

  fn hb_gpu_paint (renderCoord: vec2f, glyphLoc: u32,
		   foreground: vec4f,
		   hb_gpu_atlas: ptr<storage, array<vec4<i32>>, read>,
		   hb_gpu_palette: ptr<storage, array<vec4f>, read>) -> vec4f

hb_gpu_paint_shader_source() now returns real content for
HB_GPU_SHADER_LANG_WGSL fragment; HLSL still stubs to "".

util/gpu/web/hb-gpu-web-webgpu.cc:
  - Concats the paint source alongside the draw source into the
    WGSL shader module.
  - Declares @group(0) @binding(2) for hb_gpu_palette.
  - Allocates a 256 * vec4f storage buffer (zero-filled for now;
    real palette upload is TODO), binds it at entry index 2.
  - Fragment main switches from hb_gpu_draw to hb_gpu_paint.

util/gpu/web/gl-stub.h: adds glUniform4fv stub (demo-font.cc now
calls it for the GL palette path) and makes
glGetUniformLocation return -1 so the WebGPU build's
demo_font_upload_palette short-circuits.

Wasm sizes:
  WebGL   index.wasm  : 443628  181597 gz
  WebGPU  webgpu.wasm : 461110  188045 gz

Non-color text should render through WebGPU.  COLRv0 color glyphs
come up transparent until the cross-backend palette upload lands.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 15:27:41 -06:00
Behdad Esfahbod 5e2b77d2ea [gpu] Port paint fragment shader to MSL; wire Metal demo
MSL transcription of the GLSL paint fragment interpreter.  Same
per-pixel op-stream walk and LAYER_SOLID SRC_OVER composite; the
only surface difference is that MSL's hb_gpu_fetch /
hb_gpu_paint take the atlas and palette as explicit buffer
pointer parameters (matching MSL's lack of globally-scoped
device-address-space globals).

  float4 hb_gpu_paint (float2 renderCoord, uint glyphLoc,
		       float4 foreground,
		       device const short4* hb_gpu_atlas,
		       constant float4* hb_gpu_palette);

hb_gpu_paint_shader_source() now returns a real string for
HB_GPU_SHADER_LANG_MSL fragment; vertex and WGSL/HLSL still stub
to "".

util/gpu/demo-metal.mm: concatenates the paint source alongside
the draw source into the Metal library, fragment_main switches
from hb_gpu_draw to hb_gpu_paint, and a 256-element palette
MTLBuffer is created + bound at fragment buffer index 2.  The
palette buffer is zero-filled for now; real palette upload from
the font's active palette is a follow-up (the GL path in
demo-font.cc uses glUniform4fv, which is GL-specific; a cleaner
cross-backend upload will come with the general palette plumbing).

Non-color text (u_foreground path) should render correctly on
Metal.  COLRv0 color glyphs will render transparent until the
palette upload lands -- ready for Mac smoke-testing.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 15:14:36 -06:00
Behdad Esfahbod 34a9f22f25 [util/gpu] Extract demo shaders into .glsl files
demo_vertex_glsl and demo_fragment_glsl were inline R"glsl(...)"
string literals in util/gpu/demo-shader.cc.  Pull them into
dedicated util/gpu/demo-{vertex,fragment}.glsl source files with
their own copyright headers, and wire the existing
gen-gpu-shader-artifacts.py generator to stringize them into
demo-*-glsl.hh at build time.

Also simplifies gen-gpu-shader-artifacts.py: the decl_map had
grown to cover every shader and its entries were all trivial
filename-to-symbol derivations.  Replace the map with direct
derivation (hyphens -> underscores, strip .hh), so adding more
shaders anywhere -- library or demo -- needs no generator edit.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 15:10:09 -06:00
Behdad Esfahbod f3fcd46ba9 [gpu] First working COLRv0 GPU render
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>
2026-04-13 15:03:58 -06:00
Behdad Esfahbod 7c97464406 [gpu] encode-all: paint-first with draw fallback; skip empty clip glyphs
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>
2026-04-13 14:41:44 -06:00
Behdad Esfahbod eb46e5349e [gpu] Wire GL demo to the paint pipeline end-to-end
* hb_gpu_paint_glyph() switches from hb_font_paint_glyph_or_fail
  to hb_font_paint_glyph so non-color glyphs also produce a blob
  (harfbuzz synthesizes push_clip_glyph + color(is_foreground) +
  pop_clip which our callbacks turn into a single LAYER_SOLID
  op).  Return value is now "no internal error" rather than
  "glyph had color paint".

* util/gpu/demo-font.cc: drops the draw-only upload path and
  routes every glyph through hb_gpu_paint_{clear,glyph,encode,
  recycle_blob}.  Uploads the active palette to the
  hb_gpu_palette uniform array in demo_font_create.

* util/gpu/demo-shader.cc: concatenates hb_gpu_paint_shader_source
  after the shared + draw sources, and the demo's fragment main
  now calls hb_gpu_paint(texcoord, glyphLoc, u_foreground)
  directly.  Stem-darkening / debug overlay paths preserved
  against the premultiplied alpha channel returned by paint.

MSL / WGSL / HLSL demo paths are unchanged for now -- the paint
shader is GLSL-only and those demos keep using the draw path.

wasm size impact (local Emscripten build):
  baseline                     412722   170342 gz
  +HB_NO_COLOR/HB_NO_PAINT     437752   179165 gz
  +demo paint wiring           443313   181502 gz
  delta (vs baseline)          +30591    +11160

All 241 tests pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 14:36:32 -06:00
Behdad Esfahbod ebfea127de [gpu] Add GLSL paint fragment shader (LAYER_SOLID interpreter)
Implements the paint-renderer fragment entry point
hb_gpu_paint(renderCoord, glyphLoc, foreground) -> vec4 as an
interpreter over the blob format documented in hb-gpu-paint.hh.

For this first slice only LAYER_SOLID ops are handled -- enough
to render COLRv0 color glyphs end to end once the demo is
rewired.  LAYER_GRADIENT and PUSH/POP_GROUP cause the interpreter
to stop; COLRv1 support lands in follow-up commits.

The shader:
* Reads the blob header for num_ops and ops_offset.
* Walks the op stream.  For each LAYER_SOLID it fetches the
  clip-glyph coverage via hb_gpu_draw() (provided by
  hb_gpu_draw_shader_source), looks up the color from
  hb_gpu_palette[] or the caller-supplied foreground parameter
  (per the is_foreground flag), and composites SRC_OVER.

hb_gpu_paint_shader_source() now returns the compiled source for
GLSL fragment; other languages and the vertex stage still return
"" until transcribed.

Wires meson.build and gen-gpu-shader-artifacts.py to generate the
.hh artifact.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 14:29:03 -06:00
Behdad Esfahbod 1a94ff1f7b [gpu] Implement hb_gpu_paint_t COLRv0 encoder
Wire the paint-callback pipeline for COLRv0 color glyphs.

Adds:

* push_clip_glyph / pop_clip / color / custom_palette_color
  callbacks.  Each COLRv0 layer's push_clip_glyph is captured,
  then the following color callback rasterizes the clip-glyph
  outline through a scratch hb_gpu_draw_t, appends the resulting
  Slug sub-blob, and emits a LAYER_SOLID op carrying the
  palette_index (preserved via custom_palette_color) plus the
  is_foreground flag.  pop_clip clears the pending state.
* hb_gpu_paint_get_funcs(): cached singleton hb_paint_funcs_t via
  the standard hb_paint_funcs_lazy_loader_t.
* hb_gpu_paint_glyph(): stashes the font scale and invokes
  hb_font_paint_glyph_or_fail() with our funcs and a sentinel
  foreground (the encoder never stores foreground -- the shader
  resolves it per quad from a caller-supplied attribute).
* hb_gpu_paint_encode(): concatenates the 3-texel header, the op
  stream, and the collected sub-blobs into one RGBA16I blob,
  patching each op's sub_blob-index into an absolute texel
  offset.  Returns NULL when no layers accumulated or an
  unsupported (v1) feature was seen.
* hb_gpu_paint_clear(): discards ops, sub-blobs, and pending
  state while preserving the font scale.

The gradient / group / transform callbacks are not wired yet, so
COLRv1 paint graphs silently fall through -- callers should
precheck with hb_ot_color_glyph_has_paint() and route v1 glyphs
elsewhere (or fall back to draw).

Enables HB_NO_COLOR and HB_NO_PAINT in the web demo config
override so the wasm link resolves the new paint pipeline
symbols.  Measured on a local Emscripten build:

  raw  wasm:  412722 -> 437752  (+25030 B, +6.1%)
  gzip wasm:  170342 -> 179165  ( +8823 B, +5.2%)

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 14:26:08 -06:00
Behdad Esfahbod 5f527aeea1 [gpu] Drop hb_paint_funcs_get_empty from hb_gpu_paint_glyph stub
The stub called hb_font_paint_glyph_or_fail() with the empty paint
funcs just to get a truthful has-paint return value.  That pulls in
hb_paint_funcs_get_empty from hb-paint.cc, which HB_LEAN strips out
of the wasm build, breaking the web demo link step.

Since the encoder is still a stub that accumulates nothing, there is
no reason to actually invoke the paint callback walk.  Stash the
font scale and return false directly.  When the real encoder lands
it will naturally pull in whichever paint symbols it needs.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 13:53:48 -06:00
Behdad Esfahbod a0a469bf15 [gpu] Revert demo paint-path wiring
The previous commit routed color-glyph upload to hb_gpu_paint_t and
fell back to hb_gpu_draw_t on NULL blob.  That is fine as long as
hb_gpu_paint_encode() is a stub returning NULL, but when the real
encoder lands the demo would start uploading paint-format blobs
into the atlas while the renderer still uses only the draw-stage
fragment shader -- producing garbage.

Keep the library-side paint stubs (they are legit scaffolding) but
back out the demo changes.  The demo will grow the paint path in
lock-step with the paint shader, not ahead of it.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 13:52:16 -06:00
Behdad Esfahbod 7b5fc7f0c4 [gpu] Add hb_gpu_paint_* glyph/encode/clear/reset/recycle stubs
Reserve the paint-encoder API shape and wire the demo to try the
paint path before falling back to draw.  The encoder itself is
still a stub so the fallback always fires today; when the encoder
lands, color glyphs will flip automatically with no demo changes.

New public API:

  hb_gpu_paint_glyph (paint, font, glyph)
    Stashes the font scale on @paint and calls
    hb_font_paint_glyph_or_fail() with hb_paint_funcs_get_empty()
    so non-color glyphs report false.  Returns the funcs call
    result.

  hb_gpu_paint_encode (paint, &extents)
    Stub, returns NULL.

  hb_gpu_paint_clear (paint)
  hb_gpu_paint_reset (paint)
  hb_gpu_paint_recycle_blob (paint, blob)
    Stubs that preserve the right semantics.  clear is a no-op
    (no accumulator state yet), reset additionally zeroes the
    stashed scale, recycle_blob hb_blob_destroys.

Adds x_scale / y_scale to hb_gpu_paint_t so glyph can stash them
for the encoder to consume later.

util/gpu/demo-font.cc:
  - Creates a paired hb_gpu_paint_t alongside hb_gpu_draw_t.
  - Per glyph: if the face has COLRv1 paint for the glyph, tries
    hb_gpu_paint_glyph + hb_gpu_paint_encode.  On NULL blob, falls
    through to the existing draw path.
  - Changes the per-iteration sync from _reset to _clear for both
    draw and paint: _reset zeroes the font-scale config that
    _glyph immediately re-populates, which wastes work and is
    semantically wrong.  _clear discards accumulator state while
    preserving user config.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 13:38:14 -06:00
Behdad Esfahbod 13231bc7fe [gpu] Document hb_gpu_paint_t encoded-blob design
Add a design-doc comment in hb-gpu-paint.hh pinning the model
before any encoder code lands:

* One blob per glyph, one quad per glyph.  The fragment shader
  walks a flat pre-order op stream and maintains a small (depth-4)
  group stack to composite.
* Op types: LAYER_SOLID, LAYER_GRADIENT, PUSH_GROUP, POP_GROUP.
* Clip-glyph outlines are embedded as Slug-format sub-payloads
  (same format hb_gpu_draw_encode produces).  v1 bakes the full
  paint transform into each outline; v2 may canonicalize and share
  translate-only variants.
* Gradient parameters embedded as RGBA16I texels: inverse transform
  in q15.16, type+extend, subtype params, color stops.
* Colors carry a (palette_index, flags, alpha_q15) triple rather
  than resolved RGBA.  Palette is a shader-side uniform array of
  256 vec4; swapping palettes never requires re-encoding.  The
  encoder preserves palette indices through harfbuzz's paint
  pipeline via a custom_palette_color_func that returns a sentinel
  hb_color_t with the index encoded, decoded again in the color /
  color-stop callbacks.
* Shader entry point:
    vec4 hb_gpu_paint (vec2 renderCoord, uint glyphLoc,
                       vec4 foreground);
  Foreground is an explicit parameter; the caller chooses whether
  to source it from a uniform or a per-quad flat varying (per-quad
  lets styled text runs render in one draw call).
* Out of scope for v1: RECT_CLIP ops (treated as hints, not
  enforced), paint images.

No code yet.  The skeleton hb_gpu_paint_t stays as a bare
hb_object_header_t; encoder state and public API additions come in
follow-up commits.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 13:31:06 -06:00
Behdad Esfahbod c643c5245c [gpu] Merge *-shaders.cc dispatchers into the subsystem .cc files
Each subsystem already had a dedicated source file for its C API;
having the shader-source getter live in a separate `*-shaders.cc`
was unnecessary.  Merge:

  hb-gpu-shaders.cc       -> hb-gpu.cc
  hb-gpu-draw-shaders.cc  -> hb-gpu-draw.cc
  hb-gpu-paint-shaders.cc -> hb-gpu-paint.cc

Each subsystem's .cc is now self-contained: the lifecycle, glyph
accumulation, and shader-source getter all live together.

The large stringized-shader .hh artifacts are included locally at
the bottom of each file, right above the function that uses them,
rather than with the primary includes at the top -- they are only
used by one function.

Updates meson.build, CMakeLists.txt, and harfbuzz-world.cc to
drop the removed files.  All 241 tests still pass.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 12:10:35 -06:00
Behdad Esfahbod 70310b9e65 [gpu] Add hb_gpu_paint_t infrastructure skeleton
Reserve the API shape for the upcoming GPU color-glyph paint
encoder.  The skeleton adds:

  hb_gpu_paint_t opaque type
  hb_gpu_paint_create_or_fail ()
  hb_gpu_paint_reference ()
  hb_gpu_paint_destroy ()
  hb_gpu_paint_set_user_data () / _get_user_data ()
  hb_gpu_paint_shader_source (stage, lang)

Only the lifecycle is functional.  hb_gpu_paint_shader_source()
returns an empty string for all supported (stage, lang) pairs
until the paint-renderer shaders land.

This commit wires up the files, public declarations, section
index, and build system (meson, CMake, harfbuzz-world.cc,
vtable).  Callers can now hold, reference, destroy, and attach
user data to a paint context.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 12:10:35 -06:00
Behdad Esfahbod f587af3ec3 [gpu] Extract shared shader helpers into hb_gpu_shader_source() (#5921)
The draw-renderer fragment shaders defined utilities
(HB_GPU_UNITS_PER_EM, the hb_gpu_atlas uniform, hb_gpu_fetch) that
any future GPU renderer will also need.  The draw-renderer vertex
shader likewise contained only the generic hb_gpu_dilate helper.
If a paint renderer were added today and a caller linked both
fragment sources together, hb_gpu_fetch would be defined twice.

Move these shared helpers into a new family of sources and expose
them via a new public entry point:

  hb_gpu_shader_source (stage, lang);

The existing hb_gpu_draw_shader_source() now returns only the
draw-specific fragment code; it returns an empty string for the
vertex stage because all current vertex logic is shared.  Callers
concatenate the shared source first, then the draw-specific
source, then their own main():

  [#version, hb_gpu_shader_source (...), hb_gpu_draw_shader_source
  (...), main]

Additions:
 - src/hb-gpu-fragment.{glsl,msl,wgsl,hlsl} — shared fragment
 - src/hb-gpu-vertex.{glsl,msl,wgsl,hlsl}   — shared vertex,
   renamed from hb-gpu-draw-vertex.*
 - src/hb-gpu-shaders.cc — hb_gpu_shader_source() dispatcher

Removals:
 - src/hb-gpu-draw-vertex.{glsl,msl,wgsl,hlsl} — moved to common

Shared sources are Behdad-only copyright; the Eric Lengyel / Slug
attribution stays on the draw-specific fragment sources where the
Slug algorithm actually lives.

Updates: test/api/test-gpu.cc, the Metal/D3D11/WebGPU/GL demo
shaders, the hb-gpu SECTION documentation, meson.build,
CMakeLists.txt, gen-gpu-shader-artifacts.py decl_map,
harfbuzz-world.cc, and docs/harfbuzz-sections.txt.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 12:10:23 -06:00
jfkthame 603ab95602 Return size_t rather than unsigned int from get_size() (#5915)
* [subset] Return size_t rather than unsigned from get_size() methods

It's possible some get_size() computations during serialization
may overflow 32-bit arithmetic.

(The result of get_size() is used as size_t when allocating via
hb_serialize_context_t::extend(), but if the return value was
declared as unsigned int, the value may have wrapped resulting
in under-allocation.)

* [subset] Use size_t when accumulating subset_data_size

* [graph] Use size_t (rather than signed int64_t) for vertex_len variables

* Use size_t for sanitize_closure_t::stride to avoid narrowing
2026-04-13 11:01:19 -06:00
Behdad Esfahbod e2d68946bf Merge pull request #5916 from harfbuzz/survey-cleanup
More new-lib cleanup
2026-04-13 04:08:42 -06:00
Behdad Esfahbod 90678d6876 [docs] Register new raster and vector getters in sections.txt
Add the eight new getters introduced in the recent API-cleanup
commits to their section indexes:

  hb_raster_paint_get_foreground
  hb_raster_paint_set_palette
  hb_raster_paint_get_palette
  hb_vector_draw_get_flat
  hb_vector_draw_get_precision
  hb_vector_paint_get_foreground
  hb_vector_paint_get_palette
  hb_vector_paint_get_flat
  hb_vector_paint_get_precision

Without these entries gtk-doc's doc-check flags the new symbols
as undocumented.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 03:49:56 -06:00
Behdad Esfahbod aded5fccad [raster] Make hb_raster_image_serialize_to_png_or_fail const
The function only reads the image; the internal
hb_raster_image_t::serialize_to_png_or_fail() method is already
declared const.  Take a const pointer at the public API boundary.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 03:39:36 -06:00
Behdad Esfahbod d0c9edd7fe [vector] Add getter companions for set_flat, set_precision,
set_foreground, set_palette

Every storable setter on hb_vector_draw_t and hb_vector_paint_t
now has a matching getter, matching the symmetry already present
for transform/scale_factor/extents:

  hb_vector_draw_get_flat ()
  hb_vector_draw_get_precision ()
  hb_vector_paint_get_flat ()
  hb_vector_paint_get_precision ()
  hb_vector_paint_get_foreground ()
  hb_vector_paint_get_palette ()

set_glyph_extents has no getter companion since it does not store
its input; it transforms the glyph extents into the context's
pixel-space extents, which are already retrievable via
hb_vector_*_get_extents().

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 03:38:34 -06:00
Behdad Esfahbod 83b4b27f52 [raster] Mark hb_raster_paint_glyph as XSince: REPLACEME
The signature of hb_raster_paint_glyph() changed in the previous
commit (palette and foreground parameters dropped).  Update its
docstring from "Since: 13.0.0" to "XSince: REPLACEME" so the
release engineer documents it under the new release.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 03:37:06 -06:00
Behdad Esfahbod f9de50ab52 [raster] Simplify hb_raster_paint_glyph; add set/get_palette
hb_raster_paint_glyph() took the palette index and foreground
color as per-call arguments, duplicating state that also lives on
the paint context (foreground via hb_raster_paint_set_foreground,
palette previously only available as a per-call arg).  This gave
callers two paths for configuring the same state.

Drop the per-call palette/foreground arguments and require callers
to configure them via setters before painting, matching the
already-established pattern in hb_vector_paint_glyph() and
elsewhere in the subsystem.

- Drop palette and foreground args from hb_raster_paint_glyph().
- Add hb_raster_paint_set_palette() / _get_palette() and a
  hb_raster_paint_get_foreground() companion.
- Store palette on hb_raster_paint_t (default 0).
- Update util/raster-output.hh, util/hb-raster-all.cc, and
  test/fuzzing/hb-raster-fuzzer.cc to the new API.
- Update the hb-raster section-doc example.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 03:35:47 -06:00
Behdad Esfahbod 403c872b13 Merge pull request #5914 from harfbuzz/survey-cleanup
A few cleanups of new libraries
2026-04-13 03:25:23 -06:00
Behdad Esfahbod b8c27ad659 [subset] Rename glyph_index to glyph in CFF charstring-data API
The two experimental CFF charstring-data accessors:

  hb_subset_cff_get_charstring_data (hb_face_t *, hb_codepoint_t);
  hb_subset_cff2_get_charstring_data (hb_face_t *, hb_codepoint_t);

used "glyph_index" as the parameter name, inconsistent with the
rest of the project where glyph-ID parameters are uniformly named
"glyph".  Both APIs are behind HB_EXPERIMENTAL_API so the rename
is safe.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 03:13:37 -06:00
Behdad Esfahbod 59f71c0694 [gpu] Restructure section doc: module intro + Draw subsection
Split the hb-gpu SECTION comment into a brief module-level intro
and a dedicated Draw subsection covering the existing encoder and
shader documentation.

Today the doc block opens with Slug-specific framing ("This module
implements the Slug algorithm...") and uses top-level headings for
encoding, atlas setup, shader compilation, vertex/fragment shader
helpers, and stem darkening.  All of that belongs specifically to
the hb_gpu_draw_t renderer.  Gather it under a single "Draw"
heading and demote the former top-level headings by one level so
the section structure reflects that it documents one renderer.

Also update @short_description to "GPU text rendering" since the
module name no longer hints that encoding is its only role.

No content changes beyond headings and the opening paragraphs; no
API change.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 03:03:55 -06:00
Behdad Esfahbod 1e70544d32 [gpu] Rename hb-gpu-shaders.cc to hb-gpu-draw-shaders.cc
The file implements hb_gpu_draw_shader_source() and only dispatches
draw-subsystem shader sources.  Matching the file-naming convention
recently applied to the .glsl/.msl/.wgsl/.hlsl sources and their
generated .hh artifacts.

No behavior change; updates CMakeLists.txt, src/meson.build, and
src/harfbuzz-world.cc to reference the new filename.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 03:02:38 -06:00
Behdad Esfahbod a44eb976dc [gpu] Rename hb_gpu_draw_darken -> hb_gpu_stem_darken
The previous commit renamed hb_gpu_darken to hb_gpu_draw_darken
for symmetry with hb_gpu_draw (formerly hb_gpu_render).  But the
operation isn't draw-subsystem specific: it adjusts a coverage
value based on foreground brightness and ppem, which is just the
standard stem-darkening recipe.  Name it after what it does.

Paint doesn't need its own variant — it can call this same
function on any alpha/coverage channel it produces.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:59:37 -06:00
Behdad Esfahbod daddae08a3 [gpu] Rename fragment-shader entry points with "draw_" prefix
Rename the public fragment-shader entry points provided by the
hb_gpu_draw_t renderer:

  hb_gpu_render(...)   -> hb_gpu_draw(...)
  hb_gpu_darken(...)   -> hb_gpu_draw_darken(...)

Also rename the internal helper:

  _hb_gpu_render_single(...) -> _hb_gpu_draw_single(...)

A COLRv1 paint renderer is planned and will provide its own
fragment entry point (likely hb_gpu_paint returning a vec4); the
existing draw/coverage entry point gets a subsystem-qualified name
now so draw and paint can coexist.

Updates the .glsl/.msl/.wgsl/.hlsl sources, regenerated .hh
artifacts, the documentation block in hb-gpu.cc, and the util/gpu
demo shaders.  No behavior change.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:57:07 -06:00
Behdad Esfahbod 60a4e49aec [gpu] Rename draw shader files/symbols with "draw-" prefix
Rename hb-gpu-{fragment,vertex}.{glsl,msl,wgsl,hlsl} and their
generated .hh artifacts to hb-gpu-draw-{fragment,vertex}.{glsl,msl,
wgsl,hlsl}.  Likewise rename the C symbols in each artifact from
hb_gpu_{fragment,vertex}_<lang> to hb_gpu_draw_{fragment,vertex}_<lang>.

These are the shader sources for the hb_gpu_draw_t (Slug-style
coverage) renderer.  A COLRv1 paint renderer is planned and will
introduce its own hb-gpu-paint-*.{glsl,...} shader family, so the
existing shaders need a subsystem-qualified name to disambiguate.

No behavior change; hb_gpu_draw_shader_source() keeps returning the
same strings.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:52:02 -06:00
Behdad Esfahbod 83c7371098 [vector] Check offsets.resize result in PDF render
Follow-up to 891cb21c7 in the same direction: hb_vector_paint_render_pdf
called offsets.resize(total_objects) without checking the return value,
then dereferenced offsets.arrayZ[0] unconditionally.  Under failing-malloc
the resize leaves arrayZ null and we crash.

Return nullptr on resize failure; callers already handle a null blob.

Found by the OSS-Fuzz hb-vector-fuzzer with OOM injection, same trip as
the earlier hb_pdf_get_resources crash.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:47:18 -06:00
Behdad Esfahbod eeec9bd9fa [gpu] Unify shader source getters; rename for draw/paint split
Replace the two separate getters

  hb_gpu_shader_fragment_source (lang)
  hb_gpu_shader_vertex_source   (lang)

with a single

  hb_gpu_draw_shader_source (stage, lang)

where stage is the new hb_gpu_shader_stage_t enum (VERTEX or
FRAGMENT).  Parameter order is stage-first because "the vertex
shader in GLSL" reads more naturally than the reverse, and stage
is the primary axis (it determines which shader object the source
is compiled into).

The `_draw_` in the new name makes room for the incoming
hb_gpu_paint_shader_source() once the COLRv1 encoder lands —
that family will have its own (likely different) shader sources
per stage and language.

Updated the four in-tree callers: test/api/test-gpu.cc, and the
GPU demos under util/gpu/.  ABI break on a 14.0-only API; the
gpu library is still young enough that this is acceptable.

Marked new API with XSince: REPLACEME.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:26:21 -06:00
Behdad Esfahbod 891cb21c7b [vector] Fix NULL write in hb_pdf_get_resources under OOM
hb_pdf_get_resources stashes a heap-allocated hb_pdf_resources_t
pointer into the reused paint->defs vector.  It called
paint->defs.resize(sizeof(void*)) and ignored the return value,
then memcpy'd into paint->defs.arrayZ.  Under failing-malloc
(reached by the fuzzer), resize can fail leaving arrayZ as nullptr,
and the subsequent memcpy dereferences NULL.

Check the resize result.  On failure, destruct + free the
already-constructed resources struct and return nullptr — which
all callers of hb_pdf_get_resources already handle.

Found by the OSS-Fuzz hb-vector-fuzzer after the prior commit
that enabled PDF-format fuzzing.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:17:36 -06:00
Behdad Esfahbod 4c94a812b0 [vector] Drop redundant scale-factor > 0 guard in transform_point
hb_vector_transform_point () had a guard "(x_scale_factor > 0 ?
x_scale_factor : 1.f)" on divisions.  The setters on both
hb_vector_paint_t and hb_vector_draw_t already clamp scale factors
to > 0 at input, and every other use site in the vector code trusts
that invariant.  The guard here was redundant; drop it.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:01:22 -06:00
Behdad Esfahbod 8862ff55c2 [gpu] Rename hb_gpu_draw_glyph parameter codepoint -> glyph
All sibling APIs (hb_raster_draw_glyph, hb_vector_{draw,paint}_glyph,
hb_raster_paint_glyph) name the glyph ID parameter "glyph".  The gpu
variant was the odd one out calling it "codepoint".  The type is
hb_codepoint_t in either case — only the local parameter name
changes; no ABI impact.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 02:01:21 -06:00
Behdad Esfahbod 3e411b58d6 [api] Return hb_bool_t from hb_raster_draw_glyph and hb_gpu_draw_glyph
Both were declared void, diverging from their sibling APIs
(hb_vector_{draw,paint}_glyph, hb_raster_paint_glyph) which all
return hb_bool_t, and from the font-level hb_font_draw_glyph_or_fail()
pattern.

Switch both to return hb_bool_t and route the internal call
through hb_font_draw_glyph_or_fail() instead of hb_font_draw_glyph().
Returns false when the font has no outlines for the given glyph;
true otherwise.

Libraries are new/experimental; the ABI break is acceptable.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 01:59:18 -06:00
Behdad Esfahbod 8cd50a7b77 [gpu] Add hb_gpu_draw_get_scale companion getter
hb_gpu_draw_set_scale() existed without a paired getter; all other
draw/paint contexts have get/set pairs.  Fill the gap for symmetry.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 01:58:06 -06:00