WIP: perf(vk): the render target pool's bound spares the images that came in the last presents (RX_VK_TARGET_POOL_GRACE=0 to disable) #1996
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
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
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1996
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/vk-image-reuse"
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?
Depends on #2064 (the present's source held, split from this PR in dyst's review): this branch is stacked on it.
Summary
The render target pool's bound counts what the pool holds at one moment, and the dead targets come to it several at once (a
pass's targets, a few each present while the camera turns); over the bound the trim destroyed them, and the next presents'
targets of the same shapes were made new.
With this, an image put in the pool in the last
RX_VK_TARGET_POOL_GRACEpresents (4) is not counted out by the bound whilethe pool holds no more than twice the bound: until then its dead texture held it. The idle limit (
RX_VK_POOL_IDLE) stilltakes it, the grace is kept under it (its value less one at most), and while VRAM is short there is no grace. The 600-present
render target imagesline also gives the most the pool held over its bound after a trim since the line before.The result expected: fewer render target images destroyed and made new, where the pool goes over its bound.
The switch:
RX_VK_TARGET_POOL_GRACE(new, kindkill, int, presents), 4 by default, as the branch shipped it;0is thekill switch: no grace, the bound counts every image, as main does. Read once, at the first trim while VRAM is not short. Its
row is in
gpu/vk/switches.def, andRX_VK_TARGET_POOL_MB's row says it is the trim's bound, which the grace may keep up totwice. (
RX_VK_IMAGE_REUSE, which turned off the same thing, is gone, as dyst asked.)From bd3ea307 on
exp/x86-asm-sync(its image-reuse work; main has the other half: a dead target's image pooled at itsretirement when the GPU is past it), with 224a29b8's grace under the idle limit.
Read first:
pool_trimingpu/vk/vk_texture.cpp,effective_graceandgrace_ceilingingpu/vk/target_pool.h, thentests/test_target_pool_grace.py.Testing
Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head
850ba5dfon #2064'sa9d04a2e(main9dd41326), light jobdy1996cof this PC's job queue,RX_CPMset (the Vulkan headers found):tests/run_all.py --strict --exactovertests/test_target_pool_grace.py,tests/test_switch_table.py,tests/test_dead_targets_sweep.py,tests/test_target_retention.py,tests/test_present_source_held.py,tests/test_target_image_pool.pyandtests/test_vram_compact.py: 7 pass;tests/test_target_reuse_memory.pyfails on the two points it failed on main @f1f2dc5bin build jobfb-vkfix-1(destroy_image_laterundeclared in its fixture,vmaGetAllocationInfo2found), not rerunon
9dd41326.gpu/vk/vk_texture.cppcompiled (syntax) with the game build's own commands. Earlier, ate88ea1b7(jobsfb-1996-1tofb-1996-3): the grace's test commit failed on the PR's first code and passed at the fix.The Test Farm ran
e88ea1b7(comment #1996 (comment), KokiriForest, Linux NVIDIA and RADV): its picture check failed at both switch settings, but the pictures were taken right after a
stick-driven camera turn and show a different viewpoint on main and on the PR (no main-against-itself picture); and the grace
was not exercised: every log says the pool let go of nothing over its bound and was at most 0 MB over it.
It has NOT run in the game on this PC yet.
Still to test:
Hyrule Field, the highest Output resolution, the camera turning, on a card of 6 GB or less (issue #939) and a Tier 1
discrete card: main @
9dd41326against this branch unset and withRX_VK_TARGET_POOL_GRACE=0, at least two starts a side,interleaved; expecting the pool's own lines to show it (
the pool let go of N over its boundwith N above 0 on main,at most N MB over its boundon the branch unset), fewer made new unset than with=0, the driver's VRAM peak againstmain, pictures at an input-free point the same as main within main against itself, no FATAL or device lost (on the Test
Farm, or by hand)
python3 -I -B tests/test_target_pool_grace.py, expecting PASS (by hand)Measurements
Verdict: not measured in play yet.
RX_VK_TARGET_POOL_GRACEships at 4, as the branch shipped it; no measurement chosethat default. The farm's Kokiri run did not exercise the grace (the pool never over its bound), so its figures say nothing of
it; the A/B in Still to test does.
Risks
What could break: the pool holding more VRAM than its bound. Each image is in its grace for 4 presents at most, but while the
camera keeps turning and new shapes keep arriving, the pool can sit near twice the bound for as long as that lasts: at worst
one more bound's worth of render-target images than main's trim allows, the bound being
RX_VK_TARGET_POOL_MBor a twelfth ofthe VRAM the driver allows, 256 to 768 MB, so 256 to 768 MB more by default (as much more as
RX_VK_TARGET_POOL_MBsays whenset); not while VRAM is short. The ceiling of twice the bound is provisional, chosen, not derived from a measurement; the VRAM
peak against main decides it, on 6 GB cards most of all (issue #939). Turn it off with
RX_VK_TARGET_POOL_GRACE=0. Renderercode: the runtime is rebuilt; nothing changes for players' saves, options or caches. Overlap: #2054 (also siantm's) adds a lazy
retirement path that checks
present_source; whichever of it and #2064 lands second addsdead_targets::present_heldto it.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Possibly related, for context:
Recommendation: Request changes. Regular eviction can erase the texture that the current present still uses, and a grace setting at or above the effective idle limit disables byte-cap eviction. The patch also leaves an existing pool fixture unable to compile its extracted trim function.
The grace gives recently retired render targets more time to be reused, which could reduce image creation and destruction while the camera moves. It keeps more image memory live across presents, and the retirement changes need a complete lifetime fix before they can protect every presentation route.
@fixwill do (12)gpu/vk/vk_texture.cpp:6050: Deferring pool insertion still erases the selected Texture and queues its image with the old last_value. (more on the line)gpu/vk/vk_texture.cpp:4998: The new sweep exclusion relies on present_source, but do_present bypasses texture_for_present when it receives a null texture. (more on the line)gpu/vk/vk_texture.cpp:594: The runtime never enforces the stated rule that grace stays below the effective idle limit. (more on the line)gpu/vk/vk_texture.cpp:6049: The new failure condition delays reuse for write-backs that failed before submitting any GPU work. (more on the line)tests/test_target_reuse_memory.py:436: This fixture extracts pool_trim without declaring or extracting its two new helpers. Its generated C++ now references undeclared image_reuse_on and pool_grace even once the existing base failure is addressed. Supply deterministic switch helpers and keep the checks for indexed trimming and reuse by size.tests/test_target_pool_grace.py:146: The compiled pool fixture inherits RX_VK_TARGET_POOL_GRACE and RX_VK_POOL_IDLE. (more on the line)tests/test_target_pool_grace.py:224: The compiled trim cases exercise the defaults and the kill switch. (more on the line)tests/test_target_pool_grace.py:233: The lifetime checks match source strings. (more on the line)gpu/vk/vk_texture.cpp:599: Give grace its own byte ceiling above the usual trim target and log the peak excess between status lines.gpu/vk/switches.def:684: RX_VK_TARGET_POOL_MB still reads as a cap and the PR says grace is read at the first trim. (more on the line)For the author (2) (a run, a measurement or a decision)
gpu/vk/vk_texture.cpp:599: Measure peak pool bytes, process RAM and driver VRAM between pressure samples, including a heavy scene and a shared-memory device. (more on the line)Checks: Still running:
CI / Conventional Commit title (pull_request),CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request),CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request),CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request),CI / Workflow lint (actionlint) (pull_request),CI / Website build and checks (pull_request),Guide screenshots / Guide images and local UI source review (pull_request),Third-party parts / As their notes say (pull_request),Third-party parts / The same as upstream (pull_request),PR description / Description follows the template (pull_request_target).More: does it help, other systems, switches, what was read
Does it help: Unproven. The earlier branch reported BindImageMemory at 3.2% of a core and image destruction at 2.6% of a core on the presenting thread in Kokiri Forest. Those figures locate the cost. No game run compares
17c357ddwith75317e1for measures the savings, peak memory or frame pacing.Other systems: Exact reuse and reuse by size share the larger pool. Reuse by size can take memory after one present and destroys the old image synchronously, so fewer reaper jobs alone cannot establish a replay-thread gain. Discrete GPUs and shared-memory devices use the same grace, including Steam Deck. Pressure and compaction still participate, but the regular trim can use a pressure sample up to nine presents old. Plain blit, headless capture and frame generation consume the selected source after texture maintenance. The diff leaves shader translation, the renderer API, saves, player settings, audio and input untouched.
Switches: RX_VK_IMAGE_REUSE is a new developer kill switch, on by default and read once. Off disables grace but leaves the retirement changes active. RX_VK_TARGET_POOL_GRACE is a new tuning switch, default 4 presents, parsed into 0–1024, with 0 disabling grace. Its effective upper bound must stay below RX_VK_POOL_IDLE, including overrides. Both have sorted switch-table rows. The on and 4-present defaults still need measurements, and the RX_VK_TARGET_POOL_MB row needs to describe the permitted overshoot.
Reviewed:
17c357dd55against75317e1f31: Read the seven-file diff, the commit and trailer, all five changed Python tests, both switch entries and their neighboring pool entries, and the changed renderer functions with their eviction, timeline, present, read-back, compaction and reaper callers. Read AGENTS.md, CONTRIBUTING.md, the Forgejo template and developer standards. Read the applicable architecture, switch, measurement and screenshot rules and the dependent source-test sections. Renderer and switch-table sections outside these paths were skimmed or left unread. The description contains the run summary. Raw results were unavailable, and there were no tester comments, earlier reviews, generated files or translations in the diff. The checkout has no docs/review-checklist.md or sibling Tooling repository.; nothing run (a code review).Checked and fine:
Testing: Read-only review. The author reports 75 of 88 checks passing on Windows and names 13 checks that also fail at the base. The missing trim dependencies are visible in the source even though that fixture already fails at the base. No Linux renderer build or game run is recorded. The supplied CI jobs are still running.
Overlaps and merge order: No overlapping pull request found in the supplied material or local history. Forgejo overlap status was unavailable offline.
Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.
@ -680,3 +681,4 @@SW(RX_VK_TAAU_FXAA, kill, int, "1: FXAA in the stand-in's shader", "0 gives the plain linear upscale as before; 2 draws the pixels FXAA changed in red.")SW(RX_VK_TAAU_KEYS, hw, string, "fd029a317a9a4b94 where the network runs on software multiplies (or RX_VK_NO_F16), else '-' (the network runs)", "Program key prefixes whose upscale network is replaced by the renderer's TAAU stand-in; '-' replaces none.")SW(RX_VK_TARGET_POOL_GRACE, tune, int, "4 presents (unset or not a number; under RX_VK_POOL_IDLE's 8, so the bound can act)", "Presents an image put in the target pool is not counted out by its bound (with RX_VK_IMAGE_REUSE), 0 to 1024 (clamped); 0: none. Read once, at the first trim.")SW(RX_VK_TARGET_POOL_MB, hw, int, "a twelfth of the VRAM the driver allows, 256 to 768 MB", "Cap, in MB, on the pool of render targets kept for reuse.")L12 (minor): RX_VK_TARGET_POOL_MB still reads as a cap and the PR says grace is read at the first trim. A recent batch can exceed the stated cap, and a first trim under pressure skips the grace read. Document the cap as the normal trim target and give the grace read timing and effective limits in the table and developer switch reference.
@ -566,2 +591,4 @@const uint64_t cap = (pool_pressure >= 2) ? 0 : (pool_pressure == 1) ? (full_cap / 2) : full_cap;const size_t most = (pool_pressure > 0) ? 64 : 16;// (longshot, RX_VK_IMAGE_REUSE: what came in the last presents is not counted out by the bound, above. Not while VRAM is short)const uint64_t grace = image_reuse_on() && !pool_pressure ? pool_grace() : 0;L3: The runtime never enforces the stated rule that grace stays below the effective idle limit. With RX_VK_TARGET_POOL_GRACE=64 on a default Steam Deck, or with the default grace and RX_VK_POOL_IDLE=2, every non-idle entry is protected. The byte cap then has no effect before pressure is detected. Clamp effective grace below the configured idle limit and cover the override in the compiled test.
@ -570,2 +597,3 @@Pooled& oldest = pool_by_age.front();if (pool_bytes <= cap && !target_pool::idle_out(frame_no, oldest.since, idle)) break;if (!target_pool::idle_out(frame_no, oldest.since, idle) &&(pool_bytes <= cap || (grace && frame_no - oldest.since <= grace))) break;L9: Measure peak pool bytes, process RAM and driver VRAM between pressure samples, including a heavy scene and a shared-memory device. A 600-present snapshot can miss a whole grace window. The same images were live before retirement, but the branch can keep them while allocating the next set.
@ -4967,3 +4996,3 @@bool any = false;const auto candidate = [&](const Texture* tex) {return tex->gpu_written && tex->first_render_frame && tex->guest_size &&return tex != present_source && tex->gpu_written && tex->first_render_frame && tex->guest_size &&L2 (minor): The new sweep exclusion relies on present_source, but do_present bypasses texture_for_present when it receives a null texture. Blank presents can therefore keep excluding the previous source even when it is an otherwise eligible overlapped target. Set the source on every present, including null presents, or pass the selected source into maintenance.
@ -6017,1 +6047,3 @@destroy_later(*tex, completed);// (longshot, RX_VK_IMAGE_REUSE: a render target's image goes to the pool at once, destroy_later; not one whose write-back// above did not complete, whose copy the GPU may still be at, nor the one this present shows)const bool flush_failed = e.flush && !flushed_ok.count(tex);L4 (minor): The new failure condition delays reuse for write-backs that failed before submitting any GPU work. For example, a staging allocation failure leaves an otherwise completed target on the dead list for another present, so the next matching target can allocate a new image. A pending timeout already skips eviction through flush_later, and a failed submitted batch already raises last_value. Keep those existing protections and remove the blanket pool delay for failed write-backs.
@ -6018,0 +6047,4 @@// (longshot, RX_VK_IMAGE_REUSE: a render target's image goes to the pool at once, destroy_later; not one whose write-back// above did not complete, whose copy the GPU may still be at, nor the one this present shows)const bool flush_failed = e.flush && !flushed_ok.count(tex);destroy_later(*tex, completed, !flush_failed && tex != present_source);L1: Deferring pool insertion still erases the selected Texture and queues its image with the old last_value. When texture_for_present falls back to a differently described rendered image, a plain blit may leave its age and timeline value unchanged. If the tenth-present eviction selects that old, overlapped image, a later headless or frame-generation access can dereference the erased Texture, and the next dead-list drain can recycle the image before the present copy finishes. Exclude the active source from eviction selection and hold its image and views through completion of the actual consuming submission, including the separately submitted window copy.
@ -0,0 +143,4 @@# (-Wno-unused-variable: the pool's counters the trim does not touch come with the cut, as pool_take_memory's)subprocess.run([cxx, "-std=c++20", "-O1", "-Wall", "-Wextra", "-Werror", "-Wno-unused-function", "-Wno-unused-variable","-Wno-missing-field-initializers", "-I", str(ROOT / "gpu" / "vk"), str(src), "-o", str(exe)], check=True)r = subprocess.run([str(exe)], text=True, capture_output=True, timeout=30)L6: The compiled pool fixture inherits RX_VK_TARGET_POOL_GRACE and RX_VK_POOL_IDLE. A shell with grace set to 0 makes the default-grace test fail, and an idle override can change the age boundary. Clear both names case-insensitively for the default cases and pass explicit environments for the overrides.
@ -0,0 +221,4 @@+ block(tex, "size_t pool_trim()"))base = (FIXTURE.replace("/* DEAD */", block(tex, "struct Dead {") + ";").replace("/* SWITCHES */", switches).replace("/* POOL */", pool).replace("/* PUT_TRIM */", put_trim))compiled(a.cxx, "pool_grace", base.replace("/* MAIN */", ON))L7: The compiled trim cases exercise the defaults and the kill switch. They never run a same-present trim with the kill switch on and grace set to 0. Removing the grace truthiness check at vk_texture.cpp:599 would wrongly protect age-zero entries and still pass. Run that case, and test the effective idle boundary with a configured grace at or above it.
@ -0,0 +230,4 @@need("inline constexpr uint64_t kIdlePresents = 8;" in target_pool and"inline constexpr uint64_t kIdlePresentsReuse = 64;" in target_pool,"RX_VK_POOL_IDLE's defaults changed: the grace (4) must stay under them, or the bound gives nothing back")later = block(tex, "void destroy_later(Texture& tex, uint64_t completed, bool pool_now = true)")L8: The lifetime checks match source strings. All of them can pass while regular eviction still erases the source before the present reads it. Exercise eviction and dead-list retirement with a selected fallback source and a stub completion signal. Assert that the texture remains usable for recording and that neither reuse nor destruction occurs before the consuming submission completes.
17c357dd55e88ea1b701Thanks for the review (#1996 (comment)). The branch is rebased onto main @
f1f2dc5b; the PR's own commit is unchanged by the rebase (now39c1c0bc). Two commits on top:cbc77c78(the tests) ande88ea1b7(the fix). Point by point:e88ea1b7texture_for_presentmarks the texture it picks, including the fallback in another description (Texture::presented). The eviction intexture_frame,dead_targets_sweepandreuse_retire_framenow skip a texture a present showed in the lastdead_targets::kPresentHold(9) presents. So it is not erased, and its image and views stay while the present's recording, the headless and frame-generation paths and the window's copy use them. The window copy is only known to be done when its frame slot's fence is waited, at mostkPresentSlotsMax(8) presents later and after that present'stexture_frame; astatic_assertties the two constants. The hold counts presents, so it assumes the queue finishes the copy by the time that fence is waited, as present_image's own slot reuse does.do_presentnow callstexture_for_presentfor a null texture too, and it sets no source (e88ea1b7). The hold above no longer depends onpresent_source.target_pool::effective_gracekeeps the grace at the idle limit less one at most, whatever both are set to (e88ea1b7). The compiled test runsRX_VK_TARGET_POOL_GRACE=8andRX_VK_POOL_IDLE=2: the bound acts on an image as old as the idle limit.destroy_lateris main's again, withoutpool_now(e88ea1b7). A submitted write-back that did not complete already raiseslast_value(flush_textures), and a busy one stays throughflush_later. The four tests that had followed the signature are main's again.tests/test_target_reuse_memory.py's fixture now has fixedimage_reuse_on(off) andpool_grace(0) stand-ins and the new counter, so itspool_trimcompiles whatever the environment, and its indexed-trim and reuse-by-size checks are kept (cbc77c78). With the Vulkan headers, the PR's commit failed on the undeclared helpers; at the head it fails only as on main (destroy_image_laterundeclared in its fixture,vmaGetAllocationInfo2found), which this PR leaves alone.RX_VK_TARGET_POOL_GRACE,RX_VK_POOL_IDLEandRX_VK_IMAGE_REUSEremoved from its environment (any case) and then set as the case says (cbc77c78).RX_VK_TARGET_POOL_GRACE=0(two of three age-0 images go), the idle boundary with a grace at or over the idle limit (L3), and twice the bound as the grace's ceiling (cbc77c78).texture_for_present,dead_targets_sweepandreuse_retire_frameare now cut and run (cbc77c78). A fallback source that another target drew over is neither swept nor retired while other textures are shown, and it goes once the hold ends; a null present has no source. On the PR's code this case fails: the source is swept at the next present.texture_frame's eviction pass is run too, intests/test_target_retention.pycase 3: a texture shown in the 9 presents before, its storage written over, stays, then goes; on the PR's code it is evicted. Thestatic_assertis still a source check. The hold is counted in presents, not tied to a completion signal (see L1).e88ea1b7. Images in their grace are held only while the pool is at most twice its bound (target_pool::grace_ceiling). The 600-presentrender target imagesline now gives the most the pool held over its bound after a trim since the previous line. Measuring peak pool bytes, process RAM and driver VRAM in a heavy scene and on a shared-memory device needs runs in the game; that is pending and in Still to test.render target imagescounts are cumulative, so a run's deltas are its last line minus its first; Still to test now asks for those deltas (reused, made new, reused by size, most held over the bound) next to average FPS, 1% lows, median and p99 frame times, RAM and VRAM, for Kokiri Forest and a heavy area on the Tier 1 systems.RX_VK_IMAGE_REUSE=0a grace-only control, and the description says the hold stays on.RX_VK_TARGET_POOL_MB's row now describes it as the trim's bound, which the grace may keep up to twice for a few presents.RX_VK_TARGET_POOL_GRACE's row gives the clamp underRX_VK_POOL_IDLEand says it is read at the first trim while VRAM is not short.RX_VK_IMAGE_REUSE=0's row says the present's hold stays (e88ea1b7).docs/dev/reference/switches.mdhas no rows for the pool's switches.Checked on this PC at the head
e88ea1b7(mainf1f2dc5b), through the job queue (fb-1996-1tofb-1996-3,fb-1993-base): the test commit's checks fail on the PR's code and pass at the head; of the 205 checks--changedpicks, the 52 that fail also fail on main @f1f2dc5b;vk_texture.cppandvk_replay.cppcompiled with the game build's own commands. The description's Summary, Testing and Risks are updated. Not run in the game on this PC yet.@Beanstalk This changes the render target pool (gpu/vk): an image put in the pool in the last 4 presents (RX_VK_TARGET_POOL_GRACE) is not counted out by the pool's bound, so targets of the same shapes are reused instead of destroyed and made new while the camera turns, and the image the present shows is never pooled at once. RX_VK_IMAGE_REUSE, a kill switch on by default, turns the grace off with RX_VK_IMAGE_REUSE=0 (the present's image stays held). It has not run in the game on these PCs yet. Please play Kokiri Forest for three minutes turning the camera around, after a minute's warm-up, the PR against main on the same PC, on the PR's side with the switch unset and with RX_VK_IMAGE_REUSE=0, with a picture compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture, no crash, device lost or FATAL line; peak VRAM about main's; unset, more render target images reused and fewer made new in the log's render target images line than with it off, and frame time p99 equal to main's or better. Please report that line's counts.
@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.Description only (no push): Risks now says the grace's ceiling of twice the bound is provisional, not from a measurement, and its worst case: one more bound of render-target images after a trim than main's trim allows (the bound is RX_VK_TARGET_POOL_MB, else a twelfth of the VRAM the driver allows, 256 to 768 MB: 256 to 768 MB more by default) for up to the grace's 4 presents, not while VRAM is short. Still to test names the in-game VRAM peak against main as the run that settles it.
Description corrected (Testing; no push, the head is still
e88ea1b7). 33 of the 52 checks it counted as failing on main as well were renderer checks that had not compiled, at the head or on main: this PC's run had no Vulkan headers, and under--strictthey stopped atnot found: vulkan_headers. Run again with the headers (RX_CPMset,--strict, 20 min per check) in build jobfb-vkfix-1ate88ea1b7and on main @f1f2dc5b: 18 pass here and on main, 15 fail on main too with the headers found. None fails only at this head. The per-check list is in Testing.Verdict: Comment. I'd approve this once it is out of WIP and the farm run is in. The grace is a small, bounded change to the trim that leaves the pooling points alone, every BeanBot point is fixed in the code and has a test that fails without the fix, and the hold on the present's source closes a real lifetime gap (on main,
texture_frameruns betweentexture_for_presentandpresent_image, so a stale fallback source could be evicted before the window copied it). What's left is the in-game run, and the VRAM peak it reports against main matters most.For a player: fewer render-target images destroyed and made again while the camera turns, which should mean less work on the presenting thread. The cost is up to one more pool bound of VRAM (256 to 768 MB by default) while it does that. The gain isn't measured yet.
Reviewed:
e88ea1b7againstf1f2dc5b(the merge base). Read in full where they changed:gpu/vk/vk_texture.cpp(pool_trim,image_reuse_on,pool_grace,texture_for_present,dead_targets_sweep,reuse_retire_frame, the eviction pass and the 600-present line),gpu/vk/vk_texture.h,gpu/vk/target_pool.h,gpu/vk/dead_targets.h,gpu/vk/vk_replay.cpp(do_presentup topresent_image), thegpu/vk/switches.defrows,tests/test_target_pool_grace.py,tests/test_target_retention.cppandtests/test_target_reuse_memory.py. Also read the code they rely on:destroy_later,pool_put,pool_take_memory,compact_step's source check and the ASTC reuse retirement. I checked that the source-reading checks touching these functions (test_dead_targets_sweep.py,test_target_image_pool.py,test_image_reaper.py,test_mem_account.py) still find their strings. Nothing was run; this is a code review.Fixed in this review: nothing.
Checked and fine:
present_source.effective_gracekeeps the grace at the idle limit less one.destroy_lateris back to main's code.GRACE=0fails if thegrace &&test is dropped.texture_for_present, sweep and retirement are cut from the source and run, and retention case 3 runs the eviction pass.presentedis set beforetexture_frame'sframe_no++, so the source is released at the 9th present'stexture_frame. By then the slot fence of the present that last showed it has been waited (at mostkPresentSlotsMax= 8 slots), and thestatic_assertties the two constants together.st_pool_over_peakis written and read underpool_mu.reuse_retire_framestays a normal texture, and the eviction takes it later. Its image was copied, not shared, so nothing reads freed memory.pool_graceparses as its test says: unset or not a number gives 4, the value is clamped to 0 to 1024, and it is read once.Suggestions (the author may take or leave)
texture_for_presentanddo_present. Main addedt->output_previewanddropped_outputthere. This is more than a textual conflict. A dropped output has to go through the null path (texture_for_present(dropped_output ? nullptr : t)), so it clearspresent_sourceas L2 wanted. Theoutput_previewearly return has to setpresentedas well, or the preview's texture isn't held. Ideally rebase before the farm builds it.vk_texture.cpp:5912: the compaction hold's first pass counts a held source inhold_dead, but the main loop then skips it. It is one texture over-counted, but adding the samepresent_heldskip there keeps the two passes in step.vk_texture.cpp:4879: compaction still excludes onlypresent_source(the current present), not whatpresent_heldholds. Render targets are probably outside the compacted pool, but usingpresent_heldthere too would make "the source is held for 9 presents" true for every path.RX_VK_IMAGE_REUSE=0andRX_VK_TARGET_POOL_GRACE=0turn off the same thing. Consider keeping one: the tune switch at 0 is the kill switch.staystest checkstex == present_source. Whichever of the two lands second has to adddead_targets::present_heldto that path, or the hold has a fourth way out.Testing: no in-game run yet, on the author's PC or elsewhere. The checks pass at the head, and the author ran them against main through their job queue. CI is still pending. The farm request is open. It still needs one Windows NVIDIA run, a heavy scene and one lower-VRAM card, with the VRAM peak against main as the pass criterion. Approval waits for those runs.
Overlaps and merge order:
vk_texture.cpp/.h(texture_for_present, the dead-target paths). Either can go first, but the second needs the hold added to 2054's lazy path.texture_touch, no overlap.vk_replay.cppsiblings (2059, 2053, 2052, 2031, 2030, 2028, 1995, 1994, 759) don't touchdo_present's source line.switches.defwill conflict textually with most open PRs, as expected.@ -567,1 +594,4 @@const size_t most = (pool_pressure > 0) ? 64 : 16;// (longshot, RX_VK_IMAGE_REUSE: what came in the last presents is not counted out by the bound while the pool holds no more// than twice it, above; the grace under the idle limit. Not while VRAM is short: there RX_VK_TARGET_POOL_GRACE is not read)const uint64_t grace = image_reuse_on() && !pool_pressure ? target_pool::effective_grace(pool_grace(), idle) : 0;Each image gets at most 4 presents of grace, but the pool as a whole can sit near twice the bound for as long as new shapes keep coming in while the camera turns. Risks should say that. The farm's VRAM peak against main is the number that settles it.
@ -4926,1 +4959,4 @@// (what the present shows, held for dead_targets::kPresentHold presents from here: its window copy's frame slot comes round// again kPresentSlotsMax presents later at most. A present of nothing (t null) shows nothing: no source)static_assert(dead_targets::kPresentHold > (uint64_t)kPresentSlotsMax);Texture* texture_for_present(const nvn_tex* t) {Rebase note: main now returns early here for t->output_preview, and do_present passes null for a dropped output. Send the dropped output through texture_for_present(nullptr) so present_source is cleared (L2), and set presented on the output_preview return as well.
Beanstalk test farm · an earlier run: commit
e88ea1b(the newer results are in a comment below)Commit
e88ea1b· approved by dyst (👍 on siantm's request) (reviewed) · dashboard⚠️ Note: The PR's explicit reuse-on setting is equivalent to unset; the matrix uses 1 versus 0 because it cannot express unset as a PR-only cell.
⚠️ Note: The camera turn is 10,800 input frames, approximately three minutes at 60 fps; the farm cannot measure a segment while issuing stick inputs, so p99 and peak VRAM are measured immediately afterward, not during the turn.
⚠️ Note: Image counts are the last cumulative log values, not warm-up-subtracted deltas; the over-bound value is the maximum reported interval peak.
Started at 10:05 UTC.
Estimate: done in about 1 h 15 min, from the queue and the testers online now; some jobs can't start yet.
linux+nvidialinux+radvwindows+intelsteamdeckkokiri-camera· frame time p99 (ms)RX_VK_IMAGE_REUSE=0(reference)RX_VK_IMAGE_REUSE=1linux+nvidialinux+radvwindows+intelsteamdeckWhy it failed
linux+nvidia:kokiri-camera · RX_VK_IMAGE_REUSE=0 (PR only)screenshot.max_diff:limit 0.0linux+nvidia:kokiri-camera · RX_VK_IMAGE_REUSE=1 (PR only)screenshot.max_diff:limit 0.0linux+nvidia:kokiri-camera · RX_VK_IMAGE_REUSE=1 (PR only)value_made: RX_VK_IMAGE_REUSE=1 vs RX_VK_IMAGE_REUSE=0 (PR):8,200 → 8,414 (+2.6%); limit −1.0; the PR's own cells: RX_VK_IMAGE_REUSE=1 against RX_VK_IMAGE_REUSE=0 (RX_VK_IMAGE_REUSE=0 (PR only))linux+nvidia:kokiri-camera · RX_VK_IMAGE_REUSE=1 (PR only)after-turn.vram_peak_mb.max_delta_pct:5,962 → 6,910 (+15.9%); limit 10.0linux+radv:kokiri-camera · RX_VK_IMAGE_REUSE=0 (PR only)screenshot.max_diff:limit 0.0linux+radv:kokiri-camera · RX_VK_IMAGE_REUSE=1 (PR only)screenshot.max_diff:limit 0.0linux+radv:kokiri-camera · RX_VK_IMAGE_REUSE=1 (PR only)value_made: RX_VK_IMAGE_REUSE=1 vs RX_VK_IMAGE_REUSE=0 (PR):8,588 → 8,651 (+0.7%); limit −1.0; the PR's own cells: RX_VK_IMAGE_REUSE=1 against RX_VK_IMAGE_REUSE=0 (RX_VK_IMAGE_REUSE=0 (PR only))linux+radv:kokiri-camera · RX_VK_IMAGE_REUSE=1 (PR only)value_made: RX_VK_IMAGE_REUSE=1 vs RX_VK_IMAGE_REUSE=0 (PR):8,286 → 8,371 (+1.0%); limit −1.0; the PR's own cells: RX_VK_IMAGE_REUSE=1 against RX_VK_IMAGE_REUSE=0 (RX_VK_IMAGE_REUSE=0 (PR only))What was tested
What will be tested · AI plan (
gpt-6.1-terra)On Linux NVIDIA, Linux RADV, Windows Intel and Steam Deck, the plan compares main with the PR in Kokiri Forest after a one-minute warm-up and a sustained camera turn. It measures peak VRAM, frame time and render-target image counts, and compares a picture with main; crashes, device-lost or FATAL logs, picture differences, increased p99 or substantially higher VRAM fail. The PR's reuse-on and reuse-off counts are also compared. The run takes roughly 40 minutes per tester; a Windows Intel tester is not currently online, so that target will wait. No tester online now matches windows+intel: that target waits for one.
0or1(PR only).kokiri-start, then teleport to Kokiri Forest, 18 times: move the stick, take the picture forest to compare with main, measure after-turn for 5 s (after 0 s warm-up); 1 run on each side for each of 2 cells (2 game starts a run).Measurements on `linux+nvidia`, for the PR description
Verdict: fail on linux+nvidia (2 reports):
kokiri-camera screenshot.max_diff;kokiri-camera value_made: RX_VK_IMAGE_REUSE=1 vs RX_VK_IMAGE_REUSE=0 (PR) (+2.6%);kokiri-camera after-turn.vram_peak_mb.max_delta_pct (+15.9%)failed.Hardware: 1: linux+nvidia+nvidia-proprietary+dgpu
NVIDIA GeForce RTX 5070, 620.70.6AMD Ryzen 5 9600X 6-Core Processor, 32 GB RAM; 2: linux+nvidia+nvidia-proprietary+dgpuNVIDIA GeForce RTX 5080, 620.73.4AMD Ryzen 7 7800X3D 8-Core Processor, 32 GB RAMScene: kokiri-camera, from the repository's save kokiri-start; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); kokiri-camera: 1 game start a side, after-turn 5 s after 0 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)f1f2dc5e88ea1bRX_VK_IMAGE_REUSE=0 (PR only)· after-turn · peak VRAM (MB)RX_VK_IMAGE_REUSE=0 (PR only)· after-turn · frame time (p99) (ms)RX_VK_IMAGE_REUSE=0 (PR only)· forbidden log linesRX_VK_IMAGE_REUSE=1 (PR only)· after-turn · peak VRAM (MB)RX_VK_IMAGE_REUSE=1 (PR only)· after-turn · frame time (p99) (ms)RX_VK_IMAGE_REUSE=1 (PR only)· forbidden log linesFlags and settings
RX_VK_IMAGE_REUSE0,1As Markdown for the PR description:
Measurements on `linux+radv`, for the PR description
Verdict: fail on linux+radv (2 reports):
kokiri-camera screenshot.max_diff;kokiri-camera value_made: RX_VK_IMAGE_REUSE=1 vs RX_VK_IMAGE_REUSE=0 (PR) (+0.7%);kokiri-camera value_made: RX_VK_IMAGE_REUSE=1 vs RX_VK_IMAGE_REUSE=0 (PR) (+1.0%)failed.Hardware: 1: linux+amd+radv+dgpu
AMD Radeon RX 9070 XT (RADV GFX1201), 26.1.99AMD Ryzen 7 5700X3D 8-Core Processor, 32 GB RAM; 2: linux+amd+radv+dgpuAMD Radeon RX 9070 (RADV GFX1201), 26.0.8AMD Ryzen 7 5800X 8-Core Processor, 32 GB RAMScene: kokiri-camera, from the repository's save kokiri-start; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); kokiri-camera: 1 game start a side, after-turn 5 s after 0 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)f1f2dc5e88ea1bRX_VK_IMAGE_REUSE=0 (PR only)· after-turn · peak VRAM (MB)RX_VK_IMAGE_REUSE=0 (PR only)· after-turn · frame time (p99) (ms)RX_VK_IMAGE_REUSE=0 (PR only)· forbidden log linesRX_VK_IMAGE_REUSE=1 (PR only)· after-turn · peak VRAM (MB)RX_VK_IMAGE_REUSE=1 (PR only)· after-turn · frame time (p99) (ms)RX_VK_IMAGE_REUSE=1 (PR only)· forbidden log linesFlags and settings
RX_VK_IMAGE_REUSE0,1As Markdown for the PR description:
The testers' hardware
linux+nvidiaNVIDIA GeForce RTX 5070, 620.70.6AMD Ryzen 5 9600X 6-Core Processor, 32 GB RAMlinux+nvidiaNVIDIA GeForce RTX 5080, 620.73.4AMD Ryzen 7 7800X3D 8-Core Processor, 32 GB RAMlinux+radvAMD Radeon RX 9070 XT (RADV GFX1201), 26.1.99AMD Ryzen 7 5700X3D 8-Core Processor, 32 GB RAMlinux+radvAMD Radeon RX 9070 (RADV GFX1201), 26.0.8AMD Ryzen 7 5800X 8-Core Processor, 32 GB RAMRe the Test Farm's results on
e88ea1b7(summary):RX_VK_TARGET_POOL_GRACEat its default against=0: 8,200 → 8,414 (+2.6 %), where the grace was meant to make fewer; after-turn VRAM peak with the grace 5,962 → 6,910 (+15.9 %, limit 10 %);screenshot.max_diffover the limit in both cells (=0and default).screenshot.max_diffover the limit in both cells; p99 within ±2 %.The measurement goes against the grace. This pull request is on hold while the picture difference is traced: it shows with the switch at
0as well, so it comes from a part that runs either way, and a=0build should behave exactly as main. No push until that is found.Correction to my comment above: reading the four reports' logs, the grace never acted in these runs (every PR log ends "the pool let go of 0 over its bound", over-bound peak 0 MB), so the
=0/default gaps are not its doing: images made differ by +2.6, −3.3, +0.7 and +1.0 %, and the VRAM figure is one start's peak (the cell's mean fell, 5,962 → 5,877) on a tester whose two main cells differ by 8.9 %. The screenshots differ in viewpoint (the shot follows 18 rounds of right-stick input, so the end angle depends on frame timing), not in rendering. So the run neither supports nor goes against the grace; it is still unmeasured, and a run where the pool goes over its bound is what would settle it.e88ea1b701850ba5dfb5Beanstalk test farm
Commit
850ba5d· approved by nobody yet · dashboardA member of
BigBeanscan review this commit and comment@Beanstalkto test it.WIP: perf(vk): the render target pool's bound spares the images that came in the last presents (RX_VK_IMAGE_REUSE=0 to disable)to WIP: perf(vk): the render target pool's bound spares the images that came in the last presents (RX_VK_TARGET_POOL_GRACE=0 to disable)Thanks for the review (#1996 (comment)). The branch is now stacked on #2064 and has
850ba5dfas its head. The changes, point by point:e016aef5, fixa9d04a2e, on main9dd41326. Its game-free tests fail on main and pass there. The hold's parts are out of this PR's three commits, rebuilt on #2064 as4678fd3b,2e17a0e0and29a0e423.destroy_laterand the four checks that follow its signature are main's from the first commit on. This PR now changes the grace alone.a9d04a2e.do_presentcallstexture_for_present(dropped_output ? nullptr : t), so a dropped output clearspresent_source. The Output preview's return markspresentedtoo. #2064's test runs both cases.a9d04a2e. The compaction's first pass skips a held texture as the main loop does.tests/test_target_retention.cppcase 4 runs that pass: a held dead target is not counted as given back, and a live texture goes for the excess in its place.compact_stepskips whatpresent_heldholds as well aspresent_source.850ba5df.RX_VK_TARGET_POOL_GRACEis the kill switch now (kill, int, 4 by default;=0: the bound counts every image, as main).RX_VK_IMAGE_REUSEis gone from the code,switches.defand the tests.tests/test_target_pool_grace.pyruns=0and checks the table's row.dead_targets::present_heldto #2054's lazy retirement path.About the farm run on
e88ea1b7: the grace was not exercised. Every log says the pool let go of nothing over its bound, at most 0 MB over it, so the run does not measure the grace. Still to test asks for a scene that takes the pool over its bound, with the pool's own lines as the evidence.Checked on this PC, through the job queue (
dy1996a,dy1996b,dy1996c):850ba5df.tests/test_target_reuse_memory.pyfails, as it did on main @f1f2dc5b.a9d04a2eand fail at its test commit.vk_texture.cppandvk_replay.cppcompile with the game build's own commands.Not run in the game on this PC yet.
@Beanstalk This changes the render target pool's trim (gpu/vk/vk_texture.cpp, pool_trim): an image put in the pool in the last 4 presents is not counted out by the pool's bound; RX_VK_TARGET_POOL_GRACE (4 by default) sets that, and RX_VK_TARGET_POOL_GRACE=0 turns it off and gives main's trim. It is on #2064, whose commit is in its diff. The question is the VRAM peak against main. The grace only acts when the pool goes over its bound, so please use scenes that take it there: Castle Town Market from the market-entrance save, and Hyrule Field running with the camera turning, at the highest Output resolution; on a card with 6 GB or less and on a Tier 1 discrete card. Please take each picture at a fixed point with no input, right after the save settles, with one main-against-itself picture; then the PR against main on the same PC, on the PR's side with RX_VK_TARGET_POOL_GRACE unset and with it at 0, at least two starts a side, interleaved. From the game's log: the "render target images" line's "the pool let go of N over its bound" with N above 0 on main and with =0 (if N is 0, the run does not test the grace: please report that), and "at most N MB over its bound" on the PR unset. Please report images made new and reused, unset against =0, and the driver's VRAM peak against main. The same picture within main's own noise, no crash, device lost or FATAL line.
@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.