perf(agc): clear single-key DCC surfaces on a verified uniform color #6848
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6848"
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 NFSS10 on 2026-10-16T14:12:25Z.
What
A ClearSingle surface (all-zero keys, the DCC all-invalidate encoding) carries its clear color as the leading element of every 256-byte key block, but that value is not on the
IsDccClearwhitelist, soStorageTexture::uploadfell through to a full host upload: for the 4K color targets a title clears through its DCC keys that is 63.8 MiB of guest read, staging fill and DMA per surface per frame, while the guest texel memory never changes.Upload now reads that one key element and clears the image to it when
DccMetadata::ProvedSingleUniformproves, for the current keys, that every 256-byte block clears to that one color: every block-leading element matches the first, gathered in 1 MiB chunks bounded to the surface (about 64ReadCommittedcalls instead of 261k one-element reads) and memoized until the next key upload. Any doubt falls back to the original CPU upload path, soFillClearColor's refusal behaviour is unchanged and a wrong clear color is not possible.IsDccClearkeeps its whitelist meaning for its other callers.The proof is what makes the fast path sound: a key of all zeros leaves the stored block-0 color behind, so a ClearSingle surface is not necessarily uniform and a single-element read alone is wrong (
agc_driver_dcc_keys_first_write: 16296/16384 texels). The fast clear fires only on surfaces that are provably one color, which includes the 4K clear targets the win comes from. The gather is bounded to the surface (std::span(buffer).first(size)), so proving a surface never reads past the keys region it proves.tools/check_conventions.py --base mainpasses.Overlap: #6108 and #6820 edit the same
StorageTexture::uploadregion and #7048 the sameTexture.cpplines (differentfunctions; the overlap bot flags the shared lines). No dependency on any of them.
Tested
Windows 11 23H2 (10.0.22631), AMD Radeon RX 7900 GRE, Adrenalin 25.6.1 (LLPC),
3840x2160, Release build.
order: same, 26 points) and exited 0.agc_driver_dcc_keys_first_writepasses; it fails 3/3 without the uniformity proof (commit9900a7ed7, superseded). ItsRunUniformSingleClearcase (third commit) covers the fast clear directly on a provably uniform surface: it asserts the upload is charged as a GPU clear (LookupOutcomes::UploadClear, notUploadCpu), that the write-back texels are the kernel's writes or the proved color, and that the keys land uncompressed. ForcingProvedSingleUniformtoreturn falsemakes it fail with "the first write read the surface and uploaded it instead of clearing it on the GPU", whichever block it runs on first (unwatched or write-watched). Full ctest green except two pre-existing failures that also fail on main (MinGW 15.2 toolchain).main(c0a7468f6); the commits in7dcfff559..c0a7468f6that touchTexture.cpp/Texture.hppchange allocation (buffer pool), base-level view usage and format helpers, not theupload/clear path this PR changes. The community A/Bs below were run on builds rebased past them.Result over the 30 s window (derived from the two summary lines below):
The gain is CPU-side:
Driver.Packet.draw67.0 → 56.9 ms andDriver.Present14.6 → 8.3 ms per frame. Profiled runs confirm the mechanism: the[storage] uploads by pathcounter for the clear targets goes fromcpu 109 / 6948.8 MiBtocpu 0 / 0.0per 10 s window.gpu_busyper present is unchanged in character (38.5 → 40.6 ms, more frames presented).Summary lines of
aps5-summary.jsonl(the main line'sdirtyis untracked scratch files in the worktree; the branch line's is the proof changes uncommitted at capture time — their content is this PR's second commit):trace_droppedon the queue worker buffer (totals_full: false).APS5_TRACE_SECONDS/APS5_TRACE_DIR; same machine, scene and settings.Community testing (independent A/B on the builds linked above; thanks to each tester):
agc_driver_preparation_scope_settle) is a timing flake outside the DCC/texture code, 5/6 re-runs pass (known MinGW #6716 for the non-compiling test).All three report no visual change and no regression; the uniform-color path is clean on Ampere and Ada.
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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T14:27:41Z.
The conventions check still fails on ten newly added comment lines in
core/libs/prx/libSceAgcDriver/Graphics/include/DccMetadata.hpp(lines 84–100 in the failed run). The repository checker allows code comments only when the PR also updatesdocs/dev/TechnicalDebt.mdordocs/dev/debt/; these proof explanations may fit better in a debt entry with concise comments removed from the header. The failure annotation also points to the.githubUbuntu runner migration notice, which appears informational rather than a project check failure.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T14:30:27Z.
A separate reviewability gap remains in the performance report: the
aps5-summary.jsonlblock is still the literal... TODO, and the two traces are described as attached but are not present in the PR files or issue attachments. Since both traces also report dropped queue-worker events, could you provide the actual comparable summary lines and attach the trace files (or another complete capture) so reviewers can assess the claimed change? Please keep thetrace_droppedlimitation explicit.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T15:10:15Z.
Following up on the performance evidence request: the latest PR description still needs the actual comparable
aps5-summary.jsonlvalues and the captures (or another complete capture) before the reported speedup can be independently assessed. The new overlap report also flags #6820 inTexture.cpp; please state the dependency/relationship if this change relies on it. I am not treating the benchmark claim as validated while the summary remains... TODOand the traces are unavailable.Imported from boykopovar/AnyPS5. Originally posted by NFSS10 on 2026-10-16T15:13:19Z.
@MarcZX100 it's a draft, you should not waste AI tokens in draft PRs.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T16:07:03Z.
Understood. I had checked the draft’s failed conventions output and the missing benchmark artifacts, but I’ll leave further review of this draft to you and the maintainers unless you request another pass.
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-16T17:29:34Z.
GTA V (PPSA04264) data point for this PR, Windows 11 / RTX 4090, Story mode, same scene, frame counter over 300 s, on main
eb901bcf4+ #6488 + #6892:The rendering is unchanged.
I had an alternative for the same surfaces: comp-to-single surfaces detiled on the GPU straight from the import, with each element read at its 256-byte key block start. It handles non-uniform blocks too. On top of this PR it measured 17.36, i.e. nothing more, because GTA's single-key surfaces are the uniform-color case you cover. So I'm not proposing it, and this PR is the better fit. Thanks!
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-16T18:00:36Z.
Review: COMMENTED
Linux run on NVIDIA and lavapipe, plus two things I found in the new path.
Machine: Linux, NVIDIA GeForce RTX 3070 (driver 595.99.02) and lavapipe (Mesa 26.0.3, LLVM 21.1.8). Ubuntu 26.04, i7-8700, GCC 15.2, Release. Head
dc4fb7fd9merged intomain66e290f1c(clean).agc_dcc_key_sharing,agc_driver_dcc_keys_first_write,agc_driver_graphics: pass 3/3 on the RTX 3070, and pass on lavapipe.c5c32f6e5) merged,agc_driver_dcc_keys_first_writefails on the RTX 3070 with16296 of 16384 written-back texels are neither the kernel's write nor the first texel of their 256-byte block, as you describe. So that test guards against clearing without the proof.1. No test reaches the fast clear. With
ProvedSingleUniformchanged toreturn false;on its first line, the three tests above still pass. The only call in them is foragc_driver_dcc_keys_first_write's 64 KiB surface, which is not uniform. A wrong clear colour fromSingleKeyColorFor(element read, pattern replication,FillClearColor) or a proof that never succeeds would not fail any test. A case with a uniform ClearSingle surface that checks the uploaded texels would cover it.2. The chunk read goes past the surface. In
ProvedSingleUniform(DccMetadata.cpp:770):The read uses the whole
buffer, notsize. Since the loop starts at offset 256, the last read always ends pastbaseAddress + guestBytes: by 256 bytes whenguestBytesis a multiple of 1 MiB, and by up to about 1 MiB otherwise. With a temporary print before that line, the test's call loggedguestBytes=65536 offset=256 size=65280 read=65536 past_end=256. The comparison only uses the firstsizebytes, so the result is unaffected, butReadCommittedrunsFlushGpuWritesand the read guard over the extra range, which can belong to a neighbouring resource.buffer.data(), size(orstd::span(buffer).first(size)) keeps the read inside the surface.Not run: AMD, Windows, any title, the performance claim.
GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02), lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-16T19:52:53Z.
Data point: RTX 3060 12 GB (NVIDIA 617.42), i5-12400F, Windows 10 19045, MinGW GCC Release. Minecraft Dungeons II (PPSA16064 01.100.100), title screen, no input, 200 s rows,
APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1;mainc84249186vsmain+ this PR, interleaved with three other PRs in one batch, two rounds. FPS is the mean of the last 10[present]windows, GPU busy and idle gaps per frame over the last 8. This scene is CPU-bound on this machine (45-47 ms of idle gaps per frame).mainWithin the row spread on this scene; no regression. 0 fatal.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-16T20:33:46Z.
Tested on Windows 11, RTX 3070 (Ampere, driver 617.42), WinLibs GCC 15.2 build of dc4fb7fd9:
The uniform-color DCC clear path is clean on Ampere.
Imported from boykopovar/AnyPS5. Originally posted by NFSS10 on 2026-10-17T23:42:44Z.
Both fixed, thank you for the precise reports and for the
past_end=256measurement, which made the second one unambiguous.1. Fast clear now has a direct test (third commit,
test(agc): cover the uniform single-key DCC clear).RunUniformSingleClearlays out a surface whose every 256-byte block starts with the same color, soProvedSingleUniformholds anduploadclears on the GPU. It checks both halves of the contract:ThreadLookupOutcomes().counts[UploadClear]increments andUploadCpudoes not. This is the mutation guard you asked for, withProvedSingleUniformforced toreturn falsethe case fails withuniform single-key clear: the first write read the surface and uploaded it instead of clearing it on the GPU(verified locally; whichever block it runs on first, unwatched or write-watched). The counter was the only signal that works on every machine: on my box the write watch does not survive the import, so theGuestSnapshotValidcheck alone could not tell the paths apart.FillClearColorvalue fails the case.2. The chunk read is bounded to the surface.
ProvedSingleUniformnow readsstd::span(buffer).first(size), so the gather never reads pastbaseAddress + guestBytes— no read guard orFlushGpuWritesover a neighbour's memory. The comparison logic is unchanged.Both commits are on the updated head (
275008a34), rebased onto currentmain(c0a7468f6).agc_driver_dcc_keys_first_writepasses; the perf commit alone still fails it 3/3 as you measured.Imported from boykopovar/AnyPS5. Originally posted by CPritch on 2026-10-20T07:25:12Z.
Ran this on GTA V (PPSA04263 01.010.002), Linux 7.2.8-zen1-2-zen, NVIDIA GeForce RTX 5060 Laptop GPU, NVIDIA 615.71.09, Graphics Mode Performance, the Story prologue after Resume Story, with no input.
main
eaa5c9238against maineaa5c9238+ #6848 at275008a34, same machine and session, two runs each in the order A B A B, window frames 3500:700, caches warm, APS5_TRACE_EVENTS=4194304 (BUILD.md's remedy for full trace buffers), no other APS5_TRACE_* or APS5_PROFILE_* switch, log not redirected. The harness navigates the menus from frame dumps in boot and load to present 3300 (APS5_DUMP_FRAMES=110, every 30 presents), which stop before the window.Frame p50: main 81.5, 81.4 ms, with #6848 78.0, 78.5 ms (-3.2 ms, -3.9 %). GPU busy per present: 64.6 and 65.8 ms.
Not tested: other scenes, Fidelity mode, other GPUs.
Written with AI assistance (Claude Code); measured on the machine above.
Summary lines (main, then the PR):
{"commit":"eaa5c9238687","dirty":false,"env":{"APS5_DUMP_FRAMES":"110","APS5_DUMP_FRAMES_EVERY":"30","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"","APS5_TRACE_EVENTS":"4194304","APS5_TRACE_FRAMES":"3500:700"},"gpu":"NVIDIA GeForce RTX 5060 Laptop GPU","driver":"NVIDIA 615.71.09","os":"Linux 7.2.8-zen1-2-zen","resolution":"3840x2160","window":{"spec":"frames 3500:700","first_present":3500,"ms":58201.614},"presents":700,"frame_ms":{"p50":81.458,"p90":92.441,"p99":119.244,"max":154.395},"gpu_busy_ms_per_present":64.095,"worker_busy_pct":{"queue worker 0x0":3681.528},"top_phases_ms_per_frame":{"Driver.EndSubmission":2993.481,"Driver.Packet":65.187,"Graphics.Draw":61.021,"Graphics.Draw.draw_and_resource_release":57.137,"Driver.Packet.draw":51.674,"Driver.Draw":51.445,"VideoOut.Flip":25.405,"Driver.Present":25.388},"trace_dropped":false,"trace":"aps5-trace-eaa5c9238687-1140752.json.gz"}
{"commit":"ed8a97164af4","dirty":false,"env":{"APS5_DUMP_FRAMES":"110","APS5_DUMP_FRAMES_EVERY":"30","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"","APS5_TRACE_EVENTS":"4194304","APS5_TRACE_FRAMES":"3500:700"},"gpu":"NVIDIA GeForce RTX 5060 Laptop GPU","driver":"NVIDIA 615.71.09","os":"Linux 7.2.8-zen1-2-zen","resolution":"3840x2160","window":{"spec":"frames 3500:700","first_present":3500,"ms":55565.167},"presents":700,"frame_ms":{"p50":78.047,"p90":86.715,"p99":109.594,"max":133.464},"gpu_busy_ms_per_present":65.694,"worker_busy_pct":{"queue worker 0x0":3554.653},"top_phases_ms_per_frame":{"Driver.EndSubmission":2760.572,"Driver.Packet":58.866,"Graphics.Draw":57.655,"Graphics.Draw.draw_and_resource_release":53.98,"Driver.Packet.draw":45.788,"Driver.Draw":45.572,"VideoOut.Flip":26.917,"Driver.Present":26.906},"trace_dropped":false,"trace":"aps5-trace-ed8a97164af4-1149197.json.gz"}