Skip to content

borealis: exact buffer-alias and VA-range tracking for ALIAS_BIT render sync and packing - #1220

Merged
DjDeveloperr merged 1 commit into
aurora-wipfrom
djdev/borealis-m5-alias-exact-sync
Nov 27, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-wipfrom
djdev/borealis-m5-alias-exact-sync

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 27, 2026 •

Copy link
Copy Markdown

Summary

Replaces blanket VK_IMAGE_CREATE_ALIAS_BIT worst-case render synchronization and pass-merge/render-pack refusal with exact per-memory buffer-aliasing and GPU VA-range tracking:

  1. Per-hk_device_memory buffer/image binding tracking with submit-time resolution (has_image_binding, has_buffer_binding, buffer_alias_mem_gen):
    • Tracks atomically on each hk_device_memory whether any image and/or any buffer has been bound to it, plus a monotonic device-wide counter hk_device::buffer_alias_mem_gen incremented whenever a buffer is bound to an image-bearing memory (or an image to a buffer-bearing memory).
    • ALIAS_BIT images on image-only memory heaps (the standard D3D12-on-Vulkan / vkd3d-proton placed render-target heap layout) no longer conservatively force HK_SYNC_GFX_MEM on every render pass, restoring vertex/tiling (ta=S) pipelining across passes.
    • At submit time (hk_sync_resolve_submit_ex()), if buffer_alias_mem_gen changed after command buffer recording (a buffer was bound to an image-bearing memory post-record), Borealis conservatively upgrades affected streams (alias_image_render) back to HK_SYNC_GFX_MEM and widens intra-CB barrier_ta/prior_ta, preserving 100% soundness against late buffer aliasing.
  2. Exact GPU VA-range overlap proof for non-sparse ALIAS_BIT layout transitions:
    • Records each non-sparse ALIAS_BIT image's bound GPU VA range (hk_image_va_range) and allows content-preserving (oldLayout != UNDEFINED), non-ownership-transfer layout transitions of ALIAS_BIT images to stay transparent in pass merging (hk_m5_pass_merge_classify()) and cross-CB render packing (hk_render_pack_classify() / hk_render_pack_begin()) when their VA range does not overlap any attachment of the pass.
    • Eliminates spurious render-pass splits caused by vkd3d-proton render-target layout decay (GENERAL <-> COLOR_ATTACHMENT_OPTIMAL) on disjoint ALIAS_BIT images sharing one device heap.

Soundness & Invariants

  • Late buffer-binding soundness: Any VkBuffer bound to a VkDeviceMemory that already has (or later receives) a VkImage increments hk_device::buffer_alias_mem_gen with release/acquire ordering. Command buffers record the generation observed during recording (alias_mem_gen) and mark render streams that skipped HK_SYNC_GFX_MEM (alias_image_render); if the generation advances before submit, hk_sync_resolve_submit_ex() upgrades those streams to full HK_SYNC_GFX_MEM and widens barrier_ta/prior_ta.
  • Sparse and overlapping ALIAS_BIT safety: Sparse images (VK_IMAGE_CREATE_SPARSE_BINDING_BIT), oldLayout == UNDEFINED discard transitions, queue-family ownership transfers, and any ALIAS_BIT image whose bound GPU VA range overlaps an active pass attachment still conservatively end pass merging and render packing (HK_M5_MERGE_DEP_END).
  • Unit coverage: Added unit tests in src/asahi/vulkan/tests/test-hk-sync-prior.c covering image-only alias heaps, buffer-bound alias heaps, late post-record buffer binding upgrade at submit time, and disjoint vs overlapping VA-range layout transitions.

Verification (J714s / AGX3C / HAL300, Slot s4, base 9830668dd6b1)

  • Unit suite (--suite asahi):
    • Release build: 334/334 PASS (Fail: 0, SpillRepeatPair: 14 OK, 0 FAILED).
    • Assert build (-Db_ndebug=false): 331/331 PASS (Fail: 0).
  • Hardware tests:
    • hk-vulkan-render-pack-replay: 440/440 scenario submissions exact (0 faults).
    • vulkan-storage-alias: 32/32 case groups pass (0 faults).
  • Targeted Vulkan CTS (synchronization2, memory.requirements, dynamic_rendering.primary_cmd_buff.basic, renderpass2.suballocation.load_store_op_none): 313 Pass / 8 Skip / 0 Fail (0 faults).
  • Clang -Werror: 0 warnings/errors in touched files.
  • GTA V Enhanced (3024x1964, native internal resolution, ResScalingType=0, VSync off, isolated kits on same boot, A1 B1 B2 A2, 0 GPU faults / crashed=0 / quarantined=0, screenshots visually verified):
    • A1: P0=56.36 P1=51.86 P2=51.59 P3=55.54 P4=54.33
    • B1: P0=55.95 P1=51.59 P2=52.81 P3=57.66 P4=55.17
    • B2: P0=56.02 P1=51.75 P2=52.40 P3=57.88 P4=55.41
    • A2: P0=56.22 P1=51.94 P2=52.53 P3=57.74 P4=55.38
    • Mean (B vs A): P2 +1.05% (52.06 -> 52.61), P3 +2.00% (56.64 -> 57.77), P4 +0.79% (54.86 -> 55.29), P0 -0.54%, P1 -0.44%.

Not yet

