WIP: test(vk): a game-free bench of the replay's per-draw path, with a census of the Vulkan commands it records #3268
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3268
Loading…
Reference in a new issue
No description provided.
Delete branch "klimovich008/Longshot:perf/replay-bench"
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?
Summary
Measuring a change to the replay thread's per-draw path (program pick, descriptors, the recording) has meant a game run:
packs, a runtime, minutes of warm-up, and frame-rate noise bigger than many of these changes. This adds a bench that
measures the real renderer without the game.
tests/replay_bench.cpploads a builtlongshot_vk.dllas the game does, with a host of its own (a guest memory windowholding its pools), and writes synthetic NVN work into it: a render target, textures, uniform, storage, index and vertex
buffers, and programs of a few hand-encoded Ampere instructions that sample the textures and read the buffers, so
program_forandbuild_descriptorsdo a game draw's work. It starts the renderer windowless (start(NULL)) on thereal Vulkan device and submits each frame's command buffer as the op stream of
gpu/render/rx_nvn.h, through the realreplay(),draw()anddispatch(). No game code or data.It reports:
the steadier, and of the medians), and the same times the scene's draws and dispatches:
us a frame, to read againstthe game's frame (a gain of 0.06 us a draw is 120 us of a 10.6 ms frame, about 1 %, below a game A/B's noise);
--census, everyvkCmd*and descriptor update the renderer recorded, counted and hashed by kind with theirarguments and the data they point to (barriers, passes' attachments, copy regions, clears; a bound descriptor set
as what was written to it; handles numbered in the order first submitted, so two runs compare), and their order: each command buffer's as recorded, the buffers' as
submitted, so a path that records parts on another thread compares with the serial one, and the same commands split
into other buffers hash the same; how many
of the scene's draws and dispatches reached Vulkan; a hash of the picture (copied to a buffer by the GPU after a
scene frame) and of what the dispatches wrote. That is the check that a fast path records what its reference path
does. (Windows; on Linux the renderer loads
libvulkanitself, so the census refuses rather than report nothing.)tests/test_replay_bench.pybuilds and drives it: one renderer, two renderers (--dll-b), or one renderer with aswitch on each side (
--env-b; a switch the menu's settings hold is refused, as the bench has no settings), alternatedruns, B - A; neither side inherits the shell's
RX_,HOS_,LONGSHOT_orOOT_variables;--keep-logs DIRkeeps each run's renderer log, where a switch's check mode counts. Its self-test runs in
tests/run_all.py, with no GPU. The default scene is about the Market's mix: 2000 draws, a program and its bindingschanged every second draw, 4 textures and 2 uniform buffers a stage, indexed draws, each draw's indices and the vertex
buffer it binds at a place of their own across 256 MB of 64 MB pools that the renderer imports and mirrors on its own, as
it does the game's (
--geom-mb; 0 gives eight meshes in one pool, which every lookup finds again, as the game's do not).Read first:
tests/replay_bench.cpp(make_world,make_scene, the census), thendocs/dev/developing.md,"Benchmark the replay without the game".
Testing
Tested: Windows 11, Ryzen 7 5700X3D, RX 9070 XT (driver 32.0.32029.2010), the renderer built from
main@bd4586c2eand@
7bc53f841:host/nvn_layout.cwith its C compiler) passes, and four broken variants fail it(streams without
NOP_END; indexed draws without their index buffer; every draw from the first geometry place; thegeometry's pages left unmarked). Its census checks: a pipeline bind and a draw recorded first into a second command
buffer give the serial stream and kind hashes (handles numbered as submitted), binding one pipeline twice does not;
a submit the driver refuses folds and counts nothing; a barrier's access masks, a pass's attachment ops and a
clearing pass's clear value change the hash, where they lie, a clear value the pass does not clear with and a depth
attachment's stencil value do not; descriptor sets S and T bound in either order hash differently, and the same
writes into sets of other handles (as a pool reset gives out) hash the same. Its geometry checks: each draw's 512 bytes
inside a pool, after the last draw's, reaching the span's end, for 1 to 2048 MB and up to N x 2048 draws; over two
pools, the scene draws and binds each draw's own place, and those pages are marked written. The same compiled and run in WSL with Ubuntu's
clang 21 and g++ 15;
mainagainst itself, 5 runs a side, in each scene (draws, dispatches, mixed): the census the same (commands,their order, the picture, the storage buffers), every draw and dispatch reaching Vulkan; on this head again, one
census run a side in each scene, with the data the commands point to: the same;
RX_VK_INDEX_REBASE=0exported in the shell,mainagainst itself: the driver names it as left out of both sides,and the census is the same;
sparse mirrors on, as in the game on this PC;
RX_VK_INDEX_REBASE=0againstmain: the census namesvkCmdBindIndexBuffer(28 calls vs 8000)and
vkCmdDrawIndexed's arguments;--textures 3and with--ubos 1: each texture and uniform buffer shows in it;tests/run_all.py --strict --changed origin/main(5 passed) andmise run lint; the fulltests/run_all.py --strictin CI (both parts);
main@ 7bc53f841's headers too (API 95), and run against its renderer.The branch merges cleanly with
main@7a014436f(still API 98);vk_api.h,rx_nvn.hand the shader-cache stampare untouched.
Still to test:
python3 -I tests/test_replay_bench.py --dll build-linux/.../longshot_vk.so, expecting thesame output as on Windows (by hand; the bench's Linux loading path has not run on a GPU).
Measurements
Nothing to measure:
tests/anddocs/only, nothing the game runs changes; the bench's own baselines onmainare under Baselines.Baselines
Nothing to speed up here: a tool and its test. Its numbers for
mainon this PC, Windows 11, Ryzen 7 5700X3D,RX 9070 XT,
mainagainst itself, 5 runs a side,us eachin microseconds, the default scene (geometry pools):mainbd4586c2ebd4586c2ebd4586c2eWith the eight meshes (
--geom-mb 0, the default before the third commit), onbd4586c2e: draws 1.125 / 1.144 (+1.6 %),dispatches 2.117 / 2.087 (-1.4 %), mixed 1.204 / 1.190 (-1.2 %); on
7bc53f841: 1.101 / 1.105, 2.087 / 2.037,1.168 / 1.169. Over the A/A sets so far (four with the meshes, two with the pools: +1.4 % and the table's), the fastest
frames' B - A stayed within 2.2 % with draws and 2.4 % with dispatches alone: a smaller difference needs more runs (
--runs 10) or a set repeated.RX_VK_INDEX_REBASE=0moved the time by -1.0 % to +0.6 % in four sets, inside that: the census sees what a changerecords, the timing only what it costs above the noise.
Why the pools are the default: a cache of the draws' index and vertex lookups through the read spans
(
RX_VK_GEOM_SPAN_FAST, not proposed) looked about 8 % faster a draw on an earlier draft of this bench, whose draws allread one small index buffer (that scene is gone), and measured -2 % fps in the game over 3 pairs. Its check mode found 40 % of the game's lookups in a span. On
this bench, 7 runs a side, its switch off against on:
RX_VK_MIRROR_SPARSE=0both sides)Risks
Nothing the game runs changes:
tests/anddocs/only.MKWVK_API_VERSIONand the shader-cache stamp are untouched.The bench builds against
vk_api.h,rx_nvn.h,host/nvn_layout.candvk_loader.h's function lists as they are, soa member renamed or removed there fails its build in CI. CI cannot catch a new host callback the renderer calls
without a null check (as
page_written, API 97): the bench's GPU run would crash on it until it gets a stub. It hasone for every such callback up to API 98, and builds from API 95 on (
page_writtenbehindMKWVK_API_VERSION >= 97),so a branch on an older
maincan take the two files as they are.A run takes 256 MB of guest memory for the geometry pools and as much VRAM for their mirrors (
--geom-mbless for asmaller card). The mirrors are the device's: sparse here, whole where a device has no strict sparse residency for
buffers, and a buffer lookup takes other paths there (main's span memo serves whole mirrors: a draw 1.06 us against
1.27 here): A/B a lookup change with
RX_VK_MIRROR_SPARSE=0on both sides too, as the table above.What the census does not settle (in the how-to): where the renderer diffs mirrored write-backs on the GPU, that pass's
dispatch and its table's address enter the census, so two runs of one renderer could differ there (not on this PC;
RX_VK_WB_DIFF=0on both sides then); and the storage hash holds each storage buffer's last dispatch's result, notevery dispatch's (a dispatch that never reaches Vulkan shows in the counts).
Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (run_all --changedand lint; CI runs the rest.)main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
Assisted-by:/Co-Authored-By:trailers.🤖 Generated with Claude Code
Possibly related, for context:
@review
Recommendation: Request changes. The benchmark can report equivalent Vulkan commands when synchronization arguments differ, and its switch comparisons can silently compare the same configuration. Its threaded census and Windows path handling also need correction before the results are reliable.
Adds a game-free renderer replay benchmark, command census, self-test and usage guide. It gives developers a faster way to investigate per-draw work, but the comparison currently has blind spots that can mislead optimization work.
Blocking (3): must change before merging.
tests/replay_bench.cpp:267: The census drops the pointed-to arguments of barriers and rendering commands, yet reports their hashes as command equivalence. (more on the line) Do: Hash the relevant structures and nested arrays for commands the renderer records, including dependency and rendering information, and add a negative control that changes a barrier field.tests/test_replay_bench.py:211: The two sides inherit renderer switches from the invoking environment, so an A/B switch comparison can silently run the same value on both sides. (more on the line) Do: Remove inherited renderer switches from each child environment before applying explicit side values, or require and report explicit values for both sides; test an inherited value that conflicts with the intended comparison.tests/replay_bench.cpp:215: Handle IDs are assigned in recording order, before command buffers are folded in submission order. (more on the line) Do: Canonicalize handles in submitted command order, including handles nested in descriptor data, and extend the split-buffer self-test with distinct handles first encountered in reverse recording order.Should fix (2): not blocking, but worth doing before merging.
tests/replay_bench.cpp:1220: The Windows renderer path is passed to the ANSI LoadLibrary API. (more on the line) Do: Accept the Windows command line as Unicode and load the renderer with LoadLibraryW, preserving the full path.tests/test_replay_bench.py:61: The self-test compiles the C layout source with CXX and ignores the configured CC. (more on the line) Do: Pass run_all's cc into the test and use it for nvn_layout.c, retaining cxx for the C++ source and link.@fixcan do L1, L2, L3, L4 and L5.Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven as a reliable comparison tool. The author reports Windows self-comparisons within 1.6% for draws and 2.4% for dispatches across four sets, plus a successful index-rebase negative control; the Linux GPU path remains untested.
Other systems: The game and renderer binaries are unchanged. The tool loads the real renderer on Windows and Linux; its census currently requires the Windows loader path. Recorder threads, Vulkan synchronization and developer environment switches affect the reliability of its results.
Switches: No game switch is added, changed or removed. The benchmark defaults RX_VK_ASYNC, RX_VK_RECORDER, RX_VK_PRECOMPILE and RX_VK_FRAMEGEN to 0 only when absent from the environment; inherited values can invalidate comparisons.
Reviewed:
0ae642a277against4007f6eae4: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the pull request template, both commits, all three changed files and the relevant renderer, loader and test-runner code around their interfaces. Skimmed the reported runs. docs/review-checklist.md and ../Tooling/AGENTS.md are absent; no translations or generated files changed.; nothing run (a code review).Checked and fine:
Testing: No code was run, as requested. The author reports Windows GPU and Windows/Linux self-test runs; CI checks are still running.
Overlaps and merge order: Not checked; network access is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -0,0 +212,4 @@for (size_t i = 0; i < n; i++) h = (h ^ b[i]) * kFnv;}inline void mix_u(uint64_t& h, uint64_t v) { mix(h, &v, sizeof v); }uint64_t handle_id(const void* h) {L3 (blocking): Handle IDs are assigned in recording order, before command buffers are folded in submission order.
When: If a helper records the later buffer first and first encounters pipeline B there, B gets ID 1 and pipeline A in the earlier buffer gets ID 2. Serial recording assigns the opposite IDs, so identical submitted commands produce different hashes; the self-test uses only draws without handles and misses this.
Do: Canonicalize handles in submitted command order, including handles nested in descriptor data, and extend the split-buffer self-test with distinct handles first encountered in reverse recording order.
@ -0,0 +264,4 @@I_COUNT};// what a kind carries by pointer, mixed in (the binds' and pushes' data; barriers and passes by their numbers alone)L1 (blocking): The census drops the pointed-to arguments of barriers and rendering commands, yet reports their hashes as command equivalence.
When: For example, host_read_barrier records vkCmdPipelineBarrier2 with its stage and access masks entirely inside VkDependencyInfo. Changing or removing the host-read access mask leaves both the call hash and stream hash unchanged, so A and B can be reported as recording the same commands even though their synchronization differs.
Do: Hash the relevant structures and nested arrays for commands the renderer records, including dependency and rendering information, and add a negative control that changes a barrier field.
@ -0,0 +1217,4 @@host.vulkan_loader_proc = h_vulkan_loader_proc;#ifdef _WIN32HMODULE m = LoadLibraryA(o.dll.c_str());L4 (should fix): The Windows renderer path is passed to the ANSI LoadLibrary API.
When: A renderer stored under a path containing characters outside the Windows active code page cannot be loaded even though Python can resolve and pass that path.
Do: Accept the Windows command line as Unicode and load the renderer with LoadLibraryW, preserving the full path.
@ -0,0 +58,4 @@encoding="utf-8")layout = out / "nvn_layout.o"exe = out / ("replay_bench.exe" if WINDOWS else "replay_bench")steps = [L5 (should fix): The self-test compiles the C layout source with CXX and ignores the configured CC.
When: A developer or CI setup that supplies a required C compiler through CC has host/nvn_layout.c compiled by the independently selected C++ driver instead, so the check does not exercise the requested C toolchain and can fail when that driver cannot compile C.
Do: Pass run_all's cc into the test and use it for nvn_layout.c, retaining cxx for the C++ source and link.
@ -0,0 +208,4 @@def run_bench(exe, dll, env_pairs, bench_args, timeout=600):env = dict(os.environ)L2 (blocking): The two sides inherit renderer switches from the invoking environment, so an A/B switch comparison can silently run the same value on both sides.
When: With RX_VK_INDEX_REBASE=0 already exported, running the documented pattern with --env-b RX_VK_INDEX_REBASE=0 gives A and B the disabled value and reports a near-zero difference as though it compared the default against disabled.
Do: Remove inherited renderer switches from each child environment before applying explicit side values, or require and report explicit values for both sides; test an inherited value that conflicts with the intended comparison.
Thanks: all five fixed in
1576a1c83.vkCmdBeginRendering: flags, area, layers, view mask, and each attachment's view, layout and resolve mode, the resolve target only when it resolves, load and store ops, the clear value only when it clears (16 bytes for colour, 8 for depth and stencil). Also conditional rendering, copy, blit and resolve regions, the clears,vkCmdUpdateBuffer's bytes, blend constants and the colour-blend arrays. Structs taken by their bytes have astatic_asserton their size, so no padding gets in. Left out:pNextchains, andvkCmdSetCheckpointNV's marker (the renderer's own pointer). New self-test controls: a barrier whosedstAccessMaskchanges hashes differently, while the same barrier at another address hashes the same; changing an attachment'sstoreOpchanges the hash, while its clear value does not when it loads.RX_,HOS_,LONGSHOT_andOOT_variables before applying its--env-a/--env-bpairs, and the driver prints what it dropped.check_child_envruns inrun_all. WithRX_VK_INDEX_REBASE=0exported,mainagainst itself now names the variable and the census stays equal.bind P2, draw 4into a second buffer first and thenbind P1, draw 3into the first, submitted {first, second}, gives the serial stream and kind hashes; binding P1 twice gives other ones. Descriptor set updates happen on the device, so they are still counted and numbered as they are made (documented).--dllloads from the UTF-16 command line (CommandLineToArgvW+LoadLibraryW); linksshell32.RUN_ALL_ARGSpasses--cc {cc}, andhost/nvn_layout.cis built with it. The C++ compiler compiles it as C only when no--ccis given.A second review of the newer commits found more problems, also fixed here:
--draws 12faulted).--keep-logskeeps a run's log when it times out.us a frametoo.Verified on
1576a1c83againstmain@ bd4586c2e's renderer (RX 9070 XT):mainagainst itself records the same census in each scene: commands with their pointed-to data, their order, the picture and the storage buffers.RX_VK_INDEX_REBASE=0againstmainnamesvkCmdBindIndexBuffer(28 calls vs 8000) andvkCmdDrawIndexed's arguments.run_all --strict --changed(5 passed) andmise run lintpass.@review
Recommendation: Approve. The five ledger items are resolved, and the reported Windows runs show the bench working. The pull request remains WIP and its CI checks are still running. Nothing blocking is left. Recommend approval; not approved on the forge.
Adds a game-free renderer benchmark and command census for comparing replay paths, with documentation and self-tests. It gives renderer developers a faster comparison tool at the cost of maintaining the synthetic host and Vulkan census.
Since the last review (on
0ae642a277)Resolved: L1 (The census drops the pointed-to arguments of barriers and rendering commands, yet reports…); L2 (The two sides inherit renderer switches from the invoking environment, so an A/B switch co…); L3 (Handle IDs are assigned in recording order, before command buffers are folded in submissio…); L4 (The Windows renderer path is passed to the ANSI LoadLibrary API.); L5 (The self-test compiles the C layout source with CXX and ignores the configured CC.)
Checks: Still running: 11 checks.
Also noticed (1; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Not a game performance change. The author reports matching Windows A/A censuses and a negative control that identifies changed index-buffer commands; Linux GPU execution remains untested.
Other systems: The game and renderer are unchanged. The bench loads renderer builds on Windows and Linux; its Windows census has reported GPU coverage, while the Linux loading path has not yet run on a Vulkan GPU.
Switches: No game switches added, changed or removed. The benchmark adds --geom-mb, defaulting to 256 MB, and --keep-logs, disabled by default; the driver now removes inherited RX_, HOS_, LONGSHOT_ and OOT_ variables before applying each side's explicit environment.
Reviewed:
1576a1c83eagainst4007f6eae4: Read AGENTS.md, CONTRIBUTING.md and the pull request template in full. Reviewed the changes since the ledger and the census and driver code relevant to its items; the full benchmark, developer guide and renderer callers were not read in full.; nothing run (a code review).Checked and fine:
Testing: No commands from the pull request were run. The author reports Windows GPU and self-test coverage; CI is still running.
Overlaps and merge order: Not checked; the network is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by klimovich008. Nothing was run; a maintainer decides.
Pushed
2ee5ee119, from a second review of1576a1c83:vkCmdUpdateBuffer's bytes are left out again: they carry the guest page table's device addresses, which differ from run to run.RX_VK_ASYNC=1).--geom-mbnow shares its places out over the whole span, however many draws.Verified on
2ee5ee119against the same renderer, with the same set as before:mainagainst itself records the same census in each scene.RX_VK_INDEX_REBASE=0negative control still namesvkCmdBindIndexBuffer, and an exportedRX_VK_INDEX_REBASE=0stays out of both sides.run_all --strict --changedand lint pass.@review
Recommendation: Approve. The bench has working Windows results and adds no code to the game. It remains WIP, and its Linux GPU run and CI checks are still outstanding. Nothing blocking is left. Recommend approval; not approved on the forge.
Adds a game-free replay benchmark and Vulkan command census for comparing renderer changes, plus a driver and developer guide. It makes renderer experiments easier to assess at the cost of maintaining a substantial test tool.
Since the last review (on
1576a1c83e)Nothing changed in the ledger.
Checks: Still running: 11 checks.
Also noticed (2; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Not a game performance change. Windows A/A runs reported census agreement and timing variation within 2.2% for draws and 2.4% for dispatches; the Linux GPU path has not yet been run.
Other systems: The tool loads the renderer on Windows and Linux; the census is available only where Vulkan is loaded through the host. It does not change game runtime code.
Switches: No game switches added or changed. The bench defaults RX_VK_ASYNC, RX_VK_RECORDER, RX_VK_PRECOMPILE and RX_VK_FRAMEGEN to 0 unless supplied explicitly; those defaults suit its synchronous timing purpose.
Reviewed:
2ee5ee1198against4007f6eae4: Read the changes since1576a1c83, the developer-guide addition, repository instructions, contribution rules and PR template; inspected the benchmark and driver and the renderer descriptor and buffer-update paths. The full benchmark output was truncated during reading, so not every changed code file was verified in full.; nothing run (a code review).Checked and fine:
Testing: No commands from the project were run. The author reports Windows and WSL self-tests and Windows GPU census runs; CI is still running.
Overlaps and merge order: Not checked; network access is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by klimovich008. Nothing was run; a maintainer decides.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.