Skip to content

perf: render-perf stack (CacheRenderer sticky + E14 batching foundation) - #35

Draft
roncarbot wants to merge 9 commits into
devfrom
feature/render-perf
Draft

perf: render-perf stack (CacheRenderer sticky + E14 batching foundation)#35
roncarbot wants to merge 9 commits into
devfrom
feature/render-perf

Conversation

@roncarbot

@roncarbot roncarbot commented Sep 9, 2026

Copy link
Copy Markdown

Summary

Render-perf branch for Coolmath Diggy / FireBoy Chromebook work.

Kept earlier

  • E1 traverse GC, E4 CacheRenderer scene-transform skip, E6 timing, E8 sticky contentDirty / markContentDirty
  • E14 foundation: opaque solid atlas sort / depthOrder / opt-in VB merge (default off)

E15 VB-merge correctness + cache

  • Bake: world-space renderSceneTransform (+ depthOrder) into positions; upload view.viewMatrix3D with AGAL transpose. Full MVP→Float3 dropped clip.w (empty Diggy).
  • Merge gates: same ColorTransform + same Style images/samplers (atlas pages); curves/joints/animators rejected; opaque list only (blended stays 1:1).
  • Painter batch: DRAWCALL_BATCH_DISABLE_DEPTH default true; skip opaque material sort while batching (depth-in-batch ate Diggy detail).
  • Cache: bit-exact dual-hash signature → cached dynamic TriangleElements; soft eviction (no dispose); scratch path when cache off. Kill-switches via __AWAY_RENDER_SETTINGS__.
  • Default: ALLOW_DRAWCALL_BATCHING=false — Diggy title visual OK when forced on (logo orange≈4800), native msDraw ~0.9 / draws 233→36, but swiftshader-cpu4x msDraw regresses (~23 vs ~3) from per-frame merge/signature walk.

Numbers (Diggy title)

OFF ON (forced)
native draws / msDraw 233 / 0.75 36 / 0.86
native median ms 1.7 1.6
swiftshader-cpu4x msDraw 2.92 22.9 (regress)
swiftshader-cpu4x median 7.2 30
Visual Diggy logo OK OK (after E15)

Companion: awayjs/graphics#14 (opaque solid atlas; unchanged this turn).

SHA: 37780cb

Reuse opaque/blended renderable arrays, use cached entity.maskOwners
in draw batching, and project zIndex without Vector3D.subtract allocs.
Parent/scene matrix changes only move the blit quad (local node is
transformDisabled). Avoid invalidatePasses/full RTT rebuild; refresh
blit elements/style only. Child content still invalidates via materials.

Also expose lightweight __AWAY_PERF__ composition counters for the
render-perf harness (opaque/blended/materialRuns/cacheRenders).
@roncarbot

Copy link
Copy Markdown
Author

E4 follow-up (75b0693)

CacheRenderer scene-transform: no longer calls full onInvalidate() / invalidatePasses() when the parent matrix changes. Local node is transformDisabled, so RTT content is unchanged — only the blit quad needs refresh.

Harness counters: window.__AWAY_PERF__ exposes opaque/blended/materialRuns/maskSwitches/cacheRenders/draws per frame.

Diggy title (localhost:8080)

Metric E1+E2 E3+E4
median frame ms 99.9 83.4
draw/frame 233 233
awayPerf opaque=0 blended=233 materialRuns=17 cacheRenders=0

Frame win is from stage activeTexture skip (E3) on SwiftShader; Diggy title has zero CacheRenderer RTTs so E4 is latent until filtered gameplay.

Draw-cut investigation (Diggy)

  • All 233 draws are blended; opaque sort N/A
  • same-elements consecutive streaks ≈ 0 → instancing within material runs won't help title
  • Real draw reduction needs geometry merge/atlas or content-side cacheAsBitmap

roncarbot and others added 2 commits September 9, 2026 03:14
Diggy title profile: AVM+traverse+draw busy ~2ms while rAF gap ~83ms
(compositor backpressure from ~233 blended draws). Timers help harness
split CPU vs wait; optional __AWAY_PERF_FINISH__ for gl.finish probe.
Only rebuild RTT when bitmap contents change (child materials, color,
filters). Parent partition invalidates refresh the blit quad without
re-traversing. Holds Diggy whole-title cacheAsBitmap sticky (E8).
@roncarbot

Copy link
Copy Markdown
Author

E8 sticky CacheRenderer (contentDirty / markContentDirty) pushed: 1f50baac.

Diggy engine-path (real setter, not harness _bitmapCache hack):

mode median ms draws cacheRenders
baseline 83.3 233 0
per-child 16.7 ~11 0
whole-title 16.7 ~2 0

Companion PRs: view + scene feature/render-perf (localNode invalidate bubble + HONOR_CACHE_AS_BITMAP / timeline no-op mtx).

@roncarbot roncarbot changed the title perf: cut per-frame GC in traverse/draw hot path perf: sticky CacheRenderer + traverse GC / timing (render-perf) Sep 9, 2026
… merge)

Add DrawCallBatcher (uvMatrix + MVP bake) behind ALLOW_DRAWCALL_BATCHING
(default false — prototype cuts Diggy title draws 233→21 but is SWF-unsafe
and CPU-heavy on weak profiles). Wire opaque material-sort on the array path,
depthOrder Z encoding, and expose __AWAY_RENDER_SETTINGS__ for harness A/B.
@roncarbot roncarbot changed the title perf: sticky CacheRenderer + traverse GC / timing (render-perf) perf: render-perf stack (CacheRenderer sticky + E14 batching foundation) Sep 9, 2026
roncarbot and others added 4 commits September 9, 2026 14:56
…ache)

Fix Diggy-corrupting drawcall batcher: world-space bake + AGAL-transposed
view upload (full MVP Float3 bake dropped clip.w); same-atlas image gate;
opaque-only merge; depth-off painter order inside merged VB (skip opaque
sort while batching); bit-exact signature cache with soft eviction.
ALLOW_DRAWCALL_BATCHING stays default false — native draw 233→36 / msDraw
OK, but swiftshader-cpu4x still msDraw-regresses on merge walk.
Skip tryAdd/merge rebuild for the static opaque prefix when content
fingerprint matches; per-batch replay resumes at the first dirty span.
Keeps Diggy title draw cut when batching is forced on. Default batching
remains OFF — swiftshader-cpu4x still regresses on merged VB raster.
Kill-switches for SwiftShader merge-raster investigate:
- DRAWCALL_BATCH_MAX_VERTS / MAX_MERGE (split oversized VBs)
- DRAWCALL_BATCH_FRONT_TO_BACK (reverse IB + depth ON)
- Perf: batchVerts/Idx, uploadBytes, maxBatchVerts

Default ALLOW_DRAWCALL_BATCHING remains false.
Diggy title tessellation can change numVertices under a stable
elems.id/transform while E16 keeps recorded batch ops across partial
skips after fingerprint refresh — replaying oversized/undersized VBs
inflated batchVerts by ~50–60k and risked holes. Validate baked
vertCount vs current source sum before replay (missReason 33).

ALLOW_DRAWCALL_BATCHING remains default false.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant