Skip to content

borealis: report the M5 acceleration structure's buffer address - #1405

Merged
RyanTheTide merged 1 commit into
aurora-wipfrom
fix/borealis-m5-as-buffer-address
Nov 30, 2026
Merged

RyanTheTide merged 1 commit into
aurora-wipfrom
fix/borealis-m5-as-buffer-address

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 30, 2026 •

Copy link
Copy Markdown

What: Return the acceleration structure's buffer address from vkGetAccelerationStructureDeviceAddressKHR on M5, and round an address up to the 1 KiB image wherever the native image is read from one. The driver returned the buffer address rounded up to 1 KiB. vkd3d-proton places D3D12 structures at 256-byte aligned addresses and writes those addresses into TLAS instances, so the TLAS build read each BLAS header 256 to 768 bytes before its image. In GTA V Enhanced most BLAS sit at such addresses.

Tested: J714s (M5 Pro, G17S), stock 7.3.0-m5-pr67, built natively on the M5 from this head's tree: CTS 1.4.7.1 ray_query.acceleration_structures (traditional, GPU-built) plus ray_query.{misc,builtin,watertightness,advanced} (first 630), 11667 cases: 7249 pass, 0 fail, 4418 not supported. With nine BLAS at 256-byte aligned buffer addresses and TLAS instances holding those addresses (as vkd3d-proton writes them), rays hit 27922 of 27922 expected; on aurora-wip they hit nothing.

Risk: two-way · M5 family only (M5 native acceleration-structure format: G17G, G17S, G17C). The common leaf code gains a VK_BVH_AS_ADDRESS hook that is the identity unless a driver defines it.

Not yet: a base M5 (G17G) row.

Details
  • vkGetAccelerationStructureDeviceAddressKHR returns vk_acceleration_structure_get_va(), as every other driver does. For vkCreateAccelerationStructure2KHR the spec requires exactly that, and vkd3d-proton checks it (buffer_address = 0x5a57ace700, rtas_address = 0x5a57ace800 before this change).
  • The TLAS leaf build (agx3_batch_build_leaf.comp, through the new hook in leaf.h) rounds each instance reference up to the image before it reads the BLAS bounds and stores the instance's BLAS pointer, so the instance encoder and the traversal see the image address.
  • The software ray-query lowering rounds the structure address up as well. Descriptors already store the rounded address; an address converted from an integer (OpConvertUToAccelerationStructureKHR) is the device address.
  • Rounding is idempotent, so references that applications took from the old return value keep working.
Evidence

Instance-reference test (rqbatch, default software traversal, nine BLAS of 108 to 7151 triangles packed in one buffer at 1 KiB + 768, full rebuilds, 262144 rays per round, compared with references from vkGetAccelerationStructureDeviceAddressKHR):

Build Raw buffer addresses in instances
aurora-wip a532ab05e5bb 0 hits
this head 27922 hits, 0 mismatches

