Skip to content

hk: flush with memory scope for a G17P alias dependency recorded before any work - #124

Draft
DjDeveloperr wants to merge 8 commits into
aurora-wipfrom
fix/g17p-alias-scope-stream-opener
Draft

DjDeveloperr wants to merge 8 commits into
aurora-wipfrom
fix/g17p-alias-scope-stream-opener

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Oct 31, 2026 •

Copy link
Copy Markdown

Draft: not hardware-tested. The Neo is offline. This must not merge before the new cases have run on the affected hardware.

Follow-up to #98 and merged #123, from scottjones's and maralcbr's reviews of omacom#20. Mirror: omacom#23, based on the #20 branch. This branch merges aurora-wip at 8990cdb without rewriting its history.

There are two cases:

  • With no open compute stream holding work, an alias dependency records a memory-scope flush in a stream ordered after its source scope, then orders its destinations after that stream. This includes the first barrier of a command buffer and a barrier after a timestamp, query copy, or another stream-closing operation partway through a command buffer. hk_CmdSetEvent2() also emits the flush before the event write.
  • Transfer writes can end in stream A, followed by unrelated compute in stream B. An XFER-to-graphics barrier records the memory-scope flush in B, while its source-stage dependency reaches only A. The new ordering extends a graphics destination's CDM requirement to B only if its existing cut precedes B (or has no local cut). A requirement already including B is unchanged, including when B is the source stream. Compute and transfer destinations retain CDM subqueue ordering. This adds no flushes; it orders graphics after the existing alias flush. The new path is gated on a live G17P alias resource, a compute/transfer source, and an open stream holding work. Devices without alias resources gain no ordering or flushes from this change. The hardware performance cost is unmeasured.

The hk_device.h comment now also names the untested graphics-only source case: attachment or shader writes through a sparse image followed by transfer or compute reads through a plain alias retain the ordinary post-graphics strong flush. Its behavior is unchanged. Resources created after recording and reached through indirect device addresses or update-after-bind descriptors remain outside the record-time resource gate.

The existing hk_sync_prior CPU test now checks the production ordering helper and submit resolver for all three graphics destination classes, the source-stream case, and CDM-only destinations. It models stream dependencies, not GPU cache behavior.

CI on omacom#23 at 6a13909, which carries this code as 78198e0, built it on x86_64 and aarch64 and ran the meson suites: 156/156 pass on both, including hk_sync_prior with the new cases (run). The negative control, the new cases failing without the fix, has not been run.

Hardware tests prepared, not run: the scratch patch against gpubench db3fec6 in work/gpubench-sparse-split.patch retains GB_SPARSE_SPLIT=1 (two command buffers, same submit) and =2 (separate submits, no host wait), and adds =3 (timestamp mid-command-buffer before the barrier) and =4 (timestamp, unrelated compute, XFER-to-fragment barrier, render reading the plain pool alias). The changed C source compiles as an arm64 macOS object with -Wall -Wextra -Werror; the Linux target build is blocked by the same VM endpoint. No variant has run.

Run variants 1-4 on the Neo against private builds of #20 and this draft, with the same seed and duration, through /opt/neo-gpu/cts-1.0/gpurun.sh. The hardware question remains whether a memory-scope flush in a later stream writes back lines dirtied by an earlier stream; no new hardware result is claimed. The Zink A/B requested in #20 remains pending as well.

Comment-only follow-up to merged #123: #128; carried into this branch with cherry-pick -x and an opener-aware comment conflict resolution.

…re any work

A dependency between compute or transfer work gets its memory-scope flush
in hk_CmdPipelineBarrier2() only when the open compute stream already
holds work (hk_cdm_visibility_flush_needed() is false at stats.cmds == 0).
The first barrier of a command buffer has no open stream, so with a
sparse or capture/replay resource alive its source writes, which are in an
earlier command buffer, got no memory-scope flush before the first work
after the barrier read them through another address. hk_CmdSetEvent2()
had the same gate.

Record the flush the way a host-read dependency already does: in a stream
ordered after the source scope (hk_sync_get_cs_after()), and order the
destination kinds after that stream with hk_sync_after_stream(). A reader
in the same stream follows the record; a render waits for the stream. For
an event, the flush goes ahead of the event write in the stream that
carries it. hk_cdm_flush() still elides the record when the stream's tail
already has memory scope.

Devices without such a resource record what they did before; so does a
barrier recorded into a stream that holds work.

Not hardware-tested: the Neo is offline. Whether a memory-scope flush in a
later stream writes back lines an earlier command dirtied is the point to
test, with gpubench sparse.churn split so that the transfer barrier opens
a second command buffer, in the same vkQueueSubmit and in a following one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Name barriers after a compute stream closes as well as command-buffer openers. Also document the untested graphics-only source case, which keeps the ordinary strong flush. No behaviour changes.
Name barriers after a compute stream closes as well as command-buffer openers. Also document the untested graphics-only source case, which keeps the ordinary strong flush. No behaviour changes.

(cherry picked from commit 1498a03)
An XFER source can name stream A while the open CDM stream B holds unrelated compute work. The memory-scope flush lands in B, but the source-stage dependency only orders graphics after A.

After the alias flush, extend graphics destination requirements only when their CDM cut precedes the flush stream. Leave requirements that already include that stream and CDM destinations unchanged. The caller is gated on a live G17P alias resource and a compute or transfer source.

Exercise the ordering helper and submission resolver in the existing CPU sync test, including flushes in the source stream and CDM-only destinations.
DjDeveloperr and others added 3 commits October 31, 2026 12:49
When the open compute stream holds work unrelated to the source, the
memory-scope flush goes at its end, but a graphics destination is still
ordered only after the source's stream, so it can start before the flush.
Say so, so the comment does not imply that every recorded alias flush
orders its graphics reader. Also rewrap the one line past 80 columns.

Comment only. Raised in review of omacom#20.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tream-opener

Keep this branch's alias-scope comment, which describes the flushes this
branch adds in place of the gaps #128's comment names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The alias-scope comment names the stream-opener flush this branch adds but
not the ordering hk_sync_after_alias_flush() adds when the open stream
holds work unrelated to the source. Say that a graphics destination is
ordered after that stream too. Comment only; every line now fits in 80
columns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@RyanTheTide

Copy link
Copy Markdown

Hi, coming back to this one. Since it was opened, aurora-wip gained 8c27591 ("end compute streams with a memory-scope flush where memory may alias", merged with #266). That ends every compute stream with a memory-scope flush while hk_cdm_alias_scope() holds, on G17P too, which covers the first case here (a barrier with no open stream holding work). The two comment commits (1498a03, f1a1e8b) are already on aurora-wip as well. What still looks unique is d2e11d9, which orders a graphics destination after an alias flush in an unrelated stream; aurora-wip's hk_device.h:426-429 still lists that as a gap. Could you rebase down to that commit plus its hk_sync_prior cases? We can then run the alias cases on an A18 Pro and an M4 Pro. Happy to do the rebase if that helps.

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