perf(libc): copy strided guest rows out with batched checked writes #20832
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20832"
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-11-15T16:26:19Z.
What
libSceVideodec'sCopyPicturecopies each decoded picture into the guest frame buffer with oneGuestCopyOut_nid_no_patchper row:heightluma rows plusheight / 2chroma rows. Each call is aprocess_vm_writevsystem call on Linux, so a 1080p frame costs 1,620 system calls, and it runs on every decoded frame.This adds
GuestCopyOutRows_nid_no_patch(destination, destinationPitch, source, sourcePitch, rowBytes, rows)to libc's checked-copy helpers.CopyPictureuses it for both planes.How it works on each platform
process_vm_writevcall carries up to 1,024 rows, one local and one remoteiovecper row. A 1080p frame takes two calls.errnopreserved, asGuestCopyOut_nid_no_patchdoes. Rows before the fault are written, as the per-row loop wrote them.GuestCopyOut_nid_no_patch.VirtualQuery, reusing each queried region across rows, and then copied withmemcpy. A failure is reported before anything is written. The per-row loop could leave earlier rows written; this cannot.GuestCopyOut_nid_no_patchloop.Unchanged behaviour
rowBytesof each row is written. Padding between rows stays untouched, as before.HostWriteguard covers the span from the first row to the end of the last.CopyPicturereturns the sameVideodecErrorFrameBufferPointerfor an unwritable buffer, so the export's results don't change.glReadPixels's clipped-row path (#20807) could use the same helper later. That's a follow-up, not part of this PR.libSceVideodec2's frame output is covered separately by #20614, which stages the picture and copies it out in one piece.Tested
Linux (Ubuntu 26.04.1), GCC 15.2, Release.
New
guest_copy_out_rowstest:PROT_NONEpage fails witherrnoleft at 71.0x10), null and overflowing destinations fail.guest_videodec(decode throughCopyPicture, plus the argument and frame-buffer checks) still passes.Microbenchmark (i7-13700K pinned to one core, best of 5 × 50 copies,
GuestCopyOut_nid_no_patchper row againstGuestCopyOutRows_nid_no_patch):Merge checks:
git merge-treeagainstmainis clean.General.cpp/General.hpporlibSceVideodec/Export.cpp(#20315, #19451, #18112, #15973, #11446, #9371, #20678), the conflict count is the same as each already has withmain.tools/check_conventions.pypasses on the branch and this body.Windows 11 VM (GT 1030, WinLibs GCC 15.2 UCRT, Release): the head and its merge base were built with
guest_copy_out_rows_testsandguest_videodec_tests.guest_copy_out_rowsandguest_videodecpass 3 of 3 on the head, which exercises theVirtualQuerybranch.guest_videodecalso passes 3 of 3 on the base.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)