feat(tools): add the APS5_* and ANYPS5_* environment reference and check it #6078
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6078"
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 011010 on 2026-10-14T21:26:44Z.
What
Add a reference for the
APS5_*andANYPS5_*environment variables and a check that keeps it current, as proposed in discussion #1284.docs/dev/ENVIRONMENT.md: every name the code reads throughgetenv,IsEnvironmentSet,kibSetting,MaskFromEnvironment,EnvInt,configured/PipelineSwitch,environmentCount,GetEnvironmentVariableA,GetEnvironmentVariableWandaddWideString(436 today), one table per library, with its kind, the value used when it is unset, the source file and a one-line description.tools/env_reference.py: lists the names the code reads with their kind and default, emits the table rows (--table) and compares them with the document (--check).tools/check_conventions.py: a newenv-referencerule (hard failure, as discussed). It reads the pull request's own diff, so it never executes pull request code and it only checks the names the pull request adds or stops reading: a name the diff adds with no row is reported at the line that reads it, a row whose name the diff stops reading is reported on the document, and a row the diff removes while the head still reads its name is reported on the document.tools/tests/test_env_reference.pyandtools/tests/test_check_conventions_env_reference.py: unit tests; registered inCMakeLists.txt.Tested
Linux and macOS.
python3 tools/env_reference.py --checkreports 436 names, all documented;python3 tools/check_conventions.py --base origin/main --head HEADpasses; the tool's tests pass. Rebased onto currentmainand rechecked on Windows 11 (Python 3.14):python tools/env_reference.py --checkreports 436 names, all documented,python tools/check_conventions.py --base upstream/mainpasses, and the 41 scripts undertools/testspass. The descriptions were written from the call sites, and the rows the code does not settle are the ones to check again at review (theAPS5_HOST_IMPORT_MIBdefault and theAPS5_DUMP_TARGETS/APS5_NO_RESIDENT_TARGETSinteraction among them).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-14T22:45:31Z.
Thanks for this. I checked the rows we use most against the code at the PR's base (
f785b88a6). Most of them match. A few need fixing:APS5_DUMP_TARGETSsays it "saves the first n renders of every color target". It only dumps targets that are not resident. The copy intobinding.dumpis on the non-resident write-back path, after thebinding.resident != nullptrcontinue, and only whenbinding.gpuTilingis set (Draw.cpp:2333-2339). Multisampled and proxied targets are skipped as well. GPU-tiled targets are normally resident, so in practice the dump needsAPS5_NO_RESIDENT_TARGETS=1. Any non-zero value also turns off recorded draws, so every draw runs synchronously (Draw.cpp:1995, 2088). Files go to the working directory astarget_<address>_<n>.raw(Draw.cpp:2385).The scanner misses three names that BUILD.md:176 already documents:
APS5_THREAD_NICE(default -10),APS5_THREAD_RT(default 10) andAPS5_THREAD_RTTIME_US(default 200000). ThreadPriority.cpp reads them through its localEnvInthelper (lines 228, 256, 264), so neitherenv_reference.pynor theenv-referencerule sees them.APS5_CRASH_INDIRECT_MEMORY(CrashReport.cpp:335,GetEnvironmentVariableA) is missed for the same reason.main has moved since the base. Seven names read on current main (
eea428ca8) have no row:APS5_NO_DRAW_DATA_HITS,APS5_NO_DRAW_STAGE_DATA_HITS,APS5_SNAPSHOT_CHECK_FATAL,APS5_TRACE_DRAW_CACHE,APS5_VERIFY_BDA_TABLES,APS5_VERIFY_DRAW_DATA_HITSandAPS5_VERIFY_DRAW_SNAPSHOTS. Theenv-referencerule will fail after a rebase until they are added.Smaller notes:
APS5_HOST_IMPORT_MIB: your row is closer than what I wrote in the discussion. 6144 is the floor, not a flat default. The cap is the largest host heap minus 2 GiB rather than the host heap itself (GuestBufferMemory.cpp:849-851), and an unset or 0 value falls through to that computed budget.APS5_TRACE_GPUis read in six files (DisplayBuffer.cpp:246, PacketExecution.cpp:81 and 259, QueueWorker.cpp:108, Submission.cpp:303, WaitMemory.cpp:116), but the row lists only DisplayBuffer.cpp. It also prints execute lines and waits longer than 200 ms.env_referencetest in CMakeLists.txt has no TIMEOUT, unlike the tests next to it.These rows match the code:
APS5_TEXTURE_CACHE_MIB,APS5_NO_RESIDENT_TARGETS,APS5_THREAD_PRIORITY,APS5_NO_GPU_INDIRECT,APS5_NO_GPU_INDIRECT_DRAW,APS5_COARSE_TIMED_WAITS,APS5_PIPELINE_STATS,ANYPS5_GPUandANYPS5_SHADER_CACHE_DIR.python3 tools/env_reference.py --checkprints "383 name(s), all documented", andtools/check_conventions.py --base origin/mainpasses on the PR head.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by 011010 on 2026-10-14T22:56:29Z.
Thanks, all of it is taken:
APS5_DUMP_TARGETSnow says it dumps the first n renders of each non-resident color target, astarget_<address>_<n>.rawin the working directory, that a non-zero value also runs every draw synchronously, and that in practice it needsAPS5_NO_RESIDENT_TARGETS=1.EnvIntandGetEnvironmentVariableA, soAPS5_THREAD_NICE,APS5_THREAD_RTandAPS5_THREAD_RTTIME_US(with their defaults) andAPS5_CRASH_INDIRECT_MEMORYhave rows, and the tool's tests cover the two new readers.main; the seven names it added have rows.APS5_HOST_IMPORT_MIBnow reads 6144 as the floor, with an unset or 0 value using the largest host heap minus 2 GiB.APS5_TRACE_GPUnames the other five readers in its description.TIMEOUT 20.python3 tools/env_reference.py --checkreports 394 names, all documented, andtools/check_conventions.py --base origin/mainpasses on the new head.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:14:17Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)tools/check_conventions.pyL15tools/check_conventions.pyL31Some 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.
CMakeLists.txtCMakeLists.txtCMakeLists.txtCMakeLists.txtCMakeLists.txtCMakeLists.txtCMakeLists.txttools/check_conventions.pyCMakeLists.txtCMakeLists.txtCMakeLists.txtCMakeLists.txtCMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T23:10:15Z.
Review: DISMISSED
Rebased on current
main,python3 tools/env_reference.py --checkreports 21 names that have no row indocs/dev/ENVIRONMENT.md, so the newenv-referencerule fails on the merged tree:APS5_EXACT_DRAW_WRITES,APS5_LAZY_SHADER_PREPARE,APS5_LOG_STATS,APS5_LOG_SYNC,APS5_NO_DRAW_RELOCATION,APS5_NO_EPOCH_COLLECT_MAP,APS5_NO_GPU_SAMPLE_DUMPS,APS5_NO_PIPELINE_JOURNAL,APS5_NO_WINDOW_NARROWING,APS5_PIPELINED_DRAWS,APS5_PIPELINE_DISPATCH,APS5_PIPELINE_DMA,APS5_PIPELINE_DRAIN_FILLS,APS5_PIPELINE_DRAIN_LABELS,APS5_PIPELINE_DRAIN_SUBMISSIONS,APS5_SKIP_TIMING_TESTS,APS5_SPANNED_WAVE,APS5_SUBMISSION_EPOCH_EACH,APS5_SYNC_SAMPLE_DUMPS,APS5_TRACE_DRAW_PROGRAMS,APS5_VERIFY_SRT_COMPACT.Please rebase and add their rows (
tools/env_reference.py --tableprints them); the check should then report 415 names, all documented. Everything else checked out: the reader forms against the code, the rule failing when a row is removed, and the tool's tests.Imported from boykopovar/AnyPS5. Originally posted by 011010 on 2026-10-17T16:13:25Z.
Rebased onto current
main(66702f1cf) and added the missing rows.The list is 24 names rather than the 21 in your review:
mainmoved again since and addedAPS5_NO_RECT_INDIRECT,APS5_NO_RESIDENT_LINEARandAPS5_PLAYGO_UNLISTED_CHUNKS, the last one adding the new### libScePlayGosection.python3 tools/env_reference.py --checknow reports418 name(s), all documentedwith 0 stale,python3 tools/check_conventions.py --base origin/mainpasses, and the 40 scripts undertools/testspass,test_env_reference.pyamong them. I also updated the count in the body from 383 to 418.Two notes on how the rows are written, since they are the part worth re-checking:
--tableoutput. The generator reports the reader form it matched, not what the value means, so forAPS5_PIPELINED_DRAWSit sayspresence(it is an integer depth, 8 when unset) and forAPS5_SKIP_TIMING_TESTSit saysstring, taken from theGetEnvironmentVariableAsite, even though the Linux site tests it as presence. Both rows carry what the code gives,integerwith default 8 andpresencerespectively; every other row follows the same rule as the existing 394.APS5_PIPELINE_DRAIN_FILLS,APS5_PIPELINE_DRAIN_LABELSandAPS5_PIPELINE_DRAIN_SUBMISSIONSare gated bygetenv(...) == nullptr, so any value,0included, turns the ordering off.APS5_EXACT_DRAW_WRITESandAPS5_LOG_STATSuse the other form,strcmp(text, "0") != 0, and their descriptions carry the0escape. The rows say which form each name uses.On the overlap bot: #6757 adds its
debt-lengthrule at the same line of theRULEStable intools/check_conventions.py, so whichever of the two lands second needs a one-line rebase. There is no dependency in either direction, soDepends onstaysnone.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T02:53:22Z.
Picking this up while @adriadam10 is away. The 21 names from his review are all documented now, thanks. Main has added 7 more since your rebase (
tools/env_reference.py --checkon the merge with current main): ANYPS5_REQUIRE_ROBUST2, APS5_DISPMOVE_MAX_KIB, APS5_HANDOFF_SPIN_US, APS5_NO_ADDRESS_READ_PASSES, APS5_NO_DCC_PRESYNC, APS5_NO_DISPATCH_MOVE, APS5_TRACE_UDS. Please rebase and add their rows, written from the reader at each site as you did for the others.Imported from boykopovar/AnyPS5. Originally posted by 011010 on 2026-10-18T07:25:15Z.
@oneandonlydean thanks for the pass. Rebased onto current
main(ccb0c0926) and added the rows.The list is 10 names rather than the 7 in your message:
mainmoved again since, andtools/env_reference.py --checkon the merge with currentmainalso reportsAPS5_NO_DEFERRED_SETTLES(GuestBufferMemory.cpp:809, Windows only),APS5_NO_SRT_TAPEandAPS5_VERIFY_SRT_TAPE(SrtWalker/SrtTape.cpp:287and:292). All ten are documented, written from the reader at each site:ANYPS5_REQUIRE_ROBUST2,APS5_DISPMOVE_MAX_KIB,APS5_HANDOFF_SPIN_US,APS5_NO_ADDRESS_READ_PASSES,APS5_NO_DCC_PRESYNC,APS5_NO_DEFERRED_SETTLES,APS5_NO_DISPATCH_MOVE,APS5_NO_SRT_TAPE,APS5_TRACE_UDS,APS5_VERIFY_SRT_TAPE.Two rows are the reader form the scanner matches, not what the value means:
APS5_DISPMOVE_MAX_KIBis anintegerwith a default of 1024 (text != nullptr ? std::strtoull(text, nullptr, 10) : 1024ull, times 1024), but the scanner reportspresence/1024 because thetext != nullptrtest matches its null test before the integer test. The row carries what the code gives, as withAPS5_PIPELINED_DRAWSlast round.APS5_HANDOFF_SPIN_USis anintegerclamped to 0..10000, and an unset value picksHandoffSpinWindowFor's automatic window: 150 us when the process has more than 8 usable processors, otherwise none. The scanner reportsstring, and the row's description names the automatic rule instead of a default.Two notes on placement:
APS5_TRACE_UDSis read inlibSceNpUniversalDataSystem/src/Event.cppas well aslibSceNpTrophy2/src/TitleTrophies.cpp, so the description names both and the row sits under the new### libSceNpTrophy2section (the first site by path).APS5_NO_ADDRESS_READ_PASSESis also read bytests/execution/AddressPasses.cpp:274, which is the pass-split case of the address-passes test; the row describes the driver effect.I also fixed the document's opening line, which still named only
getenv,IsEnvironmentSet,kibSettingandMaskFromEnvironmentafter the last push taught the scannerEnvIntandGetEnvironmentVariableA.Verified at this head:
python tools/env_reference.py --checkreports 428 names, all documented, 0 stale;python tools/check_conventions.py --base upstream/mainreportsAll conventions checks passed; the 40 scripts undertools/testspass (Windows 11, Python 3.14).AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T07:52:01Z.
Thanks for adding the rows, the check now passes on current
main(428 names). One gap before this goes in:The scanner doesn't see names read through helper functions, and the stale rule then rejects their rows. On the merged tree these are read but have no row:
APS5_PIPELINE_JOURNAL_ENTRIES,APS5_PIPELINE_JOURNAL_MAX_MIB(throughconfigured(name, fallback)inPipelineJournal.cpp)APS5_PIPELINE_STORE_ENTRIES(throughPipelineSwitch)APS5_PM4_RING,APS5_STALL_WATCHDOG_SECS(throughenvironmentCountinSubmissionRing.cpp)ANYPS5_LOADEXEC_PARENT(au"..."string the Windows entry stub reads withGetEnvironmentVariableW)Adding a row for any of them fails
--checkwith "has a row but the code no longer reads it", so once theenv-referencerule is live nobody can document them. Could you teach both scanners those three helpers and the entry stub's wide-string form (addWideString(u"...")), add the six rows, and add a fixture line for each new form intest_env_reference.py?Optional, but it would stop the two scanners drifting apart: have
check_conventions.pyimport the reader pattern fromenv_reference.pyinstead of keeping its own copy.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T08:12:09Z.
One more suggestion: instead of skipping heads without ENVIRONMENT.md, could the conventions rule check only the env names a PR's own diff adds? Then PRs branched before this one can't land undocumented reads, and a later PR doesn't fail for names it didn't touch.
Imported from boykopovar/AnyPS5. Originally posted by 011010 on 2026-10-18T08:26:33Z.
@oneandonlydean thanks, I applied both points.
Helpers and wide strings (
bb109df67,47710d801):env_reference.pyandcheck_conventions.pynow share one table of reader forms.check_conventionsimportsenv_reference.GREP,line_readsanddocumented_patterninstead of keeping its own copy.configured(...)andPipelineSwitch(...),environmentCount(...),addWideString(u"...")andGetEnvironmentVariableW(L"...").APS5_PIPELINE_JOURNAL_THREADS(PipelineJournal.cpp:1136) uses the sameconfiguredform, andANYPS5_LOADEXEC_ARGV_SKIPis read withGetEnvironmentVariableW(L"...")inlibkernel/System/src/Process.cpp:90. Both have rows now.test_env_reference.pyhas one fixture line per new form, plus a negative case (reconfigured(...)must not match).env_reference.py --checkreports 436 names, all documented.Diff-based rule (
1dcd1ee4a):env-referencenow readsgit diff base head -- core. A name the pull request adds to the code without a row inENVIRONMENT.mdis reported at the file and line where it is read. If the head has noENVIRONMENT.md, the rule reports it instead of skipping.tools/tests/test_check_conventions_env_reference.pycover each case. All 41 scripts undertools/testspass, andcheck_conventions.py --base upstream/mainpasses.One trade-off: with this model, CI no longer catches an undocumented name that reached
mainthrough a path without a row. I suggest running the fullenv_reference.py --checkon a schedule againstmain, so drift shows up even when no pull request touches it. Would that work for you?Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T08:52:17Z.
Thanks, the diff-based rule matches Dean's suggestion and the earlier checks still pass on current main. Two small things: (1) a PR that deletes a row in docs/dev/ENVIRONMENT.md for a name core still reads isn't reported, because the diff only covers
core. Could the rule also diff the document and report removed rows whose names the head still reads? (2) tools/tests/test_check_conventions_env_reference.py needs anadd_testnext toenv_referencein CMakeLists.txt, otherwise CI never runs it. Nit:startswith("+++")/("---")also matches added lines starting with++and removed lines starting with--, which shifts the reported line numbers. Tracking whether you're inside a hunk (after@@) avoids that.Imported from boykopovar/AnyPS5. Originally posted by 011010 on 2026-10-18T10:17:40Z.
@oneandonlydean both done, plus the nit.
Removed rows (
061101a3e):env-referencenow diffsdocs/dev/ENVIRONMENT.mdas well. A row the pull request removes whose name the head still reads is reported on the document, and it stays quiet when the pull request removes the row together with its last read. Tests:test_a_row_the_pull_request_removes_is_reported_while_the_code_still_reads_itandtest_a_removed_row_is_kept_quiet_when_the_code_stops_reading_it_too.Registration (
99e295a7b):add_test(NAME conventions_env_reference ...)sits next toenv_reference, withTIMEOUT 60because it builds temporary repositories. Thanks for catching it.Hunk tracking (
061101a3e): the loop now opens a hunk on@@and only reads+++ b/as a file header outside one, so an added line whose content starts with++no longer skips the counter and a removed line starting with--no longer loses its read. Tests:test_an_added_line_starting_with_plus_does_not_shift_the_reported_lineandtest_a_removed_line_starting_with_minus_still_counts_as_a_removed_read.python3 tools/check_conventions.py --base origin/main --head HEADpasses,python3 tools/env_reference.py --checkreports 436 names all documented,test_check_conventions_env_reference.pyhas 9 tests, and the 41 scripts undertools/testspass.The offer from my previous comment still stands: I can run the full
env_reference.py --checkon a schedule againstmain, so drift no pull request touches still shows up. Say the word and I will add it.