fix(libSceAmpr): dynamically expand command buffer capacity on append #11727
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11727"
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 camezaro-intc on 2026-10-27T05:58:09Z.
What
When appending commands to an
Apr::CommandBufferObjectinlibSceAmpr, dynamically expand the backing storage usingGuestHeapAllocate_nid_postfix/GuestHeapReallocate_nid_postfixwhen an append would exceed the buffer's initial capacity (buffer->size), rather than failing immediately withSCE_KERNEL_ERROR_EBUSY. Track expanded buffers and free dynamic storage insceAmprCommandBufferDestructor,sceAmprAprCommandBufferDestructor,sceAmprCommandBufferClearBuffer,sceAmprCommandBufferSetBuffer, andsceAmprAmmCommandBufferDestructor.AnyPS5 uses higher-level synthetic command structs (e.g.
ReadFileCommandat 40 bytes andWriteAddressCommandat 32 bytes) that exceed the byte footprint of native PS5 console command dwords. Fixed-size buffers sized by guest titles for console command sizes would otherwise run out of space on multi-chunk command streams and drop completion writes.Tested
Windows 11 Pro, Call of Duty: Modern Warfare III (PPSA24263). Verified that fastfile decompression reading advances past slot 0 (offset 0x500000 / chunk 10) through 0x580000+, loading
eng_code_post_gfx.ffand progressing throughcode_reloadable.ffup to offset 0x900000 and reachingsceGameUpdateCreateRequest. Passedctest --test-dir build -R guest_ampr -V(3/3 tests pass).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-27T06:19:42Z.
Review: APPROVED
Reviewed exact head aa0fa80b8283c3fee155c301dbd4faacb01f2738. The full
guest_ampr_teststarget builds locally. Normal CTest startup stops at the repository's CPU-feature guard because this Xeon lacks AVX2; with only that guard bypassed in the disposable review worktree,ctest -R '^guest_ampr_markers$'passed 1/1. I restored the guard and rebuilt the test target; the review worktree is clean.git diff --checkand current-base conventions pass. The author reports the Windows title reproduction and 3/3 focused CTests; hosted product checks were skipped, so I did not independently verify Windows or the title. I found no blocker and approve.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T09:02:03Z.
Review: CHANGES_REQUESTED
Thanks, the previous points (AMM submit resolution, constructor cleanup, debt entry) are addressed. Remaining:
Export.cpp:188-189:AppendNop(and soNop,NopWithData,ConstructNop) still returnsSCE_KERNEL_ERROR_EBUSYat the original size, while every other append now grows. A buffer filled up to its bound by Nops behaves differently from the rest. Route it throughEnsureCommandCapacity, with a test.ClearBufferorSetBuffer. Please state a cap (an append past it keeps returningEBUSY, which is also the console's contract for a full buffer that titles use to flush and submit) and give peak RSS on the MW3 load before/after in the PR (docs/dev/CONVENTIONS and the memory rules for caches/kept-alive allocations).Export.cpp:44,Api.hpp:156: a test hook exported from the production library. Please use a seam that does not ship in the export surface (for example a test-only allocator override compiled into the test, or make the failure reachable through the cap above).Export.cpp:111-118:ResolveBufferBasematches any registered original base. If the guest reuses that memory for another buffer without destroying the expanded one, a submit of the new buffer is redirected to the stale allocation. Add a test with a rebind of the same memory through a second buffer object, or key on the buffer as well.docs/dev/debt/libSceAmpr.md:8): also record that a full buffer no longer reportsEBUSYbelow the cap and that growth places commands in memory the guest did not allocate. On the design question: growth is acceptable as the stop-gap given the points above; moving the encoding to console sizes can follow separately.Please rerun
ctest -R guest_amprafter these and note the result.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T17:45:29Z.
Review: CHANGES_REQUESTED
Thanks, the Nop path, the 32 MiB cap, the removed export and the rebind handling look right. Remaining:
Export.cpp:46:if (required > MAX_EXPANDED_BUFFER_CAPACITY) return EBUSYruns beforeif (required <= buffer->size) return 0. A buffer the guest bound with more than 32 MiB now returnsEBUSYfor appends that fit in its own memory, which worked before this PR. Check the cap only when growth is needed (after therequired <= buffer->sizecheck). Add a test with a bound size above the cap.EBUSY), as asked in the previous round (docs/dev/CONVENTIONS, memory rules for kept-alive allocations). Also say how many buffers can be expanded at once, since the cap is per buffer.ENOMEMpath (heap allocation or realloc failure leavesbase/size/offsetuntouched) lost its test with the hook. If there is no seam that does not ship in the export surface, say so in the PR; otherwise please cover it.Export.cpp:549:SetBufferon a second object with the same memory releases the first object's expansion and resets itsoffset/numCommandsto 0, dropping its recorded commands. Add that to the debt entry.guest_ampr_markers,guest_ampr_threadsandguest_ampr_cpp_error; please confirm the first one ran on this head, since that is the one that holds the new tests.