Skip to content

borealis: lose the device when a pass overflows its geometry heap - #1424

Merged
DjDeveloperr merged 3 commits into
aurora-silicon:aurora-wipfrom
jgoyvaerts:pr/borealis-heap-overflow
Dec 1, 2026
Merged

DjDeveloperr merged 3 commits into
aurora-silicon:aurora-wipfrom
jgoyvaerts:pr/borealis-heap-overflow

Conversation

@jgoyvaerts

@jgoyvaerts jgoyvaerts commented Nov 30, 2026 •

Copy link
Copy Markdown

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:

  • New GPU test hk-vulkan-heap-overflow: a 1024-point GS draw renders; a 32M-point draw loses the device and stderr shows MESA: error: geometry heap overflow: … needed more than its 128 MiB heap slot; device lost (base: silently drawn as nothing).
  • Test-only build with 256 KiB slots (never committed), heap-cases at -j 2: head 70 Crash (each a clean device loss), base 63 Fail (silently wrong) + 7 Crash (generic "GPU abort"); 0 GPU recoveries in both.
  • dq-fast heap-cases 0 differ vs base at this head.
  • meson --suite asahi 230/230.
  • dq-fast 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 in hk_check_status() (check order, the stderr line) and lacks the test.
  • Perf A/B on four geometry/tessellation samples (Sascha Willems Vulkan, headless 1080p, 5 interleaved runs each): -0.03% to +1.23% fps, all inside run-to-run spread (Evidence).
  • 0 GPU recoveries, 0 new kernel errors, 0 failed units.
    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
  • Every heap allocator (poly_heap_alloc_offs(), poly_heap_try_alloc_offs()) bumps bottom with an atomic add before it checks the allocation fits. So at the end of a pass, bottom > size exactly when one of its allocations failed, whichever path it took.
  • The reset that ends each heap pass is an entry in libagx_write_u32s's list. Its padding word becomes kind: LIBAGX_IMM_WRITE_HEAP_RESET checks bottom > size (size is the next word of poly_heap), sets the status word value bytes away, then zeroes bottom. 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.
  • The status word sits after the slot descriptors in the descriptor buffer (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" with mesa_loge() (vk_device_set_lost() logs only to debug messengers in release builds) and loses the device. HK_GEOMETRY_HEAP_SIZE_B names the slot size.
  • shortcut (in query.h): failed requests summing past 4 GiB in one pass wrap bottom and go unreported; the halting allocators still report through printf.
  • Recoverable overflow (growing or smaller slots) is not part of this change.
Evidence

Builds of aurora-wip 89ddabbf7 + this commit (GL + Vulkan), kernel 7.3.0-m4.212, shared gpu-runs:

check result
hk-vulkan-heap-overflow, head fitting draw 0, overflowing draw VK_ERROR_DEVICE_LOST: OK
hk-vulkan-heap-overflow, base (m4/next b54448cf7) overflowing draw VK_SUCCESS, nothing drawn: FAIL (the bug)
same, test build with 256 KiB slots 8M-point draw loses the device; 1024-point draw renders
heap-cases, 256 KiB slots, -j 2 head: 1181 P / 282 NS / 70 Crash (device lost); base: 1181 P / 282 NS / 63 Fail / 7 Crash; 0 recoveries
dq-fast heap-cases (1533) 1260 P / 273 NS, 0 differ vs aw-89ddabbf7
dq-fast api.info (10487) / memory.* (4745) 0 differ
GLES3 (392) / texture probe 392/392 / 3 of 3 ok
meson --suite asahi 230 Ok, 0 Fail

0 GPU recoveries, 0 new kernel err lines, 0 failed units.

Perf A/B (geometry/tessellation draws, normal 128 MiB slots). Base 89ddabbf7 vs head a08505efb, 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, commit 4415c09b08f3 (assets a27c0e58), built with -DUSE_HEADLESS=ON -DCMAKE_BUILD_TYPE=Release; each run VK_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=perf shows 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.

sample (fps, median of 5) base head change base range head range
geometryshader 4480.3 4506.4 +0.58% 4438.7-4527.5 4486.6-4516.7
tessellation 7654.1 7683.8 +0.39% 7583.6-7758.9 7604.8-7750.8
terraintessellation 826.1 836.3 +1.23% 824.2-831.9 826.4-837.7
displacement 1268.6 1268.1 -0.03% 1260.6-1269.4 1259.4-1269.0

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):

  • geometryshader: base 4480.3, 4515.2, 4527.5, 4438.7, 4450.1; head 4486.6, 4516.7, 4513.0, 4506.4, 4489.3
  • tessellation: base 7642.0, 7654.1, 7725.1, 7583.6, 7758.9; head 7611.1, 7703.7, 7604.8, 7683.8, 7750.8
  • terraintessellation: base 824.2, 831.9, 828.2, 826.1, 825.5; head 836.3, 837.7, 837.6, 828.2, 826.4
  • displacement: base 1260.6, 1268.9, 1268.1, 1269.4, 1268.6; head 1259.4, 1269.0, 1266.5, 1268.1, 1268.2

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>
@jgoyvaerts
jgoyvaerts force-pushed the pr/borealis-heap-overflow branch from 067b056 to a08505e Compare November 30, 2026 18:11
@jgoyvaerts
jgoyvaerts marked this pull request as ready for review November 30, 2026 21:03
@jgoyvaerts
jgoyvaerts requested review from a team and DjDeveloperr as code owners November 30, 2026 21:03

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: HOLD at a08505ef

