fix(agc): bind a T# minimum LOD through an S# that holds the LOD at 0 #12980
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12980"
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?
Imported from boykopovar/AnyPS5. Originally posted by Gonic0 on 2026-10-29T18:56:54Z.
What
Builds on #12662. Until it merges, this branch carries its commits; only
4e2a028e43is new here.#12662 applies a T#'s MIN_LOD clamp in the shader when
VK_EXT_image_view_min_lodis missing (MoltenVK). It throws when a paired S# has a MAX_LOD below the clamp, because the shader'sMinLodwould then exceed the sampler's maximum. That includes an S# with no mip filter, which holds the LOD at 0.For such an S# the view clamp has a defined result. The sampler clamps λ to 0, so the texel is magnified and the level is
d' = max(level_base + 0, level_base + c). That level is rounded to the nearest one with no mip filter, or blended with a linear one. An S# with MIN_LOD = MAX_LOD = c and the same mip filter reaches the same level. The only difference is filter choice: λ = c > 0 picks the minification filter, where the view clamp picks the magnification filter, so the variant is used only when the two filters are the same.Driver:
applyAnisoOverridebecomesapplySamplerVariants. For each S# that holds the LOD at 0 (HoldsLodAtZero: not unnormalized, and no mip filter or MAX_LOD 0) and is paired with an image with a clamp, it bindsPinnedLodSamplerWords:The shader constant from #12662 stays the clamp, so
lodmin = lodmax = c.Builder: such an S# no longer throws the MAX_LOD, filter and bias rejections, since the variant makes them hold. It still throws in these cases:
An image with a single-level view may share the S#, because the variant still reads its only level with the same filter.
The view clamp's filter for such an S# also differs between vendors. On an AMD RX 9070 XT (amdvlk), the image-view lane sampled a T# MIN_LOD of 3.0 through an S# with bilinear magnification and point minification with the point filter (run); the spec and the NVIDIA run use the magnification filter. The console's gfx1013 is unmeasured, so the shader lane throws there instead of picking one.
#12662's existing rejections stay:
image_get_lod, gathers at a clamp of one level or more, run-time S#s, and the emulated samples.PPSA21564 (ASTRO BOT 01.007.000) needs this. A pixel shader samples one image with a T# MIN_LOD of 3.0 through two S#s: one mipmapped, and one that is all zeros, so it has no mip filter. The all-zero S# also samples a single-level image.
An instruction
_clclamp above the T# clamp through such an S# makeslodmin > lodmaxhere, which Vulkan leaves undefined. The view clamp is undefined there too (_cl> 0 against MAX_LOD 0). Before this change the shader lane threw instead.Tested
Apple M5 Pro, macOS 27.2, MoltenVK from Vulkan SDK 1.4.363, x86-64 Release under Rosetta 2.
mainalone does not build on macOS. I ran the tests in a tree with the open macOS port PRs; this commit's changes are identical there.agc_driver_image_sample_lod_clamp_testspasses in the shader lane, withVK_LAYER_KHRONOS_validationloaded and noVUID-messages. A new wave32 program, assembled withllvm-mc(gfx1013), samples one T# through a mipmapped S# and through a second S#, and a second T# through the second S#. These pass in both lanes:In the shader lane only: a linear mip filter with MAX_LOD 0 at a fractional clamp (1.25), checked as a blend of levels 1 and 2 on the level, x and y channels. The view clamp may use
minLodIntegerthere, so the image-view lane cannot assert one result. There is also a rejection with an exact message: a second mipmapped T# with another clamp.Negative controls, each of which fails a test:
One-off experiments, not asserted by a test: no filter check, a filter check on point against bilinear only, and one on anisotropy only each let an S# with differing filters through.
PPSA21564 01.007.000: the shader no longer throws. Together with #12724, the game ran for the full 900 s of the run, through the intro after the title, where it previously stopped at about 400 s.
Not tested on Linux, Windows, lavapipe, or a device with
VK_EXT_image_view_min_lod.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code