graphics: fall back to base-level remap when VK_EXT_image_view_min_lod is missing #1314
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1314
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1314/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@wuboo on GitHub · 2026-10-09 16:07 UTC · original
wuboo:pr/texture-min-lod-fallback→main· +405 −11 · 16 files · 3 commits · closed without mergingProblem
f38d738e("Honor PS5 texture minimum LOD for streamed mip chains") hands the T# MinLod to the image view throughVK_EXT_image_view_min_lod, andvulkanWindow.cpprejects every device that lacks the extension. MoltenVK (macOS)does not expose it. Where the clamp cannot reach the view, a streamed texture whose T# says MinLod = 1024 (the first
four mips are not resident yet) is sampled from mips 0..3, i.e. from memory the game never filled. On the sand level
this shows up as confetti and yellow patches on the terrain.
Change
GraphicContext::has_view_min_lodsays whether theclamp can go to the view natively (then nothing changes);
min_lod_remapis its negation.base_level + ceil(MinLod / 256)(never pastthe last level) with the level count reduced accordingly (
MapMinLodToBaseLevelinminLodView.h; the shift isMinLodShiftingraphics/shader/minLodShift.h). Storage and Dynamic-mip images are left alone (Dynamic appliesMinLod in the shader).
image_get_resinfofrom the T# (extent at BASE_LEVEL, LAST_LEVEL - BASE_LEVEL + 1levels) whatever MinLod says, while a shifted view reports a smaller extent and fewer levels. When the host remaps,
the shader specialisation carries
MinLodResinfo(computed from the T# with the same shift) andQueryDimensionsemits those constants instead of
OpImageQueryLevels/ the view size. Programs without a size query and imageswithout MinLod are not affected (no new permutations).
Tests
min_lod_view(CPU): shift table (0 / 256 / 1024 / 1100 / cap), host mapping == recompiler shift, RESINFO forbase 0 / last 11 / MinLod 1024 on 2048x2048 -> 2048x2048, 12 levels.
min_lod_view_mutant_floor(floors the fraction),_no_cap(no cap at the last level),_resinfo(reports what the shifted view reports: 128x128 / 8 levels).shader_cfg/TestMinLodResinfoCorrection: compilesimage_get_resinfowith MinLod 1024, 2048x2048, 11 levels;without the remap the SPIR-V queries the view (
OpImageQueryLevels), with it the query is gone and 2048 / 11 areconstants; MinLod 0 is untouched.
ctest, macOS Release x86_64, same environment for both trees,KYTY_VS_LANE_FROM_INDEX=0for the run:origin/main (
4c8fc53a) 35 pass / 19 skipped (no Vulkan loader or hidden Vulkan window in the test environment) /0 fail; this branch 39 pass / 19 skipped / 0 fail. The only difference is the four new
min_lod_view*tests.In-game results (macOS / MoltenVK 1.4.2, sand level)
Measured on a bench build with temporary counters and an on/off switch (neither is part of this diff).
With it: 0 dropped, 1 720 939 remapped (a second run: 1 683 560 / 1 758 173).
smooth sand, dunes, and the stack with the "!" marker and the ship as in the reference frame for that level.
In the space/tunnel scene the moon was missing a quarter of its texture early on without the fix (same cause);
with it the scene is otherwise unchanged apart from asteroid positions. Menu frames are identical.
frames/s); the ratio to the run without it is 0.989 and 1.002.
Limitations
most one level blurrier than the hardware's clamped trilinear blend. MinLod was integral (1024) in all observed
content, so the image is exact there.
image_get_lodstill returns the LOD relative to the new base.image_sample_*_cl(separate, unrelated).@coderabbitai[bot] on GitHub · 2026-10-09 16:16 UTC · original · edited 2026-10-19 09:32 UTC
📝 Walkthrough
Vulkan device setup now treats native image-view MinLod support as optional. When the feature is unavailable, sampled non-dynamic image views can map MinLod into their base level. The remapping state flows into shader resource specialization, which supplies RESINFO metadata to dimension queries. Tests cover MinLod mapping, RESINFO correction, generated SPIR-V, and mutant variants.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: 🔵 Low · up to
04bfdThe MinLod fallback is a bounded change for devices without the native extension. The array-texture size-query edge case and its weak test coverage should be addressed before or soon after merge.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 41.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 29 functions across 14 files. (1 skipped: 1 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-10-09 16:16 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
d8c04f40-0f6f-4b56-9b6f-1a2bebde46d1📥 Commits
Reviewing files that changed from the base of the PR and between
4c8fc53a85and ed104a3efc6aa681348529fd3bcfb154d001e05d.📒 Files selected for processing (16)
CMakeLists.txtsrc/graphics/host_gpu/graphicContext.hsrc/graphics/host_gpu/renderer/image/imageView.cppsrc/graphics/host_gpu/renderer/image/minLodView.hsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cppsrc/graphics/presentation/window/vulkanWindow.cppsrc/graphics/shader/minLodShift.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.hsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cppsrc/graphics/shader/recompiler/ir/passes/SrtWalker.htests/MinLodViewTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@ -316,1 +316,3 @@if (info.multisampled == 0u) {// T# MinLod folded into the view base level: the view answers for the shifted base, RESINFO must not.const auto& resinfo = ctx.state.program.info.images.at(mem.resource).min_lod_resinfo;if (info.multisampled == 0u && resinfo.Active()) {@coderabbitai[bot] on GitHub · 2026-10-09 16:16 UTC · original · edited 2026-10-10 03:42 UTC
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Query a valid view level for array layer counts.
When
resinfo.Active()and a guest LOD exceeds the remapped view’slevel_count, the earlierOpImageQuerySizeLodhas an undefined result. This branch replaces the spatial components but retains the queried array layer count. Query level zero for the array layer count on this path; keep the guest LOD for the corrected spatial extents. (docs.vulkan.org)✅ Confirmed as addressed by @wuboo
@ -316,1 +316,3 @@if (info.multisampled == 0u) {// T# MinLod folded into the view base level: the view answers for the shifted base, RESINFO must not.const auto& resinfo = ctx.state.program.info.images.at(mem.resource).min_lod_resinfo;if (info.multisampled == 0u && resinfo.Active()) {@wuboo on GitHub · 2026-10-10 03:42 UTC · original
Good catch. For array views the layer count in RESINFO no longer comes from the OpImageQuerySizeLod at the guest LOD (undefined when that LOD exceeds the shifted view's levels); it is now taken from a separate LOD 0 query, while the spatial extents still come from the T#. Fixed in 5febbdb7 (new commit, with a 2D-array regression test), and the branch is rebased onto the current main.
@ -316,1 +316,3 @@if (info.multisampled == 0u) {// T# MinLod folded into the view base level: the view answers for the shifted base, RESINFO must not.const auto& resinfo = ctx.state.program.info.images.at(mem.resource).min_lod_resinfo;if (info.multisampled == 0u && resinfo.Active()) {@coderabbitai[bot] on GitHub · 2026-10-10 03:42 UTC · original
@wubooThanks for the fix. The separate LOD 0 query provides the array layer count without using the undefined guest-LOD result. The spatial extents still use the T# metadata.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@theantipopau on GitHub · 2026-10-18 23:01 UTC · original
@wuboo I ran a trial merge of this branch (60a320fc, base
d7974dc7) into current upstream/main to map the conflicts blocking this PR, since my #1547 waits on it. Good news: out of 16 touched files, everything auto-merges except a single hunk in src/graphics/presentation/window/vulkanWindow.cpp (~line 510).Both sides append one conditional feature struct to the support-query pNext chain at the same spot (after the image-atomic-int64 link, before getFeatures2): this branch adds supported_min_lod, main has since added supported_barycentric (from #1590). The resolution is to keep both blocks:
(Order between the two links is irrelevant; each just prepends.) The remaining auto-merged files most worth a second look after rebasing are descriptors.cpp, imageView.cpp, and the vulkanWindow regions around the request chain, since main moved nearby code. Happy to re-test my #1547 on top once this lands.
@wuboo on GitHub · 2026-10-19 00:48 UTC · original
@theantipopau thanks for mapping that, it saved time. Rebased onto current main (
099de8de) and resolved the vulkanWindow.cpp hunk exactly as you suggested, keeping both the min_lod and barycentric links in the query chain. I also re-checked descriptors.cpp, imageView.cpp and the device feature chain: no double pNext links, no use-before-declaration, and the remap only applies to non-storage, non-dynamic views. The build is clean and ctest shows no new failures against main. MinLodViewTests passes and its mutants are caught. Feel free to re-test #1547 on top.@ -15380,0 +15413,4 @@const auto make_shader = [](uint32_t dim) {return std::array<uint32_t, 7>{EncodeMimg0(0x0e, 0x9, false, dim),EncodeMimg1(5, 0, 0, 1), // image_get_resinfo v5 (width, mip count)@coderabbitai[bot] on GitHub · 2026-10-19 00:55 UTC · original
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Set a LOD beyond the shifted view’s level count.
The query reads its LOD from
v1, but this shader never setsv1. The array case therefore does not establish the past-the-view-levels condition described at Line 15405. Setv1to a guest LOD that is valid in the 11-level T# and beyond the shifted view’s levels. Then check that the additional size query uses LOD 0, rather than checking only the number of queries.@ -15380,0 +15422,4 @@};};const auto shader_2d = make_shader(1u);const auto shader_2d_array = make_shader(3u);@coderabbitai[bot] on GitHub · 2026-10-19 00:55 UTC · original
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Encode the 2D-array instruction dimension.
make_shader(3u)encodes a cube dimension. The existingTestNewShaderRecompilerImageViewDimensionsfixture uses5ufor a 2D-array MIMG instruction. Use5uhere so the array assertion tests the intended instruction, even if descriptor specialization selects an array view.@coderabbitai[bot] on GitHub · 2026-10-19 00:55 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
8d895d1f-823e-4e17-bc77-3d262d9b53e7📥 Commits
Reviewing files that changed from the base of the PR and between 60a320fc2f3c0091c0b63b7d692d1b689a52b6b2 and 04bfddeea665ef831fe23537eb2b3208b2f96eef.
📒 Files selected for processing: 9
src/graphics/host_gpu/graphicContext.hsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cppsrc/graphics/presentation/window/vulkanWindow.cppsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.hsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
Pull request closed