Blockers:

  1. Missing second GPU-generation regression row (Not yet: other Macs). This change modifies shared src/asahi/libagx/query.cl, query.h, hk_device.c, hk_cmd_draw.c, and hk_query_pool.c across 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/-12 across 14 files), MERGEABLE against aurora-wip.
  • struct libagx_imm_write retains 16-byte layout (static_assert + i386 layout test) with kind == 0 preserving plain stores for all existing Vulkan/GL callers; LIBAGX_IMM_WRITE_HEAP_RESET checks address[0] > address[1] (static_assert verifies size immediately follows bottom in struct poly_heap), writes 1 to dev->rodata.heap_overflow_addr, and zeroes bottom.
  • hk_check_status() checks dev->rodata.heap_overflow first, flushes the GPU printf buffer, logs a clear message naming the 128 MiB geometry heap overflow, and loses the device via vk_device_set_lost().
  • Thorough J616s (M4 Pro, G17P) exact-head verification: hk-vulkan-heap-overflow, 256 KiB slot stress (70/70 clean device loss vs 63 silent wrong frames), dq-fast heap/api/memory parity, meson --suite asahi 230/230, GLES3 392/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>

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: HOLD at 05afa095

Blockers:

  • Exact-head build, unit tests, and hardware verification at 05afa095 missing: New commits e6ea44ac (asahi: latch geometry heap exhaustion until either reset path) and 05afa095 (asahi: retain the full tessellation index total at reservation) rewrite poly_heap_try_alloc_offs() to a POLY_HEAP_EXHAUSTED CAS latch, widen poly_prefix_sum() / GS / tessellation reservations to 64-bit, route libagx_write_u32s_ordered() through libagx_apply_imm_write(), and add pixel readback to hk_vulkan_heap_overflow.c. Please post fresh build + unit test (poly_heap_math_tests, --suite asahi --suite poly) and hardware hk-vulkan-heap-overflow / CTS results at 05afa095 (current evidence is from a08505efb).
  • Second GPU-generation regression row missing: Current hardware evidence covers J616s (M4 Pro, G17P) only. Because this touches shared libagx, poly, and Borealis heap-reset / geometry / tessellation paths across all generations, please add an exact-head 05afa095 row on a second GPU generation (e.g., M1/M2/M3/M4-base/M5).

Checked:

  • Audited commits e6ea44ac and 05afa095:
    • poly_heap_next_bottom() + poly_heap_try_alloc_offs() (src/poly/poly_heap_math.h, src/poly/geometry.h): clean atomic_compare_exchange_weak loop latching POLY_HEAP_EXHAUSTED (0xffffffffu) on any overflow or 64-bit size exceeding capacity, closing the previous 4 GiB atomic_fetch_add wraparound hole; covered by new assertions in poly_heap_math_tests.c.
    • libagx_apply_imm_write() (src/asahi/libagx/query.cl): shared by both libagx_write_u32s() and libagx_write_u32s_ordered(), atomically recording device loss when *address > address[1] || *address == POLY_HEAP_EXHAUSTED before resetting *address = 0.
    • poly_prefix_sum(), libagx_prefix_sum_tess(), libagx_tess_setup_indirect(), poly_gs_setup_indirect_inner(), poly_heap_alloc_points(), and poly_tess_*_process(): retain 64-bit totals before heap reservation, zero nr_patches / out_draws[0] on exhaustion so downstream stages never read unallocated heap memory, and preserve abort() for Gallium callers.
    • hk_vulkan_heap_overflow.c: cleanly adds RGBA8 white-pixel readback verification and fence wait.
Evidence
  • Head commit: 05afa095 on top of e6ea44ac and a08505ef (MERGEABLE into aurora-wip).
  • No automated CI checks attached to this branch; PR body evidence is still tagged at a08505efb on J616s only.

@tully-8888

Copy link
Copy Markdown

Hardware row on 14-inch MacBook Pro M5 Pro (apple,j714s / apple,t6050, GPU G17S B1, firmware 27.2, kernel 7.3.0-17.v272-27-ARCH), built natively from PR head 05afa09523b57e1b386b79f64fb31d6c10180503 (release Vulkan-only build, libvulkan_asahi.so sha256 5f71f0834dda..., MESA_SHADER_CACHE_DISABLE=1):

  • meson test -C build --suite asahi: 226/226 OK, 0 fail.
  • hk-vulkan-heap-overflow on live G17S B1: PASS (exit 0):
    • fitting draw (1024 points): 0
    • MESA: error: geometry heap overflow: a geometry, tessellation or index pass needed more than its 128 MiB heap slot; device lost
    • overflowing draw (33554432 points): -4 (VK_ERROR_DEVICE_LOST)
    • hk_vulkan_heap_overflow: OK
  • Kernel log across the run: 0 GPU faults / recoveries / resets, 0 failed systemd units.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: MERGE at 05afa095

