Skip to content

hk: read occlusion results only after their submission completes - #57

Merged
RyanTheTide merged 1 commit into
aurora-silicon:aurora-wipfrom
jgoyvaerts:pr/hk-oq-after-submit
Oct 24, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:aurora-wipfrom
jgoyvaerts:pr/hk-oq-after-submit

Conversation

@jgoyvaerts

Copy link
Copy Markdown

hk: read occlusion results only after their submission completes.

A render's occlusion counts reach memory with its end-of-render cache maintenance, but the availability word is written by a post-graphics compute stream the firmware may start before that maintenance. vkGetQueryPoolResults could then see availability 1 with a count of 0 that became right shortly after: a 64-pass repro with one query per pass hit it in about 3% of submissions (every wrong value late, none lost), and the CTS occlusion_query get_* cases flaked with results such as 3,0,0.

The kernel signals a submission only after the maintenance of all its renders, which is what the gallium driver already relies on when it reads query results after the batch fence. So each occlusion query records, at submission, the queue timeline point that signals the submission ending it, and the CPU treats the query as available only once that point has signalled: VK_QUERY_RESULT_WAIT_BIT waits for it (in bounded steps, so a lost device is noticed), otherwise VK_NOT_READY. A host reset forgets the point; the point and its syncobj are published so a concurrent reader never pairs one submission's syncobj with another's point. vkCmdCopyQueryPoolResults keeps ordering on the availability word on the GPU. Queries ended in secondary command buffers are covered because they are replayed into the primary.

Hardware tested on: Apple MacBook Pro (16-inch, M4 Pro, 2024), J616s / T6040, macOS 26.6.2 firmware, kernel 7.3.0-m4.14 (aurora integration/aurora 1aa2857509d + #406, #408-#413).

How tested: Built as a system Mesa (aurora's mesa-aurora options: asahi, zink, softpipe Gallium; asahi Vulkan) and run on the M4 Pro with deqp-runner (vk-gl-cts main mustpass), 6 jobs. A 64-pass program with one occlusion query per pass, reading every result on the CPU right after the queue goes idle: 118 late reads (availability 1, count 0 that is correct shortly after) without this change, 0 with it; results copied with vkCmdCopyQueryPoolResults were never wrong, so only CPU reads need the change. Under CPU load an 18-case occlusion_query group repeated 2,000 times gave 10 non-pass results before (late counts). query_pool.occlusion_query.* (441 cases) passes three times in a row with this change (434 pass, 7 skip); the CTS hits the race rarely on this machine, the same three runs also pass without it.

🤖 Generated with Claude Code

A render's occlusion counts reach memory with its end-of-render cache
maintenance. The availability word is written by a post-graphics
compute stream that the firmware starts once the render's fragment work
is done, which can be before that maintenance. vkGetQueryPoolResults
then saw availability 1 and a count of 0 that was right after the queue
went idle: a 64-pass repro with one query per pass hit it in ~3% of
submissions, every wrong value late and none lost, and the CTS
occlusion_query get_* cases flaked with results such as 3,0,0.

The kernel signals a submission only after the maintenance of all its
renders, which is also what the gallium driver relies on when it reads
query results after the batch fence. Record, at submission, the queue
timeline point that signals the submission ending each occlusion query,
and on the CPU treat the query as available only once that point has
signalled: wait for it with VK_QUERY_RESULT_WAIT_BIT, report
VK_NOT_READY otherwise. A host reset forgets the point.

vkCmdCopyQueryPoolResults still orders its reads by the availability
word on the GPU.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Assisted-by: LLM
@RyanTheTide
RyanTheTide merged commit e41de31 into aurora-silicon:aurora-wip Oct 24, 2026
RyanTheTide added a commit that referenced this pull request Oct 24, 2026
hk: keep #57's occlusion fix to the native AGX3 path and wait once per submission
@jgoyvaerts
jgoyvaerts deleted the pr/hk-oq-after-submit branch October 24, 2026 16:34
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