GTA V (PPSA04264) Story from ~1 to ~21 FPS on Windows: findings that may speed up every title #6754
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 tibzejoker on 2026-10-16T09:40:58Z.
Summary
We have been running GTA V (PS5, PPSA04264) on Windows (RTX 4090, i9-13900K, NVIDIA 616.92) on top of main plus a stack of
upstream PRs and a local proof of concept. Story mode went from ~1 FPS (#5694) to ~21.4 FPS (66 s window, 21.1-21.6 per
10 s slice), rendering correct, in the game's "Performance" mode (2560x1440 internal, 4K output).
Branch: https://github.com/tibzejoker/AnyPS5/tree/gtav-next11-poc34 (POC quality: env switches everywhere, some test debt, not
meant to be merged as is). Most of what we learned is not GTA-specific, and several items look like cheap, large wins for other
titles. Before splitting anything into PRs, we would like to know which directions you want and in what shape.
20 s of Story with the POC branch (the window title shows the FPS counter):
https://github.com/user-attachments/assets/468466fe-23b1-48b9-89c6-23ebb23db070
Where the time went, step by step (one run each, same save, Story start, warm caches)
getenvcalls there; main does not have them)Findings that probably matter beyond GTA
shaderDenormPreserveFloat32. NVIDIA reports false, sov_fma_mix*and the f16 interpolationpath were emulated exactly through f64 (
Interpolatein SpirvAluEmitterFloat64.cpp). GeForce runs f64 at 1/64 rate: one GTAcompute went 8.25 → 5.3 ms with the host's fused f32 FMA instead.
repair in f16 conversions roughly doubled the SPIR-V of f16-heavy programs. With a "fast math" default (native
Fmaon f16x2, hostNaN payloads) the same compute went to ~1.2 ms (1.04 M → 324 k SPIR-V words, 255 → 168 registers, no spill). Rendering looks
identical; the f16 exactness tests of course need the exact path (kept behind
APS5_POC_EXACT_MATH=1).operator new/free) and~6 % was
__emutls_get_address(MinGW GCC has no native TLS; everythread_localaccess is a call throughpthread_getspecific).Our POC patches ucrtbase's heap entries to mimalloc process-wide (blocks allocated before the patch still go back to the process
heap) and gives the driver its own
__emutls_get_addressover a fixed TEB slot. Side effect: a long-standing heap-corruption flake ofagc_driver(thread-exit TLS destructors) disappeared. #6292/#6615/#6650/#6067 go in the same direction.preparation and the recording form one chain, so moving work between threads only helps when it removes a serialization point
(drains at non-draw packets and at rewind-chunk ends were the big ones). We measure that with a per-10 s
[draw-idle]line (why therecording thread is idle: waiting for preparations, for the worker, or pushing into a full pipeline).
on the pool; the POC now queues every job behind the preparations' tickets, and readers (captures, WAIT_REG_MEM, the flush hook) wait
for queued jobs that write the range they read.
so recipes cover 0.2 % of draws in GTA. The per-draw full path is what has to be cheap.
duplicated per invocation): a layout choice driven by the driver's pipeline statistics (registers/spill of the two-lane build) might
be a better rule than the IR-only test.
Where it stands now
(resource revalidation, target refresh, descriptor preparation, ~40 % of that thread) off it, in the DXVK CS-thread style.
per-texture branches).
Questions
exact (e.g. f32 FMA instead of f64 only where the result provably matches)?
per-module?
want it gated and tested?
Traces, per-step numbers and profiles are available on request. AI-assisted (Claude Code); all numbers come from runs on the machine
above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T11:34:03Z.
The findings point to several separate tracks, and a few already have related open work: #6767 replaces the interpolation path that needs Float64 on devices without it; #6503 probes an exact f32-denormal fast path; #6067 covers mimalloc for relinked Windows games; and #6292/#6615 cover AGC lock/TLS costs. Those are related rather than proof that the POC patches are equivalent, so any follow-up should compare the exact behavior and platform scope before carrying code over.
The f16 fast-math change is a different contract question: making native f16 FMA/default host NaN handling the default would relax the current exactness behavior. An opt-in mode with explicit accuracy tests seems easier to evaluate first than a default change; title-image similarity alone does not establish guest-visible equivalence. For the f64-to-f32 FMA case, a device-specific exact path with a focused differential test could be a narrower candidate if the result equivalence is established for the relevant operands/modes. The process-wide allocator/TLS replacements and queue recording redesign affect broader runtime behavior and deserve separate proposals with stress/lifetime coverage.
Could you split the measurements by exact change and report the matching source diff plus correctness test for each proposed follow-up? That would help identify which result is independently reproducible without the GTA stack.
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-16T12:05:41Z.
Thanks @MarcZX100, that's useful. Agreed on splitting.
First, a correction on overlap: I hadn't seen the GTA V discussion #1203, and part of the CPU side above duplicates work already there by @MichonGoddijn231849:
So please disregard question 3 and findings 4 and 6 as proposals.
Plan for the rest, one item at a time, each measured alone on current main (which includes #1201/#1202/#494) with its own diff and correctness test:
v_fma_mix*/ f16 interpolation on devices withoutshaderDenormPreserveFloat32. I'll compare with #6767 first rather than duplicate it, and back any remaining part with a differential test over the relevant operands and modes, as you suggest.I'll report per-item numbers here as they come.
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-16T13:49:29Z.
Item 1 of the plan:
v_fma_mix*/ f16 interpolation, f64 emulation vs #6767's integer path vs plain f32 FMA.Cost (RTX 4090, driver 616.92). One GTA compute program that is heavy on
v_fma_mix(2548 ISA words), GPU timestamps per dispatch (APS5_GPU_TIME), same session, one run each, nothing else changed:The SPIR-V is the same size in all three (323.7k / 325.0k / 324.9k words,
agc_shader_replayon the dumped request), so the gap is the f64 and 64-bit integer rate on GeForce, not code size. On this GPU #6767 does not buy much speed; the gain comes only from going to f32.Correctness (
agc_driver_interpolation_modes, which #6767 extends with 2048 random rows x 32 modes; I added a switch that counts every differing result instead of stopping at the first, 394,752 results compared):f64 emulation: 0 differences.
#6767's integer path: 0 differences on NVIDIA. (Earlier I suspected a NaN mismatch in it; that was the f32 path, sorry for the noise.)
f32 FMA: 23,694 differences. On the 1,536 hand-written hardware rows:
0x7fffffff/0x7fff; the hardware keeps the quieted input payload);The random rows also show large differences, for example
0xc3e2c9c4instead of0xc3e2c000, or0x624687dainstead of0x47800000. There the f32 result is not rounded or saturated to f16 the way the reference expects. I haven't checked yet how much of that survives into the final f16 written by the shader, so I count it as a real difference for now.So plain f32 FMA is not an exact replacement on this GPU, and it can only be an opt-in, as you said. The narrower candidate would be a guarded fast path: use f32 FMA when the operands are finite, not denormal, and the result stays in f16 range, and fall back to #6767's exact path otherwise. That keeps guest-visible results identical and the common case cheap. I'll measure that on top of #6767 before proposing anything.
Item 2 (native f16 FMA, host NaN) comes next, with the same counting on the mix-precision test.
Instrumentation:
47b2368c2(test-only,APS5_TEST_COUNT_MISMATCHES=1).Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T13:57:42Z.
Thanks for the separate timing and differential counts. The 23,694 mismatches make plain f32 FMA an unsafe replacement. One useful next check for the guarded candidate is whether each intermediate difference survives the shader’s final f16 write, while preserving the exact cases you already identified (NaN payloads, denormal/infinity, range and double rounding). I agree it should stay a separate measured change on top of #6767.
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-16T14:43:41Z.
Guarded candidate, measured on top of #6767's integer path as you suggested.
Does the plain f32 difference survive the final f16 write? Partly. On the random rows, 10,752
v_interp_p2_f16results differ before packing. After rounding both sides to f16 (RNE), 1,664 still differ: 1,528 involve a NaN on one side, 136 are numeric (denormal/flush and double-rounding cases). So most of the large intermediate differences are an artifact of comparing before the f16 write, but not all of them, and the hardware rows (NaN payloads, denormal × infinity, double rounding) are real.Guarded path (
178536006, POC switchAPS5_POC_GUARDED_FMA_MIX=1). In the interpolation helper:delta*coordinate + base - fused: the product error comes from an FMA and the sums from TwoSum. All of it is exact while the product does not underflow, and that case is guarded too.Results (RTX 4090, 394,752 compared results in
agc_driver_interpolation_modes):agc_driver_mix_precisionand the other f16/interpolation tests (15) also pass with it.The midpoint check matters: it fires often with f16 operands. Rejecting midpoints instead of resolving them cost 3.73 ms, because a single lane on the exact path makes the whole wave run it. The remaining gap to plain f32 is the extra arithmetic plus the rarer guarded cases.
If this looks like the right shape, I'd propose it as its own PR on top of #6767 once that lands, with a test that forces each guarded edge (midpoint above/below/exact, product underflow, f16 range limits) on both sides of the branch.
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-16T15:12:35Z.
Item 2 (native f16 FMA and host NaN payloads): dropping it, it no longer buys anything measurable.
Same session, one GTA Story run each, all with the guarded interpolation path from above:
agc_driverf16/interpolation tests (26)packed_float16_native: Vulkan does not requiref16vec2 Fmato be fused)The hot program does get cheaper, but frames don't get faster: with the guarded interpolation path the frame is now limited on the CPU side, so the remaining f16 savings disappear into idle GPU time. The only way native f16 FMA could become legitimate is a startup probe showing the device fuses it (like #6503 does for f32 denormal flushing), and that's not worth a proposal without a frame-time gain.
Next: item 3 (allocator / TLS) measured against #6067 and #6292/#6615.
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-16T15:19:55Z.
Item 3 (host runtime on Windows): nothing to propose beyond #6067 and #6615.
#6067 is the same allocator change (mimalloc for the whole process) and #6615 is the same TLS change (per-draw thread-locals in TEB slots) as ours. Measured on our branch, same session, one GTA Story run each:
APS5_NO_MIMALLOC=1)Both were worth a few percent earlier, when the draw path made far more allocations and
thread_locallookups per draw. Now that the frame is bound elsewhere, they are within run-to-run noise for GTA. mimalloc did fix a heap-corruption flake in ouragc_drivertest runs, but that is a stability argument for #6067, not a performance one. So for these two I'd defer to #6067 and #6615 rather than open anything.For reference, current upstream main + #6488 runs the same GTA Story scene at ~14.6 FPS on this machine (frame counter), against ~20 on our branch. Item 4 (CPU-side ordering and DCC keys on the merged #1201 path) is where the remaining difference is, so that's next.
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-16T16:05:53Z.
Item 4, plus what actually separates our branch from current main.
The three CPU items I listed:
DrawPipeline::Enqueue(commit, writes, labelAddress, labelBytes)) and preparation stays on the packet thread. Ours appeared only because our branch prepares draws on a parallel pool, which main doesn't have.WaitForKeyWriters/currentDccKeys. On our branch, turning it off costs 2.4 % (19.48 vs 19.96 FPS), at the edge of run-to-run noise. Not worth a proposal on its own.What does matter. Knock-outs on our branch, same session, one run each, reference 19.96 FPS:
The largest one is small, so I ported it alone onto current main:
a69b6287fonperf/resident-linear-targets, 18 lines on maineb901bcf4.pixel_ancillary_word/pixel_fixed_point_position: an import made over a short-lived test block left the reused address unwatched.agc_driver|agc_masked472/473 on Windows/NVIDIA. The one failure isgpu_indirect_arguments_misaligned_writer_ahead, which does not compile with MinGW on main (alignas(65536)); #6452 fixes it.@MichonGoddijn231849 this overlaps your #1191 (resident linear targets). Yours is ~6,000 commits behind main and conflicts in 10 files; this is a much narrower take on the same idea. Happy to fold it into #1191 or drop it in favour of a rebased #1191, whichever you prefer. The number above is the one to compare against.
The GPU detile of comp-to-single surfaces (main still expands them on the CPU in
ExpandSingleBlocks) is the next one I'll port and measure on main the same way.Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-16T16:16:38Z.
Second one ported alone onto main: GPU detile of comp-to-single DCC surfaces (
dd193d5d2onperf/gpu-single-key-detile, 22 lines on maineb901bcf4).What it does. A surface whose DCC keys are all comp-to-single is currently read on the CPU, expanded by
ExpandSingleBlocksand uploaded through staging. With a host import over it, it now detiles on the GPU straight from the import, like an uncompressed surface. The detile shader reads each element from the start of its 256-byte key block, which holds the block's single value. Thick surfaces, and formats whose element doesn't divide 256 bytes, keep the CPU path.GTA V Story, main + #6488, frame counter, 150 s window, same scene, rendering checked:
agc_driver|agc_masked: 474/475; the only failure is the MinGWalignasbuild break that #6452 fixes.Before turning either into a PR, I'll add a test for each that fails on main and passes with the change:
The remaining piece of our gap, parallel draw preparation (−5.4 % when off), is a structural change to #1201's model rather than a small diff, so I'm not proposing it.
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-16T17:29:48Z.
Update: the resident linear targets are now #6892 (with a test that fails on main's path, on NVIDIA and Intel, and a performance report). The GPU single-key detile turned out to be covered by #6848 (NFSS10, opened the same day): in GTA, #6848 alone gives the same gain (16.47 → 17.30 FPS on top of #6892) and ours adds nothing on top, so I'm not proposing it. Data posted on #6848.
Imported from boykopovar/AnyPS5. Originally posted by akkadbakkad89 on 2026-10-16T20:33:55Z.
Second-GPU datapoint for the guarded interpolation path (178536006, APS5_POC_GUARDED_FMA_MIX=1): Windows 11, RTX 3070 (Ampere, driver 617.42 — NVIDIA, so also without shaderDenormPreserveFloat32), WinLibs GCC 15.2 build.
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-16T20:34:43Z.
Thanks @akkadbakkad89, good to have Ampere agree with the 0-difference result. On mimalloc: the POC branch pins microsoft/mimalloc at fbd8b99c2 (a 'merge from dev' commit, not a tag), which a shallow submodule fetch can't reach.
git submodule update --init --no-recommend-shallow 3rdparty/mimalloc(or a non-shallow clone) should get it. Either way it's unrelated to the guarded path, which would go upstream on its own on top of #6767.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T01:20:25Z.
Thanks for running the mismatch comparison on an RTX 3070. Zero differences across the three paths on a second NVIDIA family is useful correctness evidence for the guarded interpolation path. The report also clearly marks the limits: there are no per-dispatch timings or GTA run on that GPU, so the performance effect remains measured on the RTX 4090 only. Any upstream follow-up should stay separate from #6767 and carry the differential edge tests onto current main after its dependency is integrated.