fix(agc): take an indexed draw's base vertex as signed #26036
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26036"
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 birdmarty on 2026-11-23T04:53:47Z.
What
An indexed draw whose base vertex is negative threw
indexed draw vertex range overflow. The base vertex is added to every index, and a negative one is valid as long as the lowest index plus it is not below 0: the hardware's base vertex and Vulkan'svertexOffsetare signed.DrawrequiredfirstVertex <= UINT32_MAX - maxIndex, which reads -532 as 0xfffffdec. The adds after that check (minIndex += firstVertex,maxIndex += firstVertex) already wrap to the right vertices, andvkCmdDrawIndexedalready gets the offset asint32_t.The indexed range check now takes the offset as signed: the lowest index plus the offset must be at least 0, and the highest index plus the offset at most UINT32_MAX. The expanded-index path (quad lists and emulated strips) now tracks its lowest index and checks both bounds the same way. Two places used the offset as unsigned as well, and now take it as signed:
zeroFrom - firstVertex), where a negative offset gave 0;minIndex) instead of the offset.The vertex offset of an indexed draw can also come from two words: GE_INDX_OFFSET and a vertex shader's base-vertex user SGPR, which
Driver::FoldDrawOffsetsadds into the draw. That add used an unsigned overflow test, so +3 and -3, a final offset of 0, threwdraw vertex offset overflow. For an indexed draw the two words are now added as signed 32-bit values, and only a total outside the signed 32-bit range is refused. The in-place index path behind a pending GPU writer (InPlaceIndexBehindWriter, opt-in throughAPS5_INDEX_IN_PLACE_BEHIND_WRITER) compared the offset as unsigned too: a large negative offset with 16-bit indices, such as -2147483648, was bound in place with its lowest index taken as 0, and the range check then refused the draw. A negative offset now stays on the copy path, which measures the real index range.Non-indexed draws are unchanged: their first vertex is an unsigned start.
Changes
core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp: the range checks above and the in-place index path.core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/IndirectDraw.cpp: the signed fold inFoldDrawOffsets.core/libs/prx/libSceAgcDriver/tests/execution/DrawOffsetIndices.cpp(run byagc_driver_draw_offset_indices,_poisonedand_poisoned_in_place): a direct indexed draw with base vertex -3 over the indices 5, 3, 4 fetches vertices 2, 0 and 1 for both instances; GE_INDX_OFFSET +3 with s16 -3, and -3 with +3, over the indices 2, 0, 1 fetch vertices 2, 0 and 1; GE_INDX_OFFSET 0x7fffffff with s16 1, and 0x80000000 with s16 -1, are refused withdraw vertex offset overflow; an indexed quad-list draw with base vertex -3 over the indices 0, 1, 2, 2 is refused withindexed draw vertex range overflow.core/libs/prx/libSceAgcDriver/tests/Recorder.cpp(agc_index_in_place_behind_writer): 16-bit index ranges with the offsets -3 and -2147483648 stay on the copy path; the case that may bind in place now uses 0x7fffffff instead of 0xffff0000, which is -65536 as a signed offset.No debt entry changes: the change closes no recorded gap and adds none.
Tested
Windows 11 Pro (build 26300), Intel Core i9-9900K, AMD Radeon RX 6800 (AMD driver 26.10.1, Windows driver 32.0.21045.16010, Vulkan 1.4.315), MinGW-w64 GCC 15.3.0, Release,
main441fa65119.Focused set (
agc_driver_graphics,agc_shader_memory,agc_driver_recorder,agc_driver_draw*,agc_driver_*vertex*,agc_driver_*index*,agc_driver_list_restart*,agc_driver_zero_stride*,agc_driver_relative*,agc_driver_mesh*,agc_driver_stencil_replay*,agc_embedded_vertex*,agc_driver_indirect*,agc_index_*,agc_driver_pm4*) withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(1.4.363) andVK_LOADER_DEBUG=layer:main441fa65119VUID-linesRebased onto
origin/main0af6efad52as6080bb0b93(resolving conflicts with merged #26775 by preserving!wholeRangeonfirstByteinDraw.cppand the 5-argumentattempt(...)signature intests/Recorder.cpp). Re-verified on the same RX 6800 withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(1.4.363.0),VK_LOADER_DEBUG=layer:agc_driver_draw_offset_indices*,agc_index_in_place_behind_writer,agc_driver_graphics,agc_driver_list_restart*,agc_driver_indirect*,agc_driver_zero_stride*,agc_driver_recorder): 20 / 20 passed on bothorigin/main0af6efad52and6080bb0b93, 34 validation layer inserts on both, 0VUID-lines.origin/main0af6efad52'sDraw.cppandIndirectDraw.cppagainst 6080bb0b93's tests): 4 / 4 failed (agc_driver_draw_offset_indices,_poisoned,_poisoned_in_placewithAGC driver: draw vertex offset overflow, andagc_index_in_place_behind_writeron the -2147483648 case); all 4 pass on6080bb0b93.441fa65119/ 8a0fcdd825 above;tools/check_conventions.py --base origin/mainandtools/debt_fold.py --checkpass on6080bb0b93.Forza Horizon 5 (PPSA22327 01.685.672), local stack of open PRs:
6080bb0b93were not run in the game.py -3 tools/check_conventions.py --base origin/mainandpy -3 tools/debt_fold.py --checkpass.py -3 tools/pr_overlap.py --branch fix/agc-negative-base-vertex(2,508 open PRs): all 83 mergeable PRs that share files merge cleanly. The 45 PRs that conflict withmainwere searched by hand; #9897 and #14032 setdraw.firstVertexin tests, #10193, #13928 and #22647 change where the zero-fetch vertex attributes come from, and #22647 callsFoldDrawOffsets; none takes the base vertex as signed or changes the fold or the in-place index check.Not tested: a negative base vertex through an indirect draw's arguments in a title, the expanded-index path with a negative base vertex in a title, other GPUs, Linux.
Related
Part of the Forza Horizon 5 (PPSA22327) bring-up, #25152. It was found on the stack of PRs the game needed (#24960, #24994, #25151, #25867–#25874, #26034 and #26035 are now merged; #23688, #23545, #21479, #11825, #23778, #21155, #22306 and #21199) and stands alone: it applies to
mainby itself and needs none of them to build or pass its tests.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)mainand this change, 0 VUIDs🤖 Generated with Claude Code
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T04:55:44Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: fix the expanded-index range check so it also rejects a negative resulting vertex index.
What I ran
Reviewed head
d85e9ac04d8aa897d51921aaf790911658a49154. Readdescription.md,commits.md,manifest.json,diff.patch, and the full text of both changed files inreview/manifest.json. No commands or tests were run;repo_read.pywas unavailable in this session.Results
Findings
Blocking
Draw.cpp:1974: The expanded-index path checks onlymaxIdx + firstVertex <= UINT32_MAX. With a signed negative base vertex, this permits a lowest index smaller than the magnitude of the offset. For example, index 2 with offset -3 passes the upper-bound check, then the indexed range check at line 2096 rejects the same invalid draw later. The expanded path must validate the lower bound too, before the subsequent additions and index limit checks.Non-blocking
None.
Not verified
The test file’s full text was included in the changed-file bundle, but the reader returned only the requested out-of-range slice for the test read; the changed test lines are visible in
diff.patch. No test execution, author-reported validation, hardware behavior, or other repository context was independently verified. No files were excluded according tomanifest.json;review/files.jsonwas not available.To get this to a good state
Add the lower-bound validation to the expanded-index path and run the focused draw tests, including a negative offset whose lowest expanded index would become negative.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T05:31:11Z.
Review: APPROVED
Reviewed — looks good
The reviewed change handles signed indexed base vertices and adds regression coverage for valid and invalid ranges; the available evidence supports merging.
What I ran
Reviewed head
4f888baf4a6b016330ecf057da5fc1e7647d07ddusingrepo_read.pyto inspect the prepared diff and relevant code ranges. No commands or tests were run by me.Read:
description.md,commits.md,manifest.json,diff.patch, and all relevant ranges ofDraw.cppandDrawOffsetIndices.cpp. Both files listed in the manifest as reviewed were read.files.jsonwas unavailable through the reader; its exclusions were not verified.Results
files.jsonunavailableFindings
Blocking
None.
Non-blocking
None.
Not verified
I did not run tests or independently verify the author's test, hardware, or game-run reports. Excluded-file details were not available. The review was based on the prepared diff and the two changed files listed in the manifest.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T07:03:58Z.
Review: CHANGES_REQUESTED
Reviewed exact head
4f888baf4a6b016330ecf057da5fc1e7647d07dd. The new range checks correctly interpret the final indexed base vertex as signed, but the producer can still reject a valid signed result before those checks.Driver::FoldDrawOffsetsadds the shader/user-SGPR word toDrawParameters::firstVertexwith an unsigned overflow test. For a direct indexed draw withGE_INDX_OFFSET=+3and a folded shader base-vertex word of-3(0xfffffffd), the correct final signed base vertex is 0. The current check treats the second word as4294967293and throwsdraw vertex offset overflow. The reverse-3 + +3case has the same problem. The two new indexed fixtures both seedfirstVertex=0, so they do not cover composition with the PM4 offset.Please combine the two words in signed/widened arithmetic for indexed draws, check the representable final signed offset, and keep the existing unsigned behavior for non-indexed starts. Add a regression through the existing
FoldedDrawwrapper with nonzerofirstVertex, e.g.+3plus shader-3over{0,1,2}.A local CPU probe using byte-verified copies of the exact
drawUserWord,FoldDrawOffsets, and changed range logic reproduced both mixed-direction rejections and passed 12 boundary/negative controls; the exact changedDraw.cppalso passed a WinLibs compile-only check. Hosted Windows is green but its logged selection did not rundraw_offset_indices; the author and peer GPU runs cover the current fixtures. I did not run a local GPU test.The overlapping index-expansion hunk in #26041 merges cleanly with this head; this finding is in the unchanged producer-side folding code.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T08:35:19Z.
Review: APPROVED
Re-reviewed fix head
8a0fcdd82559dd2a7e238653b46cf61fcb731cef. This resolves both parts of my earlier finding: indexed offset folding now uses a signed wide intermediate with checked narrowing, and every negative final indexed offset is routed away from the in-place writer.Exact-source CPU A/B results:
4f888baf→ 0/196 here, including both+3 + (-3)cancellation directions and signed upper overflow;InPlaceIndexBehindWritergate with unrelated gates controlled: 4/28 → 0/28.All four changed translation units pass WinLibs C++20 syntax checks. The recorder fixture generated its ten exact shaders with the previously built CPU glslang and current embed script, without Vulkan initialization. The new folded-draw tests cover positive/negative cancellation, signed overflow and returned vertex/instance IDs; the recorder cases discriminate the in-place gate.
Scope nuance is accurate:
INT_MINis a gate counterexample for 16-bit indices, not an otherwise renderable 16-bit draw; valid small negative offsets already selected the copy path before this follow-up. The production signed-fold fix remains independently necessary and proven. The author reports 171/171 focused tests on base and head with 223 validation-layer insertions and 0 VUIDs, plus negative controls. I ran no local GPU test. Merge preview with #26041 and current main is clean; hosted Windows is still running with no failures.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T08:36:57Z.
Review: APPROVED
Reviewed — looks good
The indexed draw changes and the added regression cases were reviewed at head
8a0fcdd82559dd2a7e238653b46cf61fcb731cef; no blocking defect was found in the code read.What I ran
No commands or tests were run. I read the prepared review bundle and used the pinned repository reader for the changed test file excluded from the bundle.
Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/tests/Recorder.cppwas not read in full; its changed lines and surrounding function were read from the pinned head. No commands or tests were run. The author-reported test results and game behavior were not independently verified. Other GPUs, Linux, and title behavior for indirect negative offsets and expanded-index draws were not verified.Files read:
review/description.md,review/commits.md,review/manifest.json,review/diff.patch;core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/IndirectDraw.cpp,core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp,core/libs/prx/libSceAgcDriver/tests/Recorder.cpp(targeted range), andcore/libs/prx/libSceAgcDriver/tests/execution/DrawOffsetIndices.cpp(targeted ranges). Excluded from full-text bundle:core/libs/prx/libSceAgcDriver/tests/Recorder.cppbecause it was too large.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T11:00:00Z.
Review: APPROVED
Reviewed — looks good
Nothing in the inspected changes shows a blocking defect, and the tests reported by the author cover the signed offset cases added here.
What I ran
Reviewed head
6080bb0b9372ff9d6eae0f170212093c52b57f80. No commands or tests were run; test results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No test execution was performed. The game runs, other GPUs, Linux, and indirect or expanded-index negative-offset behavior in titles were not verified.
Recorder.cppwas excluded from the prepared review bundle; its changed lines were read through the pinned-head reader, but its surrounding full test context was not reviewed. The other changed files were included and inspected at the relevant changed sections.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T23:04:02Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the review supports merging.
What I ran
Reviewed head
8f5ca2b793c6210e10e065bae0fccc4d504938b2. I did not run commands or tests. I read the prepared description, commits, manifest, and diff, plus the relevant changed functions and test additions at the pinned head.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I read the full text for
IndirectDraw.cpp,Draw.cpp, andDrawOffsetIndices.cpp, and the changedRecorder.cpplines through the pinned reader. All four changed files markedreviewedin the manifest were read;Recorder.cppwas excluded from the review folder because of its size, so I read only its changed region. I did not run the reported test suites or inspect unrelated file contents. Console behavior, other GPUs, Linux, and the title scenarios identified by the author as untested remain unverified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T06:03:46Z.
Review: APPROVED
I read the diff at
8f5ca2b793. Windows 11, GCC 15.2, merged intomainatcf556db18c3together with other open PRs (so not an isolated build), withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1andVK_LAYER_KHRONOS_validationon an RTX 5080 (621.24) and a Radeon iGPU (26.11.2).agc_driver_draw_offset_indices_testsandagc_driver_recorder_tests(2 of them skip on the Radeon): pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has aVUID-orSYNC-HAZARDline.main's):agc_driver_draw_offset_indices, its two poisoned variants andagc_index_in_place_behind_writerfail on both GPUs: "draw vertex offset overflow", and a 16-bit index range "whose vertex offset of -2147483648 takes every index below vertex 0". The others pass.Not checked: a title.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T21:29:16Z.
Review: COMMENTED
The signed widening covers both the offset fold and post-index range checks. The new fixture covers opposite-sign register offsets, both signed fold limits, a lowest effective vertex of zero and a quad that crosses below zero. Please add a successful expanded quad with a negative base and all raw indices above zero. That would exercise carrying the expanded minimum through to the vertex upload and alias calculation, beyond the expanded path's rejection case. The paired draw-offset and behind-writer tests are queued on Linux lavapipe.
AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.