Skip to content

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

Open
Thimo188 wants to merge 3 commits into
mainfrom
upstream-pr/22724
Open

Thimo188 wants to merge 3 commits into
mainfrom
upstream-pr/22724

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#22724, originally opened by MichonGoddijn231849.

Source commit: e5eac4e26f6fce16bc1a50c2d150515164f73f93. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


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:

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
    • Image dimension queries now report dimensions that shrink with the requested mip level, down to a minimum of 1.
    • Queries for mip levels beyond a texture’s available levels now return zero dimensions while preserving the reported level count.
    • Corrected handling of non-multisampled images with mip levels, while preserving existing multisampled image behavior.

MichonGoddijn231849 and others added 3 commits November 18, 2026 06:24
…2 does

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The past-last-mip guard wraps each size component in an OpSelect, so QueryReportsDepth now follows the select's in-range operand back to the size query.
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Image mip queries

Layer / File(s) Summary
Mip-level dimension query behavior
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp, docs/dev/debt/changes/fix-resinfo-mip-past-last-level.md
For non-multisampled images, QueryDimensions uses LOD 0 for an out-of-range request and returns zero dimensions with the queried level count. The debt note records reported results, measurement scope, and the PS5 measurement gap.
Mip query test coverage
core/libs/prx/libSceAgcDriver/tests/execution/ImageResinfoDimension.cpp, core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
The execution test checks mip queries for 2D, single-level 2D, and 2D-array descriptors. The SPIR-V inspector records OpSelect true-value operands and follows them when checking a composite component.

Change: Bug fix

Merge Risk: Minimal · up to e5eac

This change makes image resolution-info queries for out-of-range mip levels return zero dimensions with the level count, as the reported RDNA2 hardware results describe. No merge-blocking issue was identified.

Security architecture risk: Minimal · up to e5eac

The shader recompiler now returns zero dimensions for out-of-range mip levels while preserving the image’s level count. It avoids passing an invalid mip level to Vulkan without changing which image the shader can query.

Security review details

Security Blast Radius

  • inferred — The affected production surface is the existing non-multisampled image dimension query. The change does not widen resource reach: both metadata queries use the same previously selected image, and the mip operand does not select a different descriptor.

Trust Boundaries and Controls

  • observed — The generated shader checks the guest mip as an unsigned value against the Vulkan image view’s level count before supplying the operand to the size query. This bounds the metadata query’s mip operand; it does not change descriptor validation or authorization.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

Cppcheck (2.22.0)

Cppcheck (2.22.0) exceeded its 180-second time budget. Findings from completed work are retained; remaining checks are incomplete.

core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp

Cppcheck interrupted; analysis of this file is incomplete

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 4
  • Waived: $1.00 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 145d5311-4e88-49ae-8ff5-a5a0bad722f0
Commits

Reviewing files that changed from the base of the PR and between 4131f51 and e5eac4e.

Files selected for processing: 4

  • core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
  • core/libs/prx/libSceAgcDriver/tests/execution/ImageResinfoDimension.cpp
  • core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
  • docs/dev/debt/changes/fix-resinfo-mip-past-last-level.md

Limit details: You’ve used all 10 included reviews currently available.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 64 docs/dev/debt/changes/fix-resinfo-mip-past-last-level.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants