perf(ui): gate per-pixel clip compares behind a flags bit (#50) #91

Merged
catbot merged 2 commits from claude/issue-50 into master 2026-06-16 18:59:48 +02:00
Member

Summary

uiResolveScreenPixel ran four float compares against hdr.clipRectPx for every pixel of every UI dispatch, even though the clip rect is the full-surface default {0,0,1e9,1e9} in the overwhelmingly common case (issue #50).

This reserves the high bit of the header flags word (UI_FLAG_CLIP) and gates the clip compares on it:

  • UIRenderer::FillHeader now sets the bit only when the clip rect is narrower than the surface. The decision is extracted into the pure, unit-testable UIRenderer::ClipFlags.
  • The shader branch is push-constant-uniform across the dispatch, so it never diverges.
  • When the rect covers the surface, the skipped compares could never have rejected an in-surface pixel — output is pixel-identical.
  • User flag bits are preserved; only the reserved high bit is touched.

The same gate is mirrored on the WebGPU/WGSL path (additional/dom-webgpu.js) for parity. The frozen-layout contract is respected — this is an additive use of the reserved flags bits.

Testing

  • New UIClipFlag CPU test drives ClipFlags directly (full-surface vs. each narrowed edge, user-flag preservation, stale-bit clearing) — no Window/GPU needed.
  • All four standard UI compute shaders + the CustomShader example recompile cleanly with glslang.
  • crafter-build test8 passed.

Resolves #50

🤖 Generated with Claude Code

## Summary `uiResolveScreenPixel` ran four float compares against `hdr.clipRectPx` for every pixel of every UI dispatch, even though the clip rect is the full-surface default `{0,0,1e9,1e9}` in the overwhelmingly common case (issue #50). This reserves the high bit of the header `flags` word (`UI_FLAG_CLIP`) and gates the clip compares on it: - `UIRenderer::FillHeader` now sets the bit **only** when the clip rect is narrower than the surface. The decision is extracted into the pure, unit-testable `UIRenderer::ClipFlags`. - The shader branch is push-constant-uniform across the dispatch, so it never diverges. - When the rect covers the surface, the skipped compares could never have rejected an in-surface pixel — output is **pixel-identical**. - User flag bits are preserved; only the reserved high bit is touched. The same gate is mirrored on the WebGPU/WGSL path (`additional/dom-webgpu.js`) for parity. The frozen-layout contract is respected — this is an additive use of the reserved `flags` bits. ## Testing - New `UIClipFlag` CPU test drives `ClipFlags` directly (full-surface vs. each narrowed edge, user-flag preservation, stale-bit clearing) — no Window/GPU needed. - All four standard UI compute shaders + the CustomShader example recompile cleanly with glslang. - `crafter-build test` — **8 passed**. Resolves #50 🤖 Generated with [Claude Code](https://claude.com/claude-code)
uiResolveScreenPixel ran four float compares against hdr.clipRectPx for
every pixel of every UI dispatch, even though the clip rect is the
full-surface default {0,0,1e9,1e9} in the overwhelmingly common case.

Reserve the high bit of the header flags word (UI_FLAG_CLIP) and have
FillHeader set it only when the clip rect is narrower than the surface
(extracted into the unit-testable UIRenderer::ClipFlags). The shader
gates the compares on the bit; the branch is push-constant-uniform so it
never diverges. When the rect covers the surface the skipped compares
could never reject an in-surface pixel, so output is pixel-identical.

Mirrored on the WebGPU/WGSL path (dom-webgpu.js) for parity. Adds the
UIClipFlag CPU test covering the gate decision.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
catbot merged commit 508f119cc6 into master 2026-06-16 18:59:48 +02:00
catbot deleted branch claude/issue-50 2026-06-16 18:59:48 +02:00
Sign in to join this conversation.
No reviewers
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!91
No description provided.