Repository navigation
fix(mesh-layers): signal ScenegraphLayer first draw once every model drew (1/2) - #11150
charlieforward9 wants to merge 4 commits into
Conversation
…drew ScenegraphLayer called onFirstDraw after its first draw even when luma skipped a model's draw because its resources, such as glTF textures, were not ready. Tile3DLayer marks the tile as drawn there, so loaders.gl released the tile's fallback parent before the replacement was visible. Signal onFirstDraw only after every model's draw (or column batch draw) returned true, and request another frame until it does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
[Medium impact] The change affects first-draw timing for scenegraph layers and tile replacement transitions. The PR appears safe to merge, with a non-blocking gap in coverage of the column draw result. Findings
Summary
|
| const draw = vi.fn().mockReturnValueOnce(false).mockReturnValue(true); | ||
| layer.state = { | ||
| scenegraph: new GroupNode([makeModelNode([])]), | ||
| columns: {loading: false, length: 1, draw} |
There was a problem hiding this comment.
Column draw result goes untested
This test replaces LayerColumns.draw with a mock, so it never checks the changed return path through model.drawBatches. Removing the new return would leave these tests passing while column-backed layers stop calling onFirstDraw.
Add a direct LayerColumns.draw test that checks both false and true results from drawBatches, plus the empty-column result.
athomct
left a comment
There was a problem hiding this comment.
Head 2e3d708. Base master. Verdict: comment (approve after findings 1 and 2).
Summary
This PR makes ScenegraphLayer call onFirstDraw only after every model in the scenegraph reports a successful draw. Until then, the layer requests a redraw each frame. LayerColumns.draw now returns the result of model.drawBatches. The aim is correct: Tile3DLayer sets tileDrawn in onFirstDraw, and loaders.gl releases the fallback parent on that flag, so an early signal can open a hole while glTF textures load. The change works for the loading case. The new node tests and the scenegraph and simple-mesh render tests pass. I found one behaviour risk for draws that never succeed, and one test gap.
Findings
-
modules/mesh-layers/src/scenegraph-layer/scenegraph-layer.ts:553-560 — should-fix — a draw that fails permanently redraws forever.
Evidence: luma.glModel.draw()returnsfalsefor more than loading resources. In luma.gl 10.0.0-beta.2 (GPUVectorModel._draw), it also returnsfalsewhen the pipeline is errored and whenvertexArray.getDrawValidationError()sets the sticky_drawBlockedReason. In those casesallModelsDrawnstaysfalseon every frame. The layer then callssetNeedsRedraw()on every frame, so deck never goes idle.onFirstDrawnever fires, soTile3DLayernever setstileDrawn. loaders.gl then holds the parent tile and re-runsselectTiles()withsetTimeoutfor as long as the tile stays selected. Before this PR, the first draw call ended both loops. A minimal test shows the loop: a model whosedrawalways returnsfalse, drawn 1000 times, gives 1000setNeedsRedrawcalls and noonFirstDrawcall.
Suggested change: retry only while resources load. For example, stop after a bounded number of frames and signal anyway, or ask luma.gl for a loading state and treat other failures as "drawn". Add a test for a model that never draws. -
modules/core/src/lib/layer-columns.ts:448 and :497 — should-fix — the new
LayerColumns.drawreturn values have no test.
Evidence: the column test mocksLayerColumns.draw, and the empty-column test uses an emptyGroupNode, soLayerColumns.drawnever runs. Two mutations survive the PR's tests: (a) removereturnbeforemodel.drawBatches(...)(onlytsccatches this one), and (b) change the empty-column result fromtruetofalse. Mutation (b) brings back finding 1 for every empty column-backed layer. The Greptile bot also flagged this gap.
Suggested change: add a directLayerColumns.drawtest that checkstrueandfalsefromdrawBatches, andtruefor no prepared columns. -
test/modules/mesh-layers/scenegraph-columns.node.spec.ts — should-fix — the PR conflicts with
master.
Evidence:git merge-treeagainstmaster69b44bd reports a content conflict in this test file.masteralso moved to luma.gl 10.0.0-beta.2. I checked thatModel.draw()in beta.2 keeps the samefalsepaths, so the fix still applies after a rebase.
Suggested change: rebase onmasterand re-run the mesh-layers and tile-3d-layer tests. -
modules/mesh-layers/src/scenegraph-layer/scenegraph-layer.ts:143-147 — nit — document the new timing.
The TSDoc now says the callback can take several frames. Please also say what happens when a model never draws, after you choose a fix for finding 1.
Tests run (local, macOS, headless Chromium)
- Node:
test/modules/mesh-layers,test/modules/geo-layers/tile-3d-layer: 8/8 pass. - Headless:
test/modules/mesh-layers,test/modules/geo-layers/tile-3d-layer: 14/14 pass. - Render:
scenegraph-layer.spec.ts,simple-mesh-layer.spec.ts: 20/20 pass. - Mutation check of the PR's tests: ignoring the draw result fails 2 tests (good). Dropping
setNeedsRedrawfails 1 test (good). Dropping thedrawBatchesreturn survives. Changing the empty-column result tofalsesurvives. - Probe for finding 1: a model whose
drawalways returnsfalsedrew 1000 times with 1000 redraw requests and no first-draw signal. - Not run:
tscand lint.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… draws luma's Model.draw() also returns false when the pipeline errored or the vertex array fails validation, which never recovers. Call onFirstDraw after 60 incomplete draws, so deck can go idle and Tile3DLayer can release the parent tile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
Follow up of #10058. Part 1 of 2, replacing #10784 with smaller changes; pacing follows in #11151.
ScenegraphLayercallsonFirstDrawafter its firstdraw(), even when luma skipped a model's draw because its resources, such as glTF textures, are not ready:Model.draw()returnsfalsethen.Tile3DLayermarks the tile as drawn inonFirstDraw, so loaders.gl releases the tile's fallback parent before the replacement is visible.Change List
ScenegraphLayer: callonFirstDrawonce every model's draw returnedtrue, and redraw until thenLayerColumns.draw: return whether luma drewLayerColumns.draw's resultVerified with the mesh-layers and tile-3d-layer headless and node tests (the new tests fail on master) and the scenegraph-layer and simple-mesh-layer render tests.
Note
Low Risk
Low risk change to rendering lifecycle callbacks with an explicit 60-frame timeout safeguard to prevent infinite redraw loops.
Overview
Updates
ScenegraphLayerto defer callingonFirstDrawuntil every model in the scenegraph has successfully rendered, rather than signaling on the first draw pass before GPU resources like textures are ready. If any model skips drawing, the layer schedules redraws and waits up to 60 frames before falling back to signaling anyway to handle permanent draw failures (such as shader compilation errors).To support this check,
LayerColumns.drawnow returns a boolean indicating whether the batch draw was executed or skipped by luma.Reviewed by Cursor Bugbot for commit 985933c. Bugbot is set up for automated code reviews on this repo. Configure here.