Skip to content

render: pair the served pick with its newest completed frame in one drain - #5228

Merged
jakildev merged 2 commits into
masterfrom
claude/5220-same-drain-pick-pairing
Nov 21, 2026
Merged

jakildev merged 2 commits into
masterfrom
claude/5220-same-drain-pick-pairing

Conversation

@jakildev

@jakildev jakildev commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

On OpenGL, IRShapeDebug --gui-test failed newest_completed_pick_frame intermittently, at current=0/30. The latch compared the served pick with a second, separately drained newestCompletedMouseTrixelPickFrameId() read, and a GL fence can retire between the two calls. MouseTrixelPick now carries newestCompletedFrameId_ from the same history state as the served record (resolveServedPick), and the latch makes one pick call per frame. PICK_FRAME_CURRENT and PICK_STALE_CLEAR now report their true counts plus the first miss's id pair, and the pick contract states the one-result rule.

Screenshots

No visual change: this touches the pick result and the GUI-test harness only, not any rendered output.

Acceptance evidence

Host: Windows 10, NVIDIA GeForce RTX 3060 Ti, OpenGL, windows-debug, code at 024cdc1fd (the head commit after it is doc-only).

Criterion Check run Observed
GL pass, three consecutive runs python3 scripts/gui-verify.py IRShapeDebug -- --gui-test ×3 [gui-verify] 49/49 assertions passed, exit 0, on all three; each has newest_completed_pick_frame result=PASS actual=current=30/30
GL negative control python3 scripts/gui-verify.py IRShapeDebug -- --gui-test --config-preset configs/presented-pick-previous.lua exit 1, 48/49; the only FAIL is newest_completed_pick_frame result=FAIL actual=current=0/30 first_miss=served:115,newest:116
Before/after per-frame values temporary latch diagnostic (not committed), master vs PR head Master: 14/180 frames missed over 6 runs, each with second read = served + 1. PR head: served = same-result id on 30/30 in each of 3 runs. Tables are in Reviewer notes.
Unit pairing cases fleet-build --target IrredenEngineTest; ctest --test-dir build -R PresentedPick 100% tests passed, 0 tests failed out of 7 (4 new cases: newest served, previous served, empty history, accept-after-resolve)
Mutation control resolveServedPick filling newestCompletedFrameId_ from result.frameId_, same ctest 86% tests passed, 1 tests failed out of 7: only PresentedPick.ServedPreviousPairsBelowTheNewestCompletedFrame
--gui-test total stays 49 same runs 49 assertions on master and on the PR head
Reviewer notes

Plan departures

  • Phase-0 serial columns dropped from the failing table. The plan's completedSubmissionSerial() reads before each call hide the race: 8 runs, 0/240 missed frames, 49/49 every time. The failing table therefore records served id and second-read id only, captured into locals and logged once after both reads. A second read newer than the served id already proves completion advanced between the reads, because the ring hands over a slot only once its serial completes. In the polled arm the serial still advanced between the two polls on 1–5 frames per run, yet the first drain caught up every time.
  • Master is intermittent on this host, not 3/3. Bare master failed 1 of 2 runs. The poll-free diagnostic arm failed 6/6.
  • actual= wording. current=<K>/<N>, plus first_miss=served:<id>,newest:<id> when a frame misses. PICK_STALE_CLEAR gives its true current=<K>/<N>.
  • Contract-doc placement. Decision 4 put the rule in § "INPUT result". Open PR render: prototype event-cursor picks from completed images #5135 rewrites that section and nearly the whole file, so the rule is its own section, § "One result per comparison", just before § "Backend boundary". It now trial-merges cleanly with render: prototype event-cursor picks from completed images #5135. Whichever PR lands second can fold it back.
  • optimize skipped. The only per-frame production change is one 8-byte field write per getMouseTrixelPick() call. The harness latch now makes one fewer draining call per frame.

Phase 0: master eea79792d, shot 3, trailing 30 frames, run e1 of 6

# served second read first call drained a record current
1–8 117–124 = served yes true
9 124 125 no false
10–19 126–135 = served yes true
20 135 136 no false
21–30 137–146 = served yes true

Missed frames per run: 2, 1, 2, 4, 2, 3 (14/180). Every miss has the same shape: the first call drained nothing, the second read is served + 1, and served is never 0. The old all-or-nothing actual=current=0/30 reported a 2-frame miss as 30 misses.

