GPU: title textures the GPU writes share their heap's memory on the host #2226
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2226
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2226"
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?
@0xkn0wh3r3 on GitHub · 2026-11-25 08:20 UTC · original
0xkn0wh3r3:gpu/placed-targets-share-host-heaps→main· +1564 −30 · 5 files · 3 commits · openProblem
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
13f91caResource::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).11e9a54) when they take up to 16 MiB. Only render target, depth and UAV textures use the per-title-heap host heaps.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
63bcca4. Thespotrefactor 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: #2221 was closed, superseded by upstream's host textures made on first use, andspotworks from the resource alone. #2222 is not needed either. Its only interaction is themake_texturepriority condition noted in the comments.@Marvisak on GitHub · 2026-11-25 13:30 UTC · original · edited 2026-11-26 00:22 UTC
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
ID3D12Heapper title heap at 9/8 of their offsets (newcrates/victory-gpu/src/alias.rs,make_textureinresource.rs), with null aliasing barriers and discards tracked per list and judged at submission (host.rs). Title aliasing barriers become null aliasing barriers and titleDiscardResource(0x1b8,list.rsdiscard) is forwarded for placed RT/DS textures. The measured saving is large (304 -> 142 MiB at 4K intransient_targets_video_memory). CIcheckpasses and it merges cleanly.On your reply (now in the PR body): the three questions from the last triage are answered with tests. Subresource numbering:
title_discard_regions_number_subresources_as_the_host_texturecovers planar D32S8/D24S8/D16S8, mips and arrays, andalias::region_fitsdrops a region past the host texture before it reaches the host. Submission order:lists_recorded_together_are_judged_in_the_order_they_are_submitted. Works onmainwithout #2221/#2222, with themake_texturepriority condition to fix in whichever of #2222/#2226 lands second.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
@0xkn0wh3r3 on GitHub · 2026-11-25 20:56 UTC · original
A note for whichever of #2222 and #2226 lands second: they merge cleanly but clash in
make_texture. I found this merging all my open PRs together.placement.is_none()) its own residency priority.aliased), so they aren't committed either. Setting a priority on a placed resource isn't allowed: it takes its heap's priority, which #2226 already sets on its host heaps.With both merged, #2226's
aliased_targets_cleared_in_turn_read_their_own_clearsandplaced_targets_at_overlapping_offsets_share_one_host_heapfail, as does upstream'sonly_textures_fed_from_title_memory_are_given_up. The fix is one condition:if placement.is_none() && aliased.is_none(). #2222's new test also needs the fourthmake_textureargument (None) once #2226 is in. I'll make both changes in whichever branch lands second.@0xkn0wh3r3 on GitHub · 2026-11-26 00:13 UTC · original
Thanks. I rebased onto
63bcca4. The head is nowdf7d5322, in three commits:66ac5e1aplaces host textures in host heaps (with alias tracking, the barrier change and discard forwarding),fcf07a41adds the residency priority, anddf7d5322follows up on this triage.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:
host_desc(resource.rs:1131) copies the title description and changes only layout, alignment, flags and format. Dimension, width, height,DepthOrArraySizeandMipLevelsstay the title's. A mip count of 0 resolves to the full chain on both sides, by the same formula (mip_countresource.rs:301 and the console layout library'sTexture::new).host_descchanges the format in only three ways, and each keeps the plane count:pc_format118–120 → 20–22 (98c654b). Two planes before, two after.DEPTH_FORMATS: 20→19 and 45→44 have two planes, 40→39 and 55→53 one.memory_key(resource.rs:1202) has equal dimension, size, array size and counted mips.takes(resource.rs:1333) also requires the same format family, and depth textures have no castable list. So a title texture never gets a host texture with another plane count.df7d5322addstitle_discard_regions_number_subresources_as_the_host_texture. It places D32S8, D24S8, D32, D16 and the console's D16S8 depth arrays, plus RGBA8 and RGBA16F render target arrays, each with 3 slices and every mip (7). For each one it checks that the console's planes, mips and slices equal the host texture's: plane count fromD3D12_FEATURE_FORMAT_INFO, mips and slices fromGetDesc. It then discards the last subresource and the whole second plane (or two slices) through the title list. It passes, also under--features diagnosticswithVICTORY_D3D12_DEBUG=1.While writing the test, I found that a region past the last subresource ends the process:
STATUS_STACK_BUFFER_OVERRUN, with or without the debug layer. A title can't produce one for its own texture, given the above. Still,discard(list.rs:599) now passes a region on only ifalias::region_fits(alias.rs:446) confirms it lies inside the host texture's planes × mips × slices. Otherwise it skips the discard, which is always safe. The test covers that case.2. Lists recorded together, submitted in another order. The judgement against other lists happens at submission, in submission order:
ListAliases::use_texture, alias.rs:539), a list compares a use only against its own earlier uses. That state is per list and cleared on reset. A use that touches none of the list's earlier memory is stored as an event withrecorded = false, and nothing global is read or written.Host::execute(host.rs:1159) runs under thesubmittedlock. It builds each list's prelude in the order the lists go toExecuteCommandLists(host.rs:1249).preludecallsalias::at_submission(host.rs:1952, alias.rs:573), which judges each pending event against the host heap'sheld.heldholds what the lists submitted before left. After judging,at_submissionupdatesheldwith what this list leaves.Host::executethrough the hold queue (queue.rs:127, :210). So "submission order" is the order the host queue runs the lists, even when the hold queue runs one queue's list ahead of another's.recorded = falseoverlaps none of the list's earlier events. So whenat_submissionupdatesheldwith the list's own earlier events, that can't change how the later events are judged.df7d5322addslists_recorded_together_are_judged_in_the_order_they_are_submitted, using two aliased render targets: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
mainalone. #2221 was closed, superseded bya7381ed(host textures made on first use). The branch already builds on that:spot(resource.rs:1310) works out a texture's place from the resource alone, and the host heap is made at the first use of the first eligible texture. #2222 is only an interaction: whichever of the two lands second needsplacement.is_none() && aliased.is_none()inmake_texture, as noted in my earlier comment. I reworded the residency commit (fcf07a41) so it no longer claims a dependency on either PR. Here, on63bcca4,cargo test -p victory-gpu --libpasses 236 tests. The two that fail,descriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views, fail the same way on unchangedmainon this machine. Clippy reports no warnings with and withoutdiagnostics, andcargo xtask policypasses.4. Splitting. It splits cleanly into three PRs, and I can open them if you prefer:
alias.rswithoutkeep_resident,spot/shares_heap/make_textureinresource.rs, andHostList::trackplus the prelude inhost.rs. The tracking can't be split off: without it, placed aliases would go without barriers and discards.list.rs, plusregion_fitsand the discard test): aliasing barriers become barriers on any resource, andDiscardResource(0x1b8) is forwarded. PR 1 doesn't depend on it, because its own tracking already records the barriers and discards that placement needs.keep_resident, about 25 lines).The branch already keeps 3 as its own commit (
fcf07a41).@fuzeofficlal on GitHub · 2026-11-26 00:38 UTC · original
Code review and RTX 5090 + WARP + D3D12 Debug Layer verification at head
df7d53222c63merged cleanly ontomain(63bcca43c6a0):9/8for hostID3D12Heapcreation (split into RT/DS vs non-RT/DS heaps on Resource Heap Tier 1, withD3D12_RESIDENCY_PRIORITY_HIGH), placing only 1x writable textures with no pending content upload whose host size/alignment fits[scaled(offset), scaled(offset + room))and safely falling back to committed resources otherwise. Both intra-list (ListAliases::use_texture) and cross-list (at_submissionprelude injection) paths emitD3D12_RESOURCE_BARRIER_TYPE_ALIASINGbarriers and transition RT/DS targets beforeDiscardResource, and titleDiscardResourceforwarding validates plane/mip/slice bounds viaalias::region_fits.VICTORY_D3D12_DEBUG=1, Rust 1.98.1):alias:: draw::tests resource::tests twin::tests): 47/47 passed, 1 ignored (transient_targets_video_memory), 0 D3D12 Debug Layer warnings/errors--features diagnostics, same filter): 47/47 passed, 1 ignored, 0 D3D12 Debug Layer warnings/errorscargo xtask policy:192 files ok;cargo clippy --locked -p victory-gpu --tests -- -D warnings(default +--features diagnostics): 0 warnings.Clean aliasing barrier handling and zero Debug Layer issues on both RTX 5090 and WARP; LGTM.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.