Repository navigation
borealis: lazily emulate VK_EXT_image_view_min_lod on AGX3 - #1261
Merged
Merged
Conversation
On AGX3, hk_nir_lower_image_view_min_lod() currently lowers every non-buffer texture operation in every shader unconditionally to load the view's minLod from the texture descriptor, converting plain tex ops into txb with lod_bias_min_agx, clamping txl into register-LOD fmax(lod, min_lod), and wrapping txf/txf_ms/tg4 with per-channel out-of-bounds zero selects. Mirror Borealis's existing lazy custom-border emulation architecture (pdev->border_emulation / hk_border_twin()): - Track pdev->min_lod_emulation (persisted in the disk cache per process and hashed into hk_shader_cache_key()), flipping 0 -> 1 in hk_image_view_init() the first time an application creates a VkImageView with minLod > baseMipLevel. - Until then, defer hk_nir_lower_image_view_min_lod() and texture lowering in hk_lower_nir_ex(), serialize the post-descriptor / pre-texture NIR into obj->min_lod_source, and compile the primary shader without image-view minLod emulation. - Once pdev->min_lod_emulation flips, lazily compile hk_min_lod_twin() from min_lod_source using hk_nir_lower_image_view_min_lod_post_desc() (via nir_load_from_texture_handle_agx and aligned 32-bit descriptor loads) and swap bound graphics/compute stages transparently. - Preserve full 2x2 composition with border_emulation (cloning min_lod_source onto border twins built before min_lod_emulation flips) and bump the shader binary version for the new variant_flags4 byte. Signed-off-by: DjDeveloperr <hey@djdev.me>
Add vulkan-min-lod-emulation-cache, the image-view minLod counterpart of vulkan-border-emulation-cache. It creates its pipeline before its first view with minLod above the base level, so the fragment shader is compiled without the emulation and the first draw must build the emulating twin. A second instance on the same disk cache must compile the shader with the emulation from the start and build nothing while recording. The texture's three levels are cleared to different colours and the draw magnifies it, so a shader that ignores the view's minLod reads level 0 and the test fails. The dEQP-VK image_view_min_lod cases create their views before their pipelines and only run with the hk_image_view_min_lod option, so they do not reach the twin. Signed-off-by: DjDeveloperr <hey@djdev.me>
#1245 changed when hk_lower_nir() may take the post-lower preprocessing (can_post_lower). This branch moved texture lowering and that preprocessing into hk_lower_nir_post_tex(), so the new condition now feeds the hk_lower_nir_post_tex() call at the end of hk_lower_nir_ex(); lowered_tex is still checked inside it. Signed-off-by: DjDeveloperr <hey@djdev.me>
Author
|
Exact-head row at
The merge resolution: #1245's new |
|
Exact-head
|
satchlj
approved these changes
Nov 28, 2026
satchlj
left a comment
Member
There was a problem hiding this comment.
Reviewed 4b9511d4bbd3 and verified on Apple M5 Max (J775c, G17C B1):
- Mirrors the existing lazy
border_emulationtwin mechanism cleanly forVK_EXT_image_view_min_lod, bumps the shader binary cache version across chip generations, and handles both activation orders safely: activatingborder_emulationfirst clonesobj->min_lod_sourceonto the border twin (hk_compile_twin()), and activatingmin_lod_emulationfirst compiles the minLod twin withtwin_of != NULL, which keeps custom-border emulation enabled athk_shader.c:9196. - Built with
-Dbuildtype=release -Db_ndebug=false(includingvulkan-min-lod-emulation-cache) and ranMESA_SHADER_CACHE_DISABLE=1 MALLOC_PERTURB_=42 meson test -C build --suite asahi: 337/337 PASS (0fail). - Live Borealis cold-cache VK CTS (
MESA_SHADER_CACHE_DISABLE=1):dEQP-VK.api.smoke.*8/8 PASS,dEQP-VK.texture.explicit_lod.2d.sizes.128x128_*32/32 PASS, zero GPU faults indmesg.
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.
What: Borealis emulates
VK_EXT_image_view_min_lodin every shader that samples, for every vkd3d-proton game (the driconf turns the extension on for that engine), even though most D3D12 games never create a view with a minimum LOD. This leaves the emulation out until the process creates its first view withminLodabove its base level, then swaps in emulating twins at bind time, the way custom-border emulation already works. GTA V Enhanced at 3024x1964 on the M5 Pro gets 3.7 % more FPS.Tested: J714s (M5 Pro, G17S) at
679956d08d61: GCC release and Clang assert--suite asahipass, min_lod and custom-border VK CTS 0 fail, new twin test passes, GTA V A/B +3.7 % with 0 GPU faults.Risk: two-way · M5 and Neo (the chips where the lazy path applies); other GPUs are unchanged.
Not yet: a J700 (G17P) row. It conflicts with #1245 at the end of
hk_lower_nir(); whichever merges second needs a small rebase.Details
The emulation turns plain samples into biased samples that load the view's min LOD from the descriptor, clamps explicit LODs, and wraps texel fetches and gathers with out-of-bounds selects. That costs every texture operation of every shader in a vkd3d-proton game.
How it works:
hk_physical_device::min_lod_emulationis set the first timehk_image_view_init()sees a view with a relative minimum LOD above zero. It is remembered per process in the disk cache, likeborder_emulation, so the next run compiles with the emulation from the start. The pipeline cache key carries it.hk_lower_nir_ex()stops before texture lowering. The shader keeps that NIR asmin_lod_source, then finishes texture lowering without the emulation (hk_lower_nir_post_tex()).min_lod_sourceonce the flag is set builds its twin from that NIR withhk_nir_lower_image_view_min_lod_post_desc(). That variant reads the view's minimum LOD through the lowered texture handle (nir_load_from_texture_handle_agx). Graphics stages are re-checked at draw flush and compute at dispatch, as for border twins.min_lod_source, so the two emulations compose either way round.Known limit, the same as for border twins: a command buffer recorded before the first such view keeps the shaders it bound. A view created afterwards and reached through an update-after-bind descriptor in that command buffer would be sampled without its minimum LOD.
Evidence
Hardware: J714s (Apple M5 Pro, G17S B1), kernel
7.3.0-m5-cdirect16. Baseaurora-wip41857fdecfd4, candidate679956d08d61(this branch), both fetched exactly and built warm on the M5. The runtime kits were isolated throughVK_DRIVER_FILES; system Mesa was untouched.meson test --suite asahi-Db_ndebug=false)--suite asahi*min_lod*(114 cases) withhk_image_view_min_lod=truevulkan-min-lod-emulation-cache(new)vulkan-border-emulation-cachehk-vulkan-shader-binary-root-Werroron the objects of every changed C filehk_cmd_draw.cstops only on three-Winitializer-overridesalready inaurora-wip(lines 5675-5685, not touched here)The dEQP-VK
image_view_min_lodcases create their views before their pipelines, so they test the shaders compiled with the emulation from the start.vulkan-min-lod-emulation-cachecreates the pipeline first. That makes the draw build the twin, and the second instance on the same cache must compile nothing. The texture's three levels are cleared to different colours, so a shader that ignores the minimum LOD reads the wrong level.GTA V Enhanced,
-benchmark, 3024x1964 native (ResScalingType 0), VSync off, fullscreen, vkd3d-proton from Proton 11.0 (ARM64), isolated shader cache per run. Order A1 B1 B2 A2, same boot, FPS per benchmark pass:Base 56.13 FPS, PR 58.21 FPS: +3.71 %. Every pass gains 3.4-4.1 %, and the spread within each arm is under 0.4 %. The GPU had 0 faults, 0 crashed or quarantined contexts, and 0 kernel errors in every run. The only failed unit was
tailscaled, which was already failed before the slot.