28 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 4.8 4a8f1cd542 [gpu] Charge layer clip-outline references to the paint budget
The paint encoder memoizes a clip glyph's sub-blob, so layers painted
under the same clip stack cost it only a cached index and 24 bytes of
op stream each.  The fragment shader, however, walks every curve of
every clip outline again for every layer in every fragment.  Ops, clips
per layer and outline size each had a cap, but nothing bounded their
product: a small COLRv1 font nesting a few PaintGlyph clips of a dense
outline under tens of thousands of PaintSolid layers made the shader do
hundreds of millions of curve-loop iterations per fragment, a denial of
service on the GPU (or the CPU under a software rasterizer).

Charge each layer's reference to each clip sub-blob -- cached or freshly
encoded, glyph or path clip -- to the existing session work budget, in
encoded RGBA16I texels, which is what the shader's band walk scales
with.  This lives in emit_all_clip_sub_blobs(), the one path all four
layer emitters go through; exhausting the budget marks the paint
unsupported like the other encoder limits, so hb_gpu_paint_encode()
returns NULL.  It adds no new tunable: the budget defaults to
HB_BUDGET_GLYPH and hb_paint_set_budget(), including
HB_BUDGET_UNLIMITED, governs it as it does the outline work.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-FUCZJR1Y.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 16:55:57 -06:00
Behdad EsfahbodandClaude Opus 4.8 462a554921 [gpu] Charge each cu2qu subdivision node to the work budget
hb_gpu_cubic_to_quadratics() split a cubic up to 10 levels deep
(2,047 nodes, each with a fit test) without charging that work to the
per-glyph budget and without checking whether the accumulator still
accepted output.  Once the budget was spent, acc_emit() dropped every
curve but left g->success set, so each further cubic was fully
subdivided for nothing.  A VARC composite of CFF glyphs that shares one
budget across many cubic-producing components could make a single
hb_gpu_draw_glyph() (or hb_gpu_paint_glyph() clip) call spend seconds
of CPU, far past the budget, as a CPU denial of service from a small
crafted font.

Charge one unit per node and return at the top of the recursion once
g->success is false or the budget is exhausted, the same approach the
raster flattener already takes.  Returning is equivalent to emitting
here because acc_emit() discards everything once the budget is
negative, so the encoded outline is unchanged for any glyph that stays
within budget; the only cost is one extra unit per node, negligible
against HB_BUDGET_GLYPH.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-LZRUF6D2.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 16:55:11 -06:00
Behdad EsfahbodandClaude Opus 4.8 f97d6bbb0d [gpu] Count ignored rectangle clips so their pop does not pop a real clip
The GPU paint encoder left push_clip_rectangle at the no-op default
while pop_clip unconditionally decremented clip_depth.  COLR emits a
rectangle push/pop pair around every PaintColrGlyph that has a ClipBox,
so that pop removed whatever glyph/path clip sat below it on the stack.
When such a PaintColrGlyph is nested inside a PaintGlyph, the sibling
layers encoded afterwards carried one clip outline too few, painting
ink outside the enclosing outline, or were dropped entirely when they
reached an emitter with clip_depth == 0.

