[perf][HIGH] UI tiles scan the full item list — no spatial culling #46

Closed
opened 2026-06-16 16:51:30 +02:00 by jorijnvdgraaf · 0 comments

Subsystem: UI compute pipeline + GLSL shaders
Location: shaders/ui-quads.comp.glsl:21-48 (verbatim in ui-circles:18-45, ui-images:18-40, ui-text:28-62)
Impact: HIGH · Effort: Large

Problem

Each 8x8-tile workgroup iterates the entire item list with a per-pixel AABB reject. At 1080p that is 32,400 tiles each walking the whole buffer — O(tiles x N) item loads, nearly all rejected at the branch but still paying the SSBO read + math. Dominant GPU cost for typical UIs.

Proposed fix

coarse tile-binning pre-pass appends item indices to per-tile lists; render shaders iterate only their tile's items. The existing compute->compute barrier in Dispatch already gives binning->render visibility for free.

Correctness caveat (load-bearing)

Binning must preserve draw order (ui-shared.glsl:109-118: later items overdraw earlier). A naive atomic-append bin produces nondeterministic order — a blending bug. Use counting-sort / prefix-sum binning, or sort each tile's indices ascending by original item index. The interim shared-memory fix has no such hazard.

**Subsystem:** UI compute pipeline + GLSL shaders **Location:** `shaders/ui-quads.comp.glsl:21-48` (verbatim in `ui-circles:18-45`, `ui-images:18-40`, `ui-text:28-62`) **Impact:** HIGH · **Effort:** Large ### Problem Each 8x8-tile workgroup iterates the entire item list with a per-pixel AABB reject. At 1080p that is 32,400 tiles each walking the whole buffer — O(tiles x N) item loads, nearly all rejected at the branch but still paying the SSBO read + math. Dominant GPU cost for typical UIs. ### Proposed fix coarse tile-binning pre-pass appends item indices to per-tile lists; render shaders iterate only their tile's items. The existing compute->compute barrier in `Dispatch` already gives binning->render visibility for free. ### Correctness caveat (load-bearing) Binning **must preserve draw order** (`ui-shared.glsl:109-118`: later items overdraw earlier). A naive atomic-append bin produces nondeterministic order — a blending bug. Use counting-sort / prefix-sum binning, or sort each tile's indices ascending by original item index. The interim shared-memory fix has no such hazard.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Catcrafts/Crafter.Graphics#46
No description provided.