Skip to content

Mirror Aurora Mesa #103, #105–#108: virtio guest, cube samples, render area, UBO record loads, cached variants - #22

Open
DjDeveloperr wants to merge 13 commits into
integration/aurorafrom
mirror/jg-mesa-20261029
Open

DjDeveloperr wants to merge 13 commits into
integration/aurorafrom
mirror/jg-mesa-20261029

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Collaborator

Mirror of five Aurora Mesa PRs by jgoyvaerts, merged into aurora-silicon/mesa aurora-wip (now e292b25). The ten commits are cherry-picked with -x onto integration/aurora 672657e.

Not mirrored, because both are held on aurora: #104 (X11 WSI foreign server) and #109 (serialize G17P queues).

The only conflicts were in src/asahi/vulkan/meson.build, where the PRs each add a test executable at the same place. All four are kept: vulkan-render-area, vulkan-ubo-record-loop, vulkan-sample-variant-cache and vulkan-border-emulation-cache. The change set is line-for-line the same as the tested tree.

Testing:

  • J700 (Neo, G17P), kernel int1029, on aurora-wip 4f26943 with all five:
    • Regression gate PASS. Targeted CTS 4687 pass, 0 fail.
    • CTS renderpasses, ubo, robustness, texture, glsl, synchronization and synchronization2: 202,039 pass, 0 fail.
    • Multisample and sampler-border cases with the shader cache on, a cold run and then a warm run: 489 pass, 0 fail each.
    • The four hardware tests above: all PASS.
    • Same-boot perf A/B against aurora-wip: no regressions; render.light 3–13% faster.
  • This branch on integration/aurora: host build with -Dwerror=true, and meson --suite asahi --suite vulkan 78/78.

agx_create_context tested its flags against PIPE_CONTEXT_PRIORITY_*, the
screen's capability bits, not the PIPE_CONTEXT_*_PRIORITY creation
flags. PIPE_CONTEXT_PREFER_THREADED (1 << 3), which the GL state
tracker sets on nearly every context, is PIPE_CONTEXT_PRIORITY_REALTIME,
so since "asahi: create HIGH-priority contexts as HIGH" every threaded
GL context asked the kernel for HIGH priority.

On bare metal the kernel refuses that without CAP_SYS_NICE and the
context falls back to MEDIUM. Under virtio (muvm) the refused queue
creation never completes: vdrm_host_sync() spins in sched_yield()
forever, so every GL client in the guest (Wine's explorer.exe, glxinfo)
hangs in context creation. Compute-only contexts also came out LOW,
since PIPE_CONTEXT_COMPUTE_ONLY is PIPE_CONTEXT_PRIORITY_LOW.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit b5ccd72)
…first

Under virtio, binds and other ccmds are buffered in the guest until the
next flush, but bo_free closed the GEM handle with a bare GEM_CLOSE that
goes to the host at once. When the closed BO had a VM_BIND still queued,
the host saw the close first and its kernel rejected the bind with
ENOENT. In CS2 under FEX this happened within seconds of creating the
device and ended in VK_ERROR_DEVICE_LOST.

vdrm_bo_close() flushes the buffered ccmds before closing.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit f5685b5)
Under virtio, submits, binds and allocations are asynchronous ccmds: when
the host kernel rejects one (a lost VM rejects every later submit) the
guest never learns of it. The application keeps submitting and waits on
fences that never signal, instead of getting VK_ERROR_DEVICE_LOST.

The host counts the commands it failed in asahi_shmem::async_error. Read
it in hk_check_status and report the device lost once it moves.

The VM status mirror and query are asahi ioctls that can't be issued on
the virtgpu fd, so skip them under virtio.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit 14532ca)
Under virtio every BO is created shareable, so every BO is an external
object of the host VM, and the host kernel's cost per submit grows with
their number. CS2 held 13k-17k BOs, about 10.5k of them idle 128 KiB
command-pool BOs.

