Repository navigation
render: gate mouse picks on completed frames (#4999) - #5115
Conversation
jakildev
left a comment
There was a problem hiding this comment.
Review — render: gate mouse picks on completed frames (#4999)
Verdict: approve
Stacked on #5105 (cross-author lane, upstream carries fleet:approved). Reviewing the child diff only — upstream is approved separately; approval assumes #5105 lands first. Interface fragility: this PR depends on RenderDevice::submissionSerial() / completedSubmissionSerial(), FrameCompletionQueue::setFrameId, and IRRender::mouseMainFramebufferPixel() from the parent chain; if any changes between approval and merge, this needs a rebase.
Big picture. The change does what #4999 asks. getMouseTrixelPick() keeps its call shape but now serves a record that TRIXEL_TO_FRAMEBUFFER::endTick copies on the GPU timeline after the final hover writer (the per-axis scatter resolve runs first), through the existing GpuReadbackRing pattern (engine/render/CLAUDE.md readback rule): slot handed over only once completedSubmissionSerial() reaches the serial that encoded the copy, newest frame id wins, full ring drops the oldest pending slot, no finish(), no map of the live buffer. Destroyed or marked-for-deletion entities read as null while frame id and cursor survive. Staleness is reported, the entity is not suppressed, and the INPUT-tick count is once-per-tick through the new InputManager::inputTick(). The ring/slot logic is a pure header (presented_pick.hpp) with unit tests that need no GPU, which is the right seam.
CI as of this review: linux-build, perf-gate, render-harness-tests have no completed run on head 458c0b618 (unread, not green); format-check, header-checks, comment-refs, instruction-refs, closes-lint, whitespace pass.
Acceptance (issue #4999)
Graded by me against the plan's Done-means list and the PR's evidence table (no separate grader dispatched).
| Criterion | Status | Basis |
|---|---|---|
| Pick tagged with frame id + render cursor, served only after submission completes, both backends, non-blocking | met (Metal evidence; GL by construction) | render_manager.cpp:207-243; GL path only exercised by source reading — see escalation |
| Destroyed entity reports no entity | met | resolvePresentedPick + PresentedPick.DestroyedEntityIsFilteredWithoutDiscardingFrameOrCursorState; the live-check lambda in RenderManager::mouseTrixelPick is covered only by the GUI shot (see nit) |
| Stale flag + profile-report count, entity still reported | met | render_manager.cpp:876-894, profile_report.cpp, InputLatencyReport* row test |
| Tests fail when served from other than newest completed frame | met | unit tests plus GUI fault control (presented-pick-previous.lua); PR reports the negative run failing newest_completed_pick_frame |
docs/design/pick-frame-contract.md |
met | added |
| macOS editor / render-verify parity | unverifiable on mac-pool-2 (display session lost); PR says so honestly and asks for cross-host re-run — covered by smoke labels |
Nits (follow-up)
creations/demos/shape_debug/main.cpp(destroyed_entity_is_filteredshot) — the assertion isnewest pick entity == null, and the shot arms the destroy only when the pick first equals the voxel entity, with no assertion thatdestroyIssued_ever became true. If the cursor never lands on the voxel the shot passes vacuously, and after the deferred destroy the pixel is empty anyway, so the shot cannot tell the liveness filter from an empty pixel. Apredicateassertion ong_presentedPick.destroyIssued_would make it a real positive control; theRenderManagerlambda (entityExists && !isMarkedForDeletion) is otherwise untested.main.cppshot tables —kPresentedPickStaleShotIndex/kPresentedPickDestroyedShotIndexhave nostatic_asserttying them tostaleEvents_/destroyedEvents_the way the drag-pan index has; inserting a shot ahead of them silently mis-aims.main.cppcfg.settleFrames_ = 3→30applies to every--gui-testshot, not just the 30-frame assertions; a one-line comment on why (or a per-shot settle) would keep the run time from creeping unnoticed.gui_test_assertions.hpp(hoveredEntityId phase-contract comment, ~line 144) andsystem_gizmo_hover.hppheader comment still describe the hover read as the previous frame's mapped buffer; the contract is now "newest completed record". Alsoengine/render/CLAUDE.md's readback bullet could list the new ring besidecullStatsRing_/overflowCtrlRing_.
Praise
- Pure-header
PresentedPickHistory+resolvePresentedPickkeep the ordering and filtering rules unit-testable without a device, and the fault control proves the GUI assertion can actually fail.
Test plan the author should run before merge
- Windows/OpenGL:
python3 scripts/gui-verify.py IRShapeDebug -- --gui-test— the GL submission-fence path (glCopyNamedBufferSubData+getSubDatabehindcompletedSubmissionSerial()) has no run in this PR; confirmnewest_completed_pick_frameand hover latency (a gated read can serve an older frame than the old mapped read when the fence lags). - macOS: rerun the editor
face_picksession and both render-verify targets once the display session is back. - Re-run the profile/perf-gate rows the PR could not take (
valid=120 commandBuffers=120on head).
Escalation: please Opus-recheck before merge (touches: engine/render, engine/world, engine/input, engine/prefabs/irreden/render).
🤖 Reviewed by Claude Sonnet 5.5 (review-pr skill)
Opus recheck required: GPU readback lifetime and submission-serial gating on the OpenGL backend (fence polling, slot reuse when the ring is full, frame-id/serial pairing at endTick) is untested here, and the change spans engine/render, engine/world and engine/input.
Perf gateHead host slug: Perf gate — seeding new baselineNo baseline at |
jakildev
left a comment
There was a problem hiding this comment.
Review — render: gate mouse picks on completed frames (#4999) — Opus recheck
Verdict: approve
Stacked on #5105 (open, fleet:approved); approval assumes #5105 lands first. The interface-fragility note in the Sonnet pass stands: submissionSerial() / completedSubmissionSerial(), FrameCompletionQueue::frameId, and mouseMainFramebufferPixel() all come from the parent chain. If any of them changes before merge, this PR needs a rebase.
This pass covers what Sonnet asked for: GPU readback lifetime and submission-serial gating on both backends, slot reuse at capacity, and pairing the frame id and serial at endTick. I read the head 458c0b618 in full file context against the backend code on the parent tip 0f9f2c461.
Opus-only items
- OpenGL fence gating: correct.
GpuSubmissionFences::endSubmissiontags a submission with the serial that was open while it was recorded, then increments.publishMouseTrixelPickruns in RENDER beforepresent(), so its copy carries serial S.pollCompletedadvancescompletedSerialto S only after S's timestamp query is available, and fences retire oldest first, so a later fence never retires early.finish()→completeAll()sets completed to S and opens S+1, so a mid-framelegacyFinishTiming_finish still pairs correctly.glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT)is the right bit for aglCopyNamedBufferSubDatathat reads SSBO writes from the fragment pass and the scatter-resolve compute. This is the same shape asoverflowCtrlRing_(system_voxel_to_trixel.hpp:1390). - Metal: safe by construction.
present()andfinish()bothcommit()+waitUntilCompleted(), andcompletedSubmissionSerial()isserial - 1, so a slot drains on the frame after its copy. The destination slots areBUFFER_STORAGE_DYNAMIC, which isResourceStorageModeShared(metal_buffer.cpp), sogetSubDatareadscontents()with no hidden blit or wait. The backend opens one encoder per draw or dispatch (createRenderEncoderper call;memoryBarrieris a documented no-op). The blit thatendTickadds afterbindFramebuffer()therefore never runs inside an open render pass. The next composite (ENTITY_CANVAS_TO_FRAMEBUFFER) reopens withLoadActionLoadbecauseconsumeMetalRenderTargetClear()is one-shot, so it cannot wipe colour. When the drawable is starved (null command buffer), the copy falls back to an immediatememcpyof a buffer whose frame work no-opped. That yields a null-entity pick for the frame, the same answer the old persistent-map read gave there. - Slot reuse at capacity: correct. With
kMaxPresentedSubmissionsInFlight = 2and one write per frame, steady state is about 3 slots against a cap of 8. If no consumer drains (a creation with no hover reader), the ring saturates at 8 andwriteoverwrites the oldest pending slot with a copy in a newer submission. Queue order makes the later copy land last, and the slot's producer and serial are restamped together, so a drain never pairs old bytes with new metadata. It stays bounded with no growth. - Frame-id / cursor pairing: correct.
World::rendercallssetPresentingFrame(++m_renderFrameId)beforerenderFrame(). The cursor tag is recomputed atendTickfrom the same camera and framebuffer transform that the tick andresolveScatterHoverupload, and nothing in RENDER moves them between those points.PresentedPickHistory::acceptorders by frame id, not drain order, so the out-of-order drain test is the right lock. - Threading and ECS: correct. Both production callers (
ENTITY_HOVER_DETECT::beginTick,GIZMO_HOVER::beginTick) and the GUI-test latch run on the main thread, so the GLgetSubDatain the drain always has the context.entityExists && !isMarkedForDeletionis a sound liveness filter: entity ids are monotonic with no recycle pool (entity_manager.cpp:75), which the design doc relies on. The fixture'sIREntity::destroyEntityin an UPDATEendTickis the marking variant. - Lifetime: correct. The 8 slot buffers go through
createResource<Buffer>and are owned by the resource manager, with theResourceIddropped. That matches the otherRenderManager-created buffers, and nothing dereferences them after teardown.
Hot path. The per-frame cost is one blit encoder on Metal (the encoder-per-op model costs roughly tens of µs) plus one barrier and one 32-byte copy on GL. perf-gate is now green on this head.
CI on 458c0b618. perf-gate, format-check, header-checks, comment-refs, instruction-refs, instruction-size, closes-lint and whitespace pass. linux-build and render-harness-tests are still in progress at this review, so they are unread, not green.
Nits (follow-up)
creations/demos/shape_debug/main.cppdestroyed_entity_is_filtered: Sonnet flagged this shot as vacuous. On closer reading I agree, and adding adestroyIssued_predicate would not fix it. The capture frame comes 30 settle frames after the destroy, and by then every completed record shows an empty pixel, so the shot passes with or without the filter. The window where a record outlives its entity is up tokMaxPresentedSubmissionsInFlightframes on GL, and the UPDATE→RENDER span of the destroy frame on Metal. A discriminating control would latch the pick on the first frame afterdestroyIssued_, while the served frame id is still older than the destroy frame. Until then, thePresentedPick.DestroyedEntityIsFiltered…unit test is the real evidence for criterion 4. That is enough for the criterion, but the GUI row in the evidence table proves nothing.system_trixel_to_framebuffer.hpp:1062:HoveredEntityIdBufferis still allocatedMAP_READ | MAP_PERSISTENT | MAP_COHERENT, but nothing maps it now (git grep mapRangefinds no caller outside the backends). Dropping the map flags lets GL place it device-local. The@noteatir_render_enums.hpp:59("used by HoveredEntityIdBuffer") becomes stale with this PR and should go with it.- Sonnet's follow-up nits stand: the stale "previous frame's mapped buffer" wording in
gui_test_assertions.hpp:144andsystem_gizmo_hover.hpp:15-28, the missingstatic_assertfor the two new shot indices, the globalsettleFrames_ = 30, and theengine/render/CLAUDE.mdreadback bullet listing.
Praise
- The completion boundary is the right abstraction. On GL, the old code read whatever a persistent coherent map held, a frame the GPU might not have finished writing. This PR replaces that with the same serial-gated ring the counters already use, and keeps the ordering policy in a pure header that tests can drive without a device.
Acceptance (issue #4999)
I confirm Sonnet's grading: every criterion is met or honestly unverifiable. Criterion 1 on GL is met by construction, per the fence analysis above. Criterion 4 rests on the unit test (see nit). Criterion 6's macOS editor and render-verify rows are unverifiable on the author host and covered by the cross-host smoke labels (fleet:needs-windows-smoke present).
Test plan the author should run before merge
- Windows/OpenGL:
python3 scripts/gui-verify.py IRShapeDebug -- --gui-test. This is the first run of the fence-gated GL path; watchnewest_completed_pick_frameand hover latency. - macOS, once a display session is back: the editor
face_picksession and both render-verify targets. - Confirm
linux-buildandrender-harness-testsfinish green on458c0b618.
🤖 Reviewed by Claude Opus 5.5 (review-pr skill, Opus recheck)
Publish the hover buffer through a bounded GPU readback ring tagged with frame and cursor identity. Filter dead entities at the shared read chokepoint and report stale input ticks without changing dispatch behavior. Add positive and faulted GUI coverage, completion and lifetime unit tests, and document the presented-pick contract.
458c0b6 to
1b8fc3a
Compare
Perf gateHead host slug: perf comparison: 7c12467 → 7bb47bd-cibaseline: host calibration
thresholds: regress ≥ 10%, improve ≥ 5% voxel cull effectiveness
frame timing (ms)
GPU frame timing (ms; separate from stage samples)
GPU stage timing (avg ms per sampled invocation)
top CPU systems by avg ms (head)
|
| pipeline | system | avg ms (base→head) |
|---|---|---|
| RENDER | SingleVoxelToCanvasFirst |
219.473 → 218.892 (-0.3%) |
| RENDER | ComputeLightVolume |
25.611 → 26.362 (+2.9%) |
| RENDER | CanvasToFramebuffer |
14.581 → 15.039 (+3.1%) |
| RENDER | ComputeSunShadow |
12.795 → 12.839 (+0.3%) |
| RENDER | BakeSunShadowMap |
6.097 → 6.037 (-1.0%) |
| UPDATE | PropagateTransform |
3.630 → 3.622 (-0.2%) |
| UPDATE | FogRevealEval |
3.015 → 3.076 (+2.0%) |
| RENDER | LightingToTrixel |
2.798 → 2.973 (+6.3%) |
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1
| pipeline | system | avg ms (base→head) |
|---|---|---|
| RENDER | SingleVoxelToCanvasFirst |
723.353 → 718.333 (-0.7%) |
| RENDER | ComputeSunShadow |
26.165 → 26.036 (-0.5%) |
| RENDER | ComputeLightVolume |
22.470 → 23.063 (+2.6%) |
| RENDER | CanvasToFramebuffer |
13.543 → 13.854 (+2.3%) |
| RENDER | ComputeVoxelAO |
6.895 → 6.821 (-1.1%) |
| RENDER | BakeSunShadowMap |
5.179 → 5.196 (+0.3%) |
| RENDER | LightingToTrixel |
4.902 → 5.081 (+3.7%) |
| UPDATE | PropagateTransform |
3.571 → 3.425 (-4.1%) |
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1
| pipeline | system | avg ms (base→head) |
|---|---|---|
| RENDER | SingleVoxelToCanvasFirst |
233.064 → 233.307 (+0.1%) |
| RENDER | ComputeSunShadow |
35.057 → 35.432 (+1.1%) |
| RENDER | ComputeLightVolume |
24.269 → 24.106 (-0.7%) |
| RENDER | LightingToTrixel |
19.087 → 19.261 (+0.9%) |
| RENDER | CanvasToFramebuffer |
14.429 → 14.766 (+2.3%) |
| RENDER | BakeSunShadowMap |
8.082 → 8.102 (+0.2%) |
| UPDATE | PropagateTransform |
4.785 → 4.748 (-0.8%) |
| RENDER | FogToTrixel |
4.354 → 4.327 (-0.6%) |
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1
| pipeline | system | avg ms (base→head) |
|---|---|---|
| RENDER | SingleVoxelToCanvasFirst |
1099.862 → 1105.909 (+0.5%) |
| RENDER | ComputeSunShadow |
34.318 → 34.811 (+1.4%) |
| RENDER | ComputeLightVolume |
24.304 → 24.741 (+1.8%) |
| RENDER | CanvasToFramebuffer |
13.511 → 13.574 (+0.5%) |
| RENDER | ComputeVoxelAO |
5.604 → 5.581 (-0.4%) |
| RENDER | BakeSunShadowMap |
5.263 → 5.201 (-1.2%) |
| UPDATE | PropagateTransform |
4.828 → 4.956 (+2.7%) |
| RENDER | LightingToTrixel |
4.201 → 4.460 (+6.2%) |
* render: refresh macos ShapeDebug references Refresh the intended fractional-origin and yaw-22 glitch baselines, plus the finite sun-face shadow drift now present on master. CanvasStress references remain unchanged.\n\nAuthored with the Codex runtime. * render: reconcile macos ShapeDebug references * docs: complete rotation picking image acceptance Record passing native Metal ShapeDebug and CanvasStress image gates against the refreshed references, and remove the completed picking open item. Preserve the separate OpenGL runtime follow-up and link terminal verification reports on the media branch. Authored with OpenAI Codex (GPT-6). * docs: record the opengl rotation-picking acceptance run Run #4865's acceptance on a Windows GL host (RTX 3060 Ti) against master eea7979, with a parent-of-#5115 control build. GUI 8/8, sweep 360/360, three identical tie runs, both render-verify gates and continuous zoom, hover canary and editor default sessions pass. The cube probe (140/288), #5115's newest-completed-frame assertion (48/49) and the editor part_gizmo_reach session (14/24) fail on GL and are filed; the native suite's three failures are the known host set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Test plan
fleet-build --target IrredenEngineTest IRShapeDebugfleet-run IrredenEngineTest --gtest_filter='PresentedPick*:InputLatencyReport*'(6/6 passed)python3 scripts/gui-verify.py IRShapeDebug -- --gui-test(49/49 passed)python3 scripts/gui-verify.py IRShapeDebug -- --gui-test --config-preset configs/presented-pick-previous.lua(expected negative control: newest-frame assertion failed)fleet-build --target format-changedandfleet-build --target header-checksAcceptance evidence
python3 scripts/gui-verify.py IRShapeDebug -- --gui-testnewest_completed_pick_frame PASS current=30/30; full suite 49/49python3 scripts/gui-verify.py IRShapeDebug -- --gui-test --config-preset configs/presented-pick-previous.luanewest_completed_pick_frame FAIL current=0/30; all other assertions in that run passedfleet-run IrredenEngineTest --gtest_filter='PresentedPick*'PresentedPick.DestroyedEntityIsFilteredWithoutDiscardingFrameOrCursorStatedestroyed_entity_is_filtered PASS entity=0; unit passedInputLatencyReport*settled_cursor_is_current PASS current=30/30;same_batch_move_press_is_stale PASS stale; report row test writesStale pick input ticks: 7face_pick, and render verification attemptstexels=0; the Aqua session then stopped advertising displays, and render verification exitedRESULT=NO-DISPLAYbefore comparisongetSubDataonly aftercompletedSubmissionSerial, on private destination slots; nofinish()or live-buffer CPU read. Parent report hasvalid=120 commandBuffers=120; head report was unverifiable because the benchmark quiet window remained busyNotes for reviewer
The macOS display session became unavailable during the final GPU validation sweep. Cross-host smoke should rerun the editor face-pick session and both render-verify targets. The implementation changes no shader, color buffer, or command-buffer submission boundary.
fleet-pr-overlapreportedVERDICT: overlap: #4921's ShapeDebug row is a base conflict already present on the #5105 parent; overlaps with #5036, #5073, #5076, #5084, #5100, and #5101 trial-merge clean; #5105 rows are upstream by construction.Closes #4999