perf: Demon's Souls (PPSA01342) sends almost every indirect draw to the CPU path (patched SGPR not folded) #5806
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 btsouth on 2026-10-14T11:49:58Z.
Demon's Souls (PPSA01342, v1.005 US) runs its first level at about 1 FPS here, and the driver's queue thread is the limit. Almost every indirect draw takes the CPU path with "patched SGPR not folded". Before I work on a change I'd like to know which fix you would accept.
What the draws look like
With indirect tracing on, nearly every indirect draw in the level looks like this:
Three traced level runs together logged 32,927 of these for opcode 0x25, 5,905 for 0x24 and 1,208 for 0x38 with count 3, against 337 indirect draws that went GPU side. In a 10 s window of the level, the draw summary reports 21 GPU side and 35,562 CPU side, all "patched SGPR not folded".
The packet patches the start instance into s10, but the analyzer finds no instance offset in the vertex shader (i=-1), so ClassifyIndirectDraw fails with NotFolded. ClassifyIndirectDraw on
c0a272537makes the same decision for this case.Cost
In the level (Outpost Passage) each frame has about 6,300 draws and 2,600 dispatches. With APS5_FRAME_SUMMARY and APS5_PROFILE_GPU on, the queue thread spends 0.85 to 1.0 s of CPU per frame, 80 to 120 us per draw, while the GPU is busy about 120 ms per frame. Before some local caching changes it was about 1.5 s per frame.
Question
Would you take a recompiler change that reads the patched SGPR as
gl_BaseInstance, so these draws stay on the GPU with firstInstance applied in place? Or would you rather handle it differently?Setup
A branch on
bab7b3285with Demon's Souls bring-up changes (#4049, #757, #758 and some local fixes), Release, GCC 16.2.1. Arch Linux 7.2.8, i7-14700F, RTX 4070 SUPER on 615.78.08, 31 GiB RAM. Main from 10-13 (665ad7da7) ran out of memory under an 18 GiB cap while preparing shaders at registration during boot, so I haven't measured on main yet, and the base is too old for APS5_TRACE_FRAMES.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T12:08:30Z.
I traced this against current
main(344afad05). The CPU fallback is deliberate when an offset SGPR is shared or the recompiler cannot prove that it is used only by the vertex fetch:ClassifyIndirectDrawaccepts the GPU path only when the indirect packet's SGPR matches the recompiler's folded SGPR and the result is not marked shared/conflicting. For this trace,i=-1means the recompiler has not identified an instance-fetch offset to fold, so mapping the packet-patcheds10togl_BaseInstancewould need evidence that every use of that SGPR is equivalent to Vulkan's instance index. Otherwise it would change guest shader reads as well as fetch addressing.The trace does identify the immediate branch point: the packet names
s10, butresult.instanceOffsetSgpris-1. A small shader capture showing hows10reaches the fetch (and whether it has any other readers) would distinguish a missing analyzer pattern from a genuinely shared SGPR. Until then I would keep the CPU path for correctness; the proposed unconditional base-instance rewrite is not established by the current evidence.Imported from boykopovar/AnyPS5. Originally posted by Sam-mon7 on 2026-10-14T14:29:20Z.
On measuring this on
main: #5872 should fix the boot out-of-memory you hit while shaders were prepared at registration.APS5_LAZY_SHADER_PREPARE=1. Shaders then get prepared on first use instead of all at boot.mainfirst aborts on a 358 MiB address copy (an address-based build copies 358 MiB ... past 64 MiB). #5870 fixes that. If Linux doesn't hit it, you won't need it.Demon's Souls (PPSA01341, EU), Windows 11, RTX 4070, 32 GB RAM,
main63fb0cd92:main+ #5870main+ #5870 + #5872, opt-in onThat should get you a measurement on current
mainfor the indirect-draw question.Imported from boykopovar/AnyPS5. Originally posted by pedroMartinsMJ on 2026-10-14T14:46:44Z.
I'm going to run a test, I'll change a few things in the code and see if the error disappears
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-14T17:56:15Z.
Resident Evil Village (PPSA01556, 01.210.000) shows the same pattern. Setup: Windows 11, RTX 3070 Laptop;
mainat23be5a02bplus our Village stack: #5851, #5703, #5815, lazy shader preparation at first use (APS5_RE8_LAZY_PREPARE=1,APS5_NO_GPL=1) and a few local rendering experiments;APS5_PROFILE_DRAW=1. At the title screen, the[draws]line for one 10 s window:Imported from boykopovar/AnyPS5. Originally posted by btsouth on 2026-10-18T18:53:56Z.
Thanks for tracing it, and sorry for the slow reply. Agreed: the CPU path should stay unless the analyzer can show
s10only feeds the instance fetch, and I don't have a capture that shows that.I'm also withdrawing the proposal for Demon's Souls. On my branch, once these CPU-path draws were cached, the indirect path turned out to be a small part of the cost: over 10 s in Outpost Passage, 57,307 draws took it and reading their arguments cost 38.4 ms in total. Most of the ~100 us per draw went to capture, lookup and
Graphics::Draw, which every draw pays. Main doesn't have that caching, so argument reads may cost more there, as the RE Village numbers above (~0.41 s per 10 s) suggest. I'll leave the issue open for that case unless you'd rather close it.These numbers are from a local branch on
bab7b3285, not main. On 10-14, main with #5872 still went past the 18 GiB cap I run the game under during this level's first load.Imported from boykopovar/AnyPS5. Originally posted by ponhei9502 on 2026-10-20T03:50:53Z.
We captured the Demon's Souls (PPSA01341 v1.07) draws that take the CPU path. All 138 vertex shaders behind them start with
v_add_nc_u32_sdwa vD, v8, s10 src1_sel:WORD_0: vD = instance id + low16(patched start instance), and vD then indexes per-instancebuffer_load_dwordx4rows. s10 is overwritten by as_load_dwordx16right after, with no read or branch between, and v8 has no other reader.Why the analyzer misses it (EmbeddedVertexFetch.cpp): it accepts only VAddI32/VSadU32, not VAddNcU32 (VOP2 0x25 SDWA); it requires the add to write v8 itself (DeS writes v4); and the shared/observed checks are not def-use aware.
Folding s10 as userdata would be wrong here: the start instance reaches 917,966 in our captures (197 of 8,000 records >= 65,536) while the shader uses only its low 16 bits. The exact variant is the BaseInstance builtin for the instance dimension (s10 := gl_BaseInstance, v8 := gl_InstanceIndex - gl_BaseInstance).
We can attach the 138 captured requests if useful.