[perf] Hoist per-item/per-glyph loop-invariant math into shared memory at load (ui-images/text/fused) #125
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Catcrafts/Crafter.Graphics#125
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found by an adversarially-verified performance audit (confirmed real after a skeptic pass).
This issue covers hoisting loop-invariant per-item / per-glyph math out of the per-pixel inner loop into shared memory at cooperative-load time — the same technique applied in the same cooperative-load sections, so it's one pass through the shaders. (Merged from the former #126.)
Severity: medium · Effort: moderate · Category: gpu
Problem
shaders/ui-images.comp.glsl:70-71(alsoui-text.comp.glsl:76,ui-fused.comp.glsl:252,302):(sp - rect.xy) / rect.zwrecomputes a vec2 reciprocal per pixel per item.rect.zwis loaded once per item into shared memory and is loop-invariant, but the compiler can't hoist it (shared mem, varying index).ui-text.comp.glsl:93-98(alsoui-fused.comp.glsl:315-318):uvSpan/atlasPerScreen/scalePx/banddepend only on the glyph yet are computed per pixel-glyph (a divide + two maxes).Both recompute, per pixel, values that are constant for the whole item/glyph.
Fix
During the cooperative load, precompute into shared slots once per item/glyph:
invRectSize = 1.0/rect.zw, thent = (sp - rect.xy) * invRectSize;bandinto afloat[UI_CHUNK]shared slot.Both edits land in the same cooperative-load section of
ui-text/ui-fused(andui-imagesfor the rect part). Minor LDS pressure increase.Note
The SDF-band part (2) is marginal on its own — the inner loop is dominated by the SDF
texture()fetch — but it rides along for free with the rect-reciprocal hoist (1) since it's the same load-section edit.[perf] Per-pixel divide by item-constant rect size in inner loop (ui-images.comp.glsl)to [perf] Hoist per-item/per-glyph loop-invariant math into shared memory at load (ui-images/text/fused)