fix(agc): keep texture images inside their extent's mip chain #6280
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6280"
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 fdfawef324 on 2026-10-15T08:55:10Z.
What
A guest texture descriptor can name more mip levels than Vulkan permits for its extent. Cap sampled, storage and expanded-copy images at the physical chain; bound their allocations, views, uploads, blits, barriers, clears and write-back. Extra-level storage views and attachments remain refused; #7085 supplies separate backing in a follow-up.
Demon's Souls PPSA01342 originally lost the device after a 28x1 BC3 array declared ten levels while the extent held five. The private integration fault pointed to the first byte beyond that image. This is historical diagnosis; it is not a fresh title run on the final rebase.
For the decoded views exercised here (
MAX_MIP = LAST_LEVEL),image_get_resinforetains the guest level count and returns 1x1 spatial extents for extra levels within that count. AtLOD >= count, it zeros every extent/layer component and retains the count. The emitter selects a valid physical query LOD before asking Vulkan, including for LOD 31 / UINT_MAX. Single-level descriptors with an unrepresented base refuse texel loads and LOD queries; pure size queries remain valid. Repacked storage-to-sampled copies use the same allocation/view cap.The rebase preserves #6054's uploadImage path and passes physical
geometry.imageLevels/copyLevelsthrough sRGB image creation, blits, views and refresh. It retains main'sConvertedSampleRequiredalongsideViewLevelsPastChain/LevelsPastChain, and keepsconvertedSamplesandlevelUsesin the cache encoder, decoder and nonzero round-trip fixture. Final cache format:41;ImageResourceguard:40.The existing decoder still clamps raw
LAST_LEVELtoMAX_MIPwhenBASE_LEVEL <= MAX_MIP. The reported 28x1 LAST_LEVEL=9 / MAX_MIP=0 count of ten remains a discrepancy; this change does not fix it. A CPU LAST9/MAX6 control pins that unchanged decode. Samples/gathers past the chain still clamp to represented data, with console behavior unverified. There is no local PS5 or 3D/cube resinfo hardware claim.External evidence is attributed, not counted as our own testing:
Tested
Windows Server 2025 (10.0.26100), WinLibs MinGW-w64 GCC 15.2.0, Release. Final publication candidate
0e1f2ab53b596a4d33ec8426097bda2c05b82068on main676d423968a1a8fcc79c6247020ce22090a8e0d4.Seven selected Release/O3 targets complete; the final restored incremental build took 14.06 seconds. Four CPU/mock CTests passed without skips in 14.91 seconds: agc_shader_bindless, agc_shader_memory, agc_shader_disk_cache and agc_driver_graphics. Two precise current-source controls failed at the intended single-unrepresented-base admission and repacked mip-5-of-5 copy assertions. Source was restored, rebuilt and retested. Conventions pass against the pinned base and later main
72a3d9f2a49d; its clean merge was checked separately from this 676-based execution.The recording mock checks ordinary and beyond-chain sampled/upload/storage sRGB expansion and repacked-copy allocation, view and copy bounds. Device query fixtures cover shortened and ordinary five-level views, single-level base 7 / last 7, 2D/2D-array layouts, LOD=count/count+1/31/UINT_MAX, and uniform/mixed lanes. The inherited llvmpipe mixed-LOD exclusion remains; no Mesa-version cutoff is newly claimed.
Current-head device checks passed 5/5 registrations / four executables without skips in 4.35 seconds on the RTX 3060, sequentially in the managed slot. Required cases: image_levels_past_chain, image_sample_lod_clamp, image_srgb_load, image_srgb_sample_copy and forced sRGB-copy. The frozen naturally dirty query control at this same source head exited 1 in 0.90 seconds and reproduced both expected errors (LOD10 width1 instead of0; LOD5 width28 instead of0), with actual RTX/Vulkan initialization. The checker requires both diagnostics; this is an expected regression failure, separate from the five passing production cases. Device skips/exit77 are not passes. The selective control removes only the zero-extent selection, retaining the safe physical query LOD and guest count; count-boundary mismatches must be observed to count it as a meaningful red.
Runtime hashes were verified before and after; ANYPS5_REQUIRE_VULKAN=1 was set. No fresh title, FPS, console-equivalence or playability result is claimed by this update.
Shared-source coordination is pending: #7550 codec order and #7579 eligibility-line order propose this PR first, with both changes retained by the later rebase. Those proposals are not agreements, so the verified update remains a draft. #7085 already declares this PR as a prerequisite; its depth/layer/level argument order must be reconciled by meaning. There is no additional standalone build dependency or combined-runtime claim.
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)Co-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-15T13:35:37Z.
Rebased on
main71bd2876eand added a second commit for the review gaps on the shader side of a view shortened to the mip chain:image_get_resinfonow returns the T#'s level count (LAST_LEVEL - BASE_LEVEL + 1, 10 for the 28x1 T# of levels 0-9 instead of the view's 5) and 1x1 at LODs the view lacks, as Mesa'sac_nir_lower_resinfo.cderives them from the descriptor. The missing level count reaches the shader as a specialization constant, or in the runtime image metadata for registration modules.image_load_mip,image_get_lod,image_loadthrough a base level past the chain andimage_get_resinfothrough an image table now refuse the descriptor instead of reading another level.agc_driver_image_levels_past_chain, red without the commit. It also covers sampled levels 0-4 and a storage write-back that leaves levels 1-9 untouched in guest memory. The mock test now checks that the recompiler's level arithmetic matches the driver's view for seven T#s, and its range check covers layers. 147 related tests pass on the RTX 3060.CopyRefusal, the sRGB copy's image and view levels); noted in the description.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T19:56:34Z.
Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with 5fb9380b7 merged into main
44df21632:agc_driver_graphics,agc_shader_disk_cacheand the rest).agc_driver_image_levels_past_chainfails on lavapipe, in two cases:AGC graphics: image_get_resinfo of a 28x1 2D T# of levels 0-9 at LOD 1: the width is 28, expected 14AGC graphics: image_get_resinfo of a 28x1 2D-array T# of levels 0-9 at LOD 1: the width is 28, expected 14Before that, the log shows
[texture] ... (28x1, 1 layers) names 10 mip levels, more than the 5 its extent holds: levels 5-9 are not uploaded.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-16T19:53:50Z.
Thanks for running this on lavapipe. We have no lavapipe here, so what follows comes from the module our code emits and from reading Mesa's source; we did not reproduce it on lavapipe.
What we checked:
tid % levels) through oneimage_get_resinfodispatch. The module we emit for the 28x1 T# of levels 0-9 asks the view forOpImageQueryLevels(5),OpImageQuerySizeLodwith the invocation's own LOD, and adds the 5 levels the view lacks. We compiled the test's shader on the CPU (with a representative capability set, not a device's own) and read the instructions. At LOD 1 they give a width of 14, a height of 1 and a level count of 10, which is what the test expects.OpImageQuerySizeLodtakes any integer LOD per invocation (SPIR-V specification 1.6,OpImageQuerySizeLod: "Level of Detail is used to compute which mipmap level to query"), so we do not see a problem in the module.lp_build_size_query_soa(src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c) takes element 0 of the explicit-LOD vector for the whole group of invocations, with the comment/* FIXME: this needs to honor per-element lod */. We did not establish which Mesa release, if any, changed that, so we cannot say whether your lavapipe has it.What we have not verified: your Mesa version (could you post the
driverInfoline ofvulkaninfo --summary?) and that the model above is what your run does. If the commit below still fails on your lavapipe, this explanation is wrong and we would like the full output.We pushed
c80ba9e31on top (it passes on our RTX 3060, where the mixed-LOD dispatch still runs): each LOD of the T# now gets a dispatch of its own, with the same expected values (width, height, layer count, level count), so the size query never sees different LODs in one group of invocations. The dispatch with a different LOD per invocation still runs on every device except llvmpipe, where it prints that it is skipped. It changes only the test. If this commit passes on your lavapipe, the cause is the one-LOD-per-vector size query; if it still fails, it is something else.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-17T11:01:38Z.
Another title that needs the storage-image part: Uncharted: Legacy of Thieves Collection (PPSA05684) binds storage textures whose T#s name 15 mip levels on 2560x1440, 1280x720, 480x270, 512x512 and 16x16 surfaces, so the description's "no title is shown to use a storage image with more levels than its extent" no longer holds.
Tested on Linux, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08), Release, on a private build of
mainplus other open PRs (#6003, #6004, #6182, #6412, #6771, #6772), with this PR's head c80ba9e31 merged in:VK_EXT_device_address_binding_report, the fault waswrite invalid at 0x546d10000. That is the first byte past a 2560x1440, 15-level, 7-layer R16G16B16A16F storage image ([0x532b60000, +0x141b0000)), created just before the fault.past its extent's full mip chain,storage image view of mip level), so the title never accesses a level past the chain.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-18T18:32:37Z.
Two things from Demon's Souls (PPSA01341 v1.07, Linux, RTX 5070 Ti, NVIDIA 595.91.07).
It fixes our Xid 31. We'd hit
NVRM: Xid 31(MMU fault, copy engine write) three times in the level. With b9badf4c2 on our base, a 1500 s run was clean, and the clamp fired once, on the 256-layer BC array at 0x1009000000 (11 mips cut to 5). That's the texture that had been created right before each of the three faults.The conflict with main is #6054. It added
CreateExpandImage/RecordExpandBlit, which size the RGBA8 copy fromdescriptor.mipCount. Applied on top of this PR, they rebuild the over-long chain this PR removes. Our resolution, replaying b9badf4c2 on main505767380:CreateExpandImageandRecordExpandBlittake a levels argument, fedgeometry.imageLevelson the upload path.copyLevels = geometry.imageLevelsand usesViewLevels()for the view, like your block-copy and depth-copy paths.refreshSrgbExpandpassescopyLevelsthrough.uploadImageis combined with yourgeometry.imageLevels.Lavapipe full suite on that tree: 1460 of 1461 pass. The one failure,
application_heap_lazy, also fails on our trees without this PR.image_levels_past_chain,image_sample_lod_clamp,image_srgb_sample_copy,image_srgb_sample_copy_forcedandimage_srgb_loadpass. This covers only the driver commit b9badf4c2, not 5fb9380b7. Use any of it if it helps.Resolution hunks (b9badf4c2 replayed on main
505767380)AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-18T20:40:11Z.
Hardware data for the part the description says is not measured on AMD. RX 6700 XT (gfx1031, RDNA 2), run through HIP:
image_get_resinfowithdmask:0xfand the T#'s own DIM, one LOD per lane from 0 to 31, 32-bit float format:(max(1, 28 >> LOD), 1, 0, 10), so 28, 14, 7, 3, then 1 for LOD 4-9MAX_MIP0MAX_MIP9: 10 levels(1, 1, 0, 5)(1, 1, 0, 3)(1, 1, 4, 3)(4, 1, 64, 11),(2, 1, 64, 11), then width 1 up to LOD 10(max(1, 28 >> LOD), 1, max(1, 4 >> LOD), 10)(1, 1, 1, 3)So the second commit's values hold on RDNA 2: the level count is
LAST_LEVEL - BASE_LEVEL + 1whateverMAX_MIPsays, and each extent ismax(1, extent >> (BASE_LEVEL + LOD)), so it is 1 at every LOD past the chain. One case the PR's test doesn't cover: at a LOD at or past the level count, every row above returns 0 for width, height and depth, with the level count unchanged ((0, 0, 0, 10)for the 28x1 levels 0-9 T# at LOD 10 to 31).image_load_mipat (0, 0) through the 28x1 2D T# of levels 0-9, linear andSW_64KB_S, over memory where each dword holds its own index: LODs 0-9 return ten different dwords, and LODs 10 to 15 return 0. So each of the five levels past the chain reads a 1x1 texel at its own address, as the description says, and a read through such a level that the emulator served from another level would return the wrong texel. That matches refusingimage_load_mipthere.This is desktop RDNA 2, not a PS5, and it covers only the queries and loads above, not samples or gathers past the chain.
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-19T02:30:20Z.
Two more conflicts with current
main(40393b0f9), beyond the Texture.cpp one in my last comment:ResourceMaterializer.hpp: an add/add next to #5958'sConvertedSampleRequired. Both additions can stay; we keptViewLevelsPastChainandLevelsPastChainalongside it.mainis already at 39ImageResourcefields (it addedconvertedSamples) andFormatVersion39. With this PR'slevelUses, thefieldCountassert has to be 40 andFormatVersion40, not 37.With those resolved, the stack (
main40393b0f9+ this PR + #6567 + #6926) builds, and lavapipe passes 1535 of 1536 tests. The only failure isapplication_heap_lazy, which also failed on our previous stack. No game run on this build yet.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-19T05:27:03Z.
Thanks for the reports. The #6280 recovery preserves #6054's physical allocation/blit/view/refresh bounds, including uploadImage, plus the repacked-copy cap.
ConvertedSampleRequiredremains beside the level helpers;convertedSamplesandlevelUsesboth survive the codec and round-trip fixture. On final base676d423968a1a8fcc79c6247020ce22090a8e0d4, the image field guard is40and cache format is41, chosen after that base's version rather than copying an earlier suggestion.The missing LOD>=count case is now covered: a valid physical LOD is selected before the Vulkan query, every extent/layer word is zeroed beyond the decoded count, and the count is retained. Tests include ordinary and shortened views, LOD=count/count+1/31/UINT_MAX and mixed lanes. A single base 7 / last 7 missing level now refuses loads/LOD queries while pure size queries remain valid. Frozen a599 passed four CPU/mock groups and its two selective CPU controls failed as intended. Final rebased/device evidence:
0e1f2ab53b59passed the final seven-target Release build, CPU4 and actual Vulkan5 without skips; the latter took 4.35 seconds. Removing only the final zero-extent selection reproduced both expected count-boundary failures with exit1 in0.90 seconds. Exact runtime hashes were checked; the positive and negative results remain separate.The new query fixtures have MAX_MIP=LAST_LEVEL. Raw LAST_LEVEL=9 / MAX_MIP=0 still follows the inherited decoder clamp and remains a discrepancy against thuanquang's report. The debt credits that RX 6700 XT/HIP evidence as desktop RDNA2 queries/loads, not PS5 or sampling/gather proof. Uncharted's eight clean ten-minute composed runs, fisherjoey's driver-commit 1500 s run and later 1535/1536 lavapipe stack remain attributed external results, not our own reruns. Extra-level backing and the composed-title results remain #7085's scope. The shared codec/eligibility order with #7550/#7579 is being coordinated in the linked description; this verified update stays in draft pending agreement, with no invented dependency or composed execution result.
AI-assisted: yes (Codex)
Co-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-19T06:46:37Z.
On the remaining
MAX_MIPpoint: I measured what a T# whoseLAST_LEVELlies pastMAX_MIPreads, on the same RX 6700 XT (gfx1031), through HIP. 28x1 2D T#, levels 0-9, linear, 32-bit float format, over memory where each dword holds its own index, withMAX_MIP9, 4 and 0:MAX_MIP9MAX_MIP4MAX_MIP0image_get_resinfoimage_load_mipat (0, 0), LOD 0-9image_sample_lnear (0, 0), LOD 0-15image_load_mipat LOD 10 to 15 returns 0 in all three.So
MAX_MIPdoesn't change what the query reports, but it decides the memory: every level pastMAX_MIPreads the texels of levelMAX_MIP, and the levels' addresses move with it (LOD 4 reads dword 16576 withMAX_MIP9 and dword 16256 withMAX_MIP4). So the decoder's clamp toMAX_MIPmatches what loads and samples read on this GPU; onlyimage_get_resinfoanswers fromLAST_LEVEL.Desktop RDNA 2 again, not a PS5.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T14:24:13Z.
Thanks for keeping this current. Before a full review, could you rebase it onto current
main? Two things come up:Texture.cppconflicts in three places. Two are theimageInfo.mipLevelslines, wheremainalso added amaxImageArrayLayerscheck that should stay next togeometry.imageLevels. The third is the copy-refusal block:mainmoved those checks intoCopyRefusal(...), so the new "levels past the image" refusal belongs there now.mainalready raisedFormatVersionto 41 andfieldCount<ImageResource>()to 40 for another field (1ed8eb6d8b). With this PR on top,ImageResourcehas 41 fields and thestatic_assertinShaderDiskCache.cppfails to compile, so the rebase needsfieldCount41 andFormatVersion42.#7085 composes these commits, so once this is rebased it can be restacked on the new head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T18:37:12Z.
Review: COMMENTED
Reviewed — comments
The inspected mip-chain capping and resinfo paths appear consistent, but this review is incomplete because most changed files were not read.
What I ran
Reviewed prepared diff for head
0e1f2ab53b596a4d33ec8426097bda2c05b82068and inspected targeted source ranges withrepo_read.py. No build or tests were run.Results
Findings
Blocking
None identified in the inspected portions.
Non-blocking
None.
Not verified
This review did not read every changed file, so it cannot support approval. Files read:
review/description.md,review/commits.md,review/manifest.json,review/diff.patch,core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp(lines 418–480), andcore/shader/recompiler/Optimization/src/ResourceMaterializer.cpp(lines 2070–2115). The changedcore/libs/prx/libSceAgcDriver/tests/Graphics.cppwas excluded from the review bundle as too large; its changed line is visible in the diff. Most other changed files listed in the manifest were not read.review/files.jsonwas not available through the reader. Author-reported builds, tests, and device checks were not independently verified.To get this to a good state
Complete the review of the remaining changed files and run the relevant checks before making a formal approval decision.
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.