Reading, not measured: on a missed frame the first drain accepted no record, so it never reached glGetNamedBufferSubData. The window between the two drains is only microseconds of CPU work. That favours a fence retiring inside the window over a readback stall. The fix does not depend on which.

After: same diagnostic on the PR head, plus the newestCompletedFrameId_ column

Run --gui-test served = same-result id second read > same-result id
a1 49/49 30/30 3/30
a2 49/49 30/30 0/30
a3 49/49 30/30 2/30
neg (presented-pick-previous.lua) 48/49, FAIL current=0/30 first_miss=served:116,newest:117 0/30 (same-result = served + 1) 2/30

Completion still advances between two separate reads. The latch no longer takes a second read, so the race cannot fail it.

Notes for reviewer

  • format-changed can't run on this host (no clang-format on PATH). WSL clang-format 18 --dry-run over the five C++ files flags only existing lines (render_manager.cpp:351, :711, where versions 18 and 22 disagree), none added here. CI format-check is the gate.
  • fleet-pr-overlap --base master: VERDICT: overlap, every trial merge clean. Check the shared files for semantic disagreement:
    • #5135 docs/design/pick-frame-contract.md clean
    • #5135 engine/render/src/render_manager.cpp clean
    • #5135 test/render/gpu_readback_ring_test.cpp clean
    • #5161 engine/render/include/irreden/render/presented_pick.hpp clean
    • #5161 engine/render/src/render_manager.cpp clean
  • Windows-authored engine/render change. The macOS smoke should give 49/49 and a failing negative control, as the plan-time Metal table predicts.

Closes #5220

🤖 Generated with Claude Code

jakildev and others added 2 commits November 19, 2026 20:14
…rain

The --gui-test PICK_FRAME_CURRENT latch compared getMouseTrixelPick()'s
frame id with a second newestCompletedMouseTrixelPickFrameId() call. Each
call drains the readback ring again, and on OpenGL a timestamp-query
fence can retire between the two, so the second read came out one frame
newer than a pick that was in fact the newest. On the Windows GL host
1-4 of shot 3's 30 frames missed per run, and the all-or-nothing
actual= string reported that as current=0/30.

MouseTrixelPick now carries newestCompletedFrameId_, filled by
resolveServedPick from the same history state the served record came
from. The latch makes one pick call per frame and keeps the id pair.
PICK_FRAME_CURRENT and PICK_STALE_CLEAR report their true counts, and
the first miss's served/newest ids. The pick contract states the
one-result rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keeps the rule clear of the in-flight rewrite of the record and INPUT
result sections, so the two edits merge independently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jakildev jakildev added fleet:author-claude Implementation last authored by Claude; route review to Codex fleet:authored-on-windows PR was opened from a Windows (MSYS2) host labels Nov 20, 2026

@jakildev jakildev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — render: pair the served pick with its newest completed frame in one drain

Verdict: approve

The result now carries the comparison frame from the same immutable history snapshot as the served pick, removing the second-drain race without changing the standalone newest-completed query.

