fix(agc): bound sampled array views to guest allocations #9318
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9318"
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 MarcZX10 on 2026-10-21T18:18:50Z.
What
Issue #9295 reports sampled 2D-array descriptors naming 6,145 slices when only 90 complete slices fit in the contiguous mapped guest range. Building the full sampled image can request more than 100 GiB of host image memory and abort with
std::bad_alloc.Cap sampled 1D-array, 2D-array and cube views to complete slices in the mapped range before creating the cached image. If the requested starting slice is outside the range, use slice 0 alone when at least one complete slice fits; throw when none fit. Storage views are unchanged. Regression cases cover the 90-of-6,145 boundary, an in-range starting slice and the fallback/error cases.
This addresses only the oversized sampled-view allocation described in #9295. It does not establish what the console does with out-of-range descriptors and does not resolve the issue's other stops or black frames. Related open work #6481 validates image-table entries; #6977 adds GCN tiling. Neither implements allocation-bounded sampled array views.
Tested
Linux x86_64, GCC 12.2, Release.
ninja -C build agc_driver_graphics_testspassed after rebasing onmain6b6c701636. The focusedRunTextureTilingTestssuite passed in a standalone runner linked from the project-built objects.The registered
agc_driver_graphics_maps_fallbackCTest could not reach its test body: startup rejected this host's Intel Xeon E5-1620 v2 because it lacks LZCNT, BMI1, BMI2, MOVBE, AVX2 and FMA. No Vulkan or GPU test is claimed.python3 tools/check_conventions.py --base upstream/mainpassed.Checklist
main; no other open PR implements the same behaviorImported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-21T18:28:32Z.
Independent native Linux check at exact head
b21d32e41d8488b7557a0556bd9141de3f8fae3e: the registered tests reach their bodies on this CPU, and a bounded-array execution diagnostic passes on NVIDIA, RADV and lavapipe.agc_driver_graphics_tests; both registered tests,agc_driver_graphicsandagc_driver_graphics_maps_fallback, pass. This runs the newBoundArrayWindowassertions in the normal executable, beyond the standalone runner reported above. These are CPU/mock-Vulkan tests; their pass is not a GPU claim. The unrelated heap-mirror cases explicitly report unavailable/unwatched memory.agc_driver_image_array_window_past_layer_limit_tests; its stock form passes on all three ICDs.baseArray=0,lastArray=6144(6,145 declared slices), over host-mapped memory registered throughGuestAllocations::Mutation::Addfor only 90 × 256 = 23,040 bytes. Width is 8, format 56. The descriptor still describes all 6,145 slices; no call toBoundArrayWindowwas added to the test. Logs showlayers=90in the texture actually created by the sampled-resource path.image_sample_lzandimage_loadresults for 32 lanes against exact RGBA texels. The load inputs include slice 89; sample inputs include 89, 89.6 and 90, checking the final registered slice and the sampler's clamp. The adapted fixture passes 3/3 fresh processes on RTX 3090, 3/3 on gfx1036/RADV and 3/3 on lavapipe.Integration negative control: keeping that diagnostic and the PR's helper/tests, but replacing only
Graphics/src/ShaderResources.cppwith merge-base6b6c7016365271245e8b81c1b734cac2d65f664d, makes all three ICDs exit 1 withan image view of more array slices than maxImageArrayLayers is not implemented. Restoring the PR's file makes all three pass again. This checks that bounding is connected to the sampled-resource path; it does not reproduce the title's >100-GiB allocation attempt.All temporary edits were then removed, the stock graphics and array-window targets rebuilt, both registered graphics tests rerun successfully, and the stock GPU fixture rerun successfully on all three ICDs. Checkout is clean at the tested head.
Ubuntu 24.04.3, GCC 13.3, Release; RTX 3090 / NVIDIA 595.99.02, gfx1036 (
1002:13c0) / RADV Mesa 25.2.8, lavapipe Mesa 25.2.8 / LLVM 20.1.2. Each GPU process pins its ICD and usesANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1. No Khronos validation layer is installed here. The GPU diagnostic covers the shared bounding path through a 1D array, not a 2D-array/cube title render, and does not establish the console's out-of-range behavior or resolve #9295's black frames.Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-21T22:59:34Z.
Windows run of the full sampled path on NVIDIA and AMD, plus one problem in the cube fallback. Head
b21d32emerged onto maina6dcea927(clean merge,17c1e949b).Host: Windows 11 (10.0.26300), Ryzen 5 9600X, WinLibs GCC 15.2.0, Release. GPUs: NVIDIA RTX 5070 Ti (617.42) and AMD Radeon RDNA2 iGPU
1002:13c0(proprietary 32.0.21042.62,ANYPS5_GPU=AMD).ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1.Registered tests. The 81-test related set (
agc_driver_graphics*,image_*array*/*cube*,array_layer_target*, layered draws and others) matches main on both GPUs.ImageArrayWindowPastLayerLimit.cppdoes not compile under MinGW on main (alignas(65536): "requested alignment exceeds object file maximum 8192"), so it cannot run here as committed.Local GPU probe (not for the PR). I adapted that fixture to build here:
alignas(256), linear 1D array, width 8, format 56, descriptor slices 0..6144, andGuestAllocations::Mutation::Addregisters only 90 × 256 bytes.image_sample_lzandimage_loadrun on 32 lanes. Same results on both GPUs:layers=90; all 32 lanes return the slice clamped to 0..89 (sample layers 0, 1, 45, 88.4, 89, 89.6, 90, 3000).layers=84; sample layer 0→slice 6, 1→7, 45→51, 88.4→89; load layer 0→slice 6. Lanes stay inside the registered range.layers=1; every lane returns slice 0. This is the documented fallback, not the requested slices.ShaderResources.cppfrom main, NVIDIA throwsan image view of more array slices than maxImageArrayLayers is not implementedfor all three bases. AMD does not throw: it createslayers=6145/6139/6045textures and reads past the registered range. So on this AMD driver the PR changes behaviour from "whole descriptor" to "bounded".Cube fallback.
BoundArrayWindowtreatskCubelike an array of single faces. I added a unit probe toRunTextureTilingTests(16×16, format 56, 64 KiB standard tiling):baseArray=0 lastArray=0, a 1-face view.lastArray=3, 4 faces.The texture path then requires at least 6 slices for a cube (
Texture.cpp, "guest cube texture view holds fewer than 6 array slices"). So a cube whose base cube lies past the range, or whose range holds fewer than 6 faces from the base, now throws. On main it builds the full view. ForkCube, rounding the available faces down to whole cubes and falling back to faces 0..5 would avoid that. I did not run a cube draw on the GPU.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:50:55Z.
Review: COMMENTED
Correction (2026-11-01): the title-ID/log demand below is not a CONTRIBUTING requirement;
Unblocks: noneis allowed. The technical points below are unaffected.This is an approximation of what the hardware does with an out-of-range descriptor, and the PR says so itself ("does not establish what the console does with out-of-range descriptors"). Under the exact-or-throw rule that is the part that should not merge as written.
BoundArrayWindowinvents a view. When the requested range runs past the registered allocation it silently shrinksdepthOrLastArrayto the last whole slice, and whenbaseArrayis past the end it rewrites the view to slice 0 (or cube 0). A guest that really samples slice 5000 of a 90-slice allocation gets slice 0 back with no log and no throw. Nothing in the description says the console returns slice 0, or that the descriptor's slice count is meant to be clamped by the allocation size at all. If the general behaviour is unknown, the choices are to throw (as theavailableLayers == 0case already does) and record the gap indocs/dev/debt/libSceAgcDriver.md, not to pick a substitute view. The 6,145 versus 90 case in #9295 is a case where the descriptor probably does not mean what the code assumes; a throw naming the descriptor fields would show that, a clamp hides it.The clamp is keyed to registered allocations, not to what is mapped.
GuestAllocationsLookup_nid_postfix(baseAddress, false)decides the limit. A texture whose layers span two adjacent registered allocations, or memory mapped outside the registered list, gets truncated at the first allocation's end, which would produce a wrong image for a valid descriptor rather than an out-of-range one. Is the lookup guaranteed to return the whole contiguous mapping? The PR text says "contiguous mapped guest range", the code uses the registration.Per-view cost. The lookup and
DescribeSurfacenow run on every sampled 1D/2D array and cube view built, not only on the oversized ones, andguestBytes = 0is set whenever the window changes. Please state how often this path runs per draw in a real scene, or gate the lookup behind the existing size check (layers * layerBytesagainst a cheap bound) so the common case does not pay for it.Evidence. No title ID and log line showing a title reaches this on main; the justification is issue #9295 only. The regression cases test the clamp's arithmetic, but nothing checks that an in-range descriptor on an allocation that is not the first registered one is left alone.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T04:57:05Z.
Review: COMMENTED
Reviewed — four review points checked, clamp reaches every array view
Three of CnRJay's four technical points are confirmed by the code at head 8ed6ddb40781, and the fourth is only partly checked.
What I ran
Head
8ed6ddb40781f559cf60b855a99c1e794147b42d(live, OPEN). Read-only:gh pr view,gh apiGET on comments and reviews,git grepandgit showat the head. Nothing was built or run.Results
Findings
TextureTiling.cpp:523-526resetsbaseArrayto 0 when the start is past the available layers, and:528shrinksdepthOrLastArrayto the last whole slice. No log or throw on those paths. The only throw is for zero layers (:521).ShaderResources.cpp:714callsGuestAllocationsLookup_nid_postfix(resource.baseAddress, false)and clamps torange->bytes - offset(:716). The limit is the registered range, not the mapping.ShaderResources.cpp:714runs for every 1D or 2D array or cube view, with no size check first.:720setsguestBytes = 0when the window changes. How often this runs per draw in a real scene is not measured.tests/TextureTiling.cpp:535-564cover the clamp arithmetic on a 90-layer allocation and cube cases. I did not confirm whether any test puts an in-range view on a non-first registered allocation. Not verified.Sources
github.com/boykopovar/AnyPS5@8ed6ddb407/core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp (L511-L530)github.com/boykopovar/AnyPS5@8ed6ddb407/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp (L711-L720)github.com/boykopovar/AnyPS5@8ed6ddb407/core/libs/prx/libSceAgcDriver/tests/TextureTiling.cpp (L535-L564)Not verified
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.