Keep the BO cache's idle trim running under virtio, and cap idle Main
command BOs per pool at HK_CMD_POOL_BO_MAX there instead of
HK_G17P_CMD_POOL_MAIN_BO_MAX.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit 2ebb59e)
A cube sample with a register level or bias capped the fragment shader's
register file at 112 halves, so that the level, staged by
agx3_tex_stage_cube_lod in a seven-bit field, could not land above half
127. That cap applied to every value of the shader: material shaders that
sample an environment cube with a computed level or bias spilled, though
they fit in the file. Counter-Strike 2 has 48 such fragment shaders.

The staging form encodes the high bit of the CEM face (f16 bit 7), so only
the level needs a low register. Keep that one value below half 128
through texture_gpr, as the coordinate already is, and give plain cube
samples with a register level or bias the same budget as other cube
samples. Cube arrays stage their face in a seven-bit field and bias with
minimum places a packed word above the allocation; both keep the cap.

Counter-Strike 2's 1969 shaders (fossilize-replay of a capture): spills
11272 -> 9958, fills 15910 -> 13995, scratch -21%, instructions -0.4%;
48 shaders change, none for the worse, typically from ~34 spills to none.
A fragment shader with 18 live vec4s around a register-LOD cube sample
goes from 245 instructions with 7 spills to 226 without, 8-11% faster
per pass, with an identical image; its CEM face lands above half 128.
A third of the dEQP-VK cube texture function, filtering, mipmap and
gather cases (807) give the same results as before.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit 5704b52)
The packer computed every cube sample's CEM in one shared scratch above
the register allocation. A cube array stages CEM's face in a seven-bit
PACK_SMPIR field, so for cube arrays that scratch had to sit below half
128, and the whole register file of any shader sampling a cube array was
capped at 112 halves. Counter-Strike 2's cube-array material shaders hold
far more than that live and spilled heavily.

Before RA, give each cube sample (but bias with minimum and scalar-
coordinate samples) a seventh source: an undefined four-word vector,
defined right before it, which emits no code. RA places it clear of every
value live at the sample, and below half 128 for a cube array
(texture_gpr); the packer computes that sample's CEM there. Cube arrays
lose the 112-half cap and plain cubes the eight halves reserved above the
allocation. Samples with their own scratch get a 176-half budget, which
keeps a heavy shader at 576 threads: Counter-Strike 2's cube-array
material passes ran faster at 177 halves than with the full 184 (185
halves, 512 threads), though they spill more there.

Counter-Strike 2's 1969 shaders (fossilize-replay of a capture): spills
9958 -> 3510, fills 13995 -> 4313, scratch -57%, instructions -1.9%; 181
shaders change, none with more instructions. The 90 cube-array shaders
go from ~240 to ~100 spills at 177 instead of 121 halves (832 -> 576
threads); 91 plain-cube shaders each free eight halves, several gaining
an occupancy step. In de_dust2 (two runs each, kernel job traces), the
median of the 50 longest render jobs fell from 1.60-1.65 ms to
1.00-1.22 ms; average fps is within run-to-run noise.

dEQP-VK cube and cube-array texture, shadow and GLSL texture-function
cases (2615, all cube arrays and a quarter of the rest): same results as
before, 586 pass, 0 fail. A cube-array pressure bench renders the same
image. test-agx3-cube-scratch checks the pass.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit c6f52b5)
A render covers the whole attachment even when its render area is a small
rectangle of it. Draws stay inside the render area and the tiles past its
bottom-right corner keep their contents, so give the render only the
extent up to that corner: the GPU then never visits those tiles.

User interfaces render this way: in the Counter-Strike 2 main menu
(2560x1440) about 1600 render passes a second draw one element into a
full-screen target with a render area under a tenth of it. At that size
the per-pass cost is dominated by fixed overhead and the frame rate moves
within noise; the tile walk shows on larger attachments. On the M4 Pro a
pass with a 128x64 area on an 8192x8192 attachment takes 24 us instead of
125 us (37 against 180 us when the memory clock is low).

Secondary command buffers that continue a render pass do not know the
area; their streams keep the full extent.

