Skip to content

borealis: add 128-bit identical-layout compute image copy for AGX3/M5 - #1172

Merged
RyanTheTide merged 1 commit into
aurora-silicon:aurora-wipfrom
oreater:pr/borealis-128bit-identical-image-copy
Nov 27, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:aurora-wipfrom
oreater:pr/borealis-128bit-identical-image-copy

Conversation

@oreater

@oreater oreater commented Nov 26, 2026 •

Copy link
Copy Markdown

What: Add hk_agx3_copy_identical_image() at the front of hk_xfer_copyimage2() on native AGX3 and M5 (agx_chip_native_or_m5()) to copy whole planes, whole single-mip layers, or full multi-mip chains of GPU-tiled images with byte-identical AIL layouts directly via 128-bit compute copies (dispatching >= 1 MiB full-plane spans directly via vk_meta_copy_buffer_addresses() and batching smaller spans via hk_copy_batch), while keeping compressed storage (checking both vk.usage and vk.stencil_usage) and compressed MSAA images on the existing Texture+PBE/meta paths.

Tested: J716c Apple M5 Max at 3af09b4: 334/334 asahi+poly debug CI tests pass; steady-state 200-iter 3-round ABBA vs 0b8e9b836cc wins -25.3% (1.34x) on 2K compressed RGBA8 copy (9.073 -> 6.781 ms), -9.6% on 2K D32S8 copy (2.636 -> 2.382 ms), and confirms +0.36% (7.766 -> 7.795 ms, identical VDM render passes) on standalone compressed 4x MSAA fallback; Vulkan CTS copy_and_blit.core.{image_to_image.all_formats,resolve_image}.* + synchronization2 A/B 163/220 pass (0 fail, 0 status diffs).

Risk: two-way door · native AGX3 (M3/M4/A18 Pro) and M5 (agx_chip_native_or_m5()) — a plain revert restores the prior hk_g17p_copy_raw_image() / graphics meta copy path; partial VA overlaps, sparse images, compressed STORAGE_BIT images (including stencil_usage), and compressed MSAA images fall back to the existing paths.

Not yet: Upstream fork CI approval on aurora-silicon/mesa (passed on fork); native-AGX3 (G17P/J700 or G16/J773g) hardware verification row (copy_and_blit.core.image_to_image.all_formats.* + resolve_image.* + compressed whole-image copy readback) is still owed before merge.

Benchmarks, fallback audit, and CTS details

Live M5 Max 3-round ABBA vs 0b8e9b836cc (MESA_SHADER_CACHE_DISABLE=1, bit-exact readback)

Workload Base median Head median Delta
200× 2K non-uniform compressed RGBA8 2D copy 9.073 ms 6.781 ms -25.26% (1.34x)
2K D32S8 depth+stencil 2D copy (pr11_copy_resolve_bench) 2.636 ms 2.382 ms -9.6%
100× 2K compressed 4x MSAA RGBA8 copy (standalone fallback check) 7.766 ms 7.795 ms +0.36% (identical VDM passes)
  • Fallback MSAA4 audit: Verified via HK_FRAME_ANATOMY that compressed 4x MSAA copies execute identical VDM render passes (fs=1da39fbc, vs=e0c59f0e) on both base and head; the earlier +7.4% delta in the combined benchmark was caused by running the VDM MSAA test immediately after the RGBA8+D32S8 copies (which ran as VDM passes on base vs CDM dispatches on head, changing VDM clock warm-up). Standalone warmed ABBA confirms +0.36% (A=[7.48..7.88] vs B=[7.64..8.00]).
  • Large-span dispatch refinement: Flushing >= 1 MiB spans directly via vk_meta_copy_buffer_addresses() avoids hk_copy_batch over-launching max_groups * count threads across mismatched D32 (16 MiB) + S8 (4 MiB) planes.
  • Vulkan CTS (deqp-vk, MESA_SHADER_CACHE_DISABLE=1): 163/220 PASS, 0 FAIL, 57 NotSupported (0 status diffs vs base) across copy_and_blit.core.image_to_image.all_formats.{depth_stencil,color}.*, resolve_image.*, and synchronization2.op.single_queue.*write_image_{fragment,tess_eval}_read_copy_image.*.

@oreater
oreater requested review from a team and DjDeveloperr as code owners November 26, 2026 23:35

@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.

Verdict at 7d0376762737: no code blockers found, but this isn't ready to merge. It has no CI run, and no hardware rows on the other chips the new path runs on (see below).

