perf(agc): upload a GPU-written sampled texture on the GPU from its host import #16286
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16286"
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 JJenkx on 2026-11-06T04:39:14Z.
What
A sampled texture over memory that the GPU has a pending write to is now uploaded on the GPU from the host import that holds that memory, inside the open batch. It is no longer snapshotted on the CPU, which first waited for the batch and then copied the whole surface.
Where it applies. In
cachedTexture, when all of these hold:Uncompressed, without depth compare or layer rows;Recorder::SnapshotWriteOverlapsreports a recorded write over the surface;ExistingHostImportFor). The lookup does not make an import of its own: every live import adds to each submission's buffer-object work.How. The
Texturesnapshot constructor takes an optionalHostImportsource. With one, it copies the tiled bytes from the import buffer into the tiled scratch buffer, behind a barrier on the earlier writes, instead of from a host staging buffer. The detile and the image copy are unchanged.Cache reuse. The entry keeps no bytes, so a later lookup reuses it only through
unchanged()(GuestMemory::UnchangedSince). Direct GPU writes are stamped when they are recorded (ShaderResources::MarkGpuWrites→MarkDirectWrites→MarkPossiblyWritten). So the next write over the surface makes the lookup upload again, on the GPU, asmainwould snapshot again.Switch and counter.
APS5_NO_SAMPLED_IMPORT=1keeps the CPU snapshot. The[textures]profile line (APS5_PROFILE_DRAW) counts the uploads as "uploaded on the GPU from host imports", andSampledTexturesImported()exposes the count to tests.Where it came from. Bendy and the Ink Machine (PPSA27616) samples a 66.8 MB 4K
R16G16B16A16_SFLOATsurface (guest format 71) once per frame. Its pending storage image is stored back by the staged-clear flush (#4794,StagedClearSampledRead), which then reads the surface uncompressed. Onmainthat read wasReadTextureSurface→GuestMemory::ReadCommitted→Recorder::SyncThrough: about 10.9 ms of waiting in a 36.5 ms frame, plus the 66.8 MB copy. With this change the flush still stores the image, and the texture is built from the import after that store, on the GPU. The staged-clear behaviour is unchanged.Related. #9884 removes the vector copy from the same CPU snapshot but keeps the read and its wait. The two touch the same constructor, so whichever lands second needs a small rebase. No open PR builds sampled textures from a host import.
Tested
Arch Linux 7.2.11, GCC 16.2.1, Release, Ryzen 9 7950X, Radeon RX 6650 XT (RADV Mesa 26.2.6).
New test in
agc_driver_recorder(copiedDirectOrderingTests): a compute dispatch writes a host-imported surface; with the storage-image view turned off for the case (SampledFromStorageForTest), a sampled lookup in the same batch must upload from the import (SampledTexturesImported+1) with no submission in between, and the GPU write must land. At headee031780fcit passes on the RX 6650 XT and prints itsokline, and passes again underVK_LAYER_KHRONOS_validationwith noVUID-messages. An earlier version of this test read the texture back with an invalid copy and, on AMD, skipped itself; see the comment below.agc_drivertests: all 956 pass (first version of the test; it was skipped on this device, see above).agc_driver_staged_clear_sampled_readpasses with and withoutAPS5_NO_SAMPLED_IMPORT. That test runs without a recorder, so it does not take the new path; it shows the staged-clear case is unchanged.PPSA27616 on the current head (
cfb6626e7e,main85a48c99demerged), same machine, input and window, order on, off, off, on: with the change 51.12 and 51.46 (mean 51.29), withAPS5_NO_SAMPLED_IMPORT=139.71 and 40.12 (mean 39.92). That is +28%. The gain is smaller than the +97% below becausemain's staging upload has since raised the switched-off case from about 26 to about 40 FPS; the result with the change is unchanged at about 51. The figures below are kept as measured at their pins.PPSA27616, same build. These runs were made on
mainbca78a3958with the change as first written, which askedHostImportFor; the head asksExistingHostImportFor, and its own runs are below. Mean FPS over 24–70 s of the survey's timed Cross input, no compiler running, in the order on, off, off, on, off, on, on, off:APS5_NO_SAMPLED_IMPORT=1That is +97%, and both orders agree. The eighth run was relaunched after the loop's own attempt was refused for an uncommitted edit in my worktree.
Gameplay, 110–160 s, same build and order: with the change 19.04, 18.01, 18.08, 18.35 (mean 18.37); with the switch 17.92, 17.90, 18.85, 17.56 (mean 18.06). That is within the spread between runs, so gameplay is unchanged; the wait this removes is what limits the opening, not this part of the scene. The 24–70 s window is the title's near-white opening. By 115 s the scene is the lit corridor; screenshots at 115 and 150 s with and without the switch show the same corridor, posters and lighting as
main; I can attach them.This change, measured at
e0d92dd125onmain5444d9862f. The two later commits change the test and addSampledFromStorageForTest, a test hook that is on (the existing behaviour) unless a test turns it off:agc_driver_recorderand bothagc_driver_staged_clear_sampled_readtests pass. A profiled PPSA27616 run to 72 s (exit 0) uploads 2,317 textures from host imports and makes no snapshot read over a recorded write, so the existing-import lookup engages as the first version did. Opening, mean FPS over 24–70 s, order on, off, off, on: with the change 49.66 and 50.59 (mean 50.13), withAPS5_NO_SAMPLED_IMPORT=125.72 and 25.52 (mean 25.62): +96%, as with the first version.Capture pairs for the
perflabel: PPSA27616,APS5_TRACE_SECONDS=20:40, the timed Cross input, same machine and scene, ordermain5444d9862f, this change, this change,main. Bothmain-to-change pairs halve the frame time (mean -48.6% and -49.1%);maintomaindiffers by +0.8% and change to change by -0.2%. GPU busy time per present goes from 17.9 to 17.2 ms. Second pair,tools/performance_compare.py --require-matching-context:Summary lines:
tools/trace_digest.py, this change: seconds 20:40 from present 421: 1995 presents, frame p50 19.6 / p90 21.9 / p99 23.3 / max 24.9 ms, GPU busy 17.2 ms per present AMD Radeon RX 6650 XT (RADV NAVI23), radv Mesa 26.2.6-arch1.1, Linux 7.2.11-arch1-1, 3840x2160, commite0d92dd125, dropped: noThe four
.json.gztraces (1.8 to 3.5 MB) are kept locally; I can attach them.Profile (
APS5_PROFILE_DRAW=1, PPSA27616 to 170 s, one run each): withAPS5_NO_SAMPLED_IMPORT=1, 1,740 sampled snapshots, 1,666 of them read over recorded writes. With the change, 74 snapshots, none over recorded writes, and 3,140 textures uploaded from host imports. The change uploads more often thanmainsnapshots, because an entry without bytes cannot be kept by a byte compare when a write left the surface unchanged. That costs GPU copies, not waits, and the frame rate above includes it. The waits left in gameplay are the same in both runs (DRAW_INDEX_2texture reads, about 145 per 10 s); they come from another reader and are not changed here.PPSA21607 (The Smurfs – Dreams), a second title that samples surfaces over recorded writes. Profiled 293 s runs of this head (exit 0): with
APS5_NO_SAMPLED_IMPORT=1, 2,489 snapshots, 1,456 of them over recorded writes; with the change, 1,033 snapshots, 2 over recorded writes, and 1,603 textures uploaded from host imports. Frame times are unchanged: eight 8 s traces at 280 s, in the order on, off, off, on, off, on, on, off, give a median frame of 70.9, 91.9, 91.1 and 91.2 ms with the change and 91.4, 89.3, 91.1 and 67.8 ms without it. One run in each set catches a lighter part of the scene. Removing those reads does not change the frame time there.Other titles, 125 s each with Cross every 15 s and
APS5_PROFILE_DRAW=1, against the same slice onmainb6c74f1f97: PPSA02801, PPSA02817, PPSA25009 and PPSA28002 stop at the same points withmain's multisample depth publication refusal (#15600). PPSA05213, PPSA06327 and PPSA21480 run to the close atmain's frame rate. None of the seven takes the new path (the profile counts 0 imported uploads), so this change does not reach them.The branch is on
main5444d9862f, where it was measured. It merges onto currentmainf53ddbc377without conflicts; none of the commits since touches its files.Not tested on Windows or macOS.
Validated by others on head
ed403d7cc3: NVIDIA RTX 3070 Ti (615.78.08) and Intel UHD 630 (Mesa 26.2.6) on Linux, AGC, shader and VideoOut tests the same asmain17fec48224, and the recorder, staged-clear and partially-resident tests pass 3 of 3 alone on each (run). Earlier heads: the same two GPUs onb260338ac5(run); source review ofb260338ac5andcfb6626e7e(1, 2).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)