tests/vulkan_render_area.c checks that pixels inside and outside small
areas, including areas on the right and bottom edges, end up right (with
a clamp to half the area it fails), and prints the 8192x8192 timing.
dEQP-VK render-area cases and a sample of the renderpass attachment cases
give the same results as before.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit b2ddff3)
A shader that reads members of one record of a uniform buffer array as
separate expressions, as Counter-Strike 2's depth-of-field gather does
with taps[i].xy, taps[i].z and taps[i].w in a 48-tap loop, got a load
for each: once lowered to global loads, their 64-bit addresses
(base + u2u64(48 + 16 * i), + u2u64(56 + 16 * i), ...) no longer show
that they are the same record, so the vectorizer could not merge them.

Before lowering, make component reads of a uniform buffer vector loads
of the whole vector and mark the loads reorderable, as load_ubo always
is: a uniform buffer does not change during a draw or dispatch. CSE then
merges the repeated loads, and the vectorizer, run on the deref offsets,
merges neighbouring ones.

tests/vulkan_ubo_record_loop.c renders that loop twice, once as the game
writes it and once with each record read once, checks that the images
are identical and prints the cost ratio: on the M4 Pro 1.31 before this
change (69 against 64 instructions), 1.18 after (65 against 64). The
rest is the loop-invariant scale read, which stays in the loop: the game
does not enable robustBufferAccess, so it may not be read speculatively.
In a benchmark of the game's shader at 2560x1440 with 48 taps a pass
goes from 5.35 to 4.85 ms. A sample of dEQP-VK.ubo, robustness2 uniform
and binding_model uniform buffer cases (4002) passes as before.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit a044f6b)
A G17P fragment shader whose coverage or exports depend on the sample
count (sample shading, discard or sample-mask writes, a read of the sample
count), compiled without a fixed count -- a dynamic rasterization sample
count or a pipeline library -- builds its multisample variant at the first
draw that needs it (hk_fs_build_sample_variant). By then its shader object
is already in the pipeline cache, which holds the variant as absent, so
every process compiled the variant again, on the thread recording the
draw.

Under FEX that is a stall in the middle of play: Counter-Strike 2 renders
with 2x MSAA and alpha-tested materials, and on a warm cache it still
compiled about 40 such variants per de_dust2 session, 2.2 s of compiling
that landed in its 200-400 ms in-game freezes.

Store each variant that a draw builds in the disk cache, keyed by the
saved source and compile inputs that already describe it (NIR, key,
flags, robustness, features, set layouts) and the sample count, in the
form hk_api_shader_serialize() writes a variant, inline-blend NIR
included. A draw looks the variant up there before compiling it; an entry
that does not deserialize cleanly is dropped and the variant compiled.

On a warm cache Counter-Strike 2 now compiles 5 such variants per session
instead of 40 (0.7 s instead of 2.2 s). tests/vulkan_sample_variant_cache.c
records the same 2x MSAA draw from two instances on an empty cache
directory: 2.4 ms then 0.4 ms with the variant loaded, the same image;
without this change 2.2 ms then 1.5-1.9 ms, compiling it again. 535
dEQP-VK multisample, alpha-to-coverage and dynamic-sample-count cases
(monolithic, library and shader-object pipelines), run twice on a fresh
cache directory: same results as before, cold and warm, 276 pass, 0 fail.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit d4b5dce)
Whether G17P shaders emulate custom border colours is decided at the
program's first sampler that needs it. That sampler lands at a different
point among the pipelines a program compiles on worker threads each time
it runs. Shaders compiled before it leave the emulation out and get an
emulating twin, built on the draw that first binds them (hk_border_twin)
and never cached; and the shader cache key carries the setting, so a
shader compiled on one side of the sampler in one run and on the other
side in the next missed the cache.

Counter-Strike 2 appears to hit this: on a warm cache, each de_dust2
session still compiled ~35 shaders outside hk_compile_shaders() at draw
time (~1.5 s; the path twins take) and recompiled ~45 shader objects
that the previous session had compiled, and those compiles fell in its
300-900 ms in-game freezes. That they are twins and border-key misses is
inferred from the compile paths and timing, not yet confirmed in
Counter-Strike 2 with this change.

