fix(shader): size an explicit-LOD gather's level from the base level's extent #24100

Merged
GiannisG1 merged 1 commit from upstream-pr/24100 into main 2026-11-21 11:04:47 +00:00
GiannisG1 commented 2026-11-20 06:12:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GiannisG1 on 2026-11-20T06:12:14Z.


What

agc_driver_image_gather_lod fails in main's Linux job (run 44639208734) with clamp to edge, point: thread 1 (LOD 1.000000, level 1) component 0 is 0, expected 113. The runner's device is llvmpipe (LLVM 20.1.2, 256 bits), the string Ubuntu 24.04's Mesa 25.2.8-0ubuntu0.24.04.4 reports, and the test fails the same way on it here.

The image_gather4_l emulation (EmitTwoDimensionalGatherLod, #12790) takes each lane's level size from OpImageQuerySizeLod at that lane's level. llvmpipe before Mesa 26.0 answers a size query with the first lane's LOD for the whole vector (lp_build_size_query_soa in 25.2.8, L4354-L4356: /* FIXME: this needs to honor per-element lod */, then LLVMBuildExtractElement(..., params->explicit_lod, 0); 26.0.8 uses params->explicit_lod per element, L4352). Lanes at another level then scale their coordinates by that level's extent. In the test's first case (clamp to edge, point), all 32 lanes give exactly what that predicts for groups of 8 lanes (llvmpipe's vector width here): each lane gathers from its own level with the extent of its group's first lane's level, so only lanes whose level differs from that lane's are wrong.

The query now uses LOD 0, and each lane's extent is max(1, extent >> level). That is the level size Vulkan defines ("Image mip level sizing"), also for a view whose base level is not 0, so the result does not change on a driver that honours the per-lane LOD. The fallback to the T# extent when the query returns 0 is unchanged.

#23666 changes the same OpImageQuerySizeLod line (it adds the layer count for 2D arrays). Whichever merges second needs a one-line rebase; I can rebase this one onto #23666.

Tested

Linux Mint 22.3, kernel 7.0.0-38, GCC 13.3.0, Release, under Xvfb, head on main d50640e264. lavapipe from Mesa 26.0.8 was built from the release tarball and selected with VK_DRIVER_FILES.

Device main this PR, 3 runs
llvmpipe, Mesa 25.2.8 (LLVM 20.1.2) agc_driver_image_gather_lod fails 3/3 with the job's message passes 3/3
lavapipe, Mesa 26.0.8 passes passes 3/3
GTX 1050 Ti, 580.178.04 passes passes 3/3
Intel HD 630, Mesa 25.2.8 ANV passes passes 3/3
  • Validation layer 1.4.363.1 (LunarG SDK), VK_LOADER_DEBUG=layer, on agc_driver_image_gather_lod, _one_dimensional, _one_dimensional_array and _volume, main and this PR, all four devices: the loader inserts the layer in every test, no VUID-, SYNC-HAZARD- or UNASSIGNED- message on either side. main fails only agc_driver_image_gather_lod on llvmpipe 25.2.8; this PR passes all four tests on all four devices.
  • Split suite (tools/suite.py: every test once, GPU tests on the GTX 1050 Ti, the HD 630 and llvmpipe) on this PR, compared with the same suite of another branch on the same base (#24088, a libSceIcu change) on the same machine: the only difference is agc_driver_image_gather_lod, which fails on llvmpipe there and passes here. Both: GTX 1050 Ti 6338 run, 0 failed; HD 630 1457 GPU tests, the same 10 failures (the 9 of main 0626a8334f's own run and agc_driver_frame_replay_rewind_copy, intermittent, #22028); llvmpipe agc_driver_image_table_packed_guards, agc_driver_scattered_runs and agc_driver_sparse_dma_buf_straddle (the last from #23272, which this base still has).
  • check_conventions.py, check_test_registration.py, check_main_sync.py (merges cleanly with current main), check_compile.py and git diff --check are clean. pr_overlap.py --branch: #23666, as above. Of the 22 pull requests it could not compare (they conflict with main), none changes a line this PR changes; the two whose diffs share a line text with it (#6280, #7085) do so in DecodeSrgbTexel, another function.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: none
  • GPUs tested: NVIDIA GeForce GTX 1050 Ti (580.178.04), Intel HD Graphics 630 (Mesa 25.2.8 ANV), llvmpipe (Mesa 25.2.8, LLVM 20.1.2), lavapipe (Mesa 26.0.8); Linux Mint 22.3
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5408728901 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24100). Originally posted by [GiannisG1](https://github.com/GiannisG1) on 2026-11-20T06:12:14Z. --- ### What `agc_driver_image_gather_lod` fails in `main`'s Linux job (run 44639208734) with `clamp to edge, point: thread 1 (LOD 1.000000, level 1) component 0 is 0, expected 113`. The runner's device is `llvmpipe (LLVM 20.1.2, 256 bits)`, the string Ubuntu 24.04's Mesa `25.2.8-0ubuntu0.24.04.4` reports, and the test fails the same way on it here. The `image_gather4_l` emulation (`EmitTwoDimensionalGatherLod`, #12790) takes each lane's level size from `OpImageQuerySizeLod` at that lane's level. llvmpipe before Mesa 26.0 answers a size query with the first lane's LOD for the whole vector ([`lp_build_size_query_soa` in 25.2.8, L4354-L4356](https://gitlab.freedesktop.org/mesa/mesa/-/blob/mesa-25.2.8/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c#L4354-4356): `/* FIXME: this needs to honor per-element lod */`, then `LLVMBuildExtractElement(..., params->explicit_lod, 0)`; 26.0.8 uses `params->explicit_lod` per element, L4352). Lanes at another level then scale their coordinates by that level's extent. In the test's first case (clamp to edge, point), all 32 lanes give exactly what that predicts for groups of 8 lanes (llvmpipe's vector width here): each lane gathers from its own level with the extent of its group's first lane's level, so only lanes whose level differs from that lane's are wrong. The query now uses LOD 0, and each lane's extent is `max(1, extent >> level)`. That is the level size Vulkan defines ("Image mip level sizing"), also for a view whose base level is not 0, so the result does not change on a driver that honours the per-lane LOD. The fallback to the T# extent when the query returns 0 is unchanged. #23666 changes the same `OpImageQuerySizeLod` line (it adds the layer count for 2D arrays). Whichever merges second needs a one-line rebase; I can rebase this one onto #23666. ### Tested Linux Mint 22.3, kernel 7.0.0-38, GCC 13.3.0, Release, under Xvfb, head on `main` `d50640e264`. lavapipe from Mesa 26.0.8 was built from the release tarball and selected with `VK_DRIVER_FILES`. | Device | `main` | this PR, 3 runs | |---|---|---| | llvmpipe, Mesa 25.2.8 (LLVM 20.1.2) | `agc_driver_image_gather_lod` fails 3/3 with the job's message | passes 3/3 | | lavapipe, Mesa 26.0.8 | passes | passes 3/3 | | GTX 1050 Ti, 580.178.04 | passes | passes 3/3 | | Intel HD 630, Mesa 25.2.8 ANV | passes | passes 3/3 | - Validation layer 1.4.363.1 (LunarG SDK), `VK_LOADER_DEBUG=layer`, on `agc_driver_image_gather_lod`, `_one_dimensional`, `_one_dimensional_array` and `_volume`, `main` and this PR, all four devices: the loader inserts the layer in every test, no `VUID-`, `SYNC-HAZARD-` or `UNASSIGNED-` message on either side. `main` fails only `agc_driver_image_gather_lod` on llvmpipe 25.2.8; this PR passes all four tests on all four devices. - Split suite (`tools/suite.py`: every test once, GPU tests on the GTX 1050 Ti, the HD 630 and llvmpipe) on this PR, compared with the same suite of another branch on the same base (#24088, a libSceIcu change) on the same machine: the only difference is `agc_driver_image_gather_lod`, which fails on llvmpipe there and passes here. Both: GTX 1050 Ti 6338 run, 0 failed; HD 630 1457 GPU tests, the same 10 failures (the 9 of `main` `0626a8334f`'s own run and `agc_driver_frame_replay_rewind_copy`, intermittent, #22028); llvmpipe `agc_driver_image_table_packed_guards`, `agc_driver_scattered_runs` and `agc_driver_sparse_dma_buf_straddle` (the last from #23272, which this base still has). - `check_conventions.py`, `check_test_registration.py`, `check_main_sync.py` (merges cleanly with current `main`), `check_compile.py` and `git diff --check` are clean. `pr_overlap.py --branch`: #23666, as above. Of the 22 pull requests it could not compare (they conflict with `main`), none changes a line this PR changes; the two whose diffs share a line text with it (#6280, #7085) do so in `DecodeSrgbTexel`, another function. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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: none - [x] GPUs tested: NVIDIA GeForce GTX 1050 Ti (580.178.04), Intel HD Graphics 630 (Mesa 25.2.8 ANV), llvmpipe (Mesa 25.2.8, LLVM 20.1.2), lavapipe (Mesa 26.0.8); Linux Mint 22.3 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-20 06:23:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T06:23:33Z.

Review: COMMENTED


Reviewed — comments

The change addresses the stated varying-LOD query issue, but the partial view-level sizing logic needs clarification before a formal approval is justified.

What I ran

Reviewed head efee26e8a303ce1647b4709d057847d520cf942f. I read description.md, commits.md, manifest.json, diff.patch, and the changed function in SpirvImageEmitter.cpp (lines 1050–1130) through repo_read.py. No tests or build commands were run.

Results

Check Result Note
Diff and changed function passed Read at pinned head
Build and tests not run Description reports author-run results

Findings

Blocking

None verified.

Non-blocking

  • The implementation derives each mip extent by right-shifting the level-0 query result, while the description claims this also handles views whose base mip is not 0. Please confirm that OpImageQuerySizeLod(image, 0) reports the extent corresponding to the view’s base level in this backend, and that its behavior is consistent for the image types accepted by this function. The changed calculation is at core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp:1091 and core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp:1101.

Not verified

The full changed file is listed as included, but only the changed function and its immediate context were read. No tests, build, Vulkan validation, or hardware behavior were independently verified. The author’s reported test results were not reproduced.

To get this to a good state

Nothing is required. Please clarify the view-base-level extent assumption as an optional point.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5988405405 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24100#pullrequestreview-5988405405). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T06:23:33Z. **Review:** COMMENTED --- # Reviewed — comments The change addresses the stated varying-LOD query issue, but the partial view-level sizing logic needs clarification before a formal approval is justified. ## What I ran Reviewed head `efee26e8a303ce1647b4709d057847d520cf942f`. I read `description.md`, `commits.md`, `manifest.json`, `diff.patch`, and the changed function in `SpirvImageEmitter.cpp` (lines 1050–1130) through `repo_read.py`. No tests or build commands were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed function | passed | Read at pinned head | | Build and tests | not run | Description reports author-run results | ## Findings ### Blocking None verified. ### Non-blocking - The implementation derives each mip extent by right-shifting the level-0 query result, while the description claims this also handles views whose base mip is not 0. Please confirm that `OpImageQuerySizeLod(image, 0)` reports the extent corresponding to the view’s base level in this backend, and that its behavior is consistent for the image types accepted by this function. The changed calculation is at `core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp:1091` and `core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp:1101`. ## Not verified The full changed file is listed as included, but only the changed function and its immediate context were read. No tests, build, Vulkan validation, or hardware behavior were independently verified. The author’s reported test results were not reproduced. ## To get this to a good state Nothing is required. Please clarify the view-base-level extent assumption as an optional point.
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!24100
No description provided.