perf(agc): bound instance-indexed guest buffers by the draw's instance range #14032
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14032"
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 ntamas94 on 2026-10-31T16:40:32Z.
What
The follow-up #9897's review asked for (the instance-stream data point and savvaniss's reply). Stacked on #9897: this branch is
mainwith #9897 merged plus two commits.#9897 cuts a read-only V# that an
IDXENload indexes by the vertex index to the draw's last vertex. A load indexed by the instance index kept the whole V#:vertexIndexedExtentaccepted only theVertexIndexbuiltin, so such an element hadbufferVertexExtent0.vertexIndexedExtentaccepts theInstanceIndexbuiltin under the same conditions (anIDXENread with an immediate offset andSOFFSET) and marks the extent as indexed by the instance:BufferResource::vertexExtentByInstance,DescriptorBinding::bufferVertexByInstance. A V# read by both indices keeps no extent.VertexReach: the last vertex, as before, andShaderResources::LastInstance,firstInstance + instanceCount - 1computed in 64 bits.VertexBoundBytespicks the bound the element is indexed by. An unknown bound (indirect, mesh, tessellation, no instances, or a last instance that does not fit in 32 bits) leaves the element whole, as before.BufferResource13 to 14 fields) and the flag list; its format version is 65.Crysis Remastered (CUSA18659, PS4 GCN) binds its instance streams as V#s over whole heaps: stride 64, 80 and 96, 524,288 records, 40 to 50 MiB each, read by the instance id in the linked fetch subroutine (the data points in #9897's thread). On this branch they are bound to the draw's instances. Two captures of the same scripted scene (level "Contact", no camera movement),
APS5_TRACE_SECONDS=310:30,APS5_PROFILE_DRAW=1, same machine; onlylibSceAgcDriver.prxdiffers (the recompiler is linked into it). Both runs setAPS5_ALLOW_READ_TARGET_ALIAS=1, a local allowance the base needs to reach the level (without it the base stops atshader buffer aliases the render target; on this branch the allowance is a no-op, see below).aps5-summary.jsonlfiles: base, branch):tools/performance_compare.py(the captures are windows, sotrace_digest.pyhas no interval rows to print):Graphics.DrawShader.DrawStageThe storage write-backs the heap-wide read-only V#s forced ("imported buffer region": a bound range over a pending G-buffer image is written back to guest memory before the draw) go from 429 per 10 s (4,428 MiB) to none, and the draw resource cache's misses from 63,819 to 7,847 per 10 s (the moved buffers are now small enough for the moved-snapshot path); the last 10 s report of each run.
The read-only heap-wide V#s no longer reach the
shader buffer aliases the render targetcheck: a 450 s scripted run into the level without the allowance reports 0 such lines on this branch, where the base stops at that check at 257 s.Tested
Windows 11 Pro 10.0.26200, WinLibs GCC, Release with
BUILD_TESTING=ON, NVIDIA GeForce RTX 2080 (driver 617.14),ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,APS5_NO_PIPELINE_JOURNAL=1.Trees.
main474030e584with #9897 (04db012394, its current head) merged is the base,d0c72a155b; this branch is that merge plus the two commits. Both trees were built and run on the same machine.Focused set,
ctest -R "shader_disk_cache|agc_driver_graphics$|vertex_indexed_ring|agc_shader_vertex_index_extents|agc_shader_memory|agc_driver_(draw|moved|template|resource)": 51 of 51 pass on both trees. WithVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=warn,error,ctest -V: 51 of 51 on both, the loader'sadding layers "VK_LAYER_KHRONOS_validation"line 124 times in each log, nowas not found but was requested by env var VK_INSTANCE_LAYERS,VUID-lines: 0 on the base, 0 on this branch (base log, branch log).agc_shader_vertex_index_extents: two new cases, an instance-indexedbuffer_load_format_xyzw(extent 16, marked by instance) and a V# read by both the vertex and the instance index (no extent).agc_driver_graphics:VertexBoundBytescuts an instance-indexed element to the draw's last instance, binds the first instance alone, leaves the element whole without an instance bound, and does not cut a vertex-indexed element by the instance bound;LastInstancegives 4 for 3 instances from instance 2, 0 for one instance, none for no instances or forfirstInstance2 withinstanceCount0xffffffff (the element then stays whole), and 0xfffffffe for 0xffffffff instances from instance 0.agc_driver_vertex_indexed_ring: two instanced draws (3 instances from instance 2, and from instance 0) whose shader stores each fetched record atinstance * 16into an output V#, compared with the ring records of the instances drawn; and an instance-indexed ring drawn up to the render target, 3 instances from instance 0 and 3 from instance 2, the bound ending 0 and 8 bytes before the target, the fetched records compared with the bytes behind the V#. Bounding the ring byinstanceCount - 1instead (ignoringfirstInstance) fails the first instanced case: instance 3 reads zeros.agc_driver_shader_disk_cache: round trip of the newBufferResourcefield and thebufferVertexByInstanceflags.Crysis Remastered (CUSA18659, PS4 GCN): the two captures above. The runs come from a local branch that boots the title (the PS4 stand-ins it needs are not in
main): baseaed8519708, branch that plus the two commits of this PR, both built from clean trees (dirty: falsein the summaries). The earlier 10 s interval runs that found the issue agree (p50 120.6 → 89.9 ms).Merges of
main.0f302813ce(head1b167481dc): no conflicts.613f9b8edf(headfe14465c3b): #12862 moved the test registrations intotests/cmake/*.cmake, so #9897's three registrations (agc_shader_vertex_index_extents, its entry in the Windows PATH list,agc_driver_vertex_range_bindings) moved intoagc_shader_memory_tests.cmakeandagc_driver_graphics_tests.cmake;ctest -Nlists all three andagc_driver_vertex_indexed_ring. The focused set and the validation-layer run above were repeated on each merge head: 51 of 51 on the first, 52 of 52 on the second (the set now namesagc_driver_vertex_range_bindingstoo),VUID-lines 0, the layer line present.tools/check_conventions.py --base origin/mainwith this title and description: no findings.Refresh — 2026-11-03 (Codex, AI-assisted): Merged main
086c0686c8. Retained both instance-extent and current-main shader tests, merged the Windows test PATH list, and reconciled cache layout guards (BufferResource fields 14 / size 40, DescriptorBinding size 720; main's ImageResource fields 50 / size 108). Preserved main's atomic-shared-pointer guard and the PR cache format 65. MinGW-w64 GCC 15.2 syntax-only compilation passes for ShaderDiskCache.cpp, ShaderMemory.cpp and ShaderResources.cpp using the current checkout's headers. Conventions and whitespace checks pass. No new full runtime/GPU tests or performance captures; the earlier capture evidence remains historical.Checklist
main; no other open PR implements the same functions (searched open and closed boykopovar/AnyPS5 PRs for "instance-indexed", "instance extent", "bufferVertexExtent" and "fetch shader vertex range" on 2026-10-31; #9897 is the base, #9875 bounds the copy's lower end and does not touch the extent)NotImplemented_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-31T16:44:41Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The implementation and focused tests are reviewable, but the
perfclaim does not yet have attributable, comparable capture evidence required by the repository.What I ran
Reviewed head
03ed726f5fc9ad8fa05167f8db9785bbdf788ceaagainst base474030e58424fefdb65e5df9f3820810fbb4553c; the declared dependency #9897 is included in the head, and the individual merge previews against the base are clean. I inspected the changed resource-tracking, draw-bound, cache, serialization, and test code; no-build precheck ran on Linux with Python 3.11.2 and Git 2.39.5. I did not build or compile AnyPS5.Results
474030e58424are clean.Precheck output
Release asset listing
Findings
Blocking
The
perfreport is not yet reproducible or comparable under the repository’s performance-report requirements and capture form:dirty: trueandcommit: aed851970874, rather than identifying the stated baseline and change. The baseline record also setsAPS5_ALLOW_READ_TARGET_ALIAS=1andAPS5_NO_INPLACE_MOVES=1, while the branch record sets neither; these are not matched capture settings.aps5-trace-*.json.gzcaptures. The selected summary records have an emptytracefield, and notrace_digest.pyoutput is included.Please provide the exact two summary records and trace files for the stated baseline and head, with attributable source revisions and matched scene/settings, plus the output of
python3 tools/trace_digest.py <trace>for each trace. If the dirty/same-commit metadata is expected for these local builds, explain it and provide enough capture provenance to verify which source tree each binary used. I’ll recheck the report and exact head after it is updated.Sources
Not verified
I did not compile or run the C++ tests locally, inspect a raw performance trace, or independently reproduce the author’s Windows/NVIDIA measurements. Several hosted build jobs were still running at the captured check snapshot; Linux and specialized jobs were skipped.
To get this to a good state
Add attributable, settings-matched baseline and change summary records, attach both raw traces, and include the digest output for each. I’ll rerun the relevant report and head checks on the updated revision.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T08:47:34Z.
Review: COMMENTED
Reviewed — no blocking findings
The review materials and changed source files were not available through the reader, so the change could not be assessed.
What I ran
No repository or test commands were run. The pinned head and change contents were not inspected.
Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
The PR description, commits, diff, manifest, changed files, and test coverage were not read. Files read: none. Files reviewed: none.
To get this to a good state
Provide access to the review reader and prepared review folder so the change can be assessed.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:49:57Z.
Review: COMMENTED
The trial merge onto
c1601e56d5conflicts in draw bounds, resource tracking, and the shader-cache schema. Please keep a nonzero first-instance case and a binding used by both vertex and instance indexing. The first verifies the extent’s origin and the second must fall back when the proof cannot describe both streams. Reconcile the serialized binding fields before comparing graphics and shader-memory results.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.