fix(shader): gather a 2D image's image_gather4_l at its LOD #12790
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12790"
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 yinx080 on 2026-10-29T09:14:28Z.
What
image_gather4_lon a 2D image gathered the base level:EmitGatherOpemittedOpImageGatherwithout the instruction's LOD, because SPIR-V gathers take no Lod operand withoutSPV_AMD_texture_gather_bias_lod. Such a gather now picks its level in the shader and fetches the four footprint texels there (EmitTwoDimensionalGatherLod,OpImageFetch). The level follows the sampler: samplers used byimage_gather4_lare specialized on their S# LOD state (MIN_LOD,MAX_LOD,LOD_BIAS,MIP_FILTERnone,CLAMP_X/CLAMP_Y;PipelineSpecialization::GatherLodBase/GatherLodBiasBase, new useSamplerUseGatherLod); λ = lod + bias, raised toMIN_LODand lowered toMAX_LOD, raised to the T#MIN_LODabove the base level (the view's own minimum LOD; images specialized throughGatherImageMinLodBase), clamped to the view's levels in floating point, nearest level with ties down as in Vulkan (ceil(λ + 0.5) - 1). ForMIP_FILTERnone the level is the T#MIN_LODabove the base level rounded down, clamped to the view's levels, so the fetch never reads below the view's minimum LOD. The wrap modes are applied to the footprint asGuestSamplerResourcemaps them. Fetches do no filtering, so integer and unfilterable formats are fine with any guest filter. Images or samplers from a table and the border modes (4, 6) keep the base-level gather.Semantics: RDNA2 ISA, MIMG opcodes (
IMAGE_GATHER4_L: gather 4 single-component elements (2x2) with a user LOD); the 2x2 footprint and its order follow the Vulkan specification, Texel Gathering: i0 = floor(u * width - 0.5), j0 = floor(v * height - 0.5), results (i0, j1), (i1, j1), (i1, j0), (i0, j0); level selection follows Vulkan's LOD operation for a nearest mip filter. Not measured on hardware; the unmeasured parts are indocs/dev/debt/shader.md.Effect on PPSA23276: UE5's Nanite instance and cluster culling tests occlusion with four
image_gather4_lat the HZB mip that covers an object's screen rectangle and takes the minimum. Reading 2x2 texels of mip 0 instead made the test non-conservative: wall panels behind narrow gaps were culled in both the main and the post pass, so the recess in the right wall and part of the end of the first hallway rendered black, as reported in #8587.New execution test
ImageGatherLod: a 16x16 RGBA8 image with five mips,image_gather4_lwith 32 LODs per variant (integers, 0.49/0.5/0.51/1.49/1.5/2.5, negatives, 4294967296.0, +inf, NaN) in twelve variants (clamp to edge, wrap, mirror, bilinear x/y, MIN_LOD 1.25/MAX_LOD 2.75, MIN_LOD = MAX_LOD = 2, LOD_BIAS -0.75, MIP_FILTER none, 8_8_8_8_UINT with a bilinear sampler, T# MIN_LOD 2.5, MIP_FILTER none with T# MIN_LOD 2.5, border modes 6 and 4 on the base-level gather), against the footprint computed on the CPU. The two T# MIN_LOD variants run only on devices withVK_EXT_image_view_min_lod, because without it the texture path refuses such a descriptor, or on the shader-clamp lane a gather at that clamp. Mirror-once coverage is left for thesamplerMirrorClampToEdgefix:GuestSamplerResourcecreatesMIRROR_CLAMP_TO_EDGEwithout that feature, which adds validation errors of its own.Tested
Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 3060 Laptop GPU, driver 592.82, GCC 15.2.0 (WinLibs UCRT).
Rebased onto
main086c0686c8, later merged withmainup to0dd2fffe35.mainnow gives 128 images toShaderInfo::MaxImages, 64 samplers toMaxSamplers, and orders its specialization ranges with a chain ofstatic_asserts inDescriptorBindingBuilder.cppfromImageBasetoImageComponentBase. The gather constants take the free range betweenSamplerLodBiasBase(57728) andFmaskFormatBase(58048):GatherLodBase57792 andGatherLodBiasBase57856 (64 samplers each),GatherImageMinLodBase57920 (128 images, up to 58047). Threestatic_asserts join the chain there. They stay clear ofDeviceSamplerClassBaseat 58368 (#7642).GatherImageShapeBase(58432, 128 images, up to 58559, after #7642's range) holds each gathered image's view level count and base-level extent from the T#. The shader uses them only whereOpImageQueryLevelsorOpImageQuerySizeLodreturns 0, which Mesa's ANV does once a view hasminLodof 1 or more (found by Lucke0051 in the comments). Otherwise the diff is the one reviewed before;SpirvImageEmitter.cppkeeps #9183's 3D gather and this PR's 2D explicit-LOD gather side by side.GatherImageMinLodBasecarries the same T# clamp asMinLodBasefromfe18496c95, but in 1/256 steps and on every device, whereMinLodBaseis a float written only on the shader-clamp lane, so I kept them apart. That lane still refuses a gather at a clamp of a level or more, so the two T# MIN_LOD variants stay skipped withoutVK_EXT_image_view_min_lod.ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, the 31 image gather, sample and table tests (ctest -R '^(agc_driver_image_(gather|sample|texel_status|table|packed)|image_sample_gather)'): 30/31 on this branch at086c0686c8, all twelveImageGatherLodvariants and #9183'sagc_driver_image_gather_volumepass, and both lanes ofagc_driver_image_sample_lod_clamppass. The one failure isagc_driver_image_tableon itsSYNC-HAZARD, which fails onmaintoo. Validation IDs:VUID-VkDeviceCreateInfo-pNext-pNext, andVUID-VkSamplerCreateInfo-addressMode*fromagc_driver_image_gather_volumealone, whose mirror-once sampler is created withoutsamplerMirrorClampToEdge(main's code; this PR creates no samplers).agc_driver_image_gather_lodwithAPS5_NO_IMAGE_VIEW_MIN_LOD=1 APS5_NO_GPL=1(the shader-clamp lane): passes, the two T# MIN_LOD variants skipped.VK_EXT_image_view_min_lodwas run here by forcing the check off; this GPU has the extension. On lavapipe, the same change passed 3/3 in jotitadev's run.python3 tools/check_conventions.py --base origin/main: passed.0dd2fffe35(head1dc5107979), withANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1, no validation layer: the seven gather and shader-memory tests (ctest -R 'gather|^agc_shader_memory') pass on the RTX 3060 and on an AMD Radeon Vega iGPU (driver 31.0.21914.4000), both T# MIN_LOD variants included. The Radeon is wherec1d07e26ff'sOpSModfix was found.0e147f7f57(the query fallback), same settings: the seven tests pass on both GPUs. They also pass with the fallback forced on for every gather, and a forced build with a wrong width field failsagc_driver_image_gather_lod, so the forced runs used the specialized values. Neither GPU returns 0 from the queries, so the ANV case itself is untested here.main9090972b7e(the same diff except the three ids and the asserts) againstmainat that commit, both built the same way:main, 251 compute pipelines on both, cache 563 MiB against 562 MiB, recompile time 3.2-3.4 s on both. The culling samplers keep one LOD state in this scene, so the specialization adds no pipeline here.APS5_PROFILE_GPU=1, last 110 s: 26.1 and 26.6 ms per present against 26.0 and 27.0 onmain, 60.5 presents per 10 s against 58.8-60.2.main. One cluster cull went from 226-237 us to 452-457 us, the other from 272-280 us to 226-228 us; the instance cull (108 us) and the indirect culls are unchanged. I have not separated the extra fetches from the different culling work: with the right mip the culls keep instancesmaindrops, so the later passes get different inputs.main+ #11580 + a local depth-plane fix that goes in its own PR, 300 s): the panels at the far right of the first hallway were black in every shot without this change (60-75 % of the gap region near-black) and render in every shot with it (0 %); near-black share of the whole frame 1.6-1.7 % -> 0.4-0.5 %; frame rate unchanged (55-57 presents per 10 s).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
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T11:24:03Z.
Review: APPROVED
Reviewed — approved
The PR merges cleanly onto
mainand builds. The newImageGatherLodtest passes with the validation layer loaded and noVUID-lines, and it fails onmain's production code with the error the description quotes. The neighbouring gather and sample tests pass on both trees. I found nothing blocking. Two small follow-ups are below.What I ran
8502ef15f7557f7972c066f5b24e07ee6e5ee9bamain:ba5b5330b37724bca4b99f30faab504653635a04mainwith the head merged in using--no-ff(no conflicts), in a clean worktree.The changed test file only adds a new test, so the negative-control tree is
main's production code with the new test added. It was also themainbaseline for the other 13 tests.Results
maindocs/dev/debt/shader.mdauto-merged)git diff --checkcheck_conventions.py --base origin/maindebt-length, see Non-blocking)mainproduction code + new testagc_driver_image_gather_lodfails, the rest passVUID-linesmainwas not found but was requested by env var VK_INSTANCE_LAYERSVK_LAYER_KHRONOS_validation13 times (merged) and 14 times (main)agc_driver_image_gather_lod0.44–0.72 sMerged tree
mainproduction code with the new testcheck_conventions.py
Negative control
I restored
Resources.hpp,DescriptorBindingBuilder.cpp,ShaderInfoCollector.cpp,PipelineSpecialization.hppandSpirvImageEmitter.cppfromorigin/mainand kept the new test.agc_driver_image_gather_lodthen failed on its first non-zero LOD: thread 1, LOD 1, read 108 (mip 0) where 113 (mip 1) was expected. The author reports the same message. After I put the merged files back, the test passed again.Findings
Blocking
None.
Non-blocking
The debt entry is inaccurate about 1D images and leaves out 2D arrays.
docs/dev/debt/shader.md:213(line 212 on the head) says thatimage_gather4_l"on 1D, 3D or cube images" still gathers the base level. Two parts of that do not match the code:image_gather4_ldoes not fall back to a base-level gather. It is refused:SpirvImageEmitter.cpp:1437-1439callsctx.Fail(... "has an unsupported 1D gather variant")wheneverRdnaImageSampleFlagLevelZerois not set.SpirvImageEmitter.cpp:1481requiresdimension == RdnaImageDimension::Dim2D. Soimage_gather4_lon a 2D array also keeps the base-level gather, and the entry does not mention that case.This matters because a reader of the debt file would expect 1D titles to render wrong rather than abort, and would not look for 2D-array HZB reads. Suggested fix: write "on 2D array, 3D or cube images", and say that 1D explicit-LOD gathers throw. Shortening the entry at the same time would also clear the
debt-lengthwarning (1186 characters against a limit of 1000).The graphics-pipeline-library prebuild specializes on an all-zero sampler. This is a question about the prebuild path; I did not measure it.
RegistrationResultgives up on shaders whose specialization depends on sampler words (FoldsTexelOffsets), and otherwise materializes the shader with zeroed sampler descriptors. The new block atDescriptorBindingBuilder.cpp:316is not gated on that path. For a fragment shader that usesimage_gather4_l, the prebuild therefore getsGatherLodBase= wrap,MAX_LOD0 andMIP_FILTERnone. With specialization present,Recompiler.cpp:1232builds a specialized module rather than the registration module. A draw with a real sampler therefore gets a different module, so the prebuild looks wasted rather than wrong. If that is the case, addingSamplerUseGatherLodsamplers to the early return next toFoldsTexelOffsetswould avoid the useless prebuild. This only applies wheregraphicsPipelineLibraryis enabled.Other things I checked and found correct:
MIN_LOD/MAX_LODfrom word 1 [23:0] as u4.8,CLAMP_X/CLAMP_Yfrom word 0 [5:0],LOD_BIASfrom word 2 [13:0] as s5.8,MIP_FILTERfrom word 2 [27:26].4 << 24, which reads as unsupported) mean that a sampler-table sampler, or a sampler that never got the constant, keeps the old gather.GatherAddressmatches the address-mode mapping inGuestSamplerResource.cpp, and Vulkan's integer wrap, mirrored-repeat and mirror-clamp-to-edge formulas.GatherLodBase+ 32 =GatherLodBiasBase, and the bias range also has 32 IDs. Both fitShaderInfo::MaxSamplers= 32 without overlapping another range.preparedBindingPlan) and of the result-memo key, so a sampler with a different LOD state cannot reuse a stale specialization.UnnormalizedUseReason, becauseSamplerUseGatheris the lower bit.The maintainer's four points from the earlier comment are covered by the test cases (fractional and tie LODs, bilinear, MIN/MAX_LOD, MIP_FILTER none, a large/+inf/NaN LOD, UINT with a bilinear sampler), and all of them pass on this NVIDIA host.
Not verified
MIP_FILTER,LOD_BIAS_SEC, T#MIN_LOD) was not checked on a console.image_gather4_lfrom a pixel shader, or the graphics-pipeline-library path (finding 2 comes from reading the code).image_gather4_lz).Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T15:11:16Z.
Review: CHANGES_REQUESTED
Re-checked — changes still requested
The new commit
813217f0b5raises the fetched level to the T#MIN_LOD, keeps table images and samplers on the base-level gather at build time, and adds three test variants. One of those variants makesagc_driver_image_gather_lodlog three newVUID-validation errors. The production code that raises them is already onmain, but AGENTS.md asks that a GPU change add no newVUID-errors.What changed since my last review
899ae3d1a.git range-diffshows the two commits I reviewed are unchanged (5f2c39f214→f68dbf0702,8502ef15f7→9d29fb18fe).813217f0b5"fix(shader): keep an explicit-LOD gather's fetch at the view's minimum LOD". It does five things:GatherImageMinLodBasespecialization: the T#MIN_LODaboveBASE_LEVEL, set per image inDescriptorBindingBuilder::Prepare;NMin(NMax(λ, MIN_LOD), MAX_LOD), and then raises λ to the image's minimum LOD;table == NoTablefor both the image and the sampler;MIN_LOD2.5, mirror-once (modes 3 and 7), and the border fallback (modes 6 and 4);MIN_LODpoint and reports results, including the newVUID-lines from the mirror-once variant.What I ran
813217f0b543b4a61f5449ed66e0bbea444b40b1main:bb04a4f1ea0175e9e4f149f0359a764d62ff3296mainwith the head merged in using--no-ff(no conflicts), in a clean worktree.Results
git range-diffagainst the previously reviewed commitsmaingit diff --checkcheck_conventions.py --base origin/maindebt-lengthwarning from my last review is gonemainproduction codeImageGatherLodvariants (0.50–0.65 s)mainproduction code + the PR's testagc_driver_image_gather_lodfails, with the message the author quotesVUID-IDs, merged treeVUID-VkSamplerCreateInfo-addressModeU-01079,-addressModeU-parameter,-addressModeV-parameter, all fromagc_driver_image_gather_lodVUID-IDs,mainwas not found but was requested by env var VK_INSTANCE_LAYERSVK_LAYER_KHRONOS_validation10 times (merged) and 11 times (main)agc_driver_image_tableSYNC-lines on this host. The author reports aSYNC-HAZARDfailure on both trees on their machineMerged tree: the new validation errors
mainproduction code with the PR's testPrevious findings
Debt entry: 1D images and 2D arrays. Partly resolved, still open.
debt-length.image_gather4_lis refused atSpirvImageEmitter.cpp:1444-1446(ctx.Fail(... "has an unsupported 1D gather variant")).Dim2Dguard, and the fallback list does not name them.Non-blocking.
The graphics-pipeline-library prebuild specializes on an all-zero sampler. Still open and unanswered; the code is unchanged. The early return at
Recompiler.cpp:2070still covers onlyFoldsTexelOffsets. The new imageMIN_LODconstant takes 0 from zeroed T# words, so the new commit adds nothing to this. Non-blocking question.New findings
Blocking
VUID-validation errors. The variant is atImageGatherLod.cpp:234.agc_driver_image_gather_lodlogsVUID-VkSamplerCreateInfo-addressModeU-01079,-addressModeU-parameterand-addressModeV-parameter.main's log has none of them.main's production code, and the same three IDs appeared. So they come from code that is already onmain, not from the shader change.GuestSamplerResource.cpp:37-41maps clamp modes 3, 5 and 7 toVK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, and nothing undercore/enablessamplerMirrorClampToEdge.VUID-errors. Once this merges,agc_driver_image_gather_lodreportsPassedwhile it logs invalid sampler creation on every run.Depends on. That fix would enablesamplerMirrorClampToEdgeat device creation when it is supported, and refuse or emulate the mode when it is not.Non-blocking
MIP_FILTERnone, the fetch ignores the T#MIN_LOD.SpirvImageEmitter.cpp:823-831raisesnearestto the image's minimum LOD, butleveltakes the constant 0 whenmipNoneis set.MIN_LODis at least 1 aboveBASE_LEVEL, the view gets aminLodthroughChainMinLod. The fourOpImageFetches then read belowminLodInteger. The Vulkan 1.4.330 spec says such values are zero withrobustImageAccess2and undefined otherwise.{MipNone, T# MIN_LOD 640}, theT# MIN_LOD 2.5variant withMIP_FILTERnone. On the merged tree, thread 0 read 0 where any mip level holds a non-zero texel:component 0 is 0, expected 108.mainalso reads 0. The gather section of the spec makesOpImageGatherbelowminLodIntegerundefined as well, so the view does not clamp the old base-level gather either. That also qualifies the premise of oneandonlydean's point 1.Level()returns 0 forMipNonebefore it looks attextureMinLodRaw(ImageGatherLod.cpp:150).mipNone, usefloorof the image's minimum LOD, clamped to the last level, rather than 0. Add that variant to the test, and name the case as unmeasured in the debt entry. If the console's behaviour forMIP_FILTERnone with a T#MIN_LODis unknown, the debt entry is the place to say so.Other things I checked in the new commit and found correct:
EffectiveMinLodgives the view an absoluteMIN_LOD, or none whenMIN_LOD <= BASE_LEVEL·256. The constant is the same value rebased to the view (MIN_LOD - BASE_LEVEL·256, else 0), andOpImageFetch'sLodis view-relative.BASE_LEVEL + nearestis at least the view'sminLodInteger, becauseceil(λ + 0.5) - 1 >= floor(λ).EffectiveMinLod's cap atlastLevelmatches the shader's clamp tolevels - 1.GatherImageMinLodBase+ 64 (ShaderInfo::MaxImages) does not overlap another specialization range. The dedupe on equal constants is safe because only this loop writes those IDs, and each value depends on the image alone.Not verified
MIN_LODclamp and of the mirror-once modes is unmeasured, as the debt entry says.agc_driver_image_tableSYNC-HAZARD: the test passed on both trees here.To get this to a good state
VUID-errors: land thesamplerMirrorClampToEdgefix first and list it underDepends on, or drop the mirror-once variant from this PR.MIN_LODto theMIP_FILTERnone branch as well, and add a variant for it.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T15:50:15Z.
Review: APPROVED
Re-checked — approved
The new commit
01b2319b7ddrops the mirror-once variant, fetchesMIP_FILTERnone at the floor of the T#MIN_LOD, keeps gather-LOD shaders out of the pipeline-library prebuild and corrects the debt entry. The focused tests now pass on the merged tree with noVUID-lines.What changed since my last review
01b2319b7d"fix(shader): fetch an explicit-LOD gather with MIP_FILTER none at the view's minimum level". It changes 4 files, +9/−7:SpirvImageEmitter.cpp: forMIP_FILTERnone the level is nowfloor(imageMinLod), clamped to[0, levels - 1], instead of 0.Recompiler.cpp:RegistrationResultreturnsnullptrfor a shader with aSamplerUseGatherLodsampler, as well as forFoldsTexelOffsets.ImageGatherLod.cpp: removes the mirror-once variant, addsMIP_FILTER none, T# MIN_LOD 2.5, and updates the referenceLevel()to match.docs/dev/debt/shader.md: rewrites the entry.What I ran
01b2319b7dc07947ed5bf1a3005e31da622d0410main:bb04a4f1ea0175e9e4f149f0359a764d62ff3296, the samemainas last time.mainwith the head merged in using--no-ff(no conflicts), in a clean worktree.Results
maingit diff --checkcheck_conventions.py --base origin/mainagc_driver_recorder_testsagc_driver_image_gather_lodpassed in 1.30 s and printedimage 2D explicit-LOD gather tests passedagc_pipeline_library*tests, merged treeVUID-IDs, merged treeVUID-IDs,mainproduction codewas not found but was requested by env var VK_INSTANCE_LAYERSVK_LAYER_KHRONOS_validation10 times (merged) and 11 times (main)mainproduction code + the PR's testagc_driver_image_gather_lodfails:clamp to edge, point: thread 1 (LOD 1.000000, level 1) component 0 is 108, expected 113agc_driver_image_tableSYNC-lines on this hostNegative control
I restored
SpirvImageEmitter.cppfrom813217f0b5, the commit I reviewed last time, and kept the new test. The new variant fails:Output
With all of
main's production code, the test fails on its first variant, as it did last time.Previous findings
VUID-errors from the mirror-once variant (blocking): Resolved. The variant and its two constants are gone fromImageGatherLod.cpp. The merged-tree log has noVUID-lines, and neither hasmain's. The author plans to add the variant back with thesamplerMirrorClampToEdgefix.MIP_FILTERnone ignored the T#MIN_LOD: Resolved. SeeSpirvImageEmitter.cpp:831-834.imageMinLodis the view-relative constant,MIN_LOD - BASE_LEVEL·256, or 0.BASE_LEVEL + floor(imageMinLod), capped at the last level, equals the view'sminLodInteger, so the fetch no longer reads below it.ImageGatherLod.cpp:149matches, because every variant usesBASE_LEVEL0.shader.md:214now says thatimage_gather4_lthrows on 1D images. It lists 2D arrays among the base-level gathers, and namesMIP_FILTERnone with a T#MIN_LODas unverified.Recompiler.cpp:2070now returnsnullptrfor any sampler withSamplerUseGatherLod, so those shaders get no zero-sampler registration module. The sixagc_pipeline_library*tests pass. None of them contains animage_gather4_lshader, so the new condition itself is not exercised.New findings
Blocking
None.
Non-blocking
Parts of the PR description no longer match the code. Each of these could be updated:
Whatstill says "base level forMIP_FILTERnone".MIP_FILTER none, T# MIN_LOD 2.5variant.Testedstill describes the mirror-onceVkSamplerCreateInfoIDs.The 15:29 UTC comment does have the current results.
Not verified
MIP_FILTERnone combined with a T#MIN_LODis unmeasured. The debt entry says so.image_gather4_lshader through the pipeline-library registration path.agc_driver_image_tableSYNC-HAZARD: the test passed on both trees here.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-31T03:19:04Z.
Review: COMMENTED
Linux lavapipe run of head
01b2319b7d:agc_driver_image_gather_lodfails on any device withoutVK_EXT_image_view_min_lod, and lavapipe (CI'slinuxdevice) is one of them. Thelinuxjob is skipped for this head, and the runs posted so far are on NVIDIA and AMD, so no report shows it yet.Setup: i7-8700, Ubuntu 26.04, GCC 15.2, Release, lavapipe (Mesa 26.0.3, LLVM 21.1.8),
ANYPS5_NO_SHADER_CACHE=1. Runs on the head alone and on the head merged--no-ffontomain2a1ae91175, 3 runs each:Cause. The two
T# MIN_LOD 2.5variants put a T# minimum LOD on the image. Without the extension,main's texture path refuses that descriptor (Texture.cpp,Require(context.imageViewMinLod, ...)) before the gather runs. The test has no skip for that, so the whole test fails on the first of the two variants. MoltenVK has noVK_EXT_image_view_min_lodeither.Fix I checked: run the two variants only when the device has the extension, through the same test accessor #12662 uses:
With it,
agc_driver_image_gather_lodpasses 3/3 on lavapipe, on the head alone and merged ontomain. The other variants, including border modes, still run there. Devices that have the extension run the same cases as before.Also: this PR and #12662 conflict in
PipelineSpecialization.hpp. #12662 also rejects gathers at a T# clamp of one level or more in its shader lane, which is the lane MoltenVK uses. I haven't checked how these two variants behave with both PRs applied.GPUs tested: lavapipe (Mesa 26.0.3, Linux).
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:54:38Z.
Review: COMMENTED
The semantics are carefully argued. The part I would want measured is the cost on the shader side:
image_gather4_lare now specialized on their S# LOD state (MIN_LOD,MAX_LOD,LOD_BIAS,MIP_FILTER,CLAMP_X/CLAMP_Y) and images on the T#MIN_LOD. Each distinct sampler or T# state used by a gather becomes its own pipeline/shader variant. For UE5 Nanite culling, which gathers the HZB at many mip levels with whichever samplers the title binds, how many extra variants does PPSA23276 compile per frame, and what is the effect on shader-cache size and first-hit compile time? Please attach a count from a run with the change againstmain.OpImageGatherwith a LOD computation, four clamped coordinate computations and fourOpImageFetchplus the wrap-mode handling. For a culling shader that issues four gathers per instance, that is a lot more ALU per invocation than the single hardware gather. Do you have the dispatch time of the Nanite culling pass before and after, fromtools/trace_digest.pyon the same scene?Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T19:49:11Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
This pull request does not merge cleanly into
main(c955a63d3d): head 3a6f2133f2639bfea717f921c3998e44446529c6 conflicts incore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/PipelineSpecialization.hppdocs/dev/debt/shader.mdPlease rebase it onto current
main. I will review the change once it merges cleanly.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T11:38:16Z.
Review: CHANGES_REQUESTED
Re-checked — changes still requested
There is one new commit,
ed711db0e0, which runs the T#MIN_LODvariants only when the device hasVK_EXT_image_view_min_lod. The PR was also rebased onto4f41f4c375, which moved the three gather specialization ids. The test commit is fine, but the moved ids now overlap for sampler indices 32–63.What changed since my last review
ed711db0e0(test only).ImageGatherLod.cppreadsgraphicsContext().imageViewMinLodthrough aVulkanDeviceTestAccessaccessor. When the extension is missing, it skips the twoT# MIN_LOD 2.5variants and prints that it did. This is the change jotitadev checked on lavapipe.main4f41f4c375.GatherLodBase,GatherLodBiasBaseandGatherImageMinLodBasemoved from 57536/57568/57600 to 57664/57696/57728, becausemainnow uses 57536 and 57600. Commits 1–4 are otherwise unchanged; I compared them with delta.patch.MIP_FILTERnone with a T#MIN_LOD, the current variant list, the skip, and the performance numbers CnRJay asked for.What I ran
Head
ed711db0e04ad91314a1bf86d401cefad583e463,main4f41f4c375f5abb487dbd184fbc150f31994d762, merged with--no-ffinto tree053d856db5, in a clean worktree. Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6). This device has noVK_EXT_image_view_min_lod.git diff --checkcheck_conventions.pymainagc_driver_image_gather_lod, merged tree, validation layerT# MIN_LOD cases skipped, the device has no VK_EXT_image_view_min_lod, the layer was inserted, and the log has noVUID-linesagc_driver_native_depth_uniform_planesreportsVUID-vkCmdDispatch-groupCountX-00386, but the baseline never ran that test. I reran it withmain's production files: the same VUID appears 8 times there too. It is not from this PRNegative control
I restored the PR's six production files from
mainand kept the new test. The test fails on its first variant:Output
With the merged files restored, the test passes again, and
git status --porcelainis empty.Previous findings
MIP_FILTERnone level as the T#MIN_LODabove the base level, rounded down. The variant list namesMIP_FILTER none, T# MIN_LOD 2.5, and the mirror-onceVkSamplerCreateInfoIDs are gone.New findings
Blocking
bb04a4f1ea,ShaderInfo::MaxSamplerswas 32. Commit12b89239c7("raise the sampler and sampled-pair limits past the 32-bit sampler masks") raised it to 64, atShaderInfo.hpp:16. The rebase kept the 32-wide spacing atPipelineSpecialization.hpp:53-55.GatherLodBase + 32= 57696 =GatherLodBiasBase + 0, andGatherLodBiasBase + 32= 57728 =GatherImageMinLodBase + 0.SpirvModule::SpecializationConstantreturns the already-declared constant for a known id. So inSpirvImageEmitter.cpp:879-880, sampler 32's state word and sampler 0's bias share oneOpSpecConstant, and the second declaration's default is lost.DescriptorBindingBuilder.cpp:406-407and:415push two entries with the same id and different values. The duplicate check at line 416 only drops entries whose id and value are both equal.GatherLodBase57664,GatherLodBiasBase57728,GatherImageMinLodBase57792). Add astatic_assertthat ties each range width toShaderInfo::MaxSamplers/MaxImages, where both headers are visible (for example inDescriptorBindingBuilder.cpp).Non-blocking
None.
Not verified
MIN_LODvariants were skipped here, because lavapipe lacksVK_EXT_image_view_min_lod. They ran on devices that have it only in the author's and others' reports (RTX 3060 Laptop, RX 9070 XT, RX 9060 XT); those results are author-reported.To get this to a good state
MaxSamplersand moveGatherImageMinLodBaseafter them, with astatic_assertper range.agc_driver_image_gather_lodwith the validation layer.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T17:51:16Z.
Review: APPROVED
Re-checked — approved
One new commit,
702dee4ae3, makes each explicit-LOD gather sampler range 64 ids wide. It movesGatherLodBase,GatherLodBiasBaseandGatherImageMinLodBaseto 57856, 57920 and 57984, and adds astatic_assertfor each range inDescriptorBindingBuilder.cpp. This resolves the id collision for samplers 32–63.What changed since my last review
702dee4ae3, which touches two files:PipelineSpecialization.hpp:53-55: the three bases are nowGatherLodBase57856,GatherLodBiasBase57920 andGatherImageMinLodBase57984. Each sampler range is 64 wide, and the image range has room for 128 images.DescriptorBindingBuilder.cpp:22-25: fourstatic_asserts chainMinLodBase + MaxImages→ the two sampler ranges (+ MaxSamplerseach) →GatherImageMinLodBase + MaxImages≤ImageComponentBase.=).main1e658521a0, nothing else uses 57856–58111: the named bases end atMinLodBase57600 + 64, and the next isImageComponentBase65536.DescriptorIndexwith stride 128 from 16384 is used only for smallkindvalues.What I ran
Head
702dee4ae314719b94b117193022dcab7750ed14,main1e658521a0a599872612bb91949311e2956b5283, merged with--no-ffinto tree166f09675b, in a clean worktree. Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6). This device has noVK_EXT_image_view_min_lod.git diff --checkcheck_conventions.pymainVUID-agc_driver_image_gather_lod, with the validation layerVUID-lines, and it printedT# MIN_LOD cases skipped, the device has no VK_EXT_image_view_min_lodDescriptorBindingBuilder.cpp:23:79: error: static assertion failedgit status --porcelainis emptyNegative control
This commit adds or changes no test. The previous review's control still applies: with the PR's production files restored from
main,agc_driver_image_gather_lodfails on its first variant. For the new code, I put the sampler range back to 32 wide, and the newstatic_assertstopped the build as intended.Previous findings
GatherLodBase + 63= 57919, just belowGatherLodBiasBase(57920).GatherLodBiasBase + 63= 57983, just belowGatherImageMinLodBase(57984).GatherImageMinLodBase + 63= 58047, far below 65536.ShaderInfo::MaxSamplersandMaxImages(both 64 onmain), and I confirmed that they fire on a 32-wide range.New findings
Blocking
None.
Non-blocking
None.
Not verified
MIN_LODvariants were skipped here, because lavapipe has noVK_EXT_image_view_min_lod. Results on devices that have it (RTX 3060 Laptop, RX 9070 XT, RX 9060 XT) are author- or contributor-reported.mainis in this tree. As the author says, whichever of this PR and #10489 lands second has to chain its range to the other's.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T20:37:09Z.
Review: APPROVED
Re-checked — approved
The branch was rebased onto
main086c0686c8after #9183 landed. Both 2D and 3D gather branches stay inEmitGatherOp, and the firststatic_assertnow starts fromVolumeGatherBase. Checks pass, the negative control fails, and the PR adds no new validation IDs.What changed since my last review
main086c0686c8, which now has #9183 (VolumeGatherBase57664,EmitVolumeGatherLz).GatherLodBase57856,GatherLodBiasBase57920,GatherImageMinLodBase57984.DescriptorBindingBuilder.cpp:22: the first assert is nowVolumeGatherBase + MaxImages <= GatherLodBase. This is 57664 + 64 = 57728 ≤ 57856.SpirvImageEmitter.cpp:1695-1702: #9183's 3D branch returns before the 2D explicit-LOD branch at lines 1739-1753, and the two don't interact.EmitTwoDimensionalGatherLodis identical to what I reviewed before.Dim2D.delta.patchagrees: commits 4 and 5 are=, and the other changes are context lines and the id lines above.What I ran
Head
48e75dd9d096d738f9318d49329ad050081e4b09,main086c0686c8adff3ee648fdbe34e0b0b647e1d511, merged with--no-ffinto treebe2973f389, in a clean worktree. Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6). This device has noVK_EXT_image_view_min_lod.git diff --checkcheck_conventions.pymainVUID-s:agc_driver_image_gather_volume, which was not in the older baseline (see below)agc_driver_image_gather_lod, with the validation layerVUID-lines, and the T#MIN_LODcases were skipped (no extension)agc_driver_image_gather_volume, with the validation layerVUID-VkSamplerCreateInfo-addressMode*IDsmain's production filesgather_lodfails.gather_volumepasses and logs the same fourVUID-sgit status --porcelainis emptyNegative control output (main's production files)
The script's validation baseline is
main1e658521a0, which predates #9183, so it markedagc_driver_image_gather_volumeas "test not run on main". With this PR's production files reverted to086c0686c8, the test logs the same four IDs. They come frommain's mirror-once sampler created withoutsamplerMirrorClampToEdge, as the author says, and do not count against this PR.Previous findings
VolumeGatherBase(57664–57727). The four asserts compile on the merged tree.New findings
Blocking
None.
Non-blocking
docs/dev/debt/shader.md:252lists "3D and cube images" among those that "still gather the base level". Onmainsince #9183, though, a 3D gather without theLZflag fails compilation with "has an unsupported 3D gather variant" (SpirvImageEmitter.cpp:1594-1597onmain;SpirvImageEmitter.cpp:1695-1698in the merged tree). So a 3Dimage_gather4_lthrows; it does not gather the base level. Suggested fix: drop "3D" from the base-level list, and end the entry with "on 1D and 3D imagesimage_gather4_lthrows".Not verified
MIN_LODvariants were skipped, because lavapipe has noVK_EXT_image_view_min_lod. Results on devices that have it are author- or contributor-reported, and the contributor runs were on earlier heads.mainis in this tree.Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T11:50:27Z.
Review: COMMENTED
Ran
7c07be9686merged onmain302864d48con Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 621) and an Intel iGPU (driver 101.70xx), withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Khronos validation layer 1.4.368),ctest -R '^agc_driver_image_gather' -V.The new
agc_driver_image_gather_lodfails on the Intel iGPU, in both runs, with the same message:mainagc_driver_image_gather_lod)one_dimensional,one_dimensional_array,volume) pass on both GPUs with the change.maincontrol on NVIDIA isn't usable, because the machine slept during it.was not found but was requested by env var VK_INSTANCE_LAYERS, and no log on either side has aVUID-, so the Intel result is a wrong value without a validation error.MIN_LOD2.5 one: at an explicit LOD 0 the clamp should select level 2, and on this driver component 0 reads 0 there. The description's run is on an RTX 3060 only, so this is the first run on a non-NVIDIA driver.AI-assisted: yes.