Commit Graph
1181 Commits
Author SHA1 Message Date
Behdad Esfahbod 9ebdd0019f [util/gpu] Add --output-file for headless PPM render
Gives hb-gpu a non-interactive output path:

  hb-gpu --demo -o /tmp/frame.ppm
  hb-gpu --demo -o -  | display  # stdout piping

When --output-file is set, the GL backend passes
GLFW_VISIBLE=false so no window pops up.  After the normal init
and one render pass, we glReadPixels the default framebuffer,
flip row order, and write a PPM (P6) to the selected sink.
No event loop, process exits after writing.

Supported format: ppm (only).  Other formats are rejected by the
shared output_options_t machinery.  Metal and D3D11 backends
currently still open a window; headless support there is a
straightforward follow-up.

This unlocks CI golden-image tests for shader changes and
reproducible benchmark timing without swapchain-present jitter.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-14 20:48:26 -06:00
Behdad Esfahbod 6828ad2865 [util/gpu] Route LOGI to stderr
LOGI is informational output (help text, toggle state, fps).  It
belongs on stderr: that keeps stdout available for program output
(e.g. --output-file=- piping a PPM through a pipeline), and it
matches LOGW/LOGE which already go to stderr.

No user-visible change in normal (windowed) runs; stderr shows up
in the same terminal as stdout by default.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-14 20:48:17 -06:00
Behdad Esfahbod 1f813cfb86 [util/gpu] Extract MSL/HLSL/WGSL demo shaders into own files
Matches the GLSL convention: demo-shader.{msl,hlsl,wgsl} live
alongside demo-fragment.glsl and get stringified by the same
gen-gpu-shader-artifacts.py helper into demo-shader-{msl,hlsl,
wgsl}.hh.  No more giant inline R"msl(...)" / R"hlsl(...)" /
R"wgsl(...)" blobs in the .mm / .cc files.

Each language combines vertex and fragment entry points in one
source, as is idiomatic for MSL / HLSL / WGSL compilers; GLSL's
split (demo-vertex.glsl + demo-fragment.glsl) is preserved
because glCompileShader takes separate stages.

No functional change.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 15:33:44 -06:00
Behdad Esfahbod c4da618566 [gpu] Stem-darken by per-fragment color, not by foreground uniform
The demo fragment shaders were passing u_foreground's brightness
to hb_gpu_stem_darken(), which was wrong for color glyphs: a red
cheek on an emoji should darken relative to its own red, not to
whatever the text-foreground uniform happens to be.

Switch all four demo fragment paths (GL, Metal, D3D11, WebGPU)
to compute brightness from the fragment's own straight color
(c.rgb / c.a).  For monochrome glyphs this is identical to the
old formula -- the synthesized single layer's color IS the
foreground uniform -- so non-color rendering is unchanged.

The public hb_gpu_stem_darken() helper is unchanged; only its
callers pass a different brightness.  Document the paint-path
usage in the hb-gpu section.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 15:24:32 -06:00
Behdad Esfahbod 819fce8352 [gpu] Document Paint renderer; drop encode-time foreground API
Integrates the paint renderer into the hb-gpu module docs:

- Intro notes two renderers (Draw for monochrome, Paint for
  COLRv0/COLRv1, with explicit note that Paint also handles
  monochrome outlines at some cost).
- New Paint section parallel to Draw covers encoding, shader
  composition, and fragment shader, referencing Draw for the
  shared atlas / vertex / dilation / stem-darkening pieces.
- Encoding examples drop hb_gpu_*_reset() in favour of
  hb_gpu_*_encode()'s auto-clear.

Drops hb_gpu_paint_set_foreground() / _get_foreground() and the
foreground field from hb_gpu_paint_t.  The encoded blob only
records an is_foreground flag per layer/stop; the actual
foreground color has always been a shader uniform passed to
hb_gpu_paint() at render time.  The encoder API was never
load-bearing -- the value was handed to hb_font_paint_glyph() but
the encoder callback ignores everything except the flag.

Also makes hb_gpu_paint_encode() auto-clear on return (matching
hb_gpu_draw_encode()), and removes the now-dead
demo_font_set_foreground() wrapper from the demo layer.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 15:15:53 -06:00
Behdad Esfahbod f840ae39a2 [util/gpu] Add --draw / --paint flags with auto-detect by font
Adds command-line flags --draw (force monochrome Slug path) and
--paint (force COLRv1 paint path) to hb-gpu, defaulting to
auto-detect based on hb_ot_color_has_paint(face).  Threads a
draw_only bool through the demo layer so each backend compiles
exactly one fragment program (draw or paint, not both).

The paint pipeline is ~10x slower than the draw pipeline on
monochrome content; auto-detect lets monochrome fonts keep the
fast path while still exercising both code paths from the same
binary.

Plumbing:

- demo_renderer_create_{gl,metal,d3d11} and demo_font_create
  take a draw_only argument.
- demo-fragment.{glsl,msl,hlsl} branch on HB_GPU_DEMO_DRAW,
  calling either hb_gpu_draw or hb_gpu_paint.
