Repository navigation
borealis: lose the device when a pass overflows its geometry heap - #1424
DjDeveloperr merged 3 commits into
Conversation
Geometry shaders, tessellation, software index robustness and restart unrolling allocate from a fixed geometry heap on the GPU. A pass that needs more than the heap holds either drops the draw without a word (GS setup, robust index, restart unroll) or halts the allocating thread and lets the next stages run on parameters it never wrote (GS and tessellation index buffers, tessellation patches). Only the latter reached the application, as a generic "GPU abort", and only after the wrong frame was drawn. Every allocator bumps the heap's bottom before it checks that the allocation fits, so at the end of a pass bottom > size exactly when one of them failed. The heap reset that ends each such pass now checks that and sets a status word next to the heap descriptors, a new kind of libagx_write_u32s entry (LIBAGX_IMM_WRITE_HEAP_RESET) that keeps the entry layout. hk_check_status() reads the word and loses the device with a message naming the geometry heap overflow, after flushing the allocator's own printf message. HK_GEOMETRY_HEAP_SIZE_B names the slot size the message reports. hk-vulkan-heap-overflow draws points through a pass-through geometry shader with an indirect draw: 1024 points must render, 32M points need at least 512 MiB of vertex outputs from the heap and must lose the device. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
067b056 to
a08505e
Compare
There was a problem hiding this comment.
Verdict: HOLD at a08505ef
Blockers:
- Missing second GPU-generation regression row (
Not yet: other Macs). This change modifies sharedsrc/asahi/libagx/query.cl,query.h,hk_device.c,hk_cmd_draw.c, andhk_query_pool.cacross all Macs Borealis runs on; please post a second GPU-generation hardware row (e.g., G16 or M5) alongside the J616s (G17P) verification before merge.
Checked:
- Full non-test diff (
src/asahi/libagx/query.{cl,h},src/asahi/vulkan/hk_{cmd_buffer.h,cmd_draw.c,device.c,device.h,query_pool.c},meson.build,+426/-12across 14 files),MERGEABLEagainstaurora-wip. struct libagx_imm_writeretains 16-byte layout (static_assert+ i386 layout test) withkind == 0preserving plain stores for all existing Vulkan/GL callers;LIBAGX_IMM_WRITE_HEAP_RESETchecksaddress[0] > address[1](static_assertverifiessizeimmediately followsbottominstruct poly_heap), writes1todev->rodata.heap_overflow_addr, and zeroesbottom.hk_check_status()checksdev->rodata.heap_overflowfirst, flushes the GPU printf buffer, logs a clear message naming the 128 MiB geometry heap overflow, and loses the device viavk_device_set_lost().- Thorough J616s (
M4 Pro,G17P) exact-head verification:hk-vulkan-heap-overflow, 256 KiB slot stress (70/70clean device loss vs63silent wrong frames),dq-fastheap/api/memory parity,meson --suite asahi230/230, GLES3392/392, and 4 Sascha Willems perf samples neutral within noise.
Evidence
- Code, layout assertions, and J616s G17P verification are solid; strictly awaiting a second GPU-generation regression row for the shared
libagx/ Borealis paths.
Reserve aligned spans without wrapping the heap cursor. Stop dependent draws and dispatches on failed reservations and apply the same per-entry reset in both immediate writers. Transition the probe's attachment, enable geometry point size and verify the fitting draw by reading back a white pixel. Signed-off-by: DjDeveloperr <hey@djdev.me>
There was a problem hiding this comment.
Hold at e6ea44a. The delta latches heap exhaustion until reset, checks the status in both immediate-write paths, and initializes indirect records before the failure abort. Please run the constrained-heap case on the current head and include a second GPU generation. Exercise tessellation setup and prefix-sum failure and verify bounded device loss without a subsequent GPU fault. The posted J616s row predates the allocator and indirect-record changes.
Accumulate the workgroup reductions in 64 bits. Pass the full total to the heap reservation before using the draw count or per-patch offsets. This also avoids rereading the last prefix written by another lane. Signed-off-by: DjDeveloperr <hey@djdev.me>
There was a problem hiding this comment.
Verdict: HOLD at 05afa095
Blockers:
- Exact-head build, unit tests, and hardware verification at
05afa095missing: New commitse6ea44ac(asahi: latch geometry heap exhaustion until either reset path) and05afa095(asahi: retain the full tessellation index total at reservation) rewritepoly_heap_try_alloc_offs()to aPOLY_HEAP_EXHAUSTEDCAS latch, widenpoly_prefix_sum()/ GS / tessellation reservations to 64-bit, routelibagx_write_u32s_ordered()throughlibagx_apply_imm_write(), and add pixel readback tohk_vulkan_heap_overflow.c. Please post fresh build + unit test (poly_heap_math_tests,--suite asahi --suite poly) and hardwarehk-vulkan-heap-overflow/ CTS results at05afa095(current evidence is froma08505efb). - Second GPU-generation regression row missing: Current hardware evidence covers
J616s(M4 Pro,G17P) only. Because this touches sharedlibagx,poly, and Borealis heap-reset / geometry / tessellation paths across all generations, please add an exact-head05afa095row on a second GPU generation (e.g., M1/M2/M3/M4-base/M5).
Checked:
- Audited commits
e6ea44acand05afa095:poly_heap_next_bottom()+poly_heap_try_alloc_offs()(src/poly/poly_heap_math.h,src/poly/geometry.h): cleanatomic_compare_exchange_weakloop latchingPOLY_HEAP_EXHAUSTED(0xffffffffu) on any overflow or 64-bit size exceeding capacity, closing the previous 4 GiBatomic_fetch_addwraparound hole; covered by new assertions inpoly_heap_math_tests.c.libagx_apply_imm_write()(src/asahi/libagx/query.cl): shared by bothlibagx_write_u32s()andlibagx_write_u32s_ordered(), atomically recording device loss when*address > address[1] || *address == POLY_HEAP_EXHAUSTEDbefore resetting*address = 0.poly_prefix_sum(),libagx_prefix_sum_tess(),libagx_tess_setup_indirect(),poly_gs_setup_indirect_inner(),poly_heap_alloc_points(), andpoly_tess_*_process(): retain 64-bit totals before heap reservation, zeronr_patches/out_draws[0]on exhaustion so downstream stages never read unallocated heap memory, and preserveabort()for Gallium callers.hk_vulkan_heap_overflow.c: cleanly adds RGBA8 white-pixel readback verification and fence wait.
Evidence
- Head commit:
05afa095on top ofe6ea44acanda08505ef(MERGEABLEintoaurora-wip). - No automated CI checks attached to this branch; PR body evidence is still tagged at
a08505efbonJ616sonly.
|
Hardware row on 14-inch MacBook Pro M5 Pro (
|
There was a problem hiding this comment.
Verdict: MERGE at 05afa095
Blockers: None.
Checked:
- Exact-head
05afa095second-generation hardware row onJ714s(14-inch MacBook Pro M5 Pro,G17S B1, fw27.2) clears both remaining holds:meson test -C build --suite asahi:226/226 OK(0fail).- Live
hk-vulkan-heap-overflowPASS (fitting draw (1024 points): 0with white RGBA8 readback,overflowing draw (33554432 points): -4VK_ERROR_DEVICE_LOSTwith geometry heap overflow message,hk_vulkan_heap_overflow: OK),0GPU faults/recoveries/resets,0failed systemd units.
- Combined with prior
J616s(M4 Pro,G17P) 256 KiB slot overflow,dq-fast, GLES3 (392/392), and Sascha Willems A/B evidence plus full audit ofe6ea44ac+05afa095(POLY_HEAP_EXHAUSTEDCAS latch,libagx_write_u32s_orderedreset path, 64-bit tessellation/GS totals, and pixel readback test).
Evidence
- Head commit:
05afa09523b57e1b386b79f64fb31d6c10180503(MERGEABLEintoaurora-wip). - Second-gen exact-head row comment (
tully-8888,2026-11-30T22:01:17Z).
|
@DjDeveloperr, code-owner heads-up: App approval at |
|
PASS on M4 mini J773g (G16G) at Kernel: saved stock Driver unit tests (CPU only)
The intentional overflow left no GPU fault, firmware recovery or kernel error. The Khronos validation layer is not installed on this Mac, so the probe ran without it. Vulkan CTS (Borealis): 1955 cases from
GLES3 on the shared libagx paths (Gallium asahi, surfaceless):
Not covered on J773g
CTS: |
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Code approved at 05afa09523b5. Both reset writers report a latched heap failure, and dependent draws are suppressed. The tessellation reservation now receives the full index total across workgroups. The Vulkan probe enables the geometry point-size feature, transitions its attachment and checks the fitting pixel.
The warm build generated both tessellation-prefix variants for G16G and G17P. Heap arithmetic and both reset controls passed, and the fitting draw returned white on Radeon. Controlled overflow and a healthy second device still need an Apple GPU row.
What: A geometry, tessellation or index pass that needs more geometry heap than its 128 MiB slot holds either dropped its draws without a word (GS setup, robust index, restart unroll) or halted the allocating thread and let the next stages run on parameters it never wrote (GS and tessellation index buffers, tessellation patches), reported at best as a generic "GPU abort" after the wrong frame. Now every such overflow loses the device with a message that names it.
Tested: J616s M4 Pro (G17P), kernel m4.212, at a08505e on aurora-wip 89ddabb:
hk-vulkan-heap-overflow: a 1024-point GS draw renders; a 32M-point draw loses the device and stderr showsMESA: error: geometry heap overflow: … needed more than its 128 MiB heap slot; device lost(base: silently drawn as nothing).--suite asahi230/230.api.info,memory.*0 differ vs base, and GL (shared libagx): GLES3 392/392 and the texture probe correct — at the first head 635c471f7, which differs only inhk_check_status()(check order, the stderr line) and lacks the test.Risk: two-way door · all Macs Borealis runs on; libagx is shared with the GL driver, but GL never builds the new write kind
Not yet: other Macs. The halting paths (tessellation, GS prefix sum) still run their next stages on unwritten parameters until the CPU sees the status word; no fault was seen in the 256 KiB run, but that path is not made fault-free here.
Details
poly_heap_alloc_offs(),poly_heap_try_alloc_offs()) bumpsbottomwith an atomic add before it checks the allocation fits. So at the end of a pass,bottom > sizeexactly when one of its allocations failed, whichever path it took.libagx_write_u32s's list. Its padding word becomeskind:LIBAGX_IMM_WRITE_HEAP_RESETchecksbottom > size(size is the next word ofpoly_heap), sets the status wordvaluebytes away, then zeroesbottom. The entry stays 16 bytes, and all other entries are kind 0, a plain store as before. Render packing still sees the same post-graphics reset.hk_queue_reset_heap()).hk_check_status(), which the runtime calls on waits, checks it first. It flushes the printf buffer, where the halting allocators' "GPU heap overflow" line sits, then prints "geometry heap overflow: … needed more than its 128 MiB heap slot; device lost" withmesa_loge()(vk_device_set_lost() logs only to debug messengers in release builds) and loses the device.HK_GEOMETRY_HEAP_SIZE_Bnames the slot size.query.h): failed requests summing past 4 GiB in one pass wrapbottomand go unreported; the halting allocators still report through printf.Evidence
Builds of aurora-wip
89ddabbf7+ this commit (GL + Vulkan), kernel 7.3.0-m4.212, shared gpu-runs:aw-89ddabbf70 GPU recoveries, 0 new kernel err lines, 0 failed units.
Perf A/B (geometry/tessellation draws, normal 128 MiB slots). Base
89ddabbf7vs heada08505efb, same GL + Vulkan release config,VK_DRIVER_FILES, no install. J616s M4 Pro, kernel 7.3.0-m4.212, on AC (macsmc-ac/online= 1 at start and end), one perf gpu-run 2026-11-30 20:54-21:03 UTC, 0 GPU recoveries. Workload: Sascha Willems Vulkan samples, commit4415c09b08f3(assetsa27c0e58), built with-DUSE_HEADLESS=ON -DCMAKE_BUILD_TYPE=Release; each runVK_DRIVER_FILES=<icd> bin/<sample> -b -bw 3 -br 10 -w 1920 -h 1080 -bf <csv>(3 s warmup, 10 s measured). 5 runs per build per sample, interleaved, order swapped each round. Path check:ASAHI_MESA_DEBUG=perfshows geometry heap slots allocated ("Allocating geometry heap slot", 8 per run) on both builds for every sample, so these draws run through heap passes and their resets.All changes lie inside the run-to-run spread (base and head ranges overlap for every sample; per-build standard deviation 0.3-0.9%). The only new GPU work is one compare in the heap reset entry per heap pass, and one status word read in
hk_check_status(). Raw fps per run (round 1-5; base/head):