Blockers: None.

Checked:

  • Exact-head 05afa095 second-generation hardware row on J714s (14-inch MacBook Pro M5 Pro, G17S B1, fw 27.2) clears both remaining holds:
    • meson test -C build --suite asahi: 226/226 OK (0 fail).
    • Live hk-vulkan-heap-overflow PASS (fitting draw (1024 points): 0 with white RGBA8 readback, overflowing draw (33554432 points): -4 VK_ERROR_DEVICE_LOST with geometry heap overflow message, hk_vulkan_heap_overflow: OK), 0 GPU faults/recoveries/resets, 0 failed 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 of e6ea44ac + 05afa095 (POLY_HEAP_EXHAUSTED CAS latch, libagx_write_u32s_ordered reset path, 64-bit tessellation/GS totals, and pixel readback test).
Evidence
  • Head commit: 05afa09523b57e1b386b79f64fb31d6c10180503 (MERGEABLE into aurora-wip).
  • Second-gen exact-head row comment (tully-8888, 2026-11-30T22:01:17Z).

@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr, code-owner heads-up: App approval at 05afa09523b5 from a different lane. This PR goes into the merge train's next combined A/B (aurora-wip 84ba0bee + #570 #1128 #1180 #1184 #1260 #1266 #1424 #1428 #1430 #1435) on M1 Pro G13S + M4 G16G. If that row is clean, I plan to land it via --admin under the 6-point rule no earlier than one hour from now, unless you post a hold.

@DjDeveloperr

Copy link
Copy Markdown

PASS on M4 mini J773g (G16G) at 05afa09523b5: the overflow ends in a clean device loss with its diagnostic, the next device draws correctly, and there are no CTS differences from the merge base 89ddabbf72c

Kernel: saved stock 7.3.0-ARCH-m4mainefed1ae3 (linux main efed1ae3), no boot changes, SLC on. GET_PARAMS: features 0x000001026001fc06, bit 48 and bit 49 clear. Both arms used the same kernel, case lists and options, each through its own ICD JSON and library path. Every process mapped the expected library, and each library carried the expected commit.

Driver unit tests (CPU only)

Test base head
poly-heap-math pass pass
asahi-i386-layout pass pass

hk-vulkan-heap-overflow on the GPU (the probe built from this head, run on each arm's driver)

Step base head
Fitting draw, 1024 points white pixel white pixel
Overflowing draw, 33,554,432 points not run VK_ERROR_DEVICE_LOST in under 1 s, with geometry heap overflow: a geometry, tessellation or index pass needed more than its 128 MiB heap slot; device lost
Fitting draw on a fresh logical device after the loss not run white pixel

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 geometry.*, tessellation.*, draw.renderpass.indexed_draw.*, pipeline.monolithic.input_assembly.primitive_restart.*, robustness.index_access.*, robustness.bind_index_buffer2.*, api.buffer_marker.* and api.smoke.*

Pass NotSupported Fail
base 1604 351 0
head 1604 351 0

GLES3 on the shared libagx paths (Gallium asahi, surfaceless): primitive_restart.*, draw.draw_elements.* and draw.draw_range_elements.*, 261 cases: 261 pass on both arms.

  • 0 per-case differences in both suites.
  • dEQP processes grow memory quickly on both arms alike: about 3.0 GB peak per 25-case process on both. This is shared behavior, not a finding against this PR.

Not covered on J773g

  • G17P, G17S and the M5 geometry and tessellation paths, which need the Neo J700 and G17S rows.
  • The ordered and parallel reset writers were checked only through the unit fixtures and the CTS above, not with a dedicated hardware probe.

CTS: deqp-vk sha256 d3ef839a…, glcts sha256 5e4323a8… (surfaceless).

@RyanTheTide
RyanTheTide disabled auto-merge November 30, 2026 23:53
@github-actions github-actions Bot added area:asahi-common Area from CODEOWNERS (bot) area:borealis Area from CODEOWNERS (bot) area:compiler Area from CODEOWNERS (bot) labels Dec 1, 2026
@github-actions github-actions Bot added blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Merge readiness at 05afa095: ready to merge

Check Detail
CI at head ok no CI for this change (the hardware row is the gate)
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok comment at 05afa095
Conflicts ok none
PR text ok Risk: two-way · all Macs Borealis runs on; libagx is shared with the GL driver, but GL never builds the new write kind

Areas: area:asahi-common, area:borealis, area:compiler
Merge: gh pr merge 1424 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 1, 2026
@DjDeveloperr
DjDeveloperr merged commit 69a6b8d into aurora-silicon:aurora-wip Dec 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:asahi-common Area from CODEOWNERS (bot) area:borealis Area from CODEOWNERS (bot) area:compiler Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants