fix(agc): fetch zero-stride vertex buffers shorter than their element #1426
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1426"
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 gjonn on 2026-10-08T04:33:07Z.
What
A vertex attribute whose buffer descriptor has stride 0 and
NUM_RECORDSsmaller than one element made the draw throw ("vertex fetch exceeds descriptor byte range"). Titles bind such placeholders, for example a one-byte descriptor read as a 32_32_32_32 float attribute.With stride 0 every vertex fetches the same element. What the fetch returns depends on the descriptor's
OOB_SELECTfield (word 3 bits 29:28):OOB_SELECT2 (disabled): the only range check isNUM_RECORDS == 0, so the whole element is read (zeros when the buffer is empty).NUM_RECORDSreads as zero.The field values and checks follow Mesa (
src/amd/registers/gfx10-rsrc.json, theac_set_buf_desc_word3comment insrc/amd/common/ac_descriptors.c). The per-dword zero rule for range-checked buffers has no exact source and was not measured on hardware. It is listed under "Unknown function info" in TechnicalDebt with the Mesa comments that come closest.ShortRawVertexBufferBytes(VertexInput.hpp) tells whether an attribute is such a buffer, and returns how many of its bytes are read: the whole element forOOB_SELECT2, otherwise the whole in-range dwords.Drawgives such an attribute its own buffer at offset 0 instead of adding it to the guest copy plan. The bytes it reads go throughCopyDrawInput(pending GPU writes flushed, writes collected, snapshot reused) and the render-target alias check, as planned vertex copies do. A buffer that is read whole is bound directly. Otherwise the bytes are placed in a zero-filled one-element buffer. This also applies to indirect draws, which would otherwise copy the descriptor's whole (too short) range.VertexBufferReadSizestill refuses a short zero-stride buffer if it is ever asked.Tested
main.ctest -R "^agc_driver_(graphics|short_vertex_buffer|vertex_fetch|scalar_swappc_fetch|mesh)$" -j1gives 5/5 passed.agc_driver_short_vertex_buffer(tests/execution/ShortVertexBuffer.cpp): a fetch-shader vertex program stores both of its attributes to a buffer. One is a stride-0 32_32_32_32 float attribute shorter than its element, bound first. The other is a strided position. Each draw checks both values per vertex, so a wrong buffer, offset orfetchOfindex fails:OOB_SELECT2: 1 record gives the whole element; 0 records give zerosOOB_SELECT2 cases as indirect drawsOOB_SELECT2 case, the zero fill, or the alias check each fail it. Indexing the plan by attribute instead offetchOfloses the device.agc_driver_graphicsalso checksShortRawVertexBufferBytesfor a 16-byte attribute with stride 0: 16 records is not short, 8 keep 8 bytes, 1 keeps none, and withOOB_SELECT2, 1 record keeps 16 and 0 keep none.gl_Layerfrom the w component of a 32_32_32_32 float attribute read from a stride-0 buffer withNUM_RECORDS1 andOOB_SELECT2. With a zero fill every primitive went to face 0, faces 1-5 stayed empty, and the reflection probe filtered from that cube was black. Before this PR, the same title skipped about 31 000 draws in 120 s on these descriptors.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T13:28:34Z.
Review: CHANGES_REQUESTED
Thanks, the idea (a zero-stride descriptor is a raw buffer, out-of-range dwords read as zero) is reasonable. Needs a few changes:
Draw.cpp:885-891,906-913: the new path inprepareDrawInputshas no test.agc_driver_graphicsonly pinsShortRawVertexBufferBytes; breaking the buffer/offset/handle wiring leaves it green. Please add a Linux test that draws with a short zero-stride attribute and checks the fetched values (in-range dwords, then zeros), including an indirect draw and a mix with a normal attribute (checksfetchOf).Draw.cpp:888: the regular copy callsGuestMemory::FlushGpuWrites/CollectWritesbeforeRead(Draw.cpp:735-741); this path reads guest memory without flushing pending GPU writes. Same for the render-target alias check atDraw.cpp:894, skipped here.VertexInput.hpp:136-141: say where "dword-granular, partial dword reads as zero" comes from (measured on HW or a cited source) and add a TechnicalDebt line under "Unknown function info" for it.Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T17:49:38Z.
Linux results, since this was tested on Windows only. Everything passes here, including
agc_driver_graphicswith the new zero-stride checks.Nobara 44 (Linux 7.2), GCC 16.2.1, Release,
BUILD_TESTING=ON. This PR merged ontomain29e533ac.main29e533acmain+ this PRctest -R agc_driver -j1-E agc_driver)The one CPU failure is
guest_dynamic_loader(subprocess aborted), and it fails the same way onmain.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T23:29:01Z.
Review: CHANGES_REQUESTED
Thanks for the test and the
CopyDrawInputwiring, those address the previous review. I measured the stride-0 fetch on real RDNA2 hardware (gfx1035) withbuffer_load_format_xyzwandtbuffer_load_format_xyzw ... idxen, using the same word 3 as the test (0x0104dfac | OOB_SELECT << 28, 32_32_32_32_FLOAT),NUM_RECORDS0..32 and indices 0..2. Both instructions give the same results:OOB_SELECToffset >= stridecheck always fails)NUM_RECORDS, otherwise zero (vertex 1 with 1 record reads zero)NUM_RECORDSis 0 (matches this PR)NUM_RECORDS>= 16, zero for 1..15. No partial dwordsSo:
VertexInput.hpp:144:records & ~3doesn't match the hardware for any value. With 3, and with 0, a short buffer reads all zeros. With 1 the result depends on the vertex index, so a single one-element buffer can't model it. That case should throw unless it's modelled per vertex.ShortVertexBuffer.cpp:161-162,166: the range-checked cases with 8 and 6 records expect{1, 2, 0, 0}and{1, 0, 0, 0}. The hardware returns{0, 0, 0, 0}. Please pin the measured values and add anOOB_SELECT0 case and anOOB_SELECT1 case (expecting a throw, or per-vertex values).TechnicalDebt.md:113: please update it once the rule follows these measurements. What isn't measured is the PS5's gfx1013, as opposed to gfx1035, and formats other than 32_32_32_32.Draw.cpp,tests/Graphics.cppandTechnicalDebt.md), and itsOOB_SELECT2 rule is the same. Please agree with @TideOPL on which PR carries the fix so only one of them lands.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T08:03:27Z.
Closing: #1769 (merged) reads the whole element for a stride-0
OOB_SELECT2 V#, which is the PPSA01317 case here. The other modes still throw on main; a PR that follows the 10-09 hardware measurements for them is welcome.Pull request closed