Acceptance (issue #5220)

4 of 4 met. The phase-0 serial probes changed polling timing and suppressed the miss; the recorded served/second-read pairs still establish the completion advance, and the PR documents that departure and its replacement evidence.

Checked

  • Read the complete PR and issue threads, all changed files in context, and the overlapping changes in #5135 and #5161; no semantic disagreement found.
  • Exact head 38fcc8b46134ef839f4232d9af89ddd0fc8fdc44: fleet-build --detach --target IrredenEngineTest completed successfully (fleet-jobs: 20261120T042126Z-build-2eeedf succeeded exit=0).
  • fleet-run IrredenEngineTest --gtest_filter='PresentedPick.*': 7/7 passed.
  • CI format, header, comment-reference, whitespace, and fleet gates passed; Linux build and perf gate were still pending when reviewed.
  • Windows OpenGL evidence records three 49/49 positive runs, the expected 48/49 negative control, and the mutation control isolating the previous-served pairing case.

🤖 Reviewed by Codex GPT-5 (review-pr skill)

Opus recheck not required (reviewed at opus class).

@jakildev jakildev added fleet:approved Fleet reviewer approved — ready for human merge fleet:needs-macos-smoke PR needs macos-debug build + smoke-run validation and removed fleet:reviewing-mac-pool-2 labels Nov 20, 2026
@jakildev jakildev added fleet:verified-macos Cross-host smoke passed on macos-debug and removed fleet:needs-macos-smoke PR needs macos-debug build + smoke-run validation labels Nov 20, 2026
@jakildev

Copy link
Copy Markdown
Owner Author

Cross-host smoke OK on macos (fresh checkout + IRShapeDebug --auto-screenshot 10 — build clean, exit 0, no log warnings).

@github-actions

Copy link
Copy Markdown

Perf gate

Head host slug: linux-x86_64-xeon-6975p-c-03-0-vga

perf comparison: cb2e87f → b59aaea-ci

baseline: /home/runner/work/_temp/perf-baseline/history/linux-x86_64-xeon-6975p-c-03-0-vga/cb2e87f332f63470b88fccdc2448364d60bdff6c
head: /home/runner/work/IrredenEngine/IrredenEngine/save_files/perf/b59aaeaae-ci

host calibration

  • host: linux-x86_64-xeon-6975p-c-03-0-vga (matches baseline)
  • ref_ms: head 70.21 vs baseline 69.94 (load_factor 1.00×)
  • calibration target: 50.00 ms (informational)
  • baseline capture: perf-baseline@cb2e87f33 (branch tip); master 473953323, finished 2026-11-19T19:24:47Z, 0.4 d before the head run, ref_ms 69.94
  • weighting: raw (class-matched capture; load_factor 1.00×; no calibration-scaling entry)
  • attribution: no measured master improvement between capture master 473953323 and merge base eea79792d (11 commits)

thresholds: regress ≥ 10%, improve ≥ 5%

voxel cull effectiveness

cell ratio (base→head) avg visible total avg feeder
target=IRLuaPerfGrid,zoom=1,sub_mode=full,sub_base=1 1.000 → 1.000 (+0.0pp) 262144 → 262144 1024 → 1024 0 → 0
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1 0.598 → 0.598 (+0.0pp) 156637 → 156637 1024 → 1024 0 → 0
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1 1.000 → 1.000 (+0.0pp) 262144 → 262144 1024 → 1024 0 → 0
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1 0.975 → 0.975 (+0.0pp) 255592 → 255592 1024 → 1024 0 → 0

frame timing (ms)

cell avg p99
target=IRLuaPerfGrid,zoom=1,sub_mode=full,sub_base=1 419.71 → 445.14 (+6.1%) 1276.46 → 1191.46 (-6.7%) ↓
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1 940.31 → 965.37 (+2.7%) 1708.08 → 1735.75 (+1.6%)
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1 497.57 → 541.89 (+8.9%) 6789.76 → 8135.99 (+19.8%) ⚠
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1 1322.17 → 1367.14 (+3.4%) 2038.95 → 2075.93 (+1.8%)

GPU frame timing (ms; separate from stage samples)

cell envelope (base→head) buffer spans (base→head) coverage (base→head)
target=IRLuaPerfGrid,zoom=1,sub_mode=full,sub_base=1 unavailable → unavailable unavailable → unavailable unavailable → unavailable
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1 unavailable → unavailable unavailable → unavailable unavailable → unavailable
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1 unavailable → unavailable unavailable → unavailable unavailable → unavailable
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1 unavailable → unavailable unavailable → unavailable unavailable → unavailable

GPU stage timing (avg ms per sampled invocation)

cell canvasClear voxelCompact voxelStage1 voxelCardinalElect voxelStage2 voxelSunFaces textToTrixel buildLightOcclusionGrid computeVoxelAO bakeSunShadowMap computeSunShadow computeLightVolume lightingToTrixel fogToTrixel trixelToFb resolvePerAxisScreenDepth fbToScreen cardinalSurfaceFb
target=IRLuaPerfGrid,zoom=1,sub_mode=full,sub_base=1 16.29→16.90 46.34→48.62 40.16→42.10 0.96→0.81 ↓ 40.01→39.30 68.94→71.06 — 0.00→0.00 1.45→2.70 ⚠ 16.75→7.40 ↓ 13.45→0.34 ↓ 11.91→25.21 ⚠ 2.51→1.16 ↓ 0.95→0.99 0.15→0.17 ⚠ — 6.49→6.67 0.00→0.19
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1 17.20→17.66 235.08→239.94 178.46→184.36 2.96→3.08 169.06→165.79 112.95→116.02 — 0.00→0.00 1.30→6.73 ⚠ 28.77→7.28 ↓ 11.82→0.37 ↓ 10.07→22.93 ⚠ 5.03→1.35 ↓ 0.99→1.12 ⚠ 0.14→0.17 ⚠ — 6.11→6.37 0.00→0.31
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1 15.49→15.65 55.55→56.85 43.89→45.20 6.51→6.85 36.53→35.77 65.32→65.74 1.28→1.30 0.00→0.00 4.08→4.71 ⚠ 39.01→36.72 ↓ 13.10→0.59 ↓ 28.79→41.60 ⚠ 4.79→4.43 ↓ 1.35→1.42 0.15→0.16 0.00→0.00 7.15→7.33 0.00→0.20
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1 16.44→16.58 384.05→395.41 288.01→297.77 4.59→4.71 264.15→265.20 127.90→128.06 1.29→1.30 0.00→0.00 1.32→5.61 ⚠ 37.68→6.79 ↓ 13.47→0.38 ↓ 11.14→22.31 ⚠ 4.28→1.17 ↓ 1.13→1.15 0.15→0.16 ⚠ 0.00→0.00 6.04→6.50 0.00→0.52

top CPU systems by avg ms (head)

target=IRLuaPerfGrid,zoom=1,sub_mode=full,sub_base=1

pipeline system avg ms (base→head)
RENDER SingleVoxelToCanvasFirst 214.703 → 223.041 (+3.9%)
RENDER CanvasToFramebuffer 14.330 → 25.418 (+77.4%) ⚠
RENDER ComputeLightVolume 24.978 → 25.284 (+1.2%)
UPDATE FogRevealEval 7.136 → 8.292 (+16.2%) ⚠
RENDER BakeSunShadowMap 6.007 → 6.037 (+0.5%)
UPDATE PropagateTransform 3.483 → 3.795 (+9.0%)
RENDER UpdateVoxelSetChildren 2.147 → 3.098 (+44.3%) ⚠
UPDATE LuaWaveStateToOffset 2.542 → 2.979 (+17.2%) ⚠

target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1

pipeline system avg ms (base→head)
RENDER SingleVoxelToCanvasFirst 713.424 → 731.471 (+2.5%)
RENDER CanvasToFramebuffer 13.360 → 36.424 (+172.6%) ⚠
RENDER ComputeLightVolume 21.534 → 23.154 (+7.5%)
UPDATE FogRevealEval 7.943 → 8.197 (+3.2%)
RENDER ComputeVoxelAO 6.756 → 7.004 (+3.7%)
RENDER BakeSunShadowMap 5.044 → 5.259 (+4.3%)
UPDATE PropagateTransform 3.455 → 3.646 (+5.5%)
RENDER UpdateVoxelSetChildren 2.297 → 3.167 (+37.9%) ⚠

target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1

pipeline system avg ms (base→head)
RENDER SingleVoxelToCanvasFirst 234.442 → 238.799 (+1.9%)
RENDER CanvasToFramebuffer 14.537 → 36.953 (+154.2%) ⚠
RENDER ComputeSunShadow 34.544 → 30.997 (-10.3%) ↓
RENDER ComputeLightVolume 24.263 → 24.076 (-0.8%)
RENDER LightingToTrixel 18.559 → 18.772 (+1.1%)
RENDER BakeSunShadowMap 7.924 → 8.295 (+4.7%)
UPDATE FogRevealEval 6.789 → 7.803 (+14.9%) ⚠
UPDATE PropagateTransform 4.692 → 4.825 (+2.8%)

target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1

pipeline system avg ms (base→head)
RENDER SingleVoxelToCanvasFirst 1084.329 → 1112.350 (+2.6%)
RENDER CanvasToFramebuffer 13.217 → 45.629 (+245.2%) ⚠
RENDER ComputeLightVolume 24.282 → 22.437 (-7.6%) ↓
UPDATE FogRevealEval 6.477 → 7.762 (+19.8%) ⚠
RENDER ComputeVoxelAO 5.572 → 5.813 (+4.3%)
RENDER BakeSunShadowMap 5.204 → 5.457 (+4.9%)
UPDATE PropagateTransform 4.695 → 4.854 (+3.4%)
RENDER UpdateVoxelSetChildren 2.328 → 3.200 (+37.5%) ⚠

@jakildev
jakildev merged commit 8500841 into master Nov 21, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fleet:approved Fleet reviewer approved — ready for human merge fleet:author-claude Implementation last authored by Claude; route review to Codex fleet:authored-on-windows PR was opened from a Windows (MSYS2) host fleet:verified-macos Cross-host smoke passed on macos-debug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

render: --gui-test newest_completed_pick_frame fails 0/30 on OpenGL

1 participant