feat(agc): drop the top mip levels of large BC textures with APS5_TEXTURE_DOWNSCALE #12746
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12746"
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 senjinthedragon on 2026-10-29T07:11:14Z.
What
An opt-in last resort for cards whose device memory a title fills:
APS5_TEXTURE_DOWNSCALE=<n>(1 to 3, off by default) leaves out the topnmip levels of mipmapped block-compressed 2D textures uploaded from guest memory whose longest side is at leastAPS5_TEXTURE_DOWNSCALE_MINtexels (1024 by default). The image starts at guest leveln, so those textures keep about a quarter of their memory with1, a sixteenth with2and a sixty-fourth with3.It is lossy by design and documented as such in
USAGE.md: the picture is blurrier, and a shader that reads a texture's size or its texels by coordinate (image_get_resinfo,image_load) sees the smaller image, and sampling at an explicit LOD or under a sampler's or instruction's LOD clamp landsnlevels coarser. Those reads stay in bounds (the emitter checks loads against the image's own size), so a title that depends on them shows wrong or missing detail, not a fault. It is meant as "if your title runs out of VRAM, try this", not as a correct mode for every title.What it leaves alone: render targets, storage images and every copy made from them (they never take this constructor), uncompressed formats, single-level textures, a view that does not start at level 0 or ends at it, sRGB-expanded and repacked formats, and depth comparison textures.
Inside
Texture's guest-upload constructor:n;nand write image levellevel - n;n, as does the clamp of the sRGB view;nstay unbound (unmapped - nimage levels), and the uploads start at the later ofnplus the unbound levels and the snapshot's first resident level;APS5_BC1_RDNA2_DECODE) take the same first level and the same image levels;APS5_DUMP_TEXTUREdumps the first level the image holds;The texture is not written again after construction (the refresh paths only serve copies of storage images), and the sampled-memory accounting already uses the image's own allocation, so neither needs a change.
Tested
Linux (CachyOS kernel 7.3), NVIDIA GeForce RTX 2080 8 GB, driver 620.73.04, Release build of this branch at
f674171281, one commit on main68d65e6b14.agc_driver_texture_downscale(new;n = 1, plus_levels_2and_levels_3for--levels 2/3, one process each):image_sample_d_cl,image_sample_clandimage_sample_d_cl_o(main'sTextureSparseLevelsshader and gradients). Every thread must read guest levelmax(level, clamp + n, MIN_LOD): the gradient picks the same guest level as without the switch, the levels finer thanncome from leveln, and the instruction clamp landsnlevels coarser. That is checked with every level mapped atMIN_LOD0 and 2. Then, where the device has sparse BC1 images, with levels 0 and 1 unmapped atMIN_LOD2, which must sample exactly like the fully mapped texture. Uploading from the wrong guest level fails it:image_sample_d_cl in thread 0 (level 0, clamp 0) read red 0.000000 and alpha 1.000000, expected guest level 1 (red 7).11 - nat1024 >> n, and its allocation equals that of a texture of that size, which the switch leaves alone (below the minimum);n;n = 1(512x4) and none atn = 2or3(the 4-texel guard);10 - non the view (fails without the shift: "became 10.000000 on the view, expected 9")._refuse_levelsand_refuse_minimumcheck thatAPS5_TEXTURE_DOWNSCALE=-1andAPS5_TEXTURE_DOWNSCALE_MIN=largerefuse the texture with an error naming the variable.All five pass, as does
agc_driver_texture_sparse_levels. WithVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(VK_LAYER_KHRONOS_validationinserted in every run) none prints aVUID-orSYNC-HAZARD-line.tools/check_conventions.pypasses.ASTRO BOT (PPSA21567) 01.018.000 on the same card, on a clean tree: this branch only, no local patches and no
APS5_*variables other thanAPS5_TEXTURE_DOWNSCALE(SDL_VIDEODRIVER=x11, because native Wayland stays black on this NVIDIA/KWin setup). Warm shader cache: one warm-up run first. The same route in each run: title, galaxy map, then Sky Garden from the fly-in to the first platforms. One session, run back to back, onlyAPS5_TEXTURE_DOWNSCALEchanged. VRAM is fromnvidia-smievery 5 s, fps from the window title.0(unset)12[gpu] sampled texture cache budgetline)vkAllocateMemory ... recoveredlines (initialResult=-2)On current
mainthis title no longer needs the switch on 8 GB. The memory work merged in November (eviction from the pressured heap, the staging-shadow cap, the image-pool budgets during recovery) keeps the sampled textures at about 2 GB, and the route fits with every level. On87473937d3(2026-11-07) the same card and route with0held 3024 MiB of sampled textures, ran out of memory at the fly-in (0.2-0.8 FPS,initialResult=-2refusals) and only got through with1or2. The switch now only buys headroom on this title: about 1.9 GB with1.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
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:50:58Z.
Review: COMMENTED
image_get_resinfo,image_load) sees the smaller image and "shows wrong or missing detail".image_get_resinforeturning a size that is not the guest's T# size is a made-up answer, not a degraded one. The project rule is exact-or-throw; approximate fallbacks, even opt-in and logged, have been rejected upstream and belong on a probe branch.image_gather4_lon mips) all useresinfoandimage_load. With the knob on, those break silently. The only defence is a paragraph inUSAGE.md.main, and what does it show with the knob on that it does not show off? The 5 tests listed check the extent and level count, not what a shader reads.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T06:58:31Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation and test code read support merging, and the reported hardware results were not independently reproduced.
What I ran
Reviewed head
0de2f2c84069c8489ff48456084c61d3ee5f4851. No commands or tests were run. I read the changed-line diff and targeted pinned-head ranges fromTexture.cpp, along with the complete 433-lineTextureDownscale.cpp; there was no merged-preview check.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Texture.cppwas excluded from the review bundle as too large; targeted ranges covering the changed helper, constructor upload and view setup, and sRGB view setup were read through the pinned reader. The complete changed-line ranges ofCMakeLists.txt,Texture.hpp,ENVIRONMENT.md, andUSAGE.mdwere not read from their full repository files. The new test source was read in full. No tests, build, or hardware behavior were independently verified; the claimed run results come from the PR description. No commit-pinned source links are included because the reader provided local source access only.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-02T03:57:51Z.
Review: COMMENTED
Actionable comments
2ca5c5b4-d606-4916-9e03-d3b4d2c44454Reviewing files that changed from the base of the PR and between
68d65e6b14andf674171281.core/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/execution/TextureDownscale.cppdocs/dev/ENVIRONMENT.mddocs/user/USAGE.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-02T04:27:20Z.
Review: APPROVED
Reviewed — looks good
The reviewed change has no verified blocking findings, and all six changed files listed for review were read at head
f674171281e211db74286addb0237a94c58c50c4.What I ran
Read the prepared diff and changed files, then used
repo_read.pyat the pinned head for targeted source context. No build or test was run. The GPU and game results in the description are author-reported.Results
Negative control
Not run; the execution tests were not run in this review.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
The author-reported test runs, validation-layer output, and ASTRO BOT measurements were not independently verified. No console behavior or other hardware was tested. Files read:
core/libs/prx/libSceAgcDriver/CMakeLists.txt,core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp,core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp,core/libs/prx/libSceAgcDriver/tests/execution/TextureDownscale.cpp,docs/dev/ENVIRONMENT.md, anddocs/user/USAGE.md. No files were excluded.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:56:23Z.
Review: COMMENTED
The trial merge with
mainis clean. The existing texture-downscale fixture covers the non-dropped top mip, very short views and partially resident inputs. Please retain a sampled view whose entire requested mip range lies above the cutoff, and check its resolved view and data together. That is the case most likely to expose a disagreement between descriptor clamping and the mip really uploaded. I have no paired Vulkan result for this head yet.AI-assisted: yes.
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.