Repository navigation
fix(recompiler): fold draw offsets that the shader only reloads after the fetch add - #7591
Conversation
|
Intel and AMD Windows data: Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
I also ran full CTest with this PR and the 14 other open AGC PRs I tested in the same batch merged together (#7647, #7641, #7630, #7627, #7603, #7600, #7579, #7535, #7533, #7474, #7462, #7050, #7048, #7650). Neither GPU showed a failure beyond AI-assisted: yes (Claude Code) |
|
@savvaniss thanks for the Intel and AMD runs. I've added them to the description, together with Linux/AMD: Radeon 780M (RADV, Mesa 26.0.8, Ubuntu 26.04), where all 11 related tests pass. AI-assisted; the runs are from my machine(s). |
|
Tested on Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce RTX 5090 (driver 617.42), Ryzen 9 9950X3D. Head
Not tested: Diablo II: Resurrected (PPSA03912), so the AI-assisted: yes. Written with AI assistance and reviewed by me. |
|
@klosixgaming-arch thanks for the RTX 5090 run, and for pointing at the right spot. That's the list where a wrong entry would fold an offset the shader still reads. Here is why each entry is a full overwrite:
Left out on purpose:
Two other points:
AI-assisted; the runs are from my machine(s). |
… the fetch add Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BywPXoZACVi8ALV4JKvuPZ
4784b06 to
2234121
Compare
|
Read the full diff and the new test encodings (s_load_dwordx2, SOP2, s_cbranch_scc0, v_sad_u32, s_mov_b64 exec,-1 decode as the cases describe). The overwrite list only contains full writes; reads after the kill, skipped kills and an add after the overwrite all stay shared, and backward branches fall back to the whole-program check. Third-party runs in the thread cover Windows (Intel, AMD, NVIDIA); merged. |
What
An indirect draw goes GPU-side only when the vertex shader's draw-offset SGPRs (base vertex, start instance) are read by nothing but the fetch add that
EmbeddedVertexFetchAnalyzerfolds into the draw (vertexOffsetShared/vertexIndexObserved). Diablo II: Resurrected (PPSA03912) fails that check on almost every indirect draw (patched SGPR not folded, about 3,000 per 10 s), so each draw reads its arguments on the CPU. Once per frame that read waits for the compute dispatch that writes the instance count.The game's vertex shaders read the offset SGPR only in the fetch add. Four parts of the check were too wide for them:
s_load_dword*base width.scalarOperandWidthcounted every SMEM base as 4 SGPRs.s_load_*takes a 64-bit address (2 SGPRs); onlys_buffer_load_*takes a 4-SGPR V#. Sos_load_dwordx2 s[4:5], s[26:27]counted as a read of s28 and s29.s_buffer_load_dwordx16 s[28:43], ...,s_load_dwordx2 s[28:29], ...) and read only the new values. The shared check now walks the program from the start:s_movk_i32orv_readlane/v_readfirstlane.s_cmov,s_bitset*ands_movrelddon't count, ands_movrels*/s_movreld*anywhere make the register shared;s_mov_b64 exec, -1before the add. The shaders enable every lane before the fetch add. With all lanes on, the add runs on every lane, so the folded index is the same. Theobservedcheck now ignores this write.s_mov_b32 exec_lo, -1stays observed (only half of a wave64).v_sad_u32carry.carryObservedreturned true whendestination2was not decoded.v_sad_u32has no carry output, so itsdestination2staysUnknown. An unclampedv_sad_u32add now has no observable carry.On the D2R scene below, indirect draws on the CPU path go from 2,970 to 57 per 10 s. What remains is a
DRAW_INDIRECTwhose shader has no fetch add and never reads s20/s21 at entry. That case is not part of this PR.Tested
Linux: Ubuntu 26.10 (kernel 7.3), Ryzen 9 5950X, RTX 3080 Ti (NVIDIA 615.71.09 open), GCC 15.3.0, Release.
Windows: Windows 11 Pro 26200, i7-11850H, RTX A2000 Laptop GPU (NVIDIA 610.60), WinLibs GCC 15.2.0, Release.
Linux / AMD: Ubuntu 26.04.1 (kernel 7.0), Ryzen 9 PRO 8945HS, Radeon 780M (RADV, Mesa 26.0.8), GCC 15.2.0, Release.
agc_driver_draw_offset_indicesgets four analysis cases:v_sad_u32vertex add: not shared;s_mov_b64 exec, -1before the adds: not shared;s_load_dwordx2from s[14:15] after the adds and then read: not shared;The first three fail on
main. The fourth passes on both, and guards the branch handling.These tests pass on all three machines:
agc_driver_draw_offset_indices,agc_embedded_vertex_fetch,agc_embedded_vertex_fetch_aliasing, and theagc_driver_*testsgpu_indirect_arguments_misaligned_writer_ahead,gpu_indirect_arguments_written_ahead,indirect_arguments_written_ahead,indirect_patched_stage,rect_list_indirect,scalar_swappc_fetch,vertex_fetchandzero_stride_vertex_fetch.D2R (PPSA03912) on Linux: in game with a saved character, Graphics Mode "Performance", no input. Measured on
maina62c724 and on this change on top of it (b383ad4), each relinked with its own relinker.APS5_PROFILE_DRAW=1 APS5_TRACE_SUMMARY_EVERY=10, 120 s from 60 s after the character loads,mainand this change run alternately. The branch was then rebased onto 81cb863 without conflicts, and later onto 3686960 after fix(recompiler): recognize plain no-carry draw offset adds #6919 merged (one conflicting line in the analyzer: both early returns,VAddNcU32andVSadU32, kept); the related tests pass at that head (2234121).maina62c724trace_digest, steady intervals)trace_digest.pyrows from the same runs (steady part):On
mainalone the gain is small, because another wait dominates this scene: a depth bind reads HTILE under a pending fill, about 3.5 s per 10 s (#6505). With #6505 applied, and at Graphics Mode "Quality", the indirect-argument read became the main remaining stall. It was about 2.95 s per 10 s, once per frame, atDRAW_INDIRECT/DRAW_INDEX_INDIRECT indirect-args. This change took that scene from 60 to 63 presents per 10 s (main1b0c7cf + #6505, same machine).main: the same scene with no change to the game's settings, onmain3686960 (which now has perf(agc): take the HTILE words pending fills leave instead of reading them #6505) and this head (2234121) on top of it, each relinked with its own relinker.APS5_PROFILE_GPU=1 APS5_PROFILE_DRAW=1 APS5_TRACE_SUMMARY_EVERY=10, 120 s from 60 s after the character loads, run alternately (main, this, this,main). In the first pair the character loaded late, so only 4 steady intervals count there.main3686960The change still moves the indirect draws to the GPU path, but on current
mainat default settings the frame rate doesn't rise: the time spent reading indirect arguments stays at about 3.4–3.7 s per 10 s, so something still waits for the dispatch that writes them; I haven't traced what. GPU busy per present is about 12 ms higher with the change in the second pair. The presents differ by 1–2 per 10 s in both pairs, within run-to-run noise.trace_digest.pyrows (second pair, steady part):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)main3686960).agc_driver_draw_offset_indiceson Windows 11 with an Intel UHD 770 (32.0.101.7088) and an AMD RX 9070 XT (32.0.31041.1004): it fails onmainand passes with this PR on both (comment)AI-assisted; the runs are from my machine(s).