Skip to content

render/metal: draw consecutive draws to one target in one render pass (#4994) - #5100

Merged
jakildev merged 2 commits into
masterfrom
claude/4994-metal-render-pass-reuse
Nov 19, 2026
Merged

jakildev merged 2 commits into
masterfrom
claude/4994-metal-render-pass-reuse

Conversation

@jakildev

@jakildev jakildev commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Metal keeps one render pass open across consecutive draws to the same colour, depth and entity-id attachments, instead of opening and ending a pass per draw. The runtime holds the open encoder (openMetalRenderPass / beginMetalRenderPass / endMetalRenderPass in metal_runtime). renderEncoderForDraw reuses it unless a clear is pending or a bound texture is one of its attachments. Pipeline and depth-stencil state are set on every draw, and load and store actions are unchanged. A shared encoder keeps whatever an earlier draw bound, so the runtime records what the open pass holds at each slot (MetalRenderPassBindings, emptied when a pass begins or ends). bindRenderResources sets every vertex buffer, fragment buffer and texture slot whose value differs from that record, nil included. A buffer unbound or a texture destroyed between two draws is cleared on the shared pass, as a fresh encoder would have it.
  • The open pass ends before any compute or blit encoder (createComputeEncoder / createBlitEncoder), a GPU timing boundary (writeTimestamp), memoryBarrier, present() / finish(), a command-buffer swap (setMetalCommandBuffer), runtime shutdown, and untrackMetalTexture of one of its attachments.
  • Texture2D::subImage2D and clear now create their blit through createMetalBlitEncoder, so they end the open pass and are sampled by sub-stage timing.
  • RenderDeviceStats gains RenderPassStats { renderPasses_, draws_ }. The profile report prints renderPasses and draws rows beside the buffer-write counters, and World shares one per-frame delta and aggregation helper across both counter groups.
  • MetalRenderPass* unit tests: one case per pass boundary, a control, a same-target rebind, an attachment untrack, a slot cleared between two draws of one pass, and a blend check that a shared pass composes draws exactly as separate passes did.
  • gpu-stage-timing-cost-model.md § 1 notes that a draw-heavy stage now holds one encoder per run of draws.

Test plan

  • fleet-build --target IrredenEngineTest, then fleet-run IrredenEngineTest --gtest_filter='MetalRenderPass*:GpuTimestamp*:MetalStickyUntrack*:MetalGpuComputeDispatchTest.*:PositionUploadTest.*:*ProfileReport*:*DeviceCounter*:*DeviceError*:*CommandBufferError*' → [ PASSED ] 98 tests. Full fleet-run IrredenEngineTest → 4138 passed, 3 skipped, 0 failed.
  • The Metal suites under MTL_DEBUG_LAYER=1 MTL_DEBUG_LAYER_ERROR_MODE=assert (headless device) → Metal API Validation Enabled, [ PASSED ] 60 tests.
  • Review amend (SlotClearedBetweenDrawsIsClearedOnTheSharedPass): MetalRenderPass*:MetalStickyUntrack*:GpuTimestamp*:MetalGpuComputeDispatchTest.* → [ PASSED ] 61 tests.; MetalRenderPass*:MetalStickyUntrack* under MTL_DEBUG_LAYER=1 MTL_DEBUG_LAYER_ERROR_MODE=assert → Metal API Validation Enabled, [ PASSED ] 19 tests. (DrawSamplingAnAttachmentSplitsThePass excluded: it is the deliberately invalid draw). Full fleet-run IrredenEngineTest → 4139 passed, 3 skipped, 0 failed. Positive control: with nil slots skipped (the old fill), the new test fails on the buffer and texture slot assertions.
  • Interleaved base/head timing on the 128-caster fixture, Debug and Release; million control at 45° and 0°; render-verify, light-verify and nine-yaw captures, head against a same-session base; gui-verify (rows below).

Acceptance evidence

Every reading below comes from the rebased head 729a98d3e, a tree containing ebee6b621 (#5050) and 40cb99890 (#5076), per Plan corrections A1 and A2. Base = origin/master 18a91f694; head = the same commit plus this change. Host: Apple M4 Max, on AC power (battery 74–96%, charging), two displays attached. Timing: five interleaved base/head pairs, launch order alternating. Every kept run is QUIET=guarded and CLEAN (Debug logs: Discovered 2 display monitors, paced at 120 Hz); no run needed a repeat. Each arm is one scripts/perf/repeat_profile.py --repeats 1 run against its own frozen build tree (--build-dir). The fixture is run_matrix.py's COMMON + far-128 (128 coincident casters above a grid floor, 360 frames), with its ablation sampler (const bool queryHierarchy = false;) staged into every arm's runtime shaders, i.e. sun query disabled. Bounds are one-sided 95%, mean ± t(0.95, n−1)·sd/√n.

Review amend (per-slot binding record). The amend changes only which binding calls a draw issues; pass boundaries, load and store actions and the timestamp attachment are untouched. Re-run on the amend head over the same 18a91f694 base. This host now has one built-in 2x display, so the committed references apply directly:

  • render-verify: IRCanvasStress 59/59 PASS and IRPerfGrid 35/35 PASS against the references. IRShapeDebug 140/176 PASS, 36 FAIL, 10 references pending. The 36 failures are on master too. Every failing row comes from the default pass, an sdf_baked_* pass, lod_scene, or a *_standard_off pass that repeats the default shots. The default, sdf_baked_pose_root and lod_scene passes, run from a 18a91f694 tree and from the amend head, give 28/28, 6/6 and 6/6 captures identical at per-pixel tolerance 0.
  • gui-verify IRShapeDebug -- --gui-test: 49/49 assertions passed.
  • Unit tests: as in the Test plan.
  • The timing rows (criteria 1–4 and 8) are from 729a98d3e and were not retaken. Nothing they measure moved: GPU stage time and pass counts depend on pass boundaries, which the amend does not change. In a run of draws whose bindings do not change, a draw now issues no binding calls at all where it used to re-set every bound slot.
Criterion Check run Observed
1. Phase 0 reading quoted in the PR Debug three-arm session on the pre-rebase tree (2455e3240): base / Phase 0 / head. Phase 0 = reuse gated on only between the composite loop's first and last draw (a temporary patch, never committed). Not retaken: the rebase changed no draw-path code (range-diff touches only the counter-table conflicts), and criterion 3 below re-measures the full effect on the rebased tree. entityCanvasToFb base 6.563 ms → Phase 0 0.207 ms: paired delta −6.356 ms, upper bound −6.233 ms, −96.8%. The premise holds well past the plan's 40% confirm line (bail line 20%).
2. Positive fire: one render pass per draw on the parent, at most one per four draws on the head Profile report --- Render device counters --- on the 128-caster fixture (Debug). The parent has no counter (this PR adds it), so the parent row is a reuse-off control: a separate worktree of this head with openMetalRenderPass forced to return nullptr, i.e. the parent's one-pass-per-draw behaviour. Reuse-off control: renderPasses steady 391.000/frame, draws 391.000/frame (one pass per draw). Head, all ten Debug and Release runs: renderPasses 5.000/frame, draws 391.000/frame (1 pass per 78 draws).
3. entityCanvasToFb (sun query off) falls by at least half, Debug and Release, judged by the upper bound Debug and Release base/head sessions as above Debug 6.318 → 0.250 ms, delta −6.068 (upper −6.008), ratio 0.040. Per pair: base 6.316 / 6.342 / 6.374 / 6.349 / 6.211, head 0.250 / 0.250 / 0.251 / 0.250 / 0.250. Release 6.558 → 0.248 ms, delta −6.310 (upper −6.180), ratio 0.038. Per pair: base 6.481 / 6.598 / 6.354 / 6.669 / 6.686, head 0.228 / 0.257 / 0.251 / 0.251 / 0.251. Steady frame: Debug 46.54 → 38.39 ms (upper −7.66), Release 46.77 → 38.82 ms (upper −7.04).
4. Million control steady frame mean (Release, stage profiling off) not worse than the parent beyond the noise bound repeat_profile.py --target IRPerfGrid --build-dir <tree> --repeats 1 -- --config-preset configs/perf/million-profiling-off.lua --wave-freeze --no-overlay --pivot-origin --auto-profile 300 --yaw <y>, five interleaved pairs per pose Passes (i), judged by the 1.10× frame-row point ratio scripts/perf/sun_depth_slab_timing.py applies. 45°: steady 10.858 → 10.806 ms, ratio 0.995. Per pair: base 10.83 / 10.84 / 10.85 / 10.85 / 10.92, head 10.83 / 10.69 / 10.85 / 10.81 / 10.85. 0°: steady 18.244 → 18.246 ms, ratio 1.000. Per pair: base 18.19 / 18.26 / 18.29 / 18.24 / 18.24, head 18.24 / 18.25 / 18.27 / 18.24 / 18.23.
5. render-verify max delta 0 for IRShapeDebug, IRCanvasStress, IRPerfGrid; nine-yaw IRCanvasStress set RGB-identical to the parent; light-verify --if-changed passes python3 scripts/render-verify.py --target <T> --no-build from each tree, every compared capture archived and paired head against base at zero tolerance (render-compare, per-pixel tol 0) IRPerfGrid: 35/35 captures identical, max delta 0. IRCanvasStress: 53/53 identical. IRShapeDebug: 169/169 identical across 55 passes. The 56th pass, text_scale1_legibility, segfaults at startup on base and head alike (glfwSetWindowSize under offscreen mode), so it is excluded on both arms; filed as #5175. Nine-yaw (--frozen-pose 0.47 --sweep-yaw 0 6.2831853 9 --auto-screenshot 6): 9/9 captures, 0 differing RGB pixels, both runs CLEAN. light-verify (--light-domain-matrix, --light-boundary-sweep, --hover-sweep): 46/46 captures identical. A mismatched-pair positive control reads max delta 255. Against the committed references, light-verify reads 46/46 FAIL on both arms with identical metrics (size, see Plan departures).
6. gui-verify IRShapeDebug -- --gui-test passes python3 scripts/gui-verify.py IRShapeDebug -- --gui-test [gui-verify] 49/49 assertions passed.
7. One unit test per pass boundary asserting two passes, plus a control asserting one fleet-run IrredenEngineTest --gtest_filter='MetalRenderPass*' (inside the 98-test run; re-run on the amend head) 15 cases pass on the amend head (14 before it, plus SlotClearedBetweenDrawsIsClearedOnTheSharedPass): ConsecutiveDrawsToOneTargetShareOnePass (1 pass), ComputeDispatchBetweenDrawsSplitsThePass, TextureUploadBetweenDrawsSplitsThePass, TextureClearBetweenDrawsSplitsThePass, BufferCopyBetweenDrawsSplitsThePass, RenderTargetChangeSplitsThePass, RequestedClearSplitsThePass, DrawSamplingAnAttachmentSplitsThePass, GpuTimingBoundarySplitsThePass (START and END), FinishSplitsThePass, MemoryBarrierSplitsThePass (2 passes each), plus RebindingTheSameTargetKeepsThePass, UntrackingAnAttachmentEndsThePass and SharedPassBlendsLaterDrawsOverEarlierOnes.
8. Stage timing rows keep their sample counts with no new invalid samples; GpuTimestamp* passes IRCanvasStress --auto-profile reports of the fixture, base vs head (every Debug and Release pair), compared row by row; GpuTimestamp* inside the 98-test run All 15 stage rows keep 359 samples on the head (rows lost: 0). Coverage reads attempted=360 valid=360 invalid=0 on both. entityCanvasToFb goes from window-only (its 391 encoders overflow the 128 sample pairs) to a sampled exclusive row. GpuTimestamp* passes.

Stage-row attribution (mean of the five Debug pairs, base → head): canvasClear 0.048 → 0.128 ms, voxelCompact 0.013 → 0.041 ms, trixelToFb 0.050 → 0.038 ms, cardinalSurfaceFb 0.277 → 0.100 ms. On the pre-rebase tree the Phase 0 arm, which reuses passes only inside the composite loop, moved these rows the same way. So the shifts come from the part both arms share: the texture upload and clear blits are now created through the device and sampled. Pass reuse does not cause them. The frame total accounts for the change: GPU commandBufferSpans 33.549 → 27.523 ms (−6.03 ms, upper −5.44), against the composite's −6.07 ms.

Plan departures

  • Plan corrections A1 (ebee6b621) and A2 (40cb99890) applied. This branch is origin/master 18a91f694 (carrying render/metal: key the render-pipeline cache by layout value, not address #5050, render/metal: patch partial buffer writes in place instead of orphaning #5057 and render: report Metal device failures in Release #5076) plus this change. The five draw functions use render/metal: key the render-pipeline cache by layout value, not address #5050's getRenderPipelineState(currentMetalRenderPipelineKey(...), layout.vertexDescriptor_) shape. render: report Metal device failures in Release #5076's device-error counters fold into the shared helpers: kDeviceErrorCounters goes through appendFrameDelta / appendCounterEntries beside kRenderPassCounters, and master's firstCommandBufferError* report lines are kept after them. Every reading above was retaken on this tree.
  • render-verify and light-verify are graded head against base, capture by capture, not against the committed references. On this host every offscreen capture is 1280x720 (1x), and the macos-debug references are 2560x1440. Every row fails on size on both arms, with identical metrics. The rows here compare each head capture with the same base capture at zero tolerance instead.
  • memoryBarrier ends the open pass. The plan's boundary list omits it ("nothing else ends it"). On Metal memoryBarrier was a no-op relying on one encoder per dispatch. With draws sharing a pass, a fragment write to device memory in one draw is not ordered before the next draw without a pass boundary. Ending the pass keeps the barrier contract (GL glMemoryBarrier parity). The composite loops call it once, after the loop, so it does not split them (MemoryBarrierSplitsThePass).
  • Binding the render target does not itself end the pass. The plan names bindMetal*RenderTarget and requestMetalRenderTargetClear as pass-ending. Instead the next draw compares its attachments and the pending clear against the open pass (the plan's own reuse rule). A rebind of the same framebuffer keeps the pass; a changed target or a clear opens a new one. The observable boundaries are unchanged, and tests cover both sides (RebindingTheSameTargetKeepsThePass, RenderTargetChangeSplitsThePass, RequestedClearSplitsThePass).
  • The stage row is read as its window. On the parent the entityCanvasToFb row is window-only (391 encoders exceed the 128 sample pairs), and run_matrix.py's report_metrics raises on it. The A/B reads the row's Window(ms) on both arms, the figure the controller README's 6.0–6.5 ms quotes. On the head the row resolves exclusive time, equal to its window (0.207 ms).
  • The base/head A/B uses the controller's fixture and ablation staging through an interleaving driver. run_matrix.py timing interleaves production and ablation within one binary and cannot interleave two builds. The driver imports the controller's COMMON, far-128 arguments and transform(..., "ablation"), and launches repeat_profile.py per arm against each frozen tree.
  • The criterion 2 parent row comes from a reuse-off control. The parent has no pass counter.

Notes for reviewer

Closes #4994

🤖 Generated with Claude Code

@jakildev jakildev added fleet:wip Work in progress — not ready for review fleet:author-claude Implementation last authored by Claude; route review to Codex fleet:authored-on-macos PR was authored and smoke-tested on macOS Metal backend labels Nov 16, 2026
@github-actions

Copy link
Copy Markdown

Perf gate

Head host slug: linux-x86_64-xeon-platinum-8370c-unknown

perf comparison: 7c08741 → 97185d3-ci

baseline: /home/runner/work/_temp/perf-baseline/history/linux-x86_64-xeon-platinum-8370c-unknown/7c087414203d0c2baf53b05fb7a0dca285f29615
head: /home/runner/work/IrredenEngine/IrredenEngine/save_files/perf/97185d34e-ci

host calibration

  • host: linux-x86_64-xeon-platinum-8370c-unknown (matches baseline)
  • ref_ms: head 115.39 vs baseline 116.12 (load_factor 0.99×)
  • calibration target: 50.00 ms (informational)
  • baseline capture: perf-baseline@7c0874142 (branch tip); master 2b1d20122, finished 2026-11-10T06:57:14Z, 6.1 d before the head run, ref_ms 116.12
  • weighting: raw (class-matched capture; load_factor 0.99×; no calibration-scaling entry)
  • attribution: no measured master improvement between capture master 2b1d20122 and merge base 345dbbf25 (55 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 262144 → 1024 0 → 0
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1 0.788 → 0.598 (-19.1pp) 156630 → 156630 262144 → 1024 50080 → 0 (0.000×)
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1 1.000 → 1.000 (+0.0pp) 262144 → 262144 262144 → 1024 0 → 0
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1 0.990 → 0.975 (-1.5pp) 255592 → 255592 262144 → 1024 3862 → 0 (0.000×)

frame timing (ms)

cell avg p99
target=IRLuaPerfGrid,zoom=1,sub_mode=full,sub_base=1 548.57 → 582.17 (+6.1%) 1782.55 → 1836.75 (+3.0%)
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1 1400.63 → 1336.68 (-4.6%) 2541.77 → 2505.59 (-1.4%)
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1 644.61 → 683.31 (+6.0%) 8996.10 → 9450.19 (+5.0%)
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1 1853.06 → 1873.13 (+1.1%) 2873.31 → 2959.57 (+3.0%)

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)

Window rows on one side and exclusive rows on the other measure different things, so these cells carry no stage marks: target=IRLuaPerfGrid,zoom=1,sub_mode=full,sub_base=1, target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1, target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1, target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1.

cell canvasClear voxelCompact voxelStage1 voxelCardinalElect voxelStage2 voxelSunFaces textToTrixel buildLightOcclusionGrid computeVoxelAO bakeSunShadowMap computeSunShadow computeLightVolume lightingToTrixel fogToTrixel trixelToFb resolvePerAxisScreenDepth fbToScreen
target=IRLuaPerfGrid,zoom=1,sub_mode=full,sub_base=1 71.90→21.27 62.27→63.75 55.07→55.35 1.44→1.55 58.09→57.92 6.39→93.69 — 0.00→0.00 2.48→2.57 16.98→34.80 20.11→21.83 22.51→25.33 4.13→4.45 1.28→1.46 0.26→0.28 — 9.62→9.58
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1 137.15→23.28 430.94→327.55 261.46→253.57 4.58→4.46 260.85→256.06 5.42→161.50 — 0.00→0.00 2.19→2.34 31.54→57.09 19.15→20.50 20.96→23.33 8.96→9.82 1.30→1.65 0.25→0.25 — 9.07→9.05
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1 64.31→20.33 74.86→76.86 59.76→60.46 9.37→9.39 51.25→52.54 7.98→87.67 1.55→1.69 0.00→0.00 1.04→6.63 50.12→62.07 19.23→19.97 46.09→47.05 6.82→6.95 1.78→1.92 0.23→0.27 0.00→0.00 10.46→10.71
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1 150.17→21.29 545.14→523.08 418.10→406.63 6.86→6.87 407.88→396.85 6.20→170.63 1.56→1.78 0.00→0.00 0.95→2.49 27.72→80.10 18.08→21.20 20.68→25.01 7.22→8.18 1.49→1.92 0.24→0.24 0.00→0.00 9.21→9.02

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 258.186 → 295.078 (+14.3%) ⚠
RENDER ComputeLightVolume 42.093 → 46.512 (+10.5%) ⚠
RENDER ComputeSunShadow 8.886 → 26.998 (+203.8%) ⚠
RENDER CanvasToFramebuffer 21.871 → 21.986 (+0.5%)
RENDER BakeSunShadowMap 10.411 → 10.177 (-2.2%)
UPDATE PropagateTransform 5.175 → 5.624 (+8.7%)
UPDATE FogRevealEval 5.008 → 4.904 (-2.1%)
RENDER LightingToTrixel 4.256 → 4.660 (+9.5%)

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

pipeline system avg ms (base→head)
RENDER SingleVoxelToCanvasFirst 1099.483 → 1022.785 (-7.0%) ↓
RENDER ComputeSunShadow 24.535 → 50.381 (+105.3%) ⚠
RENDER ComputeLightVolume 39.483 → 43.324 (+9.7%)
RENDER CanvasToFramebuffer 20.548 → 20.543 (-0.0%)
RENDER ComputeVoxelAO 8.641 → 10.073 (+16.6%) ⚠
RENDER LightingToTrixel 9.023 → 10.042 (+11.3%) ⚠
RENDER BakeSunShadowMap 9.093 → 9.085 (-0.1%)
UPDATE PropagateTransform 4.869 → 5.397 (+10.8%) ⚠

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

pipeline system avg ms (base→head)
RENDER SingleVoxelToCanvasFirst 276.966 → 320.707 (+15.8%) ⚠
RENDER ComputeSunShadow 42.505 → 54.167 (+27.4%) ⚠
RENDER ComputeLightVolume 40.970 → 43.111 (+5.2%)
RENDER LightingToTrixel 25.716 → 25.436 (-1.1%)
RENDER CanvasToFramebuffer 21.682 → 22.157 (+2.2%)
RENDER BakeSunShadowMap 13.045 → 13.731 (+5.3%)
UPDATE PropagateTransform 6.438 → 6.648 (+3.3%)
RENDER FogToTrixel 5.843 → 5.936 (+1.6%)

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

pipeline system avg ms (base→head)
RENDER SingleVoxelToCanvasFirst 1535.741 → 1523.048 (-0.8%)
RENDER ComputeSunShadow 20.850 → 73.060 (+250.4%) ⚠
RENDER ComputeLightVolume 38.296 → 45.500 (+18.8%) ⚠
RENDER CanvasToFramebuffer 20.398 → 20.444 (+0.2%)
RENDER BakeSunShadowMap 9.056 → 9.182 (+1.4%)
RENDER ComputeVoxelAO 7.156 → 8.452 (+18.1%) ⚠
RENDER LightingToTrixel 7.408 → 8.431 (+13.8%) ⚠
UPDATE PropagateTransform 6.497 → 6.477 (-0.3%)

@jakildev jakildev added the fleet:awaiting-infra Complete-but-unverifiable PR parked until an infra blocker lands; body carries Parked-until: #N label Nov 16, 2026
@jakildev

Copy link
Copy Markdown
Owner Author

Parking fleet:awaiting-infra on #4995 (PR #5076): fleet-pr-overlap --base master reads VERDICT: block.

#5076 engine/render/include/irreden/render/metal/metal_runtime.hpp conflicts
#5076 engine/render/include/irreden/render/render_device.hpp conflicts
#5076 engine/render/src/metal/metal_render_impl.cpp conflicts
#5076 engine/render/src/metal/metal_runtime.cpp base-conflict (conflicts with master 2455e3240 alone)
#5076 engine/render/src/metal/metal_texture.cpp clean
#5076 engine/world/include/irreden/world.hpp conflicts
#5076 engine/world/src/world.cpp conflicts

Every one of these rows is also #5076's own conflict with master: git merge-tree --write-tree --name-only origin/master origin/claude/4995-metal-device-errors lists the same files with this branch out of the picture. #5076 (head f34ee1e73) forked from #5057's pre-squash branch and lacks the squash 05f910839. Once #5076 is rebased onto master, re-run fleet-pr-overlap on this PR before waiting for the merge. The remaining true overlap is the one the plan expected: both siblings add a sub-struct to RenderDeviceStats and a counter group to World::recordDeviceCounters / buildAndWriteProfileReport. This branch's appendFrameDelta / appendCounterEntries take any (name, member pointer) table, so #4995's error counters fold in as one more table.

The work is otherwise complete: all eight criteria have evidence on a tree containing ebee6b621 (Plan corrections A1); see ## Acceptance evidence. fleet:wip stays until the overlap clears. — worker (pool-4)

@evin-mac-claude-app evin-mac-claude-app Bot added fleet:design-unblocked Architect responded; worker resumes per the architect comment + updated plan file and removed fleet:awaiting-infra Complete-but-unverifiable PR parked until an infra blocker lands; body carries Parked-until: #N labels Nov 18, 2026
@jakildev jakildev removed the fleet:design-unblocked Architect responded; worker resumes per the architect comment + updated plan file label Nov 18, 2026
Every Metal draw opened its own render pass and ended it, so the
entity-canvas composite paid one pass per detached canvas: 391 passes a
frame on the 128-caster fixture, and about 6.3 ms of entityCanvasToFb
against under 1 ms on OpenGL. The runtime now keeps one render pass open,
and a draw reuses it while its colour, depth and entity-id attachments
match, no clear is pending and none of its bound textures is one of
those attachments.

Creating a compute or blit encoder, a GPU timing boundary, a memory
barrier, present/finish, a command-buffer swap and untracking an
attachment each end the open pass first. Texture uploads and clears now
create their blit through the device, so they end it too. The profile
report gains renderPasses and draws counters.

Closes #4994

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jakildev jakildev added fleet:needs-fix Fleet reviewer found issues — author must address and removed fleet:reviewing-mac-pool-4 labels Nov 18, 2026
@jakildev jakildev removed the fleet:needs-fix Fleet reviewer found issues — author must address label Nov 18, 2026
@github-actions

Copy link
Copy Markdown

Perf gate

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

perf comparison: b309c9f → 34dcb3e-ci

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

host calibration

  • host: linux-x86_64-xeon-6975p-c-03-0-vga (matches baseline)
  • ref_ms: head 70.01 vs baseline 69.98 (load_factor 1.00×)
  • calibration target: 50.00 ms (informational)
  • baseline capture: perf-baseline@b309c9f60 (branch tip); master 40cb99890, finished 2026-11-18T00:35:20Z, 0.3 d before the head run, ref_ms 69.98
  • weighting: raw (class-matched capture; load_factor 1.00×; no calibration-scaling entry)
  • attribution: no measured master improvement between capture master 40cb99890 and merge base 18a91f694 (7 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) 156630 → 156630 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 451.04 → 440.82 (-2.3%) 1173.32 → 1158.81 (-1.2%)
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1 959.09 → 958.61 (-0.1%) 1732.18 → 1703.98 (-1.6%)
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1 503.95 → 506.56 (+0.5%) 6730.35 → 6814.24 (+1.2%)
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1 1357.59 → 1342.36 (-1.1%) 2036.00 → 2074.81 (+1.9%)

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
target=IRLuaPerfGrid,zoom=1,sub_mode=full,sub_base=1 16.87→16.61 48.76→48.02 41.56→41.08 0.78→0.77 41.64→41.53 70.15→70.45 — 0.00→0.00 1.53→1.48 17.83→17.55 14.46→14.46 12.15→12.15 2.90→2.77 0.99→0.97 0.16→0.15 ↓ — 6.71→6.62
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1 17.38→17.30 241.92→237.73 182.43→180.91 3.04→3.04 172.59→172.55 114.14→114.95 — 0.00→0.00 1.29→1.30 30.18→30.09 12.93→12.42 10.14→10.30 5.01→4.88 1.09→1.05 0.16→0.15 ↓ — 6.35→6.24
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1 15.45→15.69 55.69→56.23 44.44→44.37 6.62→6.61 37.16→37.84 65.84→65.54 1.29→1.30 0.00→0.00 4.16→4.24 38.79→39.26 12.29→12.98 29.16→29.26 4.86→4.88 1.38→1.38 0.15→0.15 0.00→0.00 7.13→7.16
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1 16.48→16.70 393.12→389.52 292.56→290.70 4.66→4.70 268.53→266.83 127.72→127.43 1.33→1.30 0.00→0.00 1.31→1.32 38.63→38.38 13.79→13.88 11.02→10.96 4.34→4.03 ↓ 1.18→1.12 0.15→0.14 ↓ 0.00→0.00 6.24→6.21

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 221.593 → 220.209 (-0.6%)
RENDER ComputeLightVolume 26.250 → 26.209 (-0.2%)
RENDER CanvasToFramebuffer 14.773 → 14.580 (-1.3%)
RENDER ComputeSunShadow 13.119 → 12.851 (-2.0%)
UPDATE FogRevealEval 8.618 → 8.255 (-4.2%)
RENDER BakeSunShadowMap 6.145 → 6.060 (-1.4%)
UPDATE PropagateTransform 3.668 → 3.611 (-1.6%)
RENDER LightingToTrixel 3.013 → 2.875 (-4.6%)

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

pipeline system avg ms (base→head)
RENDER SingleVoxelToCanvasFirst 729.250 → 724.213 (-0.7%)
RENDER ComputeSunShadow 26.492 → 26.257 (-0.9%)
RENDER ComputeLightVolume 22.641 → 22.327 (-1.4%)
RENDER CanvasToFramebuffer 14.167 → 13.846 (-2.3%)
UPDATE FogRevealEval 7.354 → 7.962 (+8.3%)
RENDER ComputeVoxelAO 6.886 → 7.025 (+2.0%)
RENDER BakeSunShadowMap 5.002 → 5.154 (+3.0%)
RENDER LightingToTrixel 5.192 → 5.033 (-3.1%)

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

pipeline system avg ms (base→head)
RENDER SingleVoxelToCanvasFirst 235.817 → 237.293 (+0.6%)
RENDER ComputeSunShadow 34.222 → 34.727 (+1.5%)
RENDER ComputeLightVolume 23.624 → 24.390 (+3.2%)
RENDER LightingToTrixel 18.734 → 18.775 (+0.2%)
RENDER CanvasToFramebuffer 14.799 → 14.617 (-1.2%)
RENDER BakeSunShadowMap 8.113 → 8.132 (+0.2%)
UPDATE FogRevealEval 7.265 → 6.908 (-4.9%)
UPDATE PropagateTransform 4.769 → 4.703 (-1.4%)

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

pipeline system avg ms (base→head)
RENDER SingleVoxelToCanvasFirst 1101.999 → 1094.875 (-0.6%)
RENDER ComputeSunShadow 34.622 → 34.383 (-0.7%)
RENDER ComputeLightVolume 24.498 → 24.462 (-0.1%)
RENDER CanvasToFramebuffer 13.496 → 13.408 (-0.7%)
UPDATE FogRevealEval 7.735 → 7.182 (-7.1%) ↓
RENDER ComputeVoxelAO 5.662 → 5.600 (-1.1%)
RENDER BakeSunShadowMap 5.175 → 5.113 (-1.2%)
UPDATE PropagateTransform 4.747 → 4.816 (+1.5%)

A shared render pass keeps every binding an earlier draw set on its
encoder, so a buffer unbound or a texture destroyed between two draws
stayed bound for the second. The open pass now records what its encoder
holds at each slot, and each draw sets every vertex buffer, fragment
buffer and texture slot whose value differs from that record, nil
included, leaving the encoder as a fresh one bound for that draw alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jakildev jakildev added fleet:changes-made Agent addressed human feedback — ready for human re-review and removed fleet:amending-mac-pool-1 labels Nov 18, 2026
@jakildev

Copy link
Copy Markdown
Owner Author

Addressed feedback:

  • Needs-fix, metal_render_impl.cpp:122 (stale binding on a reused encoder): fixed, without ending the pass. The runtime records what the open pass's encoder holds at each slot (MetalRenderPassBindings, emptied when a pass begins or ends). bindRenderResources now sets each vertex buffer, fragment buffer and texture slot whose value differs from that record, nil included, with the old precedence: storage over uniform at a shared index, and the vertex layout's buffer at vertex slot 0. A buffer unbound, or a texture destroyed or untracked, between two draws is cleared on the shared pass. untrackMetalTexture of a non-attachment still leaves the pass open, which is now safe.
  • Test plan item (second draw after unbind/untrack, under the debug layer): added MetalRenderPassTest.SlotClearedBetweenDrawsIsClearedOnTheSharedPass. Draw 1 binds a storage buffer and a texture at slots the shader never reads. The buffer is unbound and the texture destroyed, then draw 2 runs in the same pass (1 pass). The test asserts both slots are nil on the encoder's record and the sampled slot is kept. It passes under MTL_DEBUG_LAYER=1 MTL_DEBUG_LAYER_ERROR_MODE=assert. Positive control: with the old fill (nil slots skipped), it fails on the buffer and texture assertions.
  • Verification on the amend head, base 18a91f694, is in the body under "Review amend": unit tests, render-verify, a base/head capture control and gui-verify. The 36 IRShapeDebug reference failures are on master too: head and base captures of those passes are identical.
    — worker (pool-1)

@jakildev jakildev removed the fleet:changes-made Agent addressed human feedback — ready for human re-review label Nov 18, 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.

Re-review — render/metal: draw consecutive draws to one target in one render pass (#4994)

Verdict: approve

The amend clears buffer and texture slots that an earlier draw left on the shared encoder while preserving storage-over-uniform precedence and the vertex-layout binding at vertex slot 0; the prior needs-fix is resolved.

Acceptance (issue #4994)

8 of 8 planned criteria met.

Checked

  • Read the complete PR #5100 and issue #4994 threads, including the prior review, amend response, plan corrections A1/A2, and inline comments (none).
  • Delta-reviewed 729a98d3e..680aecc6f; no unrelated executable changes were added.
  • git diff origin/master...HEAD --check passed; no issue-closing TODO/FIXME markers remain.
  • fleet-build --target IrredenEngineTest completed successfully on macOS Metal.
  • fleet-run IrredenEngineTest '--gtest_filter=MetalRenderPass*:MetalStickyUntrack*' passed 20/20.
  • With MTL_DEBUG_LAYER=1 and MTL_DEBUG_LAYER_ERROR_MODE=assert, the same focused set excluding the deliberately invalid attachment-sampling case passed 19/19 and reported Metal API Validation Enabled.
  • GitHub format, headers, whitespace, instruction, close-lint, and comment-reference checks pass; fleet-tests, Linux build, perf gate, and all-checks remain pending and are not treated as green.

🤖 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-windows-smoke PR needs windows-debug build + smoke-run validation and removed fleet:reviewing-mac-pool-1 labels Nov 18, 2026
@github-actions

Copy link
Copy Markdown

Perf gate

Head host slug: linux-x86_64-xeon-platinum-8573c-unknown

Perf gate — no class-matched baseline

No capture of linux-x86_64-xeon-platinum-8573c-unknown on the baseline branch is in this head's calibration class (head ref_ms 90.53; a capture qualifies within 1.20× of it, finished at most 14 days before this head started, same matrix and frame count, every cell measured). The next master push that lands on this runner class files one. Gate is informational this PR.

Captures considered:

  • a990fd60f603e872fc1f7886ba7fa10ac223d6fb ref_ms 77.66 — older than 14 days
  • 87c1d6067c42bbf4e5e83d720675c876bbacb0ab ref_ms 79.91 — older than 14 days
  • 8e87859c96d0510bdfabd97838c7dafa79fddd53 ref_ms 82.71 — older than 14 days
  • d94ace876538c293d6fe16f134022f618368d916 ref_ms 77.59 — older than 14 days
  • 0e104317362fae808ba4ee6996fc7279b75b5673 ref_ms 84.81 — older than 14 days
  • 37e07cfd9754389831781205fd3e25ae489c6975 ref_ms 90.72 — older than 14 days
  • 56dff05ff0e4a46f9e1e5f6879a5ee778b2ac615 ref_ms 81.92 — older than 14 days
  • d80f5f9a2abd2b83f5606ac278d0d82b95cdd172 ref_ms 81.54 — older than 14 days
  • 02153359a5e8fdf1429745f474758262c9e3c861 ref_ms 91.85 — older than 14 days
  • c3ea76d802943336f7cc9b92b5fafaa8e9ff3b59 ref_ms 75.28 — outside the calibration band
  • 637bc06f012aafe1cb043130d648ae9f998ff558 ref_ms 91.11 — older than 14 days
  • 82cb65a30f95ca772a2f09a0eda5c0bc0239b5a2 ref_ms 87.83 — older than 14 days
  • 5f8a95c1d941d1d36ba7109f91e63563edc70b68 ref_ms 89.94 — older than 14 days

@jakildev jakildev added fleet:verified-windows Cross-host smoke passed on windows-debug and removed fleet:needs-windows-smoke PR needs windows-debug build + smoke-run validation labels Nov 18, 2026
@jakildev

Copy link
Copy Markdown
Owner Author

Cross-host smoke OK on windows (fresh checkout + IRShapeDebug --auto-screenshot 10 — build clean, RESULT=CLEAN exit 0, no shader compile warnings; only an engine-log note 'tagGpuStage: unknown stage name guiToScreen' and the usual GL header macro-redefinition C++ warnings).

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-macos PR was authored and smoke-tested on macOS Metal backend fleet:verified-windows Cross-host smoke passed on windows-debug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

render/metal: draw consecutive draws to one target in one render pass

1 participant