When the first sampler of a process turns the emulation on, put a marker
for the process in the disk cache; when a later run of it opens the
cache, start with the emulation on. Its shaders then compile with the
emulation from the start, under one stable cache key, and need no twins.
The emulation is a branch on the bound sampler (agx_nir_lower_custom_border),
so it is correct with or without a custom border. Programs that never
create such a sampler are unaffected.

tests/vulkan_border_emulation_cache.c creates a pipeline, then a sampler
with a custom border colour, then records a draw across the border, from
two instances on an empty cache directory: 2.2-2.5 ms then 0.27-0.29 ms
to record, the same image with the custom border colour; without this
change 2.6-2.8 ms then 1.3-1.4 ms, building the twin again. 876
dEQP-VK sampler border-colour, custom-border and clamp-to-border cases,
run twice on a fresh cache directory: same results as before, cold and
warm, 280 pass, 0 fail.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
(cherry picked from commit 9deef48)
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with both previous findings addressed and no new actionable issues found.

Summary

This PR mirrors Asahi guest fixes and improvements to cube sampling, render areas, uniform-buffer reads, and shader caching.

  • Virtio guest contexts use the requested priority and report host errors.
  • Eligible AGX3B cube samples leave more registers available to shaders.
  • Small Vulkan render areas limit how many tiles the driver visits.
  • Vulkan shaders merge component reads from one uniform-buffer record.
  • Warm shader caches supply multisample variants before a draw needs them.
  • Warm shader caches remember programs that need border-colour emulation.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Create an empty cache] --> B[Create the first Vulkan instance]
  B --> C[Record commands and count shader builds]
  C --> D[Submit and read the image]
  D --> E[Destroy the instance and flush cache writes]
  E --> F[Repeat with the warm cache]
  F --> G[Require no shader builds and the same image]
Loading

Reviews (3) · Last reviewed commit: "hk: count compiles, not milliseconds, in..." · Reviewed by Greptile