GTA V Enhanced (built-in benchmark, 2560x1440, Very High ray tracing, FSR) on a private M5 ray-tracing trial build (#337 rebased, not published): vkd3d-proton logged buffer_address != rtas_address 731 times, and 1113 of 1529 acceleration-structure builds were at 256, 512 or 768 bytes past a 1 KiB boundary. With only the refit scratch fix (#1404) the run lost the device after about 3 s of ray tracing (firmware compute fault). With both changes the benchmark completes: 21.19 FPS, 0 GPU faults, 0 s at the 338 MHz clamp.

vkGetAccelerationStructureDeviceAddressKHR returned the M5 image address,
the buffer address rounded up to 1 KiB. vkd3d-proton creates every D3D12
structure as a GENERIC view at a 256-byte aligned buffer address and uses
that address directly: TLAS instances name BLAS by it. It logs the
mismatch ("buffer_address = 0x5a57ace700, rtas_address = 0x5a57ace800"),
and the TLAS build then read each BLAS header 256 to 768 bytes before the
image. In GTA V Enhanced most structures sit at such addresses; the
traversal hit garbage instance records, which ended in a firmware compute
fault and a lost device within seconds.

Report the buffer address, like the other drivers do, and round an
address up to the image wherever one is read: instance references in the
TLAS leaf build (a VK_BVH_AS_ADDRESS hook in the common leaf code, the
identity for every other driver) and the structure a ray query starts
from. Descriptors already store the rounded address.

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: MERGE at e70c5c45

Blockers:

  • None.

Checked:

  • src/asahi/vulkan/hk_m5_acceleration_structure.c: hk_m5_backend_GetAccelerationStructureDeviceAddressKHR() now returns the raw buffer address vk_acceleration_structure_get_va(as) rather than rounding up to 1 KiB, matching spec expectations and vkd3d-proton D3D12 256-byte-aligned addresses.
  • src/vulkan/runtime/bvh/leaf.h + src/asahi/vulkan/bvh/agx3_batch_build_leaf.comp: introduces VK_BVH_AS_ADDRESS(reference) (identity default for other drivers, (((reference) + 1023ul) & ~1023ul) in agx3_batch_build_leaf.comp) and applies it consistently across base_ptr, BVH_BOUNDS_OFFSET, CALCULATE_FINE_INSTANCE_NODE_BOUNDS, and ROOT_FLAGS_OFFSET.
  • Verified all M5 leaf-build paths (both initial builds and hk_update_as() -> vk_cmd_build_as_leaves()) dispatch through device->as_build_ops->build_leaves (hk_build_leaves_batched() -> agx3_batch_build_leaf.comp) and disable fused_leaf_morton, and verified descriptor paths (write_accel_struct_desc and vkGetDescriptorEXT in hk_descriptor_set.c) already round to 1 KiB on dev->m5_native_as.
  • src/asahi/vulkan/hk_nir_lower_m5_ray_queries.c: lower_rq_initialize() rounds instr->src[1].ssa up to 1 KiB ((addr + 1023) & ~1023), which preserves 0 -> 0, is idempotent on already-aligned descriptor addresses, and handles raw addresses from OpConvertUToAccelerationStructureKHR.
  • Exact-head hardware verification on J714s (M5 Pro, G17S): CTS 1.4.7.1 ray_query 7,249 pass / 0 fail, rqbatch raw 256-byte-aligned BLAS addresses 0 -> 27,922 hits (0 mismatches), and GTA V Enhanced benchmark completes (21.19 FPS, 0 GPU faults).
Evidence
  • Cross-checked against live aurora-wip src/asahi/vulkan/hk_descriptor_set.c:92-107,1742-1748 and src/vulkan/runtime/vk_acceleration_structure.c:638-774.
  • MERGEABLE against aurora-wip (disjoint from #1404 in hk_m5_acceleration_structure.c).

@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr, code-owner heads-up: App approval at e70c5c458776 from a different lane. This PR goes into the merge train's next combined A/B (aurora-wip a532ab05 + #1404 #1405) 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.

@RyanTheTide

Copy link
Copy Markdown

Merge-train landing at e70c5c458776.

Revert: git revert -m 1 <merge commit> on aurora-wip. A regression gets reverted first and fixed after.

@RyanTheTide
RyanTheTide merged commit 89ddabb into aurora-wip Nov 30, 2026
@RyanTheTide
RyanTheTide deleted the fix/borealis-m5-as-buffer-address branch November 30, 2026 15:14
@DjDeveloperr

Copy link
Copy Markdown
Author

MacBook Neo (J700, A18 Pro, G17P B1), stock Fedora 44 kernel 7.3.0-41.fc44.aurora.aarch64. Base 28170a13a4b1 and head e70c5c458776 produced identical case statuses for all 59,638 selected Vulkan CTS cases (14,416 NotSupported, 45,222 Pass per arm). The selection covered the ray-query and ray-tracing-pipeline acceleration-structure cases plus the remaining ray-query groups. Every shard loaded its arm's checksum-verified Borealis ICD. An earlier four-worker run stopped at an allocation error in a baseline serialization case. This comparison ran the operations group serially.

The compute ray-query readback passed on both builds. A four-triangle GPU-built BLAS had identical storage and scratch sizes, a 64-byte header offset, a 696-byte native image length, the expected bounds and matching relative offsets. With AGX_MESA_DEBUG=binaries, all 26 distinct shader records for the trace and all 12 for the BLAS build matched.

Zero GPU faults, kernel WARNs or AVCs. The same stock boot, four SLC planes, both CPU policies and zero failed units were verified at handback.

@DjDeveloperr

Copy link
Copy Markdown
Author

Post-merge review of e70c5c458776 (merged as 89ddabbf72c2). One path still needs a follow-up.

Deserialize keeps the raw handle. libagx_agx3_as_relink() in src/asahi/libagx/copy.cl:593-601 copies the BLAS handle the application left in the serialized header straight into the instance record (record[11] = blas, the pointer m5_enter_instance() follows at byte 88). It then looks up the BLAS ID by exact match against the object table, which holds rounded addresses (src/asahi/vulkan/hk_m5_acceleration_structure.c:326). Applications fill those handles from vkGetAccelerationStructureDeviceAddressKHR, which now returns the raw buffer address. When a replacement BLAS sits 256, 512 or 768 bytes past a 1 KiB boundary, the deserialized TLAS enters it before its image, the same early read this PR fixes for builds. The instance also keeps the stale BLAS ID from the serialized image. CTS gives each structure its own allocation, so it can't see this.

Rounding once, before both uses, fixes it (zero stays zero):

uint64_t blas = src[AGX3_AS_SERIAL_WORDS + i];
blas = (blas + 1023ul) & ~1023ul;

Row for the fix: serialize a TLAS, patch its handles with vkGetAccelerationStructureDeviceAddressKHR of BLAS placed at 1 KiB + 768, deserialize, then trace.

Everything else checks out:

  • The common leaf.h hook is a no-op for every other driver, because no other driver defines VK_BVH_AS_ADDRESS. That covers radv's own leaf.comp, plus the common leaf.comp and leaf_morton.comp that anv, turnip and lavapipe use. In their SPIR-V the only change is that build_instance() reads accelerationStructureReference from its local instance copy once instead of three times. Nothing writes that copy in between, so the value is the same.
  • On M5, every path that reads an image from an address now rounds it: the TLAS leaf build (updates too, through vk_cmd_build_as_leaves() into the batched leaf shader), ray-query initialize, both descriptor writes, and build, copy and serialize via hk_as_native_va(). as_bytes already reserves the 1023-byte slack.

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.

2 participants