fix(shader): answer image_get_resinfo past the last mip level as RDNA2 does #22724

Merged
MichonGoddijn231849 merged 3 commits from upstream-pr/22724 into main 2026-12-03 19:31:47 +00:00
MichonGoddijn231849 commented 2026-11-18 05:27:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-11-18T05:27:35Z.


What

image_get_resinfo passed the guest mip straight to OpImageQuerySizeLod. Vulkan leaves that undefined for a lod at or past the view's level count. AMD's driver then returned the halved size of the last level, e.g. 1×1 for mip 4 of an 8×8 T# with 4 levels, and 32×16 for mip 1 of a single-level 64×32 one. RDNA2 hardware returns 0 for width, height and depth or layers there, and the level count as usual.

  • SpirvImageEmitter.cpp (QueryDimensions): the level count is read first, the size is queried at the guest mip when it is below the level count and at level 0 otherwise, and the three size components are zero past the last level. The fourth component is the level count as before. Multisampled queries are unchanged.

  • test: ImageResinfoDimension.cpp gains CheckMips, which queries mips 0 to 5, 15 and 0xffffffff of:

    • an 8×8 2D T# with 4 levels;
    • a single-level 2D T#;
    • a 3-layer 2D-array T# with 2 levels (DIM 2D_ARRAY).

    The expected values are the hardware's (below). The query program takes its mip from a literal (MipCode), and Descriptor takes an optional level count; the existing cube/3D/2D-array checks keep their single-level descriptors.

  • debt: a new shader.md entry (fragment docs/dev/debt/changes/fix-resinfo-mip-past-last-level.md).

Source of the semantics: tools/hw-oracle on gfx1036 (AMD Windows driver 32.0.21045.16010). The test's three T#s on hardware:

T# mips below the level count every mip from the level count up (incl. 15, 0xffffffff)
2D 8×8, 4 levels (8,8,0,4) (4,4,0,4) (2,2,0,4) (1,1,0,4) (0,0,0,4)
2D 8×8, 1 level (8,8,0,1) (0,0,0,1)
2D array 8×8×3, 2 levels (8,8,3,2) (4,4,3,2) (0,0,0,2)

A wider differential sweep against agc_oracle_runner covered 1D, 2D, 3D, 2D-array and 1D-array T#s of 1×1 to 100×1×12 with up to 7 levels, base levels 0 to 2 and array bases 0 and 2. It gave the same rule everywhere: before this change AMD returned a computed size for every mip at or past the level count. NVIDIA's driver already returned zeros there.

Tested

Windows 11 Pro 10.0.26200, ctest --test-dir build -R agc_driver_image_resinfo_dimension -V with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer, validation layer 1.4.363, once per GPU:

GPU this branch's test on main (fix reverted) this branch
NVIDIA GeForce RTX 5080, driver 610.74 (32.0.16.1074) passes (the driver returns zeros for the undefined query) 1/1 passed, 0 VUID-
AMD Radeon(TM) Graphics (RDNA2 iGPU, gfx1036), driver 32.0.21045.16010 fails: image_get_resinfo: mip 4 of a 2D T# with 4 levels returned 1x1x0 levels 4, RDNA 2 returns 0x0x0 levels 4 1/1 passed, 0 VUID-

Each log shows Insert instance layer "VK_LAYER_KHRONOS_validation" and none shows was not found but was requested. The other execution tests that query dimensions also pass on both GPUs: image_cache_bits, image_texel_status, image_volume_address_planar_texture, ds_swizzle and image_address_dimension, 6/6 with the resinfo test.

