mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-30 01:54:21 +01:00
Merge pull request #6515 from harfbuzz/scanner/gpu
[gpu] Fix clip-pop imbalance and bound cu2qu / per-layer shader work
This commit is contained in:
4 files changed
+170
-2
No files matched your search
@@ -170,6 +170,13 @@ hb_gpu_cubic_to_quadratics (hb_gpu_draw_t *g,
|
||||
hb_gpu_cu2qu_point_t c3,
|
||||
double tolerance, unsigned depth)
|
||||
{
|
||||
/* Charge one unit per node for its fit test and split, and stop once
|
||||
* the accumulator has failed or the work budget is spent: whatever we
|
||||
* would emit from here is dropped by acc_emit() anyway. */
|
||||
if (unlikely (!g->success ||
|
||||
!hb_budget_spend (*g->get_budget_remaining (), HB_BUDGET_1)))
|
||||
return;
|
||||
|
||||
hb_gpu_cu2qu_point_t q1;
|
||||
if (hb_gpu_cubic_approx_quadratic (c0, c1, c2, c3, tolerance, &q1))
|
||||
{
|
||||
|
||||
+42
-1
@@ -104,9 +104,35 @@ hb_gpu_paint_pop_clip (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_gpu_paint_t *c = (hb_gpu_paint_t *) paint_data;
|
||||
|
||||
/* A rectangle clip pushed at this depth is popped before the
|
||||
* glyph/path clip below it; its pop leaves clip_depth alone. */
|
||||
unsigned &rects = c->rect_clips[hb_min (c->clip_depth, (unsigned) HB_GPU_PAINT_MAX_CLIP_DEPTH)];
|
||||
if (rects)
|
||||
{
|
||||
rects--;
|
||||
return;
|
||||
}
|
||||
|
||||
if (likely (c->clip_depth > 0)) c->clip_depth--;
|
||||
}
|
||||
|
||||
/* Clip rectangles are not encoded in v1 (see the design notes in
|
||||
* hb-gpu-paint.hh). Only count the push so that the matching
|
||||
* pop_clip does not pop the glyph/path clip below it. */
|
||||
static void
|
||||
hb_gpu_paint_push_clip_rectangle (hb_paint_funcs_t *funcs HB_UNUSED,
|
||||
void *paint_data,
|
||||
float xmin HB_UNUSED,
|
||||
float ymin HB_UNUSED,
|
||||
float xmax HB_UNUSED,
|
||||
float ymax HB_UNUSED,
|
||||
void *user_data HB_UNUSED)
|
||||
{
|
||||
hb_gpu_paint_t *c = (hb_gpu_paint_t *) paint_data;
|
||||
c->rect_clips[hb_min (c->clip_depth, (unsigned) HB_GPU_PAINT_MAX_CLIP_DEPTH)]++;
|
||||
}
|
||||
|
||||
/* Arbitrary-path clip: hand the caller the same hb_gpu_draw
|
||||
* funcs the encoder uses for glyph outlines, with scratch_draw
|
||||
* as the accumulator. push_clip_path_end encodes the captured
|
||||
@@ -585,7 +611,8 @@ emit_clip_sub_blob (hb_gpu_paint_t *c,
|
||||
/* Emit a sub-blob for every clip currently on the stack and return
|
||||
* their indices in @out (set to -1 for unused slots). Returns
|
||||
* false if any clip's outline is empty (caller should skip the
|
||||
* layer entirely) or hb_gpu_draw_encode failed. */
|
||||
* layer entirely), hb_gpu_draw_encode failed, or the session
|
||||
* budget is exhausted. */
|
||||
static bool
|
||||
emit_all_clip_sub_blobs (hb_gpu_paint_t *c, int out[HB_GPU_PAINT_MAX_CLIP_DEPTH])
|
||||
{
|
||||
@@ -596,6 +623,18 @@ emit_all_clip_sub_blobs (hb_gpu_paint_t *c, int out[HB_GPU_PAINT_MAX_CLIP_DEPTH]
|
||||
out[i] = emit_clip_sub_blob (c, c->clip_stack[i]);
|
||||
if (out[i] < 0)
|
||||
return false;
|
||||
|
||||
/* The memoized clip outline is encoded once however many layers
|
||||
* share it, but the fragment shader walks its band tables again
|
||||
* for every layer painted under it. Charge each reference to the
|
||||
* session budget, in RGBA16I texels, so the layer count cannot
|
||||
* multiply with the clip size past it. */
|
||||
unsigned texels = hb_blob_get_length (c->sub_blobs.arrayZ[out[i]]) / 8;
|
||||
if (unlikely (!hb_budget_spend (c->budget_remaining, HB_BUDGET_1, texels)))
|
||||
{
|
||||
c->unsupported = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1084,6 +1123,7 @@ static struct hb_gpu_paint_funcs_lazy_loader_t
|
||||
hb_paint_funcs_set_push_transform_func (funcs, hb_gpu_paint_push_transform, nullptr, nullptr);
|
||||
hb_paint_funcs_set_pop_transform_func (funcs, hb_gpu_paint_pop_transform, nullptr, nullptr);
|
||||
hb_paint_funcs_set_push_clip_glyph_func (funcs, hb_gpu_paint_push_clip_glyph, nullptr, nullptr);
|
||||
hb_paint_funcs_set_push_clip_rectangle_func (funcs, hb_gpu_paint_push_clip_rectangle, nullptr, nullptr);
|
||||
hb_paint_funcs_set_push_clip_path_start_func (funcs, hb_gpu_paint_push_clip_path_start, nullptr, nullptr);
|
||||
hb_paint_funcs_set_push_clip_path_end_func (funcs, hb_gpu_paint_push_clip_path_end, nullptr, nullptr);
|
||||
hb_paint_funcs_set_pop_clip_func (funcs, hb_gpu_paint_pop_clip, nullptr, nullptr);
|
||||
@@ -1646,6 +1686,7 @@ hb_gpu_paint_clear (hb_gpu_paint_t *paint)
|
||||
paint->sub_blobs.reset ();
|
||||
paint->sub_bytes = 0;
|
||||
paint->clip_depth = 0;
|
||||
hb_memset (paint->rect_clips, 0, sizeof (paint->rect_clips));
|
||||
paint->pending_clip_path = false;
|
||||
paint->unsupported = false;
|
||||
paint->recharge_budget ();
|
||||
|
||||
+10
-1
@@ -287,7 +287,8 @@ struct hb_gpu_paint_t
|
||||
|
||||
/* 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
|
||||
* (outline traversal, the curves generated from it, and the clip
|
||||
* outline texels the fragment shader walks per layer -- 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. */
|
||||
@@ -325,6 +326,14 @@ struct hb_gpu_paint_t
|
||||
pending_clip_t clip_stack[3];
|
||||
unsigned clip_depth = 0;
|
||||
|
||||
/* Rectangle clips are not encoded (see "Out of scope for v1"),
|
||||
* but their pop_clip must not pop the glyph/path clip below them.
|
||||
* rect_clips[d] counts the rectangle clips pushed while clip_depth
|
||||
* was d; the paint walk pops them before anything at depth d, so
|
||||
* a non-zero count at the current depth identifies a rectangle
|
||||
* pop. The last slot collects everything pushed past the cap. */
|
||||
unsigned rect_clips[3 + 1] = {};
|
||||
|
||||
/* Carries the cur_transform captured at push_clip_path_start
|
||||
* through to push_clip_path_end, where the encoded clip is
|
||||
* committed to clip_stack. */
|
||||
|
||||
Reference in new issue
Block a user