Repository navigation
GPU: title textures the GPU writes share their heap's memory on the host - #2226
0xkn0wh3r3 wants to merge 3 commits into
Conversation
A resource placed in a heap takes its heap's residency: asked of a placed texture, SetResidencyPriority removed the device at the next submission, found merging this with host heaps shared by placed render targets (Marvisak#2226), whose heaps take the priority instead. keep_resident says so, and make_texture notes that its textures are committed.
catminou4
left a comment
There was a problem hiding this comment.
Title textures the GPU writes share their heap's host memory via aliasing (new alias.rs, +573): 9/8-scaled placement, aliasing barriers, per-list use tracking. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Ambitious memory-saving feature; aliasing correctness needs Windows hardware validation.
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):
cargo test -p victory-gpu --lib alias::— passedcargo clippy -p victory-gpu --all-targets— 0 warningscargo xtask policy— ok (184 files ok)
Clean aliasing support letting GPU-written title textures share their heap memory on the host. Looks good.
AI-assisted (Gemini 4 Neon).
|
Automated triage for the maintainers. Merge candidate (worth a look, large change). Render targets, depth and UAV textures the title places in its heaps go into one host On your reply (now in the PR body): the three questions from the last triage are answered with tests. Subresource numbering: For the maintainer: this is about 1,560 lines touching barriers and memory aliasing, tested so far on one NVIDIA card. A run on AMD and on a resource-heap tier 1 host would be worth having before merging. Generated by Claude Code |
13dd7ff to
65e0910
Compare
A resource placed in a heap takes its heap's residency: asked of a placed texture, SetResidencyPriority removed the device at the next submission, found merging this with host heaps shared by placed render targets (Marvisak#2226), whose heaps take the priority instead. keep_resident says so, and make_texture gives a priority to the textures it commits only: those it places in a heap of textures (`crate::placement`, fed from title memory) keep their heap's, the normal one.
… memory on the host) into demo
…ies, written copies, residency and the memory budget) into demo With Marvisak#2051, queued refreshes of a copy in video memory copy at once (`Shadow::copy` writes the video memory, not the mirror). With Marvisak#2226, textures in a title heap's host heap take that heap's residency priority (D3D12 gives placed resources none of their own), and Marvisak#2222's test makes its textures with no spot.
|
A note for whichever of #2222 and #2226 lands second: they merge cleanly but clash in
With both merged, #2226's |
A resource placed in a heap takes its heap's residency: asked of a placed texture, SetResidencyPriority removed the device at the next submission, found merging this with host heaps shared by placed render targets (Marvisak#2226), whose heaps take the priority instead. keep_resident says so, and make_texture gives a priority to the textures it commits only: those it places in a heap of textures (`crate::placement`, fed from title memory) keep their heap's, the normal one.
7db9d87 to
6b75e7b
Compare
Engines place short-lived render targets and unordered access textures at overlapping offsets of one heap, so passes reuse each other's memory and the heap costs the largest set alive at once. Every placed texture got a committed host texture of its own (textures of one shape at one address already shared one), so the host paid the sum of them all. A title heap now gets a host heap, made with the first such texture placed in it: 9/8 of the title heap's size, default heap type, and on resource heap tier 1 one for render targets and depth textures and one for other textures. A render target, depth or unordered access texture goes at 9/8 of its offset there when the host's size and alignment for it (GetResourceAllocationInfo, with its castable formats through GetResourceAllocationInfo3) end before 9/8 of the end of its console footprint. The scaling keeps the order of offsets, so host textures overlap only where title textures do; at the same offsets with the console footprint as the limit, full-HD and 1440p targets of 8 and 16 bytes a texel did not fit (the host lays them out about 5 % larger than the console). Textures the title fills, multisampled ones and depth textures also written through unordered access (twins) stay committed, as do those that do not fit. Overlapping host textures are aliases. A list tracks which placed texture last held each piece of a host heap: a use that takes memory a texture the list used before holds records an aliasing barrier on any resource and, for render targets and depth textures, a discard (from the list's state for it and back); a list's first use of memory is judged when the list is submitted, in submission order, against what the lists submitted before it left, and its prelude records the same. A new placed target is discarded before its first use. Where a title texture lies in its title heap is worked out from the resource alone (spot), as its host texture is made on first use. The title's aliasing barriers become aliasing barriers on any resource (they may name resources without a host texture, or committed ones), and its DiscardResource reaches the host for placed targets. A host heap goes with its title heap and the last host texture in it. Measured with an ignored test (transient_targets_video_memory, RTX 4090, DXGI video memory use), eight targets of different shapes at one offset of a heap sized for the largest: 4K: committed 304.2 MiB, in host heaps 142.4 MiB full HD: committed 80.9 MiB, in host heaps 35.9 MiB full HD one after another (nothing shared): 80.9 MiB against 88.6 MiB At the same offsets (no scaling), 6 of 8 and 5 of 8 fitted: 270.9 MiB in 4K, and 87.2 MiB in full HD, more than committed.
Render targets and textures shaders write, placed in a title heap's host heap, are used every frame: the host heap gets a high residency priority, so that when video memory runs short Windows moves them out last. The priority goes on the heap, not on the textures placed in it: asked of a placed texture, SetResidencyPriority removed the device at the next submission (seen when this branch was merged with Marvisak#2222, which gives committed textures residency priorities; neither needs the other).
A title's DiscardResource region is passed to the host as it is: the host texture has the title texture's mips and array slices, and its format the same planes (depth with stencil two, the console's 16-bit depth with stencil as float depth with stencil too). A region naming subresources past the host texture's is not passed on; the host runtime stops the process on one. Tests: title discard regions over planes, every mip and array slices of placed depth and render targets, against the host texture's plane, mip and slice counts; and two lists recorded together and submitted in the other order, whose first uses are judged in submission order.
6b75e7b to
df7d532
Compare
|
Thanks. I rebased onto 63bcca4. The head is now 1. Discard regions and subresource numbering. The numbering is the same on both sides. On the console and on D3D12, a subresource index is mip + slice × mips + plane × mips × slices. So the region means the same thing on the host if mips, slices and planes match:
While writing the test, I found that a region past the last subresource ends the process: 2. Lists recorded together, submitted in another order. The judgement against other lists happens at submission, in submission order:
If the judgement had followed record order, the second round would show a discard of a. Each target also reads back its own clear. 3. Does it need #2221 or #2222? No, it works on 4. Splitting. It splits cleanly into three PRs, and I can open them if you prefer:
The branch already keeps 3 as its own commit ( |
A resource placed in a heap takes its heap's residency: asked of a placed texture, SetResidencyPriority removed the device at the next submission, found merging this with host heaps shared by placed render targets (Marvisak#2226), whose heaps take the priority instead. keep_resident says so, and make_texture gives a priority to the textures it commits only: those it places in a heap of textures (`crate::placement`, fed from title memory) keep their heap's, the normal one.
|
Code review and RTX 5090 + WARP + D3D12 Debug Layer verification at head
Clean aliasing barrier handling and zero Debug Layer issues on both RTX 5090 and WARP; LGTM. |
With Marvisak#2121's view kinds: the read-lock fast path goes into words_for, view_at and the tests take the read or write lock, and pages taken back or remade clear their slots' ready mark (mirror's lock-free check must not pass them by). Two Marvisak#2222 tests call make_texture with Marvisak#2226's spot argument.
… of their own Marvisak#2222's guard skipped textures in upstream's heaps of textures (crate::placement) but not those Marvisak#2226 places in a title heap's host heap (crate::alias), whose heap carries the priority: asked of such a texture, SetResidencyPriority removed the device at the next submission (aliased_targets_cleared_in_turn_read_their_own_clears and every GPU test after it).
GPU: a title discard region reaches the host only inside its texture GPU: host heaps are kept resident first GPU: title textures the GPU writes share their heap's memory on the host update readme
…its update applied)
Marvisak#2908 records a prelude of plain barriers on any thread, but its shortcut also took preludes with Marvisak#2226's aliasing barrier or discards, and dropped them (aliased_targets_cleared_in_turn_read_their_own_clears: b was not discarded before the second list). Those are recorded in order, as before.
Problem
Console engines place short-lived render targets and UAV textures at overlapping offsets of one heap (
CreatePlacedResource), so passes reuse each other's memory and the heap costs only the largest set alive at once. VIctory gave every placed render target, depth and UAV texture its own committed host texture, made on its first use (Resource::host→shared_texture→make_texture). Textures with the same address and shape already shared one throughmemory_key, but differently shaped ones at overlapping offsets each got their own, so host video memory was the sum of all of them instead of the heap's size.Measured with the new ignored test
resource::tests::transient_targets_video_memory(RTX 4090, DXGIQueryVideoMemoryInfolocal usage). It uses eight transient targets of different shapes (RGBA8, R16F, R8, RGBA16F render targets, a D32 depth target, an RGBA32F UAV texture, plus half-size RGBA16F RT+UAV and R32F targets), all at offset 0 of a title heap sized for the largest:Fix (
crates/victory-gpu/src/alias.rs, new)ID3D12Heap(default heap type). It is created at the first use of the first eligible texture placed in the title heap, since host textures are made on first use. OnD3D12_RESOURCE_HEAP_TIER_1(checked withCheckFeatureSupport) there are two:ALLOW_ONLY_RT_DS_TEXTURESandALLOW_ONLY_NON_RT_DS_TEXTURES.CreatePlacedResource(orCreatePlacedResource2with its castable formats, sized byGetResourceAllocationInfo3) when the host's size and alignment fit inside its console footprint, as described below. Otherwise it is committed as before.host offset + host size <= scaled(console offset + console size).memory_keysharing is unchanged: the same address and shape still share one host texture.Aliasing rules followed
pResourceBefore/After = NULL) at that point. For RT/DS textures it also recordsDiscardResource, in RENDER_TARGET or DEPTH_WRITE, transitioning there and back from the list's state.DiscardResource(slot 0x1b8, previously ignored) is passed to the host for placed RT/DS textures whose host texture exists, together with the title's region. A texture whose host texture is not made yet needs no discard: its first use discards it.host_desckeeps the title's dimension, size, mip count and array size, and every format it changes keeps its plane count (D32S8/D24S8 and the console's D16S8, which becomes D32S8 on the host, have two planes on both; D32, D16 and colour formats one). A region naming subresources past the host texture's is not passed on, since the host runtime stops the process on one.What stays out of host heaps
These are committed as before, except textures the title fills:
Tests
placed_targets_at_overlapping_offsets_share_one_host_heap: five RT/DS/UAV textures of other shapes at overlapping offsets go into one host heap (two on tier 1) of 9/8 the title heap's size, at 9/8 of their offsets. The heap is smaller than the sum of the textures.placed_textures_that_do_not_fit_their_place_are_committed: a 16x16 target with a 4 KiB console footprint, and a texture the title fills, are not placed in the host heap; a 256x256 target is.a_host_heap_goes_with_its_title_heap_and_textures: the host heap lives while a host texture in it does, and is freed with the last one.aliased_targets_cleared_in_turn_read_their_own_clears: an RGBA8 and an RGBA16F render target at the same offset are cleared in turn through the title list'sClearRenderTargetViewand read back after each clear: A red, B green, A blue in one list, then B white in the next list. The test checks the in-list and prelude discards. With--features diagnosticsandVICTORY_D3D12_DEBUG=1it fails on any debug-layer error; it passes.lists_recorded_together_are_judged_in_the_order_they_are_submitted: lists recorded A, B and submitted B, A (then recorded B, A and submitted A, B). The test checks which texture each prelude judged first and what it found, and that each target reads its own clear.title_discard_regions_number_subresources_as_the_host_texture: placed D32S8, D24S8, D32, D16, D16S8 (console) depth arrays and RGBA8/RGBA16F render target arrays, 3 slices with every mip. Console planes, mips and slices equal the host texture's (D3D12_FEATURE_FORMAT_INFOplane count,GetDesc). It discards the last subresource and the second plane (or two slices) through the title's list, plus a region one past the end that is not passed on. It passes with the debug layer on. Without the guard, that last region ends the test process (STATUS_STACK_BUFFER_OVERRUN) with or without the debug layer.alias::tests::a_texture_takes_its_memory_and_others_keep_the_rest: the piece bookkeeping.transient_targets_video_memory(ignored): the measurement above.cargo clippy --workspace --all-targets, with and without--features victory-gpu/diagnostics, reports no warnings.cargo test --workspace --exclude victory-shader --no-fail-fastpasses, apart from two tests that fail the same way on unchangedmainon this machine:descriptor::host::tests::dynamic_slots_are_held_until_released(host view heap smaller thanHEAP_VIEWS)memory::tests::lists_share_a_table_and_copies_keep_their_viewscargo test -p victory-shader -- --test-threads=1has three hardware-only failures.victory-shaderis untouched by this change and does not depend onvictory-gpu:stride_tests::a_heap_buffer_read_by_element_takes_the_views_stridestride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zerossynthetic_tests::gathers_at_a_level_match_the_hardwareLimitations
Rebased onto 13f91ca
Resource::host→shared_texture), not inCreatePlacedResource. So a host heap is made at the first use of the first eligible texture. Where a texture lies in its title heap is worked out from the resource alone (spot).DiscardResourcereaches the host only if the texture's host texture already exists. Otherwise the first use discards it.HostTexturefieldplacementis nowaliased: Option<alias::Placement>, because upstream's heaps of textures useplacement. The constructor isHostTexture::with_alias.SetResidencyPriorityon a placed texture removed the device at the next submission.Triage follow-up
spotrefactor is now in the first commit, the second commit is only the residency priority, and the third commit adds the discard-region guard and the two tests above.mainalone: GPU: host textures are made on a title texture's first use, not with the resource #2221 was closed, superseded by upstream's host textures made on first use, andspotworks from the resource alone. GPU: render targets are demoted last, and upload-heap copies take a share of the VRAM budget #2222 is not needed either. Its only interaction is themake_texturepriority condition noted in the comments.