Repository navigation
fix(agc): load single extra mips from their backing images - #28176
cmsierrave-coder wants to merge 169 commits into
Conversation
A T# or a color target may name more mip levels than its extent halves into. On RDNA a level's extent is max(1, extent >> level), so the levels past floor(log2(max(width, height, depth))) + 1 are more 1x1 levels with texels of their own in guest memory. A Vulkan image cannot have them (VUID-VkImageCreateInfo-mipLevels-00947), but the sampled texture upload, its block and depth copies and the storage image created their images with the descriptor's level count and copied every guest level into them. Demon's Souls (PPSA01342) samples 28x1 and 4x1 BC3 and BC7 arrays through T#s of 8 to 11 levels, among them a 28x1 BC3 array of 256 layers and 10 levels whose extent holds 5. NVIDIA (RTX 3060, 591.86) sizes a 28x1 BC3 image of 10 levels like one of 5 (0xc00 bytes a layer), so the copies of levels 5-9 wrote past the image's memory. Each of the title's seven device losses followed the creation of such a texture; in the run with the address log, VK_EXT_device_fault reported a write fault at the first byte past that image. SurfaceGeometry::imageLevels is the descriptor's level count, at most FullMipChainLevels of the extent. Sampled textures and their block and depth copies create, transition and copy only those levels, and their views keep the base level, the level count and the minimum LOD inside them: a view of levels past the chain reads the image's last level. Storage images hold the same levels. Their uploads, write-backs, clears, barriers and copy regions cover only those levels, so the guest bytes of the levels past the chain are neither read into the image nor written back. A storage view or a color attachment of a level past the chain throws, and so does creating a storage image for such a level. A fill or a buffer copy over such a surface is no longer turned into a clear or an image copy (FillClear and CopyFrom refuse it), since that would leave the levels past the chain unchanged, and the surface is tracked per layer: a 64 KiB unit of it may hold only those levels, which no slice window moves. docs/dev/debt/libSceAgcDriver.md records the levels that are not represented. Test: agc_driver_graphics (tests/TextureMipChain.cpp) runs the sampled upload of the 28x1 BC3 10-level array, a 4x1 11-level one and two full chains, and a 28x1 RGBA8 storage surface of 10 levels (upload, views, a color target, a fill, a buffer copy and a write-back) and a full 64x32 storage chain, through a recording mock device. It checks that every image, copy, barrier, clear and view stays inside the levels the extent can hold and that the accesses past them throw or are refused. On main it fails with "28x1 BC3 with 10 levels: the image was created with 10 mip levels, more than its 28x1 extent can hold (5)"; with only the sampled texture part it fails with "a 28x1 storage image of 10 guest levels must keep the 5 levels its extent has, not 10". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The previous commit gives a sampled view of a T# whose levels reach past its extent's full mip chain only the levels of that chain. Shader accesses that see the level count then diverged from the T#: image_get_resinfo returned the view's count (5 for the 28x1 T# of levels 0-9 that Demon's Souls samples, 1 for its levels 7-9) instead of LAST_LEVEL - BASE_LEVEL + 1, and its sizes at those LODs came from an out-of-range OpImageQuerySizeLod. image_get_resinfo adds the levels the view lacks to OpImageQueryLevels and returns 1 for the width, height and depth at a LOD the view does not hold. Both follow query_levels and lower_query_size in Mesa's src/amd/common/nir/ac_nir_lower_resinfo.c, which derive them from the descriptor: LAST_LEVEL - BASE_LEVEL + 1 and max(1, extent >> (BASE_LEVEL + lod)); every level past the chain is 1x1. The count comes from ResourceMaterializer::LevelsPastChain, which repeats the driver's view rule, as a pipeline specialization constant (LevelsPastViewBase) or, for registration modules, in bits 22-25 of the runtime image metadata flags. The tracker records which image accesses observe levels (ImageResource::levelUses), which moves the shader disk cache format to 37. MIMG BY2/BY4 and PCK2/PCK4 loads stay as they are: on hardware they return zero at every level narrower than their N texels, so a level the view lacks reads zero either way. image_load_mip and image_get_lod, an image_load through a T# whose base level lies past the chain, and image_get_resinfo through an image table cannot be exact (the texels of those levels are not represented, and a table does not carry the missing count), so such a descriptor is refused: the draw or dispatch throws, an image table entry faults. docs/dev/debt/shader.md records it. Test: agc_driver_image_levels_past_chain (tests/execution/ ImageLevelsPastChain.cpp) runs on the device: image_get_resinfo of a 28x1 2D and 2D-array T# of levels 0-9 at LODs 0-9 and of levels 7-9, image_load_mip and image_load at base level 7 refused, image_sample_l of levels 0-4 and image_load at base level 0 reading the uploaded texels, and an image_store to level 0 of a 28x1 R32_UINT surface of 10 levels (linear and R64KBX) changing only that level's 28 texels in guest memory. Without this commit it fails with "image_get_resinfo of a 28x1 2D T# of levels 0-9 at LOD 0: the level count is 5, expected 10" and the two loads run. agc_driver_graphics (tests/TextureMipChain.cpp) checks that LevelsPastChain matches the driver's view for seven T#s, the specialization constant and the metadata bits, and which accesses are refused; its range check also covers array layers now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
agc_driver_image_levels_past_chain sent each of its 32 invocations another LOD (tid % levels) in one image_get_resinfo dispatch. On lavapipe the 28x1 2D and 2D-array T#s of levels 0-9 failed at LOD 1 with a width of 28 instead of 14 (boykopovar#6280), although the module is right: OpImageQuerySizeLod takes any integer LOD per invocation. Mesa's llvmpipe up to 25.2 answers the size query of a vector of invocations at the LOD of its first one (lp_build_size_query_soa in src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c, "FIXME: this needs to honor per-element lod"), which bc56ec7ce032 (gallivm: Implement txs with divergent explicit lod) removed in 25.3.0. Applied to the emitted instructions, that behaviour gives exactly these two failures and passes the levels 7-9 case, where every width is 1. Every LOD of the T# now gets a dispatch of its own, with the same expected width, height, layer count and level count. The dispatch with a different LOD per invocation still runs on every device but llvmpipe, which prints that it skips it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Keep out-of-range queries on a valid Vulkan LOD, zero their extent and layer results, and retain the guest level count. Cover shortened and ordinary views, a single unrepresented base level, and capped sRGB copy paths. Preserve the active refusal for loads whose single base mip is not represented. Co-Authored-By: Codex <noreply@openai.com>
Keep the repacked image, its view and refresh regions inside the levels allocated for the source extent. Exercise ordinary and unrepresented guest base levels through the recording mock device. Co-Authored-By: Codex <noreply@openai.com>
Set the recording device's compute group-count limits so the repack refresh control reaches its recorded copy bounds. Qualify the existing raw LAST_LEVEL/MAX_MIP query discrepancy without changing decode behavior. Co-Authored-By: Codex <noreply@openai.com>
…base-extra-mip-maina700-20261020
…p-extra-mip-maina700-20261020
…base-extra-mip-main903c-20261020
…p-extra-mip-main903c-20261020
…p-extra-mip-main7c-20261020 # Conflicts: # core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
…base-extra-mip-main7c-20261020 # Conflicts: # core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp # docs/dev/debt/shader.md
|
Recheck at the rebased head AI-assisted: yes |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings in inspected paths
The targeted inspection found no verified blocker, but the broad stacked change remains only partially reviewed.
What I ran
Reviewed head d8748db673262828db279f94810338f71749f367 using the prepared review artifacts and targeted repo_read.py excerpts. I ran no builds or tests.
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp 5035 5100
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp 6570 6660
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp 270 460
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp 580 710
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp 9300 9389
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/TextureStorageImages.cpp 1 115
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp 630 825
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp 2150 2275
The reader returned source excerpts but could not append its read log because the review folder is read-only. The prepared description.md, commits.md, manifest.json, diff.patch, and files.json were inspected.
Results
| Check | Result | Note |
|---|---|---|
| Prepared diff inspection | passed | Broad refreshed stack |
| Targeted source review | not run | Excerpts returned; read logging failed |
| Builds and tests | not run | No compilation or test execution |
Negative control
Not run; no tests were executed.
Findings
Blocking
None verified in the targeted excerpts.
Non-blocking
No code findings from the targeted excerpts.
Sources
- Sampled extra-mip binding and guards: ShaderResources.cpp at the reviewed head.
- Extra-mip image allocation and transfer routing: TextureStorageImages.cpp at the reviewed head.
Not verified
This was not a complete review of all 40 changed files. Targeted head excerpts were read from four changed source files; full files were not read. The five files absent from the prepared files/ bundle were ShaderResources.cpp, Texture.cpp, Graphics.cpp, Recorder.cpp, and ShaderMemory.cpp; the first two were accessed only through targeted reader excerpts. The remaining changed files were not read in full. No refreshed-head Linux run or standalone SAROS gameplay run was performed by me; test results in the PR description are author-reported.
To get this to a good state
Nothing is required for the inspected paths. Optional: complete review of the remaining changed files and run the refreshed head on Linux.
Linux CircleCI verification for
|
| Revision | Passed | Failed | Did not run |
|---|---|---|---|
main at b396d834cb05 |
11 | 3 | 4 |
PR head d8748db67326 |
20 | 3 | 4 |
All nine additional tests selected on the PR head passed. They cover extra-mip rendering and readback, ClearMip, mirror and single-pass paths, image levels and dimensions, views past the last mip, and the image_by extra-base check.
The CircleCI job is red. agc_driver_graphics and agc_driver_graphics_maps_fallback failed the same mixed-layer cache reuse assertion on both revisions. agc_driver_recorder failed the same depth-surface fast-path assertion on both. Four additional graphics tests registered in CTest did not run because their executables were outside this CI job’s build target list.
Both CTest logs confirm insertion of VK_LAYER_KHRONOS_validation 1.4.335 with Vulkan required and the shader cache disabled. Both recorded 0 VUID- lines and 0 SYNC-HAZARD lines.
CircleCI job · Main CTest log · PR-head CTest log
Original CircleCI run finished later and reproduced the same test counts, failure names, and validation totals.
AI-assisted: yes
ligmaSec
left a comment
There was a problem hiding this comment.
The new sampled fixture reads two distinct mips through an array descriptor. Could it write one of those mips through the storage path and then issue image_load again on the same descriptor, checking that the changed mip updates and the sibling stays intact? The resolver now obtains the sampled view from the storage backing and marks it refreshed per use, so that sequence directly covers the backing reuse.
Source review at d8748db673. The trial merge conflicts in the image-resinfo fixture and shader cache version header.
AI-assisted: yes.
# Conflicts: # core/shader/recompiler/ShaderDiskCache.hpp
ContentKeyFlags has 12 entries now; the KeyMiss test and chargeShaderKey still assumed 11, so agc_driver_key_miss failed with equal keys not comparable.
d8748db to
e21b758
Compare
|
Recheck at the rebased head AI-assisted: yes |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Reviewed head e21b758b568c8d115cfb59d8c8a8fe75363cc9e9. The prepared diff and metadata were inspected; I used repo_read.py for pinned source context. No build or test was run, and no merged-preview check was performed.
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp 6590 6690
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/TextureStorageImages.cpp 1 115
repo_read.py cat core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp 600 735
repo_read.py cat core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp 490 570
repo_read.py cat core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp 2735 2795
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp 1420 1610
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp 2130 2275
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp 2640 2745
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp 660 820
repo_read.py cat core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp 9300 9459
Results
| Check | Result | Note |
|---|---|---|
| Targeted source review | passed | No concrete defect verified in inspected ranges |
| Reviewer tests | not run | No build or test execution |
| Author-reported CTests | not run | Description reports 28/28 on Windows |
| Negative control | not run | No test execution |
Findings
Blocking
None verified in the inspected ranges.
Non-blocking
- The description says the refreshed composition has not yet been tested on Linux. If Linux is in scope, running the focused CTests there would add coverage.
Negative control
Not run; no tests were executed in this review.
Sources
The sampled extra-mip selection and fallback are visible in ShaderResources.cpp at the reviewed head. Extra-mip storage allocation and transfer handling are in TextureStorageImages.cpp and Texture.cpp. Eligibility is defined in ResourceMaterializer.cpp.
Not verified
This review is incomplete. I inspected targeted ranges in 8 of the 38 changed files; only core/libs/prx/libSceAgcDriver/Graphics/src/TextureStorageImages.cpp was read in full. The remaining changed files and uninspected ranges—including the large Texture.cpp, Graphics.cpp, Recorder.cpp, ShaderMemory.cpp, and ShaderResources.cpp changes—were not reviewed. files.json lists no rule-excluded files; several full files were unavailable in files/ because of size and were not read in full through the reader. Runtime behavior, GPU validation, and the author-reported test results were not independently confirmed.
To get this to a good state
Nothing is required. Optional: run the focused CTests on Linux against this refreshed head.
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Reviewed head e344630b7e1070123d6c8912e226dcc7eabe51c9 using the pinned repo_read.py reader and the prepared review files. I did not run tests or build checks.
cat description.md
cat commits.md
cat manifest.json
cat diff.patch
env -u ANYPS5_READ_LOG python3 repo_read.py cat <repository-path> <start> <end>
env -u ANYPS5_READ_LOG python3 repo_read.py search <pattern>
Results
| Check | Result | Note |
|---|---|---|
| Prepared diff and manifest | passed | Read |
| Targeted source inspection | not run | Review incomplete |
| Tests and build checks | not run | No checks run |
Negative control
Not run; no tests were run.
Findings
Blocking
None identified in the inspected excerpts.
Non-blocking
The review is incomplete, so this comment does not provide a merge approval. The patch changes 39 files; only selected implementation excerpts were inspected.
Sources
No behavior claims beyond the inspected excerpts.
Not verified
The full contents and behavior of all changed files were not verified. In particular, ShaderResources.cpp, Texture.cpp, Graphics.cpp, Recorder.cpp, and ShaderMemory.cpp were too large for full text in the review folder; only targeted excerpts were inspected for ShaderResources.cpp and Texture.cpp. Other changed files were not inspected beyond the prepared diff and manifest. No tests, builds, console behavior, or hardware behavior were verified on this exact head. The description reports results for other head revisions.
No files were excluded by the files.json rule. Of the 39 reviewed paths, full text was included for 34; five were too large for the review folder.
To get this to a good state
Nothing is required. Optional: complete source inspection of the changed files before making a formal approval decision.
|
Windows/NVIDIA run of head Tests: the 304 tests added by the PR or built from a file it changes; 10 of them are new:
Not tested: Linux, AMD or Intel drivers, a title run. AI-assisted: yes. Claude Code (Claude Opus 5.5) ran the build and the tests and wrote this. |
What
Use the extra mip’s storage backing as a sampled Vulkan view for plain
image_loadthrough a direct, single-level RDNA 2D or 2D-array descriptor. The view selects mip zero of the separate Vulkan image holding the requested guest mip. It keeps the existing refusals for image tables, explicit-mip loads, and unsupported surface layouts.The synthetic regression uses the 32×32, 64-layer descriptor from #27616. Mips 5 and 6 contain distinct values for every layer and channel. The backing comes from #7085, which still depends on #6280.
The stacked branch contains the dependency commits so it can be built before #7085 merges. The seven child commits now sit on #7085 at
6e70d4e7ebb80cc9e551d1c7b726caea77a274d9. They bump the shader disk cache format from 113 to 114 and cover rejection of compressed formats. The sampled fixture writes mip 5 through a storage view, then uses the same sampled descriptor to verify the new values in mip 5 and the original values in mip 6 across all 64 layers. Review the sampled-load commit by itself.The refreshed head
26c97050e80replays both child patches on #7085 atb5c59786a10and upstreammainat76d0a4a7dcd. It inherits the layered storage-view and one-slice array sharing changes, plus ClearMip correction8a8f4677e196, which refreshes pre-collected sibling writes before publishing the clear's generation. Parent source pins and RTX 5080 and AMD Radeon Graphics red/green results.The previous repository overlap scan flagged shared files across the stack. Follow-up Git comparisons covered all 192 flagged branches. Other open branches that change the same shader cache, descriptor, or resource-binding code can require conflict resolution if they land first. The comparisons flagged #6412, #6924, #9508, #9852, #9897, #14032, #14871, #14944, #16935, #18185, #19852, #20248, #20728, #22647, #27670, and #28077 for that review.
The review follow-up updates the Linux x86-64 libstdc++ size assertion for the binding structure, whose new field is already encoded and decoded. It also clears extra-level metadata for null sampled descriptors and strengthens the tests for array-layer uploads, distinct mip backing images, tiled write-back placement, recorded and immediate draws, and validation errors. The sampled fixture unregisters its guest memory on failure. The varying-LOD test runs on llvmpipe from Mesa 25.3 onward.
Tested
Windows MSYS2 on current head e21b758 passed all 17 focused CTests with zero skips. Lavapipe ran the sampled-mip storage-write regression and the other Vulkan fixtures. The loader inserted the Khronos validation layer in all ten Vulkan test processes. There were zero missing-layer messages, VUID errors, or synchronization diagnostics. GitHub Actions run.
Current head e21b758 passed the convention, debt and whitespace checks. Git merged it with upstream main 0b0c56d without conflicts.
Paired Lavapipe validation on main and the current head ran on the same Ubuntu 24.04 runner with Lavapipe Mesa 25.2.8 and Khronos validation layer 1.4.335. The loader inserted the layer on both revisions. Both logs had zero missing-layer messages, VUID errors, or synchronization diagnostics. The PR head passed 14 of 15 tests, including the new storage-write regression. Main passed 6 of 7. The sole failure on both revisions was agc_driver_graphics, at the same assertion that a subsequent mixed-layer lookup did not reuse all three cached layers.
Earlier results follow with their original source pins.
26c97050e80passed 28/28 focused CTests, and frozenmain76d0a4a7dcdpassed all 21 matching CTests. Both were built with WinLibs GCC 15.2.0 Release and run on the same Intel Iris Xe (32.0.101.7088), Windows 11 25H2 build 26200, with Vulkan required, shader caching disabled, and Khronos validation 1.4.363 from SDK 1.4.363.1.ctest -Vlogged the loader insertingVK_LAYER_KHRONOS_validationin all 21 child and 14 main GPU test processes. Both logs contained zero missing-layer messages,VUID-errors, orSYNC-HAZARD-reports. Both runs had zero skips. The shared tests include one-slice 2D/2D-array aliasing, storage views, packed image loads/stores, graphics, and shader disk cache coverage.main.git range-diffmatched both published child patches. Conventions and whitespace checks passed.Earlier Windows and reviewer results follow with their original source pins.
agc_driver_view_past_last_mip,agc_driver_image_levels_past_chain,agc_driver_graphics, andagc_graphics_profile_drawpassed on8958f59204c. The two GPU tests loaded the validation layer and reported zeroVUID-errors with shader caching disabled.mainata4ebd9084ccreturned the expected values on this driver and loggedVUID-VkImageCreateInfo-mipLevels-00958twice. The loader inserted the validation layer on both runs.0x12050000, the mip 5 value.48c41994801, all 14 focused Windows CTests passed with zero skips, including the eight mip tests, the graphics suite, and the shader disk cache tests. On the Intel Iris Xe, Khronos validation layer 1.4.363.1 loaded for the eight GPU mip tests, and the log contained no VUID or synchronization hazards. The recorded and immediate draw tests verified their submission paths.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)Summary by CodeRabbit