fix(shader): pick image_gather4_l levels as RDNA2 does, also on 2D arrays #23666
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23666"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-11-19T12:11:41Z.
What
image_gather4_lon a 2D image is emulated: the shader picks the level and gathers its four footprint texels (#12790). The debt entry listed the level rule as unverified. It rounded to the nearest level with ties down (ceil(lod + 0.5) - 1). Measured on gfx1036, the hardware picks levelfloor(lod + 0.5 + 1/512):So LOD 0.5 reads level 1, not 0, and LOD 1.498046875 (383.5/256) already reads level 2. The rule holds after
LOD_BIAS, the S#MIN_LODandMAX_LOD, the T#MIN_LODand a nonzeroBASE_LEVEL. With a linearMIP_FILTERthe gather reads the same single level.SpirvImageEmitter.cpp(EmitTwoDimensionalGatherLod):floor(lod + 0.501953125), clamped as before (0.501953125 is exact in f32);clamp(RoundEven(z), 0, layers - 1)as for native array sampling, and the footprint is fetched from that layer. 3D and cube images still use the native gather.Explicit-LOD gathersentry records the measured rule. It drops from "unverified" the steps measured here: bias, S# and T# clamps, base level, linear and none mip filters. It keepsLOD_BIAS_SEC, mirror-once and the ±2^24 coordinate clamp as unverified.Measurement:
tools/hw-oracleon gfx1036, 16x16 32_FLOAT with five levels, texel = level·1000 + row·10 + column,image_gather4_lagainstagc_oracle_runner. The LODs were 0, 0.25, 0.49, 0.5, 0.51, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.5, 3.5, 4, 4.5, 6, -0.5, -1, 0.999, 1.4999, 2.5001 and 3.49:main, NVIDIA / AMDMIP_FILTERMIP_FILTERMIP_FILTERnone,BASE_LEVEL0 and 2LOD_BIAS+0.5LOD_BIAS-1.25MIN_LOD1.5MAX_LOD2.25BASE_LEVEL1;BASE_LEVEL1 withLAST_LEVEL3MIN_LOD1.5 and 2.25; 1.5 withBASE_LEVEL1MIN_LOD0.75 and 1.5 withMIP_FILTERnoneAround the threshold, LOD·256 of 382.5, 383, 383.25 and 383.495 reads level 1, while 383.5, 383.505, 383.75, 384 and 384.5 read level 2. Likewise 127.495 reads level 0 and 127.5 reads level 1, and 639.495 reads level 2 and 639.5 level 3. On these 22 LODs the branch matches 22/22 on both GPUs, against 13/22 on
main. On the hardware,image_sample_lwith a pointMIP_FILTERpicks the same levels as the gather in every row.2D arrays: 16x16, five levels, three layers. Every dword of the blob is distinct, so a wrong level or layer cannot match by accident. There are 32 rows of slices from -1 to 7 and LODs from -1 to 6:
main, NVIDIA / AMDMIP_FILTERLOD_BIAS+0.5MIN_LOD1.5,MAX_LOD3BASE_ARRAY1,BASE_LEVEL1, wrap addressingMIP_FILTERnoneAddress modes: 32 rows with u and v in [-2.5, 3.5] were gathered with S# clamp modes wrap, mirror, clamp to last texel and mirror once on both axes, and mirror once on x only. Each matches the hardware on 32/32 on both GPUs, so the debt entry no longer lists mirror once as unverified. Coordinates past ±2^24 texels do not match: the emulation clamps them, while the hardware keeps wrapping them at higher precision. For example, at u·W = 2^24 + 4.8 the hardware anchors at texel 3 with wrap. The entry now states this, and nothing changes for it here.
Tested
Windows 11 Pro 10.0.26200, MinGW Release build.
ctest --test-dir build -R '^agc_driver_image_gather|^agc_driver_image_sample|^agc_shader_memory$' -VwithANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, onmainand on this branch. The GPUs were an NVIDIA GeForce RTX 5080 (610.74) and an AMD Radeon(TM) Graphics iGPU (gfx1036, 32.0.21045.16010).mainNVIDIAmainAMDInsert instance layer "VK_LAYER_KHRONOS_validation"was not found but was requestedVUID-The two NVIDIA failures on both sides are
agc_driver_image_sample_lod_clampandagc_driver_image_sample_lod_clamp_shader_lane, theimage_sample_d_clMIN_LOD failure of #23232.agc_driver_image_gather_lod:MIP_FILTERnone;MIN_LOD/MAX_LODwithLOD_BIAS,MIP_FILTERnone), with slices inside and outside the range;MIN_LODcases run.main'sSpirvImageEmitter.cpp:clamp to edge, point: thread 7 (LOD 0.500000, level 1) component 0 is 134, expected 113);2D array, clamp to edge, point: thread 1 (LOD 1.000000, level 1) component 0 is 145, expected 150).tools/pr_overlap.pycould not compareSpirvImageEmitter.cppwith 21 PRs that conflict withmain. Of those, only #16935 rounds an LOD, and it does so in its unnormalized-sample path, not inEmitTwoDimensionalGatherLod. Not tested on a PS5.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T13:20:10Z.
Review: APPROVED
Reviewed — looks good
Nothing in the inspected shader changes blocks merging; the prepared description reports hardware checks, but I did not run them.
What I ran
Inspected the prepared diff and targeted source at head
ab48570bc3905598bfd8754b9cf9e05e0bd0bd97. I did not run commands, tests, or a build.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I read
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp,core/libs/prx/libSceAgcDriver/tests/execution/ImageGatherLod.cpp, anddocs/dev/debt/changes/fix-gather4-l-level-rounding.md. All three changed files listed as reviewed in the manifest were read in targeted ranges, not in full. The reader returned no files inreview/files; the shader emitter's full text was not read. I did not independently verify the reported GPU measurements, test results, PS5 behavior, other platform builds, or repository CI.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-29T23:26:16Z.
Review: COMMENTED
Actionable comments posted: 2
fba72d5c-71d0-4e28-a200-8915ed39c363Reviewing files that changed from the base of the PR and between
1f27e2abfaandb259073e4a.core/libs/prx/libSceAgcDriver/tests/execution/ImageGatherLod.cppcore/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cppdocs/dev/debt/changes/fix-gather4-l-level-rounding.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T23:29:59Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation and tests support the described 2D and 2D-array LOD gather behavior.
What I ran
Reviewed head
b259073e4a493c281d4c48f2a689c1f24fc7d2fe. No commands or tests were run; the author reports GPU measurements and Windows test runs in the PR description.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No local build, automated tests, or PS5 hardware run was performed. The PR description's reported GPU measurements and Windows test output were not independently verified. No changed files were excluded;
files.jsonwas unavailable, so excluded-by-rule entries could not be independently checked.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T21:57:10Z.
Review: COMMENTED
The LOD boundary test at 1.498046875 distinguishes the measured two-stage quantization from ordinary nearest-level selection, and the new array fixture checks ties and clamping for the layer. Please add a nonzero
BASE_ARRAYcase while keeping relative layer coordinates the same, to cover the view offset as well as the new rounding. The paired gather fixture is queued on lavapipe.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.