Checked

  • Eligibility
    • Identical format, type, samples, mips, layers, planes and extent are required.
    • Sparse images are refused, and the transfer layouts are checked.
    • hk_ail_layouts_identical_gpu() requires GPU tiling and the same compression, format, dimensions, samples, levels, size_B, layer stride, metadata offset and compression layer stride, plus the same per-level offsets, strides and tile sizes.
    • The fields it doesn't compare are either set per device (policy), set per image type (mipmapped_z, and the type is already checked equal), or covered by the whole-plane copy (level_offsets_compressed_B).
  • Regions
    • Single-mip copies need zero offsets and whole-level extents, and matching aspect and plane on both sides.
    • Partial-layer spans are 2D only. They copy layers × layer_stride_B of body, plus layers × compression_layer_stride_B of metadata at metadata_offset_B when the image is compressed.
    • Multi-mip copies need every level of a plane, all layers and zero base layers, then copy the whole plane.
    • Anything else returns false and uses the existing path.
    • The overlap check rejects any partial source/destination overlap and skips only exact self-copies.
  • Compressed raw copy
    • It is self-contained: libagx_fast_clear's solid mode keeps its colour in the tile body (compression.cl), so copying body plus metadata between identical layouts carries every tile state.
    • Compressed storage images are excluded, because their imageStore writes go through the PBE. Compressed MSAA images are excluded too.
    • The compute copy goes through hk_copy_batch, records compute_attachments for both planes and is wrapped in hk_meta_begin/end(COMPUTE). That is the same synchronization contract as the existing raw tiled copier.

Before merge

  1. CI hasn't run at this head. There are 0 checks. The repo's asahi workflow is active, so the runs from the fork branch may need a maintainer's approval.
  2. Hardware rows on native AGX3.
    • agx_chip_native_or_m5() covers the native AGX3 parts (G15/M3, G16/M4, G17P/Neo) as well as the M5 parts. The new path runs ahead of hk_g17p_copy_raw_image() and the graphics meta copy on all of them, compressed or not.
    • The only row is on J716c (M5 Max).
    • Please add at least one native-AGX3 row at this head, for example a J700 (G17P) or a J773g (G16). It should run the same copy_and_blit.core.image_to_image.all_formats.* and resolve_image.* CTS set plus a whole-image compressed copy readback.
  3. The compressed 4x MSAA copy got 7.4% slower in your own table (2.387 to 2.563 ms), on the path this PR says it leaves to fallback. The new checks can't cost 0.17 ms, so this is probably noise, but please re-measure it or explain it. The Mesa train merges with no regressions.

Not blocking

  • Doc comment wording: the comment above hk_agx3_copy_identical_image() lists "MSAA images" among what it copies, but compressed MSAA is excluded. Saying "uncompressed MSAA" would match the code.
  • Stencil storage usage: disallow_compressed checks vk.usage only. A stencil plane takes its compression from stencil_usage, so OR-ing stencil_usage in for the stencil plane would close that edge.
  • Commit: it is signed off, with no attribution.

Add hk_agx3_copy_identical_image() at the front of hk_xfer_copyimage2()
on native AGX3 and M5 (agx_chip_native_or_m5()): when source and
destination are non-sparse GPU-tiled images with identical format and
byte-identical AIL layouts (including single-sample compressed colour
attachments, D32S8/D32F/D16 depth+stencil, and uncompressed MSAA images)
and the copy covers whole planes, whole single-mip layers, or full
multi-mip chains without partial VA overlap, copy the tiled body and
compression metadata directly via batched 128-bit uvec4 compute copies
(hk_copy_batch), avoiding decompress+recompress and multi-pass graphics
render passes.

Keep compressed storage images (VK_IMAGE_USAGE_STORAGE_BIT) on the
Texture+PBE path for graphics PBE coherency, and keep compressed MSAA
images on the compressed meta path where hardware compression avoids
copying the full uncompressed sample backing buffer.

Signed-off-by: oreater <145754695+oreater@users.noreply.github.com>
@oreater
oreater force-pushed the pr/borealis-128bit-identical-image-copy branch from 7d03767 to 3af09b4 Compare November 27, 2026 02:27
@oreater

oreater commented Nov 27, 2026

Copy link
Copy Markdown
Author

Thanks for the detailed review! Updated at 3af09b42eaf:

  1. stencil_usage + doc comment: OR'd src->vk.stencil_usage | dst->vk.stencil_usage into disallow_compressed and clarified the comment to say "uncompressed MSAA images".
  2. Compressed 4x MSAA +7.4% investigation: Confirmed via HK_FRAME_ANATOMY that compressed 4x MSAA takes the exact same VDM render passes (fs=1da39fbc, vs=e0c59f0e) on base and head; the earlier delta was VDM warm-up crosstalk from running right after the RGBA8/D32S8 copies (which switched from VDM to CDM). Re-measuring 100× 2K compressed 4x MSAA standalone in 3-round ABBA gives 7.766 -> 7.795 ms (+0.36%, overlapping A=[7.48..7.88] vs B=[7.64..8.00]). Also switched >= 1 MiB spans to flush directly via vk_meta_copy_buffer_addresses() so mismatched D32+S8 planes don't over-launch max_groups * 2 threads in hk_copy_batch.
  3. Owed items: Listed the owed native-AGX3 (G17P/G16) hardware row and upstream CI run in **Not yet:** (I only have J716c M5 Max hardware locally).

