perf(agc): find a draw's highest index with a loop the compiler vectorizes #8567
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8567"
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 imellag on 2026-10-20T16:48:14Z.
What
HighestDrawIndex(VertexInput.hpp) read every index through a branch on the index size and kept the maximum in astd::optional, so neither clang nor GCC vectorized it. An indexed draw scans its whole index range whenever the range is not kept (fewer thanRecorder::KeptIndexRangeIndicesindices, or memory that is not tracked), so the draw committer pays this loop on most small draws. The scan now runs one loop per index type: the plain maximum without primitive restart, and with restart the maximum of the indices masked by "is not the restart index", plus an OR of those masks for "some index was not a restart index". Results are unchanged.highestDrawIndexTestsin tests/Graphics.cpp gains cases for an empty range, long ranges, indices above 2^31, and an unaligned range with a trailing byte.Tested
main5f7aa5570the libraries do not build on macOS, so theretests/Graphics.cppwas only compiled against this header.agc_driver_graphicswas run on the macOS integration head7cf8c610c(former #7332) with this commit: it passes, and a negative control (dropping the last index of ranges of 2048 bytes or more) makes it fail.-O3at baseline x86-64. GCC vectorizes all four loops (SSE2); the old loop stays scalar.APS5_TRACE_SECONDS=140:10only, base and change alternated twice in one session. The base is7cf8c610cand notmainbecause titles do not run frommainon macOS. Frame times do not change (this scene is paced by the queue worker and the GPU); the draw committer is busy about 1 ms less per frame:7cf8c610c7cf8c610cSummary lines
The queue worker's trace buffer filled after about 5.7 s in every capture (
trace_dropped), so its column covers only that part of the window; the draw committer dropped nothing. The four traces are attached in a comment below. Linux and Windows were not run; the change is in a header shared by all hosts, so timings on real x86-64 hardware with GCC or MSVC are welcome.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)7cf8c610c; the change itself is CPU-only)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T17:04:15Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppImported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-20T17:12:21Z.
Traces of the four captures in the table above, in the same order (each file name matches the
tracefield of its summary line):1-base-1-aps5-trace-7cf8c610c6a7-32751.json.gz
2-change-1-aps5-trace-91f4eee41c3a-34344.json.gz
3-base-2-aps5-trace-7cf8c610c6a7-35951.json.gz
4-change-2-aps5-trace-91f4eee41c3a-37509.json.gz
They open in ui.perfetto.dev;
python3 tools/trace_digest.py <trace>gives the per-thread table the draw committer numbers come from.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T21:56:23Z.
Checked the restart masking and the
keptOR against the old loop (empty range and all-restart ranges still return nullopt, no read past the range), the includes, and the new tests (empty, long u16/u32 ranges, indices above 2^31, unaligned range with trailing byte); merged.