Repository navigation
Textures: staging buffers come from a pool instead of being made per texture - #781
Open
marquezinii wants to merge 1 commit into
Open
marquezinii wants to merge 1 commit into
marquezinii wants to merge 1 commit into
Conversation
…texture A title texture's staging buffer was an upload buffer made for it and released with it. On an RTX 5070 making and mapping one costs about 1.9 ms a megabyte and releasing it 1.2 more, whatever the heap flags, against 0.36 to write one already there. The pass over the heap's textures stages up to 192 MB a frame (576 MB while it catches up) on the thread that records the frame, so most of its 250-750 ms went to that. A staging buffer let go now goes back to a pool by size class (whole 64 KiB up to 1 MiB, then eighths of a power of two), and the next texture of that class takes the one given back last. With the pool full, the oldest buffer of the class holding the most bytes is released to make room: most staging buffers live a frame, so the newest are the likeliest to be asked for again. A buffer taken from the pool that the first refresh does not detile into (memory all zero, or not there yet) is zeroed, as a new one would be. The pool keeps at most VICTORY_STAGING_POOL_MB (512); 0 makes and releases every buffer as before. The memory line counts buffers made, taken from the pool, given back and released.
Contributor
Author
|
The red check is the Clippy step failing on three lints that |
ExoCalibra
added a commit
to ExoCalibra/victory-exo
that referenced
this pull request
Nov 25, 2026
clquwu
added a commit
to clquwu/leonida-ultimate
that referenced
this pull request
Nov 25, 2026
…1887) & staging pool (#781) Wave 11D fixes four d3d12_vulkan_device.cpp hot-path regressions (GPL-3.0, zero non-trivial thread_local): 1. Page-dirty-only console descriptor heap diff + AVX2/SSE2 compare: - Extend leonida::title_shadow::Shadow::refresh() (runtime/src/title_shadow_sync.h) with optional std::vector<DirtyRange>* output recording exact changed 64 KiB page slices (page index, byte offset/length, zeroed flag). - Update DeviceState::refresh_console_copy() to scan ONLY changed 64 KiB pages (instead of all 32 MiB / 1M slots when 1 page changes), skip zeroed pages on initial refresh, fast-clear aligned zeroed pages, and compare 32-byte descriptors via AVX2/SSE2 (equal_descriptor_32 / is_zero_descriptor_32) instead of scalar memcmp. 2. Eliminate uncached WC arena.mapped reads in scan_title_table & host-RAM V# bitset: - Add leonida::ConsoleHeapVsharpSlots (runtime/src/console_heap_vsharp_slots.h, adapted from ubiquitarianism/leonida#1887, author IlyassRS3) tracking live console-heap buffer V# slots in L1-resident host RAM. - Skip console heaps in scan_title_table() (already refreshed & sanitized from cached host RAM by refresh_console_heaps() in before_execute_()). - Add a 128-entry per-submission epoch span cache for layer shader-visible heaps (invalidated on before_execute_(), heap create/destroy, and arena descriptor API writes) and stream-copy cache misses from WC arena.mapped via SSE4.1 MOVNTDQA (_mm_stream_load_si128) in 64-slot chunks, writing back only modified slots. 3. Bounded LIFO size-classed texture upload staging buffer pool: - Adapted from fxceless/victory-fork#781 (GPL-3.0, author marquezinii): 256 MiB cap, 64 KiB steps up to 1 MiB then 8 steps/power-of-two, separate upload vs cached-readback buckets, LIFO reuse, fullest-class oldest eviction outside the pool lock, and clean teardown in ~Device(). Note: ubiquitarianism/leonida#1926 (TitleImagePool / vulkan_title_image_pool.h) does not apply because leonida-ultimate uses VulkanSuballocator (vulkan_suballoc.h, outside W11D file boundary). Verified (RTX 3080, VK_VALIDATION=1, 0 validation errors): - 6/6 GPU CTests passed: d3d12_vulkan_device, d3d12_xmem_shadow, d3d12_unmapped_vsharp, d3d12_subresource_copy, d3d12_console_descriptor_heap, d3d12_console_table_draw - Dirty-page scan: 1-slot write in 16-page heap scanned 1 page (2,048 / 32,768 slots); idle submit scanned 0 pages - Staging pool: 1 created / 3 reused in d3d12_unmapped_vsharp; 2 created / 38 reused in d3d12_subresource_copy - title_shadow_sync_test: 16/16 new dirty-range & ConsoleHeapVsharpSlots checks passed (84/85 total; 1 pre-existing line-139 coalesced-run split check from 8cd13ce) - check_no_game_data.py: 0 violations; test_docs_env_vars.py: 4/4 OK
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.
The pass over the heap's textures (
draw.rsheap_textures) runs on the thread that records the frame, with a budget of 250 ms and 192 MB a pass, three times that while 1,024 or more slots are due. On a Ryzen 5 5600X + RTX 5070 the queue held about 5,000 due slots for minutes, so frames sat at that budget (0.7-1.4 s) whenever it ran full.I split the pass with local counters. In the 111 heaviest lines of a run, staging was 257 ms of the median 392 ms of the texture part. Most of it was
staging()making an upload buffer for each texture (Host::upload_buffer, a committed resource and a map) and releasing it when the texture was let go a frame later. A small benchmark of 1,000 buffers / 350 MB on the 5070:D3D12_HEAP_FLAG_CREATE_NOT_ZEROEDThis change keeps those buffers in a pool:
Stagingthat is dropped gives its buffer back. The lists that recorded a copy from it hold theArcuntil they are reset, so the card is done with it by then.detilewrites every subresource (including the zeros for levels on demand), and if the first refresh does not detile at all (memory all zero, or not there yet) the buffer is zeroed, as a new one would be.VICTORY_STAGING_POOL_MB(512) caps it; 0 makes and releases every buffer as before. The diagnostics memory line counts buffers made, taken, given back and released.Measured on
310c6ebplus #95 and #665 (the remap and fetch waits hid this otherwise), diag build, Series X, 480 s runs with the same scripted input, one exe with the switch on and off:VICTORY_STAGING_POOL_MB=0The queue drained a few minutes into the world in the runs with the pool. After that the pass costs 15-40 ms a frame. Frames in the steady door scene of the prologue are bound by the card either way (about 2 fps there with these two runs), so this shows up while textures stream in, not in the steady frame. I compared the captured frames (
VICTORY_CAPTURE) of both runs at the same offsets and saw no texture with stale texels.Tests: two new unit tests (size classes; a buffer given back is taken again for its class and not for another).
cargo test --release -p victory-gpupasses, exceptinplace::tests::warp_a_title_buffer_in_place_shows_its_bytes_at_its_offset. That test also fails ona26859fwithout this change when the whole suite runs (3 of 3 runs here) and passes alone. Clippy shows no warnings in the changed files, in both CI configurations. Rebased ona26859f; levels on demand were not enabled in the measured runs.