Nothing — J714s (AGX3C/HAL300) exact-head verification above and J773g (AGX3B/HAL200) 2nd-gen verification (#issuecomment-7215198124, 33,097 CTS cases, 440/440 replay, 214/214 unit tests, 0 faults) at bcd0ad703e4f are both complete.

…er sync and packing

Applications running through D3D12-to-Vulkan layers (vkd3d-proton) set
VK_IMAGE_CREATE_ALIAS_BIT on every placed render target even when those
targets live in image-only heaps at disjoint virtual addresses. Treating
every ALIAS_BIT attachment as a general memory writer and every ALIAS_BIT
layout transition as aliasing previously forced HK_SYNC_GFX_MEM on the
majority of renders (preventing TA/3D pipelining) and broke cross-command-
buffer render packing at render-target layout-decay barriers.

1. Track atomic has_image_binding and has_buffer_binding flags on
   hk_device_memory plus a monotonic hk_device::buffer_alias_mem_gen
   counter bumped when a buffer is first bound to an image-bearing memory.
   Exempt optimal ALIAS_BIT attachments on image-only, non-external memory
   from m5_attachments_reach_memory (HK_SYNC_GFX_MEM), and conservatively
   upgrade affected streams and intra-CB vertex waits at submit time if
   buffer_alias_mem_gen advanced after recording.
2. Check GPU VA-range overlap (hk_image_va_range) for non-sparse,
   non-external ALIAS_BIT image layout transitions in pass merging and
   cross-command-buffer render packing, and treat content-preserving
   (oldLayout != UNDEFINED) layout transitions on non-sparse images as
   transparent for single-sample render packing.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 27, 2026 09:13
@DjDeveloperr

Copy link
Copy Markdown
Author

J773g (M4 Mac mini, G16G B0, HAL200, second generation) at bcd0ad703e4f, against its parent 9830668dd6b1: PASS, no regression.

Both arms are release Borealis Vulkan overlays built natively on the Mac and loaded from private prefixes through VK_DRIVER_FILES, on the stock kernel 7.3.0-ARCH-m4mainefed1ae3. System Mesa wasn't touched. Each arm's vulkaninfo shows its git SHA.

  • meson test --suite asahi, built and run natively on the Mac at the head: 214 Ok, 0 Fail. That includes hk_sync_prior, hk_host_alias and hk_sparse_alias.
  • hk-vulkan-render-pack-replay 20 (head build of the test): 440 scenario submissions exact on both the base and the head ICD, exit 0.
  • VK CTS at 1 worker, 33,097 cases:
    • The lists: synchronization2.{basic,implicit,timeline_semaphore,signal_order.{binary,timeline}_semaphore,op.single_queue}.* (20,411), renderpasses.dynamic_rendering.*resolve* (9,750), and every memory.* / api.* / sparse_resources.* case with alias in its name (2,936).
    • Base: 24,118 Pass, 8,977 NotSupported, 2 Fail. Head: 24,119 Pass, 8,977 NotSupported, 1 Fail.
    • The 3 cases that differ are all *buffer_262144 sync cases: op.single_queue.fence.write_ssbo_tess_eval_read_ssbo_vertex and one multi_events case failed on base, and timeline_semaphore.device_host.write_ssbo_fragment_read_vertex_input failed on the head.
    • Each was rerun 5 times alone on each arm, and none fails on the head only. This buffer_262144 family fails at random on base too on this Mac.
  • GPU health: 0 faults, 0 recoveries and failed 0 errno 0 degraded 0 at start and end of every part.

@DjDeveloperr

Copy link
Copy Markdown
Author

Verdict at bcd0ad703e4f: ready

Blockers

None.

Checked

  • Exempting aliased images from HK_SYNC_GFX_MEM.
    • HK_SYNC_GFX_MEM matters only for narrowing the vertex half of later renders in hk_sync_barrier(). An optimal ALIAS_BIT attachment now keeps that kind only when its memory may be reached another way (hk_image_mem_may_alias_buffer()): linear, sparse, imported/exported/fd, or a memory object that has had a buffer bound.
    • Image-to-image aliasing still goes through image barriers, and att_bloom stays all-ones for ALIAS_BIT attachments, so vertex image reads keep the full wait.
  • Buffer bound after recording.
    • has_image_binding / has_buffer_binding are set with full fences, and the buffer bind raises buffer_alias_mem_gen once both are set. The command buffer snapshots that counter before testing the memory, so a concurrent bind is either seen at record time or raises the counter afterwards.
    • At submit, a stale snapshot turns every alias_image_render stream back into a memory writer, restores the full vertex wait, and feeds ss.last and the attachment ring. Resubmitting after a bind is covered the same way.
  • Transitions in pass merging and render packing. An ALIAS_BIT transition now ends pass merging or packing only when hk_images_va_overlap() says its range may share storage with an attachment. Unbound, sparse and imported/exported images count as overlapping, and an UNDEFINED transition of an overlapping image ends the head. Transitions record no work in hk, and hk_render_pack_continues() still requires the same attachment layout in both instances.
  • Merge and build.
  • Mutations. Dropping the submit-time upgrade fails "alias-image render submit-time gen check". Making hk_images_va_overlap() always false is not caught: no test covers the new transition handling, so a pack-boundary case with an overlapping and a disjoint ALIAS_BIT image would close that gap.
  • Policy. agent-policy.sh pr HEAD: PR is clean. Signed off, no attribution lines, no new environment options.
  • Rows. J714s and J773g (#issuecomment-7215198124) are both at this head, so nothing is owed.

Edge (not blocking). The submit-time check only covers command buffers submitted after the bind. If a buffer is bound to the memory while a command buffer that rendered into it is still running, a later render whose vertex stage writes that buffer (storage or transform feedback) narrows its vertex wait past the earlier render. Reads through the buffer are undefined there anyway; only that write ordering is affected. Raising the queue's prior HK_SYNC_GFX_MEM ordinal to its last render ordinal when the counter moves would close it.

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.

1 participant