fix(agc): copy an indirect draw's vertex buffer only up to its last element #5975
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5975"
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 milescoviello on 2026-10-14T17:47:59Z.
What
Forspoken (PPSA03984) stops on an indirect draw:
The draw is instanced, with six per-instance attributes (fetch index 1) in one buffer of 96-byte records, at offsets 0, 0x10, 0x20, 0x30, 0x40 and 0x50. Each descriptor has 0x80000 records, so
records * strideis the 48 MiB buffer, and the 16 KiB after it are not readable (a---pregion in/proc/self/maps). Because an indirect draw's counts are unknown,prepareDrawInputscopies each descriptor'sVertexBufferExtent, which wasrecords * stridefrom the descriptor's own address. For the attribute at 0x50 that ends 0x50 bytes past the buffer. The last record's element ends at(records - 1) * strideplus the element's bytes from the descriptor's address, inside the buffer, and that is as far as the fetch can read.VertexBufferExtentnow ends there. That is whatVertexBufferReadSizegives for a direct draw that reads the last record. A zero stride, a null descriptor and a descriptor without records are handled as before. The comment aboveVertexBufferOutOfBoundsSelect, which described the old extent, is removed.agc_vertex_inputnow expects32 * (records - 1) + 16where it expected32 * records, checks that the extent equalsVertexBufferReadSizeat the last record, and checks that an attribute at offset 16 of a 32-byte record ends with the descriptor's records. Withmain'sVertexInput.hppit stops at "cached layout froze the indirect descriptor extent".Tested
Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on
maindb06cb497, then rebased ontomain8b8bfe0b6, RTX 4070 Ti with NVIDIA 595.99.02:libSceAgcDriverpass after the rebase.agc_driver_stencil_ref_exportis skipped because the device lacksVK_EXT_shader_stencil_export, andagc_host_import_sparseandagc_driver_sparse_dma_buf_importbecause/dev/udmabufis not accessible here.--to-inteland run on Linux under a 15 GiB memory cap. Both builds also carry #5937, without which the title stops at 43 s, and #5511, without which a start from a filled shader cache runs out of memory within 10 s; they differ only inlibSceAgcDriver.prxand share one shader cache:tools/check_conventions.py --base upstream/mainpasses, andtools/pr_overlap.py --branchfinds no overlap.PPSA03984-app0) on currentmain8856f180c, 1920x1080, pad input, one run each:mainstops at 22 s on theDB_RENDER_CONTROLcheck (#5937); with #5937 it stops at 61 s on the indirect vertex buffer read (#5975); with #5937 and #5975 at 116 s on the depth pyramid view (#5982); with all three it draws an in-game scene by 60 s (the lower half still black, about 4 FPS) and runs to 195 s, wherevkAllocateMemoryfor a render target fails withVK_ERROR_OUT_OF_DEVICE_MEMORYon the 12 GB RTX 4070 Ti. The memory goes to retired depth surfaces that are never freed. With #6465 added as well, it reaches a 600 s limit (onmain0c4816f61).Not checked on Windows or on a console.
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
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T19:17:00Z.
Review: COMMENTED
The extent now matches what the fetch can actually reach:
(records - 1) * strideplus the element's bytes, which is also whatVertexBufferReadSizegives for the last record. The added check that the extent equals the read of the last record pins the two together. The Forspoken case (attribute at 0x50 of a 96-byte record, buffer followed by a---pregion) is exactly the one the oldrecords * stridegot wrong. It also shortens every indirect draw's copy bystride - elementBytesfor each attribute past offset 0, though that's small.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-15T20:13:20Z.
@CnRJay thanks for reviewing this, and for checking the extent against
VertexBufferReadSizefor the last record.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T19:49:01Z.
Checked the new extent
(records - 1) * stride + element bytesagainstVertexBufferReadSizefor the last record (same value;VertexBufferExtentis only used for indirect draws, Draw.cpp:1163). Built and ran thelibSceAgcDrivertests on RADV:agc_vertex_inputpasses and fails withVertexInput.hppreverted. Merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T21:09:06Z.
A re-check on current
main1b1f8483c, which now has #5937. Forspoken (PPSA03984), Linux, RTX 4070 Ti, 15 GiB cap, pad input, warm cache. #6814 is merged on top in both builds, because without it the title crashes at start-up on #6805's race.main+ #6814: 2 of 2 runs stop on this PR's error, at 36 s and 48 s:guest memory is not readable at 0x103a03c000 (range 0x103703c3c0+0x2fffc90)and... at 0x1037024000 (range 0x1034024000+0x3000050).main+ #6814 + this PR + #5982 + #6465: runs the full 300 s (1 of 1).So with #5937 merged, this is now the title's first stop on
mainafter the start-up race.AI-assisted: yes