.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
.pNext = &(VkPhysicalDeviceVulkan13Features){
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES,
.dynamicRendering = VK_TRUE,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Test uses a disabled feature

vulkan-sample-variant-cache calls vkCmdPipelineBarrier2 without enabling synchronization2. This raises Vulkan validation errors unrelated to shader caching, even when the image is correct. Set .synchronization2 = VK_TRUE in VkPhysicalDeviceVulkan13Features.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: vulkan-sample-variant-cache now sets .synchronization2 = VK_TRUE (aurora-silicon#125, f715c9f9), cherry-picked here as be3e990e. I checked the other new tests in this PR: vulkan-border-emulation-cache, vulkan-render-area and vulkan-ubo-record-loop already enable it.

It builds with -Dwerror=true and the host suites pass. It has not run on G17P yet because the Neo is offline, so I'm leaving this thread open until it has.

Comment on lines +326 to +328
if (warm * 4 > cold) {
fprintf(stderr, "FAIL: the second recording compiled the variant again\n");
return 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Timing can misreport cache misses

Both new cache tests claim compilation happened if one warm recording takes more than a quarter of one cold recording. CPU scheduling, clock changes, and disk reads can break that ratio even on a cache hit, causing false regression failures. Check a compile or cache-hit counter instead, and keep elapsed time as diagnostic output rather than a pass/fail condition. The same issue appears in vulkan_border_emulation_cache.c.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in 03e88e43 (from aurora-silicon#125, 32437aea). Both tests now count the shaders compiled while the command buffer is recorded, and elapsed time is only printed.

The count uses an existing compiler flag; the driver is unchanged. With AGX_MESA_DEBUG=shaderdb, agx_compile_shader_nir() prints one <STAGE> shader: line for each shader that is not internal. Prologs, epilogs and meta shaders come from nir_builder_init_simple_shader(), which marks them internal. The multisample variant (hk_compile_fs_sample_variant()) and the border twin (hk_border_twin()) are compiled from the application's NIR, so each prints a line. A disk-cache load compiles nothing. The new vulkan_compile_count.h captures stderr around the recording. The first recording must compile at least one shader and the second must compile none.

Two other signals don't fit:

  • MESA_SHADER_CACHE_SHOW_STATS prints only per-process hit/miss totals at disk_cache_destroy(). It can't isolate the recording, and a driver that skipped the variant lookup entirely would still show zero warm misses.
  • Pipeline creation feedback covers pipeline creation, not shaders built at bind or draw time.

Hardware verification is still pending because the Neo is offline. That run has to confirm the warm recording compiles nothing. One open point is whether the G17P inline-blend program, which also prints, hits its own disk-cache entry on the warm border run; if it doesn't, the test will report that compile. The run will also include a negative control (#108's cache paths disabled, and the cache wiped between recordings) to show the count fails on a miss. I'm leaving this thread open until then.

agx3_reserve_cube_scratch gives an AGX3B cube sample a seventh source,
the four-word vector the packer computes CEM in. The validator modelled
that source like any other 32-bit texture source, two halves wide, so a
build with assertions rejected every shader with such a sample ("source
6, expected width 2, got width 8 ... Invalid vectors after cube-array
scratch") and exited. That broke the gallium blit tests on debug builds.
Release builds skip validation, and RA and the packer already size the
scratch from its vector, so the generated code is unchanged.

Read source 6 of a seven-source texture sample as eight halves, and
validate a cube and a cube-array sample before and after the pass in the
cube scratch test.

(cherry picked from commit 4222ab4)
@DjDeveloperr

Copy link
Copy Markdown
Collaborator Author

The two asahi-g17p-gallium-blit failures came from the validator, not from wrong code. #105's per-sample CEM scratch is a four-word seventh texture source, and agx_read_registers read it as two halves, so builds with assertions rejected every cube sample that has one. RA and the packer already size the scratch correctly, and release output is unchanged.

The fix is aurora-silicon#110 (merged as 14b6b0c), now cherry-picked onto this branch as c818781. It adds a unit test that reproduces the CI error without the fix. All of agx_tests passes in a debugoptimized + assertions build (503, 1 skipped). Waiting for CI to confirm.

@DjDeveloperr

Copy link
Copy Markdown
Collaborator Author

CI is green with the validator fix: 156/156 meson tests on both arches, including asahi-g17p-gallium-blit and asahi-g17p-gallium-blit-encode.

DjDeveloperr and others added 2 commits October 31, 2026 01:20
The test records vkCmdPipelineBarrier2 but created its device without the
synchronization2 feature, which the validation layers report as an error
unrelated to what the test checks. Enable it, as
vulkan-border-emulation-cache and the other new tests already do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit f715c9f)
vulkan-sample-variant-cache and vulkan-border-emulation-cache decided that
the second, warm-cache recording compiled a shader when it took more than
a quarter of the first. Scheduling and clock changes can push a recording
that loads from the cache past that ratio, so the tests could fail with
nothing wrong.

Count the shaders compiled while recording instead. With
AGX_MESA_DEBUG=shaderdb, agx_compile_shader_nir() prints one statistics
line for every shader that is not internal. Prologs, epilogs and meta
shaders are built with nir_builder_init_simple_shader(), which marks them
internal. A multisample variant, a border-emulating twin or a G17P
inline-blend program built at draw time comes from the application's
shader and prints a line; loading one from the disk cache prints nothing.
The tests capture stderr around the recording (vulkan_compile_count.h)
and require at least one compile in the first recording and none in the
second. Recording times are still printed, for information.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 32437ae)
@DjDeveloperr

Copy link
Copy Markdown
Collaborator Author

Follow-up for the two Greptile threads, cherry-picked from aurora-silicon#125 (draft):

  • be3e990: vulkan-sample-variant-cache enables synchronization2.
  • 03e88e4: both cache tests now pass or fail on the number of shaders compiled while recording (AGX_MESA_DEBUG=shaderdb), not on timing. Test-only; no driver change.

On this branch, in the linux-build VM: gcc 16 -Dwerror=true build with 0 warnings; meson --suite asahi --suite vulkan 110/110.

These are hardware tests, and they have not run on the Neo (G17P) yet because it is offline. The cold/warm runs and a negative control are pending, and both threads stay open until they are done.

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