fix(shader): address buffers with ADD_TID in graphics stages #24781
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24781"
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 Jirka135 on 2026-11-21T02:32:48Z.
What
A V# with ADD_TID_ENABLE in a vertex, local, pixel, mesh or domain program threw at materialization (
buffer ADD_TID is only valid for compute shaders) and, read from GPU memory, faulted as an invalid descriptor. The Witcher 3 stops on it in a vertex shader (#20342,shader 0x208017400 stage 1).This applies the rule #21970 measured on RDNA2 (gfx1036, hardware oracle) for compute to every stage but hull: without IDXEN the index is the lane, with IDXEN ADD_TID is ignored, and the swizzle applies with IDXEN or with ADD_TID. The lane is the one the recompiler already gives
v_mbcnt(LaneId) in that stage, the subgroup invocation id. The ADD_TID lane is requested only for non-IDXEN buffer accesses (the only case where the lane reaches the address), so a graphics program whose buffer accesses all use IDXEN no longer declaresSubgroupLocalInvocationId. A pixel program with a non-IDXEN buffer access needs fragment-stage basic subgroups and has no fallback; vertex, local and non-mesh domain programs fall back to one lane on hosts without subgroups in that stage (recorded indocs/dev/debt/changes/fix-shader-add-tid-graphics.md). Compute programs behave as before. Hull programs keep throwing (their lane isInvocationId). The behaviour outside compute is not measured on gfx1036 or gfx1013 and is recorded indocs/dev/debt/shader.md.Built on #21970's addressing code (merged into this branch).
New execution test
agc_driver_vertex_buffer_add_tid: a guest vertex shader (96 vertices, wave32 and wave64, swizzled and linear V#s, OFFEN and immediate offsets, stride 16/32, INDEX_STRIDE 0-3) loads and stores through ADD_TID V#s and writes itsv_mbcntlane; the test checks each access against the measured address of that lane and that no other bytes change. ThealiasedBufferViewTestsstores are non-IDXEN, so the graphics fixture now lists fragment-stage basic subgroups.Tested
Rebased onto
main8ab98849d5(head809d521e5b; only conflict was the shader disk cache version, kept at 97 above main's 96). Windows 11 Enterprise 10.0.26300, WinLibs GCC 15.2.0 UCRT, Ninja, Release, Khronos validation layer 1.4.369, same machine for both sides, on the NVIDIA GeForce RTX 5090 (driver 617.42) and the AMD Radeon iGPU (ANYPS5_GPU=AMD,1002:13c0), 3 fresh ctest runs with the layer and 1 without, per GPU:ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest --test-dir build -R '^agc_driver_(vertex_buffer_add_tid|buffer_swizzled_address|runtime_buffer_spans.*|buffer_load_store|buffer_format|buffer_descriptor_runtime|draw_unsupported_buffer_type.*|vertex_elected_atomic_max|vertex_fetch.*|draw_recipe_buffers|buffer_unaligned_base|scalar_buffer_runtime_word3|pixel_lds_lane_slots|many_buffers|null_buffer_substitutes)$|^(spanned_uniformity|ir_opcode_traits|shader_memory_decoder_tolerance)$' -Vwas not foundVUID-The four rows above were at
809d521e5band did not includeagc_driver_graphics. Fix3f0983f9cdon top of it, merged into17220db6a3, AMD Radeon 8060S (gfx1151), driver 25.20.32.06, Windows 11, Khronos validation 1.4.363:agc_driver_graphicspasses on main, fails on809d521e5b(subgroup capability 61 is unsupported for shader stage 16) and passes on the fix; wholeagc_driverset (ctest -R agc_driver): main 1502 passed, 28 skipped, 4 failed; fix 1505 passed, 28 skipped, 3 failed (linear_target_import_creation,store_over_untracked,frame_replay_relaunchfail on both;native_multisample_depthcrashed on main only); no VUID.vertex_buffer_add_tidandbuffer_swizzled_addressdo not exist on main; before the rebase,mainwith only the new test added failedvertex_buffer_add_tid3/3 (buffer ADD_TID is only valid for compute shaders).vertex_elected_atomic_maxskips on both GPUs and both sides (the device runs vertex programs in subgroups). No newVUID-errors.check_conventions.py --base upstream/mainpasses;debt_fold.py --checkreports only thefeat-libwebrtc-rnn-vad.mderror that main also has.pr_overlap.py --branchreports no conflicting files; among the open PRs it could not compare (they conflict with main) is #7689, which rewrites the same throw line inResourceMaterializer.cpp(a one-line textual conflict). Not tested: the title itself, lavapipe.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)1002:13c0), driver 32.0.21045.29003, Windows 11; AMD Radeon 8060S (gfx1151), driver 25.20.32.06, Windows 11🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T02:49:41Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the remaining concerns are optional follow-up work.
What I ran
Reviewed head
c9c66ae38172f2f561984c8dc49d72170de2effdusing the prepared diff and pinned repository reader. No build or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
core/shader/recompiler/SpirvRuntimeBuffer.cpp:183enables subgroup-local invocation ID requirements for every non-hull stage with buffer accesses. The PR documents that graphics-stage ADD_TID behavior has not been measured on the hardware oracle. Consider adding oracle measurements for the other affected graphics stages and GPUs before treating this behavior as established.Not verified
The build, tests, convention checks, debt check, and behavior on physical consoles or other GPUs were not run or independently confirmed. The author reports Windows 11 / RTX 5090 test results in the PR description. All nine changed files listed as reviewed in the manifest were read; no changed files were excluded.
To get this to a good state
Nothing is required. Optional: measure ADD_TID behavior in the affected graphics stages with the hardware oracle.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T08:57:26Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks merging; the behavior is supported by the inspected code and the author-reported execution results, with graphics-stage ADD_TID hardware behavior explicitly recorded as unmeasured.
What I ran
ec03bc54fd96d9376a102b3814a534e3cbda156d; no commands or tests were run by me.description.md,commits.md,manifest.json, anddiff.patch. Read all changed files marked included in the manifest:BufferSwizzledAddress.cpp,RuntimeBufferSpans.cpp,VertexBufferAddTid.cpp,ResourceMaterializer.cpp,ShaderDiskCache.hpp,SpirvAnalysis.cpp,SpirvRuntimeBuffer.cpp, and both changed debt files.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
files.jsonwas not available through the review reader, so excluded-file reasons could not be checked. The manifest lists all eight changed files as included; each was read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T13:35:16Z.
Review: COMMENTED
Reviewed — comments
The shared runtime-buffer changes have a plausible vector-addressing defect; graphics-stage ADD_TID behavior is also unmeasured on hardware, so approval is not justified from the available evidence.
What I ran
Reviewed head
809d521e5b4264840be92bfdd9c76188187e9e49. Read the prepared description, commits, manifest, diff, and all nine changed files listed in the manifest. Read targeted runtime-buffer callers and subgroup lane helpers throughrepo_read.py. No tests were run; the reported Windows/GPU runs are author-supplied.Results
Findings
Blocking
None verified.
Non-blocking
SpirvRuntimeBuffer.cpp:236enables contiguous vector component addressing whenevermemory.idxenis set.byteAddressthen adds later components as a physicaltailafter swizzling (:211,217-222). However, thememory.idxencondition does not require a buffer resource; address calculation is also used for formatted and other buffer-like accesses. For a swizzled vector access in a path whose component layout is not physically contiguous, this can bypass the per-component swizzle calculation and produce wrong addresses. Please confirm the intended scope ofvectorand constrain contiguous addressing to the access types whose hardware layout is contiguous. The new execution coverage checks raw vector buffer loads/stores, but does not cover the formatted paths that calladdresswithout the new vector flag.SpirvRuntimeBuffer.cpp:183-186.)Not verified
Did not run tests, builds, or GPU/hardware measurements. The prepared
files.jsonexclusion list was unavailable through the reader; the manifest shows all nine changed files as included, and those nine files were read. Did not read unrelated repository files beyond targeted callers and helpers.To get this to a good state
Nothing is required. Optional: narrow the contiguous-vector condition after confirming the intended access scope, and add coverage for any formatted vector cases it should support. Keep the graphics-stage hardware limitation explicit.
Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-23T11:36:41Z.
Review: COMMENTED
Windows check of head
809d521e5bwith GCC 16 on an NVIDIA and an AMD GPU, merged ontomainf5b7e1d1ac(clean merge). The PR's own tests pass, butagc_driver_graphicsfails with it, and it passes onmain.Setup: Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (
x86_64-ucrt-posix-seh, r3), Release full build, run from PowerShell withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. GPUs, each picked withANYPS5_GPU: NVIDIA GeForce RTX 5070 Ti (621.01) and the Ryzen 7 7700X's integrated AMD Radeon (1002:164e, Adrenalin 26.10.2).^(.*add_tid.*|.*swizzled.*|.*runtime_buffer_spans.*|agc_driver_buffer_descriptor_runtime)$:main10 of 10, and with this PR 12 of 12 in 2 of 2 runs, on both GPUs (built together with #25557, #26098 and #22251). NoVUID-lines.materializeTablesrefusing ADD_TID outside compute again,agc_driver_vertex_buffer_add_tidfails withbuffer ADD_TID is only valid for compute shaders.agc_driver_graphicsfails. I first saw it in the combined build, then builtmainplus this PR alone (af98298694). It fails there too, and passes onmain:Capability 61 is
GroupNonUniform, and stage 16 is the fragment stage. The cause looks like theSpirvAnalysis.cppchange:subgroupLocalInvocationIdis now required by every non-hull stage that reads a runtime buffer, not just compute. So a fragment (or vertex) program with any runtime buffer access declares the subgroup capability, even without ADD_TID.ValidateShadersrefuses that capability for a stage the device's subgroup properties don't list, and severalGraphics.cppcases pass properties with only one stage or none. I haven't pinned down which case trips, so treat the cause as my reading, not a trace. If that's it, requiring the lane id only where ADD_TID can be set would avoid it. A real device without fragment-stage subgroup support would get the same refusal.This is in addition to MarcZX10's open point on contiguous
idxenvector addressing, which I haven't checked.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T00:18:25Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the optional points below are for follow-up validation.
What I ran
Reviewed head
3f0983f9cd46d84632eff85acca283d6bad57cfausing the prepared diff and pinned source reader. No tests were run; the test results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
ResourceMaterializer.cpp:1843).Not verified
No tests, build, or hardware runs were performed. The full
Graphics.cpptext was excluded from the prepared bundle; its changed lines were read through the pinned source reader. All nine changed files listed as reviewed in the manifest were inspected, including the changed lines ofGraphics.cpp.To get this to a good state
Nothing is required. Optional: measure ADD_TID behavior on RDNA2 or PS5 for the graphics stages recorded in the debt note.
Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-25T12:35:28Z.
Review: APPROVED
Re-check on Windows of head
3f0983f9cd, after my comment aboutagc_driver_graphics.Setup: Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (
x86_64-ucrt-posix-seh, r3), Release full build, run from PowerShell withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. GPUs, each picked withANYPS5_GPU: NVIDIA GeForce RTX 5070 Ti (621.01) and the Ryzen 7 7700X's integrated AMD Radeon (1002:164e, Adrenalin 26.10.2). Merged ontomainc3aae2e8fb(clean merge), built together with #21948 and #24906, which touch other files.^(.*add_tid.*|.*swizzled.*|.*runtime_buffer_spans.*|agc_driver_buffer_descriptor_runtime|agc_driver_graphics)$:main11 of 11, and with this PR 13 of 13 in 2 of 2 runs, on both GPUs, includingagc_driver_graphics, which failed on809d521e5b. NoVUID-lines.SpirvAnalysisback to809d521e5b's rule (every non-hull stage with a runtime buffer asks for the lane), all 13 still pass. That's expected after the fixture change:aliasedBufferViewTestsnow gives the device fragment subgroups, so the case passes under either rule. Nothing pins the narrowing itself. A non-blocking suggestion: one case with an IDXEN-only pixel program and no fragment-stage subgroups would fail on the old rule and pass on this one.The change:
SpirvAnalysisnow asks for the subgroup lane id outside compute only for a non-IDXENBufferaccess in a non-hull stage, andSpirvRuntimeBufferemits the lane only inside the!memory.idxenbranch, so the two agree. The other site that sets it,LaneId(SpirvAnalysis.cpp:557), is unchanged frommain. The fixture change inaliasedBufferViewTestsgives the device fragment-stage basic subgroups, which a pixel shader with a non-IDXEN access does need. The debt entry now says so, with no fallback for pixel programs.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Jazeupoi on 2026-11-28T22:21:55Z.
Review: COMMENTED
Tested
3f0983f9cdmerged into main4814cae855on Windows 11 with an RTX 2060, Vulkan validation on.Content: PSFlyCast (PPSA99247, the Dreamcast emulator homebrew) running Artemio Urbina's 240p Test Suite 1.25 for Dreamcast (free download from the project's SourceForge page), so anyone can reproduce it.
shader 0x200346000 stage 5: buffer ADD_TID is only valid for compute shadersThe log prints
Wave32 programs run on subgroups of 32: compute 1, mesh 1, pixel 0on this GPU, so this may be the non-compute lane case the description lists as not measured. Since main never gets this far, I can't tell whether the noise comes from the ADD_TID lane or from something later in this path. Happy to rerun with any trace you want.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T21:43:07Z.
Review: COMMENTED
The current head conflicts with
mainf3c2cd73abinShaderDiskCache.hpp. Please resolve the schema version against currentmainbefore running the paired tests. The reported older rebase used version 97, while the conflict is still present on this head. In the merged run, preserve the non-IDXEN lane path, the IDXEN negative control, and both direct and runtime descriptor cases from the new fixture coverage.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.