perf(agc): size thin surfaces without a heap mip chain #15059
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15059"
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 Sam-mon7 on 2026-11-02T13:04:15Z.
What
Many callers need only a texture's guest byte count: image resolution and the image table walk in ShaderResources.cpp, depth and stencil plane ranges, the FMASK range, volume color targets, and the written-range lists
DispatchWriteRanges/DrawWriteRanges. They calledDescribeSurface(x).guestBytes. That builds a wholeSurfaceGeometrywhosemipsis a heapstd::vector<TileMipLayout>and then keeps onlyguestBytes.DrawWriteRangesdoes this once per queued draw under the default pipelined draws.SurfaceGuestBytes(descriptor)returns the same value without the heap chain. For thin surfaces (DescribeSurface's last path),DescribeSurfaceGuestByteslays the chain out withComputeMipLayoutIntointo a 16-entry stack array (MipLayoutStorage) and sums it withComputeSurfaceSize. 16 isComputeMipLayout's own limit, so no chain is too long for the array, and a longer one is rejected with the same error as before. PS4 (gcnPitch), multisampled, 3D and tiled 2D MSAA surfaces still go throughDescribeSurface, so their sizes and rejections can't change.The linear and tiled mip layouts now fill a span.
ComputeMipLayout(vector) andComputeMipLayoutInto(caller storage) share the same checks and fill code, andComputeSurfaceSizetakes a span (vectors still convert). 27 one-line size-only call sites switch toSurfaceGuestBytes. Call sites that keep aSurfaceGeometryfor more than its size are unchanged.APS5_NO_SIZE_ONLY_SURFACE_BYTESis aRuntimeSwitchthat sendsSurfaceGuestBytesback toDescribeSurface(x).guestBytes, soAPS5_ABcan toggle it in one run. It has a row in ENVIRONMENT.md, and TRACING.md lists it as A/B-able.The new
sizeOnlySurfaceTestsintests/TextureTiling.cpp(part ofagc_driver_graphics) checks three things.ComputeMipLayoutIntomust equalComputeMipLayoutfield by field, reject alike, and leave the storage pastmipCountuntouched.DescribeSurfaceGuestBytesmust return the same value asDescribeSurface(...).guestBytes, or reject with the same message.SurfaceGuestBytesmust match with the switch both set and clear. The sweep covers every format element shape (and every format on a smaller grid), the 15 non-PS4 tile modes plus two PS4 modes, every dimension (2D arrays, cubes, 1D arrays and 3D with 6 layers or slices), mip counts 0, 1, 2, 5, 11, 16, 17 and 0xffffffff, 1/2/4/8 samples, a linear pitch, a PS4 pitch, and zero and oversized extents.Noticed while working on Demon's Souls (PPSA01341) on a local branch; the change is generic.
Tested
Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7, Release, NVIDIA GeForce RTX 4070 (driver 610.88). Branch based on
main8cf4d1ebf0; head548cc8054a.ctest -R '<list>' -V -j2andANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation.main8cf4d1ebf0: 33/33 pass. Head: 33/33 pass. Neither log containsVUID-or a missing-layer message.DescribeSurfaceGuestBytessizing cubes as one layer,agc_driver_graphicsfails withDescribeSurfaceGuestBytes differs from DescribeSurface: 1280 / 7680. Without the multisampled fallback, it fails withrejects unlike DescribeSurface: '' / 'rejected: AGC graphics: multisampled surface dimension or array range is not implemented'. With this change it passes. The sweep adds about 3 s toagc_driver_graphics.Measured on Demon's Souls (PPSA01341) in a fixed benchmark scene (camera parked by
perf_empty/camera.txt, no pad input), Windows 11 Pro 10.0.26200, Ryzen 7 5800X3D, RTX 4070 (driver 610.88), 1920x1080. WindowAPS5_TRACE_SECONDS=150:60(presents from 150 s to 210 s after the first present).Both legs carry the same extra commit, the mip clamp of #6280 (cherry-picked as ebe9c17f56, "create sampled textures with no more mip levels than their extent allows"): without it
mainloses the device in this scene (#10634), so neither leg could be measured. Main leg:8cf4d1ebf0+ clamp =10645df7dc. This PR's leg:548cc8054a+ clamp =c3fd75d577. Every library comes from the same build of the main leg; onlylibSceAgcDriver.prxdiffers between the legs.The head line comes from the same run as the in-run A/B below. The A/B starts at 240 s (
APS5_AB_START=240s), after the trace window closed, so the head line covers only phase-A settings (the change on). That is whyAPS5_ABshows in itsenv.10645df7dc)c3fd75d577)main:this PR:
Traces: aps5-trace-10645df7dc6b-20520.json.gz (main) and aps5-trace-c3fd75d5774b-211012.json.gz (this PR).
In-run A/B in the same run as the head line:
APS5_AB=15:APS5_NO_SIZE_ONLY_SURFACE_BYTES,APS5_AB_START=240s, 15 s phases with 2 s settle, 11 B phases, each compared with its two neighbouring A phases (python tools/ab_split.py). Phase A has the change on, phase B has it off (APS5_NO_SIZE_ONLY_SURFACE_BYTESset):Result: the A/B measures a gain. Turning the change off costs 5.4% frame time (1.054x +- 0.016, about 3.4 standard errors) and 5.5% presents (1.055x +- 0.015). Between the two runs, p50 is the same (122.7 vs 122.0 ms) and p90 is 4% lower (147.8 vs 154.0 ms). The run-to-run spread in this scene is ~5%, so the in-run A/B is the number to use.
python tools/check_conventions.py --base upstream/mainpasses.Overlap:
tools/pr_overlap.py --branch(1806 open pull requests) confirmed three line overlaps, all next to or on a converted line and none changing what a site computes: #9674 (PS4 Thick_1dThick layout; the same include and insertion lines in tests/TextureTiling.cpp), #12246 (1D arrays past maxImageArrayLayers; ShaderResources.cpp L373) and #14868 (pending results under clear keys; ShaderResources.cpp L1287-1288). It could not compare 110 pull requests that conflict withmain. Most of them share only ENVIRONMENT.md or one of the call-site files. #6280, #7085, #9318 and #9891 also touch TextureTiling.cpp/.hpp and should be checked by hand before merging. Whichever lands first, the other side's rebase is mechanical: a call site keepsDescribeSurface(x).guestBytesor becomesSurfaceGuestBytes(x).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)🤖 Generated with Claude Code