Repository navigation
borealis: address sparse images of 4 GiB or more in 64 bits - #1528
Conversation
Three 32-bit computations break sparse images of 4 GiB or more: - hk_image_plane_alloc_vma() sizes the image's address range with align(), which takes and returns uint32_t. An image of exactly 4 GiB gets a range of 0, which VM_BIND refuses (vkCreateImage fails); a larger one gets its size modulo 4 GiB, and its sparse binds past that map over whatever was allocated next: other images, buffers or the driver's own objects. The same applies to imageMipTailSize. - ail_get_layer_offset_B() and ail_get_layer_level_B() return uint32_t, so a clear or copy of a layer that starts at 4 GiB or more addresses a layer near the start of the image instead. - ail_bytes_to_pages() takes unsigned, so hk_sparse_image_map_commit() records the residency of a tile past 4 GiB at a tile near the start of the image: the bound tile reads as not resident, and the other tile's entry is overwritten. Mario Kart World creates an 8192x8192 array image of 68 layers that needs 5803 MiB: 1707 MiB of it were reserved, the game's binds into the rest overwrote other objects, and the GPU faulted (reads through a null base) or hung a few seconds after start-up, at varying places, with purple and stale blocks on screen until then. With these fixes it runs. Use align64() for the range and the mip tail size, and 64 bits for the layer offsets and the byte-to-page conversion. Add hk-vulkan-sparse-image-4gib, which creates a 4 GiB sparse image and reads back a tile bound past 4 GiB in a 5 GiB one. Signed-off-by: Jos Dehaes <jos.dehaes@gmail.com>
satchlj
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 4464bb5cbd5fc49edd7f83400116a61921de87a3
Blockers: none
Exact-head M5 Max (J775c, G17C B1) hardware verification + full sparse Vulkan CTS sweep at 4464bb5cbd5fc49edd7f83400116a61921de87a3 vs merge-base 689b2fe3dbfbae73beee6243ebcdca5655da7bfd: PASS, 0 regressions, 0 GPU faults.
- Environment: Apple M5 Max (
J775c,G17C B1), stocklinux@main5a870d0f0b3f(7.3.0-1-50.20261202-ARCH, bootaa051bcd-760d-499b-8add-5a5ba194f043), default kernel command line. Both ICDs built natively (--prefix /usr -Dbuildtype=release -Db_ndebug=false) and selected viaVK_ICD_FILENAMES(vulkaninfoconfirmedgit-689b2fe3dbvsgit-4464bb5cbd). - Unit tests (on-device
arm64, PR head):meson test --suite asahi --suite vulkan --suite poly— 243/243 OK, 0 Fail. hk-vulkan-sparse-image-4gib(same-boot base vs PR):- Base
689b2fe3dbfb: FAIL (rc=1,DRM_IOCTL_ASAHI_VM_BIND failed: Invalid argument ... range=0,vkCreateImage: -13). - PR
4464bb5cbd5f: PASS (rc=0,sparse images of 4 GiB and more: ok).
- Base
- Full Vulkan sparse CTS (
dEQP-VK.sparse_resources.*, 19,402 cases, cold shader cacheMESA_SHADER_CACHE_DISABLE=true, same-boot base vs PR):- Base
689b2fe3dbfb: 10,973 Pass, 0 Fail, 8,429 NotSupported (total=19,402). - PR
4464bb5cbd5f: 10,973 Pass, 0 Fail, 8,429 NotSupported (total=19,402). - Case-by-case QPA diff: 0 status changes (
DIFF count: 0).
- Base
- GPU faults (
dmesg):0before,0after.
Checked:
src/asahi/layout/layout.h:ail_get_layer_offset_B(),ail_get_layer_level_B(), andail_bytes_to_pages()widened cleanly touint64_t(layer_stride_B,level_offsets_B[], andsize_Bare alreadyuint64_t).src/asahi/vulkan/hk_image.c:hk_image_plane_alloc_vma()andhk_fill_sparse_image_memory_reqs()usealign64()and 64-bitmip_tail_stride * depth_px; host-image-copy layer/level offsets widened touint64_t.- Verified downstream callers in
hk_queue.c(hk_sparse_image_map_commit()already storesail_bytes_to_pages()outputs inuint64_t) andhk_sparse.h(hk_sparse_image_tile_offset_B()multipliesz * layout->layer_stride_Binuint64_t). - Non-blocking note:
ail_get_linear_pixel_B(),ail_get_twiddled_block_B(), andail_get_tiled_element_B()still returnuint32_t— harmless forhk_sparse_image_tile_offset_B(..., z=0)unless a single 2D layer itself exceeds 4 GiB, so fine to leave out of scope here.
satchlj
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge
Blockers:
- No CI build/test receipt recorded at
4464bb5cbd5fyet (statusCheckRollupis empty while hosted Actions is disabled, and no local/forkmeson testbuild pass is posted on the PR). Ready to flip toAPPROVEonce a CI or local/fork build+test receipt is posted.
Checked:
src/asahi/vulkan/hk_image.c:hk_image_plane_alloc_vma()now usesalign64(plane->layout.size_B, HK_SPARSE_ALIGN_B)(preventing 32-bit VA wrap at >= 4 GiB);hk_fill_sparse_image_memory_reqs()widens bothimageMipTailSizecalculations (align64(layout->size_B, ...)andalign64((uint64_t)layout->mip_tail_stride * layout->depth_px, ...)).src/asahi/layout/layout.h:ail_get_layer_offset_B()(z_px * layout->layer_stride_B, wherelayer_stride_Bisuint64_t) andail_get_layer_level_B()now returnuint64_t;ail_bytes_to_pages()now takes and returnsuint64_t. All four host-image-copy offset locals inhk_image.care widened touint64_t.src/asahi/vulkan/tests/hk_vulkan_sparse_image_4gib.c: clean regression test covering exact 4 GiB sparse image creation and 5 GiB last-layer tile bind, clear, and readback, wired intosrc/asahi/vulkan/meson.build.- Non-blocking note:
hk_copy_memory_to_image()andhk_copy_image_to_memory()still holdlayout->layer_stride_Binuint32_t dst_layer_stride/src_layer_stride; safe for any layer under 4 GiB, though widening those locals touint64_tin a follow-up would keep the host-copy path uniformly 64-bit. - Exact-head
4464bb5cbd5hardware PASS rows on J614c (M4 Max) and J493 (M2):hk-vulkan-sparse-image-4gib,bigbindup to 200,000 blocks (13 GiB), and full races in MKW Recomp and Lichii with 0 GPU faults;MERGEABLE, zero conflicts.
Evidence
- Audited full 4-file diff (
+349/-11) at4464bb5cbd5fand checkedstruct ail_layoutfield types (layer_stride_B,size_Buint64_t;mip_tail_strideuint32_t) and host-image-copy loops inhk_image.c:2452-2675. - Verified
statusCheckRollupis empty at4464bb5cbd5fand PR body/comments contain exact-head J614c and J493 hardware rows but no full Mesa build/unit-test CI run yet.
|
Local CI on the merge tree (this is the build and test receipt the review asked for; hosted Actions is off). Head
The layout tests pass (
|
What: Sparse images of 4 GiB or more were addressed with 32-bit sizes and offsets in three places: their address range, the offsets of their layers, and the byte-to-page conversion that records residency. Exactly 4 GiB fails to create. A larger image reserves only its size modulo 4 GiB, so its binds past that map over other objects, and tiles past 4 GiB read as not resident. This makes all three 64-bit and adds
hk-vulkan-sparse-image-4gib. Mario Kart World creates a 5803 MiB sparse image; with this it runs on the M4 Max, in both Mario Kart World Recomp and Lichii.Tested: J614c (M4 Max) and J493 (M2) at
4464bb5cbd5:hk-vulkan-sparse-image-4gibpasses on both (fails on7fe256e0360on the M4 and on the repo's36623c0a4a5on the M2); MKW Recomp 0.1.21 finishes a race on both, and Lichii on the M4, with no GPU fault; before, Recomp lost the device during start-up on the M4, and on the M2 it ran into GPU faults.Risk: two-way door · all Macs (shared layout helpers and sparse images; G13 to M5 use the same code)
Not yet: M1, M3, M5; a CTS sparse run.
Details
hk_image_plane_alloc_vma()sized a sparse image's VA reservation withalign(plane->layout.size_B, HK_SPARSE_ALIGN_B).align()takes and returnsuint32_t(util/u_math.h). An image of exactly 4 GiB got a range of 0:VM_BINDrefuses it (range=0,EINVAL) andvkCreateImagefails. A 5 GiB image got 1 GiB. Its sparse binds still cover the whole image, so those past the reservation map over whatever the allocator placed there next: other images, buffers, or the driver's own objects.imageMipTailSizehad the samealign(), and itsmip_tail_stride * depth_pxproduct is 32-bit too. Both now usealign64().ail_get_layer_offset_B()andail_get_layer_level_B()computedz_px * layer_stride_Bin 64 bits and returned it asuint32_t. Nearly every caller adds the result to a 64-bit base, so a clear or copy of a layer that starts at 4 GiB or more addressed a layer near the start of the image instead. Both now returnuint64_t. The four host-image-copy locals inhk_image.cthat held the result inuint32_tareuint64_tnow too.ail_bytes_to_pages()tookunsigned.hk_sparse_image_map_commit()passes the tile's 64-bit resource offset, so the residency of a tile past 4 GiB was recorded at a tile near the start of the image. The bound tile then read as not resident (zeros), and the other tile's entry was overwritten. It now takes and returnsuint64_t.The test needs all three fixes. With only (1) and (2), or only (1) and (3), the tile past 4 GiB still reads back wrong (table below).
Mario Kart World's array image is 8192x8192 with 68 layers (format 143) and needs 5803 MiB, of which 1707 MiB were reserved. The binds into the rest overwrote other objects, which is what the earlier reports of this game on M4 showed: shader reads through a null base (UL1C
0x10100),dVDMreads at0x3f000001c0, render and compute hangs, and purple or stale blocks on screen. The crash point moved with whatever was allocated past the reservation. Turning off compression (ASAHI_MESA_DEBUG=nocompress) or soft faults only moved it.Evidence
Hardware: J614c (MacBook Pro 14", M4 Max, G16C B1), kernel
7.3.0-1-43.6-ARCH: aurora linux mainb98bf00b32+ aurora-silicon/linux#2170 + aurora-silicon/linux#3200 + the VM_BIND kvmalloc fix (aurora-silicon/linux#3920). That fix matters only for single batches of more than about 210,000 bind operations:bigbindat 100,000 blocks and more needs it,hk-vulkan-sparse-image-4gibdoes not.Builds: baseline
w1202=7fe256e0360; the fix applied to689b2fe3dbf=4464bb5cbd5, driver code identical (built as packagew1202i). Intermediate builds show which fix the test needs:align64hk-vulkan-sparse-image-4gibvkCreateImage-13 (VM_BINDrange=0)The same test on RADV (RX 6800, Mesa 26.3): ok. With a wrong expected value (negative check): FAIL, as it should.
J493 (MacBook Pro 13", M2, G14G B0), kernel
linux-aurora 7.3.0.aurora1-46from the repo: with the installed Borealis36623c0a4a5,hk-vulkan-sparse-image-4gibfails (vkCreateImage-13); with this PR's driver (loaded throughVK_DRIVER_FILES) it passes.bigbindat 20,000, 48,000, 100,000 and 200,000 blocks completes with this PR's driver, with no kernel message. With this PR's driver installed, MKW Recomp 0.1.21 gets through the intro and attract and finishes a full race with no GPU fault.Tile past 4 GiB, by image size (layers of 16384x16384 RGBA8 = 1 GiB each), this PR: tiles in layers 1, 3, 4, 5 and 7 of 2- to 8-layer images all read back correctly. On the baseline with only (1), layers 1 and 3 are correct and layers 4, 5 and 7 are wrong.
bigbind(onevkQueueBindSparsealiasing N 64 KiB blocks of a 16384x16384 RGBA8 array to one 64 KiB allocation; source in aurora-silicon/linux#3920):vkCreateImage-13vkQueueWaitIdle-4Mario Kart World, all with
mesh_computeand per-draw breadcrumbs:w1202)nx2with #2669)Still seen with this PR, not caused by it: occasional flashing in Lichii, and a black instead of blurred background in its character and kart selection.
Commands: