Repository navigation
hk: give M5 barriers memory scope only while a host import may alias - #552
Draft
DjDeveloperr wants to merge 8 commits into
Draft
DjDeveloperr wants to merge 8 commits into
DjDeveloperr wants to merge 8 commits into
Conversation
Author
Independent code reviewsTwo independent reviewers (Opus 5.5, xhigh), each given only the code and the hardware rule from Commits 1–5 (per-import rule)
Commits 6–8 (per-resource widening)
🤖 Generated with Claude Code |
DjDeveloperr
force-pushed
the
m5/pack-strong-flush-tail
branch
from
November 19, 2026 22:18
9698726 to
0e5d304
Compare
DjDeveloperr
force-pushed
the
m5/host-import-alias-scope
branch
from
November 19, 2026 22:18
4394e0b to
c9644e7
Compare
DjDeveloperr
force-pushed
the
m5/pack-strong-flush-tail
branch
from
November 19, 2026 23:28
0e5d304 to
97635e9
Compare
DjDeveloperr
force-pushed
the
m5/host-import-alias-scope
branch
from
November 19, 2026 23:28
c9644e7 to
9d9275f
Compare
The pages of a host import have another GPU address only if they are mapped at another virtual address the GPU also reaches, or imported again. Add the pure functions an M5 device needs to tell (hk_host_alias.c): - a parser of /proc/self/maps lines into private anonymous memory (no pathname, [heap], or a [anon:...] name, without an inode), private mappings of a file, and everything else: shared mappings of any kind, /dev and anonymous-inode mappings, [stack] and other special regions; - a walk that folds the lines over a range in their ascending order, skipping the lines below it and stopping at the line that decides it, where a gap, an unparseable line or a line past the end of the file decide against the range; - the set of a device's live imports, which counts for each import the live imports overlapping it of which one of the two is GPU-writable; two read-only imports of the same pages do not count, as the GPU writes neither. Nothing uses them yet. The host test runs them on synthetic maps text, on the test process's own private, shared and holed mappings, and on overlapping writable and read-only imports. Signed-off-by: Diljit Singh <hey@djdev.me>
An M5 device that enabled VK_EXT_external_memory_host without hk_host_memory_import_read_only flushed with memory scope (0x6000157c) at every application dependency between compute and transfer work (hk_device_may_alias_memory()), instead of the plain strong flush (0x60001560). Memory scope is needed where a dependency's write and read go through two GPU addresses of the same pages, but an import gives its pages a second address only if they have one already: imported again, or mapped at another virtual address that something else imports. Geekbench 6 enables the extension, and on the M5 Pro the memory scope cost 10-14% of GPU time in Background Blur (8179 -> 7035 us/iter without it, measured with a measurement-only switch, HK_DEBUG_M5_NO_ALIAS_SCOPE=1, that this tree does not carry) and Face (13572 -> 12168). Where writable host imports are the device's only feature that can give memory a second address, decide it from the imports that exist (host_alias.dynamic): the device starts without the scope and counts its live imports that may alias (host_alias_live). An import may alias unless it is GPU-read-only, or its whole range lies in private anonymous mappings of the process (/proc/self/maps: private, and no pathname, [heap] or [anon:...]), and it overlaps no other live import of the device of which one of the two is GPU-writable; a read-only import needs only private mappings. Overlapping imports alias together until one of them is freed. Sparse binding and residency, capture/replay, fd and dma-buf imports keep the per-device rule, and G17P and other chips are unchanged. The scope must still cover work recorded or submitted before an import that aliases, which can reach it through a device address it loads or a descriptor updated after bind. Every application dependency recorded without memory scope because of this rule is a patch site: the stream word of its barrier record (the strong flush, or a stream's last ordering record at its end), over which the memory-scoped strong flush is written once an import may alias. A site stays a barrier record: an application dispatch after it no longer drops it, and an inline stream merge moves it with the copied bytes. The sites of a command buffer are written - at submission, while an import may alias, before submit packing copies the streams (hk_queue_submit()). Work behind a semaphore the host signals reaches the driver only once the signal is submitted, since the runtime holds it on a submit thread until its waits are (VK_SYNC_WAIT_PENDING), so this sees every import the work may reach; - for every executable command buffer, when the count leaves 0 (hk_device_patch_alias_sites()); - at vkEndCommandBuffer when an import may alias by then, or the command buffer uses events: a host-set event could let an execution that started before an import reach it, so such command buffers keep memory scope throughout, as do the dependencies of graphics paths, which record no site. Writes only add memory scope, until the command buffer is reset. The first write of a command buffer's sites excludes submit packing (host_alias.patch_lock), so a copy never takes half a word, and each word is stored whole for the GPU. Command memory on M5 is uncached, so the words need a fence, not cache maintenance. ASAHI_M5_HOST_ALIAS_STATIC=1 restores the per-device rule for host imports, for an A/B on the same build and as a fallback. ASAHI_M5_HOST_ALIAS_TRACE=1 prints each import's class and the count. Run on the M5 Pro in the lane's form of this series (packtest incl. host-import cases, the negative control and a 6,197-case dEQP-VK alias gate, see the pull request); this port itself has not run on hardware. The ordering-only compute barrier of HK_PERFTEST=weakbarrier keeps the launch's weak record instead of a flush; while the scope follows the imports, that record is a patch site as well. Signed-off-by: Diljit Singh <hey@djdev.me>
With the scope following the live host imports (previous commit), the patch sites give memory scope to reads recorded before an import that aliases, but not to writes made before it. An application barrier at the end of a command buffer leaves the strong flush without memory scope (0x60001560), which vkEndCommandBuffer did not upgrade, so a command could end with its writes still in the GPU caches under the first import's address. Pages written through one import in one submission, then imported a second time, and read through the new import in a later submission, were never flushed with memory scope in between. The same holds for a read-only import added over pages a writable import wrote, for an import that replaced a freed one of the same pages, and for the same pages imported by another VkDevice or API of the process, which the device's set of imports cannot see. With host_alias.dynamic, end every compute stream holding work with the memory-scoped strong flush at vkEndCommandBuffer, upgrading a strong flush without memory scope in place as a weak tail already was, or appending it where the last record is no barrier. Every command then writes back what it wrote by its end, as the memory scope of each barrier did under the per-device rule, whatever imports exist later. Vulkan orders the work of two devices, or of Vulkan and another API, only at submission boundaries, each of which now follows a memory-scoped flush. Launch tails are weak records, upgraded in place. Submit packing (hk_pack_runs()) still strips the scope between packet members while no import may alias and keeps it at the packet's end, so a packet pays one memory-scoped flush. Moving an imported range with mremap and importing the new address is not seen: the first import's pinned pages are then under a private anonymous mapping that overlaps no import. Document it where the classes are defined (hk_host_alias.h, which called mremap safe), with why the extension rules it out and the kernel check that would see it. Signed-off-by: Diljit Singh <hey@djdev.me>
Two follow-ups to the M5 host-import alias scope ("hk: give M5 barriers
memory scope only while a host import may alias"):
- The mappings over a host import were read after the kernel pinned its
pages, so an application that replaced the mapping between the two was
classified by the later one only. Read /proc/self/maps before the pin
as well and take the worse class.
- A submission held host_alias.patch_lock shared through the whole
submit, kernel ioctl included, so the first aliasing import waited for
every submission in flight. Only submit packing reads stream words on
the CPU (hk_pack_runs(), which copies them); hold it just around that.
The GPU reads each word whole.
Signed-off-by: Diljit Singh <hey@djdev.me>
…asing The comment on hk_cdm_alias_scope() said every command holding compute or transfer work ends with the memory-scoped flush while host imports decide the scope. Only compute streams with launches do; graphics commands, including transfers done through a render pass, get no such flush, exactly as under the per-device rule, which never gave M5 graphics memory scope. The M5 member check of submit packing (hk_pack_run_member()) now also says that under host_alias.dynamic every stream with launches ends memory-scoped, whatever its last record. Comments only. Signed-off-by: Diljit Singh <hey@djdev.me>
With ASAHI_M5_HOST_ALIAS_TRACE=1, name at device creation every enabled feature or extension through which memory can get a second GPU address (sparse binding and residency, buffer device address, descriptor buffer and acceleration structure capture/replay, fd and dma-buf memory, writable host imports), and whether the device decides the barrier memory scope per import or per device. Under the per-device rule, also say when a host import is made, so a trace shows whether an application imports at all. On the M5 Pro, Geekbench 6's device took the per-device rule (no import was traced and its GPU time did not change with the per-import rule); this names the reason. Signed-off-by: Diljit Singh <hey@djdev.me>
The per-import rule ("hk: give M5 barriers memory scope only while a
host import may alias") applied only to devices whose sole feature that
can give memory a second GPU address was writable host imports. On the M5 Pro, Geekbench 6's device enables sparse binding and
residency and buffer device address capture/replay (both exposed), so
it kept the per-device rule and the memory-scoped flush (0x6000157c) at
every application dependency between compute and transfer work.
Decide it per resource on every M5 device that enabled such a feature
(host_alias.dynamic): memory scope while the device's live aliasing
count (alias_live) is not 0. It counts
- buffers and image planes with a GPU address of their own over other
memory, sparse ones and capture/replay buffers, and memory mapped again
in the capture/replay region for descriptor buffers: the existing
va_alias_resources, each from its creation, before memory can be bound
to it, to its destruction, also on every failure path. A failed shadow
bind or host-import classification no longer leaks a capture/replay
mapping and its count;
- fd and dma-buf imports, each for its lifetime, since another import of
this or another device or process may map the same pages;
- host imports that may alias, as before.
Acceleration structure capture/replay adds no address on M5: a
structure's address is its buffer's, also on replay
(vk_common_CreateAccelerationStructureKHR()), and image views and
samplers replay descriptor indices only. Both are dynamic with nothing
of their own to count. An export (vkGetMemoryFdKHR) reaches another
device or process only across a submission boundary, after the
memory-scoped flush that ends every command; imported back here it
counts as an import.
Every increment goes through hk_device_alias_get(), which runs the patch
of all live command buffers (hk_device_patch_alias_sites()) when the
count leaves 0, before the creating call returns; the count is atomic,
exactly one caller sees it leave 0, and a creation that adds to a count
another caller is still patching for is covered by the check at
submission. The rest of the per-import machinery applies unchanged:
patch sites, the memory-scoped flush that ends every command, the pack
read lock. G17P keeps its record-time rule and other chips are
unchanged. ASAHI_M5_HOST_ALIAS_STATIC=1 restores the per-device rule for
all of these features (A/B and fallback). With ASAHI_M5_HOST_ALIAS_TRACE=1 the device trace names the
rule (per-resource, per-device or none), and each time the count leaves
0 its cause (import, sparse, capture-replay, fd) and how many command
buffers were patched.
Signed-off-by: Diljit Singh <hey@djdev.me>
The previous commit moved the add of the host imports that began to alias to after host_alias.lock was released, while their removal still subtracts under it. A free of an overlapping import could then subtract first and wrap alias_live. A sparse, capture/replay or fd resource created at that moment took the count back to 0 instead of from 0: no patch of the live command buffers ran, the count read 0 while the resource was live, and a command buffer recorded then wrote through one address, flushed without memory scope, and read through the resource's (an import B over two imports A and C: B's add of 3 delayed, A's free subtracting 1, a sparse buffer's add returning 0). For the same reason the add that took the count from 0 could miss seeing n, and the patch was skipped. Add the imports' count under host_alias.lock again, together with the set that says how many of them alias, through hk_device_alias_add(), which returns whether this call took the count from 0; run the patch of every live command buffer (hk_device_alias_began()) after the lock is released when it did. The other callers keep hk_device_alias_get(). The count now never wraps: each sparse, capture/replay and fd resource subtracts only in the destruction that follows the call that created it and added, and host imports add and subtract under the set's lock, so exactly the add that leaves 0 sees n. Lock order is unchanged. Signed-off-by: Diljit Singh <hey@djdev.me>
DjDeveloperr
force-pushed
the
m5/pack-strong-flush-tail
branch
from
November 19, 2026 23:53
97635e9 to
c3c7b08
Compare
DjDeveloperr
force-pushed
the
m5/host-import-alias-scope
branch
from
November 19, 2026 23:53
9d9275f to
0cde182
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebased 11-19 23:4x onto the rebased #506 (
c3c7b08c, on #488ee3de2b5). The head is now0cde1823(pushed before:9d9275f6on #488532fbf4d, andc9644e73). Range-diff againstc9644e73:untouchedargument ofqueue_submit(), plus itsresult == VK_SUCCESSguard. Thehost_alias.patch_lockread section still covers exactlyhk_pack_runs(), where every stream copy, every boundary change and the size-guard fallback happen. The lock is released exactly once on every path.hk_cdm_memory_scope_form()inhk_device.h.hk_pack.c, gains a clause: underhost_alias.dynamic, every stream with launches ends memory-scoped.Local checks ran per commit, all 8. Each got a host build at
-j2, an asserts-on syntax check of the changed files,hk_pack_test(145/145) andhk_host_alias, each plain and with ASan/UBSan. A focused independent re-review (Opus 5.5, xhigh) was CLEAN. Its minor findings were in #506 and are fixed there.On the M5: slot s8 runs this head. After #488's packing gate and the packing off/on timing, it runs the alias A/B (static vs per-resource rule). That covers Geekbench ABBA, packtest's alias cases under both rules, and dEQP
alias.txtunder both rules.Earlier rebase (11-19 22:1x, head
c9644e73)Onto the rebased #506 (
0e5d304f, on #4882c4692477bb6/ aurora-wipaf7ec5f4). The head is nowc9644e73, previously4394e0b2. Range-diff:167eaff3): now registershk_cdm_note_alias_site()in aurora-wip's new ordering-only compute-barrier path, replacing the oldhk_cdm_visibility_flush_needed(..., alias_scope)gate.e0346f4e) and 7 (acaac171): adapted to the same upstream code.a787ee3c(hk: give G17P dependencies memory scope while a writable import lives #472): counts fd and writable host imports inva_alias_resourcesthroughalias_import, for G17P. Its lines are kept next to ours (host_alias_tracked,alias_fd), so G17P behaves as upstream and M5's count is unchanged.1142bcb9(opt-inHK_PERFTEST=weakbarrier): keeps the launch's weak record instead of a flush when no alias scope is asked for. In the per-resource mode that record now registers a patch site (hk_cmd_alias_scope()plushk_cdm_note_alias_site()), so it gets the memory scope if an alias appears later. Outside that mode nothing changes.The sibling-queue guard is kept, so packed submits stay off sibling queues. Local checks on the new head: host build at
-j2, an asserts-on syntax check, and thehk_host_aliasunit test, plain and with ASan/UBSan. The focused independent re-review of the four changed resolutions was CLEAN.Draft. Stacked on #506 (base
m5/pack-strong-flush-tail), which is based onaurora-wip(#488 merged as11ee6231). Commits 1–5 decide the memory scope from the live host imports; commits 6–8 widen that to every live resource through which memory has a second GPU address (see "Widening (commits 6–8)"). Commits 6–8 ran on the M5 Pro in the lane's form (results below); this exact port has not.What and why
On M5, a strong CDM flush needs memory scope only where a dependency's write and read reach the same pages through two GPU addresses. That was measured on hardware in
23644ad6e3c("hk: decide per device whether M5 barrier flushes need memory scope"): without the scope (0x60001560) such a read returned stale data for every word, and with it (0x6000157c) exact data. That commit decides the question once per device. A device that enabled any feature through which memory could get a second GPU address keeps the memory-scoped flush at every application dependency for its whole life. One such feature isVK_EXT_external_memory_hostwith GPU-writable imports.Geekbench 6 enables
VK_EXT_external_memory_host. On the M5 Pro the memory scope costs 10–14% of GPU time:Both were measured with a measurement-only switch that turns the scope off (
HK_DEBUG_M5_NO_ALIAS_SCOPE=1). That switch is not part of this PR. A host import gives its pages a second GPU address only if they already have one: they are imported again, or mapped at another virtual address that something else imports. This PR makes the M5 rule follow the host imports that actually exist, instead of the extension being enabled.The rule
The device starts without memory scope and counts its live host imports that may alias (
host_alias_live). This applies only when writable host imports are the device's only reason for memory scope (host_alias.dynamic), and only on M5.Unaliased imports. An import is unaliased when both of these hold:
Private anonymous memory means a
/proc/self/mapsentry that is private with no pathname,[heap]or[anon:...]. The maps are read before the kernel pins the pages and again after, and the worse class counts. Overlapping imports alias together until one of them is freed.hk_host_alias.cholds the pure classifier and the import set, with a host unit test (tests/test-hk-host-alias.c).Patch sites. Every application dependency between compute and transfer work that is recorded without memory scope because of this rule records a patch site. A site is the stream word of its barrier record: the strong flush, or the stream's last ordering record at its end. The memory-scoped strong flush is written over it:
host_alias.patch_lockheld shared, and only around the copy; the kernel ioctl runs after the lock is released.hk_device_patch_alias_sites(), which takes the lock exclusively).vkEndCommandBufferwhen an import may alias by then.A site stays a barrier record: an application dispatch after it no longer drops it, and an inline stream merge moves it with the copied bytes. Writes only add memory scope, until the command buffer is reset. Command memory on M5 is uncached, so the writes need a fence, not cache maintenance.
End-of-command flush. In dynamic mode, every M5 compute stream that holds launches ends with the memory-scoped strong flush at
vkEndCommandBuffer. Patch sites cover reads by work recorded before an import. The end flush covers writes made before an import, which may later be read through:#488's packing keeps that flush only at a packet's end while no import may alias.
Paths that keep the old rule:
VK_KHR_external_memory_fdorVK_EXT_external_memory_dma_bufkeeps the per-device rule. Commits 6–8 replace this with the per-resource count (see "Widening (commits 6–8)").Switches:
ASAHI_M5_HOST_ALIAS_STATIC=1restores the per-device rule for host imports, for an A/B on the same build and as a fallback.ASAHI_M5_HOST_ALIAS_TRACE=1prints each import's class, the live count, and how many command buffers were patched.Known limits. Both need a kernel bit,
DRM_ASAHI_GEM_USERPTRreporting that a page it pinned was already pinned long-term (folio_maybe_dma_pinned()), which would then count as aliasing:mremap, and imports the new address too has the first import's pinned pages under a private anonymous mapping that overlaps no import. Within one submission, a write through one import, a barrier and a read through the other would read stale data. Across submissions, the end-of-command flush still covers it. The plain move leaves the first import's range unmapped, which the extension does not allow while the import lives. This is documented inhk_host_alias.h.Review history
An independent code-only review of the first two commits found it NOT CLEAN: 2 BLOCKER, 1 MAJOR and 4 MINOR.
mremapcan give pinned pages a second virtual address. This cannot be fixed without the kernel, so it is documented as a known limit (3rd commit).A re-check of the fixes was CLEAN. Remaining MINORs:
mremaplimit and the narrowed maps/pin race above;Hardware validation
Setup: M5 Pro (J714s, T6050, G17S, 20-core GPU), Arch Linux ARM, kernel
7.3.0-m5-intg16. Slot s4c, 2026-11-19 14:01–14:11.Mesa revision tested:
214f4ea9f71of the M5 driver-overhead lane's local branch, driver sha2560f62d8438ab8…. That branch carries the same five commits on top of the lane's own packing commits, which #488 ports, and the repeated-recording fix (#444 fixes that bug publicly). It also carries opt-in switches that are off by default and not part of this tree: light barrier, overlapped dispatches, extra frame-anatomy stamps, and a whole-submission packer. This PR's exact port has not run on hardware. The port differs from the tested commits only where that absent code was touched (listed below).packtest (the lane's Vulkan compute submission test; each case's output is compared word for word with a CPU model, including guard words; 4 iterations per case):
semanddup) in three arms: packing off with the new rule, default packing with the new rule (withASAHI_M5_HOST_ALIAS_TRACE=1), and the static rule (ASAHI_M5_HOST_ALIAS_STATIC=1).hostpriv: a dependent chain on an imported private allocation.hostalias: two imports of the same pages, the second created before the command buffers were recorded.hostalias-late: the same, with the second import created after recording, so it exercises the patch path.hostalias-xsub: a write before an import, read through it in a later submission.HK_DEBUG_M5_NO_ALIAS_SCOPE=1, lane-only):hostaliasandhostalias-lateMISMATCH in every iteration, as designed. The test therefore detects a missing memory scope on this hardware, and the new rule's scope is what makes those cases pass.hostalias-xsubpassed even without the scope; the end-of-command flush stays, because it covers that case by construction.dEQP-VK alias gate (the kit's
cts147build, 16 jobs): 6,197 mustpass cases frommemory.external_memory_host,api.external.memory,memory.binding,sparse_resources.buffer, buffer-device-address capture/replay,memory.pipeline_barrier,synchronization{,2}.basic,synchronization2.op.single_queue.barrier,compute.pipeline.basic, and 1/8 ofmemory_model.message_passing.No gain yet
Geekbench 6.7.1 compute (Vulkan), GPU time per iteration, static rule vs new rule in the same slot:
The import trace printed nothing, so Geekbench's device never entered the dynamic mode. The likely reason, not yet confirmed: the M5 exposes
sparseBinding,sparseResidencyBufferandbufferDeviceAddressCaptureReplay, and a device that enables them keeps the per-device rule whatever its imports.Widening plan
Widening (commits 6–8)
What and why. In slot s4c, Geekbench's device kept the per-device rule: no import was traced, and its GPU time did not change with the per-import rule. The likely reason is that it enables sparse binding or buffer device address capture/replay, which the M5 exposes.
ASAHI_M5_HOST_ALIAS_TRACE=1, a line at device creation that names every enabled feature or extension through which memory can get a second GPU address, and the rule the device took. Under the per-device rule it also traces each host import, so a trace shows whether an application imports at all. A slot is pending that runs Geekbench with this trace to confirm which features its device enables.host_alias.dynamic): sparse binding and residency, buffer-device-address, descriptor-buffer or acceleration-structure capture/replay, fd/dma-buf memory, and writable host imports. Memory scope applies while the device's live aliasing count,alias_live, is not 0. G17P keeps its record-time rule, and other chips are unchanged.The per-resource count (
alias_live). It counts:replay_va). Together with the sparse resources these are the existingva_alias_resources, which G17P still reads on its own.host_alias.lock, together with the import set.Acceleration-structure capture/replay adds no address on M5: a structure's address is its buffer's, also on replay. Image views and samplers replay descriptor indices only.
Every increment goes through one helper,
hk_device_alias_add(), which returns whether this call took the count from 0. When it did,hk_device_alias_began()writes the patch sites of every live command buffer before the call that creates the resource returns; host imports call it after releasing the lock. Each subtraction follows its own addition, so the count never wraps.Everything else from commits 1–5 applies unchanged to every dynamic M5 device: patch sites, the end-of-command flush, the submit-time patch and the pack read lock. Two more changes:
ASAHI_M5_HOST_ALIAS_STATIC=1now restores the per-device rule for all of these features. WithASAHI_M5_HOST_ALIAS_TRACE=1, the trace printsrule=per-resource|per-device|none, and each time the count leaves 0 it prints the cause (import,sparse,capture-replayorfd) and how many command buffers were patched.Exports are not counted. Exporting memory (
vkGetMemoryFdKHR, or an allocation made exportable) gives it no second address in this device. Another device or process that imports it reaches it only across a submission boundary: an external semaphore or fence, or a host wait. Every compute command on a dynamic M5 device ends with the memory-scoped flush, so this device's writes are in memory by then. The importer counts its own import: an M5 fd import counts, and a per-device importer flushes every dependency. Importing the fd back into this device goes through the import path, which counts.Review history. An independent code-only review of commit 7 was NOT CLEAN, with one BLOCKER (B1):
host_alias.lock, but added that number to the count only after releasing the lock, while freeing an import subtracted under the lock.alias_live. A sparse, capture/replay or fd resource created at that moment would then take the count back to 0 instead of from 0. No patch ran, and the count read 0 while the resource was live.Commit 8 adds the host imports' count under the lock again. The re-check was CLEAN. The review also asked for more coverage, which the
sparsealias-xsub,craliasandcralias-pendingcases below provide.New packtest cases. They run on a third test device that enables sparse binding, buffer-device-address capture/replay and update-after-bind sets where the device has them. Each case SKIPs without its features.
sparsealias: a sparse buffer is fully bound to the slot memory before recording. Dependent dispatches alternate between the slot buffer and the sparse buffer, then copy what the sparse buffer wrote through the slot buffer.sparsealias-late: the same, but the sparse buffer is created, bound and written into the descriptor set after recording and before submission (update-after-bind).sparsealias-xsub: one command buffer writes through the slot buffer and completes. Only then is the sparse buffer created, and a second submission reads every slot through it. This is the end-of-command-flush case, for sparse.cralias: likesparsealias, with a capture/replay buffer bound to the slot memory.cralias-pending: the command buffers are submitted behind a timeline semaphore that the host signals. The capture/replay buffer is created aftervkQueueSubmitreturns and before the signal, and the shaders reach it through a device address they load.sparsealias-pending: the same with a sparse capture/replay buffer, bound on a second queue (one queue cannot: the bind would wait behind the pending submission).Every case that creates the aliasing resource after recording re-records its command buffers each iteration, so each iteration exercises the 0 -> N transition.
Hardware results for commits 6–8 (lane form)
M5 Pro (J714s), kernel 7.3.0-m5-intg26, the lane's build of these commits (
195aa0790d8, driver sha25626365cb8…), slot s6, 2026-11-19 16:40–16:50. This PR's exact port has not run on hardware.Why Geekbench gained nothing before: the device trace (previous slot, s5t) showed that Geekbench 6.7.1's Vulkan devices enable
sparseBinding sparseResidencyBuffer sparseResidencyImage2D sparseResidencyAliased, plus writableVK_EXT_external_memory_hoston one of them. The sparse features kept the per-device rule. With commits 6–8, every Geekbench device runsrule=per-resource may_alias=0. Its four host imports (95 MB and 24 MB ranges) are private anonymous memory with no alias, and no aliasing resource is created during the run.Geekbench 6.7.1 compute (Vulkan), new rule vs
ASAHI_M5_HOST_ALIAS_STATIC=1in the same slot:Known measurement artifact: Horizon Detection. Its +9.5% is not an effect of this change. Its GPU time is unchanged (−0.4%), and its iteration time is dominated by Geekbench's own CPU phase between GPU waits, which is bimodal from run to run regardless of driver configuration. In this slot the static-rule runs took 12.0 and 14.0 ms per iteration and the new-rule runs 16.5 and 12.0 ms. The same swing appears between identical configurations in earlier slots (13.9 vs 16.8 ms). Read Horizon from GPU time, not iteration time.
Correctness:
hostalias,hostalias-late,sparsealias,sparsealias-late,cralias,cralias-pendingandsparsealias-pendingmismatch in every iteration, so each detects a missing scope on this hardware. The-xsubcases pass even then; the end-of-command flush covers them by construction.Port from the tested commits
These are the only differences from the tested lane commits:
hk_CmdPipelineBarrier2(), and its mentions in comments and messages, are dropped. This tree has no light barrier, so a site is always a strong flush or a launch's ordering record.HK_DEBUG_M5_NO_ALIAS_SCOPEblock inhk_CreateDevice()and its comment are dropped; that switch is lane-only.queue_submit()→hk_pack_runs()instead of the lane'squeue_submit_unique()→hk_pack_submit()/hk_pack_runs(). It is still held shared only around the copy.try_relu6) is dropped, so the 4th commit is titled "...classification and pack locking".Commits 6–8 needed these adaptations:
hk_CreateDevice(), because the lane-onlyHK_DEBUG_M5_NO_ALIAS_SCOPEblock it followed is absent.#488's
hk_pack_runs()M5 branch needed no change: it already strips memory scope between members only whilehk_cdm_alias_scope()is false and keeps it at the packet's end. G16G is untouched.Not run: this PR's exact port on any hardware; commits 6–8 on any hardware, in any form; G16G (by construction it never enters the mode); other M5 parts.
Host checks (all eight commits):
test-hk-host-alias.cbuilt standalone and run, plain and with ASan/UBSan.packtest is the lane's test program and is not published yet. Raw logs of every arm are kept with the lane.
Environment switches
Environment switches and the cleanup in #551:
aurora-wipis removing driver environment switches (#551). This stack relies onHK_PACK_CDM_SUBMIT,HK_PACK_ATOMICSandHK_PACK_CDM_TRACEfrom #488, and onASAHI_M5_HOST_ALIAS_STATICandASAHI_M5_HOST_ALIAS_TRACEfrom #552. They stay until each PR is merged and verified on hardware, as the A/B and fallback for that verification. One follow-up PR then removes them all.🤖 Generated with Claude Code