Repository navigation
render: report Metal device failures in Release - #5076
Conversation
Authored-by: Codex (GPT-5 runtime)
f34ee1e to
75c6ea7
Compare
|
Addressed feedback: rebased only the PR-owned commit onto current master; integrated the MetalRenderPipelineKey API and the adjacent profile-report test; reran Debug, Release, full C++, Python, lint, formatting, and header validation. Visual verification remains host-blocked after two supervised attempts because the macOS display is asleep, so the PR remains WIP with fleet:needs-macos-host. — worker |
Perf gateHead host slug: perf comparison: cc736b3 → eac59bf-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 |
191.271 → 222.619 (+16.4%) ⚠ |
| RENDER | ComputeLightVolume |
32.541 → 32.604 (+0.2%) |
| RENDER | ComputeSunShadow |
6.420 → 16.524 (+157.4%) ⚠ |
| RENDER | CanvasToFramebuffer |
15.320 → 15.239 (-0.5%) |
| RENDER | BakeSunShadowMap |
7.876 → 7.951 (+1.0%) |
| UPDATE | PropagateTransform |
3.863 → 3.899 (+0.9%) |
| RENDER | LightingToTrixel |
3.505 → 3.432 (-2.1%) |
| UPDATE | FogRevealEval |
3.191 → 3.239 (+1.5%) |
target=IRLuaPerfGrid,zoom=4,sub_mode=full,sub_base=1
| pipeline | system | avg ms (base→head) |
|---|---|---|
| RENDER | SingleVoxelToCanvasFirst |
726.460 → 699.248 (-3.7%) |
| RENDER | ComputeSunShadow |
16.643 → 32.211 (+93.5%) ⚠ |
| RENDER | ComputeLightVolume |
28.133 → 28.853 (+2.6%) |
| RENDER | CanvasToFramebuffer |
14.318 → 14.071 (-1.7%) |
| RENDER | ComputeVoxelAO |
5.987 → 7.073 (+18.1%) ⚠ |
| RENDER | LightingToTrixel |
6.759 → 6.967 (+3.1%) |
| RENDER | BakeSunShadowMap |
6.498 → 6.462 (-0.6%) |
| UPDATE | PropagateTransform |
3.765 → 3.764 (-0.0%) |
target=IRPerfGrid,zoom=1,sub_mode=full,sub_base=1
| pipeline | system | avg ms (base→head) |
|---|---|---|
| RENDER | SingleVoxelToCanvasFirst |
209.862 → 240.060 (+14.4%) ⚠ |
| RENDER | ComputeSunShadow |
33.923 → 39.613 (+16.8%) ⚠ |
| RENDER | ComputeLightVolume |
29.755 → 30.834 (+3.6%) |
| RENDER | LightingToTrixel |
19.508 → 19.694 (+1.0%) |
| RENDER | CanvasToFramebuffer |
15.191 → 15.454 (+1.7%) |
| RENDER | BakeSunShadowMap |
10.089 → 10.203 (+1.1%) |
| UPDATE | PropagateTransform |
5.249 → 5.303 (+1.0%) |
| RENDER | FogToTrixel |
4.581 → 4.599 (+0.4%) |
target=IRPerfGrid,zoom=4,sub_mode=full,sub_base=1
| pipeline | system | avg ms (base→head) |
|---|---|---|
| RENDER | SingleVoxelToCanvasFirst |
1005.008 → 1050.956 (+4.6%) |
| RENDER | ComputeSunShadow |
14.149 → 43.640 (+208.4%) ⚠ |
| RENDER | ComputeLightVolume |
28.577 → 31.863 (+11.5%) ⚠ |
| RENDER | CanvasToFramebuffer |
14.045 → 13.858 (-1.3%) |
| RENDER | BakeSunShadowMap |
6.710 → 6.851 (+2.1%) |
| RENDER | LightingToTrixel |
5.644 → 6.076 (+7.7%) |
| RENDER | ComputeVoxelAO |
4.908 → 5.927 (+20.8%) ⚠ |
| UPDATE | PropagateTransform |
5.189 → 5.292 (+2.0%) |
|
Design-unblocked validation progress on the awake macOS host:
The PR body now carries the exact evidence and leaves ShapeDebug unchecked. Keeping |
|
ShapeDebug validation update on the awake-then-sleeping macOS host:
The PR body now records these exact results. Because the master control could not complete, the 20 PR-head rows cannot yet be classified as inherited or introduced. Keeping |
|
Addressed feedback:
— worker (Codex) |
jakildev
left a comment
There was a problem hiding this comment.
Review — Metal device errors: descriptive exceptions and command-buffer/skipped-frame counters
Verdict: approve
The change does what #4995 asked: allocation, shader-library and render-pipeline failures throw named std::runtime_errors in Debug and Release, and command-buffer errors and skipped frames flow through DeviceErrorStats into the profile report and repeat_profile.py. I found no blocker or needs-fix defect.
Nits (follow-up)
engine/render/src/metal/metal_runtime.cpp:645-698—newMetalBuffer/newMetalTexturecheck the test-onlyfailNextAllocationArmed_seam on every production allocation. It is a single bool read and harmless, but the seam entry points (failNextMetalAllocationForTesting,failNextMetalRenderPipelineForTesting,compileMetalRenderPipelineForTesting) live in the publicmetal_runtime.hpp. Consider adetail/testing header next time this file is touched.test/render/gpu_compute_dispatch_test.cpp:1074-1089—CommandBufferAndSkippedFrameCountersAreReportedassertsfirstCommandBufferErrorFrame_ == 23and the exact first-error text.recordMetalCommandBufferCompletionkeeps only the first error per process, so the test passes only while no earlier test or real frame has recorded one. Today that holds. Asserting on the delta, or resetting the first-error state in the fixture, would remove the order dependence.engine/render/src/metal/metal_pipeline.cpp:320-330— the newthrowfor a missing shader function leaves the already-createdMTL::Functions and library of earlier stages unreleased. This is a leak on a path that already terminates the run, so it is only worth tidying if the constructor is reworked.
Praise
- Replacing
IR_ASSERTwith a thrown exception fixes a real Release gap: the old assert stripped its expression and condition in Release, so an allocation failure was a null dereference there. firstCommandBufferError_is astring_viewinto runtime-owned storage that is written once and never reassigned, so the by-valueRenderDeviceStatscopy indeviceStats()stays valid.recordCompletedFrameBufferruns only afterwaitUntilCompleted()inpresent()/finish(), so the counters are mutated on the render thread with no completion-handler race.- The report writer and
World::buildAndWriteProfileReportgate the new counters on the existingdeviceCountersSupported_, so OpenGL does not report zeros as measured.
Checked
- Read the full diff and the touched call sites in
metal_render_impl.cpp(beginFrame,present,finish,recordCompletedFrameBuffer) andworld.cpp(recordDeviceCounters,buildAndWriteProfileReport). - CI, inherited red:
render-harness-testsis red on this head becausetest_harness_dependency_contract.pyflagsscripts/verify_common.pyimportingfleet. This PR does not touch that file (empty diff vs master). I ran the test on the PR head (reproduces, 3 failures) and on currentorigin/master(13 tests OK, fixed upstream by #5109 after this branch's merge base, 2026-11-15). The failing run is from 2026-11-16 on this same head, so a rebase or re-run onto current master should clear it. Not held against the PR. - CI, all other checks on the head are green:
linux-build,header-checks,format-check,fleet-tests,python-lint,perf-gate,comment-refs,closes-lint. - Acceptance: the body says
Refs #4995, notCloses, so I did not dispatch the acceptance grader. I read the## Acceptance evidencetable against the diff: each of criteria 1-6 is backed by a test in the diff, and criterion 7's departure (inherited ShapeDebug and CanvasStress rows, same-session master control) is documented. - Not run by me: the Metal gtest suite,
render-verifyandlight-verify(macOS-host; I am relying on the author's recorded job IDs).
Test plan the author should run before merge
- Re-run
render-harness-testson a master-rebased head to confirm the inherited red clears.
Escalation: please Opus-recheck before merge (touches: engine/render, engine/world).
🤖 Reviewed by Claude Sonnet 5.5 (review-pr skill)
Opus recheck required: touches engine/render/ (Metal allocation, pipeline, and command-buffer error paths) and engine/world/ (per-frame device-counter bookkeeping); how thrown allocation failures propagate through frame init, and the lifetime of the string_view first-error handoff, deserve a core-path read.
jakildev
left a comment
There was a problem hiding this comment.
Opus recheck — Metal device errors: descriptive exceptions and command-buffer/skipped-frame counters
Verdict: approve
I agree with Sonnet's approve. I spent this pass on the two items Sonnet escalated: where the new throws land, and the lifetime of the string_view first-error handoff. I also checked counter coverage across every commit site and the per-frame cost. Neither escalated item hides a defect.
Sonnet's escalation items
- Throw propagation through frame init. Sonnet asked how a thrown allocation failure propagates. On closer read it is safe.
World::gameLoop'scatch (...)(engine/world/src/world.cpp:445) runsend()and rethrows, so a failure inside a frame still ends the process, with a named message where Release used to dereference null. Every constructor that throws releases itsMTL::TextureDescriptorfirst (metal_texture.cpp,metal_render_impl.cppoffscreen target).getRenderPipelineStatereleases its descriptor before the null check. The test helper releases its vertex descriptor on both paths. No newnoexceptboundary sits on these paths. string_viewlifetime. I confirm Sonnet's read.firstCommandBufferError_points atMetalRuntimeState::firstCommandBufferErrorText_, which is written only while the view is empty.shutdownMetalRuntime(g_runtime() = MetalRuntimeState{}) resets the view and its backing string together, so they never come apart.Worldcopies the view intom_deviceErrorsAtLastFrameand the per-frame deltas but never reads it there; onlybuildAndWriteProfileReportreads it, from a freshdeviceStats(), and copies it into an owningstd::string.
Opus-only checks
- Counter coverage. Every Metal commit site counts: there are exactly two (
present()andfinish(),metal_render_impl.cpp:462/1133), and both callrecordCompletedFrameBufferafterwaitUntilCompleted(). That also covers command buffers that a mid-framefinish()commits. Both calls run on the render thread, so there is no completion-handler race. - Hot path.
newMetalBuffersits onreplaceBacking, which can run once per frame. It adds one bool read and astring_viewargument next to anewBuffercall, so the cost is negligible.recordDeviceCountersstill callsdeviceStats()once per frame.m_frameDeviceErrorsfollows the existingm_frameBufferWritesreserve-then-grow pattern with the same warm-up divisor. - Report and parser. The new rows use the existing
DEVICE_COUNTER_REshape.device_counter_lineslists only names that every run reports, so mixing an old run with a new one cannot raise aKeyError. TheFirst command-buffer error:line falls through the parser as an unmatched line.
Nits (follow-up)
engine/render/src/metal/metal_buffer.cppresize():m_sizeis assigned beforenewMetalBufferruns. If the allocation throws and a caller catches it, the object keeps the old, smaller backing but reports the new size, and a latersubDataof up tom_sizebytes writes past it. Today the only broadstd::exceptioncatches are Lua script loading (lua_script.cpp:569,prefab_api.cpp), so this needs an out-of-memory failure inside a script-driven resize. Before this PR the same failure crashed outright. Allocating into a local and assigningm_sizeafter success gives the strong guarantee at no cost.beginFrame's newlayer == nullptrbranch can only run for the headless bootstrap device. The comment abovebootstrapHeadlessRenderDevicestill says a headless test never callsbeginFrame. Either the branch has a caller this PR adds (I found none intest/), or it is defensive code the comment should mention.recordMetalCommandBufferCompletiononly records a "first" error while the stored text is empty. An error whoselocalizedDescriptionis non-null but empty therefore leaves the slot open, and a later error overwrites the reported first frame. Testing a separatehasFirstErrorflag, or the frame number, would remove that edge.- I confirm Sonnet's three nits: the test seams sit in the public
metal_runtime.hpp, the== 23first-error assertion depends on test order, and the missing-function throw leaks the earlierMTL::Functions.
Checked
- Read the full diff, plus the surrounding
beginFrame/present/finish/bootstrapHeadlessRenderDevicecode,MetalRuntimeStateandshutdownMetalRuntime,World::recordDeviceCounters/buildAndWriteProfileReport, thecatchsites acrossengine/, and therepeat_profile.py/compare_perf_runs.pycounter parsing. - CI:
render-harness-tests(and thereforeall-checks) is still red on this head. I accept Sonnet's attribution, verified on both trees, to the inheritedverify_common.pycontract failure that #5109 fixed on master after this branch's merge base. Every other check is green. - Not run by me: the Metal gtest suite,
render-verifyandlight-verify(macOS host). I am relying on the author's recorded job IDs and the same-session master control for criterion 7.
🤖 Reviewed by Claude Opus 5.5 (opus-reviewer, review-pr skill)
|
Cross-host smoke OK on windows (fresh checkout + IRShapeDebug --auto-screenshot 10 — build clean, ir-run RESULT=CLEAN exit 0, no shader/compile warnings; one pre-existing runtime profiler-registry warning 'tagGpuStage: unknown stage guiToScreen' from a file this PR does not touch). |
Summary
Plan departures
origin/masterby replaying only its own commit. The failure path and test seam now use the currentMetalRenderPipelineKeyAPI, while the merged base implementation is inherited from master.IRCanvasStresspasses all 59 checks but carries the same inheritedso3_wide_parityreading on PR head and master.IRShapeDebughas 20 failing reference rows on PR head; every one appears on same-sessionorigin/masterwith identical metrics. This PR does not move either set of rows.Acceptance evidence
fleet-run IrredenEngineTest --gtest_filter='MetalDeviceErrorsTest.*:ProfileReportDeviceErrors.*'BufferAllocationFailureNamesKindAndSizepassed and observedbufferplus64 bytes.TextureAllocationFailuresNameDimensionspassed for17x19x1and7x11x13.CommandBufferAndSkippedFrameCountersAreReportedpassed with +1 for each counter and first error frame/text23/injected command failure; the headless fixture did not count its null layer as a skipped drawable.fleet-run --release IrredenEngineTest --gtest_filter='MetalDeviceErrorsTest.*:ProfileReportDeviceErrors.*'python3 -m unittest discover -p 'test_*.py'inscripts/perf; focused C++ suite abovelight-verify, pairedIRCanvasStressruns, and same-session pairedIRShapeDebugmanifestsso3_wide_paritymetric. On 2026-11-17, PR head75c6ea77job20261117T221545Z-render-verify-7bdb33completed 148 checks: 20 failed and 10 skipped for pending references. Current master44955ae9control job20261117T224037Z-render-verify-f76179completed 176 checks: all 20 PR-head failures reproduced with identical metrics; its additional failures belong to post-PR master changes. Both terminal jobs exited 1 for reference mismatches with an awake macOS display; no host-domain failure occurred.Test plan
fleet-run IrredenEngineTest— 3,839 passed, 3 expected backend/platform skipspython3 -m unittest discover -p 'test_*.py'fromscripts/perf— 167 passedruff check scripts/fleet-build --target header-checks— 844 headers scanned; all convention checks passedfleet-build --target format-changedgit diff --checkpython3 scripts/light-verify.py --if-changed— 46 checks passed on macOS Metalpython3 scripts/render-verify.py --target IRCanvasStress— 59/59 twice; same-session master metrics matchpython3 scripts/render-verify.py --target IRShapeDebug— every PR-head failure reproduced on same-session current master with identical metricsRefs #4995
Authored by Codex (GPT-5 runtime).