perf(agc): serve a buffer range that crosses host import windows in place from one joined import #22072
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22072"
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 nicolasabosch on 2026-11-17T03:55:13Z.
What
A buffer range that starts inside one registered range and crosses into the next, across a host import window boundary, has no import that covers it, so
maincopies it through the CPU on every bind: a guest read that waits on the recorder's fence while holding the GPU mutex.UploadFinishnow joins the adjacent registered ranges such a buffer crosses into one import and binds the buffer in place, as for any range one import covers.joinedRunaccepts a buffer that starts inside the first crossed range when that range is no larger than the import window and the crossed ranges are at most two import windows longer than the span being joined (run.bytes <= end - begin + 2 * window). That span is the buffer, widened byimportJoinedto the whole of any joined import it starts or ends in, as for every join, so a buffer that ends inside an existing joined import is measured up to that import's end. This is intended: the new join replaces that import, so it must cover it. A first range larger than the window keeps the rule from #15658, whose test (a buffer bound from inside a range larger than the import window across more than a window of small ranges was joined) still passes.findImportfinds it on the next bind. Only non-sparse regions that are host-backed or writable take this join; a join that cannot be made leaves the range copied as before.APS5_NO_JOIN_STRADDLE=1turns the join off (newENVIRONMENT.mdrow).deviceLocalHasRoomno longer throws on a device without a device-local memory type; it reports no room instead.docs/dev/debt/changes/perf-agc-join-straddling-imports.md.Overlap: #5372 relaxes the same
joinedRuncheck for a buffer bound from inside a range (begin == run.base || run.bytes <= window) and edits the same assertion inimportJoinTests. The two rules differ: #5372 caps the joined run at one window and also widensimportJoinedto non-joined neighbouring imports; this change keeps the widening as it is and bounds the run by the buffer's size plus two windows. Whichever merges second needs a rebase on these lines; the order is to be agreed with its author.Tested
Windows 11 Pro, MinGW (GCC, Release), NVIDIA GeForce RTX 4070 Laptop GPU.
ctest -R '^(agc_graphics_profile_draw|agc_bda_staging.*|agc_changed_copy.*|agc_driver_host_import_windows|agc_driver_host_import_alias_failure|agc_driver_partial_resident_alias)$'passed (8/8). After review (61cc86904e):deviceLocalHasRoomkeeps its 250 ms throttle on a device with no device-local memory type, and the read-only V# test sorts the address ranges before checking coverage; the same 8 tests pass, with the validation layer and noVUID-error, andagc_driver_graphicsand theagc_driver_bda_*tests pass too (17/17).agc_graphics_profile_drawruns the BDA import-join tests:importJoinTestsnow binds 32 bytes from 16 bytes before the end of one 64 KiB piece into the next and requires one joined import over both pieces, bound in place with nothing copied;spaceReadAcrossImportsTeststakes a third build and requires the read-only V# across two imports to be bound in place at its offset in the joined import without dissolving the cached address space. WithAPS5_NO_JOIN_STRADDLE=1,agc_graphics_profile_drawfails (1 run): "a buffer bound from inside the first of two pieces no larger than the import window across the import window boundary was not joined and bound in place".Validation layer: the same tests on
main(ec9f142628) and on this branch withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1throughctest -V(Khronos validation layer 1.4.363.1): every log showsInsert instance layer "VK_LAYER_KHRONOS_validation"(11 times in each), none reportswas not found but was requested by env var VK_INSTANCE_LAYERS, and neither run logs aVUID-error.Performance (captured by @Logan1h on Windows 11, Ryzen 5 7500F, RTX 4070 SUPER, NVIDIA 621.24; paired 60 s captures of the same practice fight in EA SPORTS UFC 6 (PPSA23566, 01.004.000),
mainvs this change; traces andtrace_digest.pyoutputs attached):Traces and
trace_digest.pyoutputs (both traces reporttrace_droppedafter the queue-worker event buffer fills; the summary lines, phase totals and import counters are complete):b7aeb6f406with read-only diagnostics: event trace, digestThe GPU-busy increase comes from direct host-import reads replacing the CPU-side copies.
Second capture, of this port (with the guard for #15658's rule), on another machine (NVIDIA GeForce RTX 4070 Laptop GPU, driver 616.92, Intel Core i9-14900HX, Windows 11 Pro 26300): one 60 s capture each with
APS5_TRACE_SECONDS=660:60, warm shader caches, same scripted practice fight of EA SPORTS UFC 6 (PPSA23566, 01.004.000). Both builds aremain2a8a0d1fc3plus the pad-script commit of #22064, which only injects the scripted input.mainseconds 660:60 from present 11012: 55 presents, frame p50 1004.2 / p90 1086.4 / p99 5716.0 / max 5716.0 ms, GPU busy 288.6 ms per presentseconds 660:60 from present 12256: 173 presents, frame p50 327.7 / p90 356.0 / p99 394.0 / max 3685.6 ms, GPU busy 286.3 ms per presentTraces and
trace_digest.pyoutputs:main: trace, digest; this change: trace, digest.aps5-summary.jsonllinesmain:
this change:
Checklist
main; no other open PR implements the same functions (#5372 changes the samejoinedRuncheck; see What)NotImplemented_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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T09:08:25Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
d86f2cb161de60dee98520fee81478cdb9df64e2, basemain.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp:6290: when no device-local memory type exists,deviceLocalHasRoomreturnsfalsebefore it storescheckedMs. The 250 ms throttle is then skipped, and the memory properties are queried on every call for that device. The case is unlikely on real hardware, so this is cosmetic.Not verified
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp:2897: the newcoveredloop inspaceReadAcrossImportsTestsassumesAddressRanges()returns ranges in address order. I did not check that.GuestBufferMemory.cpp(changed hunks and their callers at head, through the reader),BdaResources.cpp(changed hunks and the setup it uses),ENVIRONMENT.mdandperf-agc-join-straddling-imports.md(from the diff). Excluded: none.To get this to a good state
Nothing is required.
Optional: clear
checkedMs(or return before the throttle check) in the no-device-local branch ofdeviceLocalHasRoom, and check the ordering ofAddressRanges()in the new test loop.Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-17T09:35:17Z.
Review: COMMENTED
Tested on macOS 27.2 on an Apple M4. This is an x86-64 build under Rosetta with Apple clang 21.0.0, on MoltenVK 1.4.2 from the LunarG Vulkan SDK 1.4.363.1.
Method. The base was
mainata72186d3cfplus #22056 and #22074, which fix the macOS build of two other targets; both have since merged. I built the base and this PR merged onto it (a clean merge) in two separate build directories. I ran them alternately, base then PR, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer: three runs each. The pattern adds the tests named in the description to the BDA and graphics tests:agc_graphics_profile_draw(runsimportJoinTests)agc_driver_host_import_windowsagc_driver_host_import_dma_buf_watchwas not found but was requestedVUID-linesVUID-VkDeviceCreateInfo-sType-uniqueThe 16
sType-uniquelines come from device creation and appear on the base as often as with the PR, so this PR adds no validation errors.Negative control. I kept this PR's test and restored the base's
GuestBufferMemory.cpp. Thenagc_graphics_profile_drawfails witha buffer bound from inside the first of two pieces no larger than the import window across the import window boundary was not joined and bound in place. So the join path runs on macOS: MoltenVK's host import accepts the joined range on the M4.Not tested: the speed claim, since I have no title or capture here. I also didn't try
APS5_NO_JOIN_STRADDLE=1.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T15:54:20Z.
Review: COMMENTED
Reviewed — no blocking findings
The changed hunks show no verified defect, but the review is incomplete: no build or test was run, and the full
GuestBufferMemory.cppwas not read, so this is a comment, not an approval.Nothing blocks this; the points below are optional.
What I ran
Exact head:
61cc86904ef77b8f1273d43fa415962453761763, basemain. No build, noctest, no validation-layer run. I read the run folder (description.md,commits.md,manifest.json,diff.patch,files.json) and the house rules, then read repository code at the head withrepo_read.py:Files read:
GuestBufferMemory.cppthrough its changed hunks indiff.patchand the ranges above, not the whole file (8124 lines, excluded from the run folder for size).tests/BdaResources.cpp,docs/dev/ENVIRONMENT.mdand the debt fragment through their changed hunks indiff.patch; I did not open their full copies infiles/. No file was excluded by rule.Results
files.jsonctestVUID-errorFindings
Blocking
None verified.
Non-blocking
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp:6290: on a device with no device-local memory type,deviceLocalHasRoomreturnsfalsefor everybytes, including0. The normal path returnsbytes <= room, which istruefor0when room is0. This branch also leavesliveShadowLimitat its previous value. Impact looks small; I did not check whether any caller passes0.Sources
joinedRunwith the straddle clause:github.com/boykopovar/AnyPS5@61cc86904e/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp (L1837-L1847)continuesRun:github.com/boykopovar/AnyPS5@61cc86904e/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp (L1675-L1677)deviceLocalHasRoom:github.com/boykopovar/AnyPS5@61cc86904e/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp (L6275-L6302)UploadFinishjoin loop:github.com/boykopovar/AnyPS5@61cc86904e/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp (L6756-L6761)github.com/boykopovar/AnyPS5@61cc86904e/core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp (L708-L718)Not verified
ctest, validation-layer and performance figures in the description are the author's; I did not confirm them.GuestBufferMemory.cppwas read only in the ranges above. Callers ofjoinedRunandimportJoinedoutside those ranges were not checked.continuesRunchecks readable, writable and gpu, but not host-backed. The straddle gate inUploadFinishchecks only the target region. I did not confirm whether a host-backed read-only region can join a neighbour that is not host-backed.To get this to a good state
Nothing is required.
To move this to
APPROVE, the next review needs the fullGuestBufferMemory.cppread, and the author's build andctestoutput for head61cc86904ef7attached.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T16:13:57Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
58ef1c564bd48f92de6e100278b24af38fe64ff1, basemain. No merged-preview check.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp:1845: the straddle bound compares againstend - begin.importJoinedmay widenendfirst (GuestBufferMemory.cpp:2335,end = high->base + high->bytes), so for a buffer that ends inside a joined import the allowed run is larger than "buffer plus two windows" in the description. The run stays bounded, so this is not a defect shown. Confirm that the wider bound is intended, or take the bound from the originalend.joinedRuncheck, and that the merge order must be agreed with its author. That is coordination, not a code defect.Not verified
agc_*test runs, theAPS5_NO_JOIN_STRADDLE=1negative control and the validation-layer run are author-reported.GuestBufferMemory.cppis 8124 lines. I read the changed hunks and the functions they call (joinedRun,crossedRun,importJoined,importRunAt,deviceLocalHasRoom, and the join loop inUploadFinish). How the join interacts withrefreshImports, budget eviction andfailedJoinswas not traced.deviceLocalHasRoomwith no device-local memory type: room is 0 and the shadow limit falls back to the default inshadowBytesLimit. Checked by reading; not run.dissolvedImportscounter was not checked.HostImportOffsetis declared inGuestBufferMemory.hpp.docs/dev/debt/changes/.Sources
58ef1c564bd4:GuestBufferMemory.cpplines 1837–1847, 2333–2344, 6283–6299, 6756–6760;tests/BdaResources.cpplines 708–715 and 2878–2903. No permalinks are given.To get this to a good state
Nothing is required.
Optional:
GuestBufferMemory.cpp:1845whenendwas widened.Files: all four files in the reviewed list were covered.
GuestBufferMemory.cppwas read in the ranges above,BdaResources.cppby its diff and lines 2860–2884, andENVIRONMENT.mdand the debt fragment by their diff only. Nothing was excluded.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T18:31:42Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
4e740bb21f360a6f4685df024b96eeedd4602909(basemain), PR #22072, 4 files in the review folder.files.jsonanddiff.patchfrom the review folder.repo_read.py catonGuestBufferMemory.cpplines 1820–1850, 6270–6305, 6740–6760;repo_read.py searchforjoinedRun,shadowBytesLimit,HostImportOffset,memoryTypeCount,hostBacked,#include <optional>).Results
Commands
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp:6292— when no memory type is device-local, the new branch setsliveShadowLimittoshadowBytesLimit(0), which returns 256 MiB at head. The description says only that the check "reports no room". The room is 0, so nothing is staged there, but the shadow limit is a separate value. Say what it should be, or name the reason for 256 MiB.core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp:1845— the straddle rule reads correctly against the description: the first crossed range is at most one window, and the run is capped at the widened span plus two windows. No defect found, but the cap has no test that sits exactly at the boundary.Not verified
4e740bb21f36was not inspected.GuestBufferMemory.cppis 8124 lines. I read the changed hunks and the three ranges above, not the whole file. Where the diff's changed regions depend on helpers outside those ranges, I relied on the reader searches.diff.patch. I did not open their full texts infiles/.docs/dev/debt/changes/perf-agc-join-straddling-imports.md) was not verified.To get this to a good state
Nothing is required.
Optional: state the shadow limit used when no device-local memory type exists (see the non-blocking point above). Rerun the listed tests on the next head, if the head changes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T01:26:05Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the reviewed code supports the intended straddling import behavior, and the author-reported checks provide supporting evidence.
What I ran
Head reviewed:
7099836106bb93eb24928c11fc042b4a27f36658. I inspected the prepared diff and targeted source throughrepo_read.py; no commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full text of
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppwas excluded because it was too large for the review folder. I read targeted ranges covering the changed join logic, import creation, device-local room check, andUploadFinishcall site. The other changed files were read at their changed sections:core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp,docs/dev/ENVIRONMENT.md, anddocs/dev/debt/changes/perf-agc-join-straddling-imports.md. Tests, performance captures, and physical console behavior were not independently verified; the description reports the test and capture results.To get this to a good state
Nothing is required.