pr_overlap.py --branch failed closed on 14 open PRs that conflict with main; I compared their diffs by hand:

  • #6280 and #7085 also change QueryDimensions, for guest levels the host view lacks, so they and this PR need a textual merge. They report size 1 for those levels and do not zero a mip past the T#'s last level, which is what this PR fixes.
  • #19682 changes the multisampled initialiser two lines away.
  • The others only mention OpImageQueryLevels elsewhere.

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 RTX 5080, driver 610.74, Windows 11 Pro 10.0.26200; AMD Radeon(TM) Graphics (RDNA2 iGPU, gfx1036), driver 32.0.21045.16010, Windows 11 Pro 10.0.26200
  • AI-assisted: yes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Texture dimension queries now return zero width, height, and depth or layer count when the requested mip level is beyond the texture’s available levels. The total mip-level count remains available in the result.
    • Queries for valid mip levels continue to report dimensions that shrink with each level, down to a minimum of one pixel.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5370486583 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22724). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-11-18T05:27:35Z. --- ### What `image_get_resinfo` passed the guest mip straight to `OpImageQuerySizeLod`. Vulkan leaves that undefined for a lod at or past the view's level count. AMD's driver then returned the halved size of the last level, e.g. 1×1 for mip 4 of an 8×8 T# with 4 levels, and 32×16 for mip 1 of a single-level 64×32 one. RDNA2 hardware returns 0 for width, height and depth or layers there, and the level count as usual. - **`SpirvImageEmitter.cpp` (`QueryDimensions`):** the level count is read first, the size is queried at the guest mip when it is below the level count and at level 0 otherwise, and the three size components are zero past the last level. The fourth component is the level count as before. Multisampled queries are unchanged. - **test:** `ImageResinfoDimension.cpp` gains `CheckMips`, which queries mips 0 to 5, 15 and 0xffffffff of: - an 8×8 2D T# with 4 levels; - a single-level 2D T#; - a 3-layer 2D-array T# with 2 levels (DIM 2D_ARRAY). The expected values are the hardware's (below). The query program takes its mip from a literal (`MipCode`), and `Descriptor` takes an optional level count; the existing cube/3D/2D-array checks keep their single-level descriptors. - **debt:** a new `shader.md` entry (fragment `docs/dev/debt/changes/fix-resinfo-mip-past-last-level.md`). **Source of the semantics:** `tools/hw-oracle` on gfx1036 (AMD Windows driver 32.0.21045.16010). The test's three T#s on hardware: | T# | mips below the level count | every mip from the level count up (incl. 15, 0xffffffff) | | --- | --- | --- | | 2D 8×8, 4 levels | (8,8,0,4) (4,4,0,4) (2,2,0,4) (1,1,0,4) | (0,0,0,4) | | 2D 8×8, 1 level | (8,8,0,1) | (0,0,0,1) | | 2D array 8×8×3, 2 levels | (8,8,3,2) (4,4,3,2) | (0,0,0,2) | A wider differential sweep against `agc_oracle_runner` covered 1D, 2D, 3D, 2D-array and 1D-array T#s of 1×1 to 100×1×12 with up to 7 levels, base levels 0 to 2 and array bases 0 and 2. It gave the same rule everywhere: before this change AMD returned a computed size for every mip at or past the level count. NVIDIA's driver already returned zeros there. ### Tested Windows 11 Pro 10.0.26200, `ctest --test-dir build -R agc_driver_image_resinfo_dimension -V` with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `VK_LOADER_DEBUG=layer`, validation layer 1.4.363, once per GPU: | GPU | this branch's test on main (fix reverted) | this branch | | --- | --- | --- | | NVIDIA GeForce RTX 5080, driver 610.74 (32.0.16.1074) | passes (the driver returns zeros for the undefined query) | 1/1 passed, 0 `VUID-` | | AMD Radeon(TM) Graphics (RDNA2 iGPU, gfx1036), driver 32.0.21045.16010 | fails: `image_get_resinfo: mip 4 of a 2D T# with 4 levels returned 1x1x0 levels 4, RDNA 2 returns 0x0x0 levels 4` | 1/1 passed, 0 `VUID-` | Each log shows `Insert instance layer "VK_LAYER_KHRONOS_validation"` and none shows `was not found but was requested`. The other execution tests that query dimensions also pass on both GPUs: `image_cache_bits`, `image_texel_status`, `image_volume_address_planar_texture`, `ds_swizzle` and `image_address_dimension`, 6/6 with the resinfo test. `pr_overlap.py --branch` failed closed on 14 open PRs that conflict with `main`; I compared their diffs by hand: - #6280 and #7085 also change `QueryDimensions`, for guest levels the host view lacks, so they and this PR need a textual merge. They report size 1 for those levels and do not zero a mip past the T#'s last level, which is what this PR fixes. - #19682 changes the multisampled initialiser two lines away. - The others only mention `OpImageQueryLevels` elsewhere. ### 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 RTX 5080, driver 610.74, Windows 11 Pro 10.0.26200; AMD Radeon(TM) Graphics (RDNA2 iGPU, gfx1036), driver 32.0.21045.16010, Windows 11 Pro 10.0.26200 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Texture dimension queries now return zero width, height, and depth or layer count when the requested mip level is beyond the texture’s available levels. The total mip-level count remains available in the result. * Queries for valid mip levels continue to report dimensions that shrink with each level, down to a minimum of one pixel. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