Register a push_clip_rectangle callback that records the push in a
small per-depth counter (rect_clips[d] = rectangles pushed while
clip_depth was d).  pop_clip consumes a non-zero count at the current
depth first and only otherwise pops a real clip.  Rectangle clips are
still left unencoded, exactly as the v1 design notes state; the counter
only keeps the glyph/path clip depth balanced across the ignored pair.
This is correct for any LIFO push/pop order without allocation, and
changes nothing for paint trees without rectangle clips (the top-level
ClipBox in COLR::paint_glyph is already balanced).

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-ZEL64M07.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 16:54:46 -06:00
Behdad Esfahbod 7768296945 [gpu] Skip paint layers with empty clip outlines (#6483)
The draw encoder returns the empty blob for outlines without curves.
Treating it as a clip sub-blob leaves a layer referring to the next
payload or the end of the encoded data. Cache empty glyph and path
clips separately and skip their consuming layers. Preserve the
paint encoder's no-ink contract when only group operations remain,
returning an empty blob with zero extents.

Use fallible blob creation for gradient payloads so allocation failure
cannot produce the same zero-length sub-blob references.

Add an API regression using an ordinary font and paint callbacks,
covering solid and gradient layers, empty paths, groups, and clip slot
reuse. Validate the surviving layer's outline and band references.
The regression fails on the original encoder; the full Meson suite
passes (274 tests).

Reported by Anthropic's OSS Scanner as ANT-2026-5Z1FLVCW.

Assisted-by: OpenAI Codex
2026-10-30 15:07:23 -06:00
Behdad Esfahbod 68641b2aed [limits] Consolidate rendering work budgets
Use HB_BUDGET_GLYPH as the common finite default for VARC and the
in-house draw and paint backends. Raster paint retains its surface-size
scaling so large targets still permit a small number of full passes.

Remove redundant exhaustion checks around hb_budget_spend(). A spend
that lands exactly on zero succeeds; only a negative live value latches
exhaustion. Apply the same boundary consistently to postcharged
renderer work and cover the next positive-cost attempt in tests.

The full Meson suite passes, as do the full TSan suite and the three
rendering regression seeds under ASan and UBSan.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-26 18:34:31 -06:00
Behdad Esfahbod 9a424f1808 [gpu] Share rendering work budgets
Store finite budget policy and live state on GPU draw and paint
contexts. Charge generated curves against the draw context and make
paint-owned scratch draws borrow the paint session's counter.

Propagate the same live counter through both identity clip extraction
and the transforming forwarding pen. Preserve policy across clear and
restore DEFAULT on reset, with focused lifecycle and propagation tests.

The ClusterFuzz GPU timeout seed completes in 0.11 seconds in the
optimized build.

Tests: meson test -C build (273/273 passed)

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-26 17:28:03 -06:00
nussaibah shaikh fde0fd8592 Merge pull request #6164 from Nussu06/gpu-clamp-i16-nan-guard
[gpu] handle NaN in clamp_i16 before int16 cast
2026-08-17 13:50:20 -06:00
Behdad Esfahbod dde1f1baee [gpu] Assign curves to bands using quantized bounds (#6132)
The fragment shader picks one horizontal and one vertical band from
the fragment position and walks only that band's curve list, so a
curve must be listed in every band its bounding box reaches into.

The encoder computed those bounding boxes from the unquantized
control points, but the shader only ever sees the coordinates after
they are rounded to quarter font units.  When rounding pushed a
curve's extreme across a band boundary, the curve was left out of the
band it now reached into.  Fragments landing in that sliver never saw
the curve, so their winding number was off by one and the pixel came
out empty in the middle of a filled area -- a thin black line through
the glyph, appearing and disappearing as the font size moves the
pixel grid.

The rounding error is at most an eighth of a font unit, so this is
invisible for an integer-coordinate glyph rendered at its own upem.
It gets easy to hit when the coordinates are fractional: CFF glyphs
after cu2qu, or any font whose hb_font_t scale is not its upem.  With
hb_font_set_scale(font, 163, 163), as in issue #6131, more than half
of the glyphs of util/gpu/default-font.ttf had at least one band the
shader could reach but that did not list the curve.

Compute the bounds (and the is_horizontal/is_vertical tests) from the
quantized control points instead, and widen the band range by 1/1024
of a band so that the double arithmetic here cannot disagree with the
shader's float32 band index right at a boundary.

Verified with a CPU port of _hb_gpu_slug_single: comparing the banded
lookup against a walk over every curve of the glyph, at sizes 39, 47
and 107 with scale 163, default-font.ttf had 27 wrong pixels before
and none after.  Encoded atlas size grows by 0.12%.

Adds test_encode_band_membership, which checks the invariant directly
on the encoded blob and fails before this change.

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-04 22:41:56 -06:00
nussaibah shaikh 53900fd388 [gpu] bound clip depth in push_clip_path_end (#6073)
push_clip_path_end wrote clip_stack[clip_depth] without the
HB_GPU_PAINT_MAX_CLIP_DEPTH check that push_clip_glyph and
push_clip_path_start both apply. clip_depth can be pushed past
the fixed 3-entry clip_stack, so closing a clip path while the
stack is full writes a pending_clip_t past the array. Guard it
like the sibling clip pushes.
2026-07-21 18:45:53 -06:00
Behdad EsfahbodandClaude Opus 4.6 591748f1e1 [draw][paint] Make get_funcs instance-aware; add get_format
The six public draw / paint funcs getters across raster,
vector, and gpu used to be singletons:

  hb_raster_draw_get_funcs (void)
  hb_raster_paint_get_funcs (void)
  hb_vector_draw_get_funcs (void)
  hb_vector_paint_get_funcs (void)
  hb_gpu_draw_get_funcs (void)
  hb_gpu_paint_get_funcs (void)

That works fine for raster and gpu, where there's a single
backend per type, but breaks for the vector backend where
SVG and PDF have separate funcs sets — callers using the
public getter always got SVG funcs and silently produced
SVG markup inside PDF output streams when invoking the new
arbitrary-path clip API on a PDF context.

Make all six take a const-pointer to the relevant context
instance.  vector_paint dispatches on paint->format; the
other five just use the instance for symmetry today (room
for future format-style dispatch later).

Also expose hb_vector_draw_get_format / hb_vector_paint_
get_format public getters so callers (or third parties)
can ask a vector context for its format without poking at
internals.

Also: hb_vector_paint_push_clip_path_end now wraps the
emitted SVG clipPath's path in transform="scale(1,-1)" so
free-form arbitrary clips at base body level land in the
same coord system the per-glyph <use scale(_,-sy)>
wrappers establish.  Without this, free-form clip-path
arbitrary outlines emitted between paint_glyph calls came
out mirrored across the X axis.

Updates internal callers (hb_vector_paint_glyph,
hb_pdf_emit_glyph_path, hb_raster_paint_push_clip_path_
start, hb_gpu_paint_push_clip_path_start, the GPU pen
adapter), util sites (raster-output.hh, vector-output.hh,
gpu/demo-font.cc), API tests (test-raster.cc, test-gpu.cc),
and the docs section index.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:21:49 -06:00
Behdad EsfahbodandClaude Opus 4.6 98470a3e02 [draw] Rename hb_draw_rect to hb_draw_rectangle
API rename for the not-yet-released stroked/filled
rectangle helper added to hb-draw — full names
(hb_draw_line, hb_draw_circle, hb_draw_rectangle) read
better than mixed full/abbreviated.

Updates the public header, impl, the gpu doc reference,
the GPU API test, the GPU demo's extents overlay, the
extents-overlay paint helper, and the docs section
listing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:18:20 -06:00
Behdad Esfahbod 98f3a42ee2 [vector/raster/gpu] Add *_glyph_or_fail() variants across all three
Consolidate the {vector,raster,gpu}_{draw,paint}_glyph APIs
to match the hb_font_{draw,paint}_glyph / _or_fail pattern:

  * Each existing *_glyph() public function now returns void.
    For the draw variants this is purely a return-value drop.
    For the paint variants the void entry additionally gains a
    synthesize fallback for non-color glyphs (calls
    hb_font_paint_glyph instead of _or_fail) so a mono glyph
    still produces output via a foreground-colored outline.

  * New *_glyph_or_fail() variants return hb_bool_t, reporting
    exactly what hb_font_{draw,paint}_glyph_or_fail() would.
    Callers that care about distinguishing color paint from
    synthesized outline now have a clean boolean signal.

Refactors the internal impls behind a shared static helper
parameterised by a `fallible` flag; the two public entries
delegate, passing true (for _or_fail) or false (for the void
alias).

For GPU specifically, paint_glyph_or_fail no longer folds the
encoder's unsupported flag into its return -- that state was
always better reported from hb_gpu_paint_encode() (which
returns NULL), and conflating the two prevented callers from
telling "font has no paint data" from "encoder hit a limit".

While in there, remove a dead branch at the end of
hb_vector_paint_glyph's SVG case (both inner blocks had
already returned; the tail was unreachable).

Updates docs/harfbuzz-sections.txt with the six new symbols
and the NEWS note with the Changed API callouts.  Updates
in-tree callers (hb-vector-svg-all, hb-raster-all, test-gpu,
util/vector-output.hh) to the _or_fail variants where they
previously read the return value.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/5926

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 00:36:37 -06:00
Behdad Esfahbod fd2a6968ab [draw] hb_draw_line: add cap parameter (butt / square)
Add hb_draw_line_cap_t enum with HB_DRAW_LINE_CAP_BUTT (the
existing default behavior) and HB_DRAW_LINE_CAP_SQUARE, which
extends each endpoint along the line direction by half its
local stroke width.

Square caps let four hb_draw_line() calls form a closed
rectangle without gaps at the corners -- a meaningfully
cheaper alternative to hb_draw_rect() for thin outlined
rectangles, since each line's bbox is just stroke_width tall
instead of covering the full rectangle interior.

Round caps not implemented yet; can be added as a third enum
value when a use case shows up.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-15 02:35:10 -06:00
Behdad Esfahbod e731c38975 [draw] Promote shape helpers from hb-gpu-draw to hb-draw
Three shape-emitting helpers (line, rect, circle) operate on
any hb_draw_funcs_t, not specifically the GPU backend.  Move
them out of the GPU-only API surface into the core hb-draw
API so any pen (raster, vector, gpu, user-supplied) gets
them.

API rename / move:

  hb_gpu_draw_line   -> hb_draw_line   (in src/hb-draw.h)
  hb_gpu_draw_rect   -> hb_draw_rect
  hb_gpu_draw_circle -> hb_draw_circle

Signatures gain a (dfuncs, draw_data, st) prefix to match the
existing hb_draw_move_to / line_to / cubic_to / close_path
shape -- the helpers are thin wrappers over those.

Callers in test/api/test-gpu.cc and util/gpu/demo-font.cc
updated to call hb_draw_* with hb_gpu_draw_get_funcs() and a
local hb_draw_state_t.

Updated harfbuzz-sections.txt with the new entries; removed
hb_gpu_draw_line / _rect / _circle from hb-gpu.h.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-15 02:27:43 -06:00
Behdad Esfahbod cfdcea6c79 [gpu] Add hb_gpu_draw_line / _rect / _circle shape helpers
The GPU draw encoder already consumes arbitrary curves via the
hb_draw_funcs_t machinery -- that's how glyph outlines feed in.
Expose three convenience helpers so callers can emit common
shapes (tapered line, rectangle, circle) without having to
hand-roll the curve math:

    hb_gpu_draw_line   (draw, x0,y0,w0, x1,y1,w1);
    hb_gpu_draw_rect   (draw, x,y,w,h, stroke_width);
    hb_gpu_draw_circle (draw, cx,cy,r, stroke_width);

stroke_width = NaN means "filled".  A finite positive value
produces a stroked outline by emitting an outer contour CCW
and an inner contour CW so the fill rule carves a hole.

For shapes beyond these three helpers, callers can feed any
outline through hb_draw_move_to / _line_to / _quadratic_to /
_cubic_to / _close_path with the funcs from
hb_gpu_draw_get_funcs() and the hb_gpu_draw_t as data -- the
helpers are thin wrappers over that path.

Useful for game UI: health bars, progress rings, custom
line-art decorations, rendered through the same slug shader
as text.

Assisted-by: Claude <noreply@anthropic.com>
2026-04-15 01:54:08 -06:00
Behdad Esfahbod a01bd008ad [gpu] paint_encode: empty-blob singleton for "no ink" (match draw)
hb_gpu_draw_encode already returns the empty-blob singleton (not
NULL) when the encoder has accumulated no curves -- the convention
is "NULL = encoder failed, empty blob = nothing to render".

Make hb_gpu_paint_encode follow the same shape:
  - NULL  -> hard failure (paint_glyph hit an unsupported feature
             or allocation failed).
  - empty -> no ink (e.g. space glyph or paint tree that produced
             no layer ops).

Document on both encode functions, and update the tests to expect
empty (not NULL) for the no-ink path.

The demo already short-circuits on length 0 (no atlas upload) and
_hb_gpu_blob_recycle drops the empty singleton instead of stashing
it, so nothing downstream needs to change.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 18:50:16 -06:00
Behdad Esfahbod b38c5189df [gpu] Detect paint-encoder limits, fail rather than misrender
Paint encoder used to push past several limits and produce a blob
that wraps an int16, overflows the shader's group stack, or skips
unsupported callbacks entirely.  Detect each:

- num_ops > 32767 (the i16 blob header field's range): set
  paint->unsupported in every emit path.
- group depth > HB_GPU_PAINT_MAX_GROUP_DEPTH (4 -- matches the
  fragment shader's HB_GPU_PAINT_GROUP_DEPTH): set unsupported
  in push_group; mirror the symmetric pop guard.
- PaintImage: register an `image` callback that sets unsupported
  (the slug+gradient encoder can't represent raster images).

push_clip_rectangle is intentionally NOT trapped -- the encoder
silently ignores it; rendered output is wider than the rectangle
asks but doesn't fail.

Nested PaintGlyph clips still silently override the outer clip
(only depth 1 is faithfully stored); follow-up commit will lift
this to depth 2.

Document all of the above in NEWS, and relax the COLR test to
tolerate a font where every glyph trips one of these limits.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 18:45:35 -06:00
Behdad Esfahbod d235a23b45 [test/api] Silence cast-align in test-gpu blob accessors
Casting hb_blob_get_data()'s const char* to a struct pointer
trips clang's -Wcast-align (1-byte to 2-byte short).  In practice
the blob's underlying buffer is malloc'd and so suitably aligned
for any standard type; suppress the warning around the cast with
the same #pragma GCC diagnostic ignored "-Wcast-align" pattern
used elsewhere in the codebase (hb-bit-set.hh, hb-machinery.hh).

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 16:26:01 -06:00
Behdad Esfahbod 157e5111b3 [gpu] Add tests + benchmark for hb_gpu_paint, NEWS draft
test/api/test-gpu: extends the existing draw test suite with
paint counterparts -- create/destroy, get_funcs singleton,
shader_source for all four langs, empty encode returns nullptr,
encode of a monochrome glyph (synthesized single-layer fallback),
encode of a real COLRv1 glyph (test_glyphs-glyf_colr_1.ttf,
scanning for a glyph our encoder fully supports), auto-clear on
encode, reset wipes config, recycle_blob roundtrip.

perf/benchmark-gpu: add BM_GpuPaintEncode parallel to
BM_GpuDrawEncode (renamed from BM_GpuEncode for symmetry) so the
two paths can be compared on the same fonts.

NEWS: draft entry under "leading to NEXT (REPLACEME)" listing the
new hb_gpu_paint_* API surface and the recent GPU library changes
(--draw / --paint flags, gradient inverse-transform).  Release
manager will fold this into the actual release section.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 16:00:51 -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 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 b5287cb3fb [gpu] Clamp exported draw extents
hb_gpu_draw_get_extents() cast rounded bounds to hb_position_t
before subtracting them. A fuzzed glyph outline with an extreme
negative bound could therefore overflow signed int arithmetic while
forming width or height.

Compute the rounded bounds in double, reject non-finite values, and
clamp the exported extents to hb_position_t before returning them.
Add an API regression that covers the OSS-Fuzz testcase through the
public GPU draw API.

Fixes: https://oss-fuzz.com/testcase-detail/5918954634936320
Tested: meson test -C build --print-errorlogs
Assisted-by: OpenAI Codex
2026-04-09 23:15:34 -06:00
Behdad Esfahbod 3b7ee09f0e [gpu] Fix draw encode blob ownership leaks
hb_gpu_draw_encode() could allocate a fresh output buffer and then
return NULL before transferring ownership to a blob, leaking that
temporary buffer on late encode failures.

The recycled-blob growth path also tried hb_realloc() first and fell
back to hb_malloc() when that failed. Once the new buffer was committed
to the recycled blob, the old recycled buffer could be orphaned.

Free temporary buffers on the remaining late-failure exits and keep
the old recycled buffer alive until a replacement has been committed.
Tighten the GPU API recycle test to encode a larger second outline so
that reused-buffer growth stays covered.

Tested:
- meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
2026-04-04 19:44:54 -06:00
Behdad EsfahbodandOpenAI Codex a4aff49856 [gpu] Fix contour breaks and bounds quantization in encode (#5892)
Encode used adjacent endpoint equality to infer contour breaks, which
fails when two contours touch at the same point. Track contour starts
explicitly during accumulation instead, and use that flag when packing
shared endpoints.

Encode also rounded blob bounds to the nearest quarter unit. That can
shrink the encoded extents and clip coverage at glyph edges. Quantize
mins downward and maxes upward so the blob header always encloses the
actual geometry.

Add focused API tests for both regressions.

Testing:
- meson test -C build

Co-authored-by: OpenAI Codex <codex@openai.com>
2026-04-03 12:09:02 -06:00
Behdad EsfahbodandClaude Opus 4.6 d46f8e3444 [gpu] Rename HB_GPU_SHADER_GLSL_330 to HB_GPU_SHADER_LANG_GLSL
The shader source is compatible with both GLSL 3.30 and
GLSL ES 3.00.  Rename the enum value to reflect this and
match the type name convention.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 00:40:11 -06:00
Behdad EsfahbodandClaude Opus 4.6 0582846c08 [gpu] Simplify shader API: return single string per language
Change hb_gpu_shader_{fragment,vertex}_sources() (array + count)
to hb_gpu_shader_{fragment,vertex}_source() returning a single
const char *.  Each language variant is one complete string.

Simplifies the demo shader compilation and documentation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 17:10:04 -06:00
Behdad EsfahbodandClaude Opus 4.6 971e607319 [gpu] Add API test and google-benchmark encode benchmark
test-gpu: 7 subtests covering create/destroy, empty encode,
glyph encode, reset, draw funcs singleton, shader sources,
and recycle_blob.

benchmark-gpu: benchmarks draw, encode, and draw+encode
per-glyph across several fonts using google-benchmark.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 22:27:40 -06:00