perf(shader): reuse the source of a bitcast round trip #7677
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7677"
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-18T21:46:01Z.
What
Guest registers are 32-bit words. A float result is bitcast to
u32when it is written to a register, and back tof32when it is read, so emitted modules carry pairs ofOpBitcastthat return to the type of the first one's source. This change makes a bitcast back to that type return the source itself. The source dominates every use of the first bitcast, so the module stays valid.To support this,
SpirvModulerecords the result type and the bitcast source of each function instruction. BothUnaryandEmitNativebitcasts look them up.Tested
Windows 11, MinGW GCC 15.2, RTX 4090 (616.92):
agc_bitcast_round_trip. It recompilesv_cvt_f32_u32results added withv_add_f32and requires that no bitcast goes back to the type of a bitcast's source. It fails onmain(one of six bitcasts) and passes with this change.ctest -R ^agc_: 727/728. The failure isagc_driver_bda_device, which fails onmaintoo.APS5_DUMP_SHADERSwere dispatched on synthetic guest memory withmainand with this change. Every byte they wrote was identical. SPIR-V words over these 72 went from 1,930,912 to 1,898,324 (-1.7 %); for example compute 0x143978f00 went from 8,545 to 8,457 words, and 0x25b390800 from 647,759 to 642,443.This is a small size win: every round trip removed is one instruction the driver no longer compiles.
Performance capture
GTA V (PPSA04264), open world from the same save, RTX 4090, one run each, same session. Base =
main47a266cf9+ #6488 + #6848 + a local bench aid (keyboard pad input while an IME session is open), because GTA V does not run on plainmain;c0206c244d15is this PR on top of it. Traces: fork release perf-7673-7677-20261019.These frame times do not measure this change. The trace buffer of queue worker 0 fills after about 3.7 s (
trace_dropped), and in the open world frame time follows where the save respawns. This PR shortens shader compiles: the SPIR-V word counts and the cold compile times under Tested are the measurement.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)🤖 Generated with Claude Code
https://claude.ai/code/session_01XBXM4pgkMHYEtqN1EQni2P
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T21:46:13Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T22:33:40Z.
AMD run, since the description covers an RTX 4090. Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON. Build:main8a456334fwith #7677, #7673, #7671, #7666, #7676, #7675, #7672, #7668, #7664 and #7658 merged together (each merge clean, built once).agc_bitcast_round_tripandagc_driver_bda_devicepass 3 runs of 3 on AMD's proprietary driver.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-19T00:10:20Z.
About the performance-report request: I captured the requested warm-cache traces (GTA V PPSA04264, open world, RTX 4090). Two things make them a poor fit for this change:
trace_dropped: true, about 3.3 M events lost), so the per-phase totals are not usable. Only the frame percentiles survive.Driver.Draw.shader_compile_and_link), depending on which new shaders that run meets.This change only makes modules smaller. Its effect is on pipeline creation, so I measured that directly: cold NVIDIA
pipeline_create, median of 3agc_compute_pipeline_replayruns, each with a distinctOpSourceExtensionso the driver cache misses. The numbers are in the description. If you'd rather have a specific trace or scene, tell me which and I'll capture it. The three traces I took are here, for completeness: https://github.com/tibzejoker/AnyPS5/releases/tag/perf-7673-7677-20261019AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-20T16:59:20Z.
First Linux run of this PR, on AMD with RADV. Head
c07b6bdc0merged ontomain6bef96df7(clean merge), built in full and compared with the samemain, on the same machine.AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.
Full suite (
ANYPS5_REQUIRE_VULKAN=1 ctest -j8) at56990699d: 1713/1714 with this PR, against 1712/1713 onmain. The one failure is the same on both, so this PR adds none:agc_driver_guest_memory_lifetime(#7784).Comparing the JUnit output with
main: the PR's new entry,agc_bitcast_round_trip, runs and passes. No other entry is added, and none is skipped or removed.This checks correctness only; I did not measure performance.
GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-20T17:01:23Z.
Thanks @DavidAmsellem for the RADV run on gfx1100: same single failure as
main(#7784), andagc_bitcast_round_tripruns and passes.AI-assisted: yes (Claude Code)
Pull request closed