@RyanTheTide RyanTheTide 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 3af09b42eafb

Blockers: none

Checked: Read the whole of hk_agx3_copy_identical_image(). Eligibility needs identical AIL layouts (tiling, compression, per-level offsets/strides/tiles, metadata offset and compression layer stride), whole planes, whole layers or the full mip chain, no sparse, transfer layouts checked; compressed storage images (usage and stencil_usage) and compressed MSAA fall back. Partial VA overlap between spans is refused. The compute attachments are added for both images. Selected by agx_chip_native_or_m5(). Gate green. Native-AGX3 row owed as you list; we will run copy_and_blit image_to_image and resolve_image on J700 (G17P) and J713 (G16G).

Evidence

Local Mesa gate (stands in for CI; buildbox x86 docker aurora/hk6356-mesa-x86-tests:local, clang release with asserts, -Dbuild-tests=true -Dtools=asahi,drm-shim, meson test --suite asahi --suite poly):

@RyanTheTide

Copy link
Copy Markdown

3af09b42eafb Neo (J700, Apple A18 Pro / G17P B1, 7.3.0-aurora-fleet89, default cmdline) PASS: Borealis overlay ICD (-Dbuildtype=release -Db_ndebug=false, sha256: d2c5b4189faf..., combined disjoint overlay on aurora-wip@e1b5658fe695 with this PR's touched files verified 0-byte diff vs merge(aurora-wip, head)), meson test --suite asahi 214/214 PASS; live VK CTS (J=1, MemoryMax=3G): dEQP-VK.api.copy_and_blit.core.image_to_image.* (--deqp-fraction=1,100) 344/536 PASS / 0 FAIL (192 NotSupported), dEQP-VK.api.copy_and_blit.core.resolve_image.* 80/240 PASS / 0 FAIL (160 NotSupported); 0 GPU faults/recoveries, 0 failed units, SELinux Enforcing, 0 new AVC denials, stock /usr/lib64/libvulkan_asahi.so untouched.

@RyanTheTide

Copy link
Copy Markdown

3af09b4 J713 M4 Air (G16G B0, 7.3.0-aurora-fleet85) PASS: api.copy_and_blit.core.image_to_image.* 33,663 pass / 19,029 not supported / 0 fail, api.copy_and_blit.core.resolve_image.* 76 / 164 / 0 (52,932 cases, every listed case ran), 0 GPU faults, Enforcing, 0 failed, 0 AVC; system Mesa untouched

Details
  • Build: exact head 3af09b4 (git archive of the PR head, no merge), release with assertions on (-Dbuildtype=release -Db_ndebug=false -Dvulkan-drivers=asahi), built natively on aarch64 Fedora 45 in a container. vulkaninfo with the overlay: Apple M4 (G16G B0), Mesa 26.3.0-devel (git-3af09b42ea), Borealis.
  • Loaded through VK_DRIVER_FILES only. /usr/lib64/libvulkan_asahi.so sha256 9b40d2912963... before and after. Shader cache off.
  • CTS: deqp-vk 1.4.7.1 (3fd4ea318fe2), both globs in full, 4 parallel processes, no crashes.
  • Kernel log over the run: 0 GPU faults, recoveries, timeouts or rejected submits. 0 AVC, 0 failed units, Enforcing.

DanteCpp pushed a commit to DanteCpp/mesa that referenced this pull request Dec 1, 2026
… it"

Restore full shader binary uploads. Commit f5089f1
(Mesa PR aurora-silicon#1127) introduced a deterministic memory mismatch on J773g (M4
mini, G16G) in the Vulkan CTS case:

dEQP-VK.synchronization.op.multi_queue.timeline_semaphore.write_image_compute_indirect_read_copy_image_to_buffer.image_128x128_r8_unorm_concurrent

With PR aurora-silicon#1172 active, the regression also produced VK_ERROR_DEVICE_LOST
and a GPU firmware recovery. Reverting aurora-silicon#1127 alone cleared both failures
in five shard runs while retaining aurora-silicon#1172's identical-layout image copy.

Signed-off-by: DjDeveloperr <hey@djdev.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants