Repository navigation
Conversation
… budget for AMD Windows All off by default: - RX_VK_BINARY_CACHE=1: pipelines kept one by one as VK_KHR_pipeline_binary data in hookshot_pipeline_binaries.bin (index in memory, data read per pipeline); RX_VK_PCACHE_SKIP=1 then leaves mkw_vk_pipelines.bin unread and unwritten. RX_VK_BINARY_TEST=<n>: a measurement. - RX_VK_PRECOMPILE_GRAPHICS=keep|release|none: whether the precompiled graphics pipelines and their programs stay resident. - RX_VK_PIPE_WAIT_MS=<ms>: a per-frame budget for waits on pipelines of draws that may be left out (jobs_wait_for: the job goes to the queue's front, no inline run). - RX_VK_PIPE_TRY_CACHED=<ms>: cache hits made at the draw instead of queued behind compiles. - In-play graphics pipelines over 50 ms are logged. Measured on an RX 7700S (AMD 2.0.416, Windows 11) on v2.1.0; see the PR for numbers and what is not tested. Assisted-by: Claude Code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e check's fixture on Linux Assisted-by: Claude Code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cleanup check extracts, which stays as main's Assisted-by: Claude Code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On an 8 GB AMD laptop with 32 GB of RAM, v2.1.0 grows past the PC's RAM after a few area changes (33-37 GB private), so Windows pages the game out and single frames take 5-10 s. First-time cutscenes and boss fights also stop the picture for minutes while AMD's compiler builds new pipelines (10-57 s each).
This draft adds opt-in switches against both, plus a pipeline cache built on
VK_KHR_pipeline_binarythat turned out much faster than the pipeline cache on this AMD driver. Everything is off by default: with no new variable set, behaviour is main's. It is a draft because the rebased build has not been run in the game yet (see Status). It groups several pieces under one topic (RAM and long waits on AMD Windows); I am happy to split it into separate PRs if you prefer.Status, and what was tested where
51da0464). It builds with llvm-mingw, and the game-free suite result is under Tests. The rebased build has not been run in the game.What is in it
1. A pipeline cache made of pipeline binaries:
RX_VK_BINARY_CACHE=1,RX_VK_PCACHE_SKIP=1mkw_vk_pipelines.binis read whole at every start and the driver holds it for the whole session (2.4-2.5 GB here). WithRX_VK_BINARY_CACHE=1, each pipeline's binaries are kept on their own inhookshot_pipeline_binaries.bin, with an index of keys in memory, and only the binaries of the pipeline being made are read from the file.How it works:
cached_graphics/cached_compute(every pipeline goes through them), the pipeline's key is computed withvkGetPipelineKeyKHR, using the create info without the ask-only flag.vkCreatePipelineBinariesKHRis called from that data, and the pipeline is created with the binaries and a null cache.create_cached). Its binaries are then taken from the driver's own cache by probing it with the create info (pipelineBinaryInternalCacheis true on this driver), so nothing is compiled twice, and they are appended to the file..oldand a new one is started.VK_KHR_maintenance5andVK_KHR_pipeline_binaryare enabled on the device only when one of these switches is set.RX_VK_PCACHE_SKIP=1needs the binary cache. It does what main'sRX_VK_PCACHE_LOAD=0does (the file is not read and not saved), but meant for play:mkw_vk_pipelines.binstays as it was, and the play files are not merged into the empty cache, only numbered on.RX_VK_BINARY_TEST=<n>is a measurement only. On the first n pipelines made in play, it logs the key time, whether the driver's cache has the pipeline, a capturing build, a build from the captured data, and a build from the previous run's data (kept inhookshot_binary_test.bin). Everything it makes is destroyed.Measured on the RX 7700S:
RX_VK_PRECOMPILE_GRAPHICS=release, see 2)mkw_vk_pipelines.binThis is the opposite of what #2760 found on NVIDIA (1.2-1.7 ms median against 0.4-0.6 with the pipeline cache, 2.2 MB a pipeline, 159 compute pipelines), so it looks driver-dependent. Numbers from NVIDIA and Intel with this branch would tell.
A finding that may help others: AMD's own Vulkan cache is one file of a fixed 896 MiB (
%LOCALAPPDATA%\AMD\VkCache\*.parc, exactly 939,524,096 bytes) and evicts. Pipelines that came from the driver's cache fell from 3,245 in one session to 11 two sessions later.2. How much the precompile keeps:
RX_VK_PRECOMPILE_GRAPHICS=keep|release|noneThe start builds every noted graphics pipeline (15,000-17,000 here) and keeps all of them, and their programs, for the whole session.
keep(default): as main.release: each pipeline is built (so it is in the driver's cache) and destroyed.none: the notes are not built and their programs not read. Play makes them on first use.A controlled test at the title screen, same install,
RX_VK_PRECOMPILE=0against the default:With
release, the start was at 22.7 GB. So the programs are ~8 GB of that, and the pipelines themselves ~1.2 GB.Caveat: with
noneon v2.1.0, programs were then read fromhookshot_programs.binon the replay thread at their first draw. That gave 100-1,700 ms frames: micro-stutter that the player noticed. Locally I had a switch that read them on a worker (left out here, see below). On main,nonewill most likely stutter the same way unless programs are loaded ahead of their first draw, which is what #2760's load-at-create does better.noneprobably belongs with #2760, andreleaseis the safe one.3. A per-frame wait budget:
RX_VK_PIPE_WAIT_MS=<ms>A frame waits at most this long, in all, for the pipelines of draws that main already allows to be left out (none of their stages writes memory). Past the budget they are left out until a worker has them.
jobs_wait_formoves the waited job to the front of the queue and waits with a timeout; it does not run the job inline, where an AMD compile can take seconds.jobs_wait's steal. With the budget (50 ms) the game kept presenting while they compiled, at a low frame rate with missing parts.This overlaps #1946, which gives a waited draw an unoptimized stand-in. On this AMD card, an earlier benchmark found
VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BITdid not make compiles faster (47 compute shaders, 182 s against 181 s), so stand-ins may help less on AMD. The two could live together.4. Cache hits made at the draw:
RX_VK_PIPE_TRY_CACHED=<ms>A pipeline the driver's cache or ours already has is made at the draw, asked without compiling (
FAIL_ON_PIPELINE_COMPILE_REQUIRED), up to that many ms a frame. Only pipelines that must be compiled go to the workers.In a boss area on v2.1.0 the queue reached 286 jobs for 4 workers. Pipelines the caches had sat behind compiles of 10-44 s each, and the boss model was not drawn for minutes. In a later 30-minute session with the switch at 8 ms, 4,000 pipelines were made at the draw and 824 went to the workers.
5. A log line for slow pipelines in play
Each graphics pipeline built in play that takes 50 ms or more is logged (the first 60, then every 100th), with the program key and the time.
Left out of this rebase (tested on v2.1.0 only)
RX_VK_PROGRAM_ASYNC: programs read on a worker, with a stand-in for the draw, and translations moved ahead of pipeline builds. Main now waits for translations whole, so the draw would wait for the read anyway. It also touchedvk_shader.cpp, which changes the translator stamp, and without it this PR does not change the stamp: no new prepare for anyone. feat(vk): load shader programs when the game creates them (RX_VK_LOAD=create) #2760 covers this better.RX_VK_WORKERSand 6 workers with 16+ threads now.Sessions, for context (v2.1.0, local builds; real fps = presents / time)
Different routes, so read this as context, not an A/B. In every session I also had
RX_VK_KEEP_RETIRED=0in the environment (retired imports given back at once: 0.9-3.7 GB freed in a session, no device loss in about ten sessions). Main has #1906's graceful version of this now, so it is not part of this PR.Private memory still grows during long, varied sessions. The game window's committed memory went from 7.8 to 15.2 GB in one session, more than the game's 9.8 GB, and I have not found why.
The frame rate in busy places
Fps drop in busy places such as Kakariko Village and Castle Town. In one 30-minute session it went from 62 fps (first two thirds) to 46 fps (last third): draws from ~930 to ~1,600 a frame, replay from 8.8 to 13.8 ms, GPU from 9.7 to 12.9 ms. I don't think these switches cause it: the cost rises with what the scene draws, and the replay thread (CPU) is the limit here. It has not been A/B tested in those places.
Other findings on this machine
RX_VK_GPL=1): 937 of 42,549 program variants in about 4 minutes, so about 3 hours for the whole pass. Keeping every library inmkw_vk_pipelines.binwould also grow it to an estimated ~8 GB, read whole into RAM. I did not use it.RX_VK_KEEP_FINALIZED_POOLS=1the same area was fine. This was on a backport, so it may not apply to vk: retire finalized pools without inheritance, remove 1.4 GB VMA prealloc, and trim stale render targets #2759 as it stands on main, but it is AMD evidence for it.Not tested
RX_VK_GPL=1; pipelines that come back with more than one binary (all of mine had one); a binary file damaged by a crash mid-write (records cut short are written over, but this was not forced).Tests
RX_VK_ONLY=1 RX_RELEASE=1 nx2/build.py --standalone).python -I -B tests/run_all.pyon Windows: 449 passed, 11 failed, 35 skipped, the same as clean main (51da0464) on the same PC, with the same 11 failures (builder, portable archive, updater digest,test_input_background,test_gpu_hang_watch,test_spawn_emit,test_fpx_sticky,nx2/test_nup_paths.py: environment ones, nothing these changes touch).tests/test_draw_side_effects.py(its fixture gets stubs fortexture_frame_no,jobs_wait_forandlogf, which the budgeted wait uses; with the budget unset the decisions it checks are unchanged, underRX_VK_PIPE_SKIPunset,0and2), andtests/test_precompile_pipeline_cleanup.py(no change to the test: thereleasebranch was rewritten so the block it extracts still compiles).See #993, #995. Related: #2760, #1946, #2649, #2759, #1906.
This was developed with AI assistance (Claude Code). The measurements come from my own runs of the game.
🤖 Generated with Claude Code