- demo-shader / glstate / d3d11 / metal include only the
  fragment helper for the chosen path and prepend
  HB_GPU_DEMO_DRAW to the source when draw_only.
- demo-font dispatches glyph upload to hb_gpu_draw_* or
  hb_gpu_paint_* and hides palette/foreground setters in
  draw mode.

Web demos pass false (paint-only) for now; a runtime
re-creation hook on font change would be needed there.

Tested on desktop GL, win64 D3D11, WebGL, WebGPU.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 00:04:27 -06:00
Behdad Esfahbod 6ca076f36b [util/gpu] Apply stem darkening in Metal and D3D11 fragment shaders
demo-fragment.glsl (desktop GL/WebGL) and the WGSL shader in
hb-gpu-web-webgpu.cc already invoked hb_gpu_stem_darken on the
painted result; the Metal (fragment_main) and D3D11 (ps_main)
entry points were missing that block, so stem darkening did
nothing on those backends.

Add the same call: compute ppem from fwidth(texcoord), derive
brightness from the foreground luminance, and scale the
premultiplied result by darkened/c.a.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 22:43:18 -06:00
Behdad Esfahbod ea88d25d07 [util/gpu] Web demos: drop stale gamma-toggle hints
The `g` key was removed when we hardcoded gamma 2.2; the shell's
help overlay still mentioned it.  Drop the lines.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 22:29:00 -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 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 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 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 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 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
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 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 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 4650398a07 [gpu] encode() returns extents + auto-clears; drop get_extents() (#5910)
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>
2026-04-13 00:15:54 -06:00
Behdad Esfahbod 0cf2fa0929 Merge pull request #5891 from harfbuzz/vector-pdf
PDF output from hb-vector
2026-04-11 22:20:01 -06:00
Behdad Esfahbod 7b6f26e844 [vector] Address review feedback
- Default hb_vector_{draw,paint}_t::format to HB_VECTOR_FORMAT_INVALID
  instead of HB_VECTOR_FORMAT_SVG.
- Update renamed hb_vector_{draw,paint}_set_{flat,precision} API docs
  from "Since: 13.0.0" to "XSince: REPLACEME".
- Extract hb_vector_draw_render_svg() helper to match the
  hb_vector_draw_render_pdf() pattern; move the misplaced
  hb_vector_draw_render doc comment to the actual function and update
  it to say "output blob" since the renderer is no longer SVG-only.
- Revert 14.0.0 NEWS entry edits; the API rename will be announced in
  the next release entry.
- Update docs/harfbuzz-sections.txt to reflect the API renames.
- hb-vector tool: expose -O/--output-format with supported formats
  "svg/pdf", validate format, update description string, and switch
  PDF detection to g_ascii_strcasecmp for case-insensitive matching.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 22:02:38 -06:00
Behdad Esfahbod 81a9830f30 [gpu] Make Escape exit fullscreen before quitting
When in fullscreen mode, pressing Escape now exits fullscreen
instead of closing the application. Pressing Escape again (or Q
at any time) still quits.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 18:05:00 -06:00
Behdad Esfahbod 30ee1bb2c6 [vector] Rename hb_vector_svg_*set_{flat,precision} API
Drop "svg" from the names since flat/precision settings apply
equally to PDF output.  The new names follow the hb_vector_draw_*
/ hb_vector_paint_* convention:

  hb_vector_svg_set_flat         -> hb_vector_draw_set_flat
  hb_vector_svg_set_precision    -> hb_vector_draw_set_precision
  hb_vector_svg_paint_set_flat   -> hb_vector_paint_set_flat
  hb_vector_svg_paint_set_precision -> hb_vector_paint_set_precision

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 12:16:55 -06:00
Behdad Esfahbod e046d2ba6d [vector] Add PDF color font rendering via paint API
Add hb-vector-pdf-paint.cc with a complete set of PDF paint
callbacks for the HarfBuzz paint API:

  push/pop_transform  →  q + cm / Q
  push/pop_clip_glyph →  q + path + W n / Q
  push/pop_clip_rect  →  q + re + W n / Q
  color               →  rg + re + f
  push/pop_group      →  q / Q
  gradients           →  solid fallback (first stop color)

The PDF paint backend reuses the draw funcs for glyph clip
path emission and shares the hb_vector_paint_t struct with
the SVG backend via hb-vector-paint.hh.

hb_vector_paint_glyph dispatches to SVG or PDF paint funcs
based on format.  hb_vector_paint_render delegates to the
PDF render function for PDF output.

Tested with COLRv0 (RocherColorGX) — color layers render
correctly with proper clipping.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Behdad Esfahbod a43971d2a3 [vector] Add PDF output backend
Add HB_VECTOR_FORMAT_PDF to hb_vector_format_t.  The hb-vector
tool now produces self-contained PDF when invoked with -o out.pdf.

PDF path operators map directly from the draw callbacks:
move_to → m, line_to → l, cubic_to → c, close_path → h,
with quadratic-to-cubic promotion (PDF has no Q operator).

The render function builds a minimal PDF 1.4 with catalog,
page, and content stream objects plus a cross-reference table.

Implementation:
- Extract hb_vector_draw_t struct to hb-vector-draw.hh so
  future backends can share it.
- Draw callbacks branch on format for SVG vs PDF syntax.
- hb_vector_draw_glyph and hb_vector_draw_render dispatch by
  format.
- vector-output.hh selects format from file extension and
  skips paint (color glyphs) for PDF.

Coordinate system needs refinement — the page layout inherits
the SVG Y-flip transform, placing glyphs at the top with
extra whitespace.  Correct PDF coordinate handling is a
follow-up.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-07 20:12:59 -06:00
Behdad Esfahbod 0234df4db6 [gpu] Fix WebGPU error page not showing when adapter unavailable
Check navigator.gpu synchronously in main() before calling
the WebGPU C API.  Previously the error was reported in an
async callback that raced with onRuntimeInitialized, which
hid the loading div before the error message could appear.

Also re-show the loading div and set window._webgpuError in
the adapter callback as a fallback.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 01:26:54 -06:00
Behdad Esfahbod e7c5b839eb [gpu] Store font scale in blob header; auto-MSAA in hb_gpu_render
Add hb_gpu_draw_set_scale() API and store x/y scale in the
glyph blob header (buf[1].b/a).  hb_gpu_draw_glyph() sets it
automatically from the font.

hb_gpu_render() now reads the scale, computes ppem via fwidth,
and automatically blends 4 corner samples at ±1/3 pixel when
ppem < 16 to reduce moiré at small sizes.  Define
HB_GPU_NO_MSAA to disable.

Add hb_gpu_ppem() public shader helper so clients can get
ppem without touching internal functions (e.g. for
hb_gpu_darken).

Remove hb_gpu_render_aaa(), u_upem uniform, and set_upem
plumbing from the demo — no longer needed.

GLSL only for now.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 00:59:39 -06:00
Behdad Esfahbod a255d9745b [gpu] Rework MSAA into hb_gpu_render_aaa with caller-provided ppem
Replace the two-program MSAA toggle with hb_gpu_render_aaa()
that takes ppem from the caller and auto-selects single-sample
(ppem >= 16) or 4-corner MSAA (ppem < 16).  This keeps
hb_gpu_render() lean for the fast path while letting the
adaptive function handle small sizes.

The previous approach had the ppem calculation inside the
library shader using 1/fwidth(texcoord), which was wrong by
a factor of upem — MSAA fired at all sizes.  Now the demo
passes correct ppem via a u_upem uniform.

Remove the 'm' key toggle, two-program compilation, and
set_msaa plumbing — no longer needed.

GLSL only for now.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 00:40:49 -06:00
Behdad Esfahbod 39d3b83b47 [gpu] Add GLFW_KEY_M to web GL stub for MSAA toggle
Assisted-by: Claude <noreply@anthropic.com>
2026-04-02 00:19:04 -06:00
Behdad Esfahbod 4f9048cd27 Revert "Revert small-size MSAA experiment"
This reverts commit 3c291a5015.
2026-04-02 00:18:05 -06:00
Behdad Esfahbod 5eb52c7407 [gpu] Fix display() signature in D3D11, Metal, and WebGPU renderers
Drop HB_UNUSED from the generation parameter — it's not
available in MinGW or Emscripten build contexts.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-01 23:52:54 -06:00
Behdad Esfahbod 61db984844 [gpu] Pass buffer generation to renderer display
The previous commit added the generation parameter to the
display interface but missed passing it from demo_view_display.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-01 23:29:15 -06:00
Behdad Esfahbod c86cb51bf6 [gpu] Fix garbled rendering after font change in web demo
The GL renderer cached the vertex buffer upload by comparing
the data pointer and count.  After clearing and refilling the
buffer with a new font's glyphs, std::vector reused the same
allocation, so the pointer and count matched — the upload was
skipped and the GPU drew with stale vertex data containing old
atlas offsets.

Fix by adding a generation counter to demo_buffer_t that
increments on clear().  The renderer compares generation and
count to decide whether to re-upload.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-01 23:25:48 -06:00
Behdad Esfahbod 3c291a5015 Revert small-size MSAA experiment
Reverts dc19a8002 and 7ac851ab6.  The improvement was not
worth the complexity or performance cost.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-01 23:09:36 -06:00
Behdad Esfahbod dc19a8002a [gpu] Add optional MSAA mode for small-size antialiasing
Add hb_gpu_render_msaa() that evaluates 9 samples (3x3 grid
at ±1/3 pixel) to reduce moiré at small sizes.  GLSL only.

The demo compiles two shader programs and toggles between them
with the 'm' key, so the MSAA program's register pressure
does not affect the fast single-sample path.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-01 23:08:30 -06:00
Behdad Esfahbod 4b2bce0d74 [gpu] Disable vsync in --bench mode
Pre-type 'v' before zoom/fullscreen/animate so that
benchmarking measures uncapped frame rate.

Assisted-by: Claude <noreply@anthropic.com>
2026-03-31 19:32:07 -06:00