Repository navigation
Mirror Aurora Mesa #103, #105–#108: virtio guest, cube samples, render area, UBO record loads, cached variants - #22
DjDeveloperr wants to merge 13 commits into
Conversation
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)
[Medium impact] The PR appears safe to merge, with both previous findings addressed and no new actionable issues found. SummaryThis PR mirrors Asahi guest fixes and improvements to cube sampling, render areas, uniform-buffer reads, and shader caching.
|
| .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, | ||
| .pNext = &(VkPhysicalDeviceVulkan13Features){ | ||
| .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES, | ||
| .dynamicRendering = VK_TRUE, |
There was a problem hiding this comment.
There was a problem hiding this comment.
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.
| if (warm * 4 > cold) { | ||
| fprintf(stderr, "FAIL: the second recording compiled the variant again\n"); | ||
| return 1; |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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_STATSprints only per-process hit/miss totals atdisk_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)
|
The two 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 |
|
CI is green with the validator fix: 156/156 meson tests on both arches, including |
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)
|
Follow-up for the two Greptile threads, cherry-picked from aurora-silicon#125 (draft):
On this branch, in the linux-build VM: gcc 16 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. |
Mirror of five Aurora Mesa PRs by jgoyvaerts, merged into aurora-silicon/mesa aurora-wip (now e292b25). The ten commits are cherry-picked with
-xonto 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:
-Dwerror=true, and meson--suite asahi --suite vulkan78/78.