fix(shader): gather a 2D image's image_gather4_l at its LOD #12790

Merged
yinx080 merged 13 commits from upstream-pr/12790 into main 2026-11-19 09:10:01 +00:00
yinx080 commented 2026-10-29 09:14:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by yinx080 on 2026-10-29T09:14:28Z.


What

image_gather4_l on a 2D image gathered the base level: EmitGatherOp emitted OpImageGather without the instruction's LOD, because SPIR-V gathers take no Lod operand without SPV_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 by image_gather4_l are specialized on their S# LOD state (MIN_LOD, MAX_LOD, LOD_BIAS, MIP_FILTER none, CLAMP_X/CLAMP_Y; PipelineSpecialization::GatherLodBase/GatherLodBiasBase, new use SamplerUseGatherLod); λ = lod + bias, raised to MIN_LOD and lowered to MAX_LOD, raised to the T# MIN_LOD above the base level (the view's own minimum LOD; images specialized through GatherImageMinLodBase), clamped to the view's levels in floating point, nearest level with ties down as in Vulkan (ceil(λ + 0.5) - 1). For MIP_FILTER none the level is the T# MIN_LOD above 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 as GuestSamplerResource maps 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 in docs/dev/debt/shader.md.

Effect on PPSA23276: UE5's Nanite instance and cluster culling tests occlusion with four image_gather4_l at 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_l with 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 with VK_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 the samplerMirrorClampToEdge fix: GuestSamplerResource creates MIRROR_CLAMP_TO_EDGE without 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 main 086c0686c8, later merged with main up to 0dd2fffe35. main now gives 128 images to ShaderInfo::MaxImages, 64 samplers to MaxSamplers, and orders its specialization ranges with a chain of static_asserts in DescriptorBindingBuilder.cpp from ImageBase to ImageComponentBase. The gather constants take the free range between SamplerLodBiasBase (57728) and FmaskFormatBase (58048): GatherLodBase 57792 and GatherLodBiasBase 57856 (64 samplers each), GatherImageMinLodBase 57920 (128 images, up to 58047). Three static_asserts join the chain there. They stay clear of DeviceSamplerClassBase at 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 where OpImageQueryLevels or OpImageQuerySizeLod returns 0, which Mesa's ANV does once a view has minLod of 1 or more (found by Lucke0051 in the comments). Otherwise the diff is the one reviewed before; SpirvImageEmitter.cpp keeps #9183's 3D gather and this PR's 2D explicit-LOD gather side by side. GatherImageMinLodBase carries the same T# clamp as MinLodBase from fe18496c95, but in 1/256 steps and on every device, where MinLodBase is 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 without VK_EXT_image_view_min_lod.

  • With ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_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 at 086c0686c8, all twelve ImageGatherLod variants and #9183's agc_driver_image_gather_volume pass, and both lanes of agc_driver_image_sample_lod_clamp pass. The one failure is agc_driver_image_table on its SYNC-HAZARD, which fails on main too. Validation IDs: VUID-VkDeviceCreateInfo-pNext-pNext, and VUID-VkSamplerCreateInfo-addressMode* from agc_driver_image_gather_volume alone, whose mirror-once sampler is created without samplerMirrorClampToEdge (main's code; this PR creates no samplers).
  • agc_driver_image_gather_lod with APS5_NO_IMAGE_VIEW_MIN_LOD=1 APS5_NO_GPL=1 (the shader-clamp lane): passes, the two T# MIN_LOD variants skipped.
  • The skip without VK_EXT_image_view_min_lod was 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.
  • After the merge with 0dd2fffe35 (head 1dc5107979), with ANYPS5_REQUIRE_VULKAN=1 and ANYPS5_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 where c1d07e26ff's OpSMod fix was found.
  • At 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 fails agc_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.
  • Cost in PPSA23276 (The Exit 8) 01.004.000 at 1080p, first hallway, no input, measured on the previous rebase onto main 9090972b7e (the same diff except the three ids and the asserts) against main at that commit, both built the same way:
    • Variants, 150 s from an empty shader cache: 1,430 and 1,431 shader disk cache writes against 1,430 on 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.
    • GPU time, 180 s with a warm cache, APS5_PROFILE_GPU=1, last 110 s: 26.1 and 26.6 ms per present against 26.0 and 27.0 on main, 60.5 presents per 10 s against 58.8-60.2.
    • Culling dispatches (the 9x1x1 instance cull, the two 1440x1x1 cluster culls and the two indirect culls that sample the 512x512 R16F HZB), per-program GPU timestamps over 50 s, two runs each: 1.06-1.10 ms per frame against 0.91-0.92 ms on 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 instances main drops, so the later passes get different inputs.
  • In-game result (before the rebase, on 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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: PPSA23276 #8587
  • GPUs tested: NVIDIA GeForce RTX 3060 Laptop GPU, driver 592.82, Windows 11 Pro 10.0.26200; AMD Radeon Vega iGPU (device 0x1638), driver 31.0.21914.4000, same machine. Reported in the comments on this PR: AMD Radeon RX 9070 XT on Windows (bunbeans2-arch), AMD Radeon RX 9060 XT on Linux with RADV (RNK123), lavapipe on Linux (jotitadev), NVIDIA RTX 2000 Ada on Linux (TechLevelZero's test run)
  • AI-assisted: yes (Claude Code); the change, the test and the results were reviewed by me

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5065359225 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12790). Originally posted by [yinx080](https://github.com/yinx080) on 2026-10-29T09:14:28Z. --- ### What `image_gather4_l` on a 2D image gathered the base level: `EmitGatherOp` emitted `OpImageGather` without the instruction's LOD, because SPIR-V gathers take no Lod operand without `SPV_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 by `image_gather4_l` are specialized on their S# LOD state (`MIN_LOD`, `MAX_LOD`, `LOD_BIAS`, `MIP_FILTER` none, `CLAMP_X`/`CLAMP_Y`; `PipelineSpecialization::GatherLodBase`/`GatherLodBiasBase`, new use `SamplerUseGatherLod`); λ = lod + bias, raised to `MIN_LOD` and lowered to `MAX_LOD`, raised to the T# `MIN_LOD` above the base level (the view's own minimum LOD; images specialized through `GatherImageMinLodBase`), clamped to the view's levels in floating point, nearest level with ties down as in Vulkan (`ceil(λ + 0.5) - 1`). For `MIP_FILTER` none the level is the T# `MIN_LOD` above 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 as `GuestSamplerResource` maps 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](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf), 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](https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#textures-gather): 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](https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#textures-lod-and-scale-factor) for a nearest mip filter. Not measured on hardware; the unmeasured parts are in `docs/dev/debt/shader.md`. Effect on PPSA23276: UE5's Nanite instance and cluster culling tests occlusion with four `image_gather4_l` at 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_l` with 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 with `VK_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 the `samplerMirrorClampToEdge` fix: `GuestSamplerResource` creates `MIRROR_CLAMP_TO_EDGE` without 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 `main` `086c0686c8`, later merged with `main` up to `0dd2fffe35`. `main` now gives 128 images to `ShaderInfo::MaxImages`, 64 samplers to `MaxSamplers`, and orders its specialization ranges with a chain of `static_assert`s in `DescriptorBindingBuilder.cpp` from `ImageBase` to `ImageComponentBase`. The gather constants take the free range between `SamplerLodBiasBase` (57728) and `FmaskFormatBase` (58048): `GatherLodBase` 57792 and `GatherLodBiasBase` 57856 (64 samplers each), `GatherImageMinLodBase` 57920 (128 images, up to 58047). Three `static_assert`s join the chain there. They stay clear of `DeviceSamplerClassBase` at 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 where `OpImageQueryLevels` or `OpImageQuerySizeLod` returns 0, which Mesa's ANV does once a view has `minLod` of 1 or more (found by Lucke0051 in the comments). Otherwise the diff is the one reviewed before; `SpirvImageEmitter.cpp` keeps #9183's 3D gather and this PR's 2D explicit-LOD gather side by side. `GatherImageMinLodBase` carries the same T# clamp as `MinLodBase` from fe18496c95, but in 1/256 steps and on every device, where `MinLodBase` is 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 without `VK_EXT_image_view_min_lod`. - With `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_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 at `086c0686c8`, all twelve `ImageGatherLod` variants and #9183's `agc_driver_image_gather_volume` pass, and both lanes of `agc_driver_image_sample_lod_clamp` pass. The one failure is `agc_driver_image_table` on its `SYNC-HAZARD`, which fails on `main` too. Validation IDs: `VUID-VkDeviceCreateInfo-pNext-pNext`, and `VUID-VkSamplerCreateInfo-addressMode*` from `agc_driver_image_gather_volume` alone, whose mirror-once sampler is created without `samplerMirrorClampToEdge` (main's code; this PR creates no samplers). - `agc_driver_image_gather_lod` with `APS5_NO_IMAGE_VIEW_MIN_LOD=1 APS5_NO_GPL=1` (the shader-clamp lane): passes, the two T# MIN_LOD variants skipped. - The skip without `VK_EXT_image_view_min_lod` was 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. - After the merge with `0dd2fffe35` (head `1dc5107979`), with `ANYPS5_REQUIRE_VULKAN=1` and `ANYPS5_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 where `c1d07e26ff`'s `OpSMod` fix was found. - At `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 fails `agc_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. - Cost in PPSA23276 (The Exit 8) 01.004.000 at 1080p, first hallway, no input, measured on the previous rebase onto `main` `9090972b7e` (the same diff except the three ids and the asserts) against `main` at that commit, both built the same way: - Variants, 150 s from an empty shader cache: 1,430 and 1,431 shader disk cache writes against 1,430 on `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. - GPU time, 180 s with a warm cache, `APS5_PROFILE_GPU=1`, last 110 s: 26.1 and 26.6 ms per present against 26.0 and 27.0 on `main`, 60.5 presents per 10 s against 58.8-60.2. - Culling dispatches (the 9x1x1 instance cull, the two 1440x1x1 cluster culls and the two indirect culls that sample the 512x512 R16F HZB), per-program GPU timestamps over 50 s, two runs each: 1.06-1.10 ms per frame against 0.91-0.92 ms on `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 instances `main` drops, so the later passes get different inputs. - In-game result (before the rebase, on `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 <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: PPSA23276 #8587 - [x] GPUs tested: NVIDIA GeForce RTX 3060 Laptop GPU, driver 592.82, Windows 11 Pro 10.0.26200; AMD Radeon Vega iGPU (device 0x1638), driver 31.0.21914.4000, same machine. Reported in the comments on this PR: AMD Radeon RX 9070 XT on Windows (bunbeans2-arch), AMD Radeon RX 9060 XT on Linux with RADV (RNK123), lavapipe on Linux (jotitadev), NVIDIA RTX 2000 Ada on Linux (TechLevelZero's test run) - [x] AI-assisted: yes (Claude Code); the change, the test and the results were reviewed by me 🤖 Generated with [Claude Code](https://claude.com/claude-code)
XairRrR commented 2026-10-29 11:24:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T11:24:03Z.

Review: APPROVED


Reviewed — approved

The PR merges cleanly onto main and builds. The new ImageGatherLod test passes with the validation layer loaded and no VUID- lines, and it fails on main'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

  • PR head: 8502ef15f7557f7972c066f5b24e07ee6e5ee9ba
  • main: ba5b5330b37724bca4b99f30faab504653635a04
  • Tree under test: main with the head merged in using --no-ff (no conflicts), in a clean worktree.
  • Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08), Release build with Ninja.
git fetch origin main pull/12790/head:refs/review/12790
git checkout --detach origin/main
git merge --no-ff --no-edit refs/review/12790
git diff --check origin/main...refs/review/12790
python3 tools/check_conventions.py --base origin/main
cmake -S . -B build
cmake --build build -j10 --target \
  agc_driver_image_gather_lod_tests agc_driver_image_gather_one_dimensional_tests \
  agc_driver_image_gather_one_dimensional_array_tests agc_driver_image_packed_horizontal_gather_tests \
  agc_driver_image_sample_lod_clamp_tests agc_driver_image_sample_unnormalized_tests \
  agc_driver_image_sample_shared_sampler_tests agc_driver_image_sample_border_color_tests \
  image_sample_gather_tests agc_driver_image_texel_status_tests agc_driver_image_converted_unorm_tests \
  agc_driver_image_srgb_load_tests agc_driver_image_sint8_tests agc_driver_image_cache_bits_tests
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 \
VK_LOADER_DEBUG=error,warn,layer ctest --test-dir build -j4 -V --output-on-failure -R \
  '^(agc_driver_image_gather_lod|agc_driver_image_gather_one_dimensional|agc_driver_image_gather_one_dimensional_array|agc_driver_image_packed_horizontal_gather|agc_driver_image_sample_border_color|agc_driver_image_sample_lod_clamp|agc_driver_image_sample_shared_sampler|agc_driver_image_sample_unnormalized|image_sample_gather|agc_driver_image_texel_status|agc_driver_image_converted_unorm|agc_driver_image_srgb_load|agc_driver_image_sint8|agc_driver_image_cache_bits)$'
# baseline / negative control: the same build and ctest command after
git checkout origin/main -- <the five changed files under core/shader>

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 the main baseline for the other 13 tests.

Results

Check Result
Merge onto main Clean (docs/dev/debt/shader.md auto-merged)
git diff --check Clean
check_conventions.py --base origin/main 0 errors, 1 warning (debt-length, see Non-blocking)
Build of the 14 test targets (merged tree) OK
Focused tests, merged tree, validation layer 14/14 passed
Focused tests, main production code + new test 13/14; agc_driver_image_gather_lod fails, the rest pass
VUID- lines 0 on the merged tree, 0 on main
was not found but was requested by env var VK_INSTANCE_LAYERS Absent from both logs; the loader logged inserting VK_LAYER_KHRONOS_validation 13 times (merged) and 14 times (main)
Test duration agc_driver_image_gather_lod 0.44–0.72 s
Merged tree
1164: image 2D explicit-LOD gather tests passed
 3/14 Test #1164: agc_driver_image_gather_lod .....................   Passed    0.72 sec
...
100% tests passed out of 14
main production code with the new test
1164: AGC graphics: clamp to edge, point: thread 1 (LOD 1.000000, level 1) component 0 is 108, expected 113
 1/14 Test #1164: agc_driver_image_gather_lod .....................***Failed    0.70 sec
...
93% tests passed, 1 tests failed out of 14
check_conventions.py
docs/dev/debt/shader.md:213: warning: [debt-length] Technical debt entry over 1000 characters: state the gap first (what differs from the console, what is unverified, what throws) and keep only the behaviour it needs: 1186 characters
1 findings, 0 errors

Negative control

I restored Resources.hpp, DescriptorBindingBuilder.cpp, ShaderInfoCollector.cpp, PipelineSpecialization.hpp and SpirvImageEmitter.cpp from origin/main and kept the new test. agc_driver_image_gather_lod then 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

  1. 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 that image_gather4_l "on 1D, 3D or cube images" still gathers the base level. Two parts of that do not match the code:

    • On 1D, 1D-array and remapped-depth-1D images, image_gather4_l does not fall back to a base-level gather. It is refused: SpirvImageEmitter.cpp:1437-1439 calls ctx.Fail(... "has an unsupported 1D gather variant") whenever RdnaImageSampleFlagLevelZero is not set.
    • The new path's guard at SpirvImageEmitter.cpp:1481 requires dimension == RdnaImageDimension::Dim2D. So image_gather4_l on 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-length warning (1186 characters against a limit of 1000).

  2. The graphics-pipeline-library prebuild specializes on an all-zero sampler. This is a question about the prebuild path; I did not measure it. RegistrationResult gives up on shaders whose specialization depends on sampler words (FoldsTexelOffsets), and otherwise materializes the shader with zeroed sampler descriptors. The new block at DescriptorBindingBuilder.cpp:316 is not gated on that path. For a fragment shader that uses image_gather4_l, the prebuild therefore gets GatherLodBase = wrap, MAX_LOD 0 and MIP_FILTER none. With specialization present, Recompiler.cpp:1232 builds 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, adding SamplerUseGatherLod samplers to the early return next to FoldsTexelOffsets would avoid the useless prebuild. This only applies where graphicsPipelineLibrary is enabled.

Other things I checked and found correct:

  • The S# fields are extracted from the right bits: MIN_LOD/MAX_LOD from word 1 [23:0] as u4.8, CLAMP_X/CLAMP_Y from word 0 [5:0], LOD_BIAS from word 2 [13:0] as s5.8, MIP_FILTER from word 2 [27:26].
  • The specialization defaults (4 << 24, which reads as unsupported) mean that a sampler-table sampler, or a sampler that never got the constant, keeps the old gather.
  • GatherAddress matches the address-mode mapping in GuestSamplerResource.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 fit ShaderInfo::MaxSamplers = 32 without overlapping another range.
  • Sampler words are fully part of the binding-plan key (preparedBindingPlan) and of the result-memo key, so a sampler with a different LOD state cannot reuse a stale specialization.
  • With an unnormalized sampler, the gather is still refused through UnnormalizedUseReason, because SamplerUseGather is 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

  • I ran nothing on AMD or Windows. The behaviour the debt entry lists as unmeasured on hardware (tie rounding, linear MIP_FILTER, LOD_BIAS_SEC, T# MIN_LOD) was not checked on a console.
  • I did not run PPSA23276, so the in-game result is the author's.
  • I did not exercise image_gather4_l from a pixel shader, or the graphics-pipeline-library path (finding 2 comes from reading the code).
  • I did not check the textual overlap with #9183 beyond confirming that it is a different feature (3D image_gather4_lz).
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5696885923 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12790#pullrequestreview-5696885923). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T11:24:03Z. **Review:** APPROVED --- # Reviewed — approved The PR merges cleanly onto `main` and builds. The new `ImageGatherLod` test passes with the validation layer loaded and no `VUID-` lines, and it fails on `main`'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 - PR head: `8502ef15f7557f7972c066f5b24e07ee6e5ee9ba` - `main`: `ba5b5330b37724bca4b99f30faab504653635a04` - Tree under test: `main` with the head merged in using `--no-ff` (no conflicts), in a clean worktree. - Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08), Release build with Ninja. ```sh git fetch origin main pull/12790/head:refs/review/12790 git checkout --detach origin/main git merge --no-ff --no-edit refs/review/12790 git diff --check origin/main...refs/review/12790 python3 tools/check_conventions.py --base origin/main cmake -S . -B build cmake --build build -j10 --target \ agc_driver_image_gather_lod_tests agc_driver_image_gather_one_dimensional_tests \ agc_driver_image_gather_one_dimensional_array_tests agc_driver_image_packed_horizontal_gather_tests \ agc_driver_image_sample_lod_clamp_tests agc_driver_image_sample_unnormalized_tests \ agc_driver_image_sample_shared_sampler_tests agc_driver_image_sample_border_color_tests \ image_sample_gather_tests agc_driver_image_texel_status_tests agc_driver_image_converted_unorm_tests \ agc_driver_image_srgb_load_tests agc_driver_image_sint8_tests agc_driver_image_cache_bits_tests VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 \ VK_LOADER_DEBUG=error,warn,layer ctest --test-dir build -j4 -V --output-on-failure -R \ '^(agc_driver_image_gather_lod|agc_driver_image_gather_one_dimensional|agc_driver_image_gather_one_dimensional_array|agc_driver_image_packed_horizontal_gather|agc_driver_image_sample_border_color|agc_driver_image_sample_lod_clamp|agc_driver_image_sample_shared_sampler|agc_driver_image_sample_unnormalized|image_sample_gather|agc_driver_image_texel_status|agc_driver_image_converted_unorm|agc_driver_image_srgb_load|agc_driver_image_sint8|agc_driver_image_cache_bits)$' # baseline / negative control: the same build and ctest command after git checkout origin/main -- <the five changed files under core/shader> ``` 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 the `main` baseline for the other 13 tests. ## Results | Check | Result | |---|---| | Merge onto `main` | Clean (`docs/dev/debt/shader.md` auto-merged) | | `git diff --check` | Clean | | `check_conventions.py --base origin/main` | 0 errors, 1 warning (`debt-length`, see Non-blocking) | | Build of the 14 test targets (merged tree) | OK | | Focused tests, merged tree, validation layer | 14/14 passed | | Focused tests, `main` production code + new test | 13/14; `agc_driver_image_gather_lod` fails, the rest pass | | `VUID-` lines | 0 on the merged tree, 0 on `main` | | `was not found but was requested by env var VK_INSTANCE_LAYERS` | Absent from both logs; the loader logged inserting `VK_LAYER_KHRONOS_validation` 13 times (merged) and 14 times (`main`) | | Test duration | `agc_driver_image_gather_lod` 0.44–0.72 s | <details><summary>Merged tree</summary> ``` 1164: image 2D explicit-LOD gather tests passed 3/14 Test #1164: agc_driver_image_gather_lod ..................... Passed 0.72 sec ... 100% tests passed out of 14 ``` </details> <details><summary><code>main</code> production code with the new test</summary> ``` 1164: AGC graphics: clamp to edge, point: thread 1 (LOD 1.000000, level 1) component 0 is 108, expected 113 1/14 Test #1164: agc_driver_image_gather_lod .....................***Failed 0.70 sec ... 93% tests passed, 1 tests failed out of 14 ``` </details> <details><summary>check_conventions.py</summary> ``` docs/dev/debt/shader.md:213: warning: [debt-length] Technical debt entry over 1000 characters: state the gap first (what differs from the console, what is unverified, what throws) and keep only the behaviour it needs: 1186 characters 1 findings, 0 errors ``` </details> ## Negative control I restored `Resources.hpp`, `DescriptorBindingBuilder.cpp`, `ShaderInfoCollector.cpp`, `PipelineSpecialization.hpp` and `SpirvImageEmitter.cpp` from `origin/main` and kept the new test. `agc_driver_image_gather_lod` then 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 1. **The debt entry is inaccurate about 1D images and leaves out 2D arrays.** [`docs/dev/debt/shader.md:213`](https://github.com/boykopovar/AnyPS5/blob/8502ef15f7557f7972c066f5b24e07ee6e5ee9ba/docs/dev/debt/shader.md#L212-L212) (line 212 on the head) says that `image_gather4_l` "on 1D, 3D or cube images" still gathers the base level. Two parts of that do not match the code: - On 1D, 1D-array and remapped-depth-1D images, `image_gather4_l` does not fall back to a base-level gather. It is refused: [`SpirvImageEmitter.cpp:1437-1439`](https://github.com/boykopovar/AnyPS5/blob/8502ef15f7557f7972c066f5b24e07ee6e5ee9ba/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1437-L1439) calls `ctx.Fail(... "has an unsupported 1D gather variant")` whenever `RdnaImageSampleFlagLevelZero` is not set. - The new path's guard at [`SpirvImageEmitter.cpp:1481`](https://github.com/boykopovar/AnyPS5/blob/8502ef15f7557f7972c066f5b24e07ee6e5ee9ba/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1481-L1481) requires `dimension == RdnaImageDimension::Dim2D`. So `image_gather4_l` on 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-length` warning (1186 characters against a limit of 1000). 2. **The graphics-pipeline-library prebuild specializes on an all-zero sampler.** This is a question about the prebuild path; I did not measure it. [`RegistrationResult`](https://github.com/boykopovar/AnyPS5/blob/ba5b5330b37724bca4b99f30faab504653635a04/core/shader/recompiler/Recompiler.cpp#L2066-L2070) gives up on shaders whose specialization depends on sampler words (`FoldsTexelOffsets`), and otherwise materializes the shader with zeroed sampler descriptors. The new block at [`DescriptorBindingBuilder.cpp:316`](https://github.com/boykopovar/AnyPS5/blob/8502ef15f7557f7972c066f5b24e07ee6e5ee9ba/core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp#L316-L323) is not gated on that path. For a fragment shader that uses `image_gather4_l`, the prebuild therefore gets `GatherLodBase` = wrap, `MAX_LOD` 0 and `MIP_FILTER` none. With specialization present, [`Recompiler.cpp:1232`](https://github.com/boykopovar/AnyPS5/blob/ba5b5330b37724bca4b99f30faab504653635a04/core/shader/recompiler/Recompiler.cpp#L1232-L1232) builds 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, adding `SamplerUseGatherLod` samplers to the early return next to `FoldsTexelOffsets` would avoid the useless prebuild. This only applies where `graphicsPipelineLibrary` is enabled. Other things I checked and found correct: - The S# fields are extracted from the right bits: `MIN_LOD`/`MAX_LOD` from word 1 [23:0] as u4.8, `CLAMP_X`/`CLAMP_Y` from word 0 [5:0], `LOD_BIAS` from word 2 [13:0] as s5.8, `MIP_FILTER` from word 2 [27:26]. - The specialization defaults (`4 << 24`, which reads as unsupported) mean that a sampler-table sampler, or a sampler that never got the constant, keeps the old gather. - `GatherAddress` matches the address-mode mapping in `GuestSamplerResource.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 fit `ShaderInfo::MaxSamplers` = 32 without overlapping another range. - Sampler words are fully part of the binding-plan key (`preparedBindingPlan`) and of the result-memo key, so a sampler with a different LOD state cannot reuse a stale specialization. - With an unnormalized sampler, the gather is still refused through `UnnormalizedUseReason`, because `SamplerUseGather` is 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 - I ran nothing on AMD or Windows. The behaviour the debt entry lists as unmeasured on hardware (tie rounding, linear `MIP_FILTER`, `LOD_BIAS_SEC`, T# `MIN_LOD`) was not checked on a console. - I did not run PPSA23276, so the in-game result is the author's. - I did not exercise `image_gather4_l` from a pixel shader, or the graphics-pipeline-library path (finding 2 comes from reading the code). - I did not check the textual overlap with #9183 beyond confirming that it is a different feature (3D `image_gather4_lz`).
XairRrR commented 2026-10-29 15:11:16 +00:00 (Migrated from github.com)

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 813217f0b5 raises 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 makes agc_driver_image_gather_lod log three new VUID- validation errors. The production code that raises them is already on main, but AGENTS.md asks that a GPU change add no new VUID- errors.

What changed since my last review

  • The branch was rebased onto 899ae3d1a. git range-diff shows the two commits I reviewed are unchanged (5f2c39f214 → f68dbf0702, 8502ef15f7 → 9d29fb18fe).
  • New commit 813217f0b5 "fix(shader): keep an explicit-LOD gather's fetch at the view's minimum LOD". It does five things:
    • adds the GatherImageMinLodBase specialization: the T# MIN_LOD above BASE_LEVEL, set per image in DescriptorBindingBuilder::Prepare;
    • applies the S# clamp in a fixed order, NMin(NMax(λ, MIN_LOD), MAX_LOD), and then raises λ to the image's minimum LOD;
    • gates the new path on table == NoTable for both the image and the sampler;
    • adds three test variants: T# MIN_LOD 2.5, mirror-once (modes 3 and 7), and the border fallback (modes 6 and 4);
    • rewrites the debt entry.
  • The author's 14:54 UTC comment replies to oneandonlydean's T# MIN_LOD point and reports results, including the new VUID- lines from the mirror-once variant.

What I ran

  • PR head: 813217f0b543b4a61f5449ed66e0bbea444b40b1
  • main: bb04a4f1ea0175e9e4f149f0359a764d62ff3296
  • Tree under test: main with the head merged in using --no-ff (no conflicts), in a clean worktree.
  • Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08), Release build with Ninja.
git fetch origin main pull/12790/head:refs/review/12790
git range-diff ba5b5330b3..8502ef15f7 899ae3d1ad..refs/review/12790
git checkout --detach origin/main
git merge --no-ff --no-edit refs/review/12790
git diff --check origin/main...refs/review/12790
python3 tools/check_conventions.py --base origin/main
cmake -S . -B build
cmake --build build -j10 --target \
  agc_driver_image_gather_lod_tests agc_driver_image_gather_one_dimensional_tests \
  agc_driver_image_gather_one_dimensional_array_tests agc_driver_image_packed_horizontal_gather_tests \
  agc_driver_image_sample_lod_clamp_tests agc_driver_image_sample_unnormalized_tests \
  agc_driver_image_sample_shared_sampler_tests agc_driver_image_sample_border_color_tests \
  image_sample_gather_tests agc_driver_image_texel_status_tests agc_driver_image_table_tests
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 \
VK_LOADER_DEBUG=error,warn,layer ctest --test-dir build -j4 -V --output-on-failure -R \
  '^(agc_driver_image_gather_lod|agc_driver_image_gather_one_dimensional|agc_driver_image_gather_one_dimensional_array|agc_driver_image_packed_horizontal_gather|agc_driver_image_sample_border_color|agc_driver_image_sample_lod_clamp|agc_driver_image_sample_shared_sampler|agc_driver_image_sample_unnormalized|image_sample_gather|agc_driver_image_texel_status|agc_driver_image_table)$'
# main baseline and negative control: the same build and ctest after
git checkout origin/main -- <the five changed files under core/shader>
# probes: one extra Run(...) line inserted temporarily into ImageGatherLod.cpp,
# built and run with the same environment, on both trees

Results

Check Result
git range-diff against the previously reviewed commits The first two commits are identical; one new commit
Merge onto main Clean
git diff --check Clean
check_conventions.py --base origin/main All checks passed. The debt-length warning from my last review is gone
Build of the 11 targets, merged tree and main production code OK
Focused tests, merged tree, validation layer 11/11 passed, including all 12 ImageGatherLod variants (0.50–0.65 s)
Focused tests, main production code + the PR's test 10/11; only agc_driver_image_gather_lod fails, with the message the author quotes
VUID- IDs, merged tree 3 new: VUID-VkSamplerCreateInfo-addressModeU-01079, -addressModeU-parameter, -addressModeV-parameter, all from agc_driver_image_gather_lod
VUID- IDs, main None
was not found but was requested by env var VK_INSTANCE_LAYERS Absent from both logs; the loader inserted VK_LAYER_KHRONOS_validation 10 times (merged) and 11 times (main)
agc_driver_image_table Passed on both trees with no SYNC- lines on this host. The author reports a SYNC-HAZARD failure on both trees on their machine
Merged tree: the new validation errors
1172: Validation Error: [ VUID-VkSamplerCreateInfo-addressModeU-01079 ] | MessageID = 0x1aa95c2b
1172: The Vulkan spec states: If the samplerMirrorClampToEdge feature is not enabled, and if the VK_KHR_sampler_mirror_clamp_to_edge extension is not enabled, addressModeU, addressModeV and addressModeW must not be VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
1172: Validation Error: [ VUID-VkSamplerCreateInfo-addressModeU-parameter ] | MessageID = 0x3fcec07
1172: Validation Error: [ VUID-VkSamplerCreateInfo-addressModeV-parameter ] | MessageID = 0xf8361085
1172: image 2D explicit-LOD gather tests passed
10/11 Test #1172: agc_driver_image_gather_lod .....................   Passed    0.65 sec
100% tests passed out of 11
main production code with the PR's test
1172: AGC graphics: clamp to edge, point: thread 1 (LOD 1.000000, level 1) component 0 is 108, expected 113
 1/11 Test #1172: agc_driver_image_gather_lod .....................***Failed    1.02 sec
91% tests passed, 1 tests failed out of 11

Previous findings

  1. Debt entry: 1D images and 2D arrays. Partly resolved, still open.

    • Resolved: the entry was rewritten and no longer trips debt-length.
    • Still open: it still says 1D images "still gather the base level". On 1D, 1D-array and remapped-depth-1D images, image_gather4_l is refused at SpirvImageEmitter.cpp:1444-1446 (ctx.Fail(... "has an unsupported 1D gather variant")).
    • Still open: 2D arrays also keep the base-level gather because of the Dim2D guard, and the fallback list does not name them.

    Non-blocking.

  2. 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:2070 still covers only FoldsTexelOffsets. The new image MIN_LOD constant takes 0 from zeroed T# words, so the new commit adds nothing to this. Non-blocking question.

New findings

Blocking

  1. The mirror-once variant adds three new VUID- validation errors. The variant is at ImageGatherLod.cpp:234.
    • What I see. I confirm the author's report: on the merged tree, agc_driver_image_gather_lod logs VUID-VkSamplerCreateInfo-addressModeU-01079, -addressModeU-parameter and -addressModeV-parameter. main's log has none of them.
    • Where they come from. I moved a mirror-once variant to the front of the test and ran it against main's production code, and the same three IDs appeared. So they come from code that is already on main, not from the shader change. GuestSamplerResource.cpp:37-41 maps clamp modes 3, 5 and 7 to VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, and nothing under core/ enables samplerMirrorClampToEdge.
    • Why it blocks. AGENTS.md asks that an AGC or shader recompiler change add no new VUID- errors. Once this merges, agc_driver_image_gather_lod reports Passed while it logs invalid sampler creation on every run.
    • Suggested fix. Either option works:
      • Land the sampler fix the author mentions first, and list it under Depends on. That fix would enable samplerMirrorClampToEdge at device creation when it is supported, and refuse or emulate the mode when it is not.
      • Drop the mirror-once variant here and add it with that fix.

Non-blocking

  1. With MIP_FILTER none, the fetch ignores the T# MIN_LOD.
    • The code. SpirvImageEmitter.cpp:823-831 raises nearest to the image's minimum LOD, but level takes the constant 0 when mipNone is set.
    • Why it matters. When the T# MIN_LOD is at least 1 above BASE_LEVEL, the view gets a minLod through ChainMinLod. The four OpImageFetches then read below minLodInteger. The Vulkan 1.4.330 spec says such values are zero with robustImageAccess2 and undefined otherwise.
    • Probe. I added {MipNone, T# MIN_LOD 640}, the T# MIN_LOD 2.5 variant with MIP_FILTER none. On the merged tree, thread 0 read 0 where any mip level holds a non-zero texel: component 0 is 0, expected 108.
    • Not a regression. The same probe on main also reads 0. The gather section of the spec makes OpImageGather below minLodInteger undefined as well, so the view does not clamp the old base-level gather either. That also qualifies the premise of oneandonlydean's point 1.
    • Why it is still worth fixing. The new commit's message says "the fetched level never falls below the view's integer minimum LOD". That is not true for this branch. The test's reference model encodes the same gap: Level() returns 0 for MipNone before it looks at textureMinLodRaw (ImageGatherLod.cpp:150).
    • Suggested fix. For mipNone, use floor of 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 for MIP_FILTER none with a T# MIN_LOD is unknown, the debt entry is the place to say so.

Other things I checked in the new commit and found correct:

  • The constant matches the view's minimum LOD.
    • EffectiveMinLod gives the view an absolute MIN_LOD, or none when MIN_LOD <= BASE_LEVEL·256. The constant is the same value rebased to the view (MIN_LOD - BASE_LEVEL·256, else 0), and OpImageFetch's Lod is view-relative.
    • So for mip filters other than none, the fetched level BASE_LEVEL + nearest is at least the view's minLodInteger, because ceil(λ + 0.5) - 1 >= floor(λ).
    • EffectiveMinLod's cap at lastLevel matches the shader's clamp to levels - 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.
  • The image constant is set only for non-table images, and the shader now also takes the base-level path for table images and table samplers, so the default constant is never relied on there.

Not verified

  • Nothing ran on AMD or Windows, and I did not run PPSA23276. The in-game result in the author's comment is author-reported.
  • The hardware behaviour of the T# MIN_LOD clamp and of the mirror-once modes is unmeasured, as the debt entry says.
  • I did not reproduce the author's agc_driver_image_table SYNC-HAZARD: the test passed on both trees here.
  • I did not exercise the graphics-pipeline-library prebuild path.

To get this to a good state

  1. Remove the three new VUID- errors: land the samplerMirrorClampToEdge fix first and list it under Depends on, or drop the mirror-once variant from this PR.
  2. Optionally, apply the T# MIN_LOD to the MIP_FILTER none branch as well, and add a variant for it.
  3. Optionally, correct the debt entry for 1D (it throws) and 2D arrays (base-level gather).
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5700096404 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12790#pullrequestreview-5700096404). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T15:11:16Z. **Review:** CHANGES_REQUESTED --- # Re-checked — changes still requested The new commit `813217f0b5` raises 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 makes `agc_driver_image_gather_lod` log three new `VUID-` validation errors. The production code that raises them is already on `main`, but AGENTS.md asks that a GPU change add no new `VUID-` errors. ## What changed since my last review - The branch was rebased onto `899ae3d1a`. `git range-diff` shows the two commits I reviewed are unchanged (`5f2c39f214` → `f68dbf0702`, `8502ef15f7` → `9d29fb18fe`). - New commit `813217f0b5` "fix(shader): keep an explicit-LOD gather's fetch at the view's minimum LOD". It does five things: - adds the `GatherImageMinLodBase` specialization: the T# `MIN_LOD` above `BASE_LEVEL`, set per image in `DescriptorBindingBuilder::Prepare`; - applies the S# clamp in a fixed order, `NMin(NMax(λ, MIN_LOD), MAX_LOD)`, and then raises λ to the image's minimum LOD; - gates the new path on `table == NoTable` for both the image and the sampler; - adds three test variants: T# `MIN_LOD` 2.5, mirror-once (modes 3 and 7), and the border fallback (modes 6 and 4); - rewrites the debt entry. - The author's 14:54 UTC comment replies to oneandonlydean's T# `MIN_LOD` point and reports results, including the new `VUID-` lines from the mirror-once variant. ## What I ran - PR head: `813217f0b543b4a61f5449ed66e0bbea444b40b1` - `main`: `bb04a4f1ea0175e9e4f149f0359a764d62ff3296` - Tree under test: `main` with the head merged in using `--no-ff` (no conflicts), in a clean worktree. - Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08), Release build with Ninja. ```sh git fetch origin main pull/12790/head:refs/review/12790 git range-diff ba5b5330b3..8502ef15f7 899ae3d1ad..refs/review/12790 git checkout --detach origin/main git merge --no-ff --no-edit refs/review/12790 git diff --check origin/main...refs/review/12790 python3 tools/check_conventions.py --base origin/main cmake -S . -B build cmake --build build -j10 --target \ agc_driver_image_gather_lod_tests agc_driver_image_gather_one_dimensional_tests \ agc_driver_image_gather_one_dimensional_array_tests agc_driver_image_packed_horizontal_gather_tests \ agc_driver_image_sample_lod_clamp_tests agc_driver_image_sample_unnormalized_tests \ agc_driver_image_sample_shared_sampler_tests agc_driver_image_sample_border_color_tests \ image_sample_gather_tests agc_driver_image_texel_status_tests agc_driver_image_table_tests VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 \ VK_LOADER_DEBUG=error,warn,layer ctest --test-dir build -j4 -V --output-on-failure -R \ '^(agc_driver_image_gather_lod|agc_driver_image_gather_one_dimensional|agc_driver_image_gather_one_dimensional_array|agc_driver_image_packed_horizontal_gather|agc_driver_image_sample_border_color|agc_driver_image_sample_lod_clamp|agc_driver_image_sample_shared_sampler|agc_driver_image_sample_unnormalized|image_sample_gather|agc_driver_image_texel_status|agc_driver_image_table)$' # main baseline and negative control: the same build and ctest after git checkout origin/main -- <the five changed files under core/shader> # probes: one extra Run(...) line inserted temporarily into ImageGatherLod.cpp, # built and run with the same environment, on both trees ``` ## Results | Check | Result | |---|---| | `git range-diff` against the previously reviewed commits | The first two commits are identical; one new commit | | Merge onto `main` | Clean | | `git diff --check` | Clean | | `check_conventions.py --base origin/main` | All checks passed. The `debt-length` warning from my last review is gone | | Build of the 11 targets, merged tree and `main` production code | OK | | Focused tests, merged tree, validation layer | 11/11 passed, including all 12 `ImageGatherLod` variants (0.50–0.65 s) | | Focused tests, `main` production code + the PR's test | 10/11; only `agc_driver_image_gather_lod` fails, with the message the author quotes | | `VUID-` IDs, merged tree | 3 new: `VUID-VkSamplerCreateInfo-addressModeU-01079`, `-addressModeU-parameter`, `-addressModeV-parameter`, all from `agc_driver_image_gather_lod` | | `VUID-` IDs, `main` | None | | `was not found but was requested by env var VK_INSTANCE_LAYERS` | Absent from both logs; the loader inserted `VK_LAYER_KHRONOS_validation` 10 times (merged) and 11 times (`main`) | | `agc_driver_image_table` | Passed on both trees with no `SYNC-` lines on this host. The author reports a `SYNC-HAZARD` failure on both trees on their machine | <details><summary>Merged tree: the new validation errors</summary> ``` 1172: Validation Error: [ VUID-VkSamplerCreateInfo-addressModeU-01079 ] | MessageID = 0x1aa95c2b 1172: The Vulkan spec states: If the samplerMirrorClampToEdge feature is not enabled, and if the VK_KHR_sampler_mirror_clamp_to_edge extension is not enabled, addressModeU, addressModeV and addressModeW must not be VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE 1172: Validation Error: [ VUID-VkSamplerCreateInfo-addressModeU-parameter ] | MessageID = 0x3fcec07 1172: Validation Error: [ VUID-VkSamplerCreateInfo-addressModeV-parameter ] | MessageID = 0xf8361085 1172: image 2D explicit-LOD gather tests passed 10/11 Test #1172: agc_driver_image_gather_lod ..................... Passed 0.65 sec 100% tests passed out of 11 ``` </details> <details><summary><code>main</code> production code with the PR's test</summary> ``` 1172: AGC graphics: clamp to edge, point: thread 1 (LOD 1.000000, level 1) component 0 is 108, expected 113 1/11 Test #1172: agc_driver_image_gather_lod .....................***Failed 1.02 sec 91% tests passed, 1 tests failed out of 11 ``` </details> ## Previous findings 1. **Debt entry: 1D images and 2D arrays.** Partly resolved, still open. - Resolved: the entry was rewritten and no longer trips `debt-length`. - Still open: it still says 1D images "still gather the base level". On 1D, 1D-array and remapped-depth-1D images, `image_gather4_l` is refused at [`SpirvImageEmitter.cpp:1444-1446`](https://github.com/boykopovar/AnyPS5/blob/813217f0b543b4a61f5449ed66e0bbea444b40b1/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1444-L1446) (`ctx.Fail(... "has an unsupported 1D gather variant")`). - Still open: 2D arrays also keep the base-level gather because of the `Dim2D` guard, and the fallback list does not name them. Non-blocking. 2. **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:2070`](https://github.com/boykopovar/AnyPS5/blob/813217f0b543b4a61f5449ed66e0bbea444b40b1/core/shader/recompiler/Recompiler.cpp#L2070-L2070) still covers only `FoldsTexelOffsets`. The new image `MIN_LOD` constant takes 0 from zeroed T# words, so the new commit adds nothing to this. Non-blocking question. ## New findings ### Blocking 1. **The mirror-once variant adds three new `VUID-` validation errors.** The variant is at [`ImageGatherLod.cpp:234`](https://github.com/boykopovar/AnyPS5/blob/813217f0b543b4a61f5449ed66e0bbea444b40b1/core/libs/prx/libSceAgcDriver/tests/execution/ImageGatherLod.cpp#L234-L234). - **What I see.** I confirm the author's report: on the merged tree, `agc_driver_image_gather_lod` logs `VUID-VkSamplerCreateInfo-addressModeU-01079`, `-addressModeU-parameter` and `-addressModeV-parameter`. `main`'s log has none of them. - **Where they come from.** I moved a mirror-once variant to the front of the test and ran it against `main`'s production code, and the same three IDs appeared. So they come from code that is already on `main`, not from the shader change. [`GuestSamplerResource.cpp:37-41`](https://github.com/boykopovar/AnyPS5/blob/bb04a4f1ea0175e9e4f149f0359a764d62ff3296/core/libs/prx/libSceAgcDriver/Graphics/src/GuestSamplerResource.cpp#L37-L41) maps clamp modes 3, 5 and 7 to `VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE`, and nothing under `core/` enables `samplerMirrorClampToEdge`. - **Why it blocks.** AGENTS.md asks that an AGC or shader recompiler change add no new `VUID-` errors. Once this merges, `agc_driver_image_gather_lod` reports `Passed` while it logs invalid sampler creation on every run. - **Suggested fix.** Either option works: - Land the sampler fix the author mentions first, and list it under `Depends on`. That fix would enable `samplerMirrorClampToEdge` at device creation when it is supported, and refuse or emulate the mode when it is not. - Drop the mirror-once variant here and add it with that fix. ### Non-blocking 2. **With `MIP_FILTER` none, the fetch ignores the T# `MIN_LOD`.** - **The code.** [`SpirvImageEmitter.cpp:823-831`](https://github.com/boykopovar/AnyPS5/blob/813217f0b543b4a61f5449ed66e0bbea444b40b1/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L823-L831) raises `nearest` to the image's minimum LOD, but `level` takes the constant 0 when `mipNone` is set. - **Why it matters.** When the T# `MIN_LOD` is at least 1 above `BASE_LEVEL`, the view gets a `minLod` through `ChainMinLod`. The four `OpImageFetch`es then read below `minLodInteger`. The [Vulkan 1.4.330 spec](https://github.com/KhronosGroup/Vulkan-Docs/blob/v1.4.330/chapters/textures.adoc?plain=1#L2049-L2059) says such values are zero with `robustImageAccess2` and undefined otherwise. - **Probe.** I added `{MipNone, T# MIN_LOD 640}`, the `T# MIN_LOD 2.5` variant with `MIP_FILTER` none. On the merged tree, thread 0 read 0 where any mip level holds a non-zero texel: `component 0 is 0, expected 108`. - **Not a regression.** The same probe on `main` also reads 0. The [gather section of the spec](https://github.com/KhronosGroup/Vulkan-Docs/blob/v1.4.330/chapters/textures.adoc?plain=1#L2177-L2183) makes `OpImageGather` below `minLodInteger` undefined as well, so the view does not clamp the old base-level gather either. That also qualifies the premise of oneandonlydean's point 1. - **Why it is still worth fixing.** The new commit's message says "the fetched level never falls below the view's integer minimum LOD". That is not true for this branch. The test's reference model encodes the same gap: `Level()` returns 0 for `MipNone` before it looks at `textureMinLodRaw` ([`ImageGatherLod.cpp:150`](https://github.com/boykopovar/AnyPS5/blob/813217f0b543b4a61f5449ed66e0bbea444b40b1/core/libs/prx/libSceAgcDriver/tests/execution/ImageGatherLod.cpp#L150-L150)). - **Suggested fix.** For `mipNone`, use `floor` of 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 for `MIP_FILTER` none with a T# `MIN_LOD` is unknown, the debt entry is the place to say so. Other things I checked in the new commit and found correct: - The constant matches the view's minimum LOD. - `EffectiveMinLod` gives the view an absolute `MIN_LOD`, or none when `MIN_LOD <= BASE_LEVEL·256`. The constant is the same value rebased to the view (`MIN_LOD - BASE_LEVEL·256`, else 0), and `OpImageFetch`'s `Lod` is view-relative. - So for mip filters other than none, the fetched level `BASE_LEVEL + nearest` is at least the view's `minLodInteger`, because `ceil(λ + 0.5) - 1 >= floor(λ)`. - `EffectiveMinLod`'s cap at `lastLevel` matches the shader's clamp to `levels - 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. - The image constant is set only for non-table images, and the shader now also takes the base-level path for table images and table samplers, so the default constant is never relied on there. ## Not verified - Nothing ran on AMD or Windows, and I did not run PPSA23276. The in-game result in the author's comment is author-reported. - The hardware behaviour of the T# `MIN_LOD` clamp and of the mirror-once modes is unmeasured, as the debt entry says. - I did not reproduce the author's `agc_driver_image_table` `SYNC-HAZARD`: the test passed on both trees here. - I did not exercise the graphics-pipeline-library prebuild path. ## To get this to a good state 1. Remove the three new `VUID-` errors: land the `samplerMirrorClampToEdge` fix first and list it under `Depends on`, or drop the mirror-once variant from this PR. 2. Optionally, apply the T# `MIN_LOD` to the `MIP_FILTER` none branch as well, and add a variant for it. 3. Optionally, correct the debt entry for 1D (it throws) and 2D arrays (base-level gather).
XairRrR commented 2026-10-29 15:50:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T15:50:15Z.

Review: APPROVED


Re-checked — approved

The new commit 01b2319b7d drops the mirror-once variant, fetches MIP_FILTER none 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 no VUID- lines.

What changed since my last review

  • One new commit, 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: for MIP_FILTER none the level is now floor(imageMinLod), clamped to [0, levels - 1], instead of 0.
    • Recompiler.cpp: RegistrationResult returns nullptr for a shader with a SamplerUseGatherLod sampler, as well as for FoldsTexelOffsets.
    • ImageGatherLod.cpp: removes the mirror-once variant, adds MIP_FILTER none, T# MIN_LOD 2.5, and updates the reference Level() to match.
    • docs/dev/debt/shader.md: rewrites the entry.
  • The first three commits are unchanged.
  • The author's 15:29 UTC comment answers all four points from my last review.

What I ran

  • PR head: 01b2319b7dc07947ed5bf1a3005e31da622d0410
  • main: bb04a4f1ea0175e9e4f149f0359a764d62ff3296, the same main as last time.
  • Tree under test: main with the head merged in using --no-ff (no conflicts), in a clean worktree.
  • Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08), Release build with Ninja.
git fetch origin main pull/12790/head:refs/review/12790
git diff 813217f0b543 refs/review/12790
git checkout --detach origin/main
git merge --no-ff --no-edit refs/review/12790
git diff --check origin/main...refs/review/12790
python3 tools/check_conventions.py --base origin/main
cmake --build build -j10 --target \
  agc_driver_image_gather_lod_tests agc_driver_image_gather_one_dimensional_tests \
  agc_driver_image_gather_one_dimensional_array_tests agc_driver_image_packed_horizontal_gather_tests \
  agc_driver_image_sample_lod_clamp_tests agc_driver_image_sample_unnormalized_tests \
  agc_driver_image_sample_shared_sampler_tests agc_driver_image_sample_border_color_tests \
  image_sample_gather_tests agc_driver_image_texel_status_tests agc_driver_image_table_tests
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 \
VK_LOADER_DEBUG=error,warn,layer ctest --test-dir build -j4 -V --output-on-failure -R \
  '^(agc_driver_image_gather_lod|agc_driver_image_gather_one_dimensional|agc_driver_image_gather_one_dimensional_array|agc_driver_image_packed_horizontal_gather|agc_driver_image_sample_border_color|agc_driver_image_sample_lod_clamp|agc_driver_image_sample_shared_sampler|agc_driver_image_sample_unnormalized|image_sample_gather|agc_driver_image_texel_status|agc_driver_image_table)$'
cmake --build build -j10 --target agc_driver_recorder_tests
ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build -j4 --output-on-failure -R '^agc_pipeline_library'
# negative control: the previous commit's emitter with the new test
git checkout 813217f0b543 -- core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
# build agc_driver_image_gather_lod_tests, run it with the same environment
# main baseline: main's production code with the PR's test
git checkout origin/main -- core/shader
# same build and validation ctest as above, then the merged files were restored

Results

Check Result
Merge onto main Clean
git diff --check Clean
check_conventions.py --base origin/main All conventions checks passed
Build: the 11 focused targets and agc_driver_recorder_tests OK
Focused tests, merged tree, validation layer 11/11 passed. agc_driver_image_gather_lod passed in 1.30 s and printed image 2D explicit-LOD gather tests passed
agc_pipeline_library* tests, merged tree 6/6 passed
VUID- IDs, merged tree None
VUID- IDs, main production code None
was not found but was requested by env var VK_INSTANCE_LAYERS Absent from both logs. The loader inserted VK_LAYER_KHRONOS_validation 10 times (merged) and 11 times (main)
main production code + the PR's test 10/11. Only agc_driver_image_gather_lod fails: clamp to edge, point: thread 1 (LOD 1.000000, level 1) component 0 is 108, expected 113
agc_driver_image_table Passed on both trees, with no SYNC- lines on this host

Negative control

I restored SpirvImageEmitter.cpp from 813217f0b5, the commit I reviewed last time, and kept the new test. The new variant fails:

Output
1/1 Test #1172: agc_driver_image_gather_lod ......***Failed    0.84 sec
AGC graphics: MIP_FILTER none, T# MIN_LOD 2.5: thread 0 (LOD 0.000000, level 2) component 0 is 0, expected 146

With all of main's production code, the test fails on its first variant, as it did last time.

Previous findings

  1. New VUID- errors from the mirror-once variant (blocking): Resolved. The variant and its two constants are gone from ImageGatherLod.cpp. The merged-tree log has no VUID- lines, and neither has main's. The author plans to add the variant back with the samplerMirrorClampToEdge fix.
  2. MIP_FILTER none ignored the T# MIN_LOD: Resolved. See SpirvImageEmitter.cpp:831-834.
    • imageMinLod is the view-relative constant, MIN_LOD - BASE_LEVEL·256, or 0.
    • BASE_LEVEL + floor(imageMinLod), capped at the last level, equals the view's minLodInteger, so the fetch no longer reads below it.
    • The reference model at ImageGatherLod.cpp:149 matches, because every variant uses BASE_LEVEL 0.
    • The new variant at line 233 covers the change; see the negative control.
  3. Debt entry for 1D and 2D arrays: Resolved. shader.md:214 now says that image_gather4_l throws on 1D images. It lists 2D arrays among the base-level gathers, and names MIP_FILTER none with a T# MIN_LOD as unverified.
  4. Pipeline-library prebuild specialized on an all-zero sampler: Resolved. Recompiler.cpp:2070 now returns nullptr for any sampler with SamplerUseGatherLod, so those shaders get no zero-sampler registration module. The six agc_pipeline_library* tests pass. None of them contains an image_gather4_l shader, so the new condition itself is not exercised.

New findings

Blocking

None.

Non-blocking

  1. Parts of the PR description no longer match the code. Each of these could be updated:

    • What still says "base level for MIP_FILTER none".
    • The test list still names "mirror once (3, 7)" and not the new MIP_FILTER none, T# MIN_LOD 2.5 variant.
    • Tested still describes the mirror-once VkSamplerCreateInfo IDs.

    The 15:29 UTC comment does have the current results.

Not verified

  • Nothing ran on AMD or Windows, and I did not run PPSA23276. The author's in-game and Windows results are author-reported.
  • The hardware behaviour of MIP_FILTER none combined with a T# MIN_LOD is unmeasured. The debt entry says so.
  • No test runs an image_gather4_l shader through the pipeline-library registration path.
  • I did not reproduce the author's agc_driver_image_table SYNC-HAZARD: the test passed on both trees here.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5700728113 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12790#pullrequestreview-5700728113). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T15:50:15Z. **Review:** APPROVED --- # Re-checked — approved The new commit `01b2319b7d` drops the mirror-once variant, fetches `MIP_FILTER` none 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 no `VUID-` lines. ## What changed since my last review - One new commit, `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`: for `MIP_FILTER` none the level is now `floor(imageMinLod)`, clamped to `[0, levels - 1]`, instead of 0. - `Recompiler.cpp`: `RegistrationResult` returns `nullptr` for a shader with a `SamplerUseGatherLod` sampler, as well as for `FoldsTexelOffsets`. - `ImageGatherLod.cpp`: removes the mirror-once variant, adds `MIP_FILTER none, T# MIN_LOD 2.5`, and updates the reference `Level()` to match. - `docs/dev/debt/shader.md`: rewrites the entry. - The first three commits are unchanged. - The author's 15:29 UTC comment answers all four points from my last review. ## What I ran - PR head: `01b2319b7dc07947ed5bf1a3005e31da622d0410` - `main`: `bb04a4f1ea0175e9e4f149f0359a764d62ff3296`, the same `main` as last time. - Tree under test: `main` with the head merged in using `--no-ff` (no conflicts), in a clean worktree. - Machine: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08), Release build with Ninja. ```sh git fetch origin main pull/12790/head:refs/review/12790 git diff 813217f0b543 refs/review/12790 git checkout --detach origin/main git merge --no-ff --no-edit refs/review/12790 git diff --check origin/main...refs/review/12790 python3 tools/check_conventions.py --base origin/main cmake --build build -j10 --target \ agc_driver_image_gather_lod_tests agc_driver_image_gather_one_dimensional_tests \ agc_driver_image_gather_one_dimensional_array_tests agc_driver_image_packed_horizontal_gather_tests \ agc_driver_image_sample_lod_clamp_tests agc_driver_image_sample_unnormalized_tests \ agc_driver_image_sample_shared_sampler_tests agc_driver_image_sample_border_color_tests \ image_sample_gather_tests agc_driver_image_texel_status_tests agc_driver_image_table_tests VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 \ VK_LOADER_DEBUG=error,warn,layer ctest --test-dir build -j4 -V --output-on-failure -R \ '^(agc_driver_image_gather_lod|agc_driver_image_gather_one_dimensional|agc_driver_image_gather_one_dimensional_array|agc_driver_image_packed_horizontal_gather|agc_driver_image_sample_border_color|agc_driver_image_sample_lod_clamp|agc_driver_image_sample_shared_sampler|agc_driver_image_sample_unnormalized|image_sample_gather|agc_driver_image_texel_status|agc_driver_image_table)$' cmake --build build -j10 --target agc_driver_recorder_tests ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build -j4 --output-on-failure -R '^agc_pipeline_library' # negative control: the previous commit's emitter with the new test git checkout 813217f0b543 -- core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp # build agc_driver_image_gather_lod_tests, run it with the same environment # main baseline: main's production code with the PR's test git checkout origin/main -- core/shader # same build and validation ctest as above, then the merged files were restored ``` ## Results | Check | Result | |---|---| | Merge onto `main` | Clean | | `git diff --check` | Clean | | `check_conventions.py --base origin/main` | All conventions checks passed | | Build: the 11 focused targets and `agc_driver_recorder_tests` | OK | | Focused tests, merged tree, validation layer | 11/11 passed. `agc_driver_image_gather_lod` passed in 1.30 s and printed `image 2D explicit-LOD gather tests passed` | | `agc_pipeline_library*` tests, merged tree | 6/6 passed | | `VUID-` IDs, merged tree | None | | `VUID-` IDs, `main` production code | None | | `was not found but was requested by env var VK_INSTANCE_LAYERS` | Absent from both logs. The loader inserted `VK_LAYER_KHRONOS_validation` 10 times (merged) and 11 times (`main`) | | `main` production code + the PR's test | 10/11. Only `agc_driver_image_gather_lod` fails: `clamp to edge, point: thread 1 (LOD 1.000000, level 1) component 0 is 108, expected 113` | | `agc_driver_image_table` | Passed on both trees, with no `SYNC-` lines on this host | ## Negative control I restored `SpirvImageEmitter.cpp` from `813217f0b5`, the commit I reviewed last time, and kept the new test. The new variant fails: <details><summary>Output</summary> ``` 1/1 Test #1172: agc_driver_image_gather_lod ......***Failed 0.84 sec AGC graphics: MIP_FILTER none, T# MIN_LOD 2.5: thread 0 (LOD 0.000000, level 2) component 0 is 0, expected 146 ``` </details> With all of `main`'s production code, the test fails on its first variant, as it did last time. ## Previous findings 1. **New `VUID-` errors from the mirror-once variant (blocking): Resolved.** The variant and its two constants are gone from `ImageGatherLod.cpp`. The merged-tree log has no `VUID-` lines, and neither has `main`'s. The author plans to add the variant back with the `samplerMirrorClampToEdge` fix. 2. **`MIP_FILTER` none ignored the T# `MIN_LOD`: Resolved.** See [`SpirvImageEmitter.cpp:831-834`](https://github.com/boykopovar/AnyPS5/blob/01b2319b7dc07947ed5bf1a3005e31da622d0410/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L831-L834). - `imageMinLod` is the view-relative constant, `MIN_LOD - BASE_LEVEL·256`, or 0. - `BASE_LEVEL + floor(imageMinLod)`, capped at the last level, equals the view's `minLodInteger`, so the fetch no longer reads below it. - The reference model at [`ImageGatherLod.cpp:149`](https://github.com/boykopovar/AnyPS5/blob/01b2319b7dc07947ed5bf1a3005e31da622d0410/core/libs/prx/libSceAgcDriver/tests/execution/ImageGatherLod.cpp#L149-L149) matches, because every variant uses `BASE_LEVEL` 0. - The new variant at [line 233](https://github.com/boykopovar/AnyPS5/blob/01b2319b7dc07947ed5bf1a3005e31da622d0410/core/libs/prx/libSceAgcDriver/tests/execution/ImageGatherLod.cpp#L233-L233) covers the change; see the negative control. 3. **Debt entry for 1D and 2D arrays: Resolved.** [`shader.md:214`](https://github.com/boykopovar/AnyPS5/blob/01b2319b7dc07947ed5bf1a3005e31da622d0410/docs/dev/debt/shader.md#L214-L214) now says that `image_gather4_l` throws on 1D images. It lists 2D arrays among the base-level gathers, and names `MIP_FILTER` none with a T# `MIN_LOD` as unverified. 4. **Pipeline-library prebuild specialized on an all-zero sampler: Resolved.** [`Recompiler.cpp:2070`](https://github.com/boykopovar/AnyPS5/blob/01b2319b7dc07947ed5bf1a3005e31da622d0410/core/shader/recompiler/Recompiler.cpp#L2070-L2070) now returns `nullptr` for any sampler with `SamplerUseGatherLod`, so those shaders get no zero-sampler registration module. The six `agc_pipeline_library*` tests pass. None of them contains an `image_gather4_l` shader, so the new condition itself is not exercised. ## New findings ### Blocking None. ### Non-blocking 1. **Parts of the PR description no longer match the code.** Each of these could be updated: - `What` still says "base level for `MIP_FILTER` none". - The test list still names "mirror once (3, 7)" and not the new `MIP_FILTER none, T# MIN_LOD 2.5` variant. - `Tested` still describes the mirror-once `VkSamplerCreateInfo` IDs. The 15:29 UTC comment does have the current results. ## Not verified - Nothing ran on AMD or Windows, and I did not run PPSA23276. The author's in-game and Windows results are author-reported. - The hardware behaviour of `MIP_FILTER` none combined with a T# `MIN_LOD` is unmeasured. The debt entry says so. - No test runs an `image_gather4_l` shader through the pipeline-library registration path. - I did not reproduce the author's `agc_driver_image_table` `SYNC-HAZARD`: the test passed on both trees here.
jotitadev commented 2026-10-31 03:19:04 +00:00 (Migrated from github.com)

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_lod fails on any device without VK_EXT_image_view_min_lod, and lavapipe (CI's linux device) is one of them. The linux job 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-ff onto main 2a1ae91175, 3 runs each:

AGC graphics: guest texture descriptor uses a minimum LOD clamp, which needs VK_EXT_image_view_min_lod

Cause. The two T# MIN_LOD 2.5 variants 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 no VK_EXT_image_view_min_lod either.

Fix I checked: run the two variants only when the device has the extension, through the same test accessor #12662 uses:

+namespace AgcDriver {
+
+struct VulkanDeviceTestAccess {
+    static bool ImageViewMinLod(const VulkanDevice& device) { return device.graphicsContext().imageViewMinLod; }
+};
+
+}
+
@@ int main() {
-        Run(*device, {Format8888UNorm, ClampEdge, ClampEdge, FilterPoint, MipPoint, 0u, AllLevels, 0, 640u, "T# MIN_LOD 2.5"});
-        Run(*device, {Format8888UNorm, ClampEdge, ClampEdge, FilterPoint, MipNone, 0u, AllLevels, 0, 640u, "MIP_FILTER none, T# MIN_LOD 2.5"});
+        if (AgcDriver::VulkanDeviceTestAccess::ImageViewMinLod(*device)) {
+            Run(*device, {Format8888UNorm, ClampEdge, ClampEdge, FilterPoint, MipPoint, 0u, AllLevels, 0, 640u, "T# MIN_LOD 2.5"});
+            Run(*device, {Format8888UNorm, ClampEdge, ClampEdge, FilterPoint, MipNone, 0u, AllLevels, 0, 640u, "MIP_FILTER none, T# MIN_LOD 2.5"});
+        } else {
+            std::puts("T# MIN_LOD cases skipped, the device has no VK_EXT_image_view_min_lod");
+        }

With it, agc_driver_image_gather_lod passes 3/3 on lavapipe, on the head alone and merged onto main. 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5720849950 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12790#pullrequestreview-5720849950). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-31T03:19:04Z. **Review:** COMMENTED --- Linux lavapipe run of head `01b2319b7d`: `agc_driver_image_gather_lod` fails on any device without `VK_EXT_image_view_min_lod`, and lavapipe (CI's `linux` device) is one of them. The `linux` job 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-ff` onto `main` `2a1ae91175`, 3 runs each: ``` AGC graphics: guest texture descriptor uses a minimum LOD clamp, which needs VK_EXT_image_view_min_lod ``` **Cause.** The two `T# MIN_LOD 2.5` variants 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 no `VK_EXT_image_view_min_lod` either. **Fix I checked**: run the two variants only when the device has the extension, through the same test accessor #12662 uses: ```diff +namespace AgcDriver { + +struct VulkanDeviceTestAccess { + static bool ImageViewMinLod(const VulkanDevice& device) { return device.graphicsContext().imageViewMinLod; } +}; + +} + @@ int main() { - Run(*device, {Format8888UNorm, ClampEdge, ClampEdge, FilterPoint, MipPoint, 0u, AllLevels, 0, 640u, "T# MIN_LOD 2.5"}); - Run(*device, {Format8888UNorm, ClampEdge, ClampEdge, FilterPoint, MipNone, 0u, AllLevels, 0, 640u, "MIP_FILTER none, T# MIN_LOD 2.5"}); + if (AgcDriver::VulkanDeviceTestAccess::ImageViewMinLod(*device)) { + Run(*device, {Format8888UNorm, ClampEdge, ClampEdge, FilterPoint, MipPoint, 0u, AllLevels, 0, 640u, "T# MIN_LOD 2.5"}); + Run(*device, {Format8888UNorm, ClampEdge, ClampEdge, FilterPoint, MipNone, 0u, AllLevels, 0, 640u, "MIP_FILTER none, T# MIN_LOD 2.5"}); + } else { + std::puts("T# MIN_LOD cases skipped, the device has no VK_EXT_image_view_min_lod"); + } ``` With it, `agc_driver_image_gather_lod` passes 3/3 on lavapipe, on the head alone and merged onto `main`. 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.
CnRJay commented 2026-11-01 19:54:38 +00:00 (Migrated from github.com)

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:

  1. More variants. Samplers used by image_gather4_l are 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 against main.
  2. Larger SPIR-V on every gather. The path replaces one OpImageGather with a LOD computation, four clamped coordinate computations and four OpImageFetch plus 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, from tools/trace_digest.py on the same scene?
  3. Images or samplers from a table, and border modes 4 and 6, keep the base-level gather, so the result stays wrong for those. Is that recorded in the debt file as a known divergence?
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729939087 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12790#pullrequestreview-5729939087). Originally posted by [CnRJay](https://github.com/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: 1. **More variants.** Samplers used by `image_gather4_l` are 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 against `main`. 2. **Larger SPIR-V on every gather.** The path replaces one `OpImageGather` with a LOD computation, four clamped coordinate computations and four `OpImageFetch` plus 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, from `tools/trace_digest.py` on the same scene? 3. Images or samplers from a table, and border modes 4 and 6, keep the base-level gather, so the result stays wrong for those. Is that recorded in the debt file as a known divergence?
XairRrR commented 2026-11-02 19:49:11 +00:00 (Migrated from github.com)

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 in

  • core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp
  • core/shader/recompiler/PipelineSpecialization.hpp
  • docs/dev/debt/shader.md

Please rebase it onto current main. I will review the change once it merges cleanly.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5742419376 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12790#pullrequestreview-5742419376). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-02T19:49:11Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested This pull request does not merge cleanly into `main` (c955a63d3d20822e13bb1c6b55ac5800ca5e4176): head 3a6f2133f2639bfea717f921c3998e44446529c6 conflicts in - `core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp` - `core/shader/recompiler/PipelineSpecialization.hpp` - `docs/dev/debt/shader.md` Please rebase it onto current `main`. I will review the change once it merges cleanly. <!-- anyps5-bots job=2274 head=3a6f2133f2639bfea717f921c3998e44446529c6 -->
XairRrR commented 2026-11-03 11:38:16 +00:00 (Migrated from github.com)

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_LOD variants only when the device has VK_EXT_image_view_min_lod. The PR was also rebased onto 4f41f4c375, 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

  • New commit ed711db0e0 (test only). ImageGatherLod.cpp reads graphicsContext().imageViewMinLod through a VulkanDeviceTestAccess accessor. When the extension is missing, it skips the two T# MIN_LOD 2.5 variants and prints that it did. This is the change jotitadev checked on lavapipe.
  • Rebase onto main 4f41f4c375. GatherLodBase, GatherLodBiasBase and GatherImageMinLodBase moved from 57536/57568/57600 to 57664/57696/57728, because main now uses 57536 and 57600. Commits 1–4 are otherwise unchanged; I compared them with delta.patch.
  • Description. It now covers MIP_FILTER none with a T# MIN_LOD, the current variant list, the skip, and the performance numbers CnRJay asked for.

What I ran

Head ed711db0e04ad91314a1bf86d401cefad583e463, main 4f41f4c375f5abb487dbd184fbc150f31994d762, merged with --no-ff into tree 053d856db5, in a clean worktree. Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6). This device has no VK_EXT_image_view_min_lod.

git diff --check 4f41f4c375...ed711db0e0
python3 tools/check_conventions.py --base 4f41f4c375
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 VK_LOADER_DEBUG=error,warn,layer \
  ctest --test-dir build -V -R '^agc_driver_image_gather_lod$'
# negative control: the 6 production files of the PR restored from main
git show 4f41f4c375:<path> > <path>
ninja -C build agc_driver_image_gather_lod_tests agc_driver_native_multisample_depth_tests
ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build --output-on-failure -R '^agc_driver_image_gather_lod$'
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 \
  ctest --test-dir build -V -R '^agc_driver_native_depth_uniform_planes$'
# restore the merged files from 053d856db5, rebuild, rerun both; git status --porcelain is clean
Check Result
git diff --check Clean
check_conventions.py All conventions checks passed
Build (script) OK
Selected tests (script) 2179 run, no new failures, no timeouts. All 7 failures also fail on main
agc_driver_image_gather_lod, merged tree, validation layer Passed in 0.93 s. It printed T# MIN_LOD cases skipped, the device has no VK_EXT_image_view_min_lod, the layer was inserted, and the log has no VUID- lines
Script's validation diff One new-VUID entry: agc_driver_native_depth_uniform_planes reports VUID-vkCmdDispatch-groupCountX-00386, but the baseline never ran that test. I reran it with main's production files: the same VUID appears 8 times there too. It is not from this PR

Negative control

I restored the PR's six production files from main and kept the new test. The test fails on its first variant:

Output
AGC graphics: clamp to edge, point: thread 1 (LOD 1.000000, level 1) component 0 is 108, expected 113

With the merged files restored, the test passes again, and git status --porcelain is empty.

Previous findings

  1. The description no longer matched the code (non-blocking): Resolved. "What" now gives the MIP_FILTER none level as the T# MIN_LOD above the base level, rounded down. The variant list names MIP_FILTER none, T# MIN_LOD 2.5, and the mirror-once VkSamplerCreateInfo IDs are gone.

New findings

Blocking

  1. Specialization ids collide for sampler indices 32–63. This confirms oneandonlydean's 11:24 comment, with two extra pieces of evidence.
    • When it started. The 32-wide ranges were safe when I approved: at bb04a4f1ea, ShaderInfo::MaxSamplers was 32. Commit 12b89239c7 ("raise the sampler and sampled-pair limits past the 32-bit sampler masks") raised it to 64, at ShaderInfo.hpp:16. The rebase kept the 32-wide spacing at PipelineSpecialization.hpp:53-55.
    • Which ids collide. GatherLodBase + 32 = 57696 = GatherLodBiasBase + 0, and GatherLodBiasBase + 32 = 57728 = GatherImageMinLodBase + 0.
    • Effect in the shader. SpirvModule::SpecializationConstant returns the already-declared constant for a known id. So in SpirvImageEmitter.cpp:879-880, sampler 32's state word and sampler 0's bias share one OpSpecConstant, and the second declaration's default is lost.
    • Effect in the plan. DescriptorBindingBuilder.cpp:406-407 and :415 push 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.
    • Result. A shader with more than 32 samplers that gathers at an explicit LOD through a high-index sampler reads a wrong LOD state, bias or min LOD. No test covers this.
    • Suggested fix. Make each per-sampler range 64 wide (GatherLodBase 57664, GatherLodBiasBase 57728, GatherImageMinLodBase 57792). Add a static_assert that ties each range width to ShaderInfo::MaxSamplers / MaxImages, where both headers are visible (for example in DescriptorBindingBuilder.cpp).

Non-blocking

None.

Not verified

  • The T# MIN_LOD variants were skipped here, because lavapipe lacks VK_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.
  • No shader with more than 32 samplers was compiled to show the collision at run time. The finding comes from reading the code and the id arithmetic.
  • The PPSA23276 in-game result and the cost numbers are author-reported.

To get this to a good state

  • Widen the two sampler ranges to MaxSamplers and move GatherImageMinLodBase after them, with a static_assert per range.
  • Rerun agc_driver_image_gather_lod with the validation layer.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5751502937 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12790#pullrequestreview-5751502937). Originally posted by [XairRrR](https://github.com/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_LOD` variants only when the device has `VK_EXT_image_view_min_lod`. The PR was also rebased onto `4f41f4c375`, 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 - **New commit `ed711db0e0` (test only).** `ImageGatherLod.cpp` reads `graphicsContext().imageViewMinLod` through a `VulkanDeviceTestAccess` accessor. When the extension is missing, it skips the two `T# MIN_LOD 2.5` variants and prints that it did. This is the change jotitadev checked on lavapipe. - **Rebase onto `main` `4f41f4c375`.** `GatherLodBase`, `GatherLodBiasBase` and `GatherImageMinLodBase` moved from 57536/57568/57600 to 57664/57696/57728, because `main` now uses 57536 and 57600. Commits 1–4 are otherwise unchanged; I compared them with delta.patch. - **Description.** It now covers `MIP_FILTER` none with a T# `MIN_LOD`, the current variant list, the skip, and the performance numbers CnRJay asked for. ## What I ran Head `ed711db0e04ad91314a1bf86d401cefad583e463`, `main` `4f41f4c375f5abb487dbd184fbc150f31994d762`, merged with `--no-ff` into tree `053d856db5`, in a clean worktree. Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6). This device has no `VK_EXT_image_view_min_lod`. ```sh git diff --check 4f41f4c375...ed711db0e0 python3 tools/check_conventions.py --base 4f41f4c375 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 VK_LOADER_DEBUG=error,warn,layer \ ctest --test-dir build -V -R '^agc_driver_image_gather_lod$' # negative control: the 6 production files of the PR restored from main git show 4f41f4c375:<path> > <path> ninja -C build agc_driver_image_gather_lod_tests agc_driver_native_multisample_depth_tests ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build --output-on-failure -R '^agc_driver_image_gather_lod$' VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 \ ctest --test-dir build -V -R '^agc_driver_native_depth_uniform_planes$' # restore the merged files from 053d856db5, rebuild, rerun both; git status --porcelain is clean ``` | Check | Result | |---|---| | `git diff --check` | Clean | | `check_conventions.py` | All conventions checks passed | | Build (script) | OK | | Selected tests (script) | 2179 run, no new failures, no timeouts. All 7 failures also fail on `main` | | `agc_driver_image_gather_lod`, merged tree, validation layer | Passed in 0.93 s. It printed `T# MIN_LOD cases skipped, the device has no VK_EXT_image_view_min_lod`, the layer was inserted, and the log has no `VUID-` lines | | Script's validation diff | One new-VUID entry: `agc_driver_native_depth_uniform_planes` reports `VUID-vkCmdDispatch-groupCountX-00386`, but the baseline never ran that test. I reran it with `main`'s production files: the same VUID appears 8 times there too. It is not from this PR | ## Negative control I restored the PR's six production files from `main` and kept the new test. The test fails on its first variant: <details><summary>Output</summary> ``` AGC graphics: clamp to edge, point: thread 1 (LOD 1.000000, level 1) component 0 is 108, expected 113 ``` </details> With the merged files restored, the test passes again, and `git status --porcelain` is empty. ## Previous findings 1. **The description no longer matched the code (non-blocking): Resolved.** "What" now gives the `MIP_FILTER` none level as the T# `MIN_LOD` above the base level, rounded down. The variant list names `MIP_FILTER none, T# MIN_LOD 2.5`, and the mirror-once `VkSamplerCreateInfo` IDs are gone. ## New findings ### Blocking 1. **Specialization ids collide for sampler indices 32–63.** This confirms oneandonlydean's 11:24 comment, with two extra pieces of evidence. - **When it started.** The 32-wide ranges were safe when I approved: at `bb04a4f1ea`, `ShaderInfo::MaxSamplers` was 32. Commit `12b89239c7` ("raise the sampler and sampled-pair limits past the 32-bit sampler masks") raised it to 64, at [`ShaderInfo.hpp:16`](https://github.com/boykopovar/AnyPS5/blob/4f41f4c375f5abb487dbd184fbc150f31994d762/core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/ShaderInfo.hpp#L16-L16). The rebase kept the 32-wide spacing at [`PipelineSpecialization.hpp:53-55`](https://github.com/boykopovar/AnyPS5/blob/ed711db0e04ad91314a1bf86d401cefad583e463/core/shader/recompiler/PipelineSpecialization.hpp#L53-L55). - **Which ids collide.** `GatherLodBase + 32` = 57696 = `GatherLodBiasBase + 0`, and `GatherLodBiasBase + 32` = 57728 = `GatherImageMinLodBase + 0`. - **Effect in the shader.** [`SpirvModule::SpecializationConstant`](https://github.com/boykopovar/AnyPS5/blob/4f41f4c375f5abb487dbd184fbc150f31994d762/core/shader/recompiler/SpirvBackend/src/SpirvModule.cpp#L180-L181) returns the already-declared constant for a known id. So in [`SpirvImageEmitter.cpp:879-880`](https://github.com/boykopovar/AnyPS5/blob/ed711db0e04ad91314a1bf86d401cefad583e463/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L879-L880), sampler 32's state word and sampler 0's bias share one `OpSpecConstant`, and the second declaration's default is lost. - **Effect in the plan.** [`DescriptorBindingBuilder.cpp:406-407`](https://github.com/boykopovar/AnyPS5/blob/ed711db0e04ad91314a1bf86d401cefad583e463/core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp#L406-L407) and [`:415`](https://github.com/boykopovar/AnyPS5/blob/ed711db0e04ad91314a1bf86d401cefad583e463/core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp#L415-L415) push 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. - **Result.** A shader with more than 32 samplers that gathers at an explicit LOD through a high-index sampler reads a wrong LOD state, bias or min LOD. No test covers this. - **Suggested fix.** Make each per-sampler range 64 wide (`GatherLodBase` 57664, `GatherLodBiasBase` 57728, `GatherImageMinLodBase` 57792). Add a `static_assert` that ties each range width to `ShaderInfo::MaxSamplers` / `MaxImages`, where both headers are visible (for example in `DescriptorBindingBuilder.cpp`). ### Non-blocking None. ## Not verified - The T# `MIN_LOD` variants were skipped here, because lavapipe lacks `VK_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. - No shader with more than 32 samplers was compiled to show the collision at run time. The finding comes from reading the code and the id arithmetic. - The PPSA23276 in-game result and the cost numbers are author-reported. ## To get this to a good state - Widen the two sampler ranges to `MaxSamplers` and move `GatherImageMinLodBase` after them, with a `static_assert` per range. - Rerun `agc_driver_image_gather_lod` with the validation layer. <!-- anyps5-bots job=3309 head=ed711db0e04ad91314a1bf86d401cefad583e463 -->
XairRrR commented 2026-11-03 17:51:16 +00:00 (Migrated from github.com)

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 moves GatherLodBase, GatherLodBiasBase and GatherImageMinLodBase to 57856, 57920 and 57984, and adds a static_assert for each range in DescriptorBindingBuilder.cpp. This resolves the id collision for samplers 32–63.

What changed since my last review

  • New commit 702dee4ae3, which touches two files:
    • PipelineSpecialization.hpp:53-55: the three bases are now GatherLodBase 57856, GatherLodBiasBase 57920 and GatherImageMinLodBase 57984. Each sampler range is 64 wide, and the image range has room for 128 images.
    • DescriptorBindingBuilder.cpp:22-25: four static_asserts chain MinLodBase + MaxImages → the two sampler ranges (+ MaxSamplers each) → GatherImageMinLodBase + MaxImages ≤ ImageComponentBase.
  • Commits 1–5 are unchanged (delta.patch shows them as =).
  • The description and the author's 17:33 reply explain why the bases start above 57728 rather than at the 57664 or 57728 that oneandonlydean suggested: open PRs #10489, #9183 and #14621 use ids there. I did not check those PRs, which are outside this tree. On main 1e658521a0, nothing else uses 57856–58111: the named bases end at MinLodBase 57600 + 64, and the next is ImageComponentBase 65536. DescriptorIndex with stride 128 from 16384 is used only for small kind values.

What I ran

Head 702dee4ae314719b94b117193022dcab7750ed14, main 1e658521a0a599872612bb91949311e2956b5283, merged with --no-ff into tree 166f09675b, in a clean worktree. Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6). This device has no VK_EXT_image_view_min_lod.

git diff --check 1e658521a0...702dee4ae3
python3 tools/check_conventions.py --base 1e658521a0
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 VK_LOADER_DEBUG=error,warn,layer \
  ctest --test-dir build -V -R '^agc_driver_image_gather_lod$'
# check of the new asserts: put GatherLodBiasBase back to a 32-wide spacing (57888) and compile only DescriptorBindingBuilder.cpp.o
ninja -C build -j32 -l32 <DescriptorBindingBuilder.cpp.o>
# restore PipelineSpecialization.hpp from 166f09675b, then rebuild and rerun
ninja -C build -j32 -l32 agc_driver_image_gather_lod_tests
ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build --output-on-failure -R '^agc_driver_image_gather_lod$'
git status --porcelain
Check Result
git diff --check Clean
check_conventions.py All conventions checks passed
Build (script) OK
Selected tests (script) 2170 run, no new failures, no timeouts. The 7 failures all also fail on main
Script's validation diff 773 tests, layer loaded in 772 and missing in none, 0 tests with a new VUID-
agc_driver_image_gather_lod, with the validation layer Passed in 0.91 s. The layer was inserted, no VUID- lines, and it printed T# MIN_LOD cases skipped, the device has no VK_EXT_image_view_min_lod
New asserts with a 32-wide sampler range Compile fails with DescriptorBindingBuilder.cpp:23:79: error: static assertion failed
After restoring the merged files Rebuilt, the test passes, git status --porcelain is empty

Negative 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_lod fails on its first variant. For the new code, I put the sampler range back to 32 wide, and the new static_assert stopped the build as intended.

Previous findings

  1. Specialization ids collide for sampler indices 32–63 (blocking): Resolved.
    • GatherLodBase + 63 = 57919, just below GatherLodBiasBase (57920).
    • GatherLodBiasBase + 63 = 57983, just below GatherImageMinLodBase (57984).
    • GatherImageMinLodBase + 63 = 58047, far below 65536.
    • The asserts tie these widths to ShaderInfo::MaxSamplers and MaxImages (both 64 on main), and I confirmed that they fire on a 32-wide range.

New findings

Blocking

None.

Non-blocking

None.

Not verified

  • The T# MIN_LOD variants were skipped here, because lavapipe has no VK_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.
  • No shader with more than 32 samplers that gathers at an explicit LOD was compiled or run. The fix is checked by the id arithmetic and the asserts only, which the author also notes.
  • I did not check the id use of the open PRs named in the description (#10489, #9183, #14621); only main is in this tree. As the author says, whichever of this PR and #10489 lands second has to chain its range to the other's.
  • The PPSA23276 in-game result and the cost numbers are author-reported.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5757028278 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12790#pullrequestreview-5757028278). Originally posted by [XairRrR](https://github.com/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 moves `GatherLodBase`, `GatherLodBiasBase` and `GatherImageMinLodBase` to 57856, 57920 and 57984, and adds a `static_assert` for each range in `DescriptorBindingBuilder.cpp`. This resolves the id collision for samplers 32–63. ## What changed since my last review - **New commit `702dee4ae3`**, which touches two files: - [`PipelineSpecialization.hpp:53-55`](https://github.com/boykopovar/AnyPS5/blob/702dee4ae314719b94b117193022dcab7750ed14/core/shader/recompiler/PipelineSpecialization.hpp#L53-L55): the three bases are now `GatherLodBase` 57856, `GatherLodBiasBase` 57920 and `GatherImageMinLodBase` 57984. Each sampler range is 64 wide, and the image range has room for 128 images. - [`DescriptorBindingBuilder.cpp:22-25`](https://github.com/boykopovar/AnyPS5/blob/702dee4ae314719b94b117193022dcab7750ed14/core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp#L22-L25): four `static_assert`s chain `MinLodBase + MaxImages` → the two sampler ranges (`+ MaxSamplers` each) → `GatherImageMinLodBase + MaxImages` ≤ `ImageComponentBase`. - **Commits 1–5 are unchanged** (delta.patch shows them as `=`). - **The description and the author's 17:33 reply** explain why the bases start above 57728 rather than at the 57664 or 57728 that oneandonlydean suggested: open PRs #10489, #9183 and #14621 use ids there. I did not check those PRs, which are outside this tree. On `main` `1e658521a0`, nothing else uses 57856–58111: the named bases end at `MinLodBase` 57600 + 64, and the next is `ImageComponentBase` 65536. `DescriptorIndex` with stride 128 from 16384 is used only for small `kind` values. ## What I ran Head `702dee4ae314719b94b117193022dcab7750ed14`, `main` `1e658521a0a599872612bb91949311e2956b5283`, merged with `--no-ff` into tree `166f09675b`, in a clean worktree. Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6). This device has no `VK_EXT_image_view_min_lod`. ```sh git diff --check 1e658521a0...702dee4ae3 python3 tools/check_conventions.py --base 1e658521a0 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 VK_LOADER_DEBUG=error,warn,layer \ ctest --test-dir build -V -R '^agc_driver_image_gather_lod$' # check of the new asserts: put GatherLodBiasBase back to a 32-wide spacing (57888) and compile only DescriptorBindingBuilder.cpp.o ninja -C build -j32 -l32 <DescriptorBindingBuilder.cpp.o> # restore PipelineSpecialization.hpp from 166f09675b, then rebuild and rerun ninja -C build -j32 -l32 agc_driver_image_gather_lod_tests ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build --output-on-failure -R '^agc_driver_image_gather_lod$' git status --porcelain ``` | Check | Result | |---|---| | `git diff --check` | Clean | | `check_conventions.py` | All conventions checks passed | | Build (script) | OK | | Selected tests (script) | 2170 run, no new failures, no timeouts. The 7 failures all also fail on `main` | | Script's validation diff | 773 tests, layer loaded in 772 and missing in none, 0 tests with a new `VUID-` | | `agc_driver_image_gather_lod`, with the validation layer | Passed in 0.91 s. The layer was inserted, no `VUID-` lines, and it printed `T# MIN_LOD cases skipped, the device has no VK_EXT_image_view_min_lod` | | New asserts with a 32-wide sampler range | Compile fails with `DescriptorBindingBuilder.cpp:23:79: error: static assertion failed` | | After restoring the merged files | Rebuilt, the test passes, `git status --porcelain` is empty | ## Negative 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_lod` fails on its first variant. For the new code, I put the sampler range back to 32 wide, and the new `static_assert` stopped the build as intended. ## Previous findings 1. **Specialization ids collide for sampler indices 32–63 (blocking): Resolved.** - `GatherLodBase + 63` = 57919, just below `GatherLodBiasBase` (57920). - `GatherLodBiasBase + 63` = 57983, just below `GatherImageMinLodBase` (57984). - `GatherImageMinLodBase + 63` = 58047, far below 65536. - The asserts tie these widths to `ShaderInfo::MaxSamplers` and `MaxImages` (both 64 on `main`), and I confirmed that they fire on a 32-wide range. ## New findings ### Blocking None. ### Non-blocking None. ## Not verified - The T# `MIN_LOD` variants were skipped here, because lavapipe has no `VK_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. - No shader with more than 32 samplers that gathers at an explicit LOD was compiled or run. The fix is checked by the id arithmetic and the asserts only, which the author also notes. - I did not check the id use of the open PRs named in the description (#10489, #9183, #14621); only `main` is in this tree. As the author says, whichever of this PR and #10489 lands second has to chain its range to the other's. - The PPSA23276 in-game result and the cost numbers are author-reported. <!-- anyps5-bots job=3482 head=702dee4ae314719b94b117193022dcab7750ed14 -->
XairRrR commented 2026-11-03 20:37:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T20:37:09Z.

Review: APPROVED


Re-checked — approved

The branch was rebased onto main 086c0686c8 after #9183 landed. Both 2D and 3D gather branches stay in EmitGatherOp, and the first static_assert now starts from VolumeGatherBase. Checks pass, the negative control fails, and the PR adds no new validation IDs.

What changed since my last review

  • Rebase onto main 086c0686c8, which now has #9183 (VolumeGatherBase 57664, EmitVolumeGatherLz).
    • In commits 2–5, the intermediate ids are now 57856, 57888 and 57920.
    • The final ids are unchanged: GatherLodBase 57856, GatherLodBiasBase 57920, GatherImageMinLodBase 57984.
  • DescriptorBindingBuilder.cpp:22: the first assert is now VolumeGatherBase + 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.
    • EmitTwoDimensionalGatherLod is identical to what I reviewed before.
    • Its guard still requires Dim2D.
  • The description and the 20:10 reply describe this rebase. Both say that apart from the assert the diff is the one I approved. delta.patch agrees: commits 4 and 5 are =, and the other changes are context lines and the id lines above.

What I ran

Head 48e75dd9d096d738f9318d49329ad050081e4b09, main 086c0686c8adff3ee648fdbe34e0b0b647e1d511, merged with --no-ff into tree be2973f389, in a clean worktree. Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6). This device has no VK_EXT_image_view_min_lod.

git diff --check 086c0686c8...48e75dd9d0
python3 tools/check_conventions.py --base 086c0686c8
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 VK_LOADER_DEBUG=error,warn,layer \
  ctest --test-dir build -V -R '^agc_driver_image_gather_(lod|volume)$'
# negative control: restore the six production files from 086c0686c8
ninja -C build -j32 -l32 agc_driver_image_gather_lod_tests agc_driver_image_gather_volume_tests
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 \
  ctest --test-dir build -V -R '^agc_driver_image_gather_(lod|volume)$'
# restore from be2973f389, rebuild, rerun
ninja -C build -j32 -l32 agc_driver_image_gather_lod_tests agc_driver_image_gather_volume_tests
ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build --output-on-failure -R '^agc_driver_image_gather_(lod|volume)$'
git status --porcelain
Check Result
git diff --check Clean
check_conventions.py All conventions checks passed
Build (script) OK
Selected tests (script) 2188 run, no new failures, no timeouts. The 7 failures are all known on main
Script's validation diff 784 tests; the layer loaded in 783 and was missing in none. One test has "new" VUID-s: agc_driver_image_gather_volume, which was not in the older baseline (see below)
agc_driver_image_gather_lod, with the validation layer Passed (0.95 s). The layer was inserted, there were no VUID- lines, and the T# MIN_LOD cases were skipped (no extension)
agc_driver_image_gather_volume, with the validation layer Passed (9.6 s). It logs four VUID-VkSamplerCreateInfo-addressMode* IDs
Same two tests with main's production files gather_lod fails. gather_volume passes and logs the same four VUID-s
After restoring the merged files Both pass, and git status --porcelain is empty
Negative control output (main's production files)
1234: AGC graphics: clamp to edge, point: thread 1 (LOD 1.000000, level 1) component 0 is 108, expected 113
1/2 Test #1234: agc_driver_image_gather_lod ......***Failed    0.19 sec
1237: Validation Error: [ VUID-VkSamplerCreateInfo-addressModeU-parameter ]
1237: Validation Error: [ VUID-VkSamplerCreateInfo-addressModeV-parameter ]
1237: Validation Error: [ VUID-VkSamplerCreateInfo-addressModeW-parameter ]
1237: Validation Error: [ VUID-VkSamplerCreateInfo-addressModeU-01079 ]
2/2 Test #1237: agc_driver_image_gather_volume ...   Passed    9.61 sec

The script's validation baseline is main 1e658521a0, which predates #9183, so it marked agc_driver_image_gather_volume as "test not run on main". With this PR's production files reverted to 086c0686c8, the test logs the same four IDs. They come from main's mirror-once sampler created without samplerMirrorClampToEdge, as the author says, and do not count against this PR.

Previous findings

  1. Specialization ids collide for sampler indices 32–63 (blocking, resolved in my last review): still resolved. The bases are 57856, 57920 and 57984, each sampler range is 64 wide, and the image range is now chained from VolumeGatherBase (57664–57727). The four asserts compile on the merged tree.

New findings

Blocking

None.

Non-blocking

  • The debt entry is out of date for 3D images after the rebase. docs/dev/debt/shader.md:252 lists "3D and cube images" among those that "still gather the base level". On main since #9183, though, a 3D gather without the LZ flag fails compilation with "has an unsupported 3D gather variant" (SpirvImageEmitter.cpp:1594-1597 on main; SpirvImageEmitter.cpp:1695-1698 in the merged tree). So a 3D image_gather4_l throws; 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 images image_gather4_l throws".

Not verified

  • The T# MIN_LOD variants were skipped, because lavapipe has no VK_EXT_image_view_min_lod. Results on devices that have it are author- or contributor-reported, and the contributor runs were on earlier heads.
  • No shader with more than 32 samplers that gathers at an explicit LOD was compiled or run.
  • I did not check the id use of the open PRs named in the description (#10489, #14621); only main is in this tree.
  • The PPSA23276 in-game result and the cost numbers are author-reported and predate this rebase.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5759121462 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12790#pullrequestreview-5759121462). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T20:37:09Z. **Review:** APPROVED --- # Re-checked — approved The branch was rebased onto `main` `086c0686c8` after #9183 landed. Both 2D and 3D gather branches stay in `EmitGatherOp`, and the first `static_assert` now starts from `VolumeGatherBase`. Checks pass, the negative control fails, and the PR adds no new validation IDs. ## What changed since my last review - **Rebase onto `main` `086c0686c8`**, which now has #9183 (`VolumeGatherBase` 57664, `EmitVolumeGatherLz`). - In commits 2–5, the intermediate ids are now 57856, 57888 and 57920. - The final ids are unchanged: `GatherLodBase` 57856, `GatherLodBiasBase` 57920, `GatherImageMinLodBase` 57984. - **`DescriptorBindingBuilder.cpp:22`**: the first assert is now `VolumeGatherBase + 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. - `EmitTwoDimensionalGatherLod` is identical to what I reviewed before. - Its guard still requires `Dim2D`. - **The description and the 20:10 reply** describe this rebase. Both say that apart from the assert the diff is the one I approved. `delta.patch` agrees: commits 4 and 5 are `=`, and the other changes are context lines and the id lines above. ## What I ran Head `48e75dd9d096d738f9318d49329ad050081e4b09`, `main` `086c0686c8adff3ee648fdbe34e0b0b647e1d511`, merged with `--no-ff` into tree `be2973f389`, in a clean worktree. Debian 13 VM, GCC 14.2.0, lavapipe (Mesa 26.1.6). This device has no `VK_EXT_image_view_min_lod`. ```sh git diff --check 086c0686c8...48e75dd9d0 python3 tools/check_conventions.py --base 086c0686c8 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 VK_LOADER_DEBUG=error,warn,layer \ ctest --test-dir build -V -R '^agc_driver_image_gather_(lod|volume)$' # negative control: restore the six production files from 086c0686c8 ninja -C build -j32 -l32 agc_driver_image_gather_lod_tests agc_driver_image_gather_volume_tests VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 \ ctest --test-dir build -V -R '^agc_driver_image_gather_(lod|volume)$' # restore from be2973f389, rebuild, rerun ninja -C build -j32 -l32 agc_driver_image_gather_lod_tests agc_driver_image_gather_volume_tests ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build --output-on-failure -R '^agc_driver_image_gather_(lod|volume)$' git status --porcelain ``` | Check | Result | |---|---| | `git diff --check` | Clean | | `check_conventions.py` | All conventions checks passed | | Build (script) | OK | | Selected tests (script) | 2188 run, no new failures, no timeouts. The 7 failures are all known on `main` | | Script's validation diff | 784 tests; the layer loaded in 783 and was missing in none. One test has "new" `VUID-`s: `agc_driver_image_gather_volume`, which was not in the older baseline (see below) | | `agc_driver_image_gather_lod`, with the validation layer | Passed (0.95 s). The layer was inserted, there were no `VUID-` lines, and the T# `MIN_LOD` cases were skipped (no extension) | | `agc_driver_image_gather_volume`, with the validation layer | Passed (9.6 s). It logs four `VUID-VkSamplerCreateInfo-addressMode*` IDs | | Same two tests with `main`'s production files | `gather_lod` fails. `gather_volume` passes and logs the **same four** `VUID-`s | | After restoring the merged files | Both pass, and `git status --porcelain` is empty | <details><summary>Negative control output (main's production files)</summary> ``` 1234: AGC graphics: clamp to edge, point: thread 1 (LOD 1.000000, level 1) component 0 is 108, expected 113 1/2 Test #1234: agc_driver_image_gather_lod ......***Failed 0.19 sec 1237: Validation Error: [ VUID-VkSamplerCreateInfo-addressModeU-parameter ] 1237: Validation Error: [ VUID-VkSamplerCreateInfo-addressModeV-parameter ] 1237: Validation Error: [ VUID-VkSamplerCreateInfo-addressModeW-parameter ] 1237: Validation Error: [ VUID-VkSamplerCreateInfo-addressModeU-01079 ] 2/2 Test #1237: agc_driver_image_gather_volume ... Passed 9.61 sec ``` </details> The script's validation baseline is `main` `1e658521a0`, which predates #9183, so it marked `agc_driver_image_gather_volume` as "test not run on main". With this PR's production files reverted to `086c0686c8`, the test logs the same four IDs. They come from `main`'s mirror-once sampler created without `samplerMirrorClampToEdge`, as the author says, and do not count against this PR. ## Previous findings 1. **Specialization ids collide for sampler indices 32–63 (blocking, resolved in my last review): still resolved.** The bases are 57856, 57920 and 57984, each sampler range is 64 wide, and the image range is now chained from `VolumeGatherBase` (57664–57727). The four asserts compile on the merged tree. ## New findings ### Blocking None. ### Non-blocking - **The debt entry is out of date for 3D images after the rebase.** [`docs/dev/debt/shader.md:252`](https://github.com/boykopovar/AnyPS5/blob/48e75dd9d096d738f9318d49329ad050081e4b09/docs/dev/debt/shader.md#L252) lists "3D and cube images" among those that "still gather the base level". On `main` since #9183, though, a 3D gather without the `LZ` flag fails compilation with "has an unsupported 3D gather variant" ([`SpirvImageEmitter.cpp:1594-1597` on `main`](https://github.com/boykopovar/AnyPS5/blob/086c0686c8adff3ee648fdbe34e0b0b647e1d511/core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp#L1594-L1597); `SpirvImageEmitter.cpp:1695-1698` in the merged tree). So a 3D `image_gather4_l` throws; 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 images `image_gather4_l` throws". ## Not verified - The T# `MIN_LOD` variants were skipped, because lavapipe has no `VK_EXT_image_view_min_lod`. Results on devices that have it are author- or contributor-reported, and the contributor runs were on earlier heads. - No shader with more than 32 samplers that gathers at an explicit LOD was compiled or run. - I did not check the id use of the open PRs named in the description (#10489, #14621); only `main` is in this tree. - The PPSA23276 in-game result and the cost numbers are author-reported and predate this rebase. <!-- anyps5-bots job=3579 head=48e75dd9d096d738f9318d49329ad050081e4b09 -->
gabichuuuuu commented 2026-11-08 11:50:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T11:50:27Z.

Review: COMMENTED


Ran 7c07be9686 merged on main 302864d48c on Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 621) and an Intel iGPU (driver 101.70xx), with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_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_lod fails on the Intel iGPU, in both runs, with the same message:

AGC graphics: T# MIN_LOD 2.5: thread 0 (LOD 0.000000, level 2) component 0 is 0, expected 146

main change, 2 runs each
NVIDIA — 4/4, 4/4
Intel 3/3 3/4, 3/4 (agc_driver_image_gather_lod)
  • The three existing gather tests (one_dimensional, one_dimensional_array, volume) pass on both GPUs with the change.
  • The main control on NVIDIA isn't usable, because the machine slept during it.
  • The layer was inserted in every test. No log has was not found but was requested by env var VK_INSTANCE_LAYERS, and no log on either side has a VUID-, so the Intel result is a wrong value without a validation error.
  • The failing case is the T# MIN_LOD 2.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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5817760223 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12790#pullrequestreview-5817760223). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-08T11:50:27Z. **Review:** COMMENTED --- Ran `7c07be9686` merged on `main` 302864d48c on Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 621) and an Intel iGPU (driver 101.70xx), with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_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_lod` fails on the Intel iGPU**, in both runs, with the same message: > AGC graphics: T# MIN_LOD 2.5: thread 0 (LOD 0.000000, level 2) component 0 is 0, expected 146 | | `main` | change, 2 runs each | |---|---|---| | NVIDIA | — | 4/4, 4/4 | | Intel | 3/3 | 3/4, 3/4 (`agc_driver_image_gather_lod`) | - The three existing gather tests (`one_dimensional`, `one_dimensional_array`, `volume`) pass on both GPUs with the change. - The `main` control on NVIDIA isn't usable, because the machine slept during it. - The layer was inserted in every test. No log has `was not found but was requested by env var VK_INSTANCE_LAYERS`, and no log on either side has a `VUID-`, so the Intel result is a wrong value without a validation error. - The failing case is the T# `MIN_LOD` 2.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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!12790
No description provided.