fix(shader): align raw vector buffer dword accesses to the V# base #16415
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16415"
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 akkadbakkad89 on 2026-11-06T16:34:58Z.
What
A V# whose base is not DWORD-aligned previously produced exact-byte accesses for raw
buffer_load/store_dword[xN](the gfx1035 UNALIGNED-mode model):SpirvRuntimeBufferfed the base's low two bits intobaseMisalignmentand shift-merged the read across two dwords, and BDA paths added the unmasked base.On the console (
SH_MEM_CONFIG.alignment_mode= DWORD) the two low bits are dropped: a PS5 (13.40, gfx1013, measured 2026-10-19)buffer_load_dwordwith the V# base 1 byte past a dword, or an aligned base andvoffset1, returned the aligned dword (0x44332211, not 0x55443322). This change addsAlignsRawDwordAddress(ResourceKind::Buffer&& !formatted && dataBits == 32 && non-atomic) and applies it inbyteAddress(masks the computed guest byte offset),address(masks the V# base on the BDA path), andreadBuffer/writeBuffer(skip the misalignment shift-merge), so raw dword accesses use the aligned-down dword.Out of scope, still as before: scalar buffers (already aligned), buffer atomics (byte-addressed, measured on gfx1031), formatted/typed accesses (element alignment enforced at decode), and byte/short accesses (exact bytes, console behavior unmeasured — kept in the debt file).
Tested
Windows 11,
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(confirmed loaded, noVUID-errors),cteston an NVIDIA GeForce RTX 3070:agc_driver_buffer_unaligned_base— updated the raw dword/dwordx2 load expectations and the store model to the aligned-down view (stores below the view base stay clipped by the copy-back window; later byte/short stores overwrite overlaps). Passes at base misalignments 1, 2 and 3 for loads, stores,dwordx2GLC, scalar, atomic, formatted and fault cases.agc_driver_buffer_descriptor_runtime— thebase +1/+2/+3andrecords 64 base +2cases now expect the aligned-down view; the scalar sections were already aligned and are unchanged. Passes for specialized and registration modules, plain and coherent.agc_driver_buffer_load_store,_draw_pipeline,agc_driver_buffer_atomics,_float,_inc_dec64,_or_swap64,agc_driver_buffer_atomic_csub,agc_driver_buffer_atomic_unaligned,agc_driver_buffer_integer_atomics,agc_driver_buffer_format,agc_driver_masked_global_store,agc_driver_scalar_wide_loads,agc_driver_sparse_buffer_holes,agc_driver_many_buffers,agc_driver_scalar_buffer_runtime_word3,agc_driver_formatted_store_unaligned,agc_driver_null_buffer_substitutes,agc_driver_pattern_buffer_fill,agc_driver_pooled_buffer_range— all pass.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)Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-06T16:44:30Z.
Review: COMMENTED
Read through the change against
SpirvRuntimeBuffer.cpponmain. Two points, neither about the measured cases, which the new expectations match.byteAddressmasks the offset (byte & ~3), and the base's low bits are dropped either by forcingmisalignmentto 0 or, on the BDA path, byresource.base & ~3. So the dword read is(base & ~3) + (offset & ~3). Section 8.1.7 of the RDNA2 ISA, which the unaligned-atomics entry next to this one cites for mode DWORD, aligns the final address: that entry's PS5 measurement has the atomic at byte 0x0D act on the dword that holds it, 0x0C. If loads and stores follow the same rule, the dword is(base + offset) & ~3. The two only differ when(base & 3) + (offset & 3) >= 4. For example, a base 3 bytes past a dword withvoffset1 gives the next dword by the final-address rule and the current one here. The two PS5 cases (base +1 / offset 0, and an aligned base /voffset1) can't tell them apart, so a base +3 /voffset1 run on the console would settle it. Until then the debt entry could say which of the two this models.BufferUnalignedBaseexpects those leading bytes to keep their old value (clipped by the copy-back window), while mode DWORD would write the whole dword. That's a reasonable limit, but the debt entry doesn't mention it yet; one sentence there would keep the entry and the test in step.No build or run from me yet.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T21:26:53Z.
Review: COMMENTED
Reviewed — comments
The changed code implements separate alignment of the buffer base and byte offset, while the review materials say console measurements do not distinguish that behavior from aligning their sum.
What I ran
Reviewed head
991eef4ef25bacc1fe6ce37d01b98181ecdda7a3. I read the prepared description, commits, manifest, diff, and targeted ranges from each of the six changed files. I did not run commands or tests.Results
Findings
Blocking
None.
Non-blocking
SpirvRuntimeBuffer.cpp:225aligns the computed byte offset, andSpirvRuntimeBuffer.cpp:242separately aligns the BDA base. As the updated debt entry describes, these produce a different address from aligning the final sum when both the base and offset have nonzero low bits. The cited console measurements cover each being misaligned separately, but do not resolve the combined case. Please keep this behavior marked as an unverified interpretation until a console measurement or other authoritative evidence establishes which rule applies.Not verified
The tests described in the PR description were not run here. Only targeted ranges were read; the remainder of the six changed files was not inspected.
files.jsoncould not be read from the review folder, so any exclusions it records are not verified. Console behavior for the combined misalignment case is not verified.Files read:
description.md,commits.md,manifest.json,diff.patch; targeted ranges inGuardedMemoryLoads.cpp,ShaderDiskCache.cpp,BufferDescriptorRuntime.cpp,BufferUnalignedBase.cpp,SpirvRuntimeBuffer.cpp, andshader.md. No changed files were excluded by the manifest.To get this to a good state
Nothing is required. Optional: add a console measurement for a base and offset that are both misaligned, then update the implementation and debt note to match the measured behavior.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T16:47:58Z.
Review: COMMENTED
On Linux/lavapipe,
agc_driver_buffer_unaligned_basepassed on main atba0ff896612band failed with this head integrated. In the firstview +2, stores +1run, byte 64 is0x08and the fixture expects0xbe. The two buffer-descriptor and scalar controls passed on both sides. All six Vulkan invocations loaded Khronos validation 1.4.369 with Vulkan required and shader caching disabled. The logs show no missing-layer warnings or VUIDs.The expected-byte loop prioritizes the upper byte of lane 7's unaligned short store at byte 64. After dword alignment, lane 8's dword store also covers byte 64 and can write
0x08there. These are different lanes. Please give the raw dword and subword stores non-overlapping destinations so the fixture can check each addressing rule independently.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.