Repository navigation
borealis: serialize the application's M5 BLAS addresses - #1422
Conversation
There was a problem hiding this comment.
Verdict: HOLD at 9a11c158
Blockers:
- Pending G17P no-change hardware row listed under Not yet before merge (shared
src/asahi/libagx/copy.cltouched).
Checked:
src/asahi/libagx/copy.cl,src/asahi/vulkan/hk_agx3_as_format.h: verifiedHK_AGX3_M5_IMAGE_ALIGN(1024u) exposed cleanly under#ifndef __OPENCL_VERSION__,AGX3_AS_SLACK = HK_AGX3_M5_IMAGE_ALIGN - 1, andlibagx_agx3_as_relink()roundingsrc[AGX3_AS_SERIAL_WORDS + i]up to the 1 KiB image boundary once before storingrecord[11]and matchingtable[2 * id](preserving0 -> 0for null handles and exact identity for already 1 KiB-aligned addresses).src/asahi/vulkan/hk_m5_acceleration_structure.c: verifiedhk_as_native_va()consolidates all fourALIGN_POT(..., HK_AGX3_M5_IMAGE_ALIGN)sites with no behavioral drift.src/asahi/vulkan/tests/as_copy_alignment.{c,comp}: verified reproducer exercises 1 KiB + 768 BLAS relocation with swapped original triangles so stale ID vs unaligned pointer vs fixed relink are cleanly distinguished.- Exact-head J714s (M5 Pro, G17S) testing at
9a11c1582116:as_copy_alignmentpasses 3/3 (base fails 3/3), 1,013 CTS copy/serialization cases (128 pass, 0 fail, identical to base), 0 GPU faults, plus x86_64 C-kernel check and RADV reference pass.
Evidence
- Both
(0 + 1023) & ~1023ULL == 0(null handle preserved) and(addr + 1023) & ~1023ULLmatchhk_as_native_va()for 256-byte-aligned 48-bit GPU VAs without wrap risk. - Ready to approve once the G17P no-change row is posted.
There was a problem hiding this comment.
Verdict: HOLD at 0aab9c8e
Blockers:
- Pending
G17Pno-change hardware row at0aab9c8e(Not yet).
Checked:
- Audited all 13 files (
+1095/-69) across the 4 new commits (c39a931c..0aab9c8e):- API BLAS address preservation (
leaf.h,agx3_batch_build_leaf.comp,agx3_m5_legacy_leaf.comp,copy.cl):VK_BVH_AS_ADDRESSis gated under#ifdef VK_BVH_AS_ADDRESS(M5-only, keeping shared/GEN1 SPIR-V byte-identical);build_instance()reads BLAS bounds from the 1 KiB-aligned address while retaining the raw APIaccelerationStructureReferenceinbase_ptr.encode_instance()stores the aligned address for traversal and saves the API reference attransform + HK_AGX3_M5_INSTANCE_REFERENCE_OFFSET(+56).libagx_agx3_as_serializereads*agx3_as_instance_reference(record)back into the serialized header, andlibagx_agx3_as_relinkwrites the replacement API reference back while resolvingHK_AGX3_M5_IMAGE_ADDRESS(reference)(preserving0 -> 0) forrecord[11]and the object-table ID lookup. - Retained update IR/plan across copies (
hk_agx3_as_format.h,hk_agx3_as_layout.h,agx3_m5_legacy_envelope.comp,agx3_m5_legacy_refit.comp,hk_m5_acceleration_structure.c,copy.cl):hk_m5_retained_offset()andhk_m5_plan_offset()are anchored relative tohk_as_native_va()so copies/deserializations at any 1 KiB residue preserve retained offsets. Verifiedstorage_bytesword placement (HK_AGX3_M5_STORAGE_WORD_BYTES= 8B immediately afterhk_m5_image_bytes()/HK_AGX3_M5_EMPTY_IMAGE_BYTES, written byenvelope/empty-CP for non-updatable builds and byrefitSAVE_PLAN/REFITforALLOW_UPDATEincludingHK_AGX3_PLAN_EMPTY),agx3_as_storage_bytes()propagation into copy/serialize/property kernels, andhk_as_copy_threads()sizing (as->size - padding >= storage_bytes). - Tests (
as_copy_alignment.c,test-hk-agx3-as-format.c): comprehensive coverage of unaligned BLAS replacement/re-serialization and clone/compact/serialize+deserialize update-after-copy with pre/post guard checks; verified exact-head J714s (M5 Pro,G17S) results (6/6serialized addresses,3/3post-replace ray hits,9/9update-after-copy hits with intact guards,128/128CTS pass, 0 GPU faults).
- API BLAS address preservation (
Evidence
- Code is clean across all 13 files with zero defects found; ready to approve once the
G17Pno-change row at0aab9c8elands.
|
On the MacBook Neo (J700, A18 Pro G17P B1), Borealis head Three shards on each build reported a resource error and ended early. The same 380 cases on each build were run individually, including the 377 cases those shards had not reached. Every case then had a recorded result, with identical statuses across builds. The checked ray-query smoke passed, the BLAS layout fixture produced identical output, and the emitted shader binaries matched in both fixtures. The stock Fedora 44 kernel recorded zero GPU faults, kernel WARNs or SELinux AVCs. Stock userspace and the original boot were verified at handback. |
There was a problem hiding this comment.
Verdict: MERGE at 0aab9c8e
Blockers: none
Checked:
- Full 13-file diff (
+1095/-69),MERGEABLEagainstaurora-wip: API BLAS address preservation (leaf.h#ifdef VK_BVH_AS_ADDRESSM5-only,+56transform reference slot,copy.clagx3_as_instance_referenceserialize/relink round-trip) and image-relative retained update IR/plan preservation across clone/compact/serialize/deserialize (storage_bytesword inenvelope/refit/empty-CP includingHK_AGX3_PLAN_EMPTY,agx3_as_storage_bytes(),hk_as_copy_threads()). - Dual GPU-generation exact-head hardware proof at
0aab9c8e:- M5 Pro (J714s):
6/6API BLAS addresses,3/3post-replace hits,9/9update-after-copy hits and intact guards,128/128CTS pass, 0 GPU faults. - A18 Pro (J700, G17P B1): exact-head
0aab9c8e43dfmatchedaurora-wip138a5228631eacross all49,476individual CTS outcomes (35,056pass,14,420unsupported,0failures — all49,359ray_query.*+117RT pipeline +1,013-case AS copy/serialization subset with1,009pass /4unsupported), ray-query smoke passed, BLAS layout fixture and emitted shader binaries identical, 0 GPU faults / kernel WARNs / SELinux AVCs.
- M5 Pro (J714s):
Evidence
- The sole remaining blocker from the prior review at
0aab9c8e(G17P no-change regression row) is cleared by the J700 G17P B1 run posted on2026-11-30T20:16:41Z.
|
@DjDeveloperr, code-owner heads-up: App approval at |
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Merge train status: ported. The branch is now one commit, head Remaining gate: two hardware rows comparing base and this branch, queued in the merge train. J714s runs the serialized-address regression plus acceleration-structure copy and serialization CTS. J700 runs a no-change row on the same set. |
Serializing an M5 top-level structure wrote each instance's bottom-level image address into the header. The image starts at the structure's Vulkan address rounded up to 1 KiB, so for a BLAS at a 256-byte aligned address the handle did not match vkGetAccelerationStructureDeviceAddressKHR, and a TLAS that was deserialized and serialized again lost the address the application had given it. Keep the application's reference in the leaf IR and resolve it to the image only in the M5 encoder. Store the reference in the instance's transform entry next to the SBT word, report it when serializing, and write the application's handle back there when deserialization relinks an instance. Traversal and the object table keep using the image address. Drivers that do not define VK_BVH_AS_ADDRESS, G17P among them, keep the original leaf code. Share the address rounding and the record layout between the encoder, the copy kernels and a host test of the round trip. Signed-off-by: DjDeveloperr <hey@djdev.me>
18809b9 to
1515081
Compare
|
M5 Pro row at exact head Method: base
Not covered: the serialized BLAS address regression test itself (not in CTS), and the J700 no-change row. The Neo is currently down for an unrelated reason, so that row waits. |
|
J700 no-change row at exact head |
satchlj
left a comment
There was a problem hiding this comment.
Verdict: MERGE
Blockers: none.
Checked:
src/vulkan/runtime/bvh/leaf.h:#ifdef VK_BVH_AS_ADDRESSkeepsinstance.accelerationStructureReferenceinDEREF(node).base_ptrwhile resolvingblasviaVK_BVH_AS_ADDRESSfor bounds reads;#elsepreserves the exact original code path so G17P and other drivers emit byte-identical shaders.src/asahi/libagx/m5_as_metadata.h+src/asahi/vulkan/bvh/agx3_batch_build_leaf.comp+src/asahi/vulkan/bvh/agx3_m5_legacy_leaf.comp: centralizes the 1 KiB image alignment macro and instance/transform offsets; the M5 leaf encoder resolvesreference->blasfor bounds, BLAS ID (blas + 176ul), and word 11 while writing(sbt, 0u, ref.lo, ref.hi)in one 128-bit store at byte 48 of the 64-byte transform entry (reference at byte 56).src/asahi/libagx/copy.cl: validates the transform entry bounds inagx3_as_instance_record(), serializes from*libagx_m5_as_instance_reference(record), and updates both the reference slot and word 11 vialibagx_m5_as_relink_instance(). (Non-blocking hardening note: inagx3_as_instance_record(), checkinguint64_t rel = record[LIBAGX_M5_AS_INSTANCE_TRANSFORM_WORD];againstrel > bytes - (offset - 4)before adding tooffset - 4would prevent 64-bit wraparound on a malformed image, matching the overflow-safe check onoffsetabove.)src/asahi/vulkan/tests/test-hk-as-blas-reference.c: thorough host test withstatic_assertlayout checks, 0/256/768-byte residues, replacement/null/unchanged relink + second round-trip idempotency, and G17P relocation invariance.- Local full build + 248/248
asahi/vulkan/polytests + 0 new warnings + SPIR-V/libagx_shaders.cbinary-identity checks (while hosted Actions is disabled), plus exact-head151508173a51hardware A/B PASS rows on both K114s (M5 Pro, T6050) and J700 (G17P) covering 2,196 acceleration-structure CTS cases with 0 regressions and 0 GPU faults.
Evidence
- Audited full 7-file diff (
+338/-19) at151508173a51plus surrounding code insrc/asahi/libagx/copy.cl:515-565andsrc/asahi/vulkan/bvh/agx3_m5_legacy_leaf.comp:258-322. - Verified local host build/test receipts (248/248 PASS) and exact-head hardware A/B rows on K114s (
T6050, 586 Pass->Pass, 1,610 NotSupported->NotSupported, 0 Fail) and J700 (G17P, 2,196 Pass->Pass, 0 Fail).
|
Local CI on the merge tree (hosted Actions is off). Head
Hardware rows at this head, same-boot A/B against Merging at |
|
J714s (M5 Pro, G17S B1) exact-head row at Base is the PR's merge base with MacBook Pro (M5 Pro, G17S B1), stock
|
What: M5 TLAS serialization reports the BLAS address the application referenced, the value
vkGetAccelerationStructureDeviceAddressKHRreturned, instead of the 1 KiB-aligned image address. A TLAS that is deserialized with a replacement BLAS keeps that BLAS's address the next time it is serialized. This is the only part of this PR that #1482 did not land: #1482 already aligns replacement addresses during relinking and carries retained update data through copies.Tested: On x86_64 (pc), base
7fe256e03606and this branch were built with the same options. The branch added no compiler warnings.meson test --suite asahi --suite vulkan --suite polypassed 248 of 248 tests, including the newhk_as_blas_referencetest. That test fails if relinking drops the reference or skips the rounding. Only the four M5 leaf shaders and the M5 serialize and relink kernels changed. The shared runtime leaf shader, every GEN1 (G17P) build shader and every G17P libagx binary are byte-identical. Hardware, same-boot A/B against base7fe256e03606at this head on 2,196 acceleration-structure copy, serialization and update CTS cases, 0 status changes and 0 GPU faults: M5 Pro (T6050, the J714s SoC) (row) and J700 (G17P) (row).Risk: two-way. Affects M5 (J714s, G17S) native acceleration-structure builds and copies. The shared leaf IR code in
src/vulkan/runtime/bvh/leaf.halso builds Neo (J700, G17P) structures, and keeps its original code there.Not yet: nothing owed for merge. The
as_copy_alignmentreproducer itself has not run on an M5 at this head; the M5 lead's kit carries it.Details
The M5 image starts at the structure's Vulkan address rounded up to 1 KiB, and applications such as vkd3d-proton place structures at 256-byte aligned buffer addresses. Before this change, the shared leaf pass stored that rounded address in the instance IR. The encoder wrote it to word 11 of the instance record, and serialization copied word 11 into the header. The application's own address was lost.
src/vulkan/runtime/bvh/leaf.h: when a driver definesVK_BVH_AS_ADDRESS(only the M5 batched leaf pass does), the IR keepsaccelerationStructureReference, andVK_BVH_AS_ADDRESSis used only to read the BLAS bounds. Without it, the code is the original two lines, so G17P and every other driver compile the same shader.bvh/agx3_m5_legacy_leaf.comp: the encoder resolves the reference to the image for word 11 and the BLAS ID. It writes the SBT word, a zero word and the reference as one 16-byte store at byte 48 of the instance's 64-byte transform entry. Traversal reads only the matrix and the SBT word there.libagx/copy.cl: serialization reports the reference from the transform entry. Relinking writes the application's handle back to it and the rounded image address to word 11, as before. An instance record now also needs its transform entry inside the image.libagx/m5_as_metadata.h: the rounding, the record and transform-entry offsets, and two small helpers. The encoder, the kernels and the host test all use them.tests/test-hk-as-blas-reference.c(host): encodes three M5 instances with 0, 256 and 768-byte residues, then serializes them, deserializes them with an unaligned replacement, a null BLAS and an unchanged one, relinks them and serializes them again. It checks that only the two link words change, and that a second round trip leaves the TLAS unchanged. For G17P, it checks that the GEN1 relocation used by copies and deserialization leaves the records' application addresses untouched.The earlier head
18809b9230a1had six commits written before #1482. This branch is now one commit on currentaurora-wip. The alignment fix and the storage-size word from that history are gone; #1482's version is in the base.Evidence
7fe256e036068b23aaa4e9ce21132ceddd06908c(currentaurora-wip); head is this PR's single commit on it.-Dbuildtype=release -Db_ndebug=false -Dplatforms=x11,wayland -Dgallium-drivers=asahi -Dvulkan-drivers=asahi -Dglx=disabled -Degl=disabled -Dllvm=enabled -Dbuild-tests=true -Dtools=asahi -Dvideo-codecs=all_free, GCC 16 on x86_64.meson test --no-rebuild --suite asahi --suite vulkan --suite poly: Ok 248, Fail 0.hk_as_blas_referencefails whenlibagx_m5_as_relink_instance()drops the reference store, and when it skips the rounding.src/vulkan/runtime/bvh,src/asahi/vulkan/bvh): 43 of 47 headers are byte-identical, includingleaf.spv.h,leaf_morton_32.spv.hand everyhk_agx3_gen1_*andhk_agx3_refit*shader. The changed headers arehk_agx3_batch_build_leaf,hk_agx3_m5_legacy_leaf,hk_agx3_m5_legacy_leaf_pairsandhk_agx3_m5_legacy_leaf_batched.libagx_shaders.c: 684 precompiled arrays. The only changed arrays arelibagx_agx3_as_serializeandlibagx_agx3_as_relinkin theg13g/g13x/g17gtables. Theg17ptable has noagx3_askernels, and none of its entries changed.src/asahi/vulkan/tests/as_copy_alignment.{c,comp}from the earlier head18809b9230a1. It is a plain Vulkan program; build and run steps are in its header comment.