From 76eccd5f2771b94e401e629098c2d9b52abff7bf Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 27 Aug 2026 17:00:41 -0600 Subject: [PATCH] [gpu] Share the work budget through the public draw API hb_gpu_paint reached into the scratch encoder by writing its external_budget pointer directly, so a whole paint session could share one work counter. Drive that sharing through the public draw-budget API instead: seed the scratch encoder with hb_draw_set_budget() before each clip glyph (and before a client-drawn clip path) and read the remainder back with hb_draw_get_budget_remaining(), so the COLR walk aggregates its work without touching encoder internals. The transforming pen now exposes the scratch encoder's own live counter rather than the paint session's. Unlike the rasterizer, the GPU backend never rasterizes -- it emits slug curves for the GPU to fill later -- so all of its work is outline-derived (traversal plus the curves generated from it) and one budget suffices; no separate pixel budget applies here. Remove the now-unused external_budget field and its write-through in hb_gpu_draw_set_budget(). Tests: meson test -C build (275/275 passed); the CFF/COLR gpu-fuzzer regression seed completes in 0.46s. The existing budget test already covers both the identity and transforming-pen clip paths. Assisted-by: Claude --- src/hb-gpu-draw.cc | 3 --- src/hb-gpu-draw.hh | 9 +++++---- src/hb-gpu-paint.cc | 19 ++++++++++++++++--- src/hb-gpu-paint.hh | 9 ++++++--- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/hb-gpu-draw.cc b/src/hb-gpu-draw.cc index 246988786..9a998f949 100644 --- a/src/hb-gpu-draw.cc +++ b/src/hb-gpu-draw.cc @@ -246,8 +246,6 @@ hb_gpu_draw_set_budget (hb_draw_funcs_t *, void *draw_data, auto *draw = (hb_gpu_draw_t *) draw_data; draw->budget = budget; draw->recharge_budget (); - if (draw->external_budget) - *draw->external_budget = draw->budget_remaining; return true; } @@ -1130,7 +1128,6 @@ hb_gpu_draw_clear (hb_gpu_draw_t *draw) draw->ext_max_x = -HUGE_VAL; draw->ext_max_y = -HUGE_VAL; - draw->external_budget = nullptr; draw->recharge_budget (); } diff --git a/src/hb-gpu-draw.hh b/src/hb-gpu-draw.hh index b20f26803..f2d717019 100644 --- a/src/hb-gpu-draw.hh +++ b/src/hb-gpu-draw.hh @@ -110,11 +110,12 @@ struct hb_gpu_draw_t int x_scale = 0; int y_scale = 0; - /* Cumulative work budget for the current draw session. Paint-owned - * scratch draws borrow the paint session's live counter. */ + /* Work budget for outline traversal and generated curves. A paint + * backend seeds this through the public draw-budget API before drawing + * and reads the remainder back afterwards, so a whole paint session + * shares one budget without reaching into this object. */ int64_t budget = HB_BUDGET_DEFAULT; int64_t budget_remaining = HB_BUDGET_GLYPH; - int64_t *external_budget = nullptr; void recharge_budget () { @@ -123,7 +124,7 @@ struct hb_gpu_draw_t } int64_t *get_budget_remaining () - { return external_budget ? external_budget : &budget_remaining; } + { return &budget_remaining; } /* Encode scratch (reused across calls) */ hb_gpu_encode_scratch_t scratch; diff --git a/src/hb-gpu-paint.cc b/src/hb-gpu-paint.cc index 78569dd88..eeeec1e55 100644 --- a/src/hb-gpu-paint.cc +++ b/src/hb-gpu-paint.cc @@ -136,7 +136,10 @@ hb_gpu_paint_push_clip_path_start (hb_paint_funcs_t *funcs HB_UNUSED, } hb_gpu_draw_clear (c->scratch_draw); - c->scratch_draw->external_budget = &c->budget_remaining; + /* Seed the scratch encoder's budget from the session's remainder; it is + * read back in push_clip_path_end after the caller has drawn the path. */ + hb_draw_set_budget (hb_gpu_draw_get_funcs (c->scratch_draw), c->scratch_draw, + c->budget_remaining); hb_gpu_draw_set_scale (c->scratch_draw, c->x_scale, c->y_scale); c->pending_clip_path_transform = c->cur_transform; @@ -157,6 +160,10 @@ hb_gpu_paint_push_clip_path_end (hb_paint_funcs_t *funcs HB_UNUSED, return; c->pending_clip_path = false; + /* Pull back the outline budget the caller's path draw consumed. */ + c->budget_remaining = hb_draw_get_budget_remaining (hb_gpu_draw_get_funcs (c->scratch_draw), + c->scratch_draw); + hb_glyph_extents_t ext; hb_blob_t *blob = hb_gpu_draw_encode (c->scratch_draw, &ext); if (unlikely (!blob || !c->sub_blobs.push_or_fail (blob))) @@ -474,7 +481,11 @@ emit_clip_sub_blob (hb_gpu_paint_t *c, } } hb_gpu_draw_clear (c->scratch_draw); - c->scratch_draw->external_budget = &c->budget_remaining; + /* Seed the scratch encoder's budget from the session's remainder and + * read it back after the glyph is drawn, so the whole paint walk shares + * one budget through the public draw-budget API. */ + hb_draw_set_budget (hb_gpu_draw_get_funcs (c->scratch_draw), c->scratch_draw, + c->budget_remaining); bool ok; if (clip.transform.is_identity ()) @@ -498,7 +509,7 @@ emit_clip_sub_blob (hb_gpu_paint_t *c, pen.dfuncs = hb_gpu_draw_get_funcs (c->scratch_draw); pen.data = c->scratch_draw; pen.down_st = HB_DRAW_STATE_DEFAULT; - pen.budget_remaining = &c->budget_remaining; + pen.budget_remaining = &c->scratch_draw->budget_remaining; ok = hb_font_draw_glyph_or_fail (clip.font, clip.glyph, static_gpu_paint_pen_funcs.get_unconst (), &pen); @@ -506,6 +517,8 @@ emit_clip_sub_blob (hb_gpu_paint_t *c, * hb_font_draw_glyph_or_fail only closes via our pen's state. */ pen.dfuncs->close_path (pen.data, pen.down_st); } + c->budget_remaining = hb_draw_get_budget_remaining (hb_gpu_draw_get_funcs (c->scratch_draw), + c->scratch_draw); if (!ok) return -1; /* Clip glyph has no outline -- skip. */ diff --git a/src/hb-gpu-paint.hh b/src/hb-gpu-paint.hh index 0c05b3066..27148817a 100644 --- a/src/hb-gpu-paint.hh +++ b/src/hb-gpu-paint.hh @@ -273,9 +273,12 @@ struct hb_gpu_paint_t * which matches HB_GPU_PAINT_GROUP_DEPTH in the fragment shader. */ unsigned group_depth = 0; - /* Cumulative work budget for the current paint session; reset by - * hb_gpu_paint_clear(). Outline traversal and generated curves - * charge the same live counter. */ + /* Work budget for the current paint session; reset by + * hb_gpu_paint_clear(). All the session's work is outline-derived + * (outline traversal and the curves generated from it -- the GPU + * backend never rasterizes), so a single counter suffices. It is the + * public draw/paint budget: seeded into the scratch encoder through the + * public draw-budget API before each glyph and read back afterwards. */ int64_t budget = HB_BUDGET_DEFAULT; int64_t budget_remaining = HB_BUDGET_GLYPH;