MarcZX10 commented 2026-11-18 06:21:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T06:21:49Z.

Review: COMMENTED


Reviewed — no blocking findings

The inspected shader change guards out of range mip queries and the included tests cover representative 2D and array cases; the full review remains incomplete because one changed file was only read around its modified code.

What I ran

Reviewed head 84562572a5f6dbb3fd6f52d43342caa089353250 using the prepared review bundle and pinned-head reader. No tests or build commands were run in this review.

Results

Check Result Note
Diff and targeted code review passed Three changed files read in full; one changed file read around its edits
Tests not run Author-reported GPU runs were not independently run

Negative control

Not run; no test environment was available in this review.

Findings

Blocking

None identified in the inspected code.

Non-blocking

None.

Not verified

The remainder of core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp was not read; only the modified SPIR-V parsing and query-checking area was inspected. The reported Windows GPU test runs and hardware-oracle measurements were not independently verified. The other changed files read in full were core/libs/prx/libSceAgcDriver/tests/execution/ImageResinfoDimension.cpp, core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp (changed function), and docs/dev/debt/changes/fix-resinfo-mip-past-last-level.md. The description, commits, manifest, and diff were also read. No files were excluded from the prepared review bundle beyond the noted oversized ShaderMemory.cpp.

To get this to a good state

Nothing is required. Optional: run the reported execution tests on the target GPUs and inspect the remaining ShaderMemory.cpp context before treating this review as complete.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5951712333 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22724#pullrequestreview-5951712333). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T06:21:49Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The inspected shader change guards out of range mip queries and the included tests cover representative 2D and array cases; the full review remains incomplete because one changed file was only read around its modified code. ## What I ran Reviewed head `84562572a5f6dbb3fd6f52d43342caa089353250` using the prepared review bundle and pinned-head reader. No tests or build commands were run in this review. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted code review | passed | Three changed files read in full; one changed file read around its edits | | Tests | not run | Author-reported GPU runs were not independently run | ## Negative control Not run; no test environment was available in this review. ## Findings ### Blocking None identified in the inspected code. ### Non-blocking None. ## Not verified The remainder of `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` was not read; only the modified SPIR-V parsing and query-checking area was inspected. The reported Windows GPU test runs and hardware-oracle measurements were not independently verified. The other changed files read in full were `core/libs/prx/libSceAgcDriver/tests/execution/ImageResinfoDimension.cpp`, `core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp` (changed function), and `docs/dev/debt/changes/fix-resinfo-mip-past-last-level.md`. The description, commits, manifest, and diff were also read. No files were excluded from the prepared review bundle beyond the noted oversized `ShaderMemory.cpp`. ## To get this to a good state Nothing is required. Optional: run the reported execution tests on the target GPUs and inspect the remaining `ShaderMemory.cpp` context before treating this review as complete.
MarcZX10 commented 2026-11-30 06:38:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T06:38:45Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation and the changed test cases support merging.

What I ran

Reviewed head e5eac4e26f6fce16bc1a50c2d150515164f73f93 using the prepared diff and repo_read.py source reads. No commands or tests were run.

Results

Check Result Note
Diff and targeted source review passed Core logic and test additions reviewed
Runtime tests not run Results in the description are author-reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

ShaderMemory.cpp was excluded from the review bundle because it was too large; its changed lines were not read. No tests were run independently. Runtime behavior and the GPU results described in the PR were not independently verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6107844979 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22724#pullrequestreview-6107844979). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-30T06:38:45Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation and the changed test cases support merging. ## What I ran Reviewed head `e5eac4e26f6fce16bc1a50c2d150515164f73f93` using the prepared diff and `repo_read.py` source reads. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | Core logic and test additions reviewed | | Runtime tests | not run | Results in the description are author-reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified `ShaderMemory.cpp` was excluded from the review bundle because it was too large; its changed lines were not read. No tests were run independently. Runtime behavior and the GPU results described in the PR were not independently verified. ## To get this to a good state Nothing is required.
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!22724
No description provided.