Repository navigation
render/metal: draw consecutive draws to one target in one render pass (#4994) - #5100
Conversation
Perf gateHead host slug: perf comparison: 7c08741 → 97185d3-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)Window rows on one side and exclusive rows on the other measure different things, so these cells carry no stage marks:
top CPU systems by avg ms (head)
|
| 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%) |
|
Parking Every one of these rows is also #5076's own conflict with master: The work is otherwise complete: all eight criteria have evidence on a tree containing |
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>
6d17dfb to
729a98d
Compare
Perf gateHead host slug: perf comparison: b309c9f → 34dcb3e-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 |
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>
|
Addressed feedback:
|
jakildev
left a comment
There was a problem hiding this comment.
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 --checkpassed; no issue-closing TODO/FIXME markers remain.fleet-build --target IrredenEngineTestcompleted successfully on macOS Metal.fleet-run IrredenEngineTest '--gtest_filter=MetalRenderPass*:MetalStickyUntrack*'passed 20/20.- With
MTL_DEBUG_LAYER=1andMTL_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).
Perf gateHead host slug: Perf gate — no class-matched baselineNo capture of Captures considered:
|
|
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). |
Summary
openMetalRenderPass/beginMetalRenderPass/endMetalRenderPassinmetal_runtime).renderEncoderForDrawreuses 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).bindRenderResourcessets 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.createComputeEncoder/createBlitEncoder), a GPU timing boundary (writeTimestamp),memoryBarrier,present()/finish(), a command-buffer swap (setMetalCommandBuffer), runtime shutdown, anduntrackMetalTextureof one of its attachments.Texture2D::subImage2Dandclearnow create their blit throughcreateMetalBlitEncoder, so they end the open pass and are sampled by sub-stage timing.RenderDeviceStatsgainsRenderPassStats { renderPasses_, draws_ }. The profile report printsrenderPassesanddrawsrows beside the buffer-write counters, andWorldshares 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, thenfleet-run IrredenEngineTest --gtest_filter='MetalRenderPass*:GpuTimestamp*:MetalStickyUntrack*:MetalGpuComputeDispatchTest.*:PositionUploadTest.*:*ProfileReport*:*DeviceCounter*:*DeviceError*:*CommandBufferError*'→[ PASSED ] 98 tests.Fullfleet-run IrredenEngineTest→ 4138 passed, 3 skipped, 0 failed.MTL_DEBUG_LAYER=1 MTL_DEBUG_LAYER_ERROR_MODE=assert(headless device) →Metal API Validation Enabled,[ PASSED ] 60 tests.SlotClearedBetweenDrawsIsClearedOnTheSharedPass):MetalRenderPass*:MetalStickyUntrack*:GpuTimestamp*:MetalGpuComputeDispatchTest.*→[ PASSED ] 61 tests.;MetalRenderPass*:MetalStickyUntrack*underMTL_DEBUG_LAYER=1 MTL_DEBUG_LAYER_ERROR_MODE=assert→Metal API Validation Enabled,[ PASSED ] 19 tests.(DrawSamplingAnAttachmentSplitsThePassexcluded: it is the deliberately invalid draw). Fullfleet-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.gui-verify(rows below).Acceptance evidence
Every reading below comes from the rebased head
729a98d3e, a tree containingebee6b621(#5050) and40cb99890(#5076), per Plan corrections A1 and A2. Base =origin/master18a91f694; 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 isQUIET=guardedand CLEAN (Debug logs:Discovered 2 display monitors,paced at 120 Hz); no run needed a repeat. Each arm is onescripts/perf/repeat_profile.py --repeats 1run against its own frozen build tree (--build-dir). The fixture isrun_matrix.py'sCOMMON+far-128(128 coincident casters above a grid floor, 360 frames), with itsablationsampler (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
18a91f694base. This host now has one built-in 2x display, so the committed references apply directly:render-verify:IRCanvasStress59/59 PASS andIRPerfGrid35/35 PASS against the references.IRShapeDebug140/176 PASS, 36 FAIL, 10 references pending. The 36 failures are on master too. Every failing row comes from the default pass, ansdf_baked_*pass,lod_scene, or a*_standard_offpass that repeats the default shots. The default,sdf_baked_pose_rootandlod_scenepasses, run from a18a91f694tree 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.729a98d3eand 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.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.entityCanvasToFbbase 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%).--- 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 withopenMetalRenderPassforced to return nullptr, i.e. the parent's one-pass-per-draw behaviour.renderPassessteady 391.000/frame,draws391.000/frame (one pass per draw). Head, all ten Debug and Release runs:renderPasses5.000/frame,draws391.000/frame (1 pass per 78 draws).entityCanvasToFb(sun query off) falls by at least half, Debug and Release, judged by the upper boundrepeat_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 posescripts/perf/sun_depth_slab_timing.pyapplies. 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.render-verifymax delta 0 forIRShapeDebug,IRCanvasStress,IRPerfGrid; nine-yawIRCanvasStressset RGB-identical to the parent;light-verify --if-changedpassespython3 scripts/render-verify.py --target <T> --no-buildfrom each tree, every compared capture archived and paired head against base at zero tolerance (render-compare, per-pixel tol 0)text_scale1_legibility, segfaults at startup on base and head alike (glfwSetWindowSizeunder 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-verifyreads 46/46 FAIL on both arms with identical metrics (size, see Plan departures).gui-verify IRShapeDebug -- --gui-testpassespython3 scripts/gui-verify.py IRShapeDebug -- --gui-test[gui-verify] 49/49 assertions passed.fleet-run IrredenEngineTest --gtest_filter='MetalRenderPass*'(inside the 98-test run; re-run on the amend head)SlotClearedBetweenDrawsIsClearedOnTheSharedPass):ConsecutiveDrawsToOneTargetShareOnePass(1 pass),ComputeDispatchBetweenDrawsSplitsThePass,TextureUploadBetweenDrawsSplitsThePass,TextureClearBetweenDrawsSplitsThePass,BufferCopyBetweenDrawsSplitsThePass,RenderTargetChangeSplitsThePass,RequestedClearSplitsThePass,DrawSamplingAnAttachmentSplitsThePass,GpuTimingBoundarySplitsThePass(START and END),FinishSplitsThePass,MemoryBarrierSplitsThePass(2 passes each), plusRebindingTheSameTargetKeepsThePass,UntrackingAnAttachmentEndsThePassandSharedPassBlendsLaterDrawsOverEarlierOnes.GpuTimestamp*passes--auto-profilereports of the fixture, base vs head (every Debug and Release pair), compared row by row;GpuTimestamp*inside the 98-test runattempted=360 valid=360 invalid=0on both.entityCanvasToFbgoes fromwindow-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):
canvasClear0.048 → 0.128 ms,voxelCompact0.013 → 0.041 ms,trixelToFb0.050 → 0.038 ms,cardinalSurfaceFb0.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: GPUcommandBufferSpans33.549 → 27.523 ms (−6.03 ms, upper −5.44), against the composite's −6.07 ms.Plan departures
ebee6b621) and A2 (40cb99890) applied. This branch isorigin/master18a91f694(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'sgetRenderPipelineState(currentMetalRenderPipelineKey(...), layout.vertexDescriptor_)shape. render: report Metal device failures in Release #5076's device-error counters fold into the shared helpers:kDeviceErrorCountersgoes throughappendFrameDelta/appendCounterEntriesbesidekRenderPassCounters, and master'sfirstCommandBufferError*report lines are kept after them. Every reading above was retaken on this tree.macos-debugreferences 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.memoryBarrierends the open pass. The plan's boundary list omits it ("nothing else ends it"). On MetalmemoryBarrierwas 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 (GLglMemoryBarrierparity). The composite loops call it once, after the loop, so it does not split them (MemoryBarrierSplitsThePass).bindMetal*RenderTargetandrequestMetalRenderTargetClearas 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).entityCanvasToFbrow iswindow-only(391 encoders exceed the 128 sample pairs), andrun_matrix.py'sreport_metricsraises on it. The A/B reads the row'sWindow(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).run_matrix.py timinginterleaves production and ablation within one binary and cannot interleave two builds. The driver imports the controller'sCOMMON,far-128arguments andtransform(..., "ablation"), and launchesrepeat_profile.pyper arm against each frozen tree.Notes for reviewer
DeviceErrorStats/errors_besideRenderPassStats/renderPasses_, bothdeviceStats()initializers, bothWorldmember pairs, andkDeviceErrorCountersfolded intoappendFrameDelta/appendCounterEntries.git range-diff 2455e3240..6d17dfb0a origin/master..729a98d3ediffers only in those hunks.fleet-pr-overlap --base masteron the rebased head: no open competitor overlaps except render: bound Metal frame overlap and pace input [WIP] #5161 (render/metal: present without blocking the CPU on the GPU, with no added input latency #5000,fleet:wip+fleet:awaiting-infra), whose body says its overlap gate requires sequencing behind render/metal: draw consecutive draws to one target in one render pass #4994. It rebases after this lands.Closes #4994
🤖 Generated with Claude Code