GPU: title textures the GPU writes share their heap's memory on the host #2226

Open
github-bot wants to merge 3 commits from github-bot/gh-2226 into main AGit
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 08:20 UTC · original
0xkn0wh3r3:gpu/placed-targets-share-host-heaps → main · +1564 −30 · 5 files · 3 commits · open

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 through memory_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, DXGI QueryVideoMemoryInfo local 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:

case before (committed) after (host heap)
3840x2160, one offset 304.2 MiB 142.4 MiB
1920x1080, one offset 80.9 MiB 35.9 MiB
1920x1080, one after another (nothing to share) 80.9 MiB 88.6 MiB

Fix (crates/victory-gpu/src/alias.rs, new)

  • Each title heap lazily gets an 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. On D3D12_RESOURCE_HEAP_TIER_1 (checked with CheckFeatureSupport) there are two: ALLOW_ONLY_RT_DS_TEXTURES and ALLOW_ONLY_NON_RT_DS_TEXTURES.
  • Eligible textures are the ones the host GPU writes: render target, depth or UAV flags (their contents are never uploaded from title memory). They must also be single-sampled and not depth+UAV (those have a writable twin).
  • Such a texture is made with CreatePlacedResource (or CreatePlacedResource2 with its castable formats, sized by GetResourceAllocationInfo3) when the host's size and alignment fit inside its console footprint, as described below. Otherwise it is committed as before.
  • Host offsets are 9/8 of title offsets, rounded up to 64 KiB, and the host heap is 9/8 of the title heap. This scaling is a change from the plain same-offset placement first planned:
    • It keeps the order of offsets, so title textures that do not overlap never overlap on the host. The fit test is host offset + host size <= scaled(console offset + console size).
    • It gives each texture an eighth more room. At the same offsets, with the console footprint as the limit, full-HD and 1440p 8- and 16-byte-per-texel targets miss by about 5 %, because the host lays them out larger than the console. Without scaling only 6/8 (4K) and 5/8 (1080p) of the targets above fitted: 270.9 MiB in 4K, and 87.2 MiB in 1080p, which is more than committed.
  • memory_key sharing is unchanged: the same address and shape still share one host texture.
  • The frame-rate log gets a "host heaps" line: heaps, their bytes, textures placed, and how many did not fit. It sits next to upstream's "heaps of textures" line, which is about the heaps for textures the title fills.

Aliasing rules followed

  • Every list tracks which placed texture last held each piece of a host heap.
    • If a use takes memory that another texture used earlier in the same list holds, the list records a null aliasing barrier (pResourceBefore/After = NULL) at that point. For RT/DS textures it also records DiscardResource, in RENDER_TARGET or DEPTH_WRITE, transitioning there and back from the list's state.
    • A list's first use of a piece of memory is judged at submission, in submission order, against what the earlier lists left. The list's prelude then records the barrier and discard.
    • A newly placed RT/DS texture is discarded before its first use.
  • The title's own barriers do not carry enough for the host (a console aliasing barrier may name resources that have no host texture, or committed ones). So title aliasing barriers become null aliasing barriers, and title 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.
    • The region's subresource numbers mean the same on the host: host_desc keeps 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.
  • A host heap is freed when the title heap is released and no host texture in it is still alive (lists hold their textures until reset).

What stays out of host heaps

These are committed as before, except textures the title fills:

  • Textures the title fills (no RT/DS/UAV flags), which keep their staging uploads. They go into upstream's placement heaps of textures when they take up to 16 MiB, and are committed otherwise.
  • Multisampled textures.
  • Depth textures that are also UAV (twins).
  • Textures whose host size or alignment does not fit their scaled place (for example, small targets the console packs into 4 KiB, or half-size UAV-only textures).
  • Any placed creation the host refuses.

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's ClearRenderTargetView and 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 diagnostics and VICTORY_D3D12_DEBUG=1 it 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_INFO plane 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-fast passes, apart from two tests that fail the same way on unchanged main on this machine:

  • descriptor::host::tests::dynamic_slots_are_held_until_released (host view heap smaller than HEAP_VIEWS)
  • memory::tests::lists_share_a_table_and_copies_keep_their_views

cargo test -p victory-shader -- --test-threads=1 has three hardware-only failures. victory-shader is untouched by this change and does not depend on victory-gpu:

  • stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride
  • stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros
  • synthetic_tests::gathers_at_a_level_match_the_hardware

Limitations

  • A host heap is 9/8 of the title heap's whole size, even when few of its textures go there or they do not overlap. Such heaps can cost up to an eighth more than their textures did committed (the "one after another" row). If a title shows this, host heaps per window of the title heap are the upgrade.
  • A title texture that overlaps another only in part, and relies on its other part surviving, loses that part: the host lays textures out its own way.
  • Shader reads through bindless view heaps that never pass through a list's state tracking are not seen by the alias tracking (they are not transitioned either).
  • Tier-1 hosts are handled by code but not exercised here (the test machine is tier 2).

Rebased onto 13f91ca

  • Host textures are now made on a title texture's first use (Resource::host → shared_texture), not in CreatePlacedResource. 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).
  • Textures the title fills now go into upstream's heaps of textures (11e9a54) when they take up to 16 MiB. Only render target, depth and UAV textures use the per-title-heap host heaps.
  • A title DiscardResource reaches the host only if the texture's host texture already exists. Otherwise the first use discards it.
  • Renamed: the HostTexture field placement is now aliased: Option<alias::Placement>, because upstream's heaps of textures use placement. The constructor is HostTexture::with_alias.
  • The second commit gives host heaps a high residency priority. It is set on the heap, not on the placed textures: SetResidencyPriority on a placed texture removed the device at the next submission.

Triage follow-up

  • Rebased onto 63bcca4. The spot refactor 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.
  • Works on main alone: #2221 was closed, superseded by upstream's host textures made on first use, and spot works from the resource alone. #2222 is not needed either. Its only interaction is the make_texture priority condition noted in the comments.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 08:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2226) `0xkn0wh3r3:gpu/placed-targets-share-host-heaps` → `main` · +1564 −30 · 5 files · 3 commits · open ## 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 through `memory_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, DXGI `QueryVideoMemoryInfo` local 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: | case | before (committed) | after (host heap) | |---|---|---| | 3840x2160, one offset | 304.2 MiB | 142.4 MiB | | 1920x1080, one offset | 80.9 MiB | 35.9 MiB | | 1920x1080, one after another (nothing to share) | 80.9 MiB | 88.6 MiB | ## Fix (`crates/victory-gpu/src/alias.rs`, new) - Each title heap lazily gets an `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. On `D3D12_RESOURCE_HEAP_TIER_1` (checked with `CheckFeatureSupport`) there are two: `ALLOW_ONLY_RT_DS_TEXTURES` and `ALLOW_ONLY_NON_RT_DS_TEXTURES`. - Eligible textures are the ones the host GPU writes: render target, depth or UAV flags (their contents are never uploaded from title memory). They must also be single-sampled and not depth+UAV (those have a writable twin). - Such a texture is made with `CreatePlacedResource` (or `CreatePlacedResource2` with its castable formats, sized by `GetResourceAllocationInfo3`) when the host's size and alignment fit inside its console footprint, as described below. Otherwise it is committed as before. - Host offsets are 9/8 of title offsets, rounded up to 64 KiB, and the host heap is 9/8 of the title heap. This scaling is a change from the plain same-offset placement first planned: - It keeps the order of offsets, so title textures that do not overlap never overlap on the host. The fit test is `host offset + host size <= scaled(console offset + console size)`. - It gives each texture an eighth more room. At the same offsets, with the console footprint as the limit, full-HD and 1440p 8- and 16-byte-per-texel targets miss by about 5 %, because the host lays them out larger than the console. Without scaling only 6/8 (4K) and 5/8 (1080p) of the targets above fitted: 270.9 MiB in 4K, and 87.2 MiB in 1080p, which is more than committed. - `memory_key` sharing is unchanged: the same address and shape still share one host texture. - The frame-rate log gets a "host heaps" line: heaps, their bytes, textures placed, and how many did not fit. It sits next to upstream's "heaps of textures" line, which is about the heaps for textures the title fills. ## Aliasing rules followed - Every list tracks which placed texture last held each piece of a host heap. - If a use takes memory that another texture used earlier in the same list holds, the list records a null aliasing barrier (`pResourceBefore/After = NULL`) at that point. For RT/DS textures it also records `DiscardResource`, in RENDER_TARGET or DEPTH_WRITE, transitioning there and back from the list's state. - A list's first use of a piece of memory is judged at submission, in submission order, against what the earlier lists left. The list's prelude then records the barrier and discard. - A newly placed RT/DS texture is discarded before its first use. - The title's own barriers do not carry enough for the host (a console aliasing barrier may name resources that have no host texture, or committed ones). So title aliasing barriers become null aliasing barriers, and title `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. - The region's subresource numbers mean the same on the host: `host_desc` keeps 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. - A host heap is freed when the title heap is released and no host texture in it is still alive (lists hold their textures until reset). ## What stays out of host heaps These are committed as before, except textures the title fills: - Textures the title fills (no RT/DS/UAV flags), which keep their staging uploads. They go into upstream's placement heaps of textures when they take up to 16 MiB, and are committed otherwise. - Multisampled textures. - Depth textures that are also UAV (twins). - Textures whose host size or alignment does not fit their scaled place (for example, small targets the console packs into 4 KiB, or half-size UAV-only textures). - Any placed creation the host refuses. ## 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's `ClearRenderTargetView` and 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 diagnostics` and `VICTORY_D3D12_DEBUG=1` it 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_INFO` plane 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-fast` passes, apart from two tests that fail the same way on unchanged `main` on this machine: - `descriptor::host::tests::dynamic_slots_are_held_until_released` (host view heap smaller than `HEAP_VIEWS`) - `memory::tests::lists_share_a_table_and_copies_keep_their_views` `cargo test -p victory-shader -- --test-threads=1` has three hardware-only failures. `victory-shader` is untouched by this change and does not depend on `victory-gpu`: - `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride` - `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` - `synthetic_tests::gathers_at_a_level_match_the_hardware` ## Limitations - A host heap is 9/8 of the title heap's whole size, even when few of its textures go there or they do not overlap. Such heaps can cost up to an eighth more than their textures did committed (the "one after another" row). If a title shows this, host heaps per window of the title heap are the upgrade. - A title texture that overlaps another only in part, and relies on its other part surviving, loses that part: the host lays textures out its own way. - Shader reads through bindless view heaps that never pass through a list's state tracking are not seen by the alias tracking (they are not transitioned either). - Tier-1 hosts are handled by code but not exercised here (the test machine is tier 2). ### Rebased onto 13f91ca - Host textures are now made on a title texture's first use (`Resource::host` → `shared_texture`), not in `CreatePlacedResource`. 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`). - Textures the title fills now go into upstream's heaps of textures (11e9a54) when they take up to 16 MiB. Only render target, depth and UAV textures use the per-title-heap host heaps. - A title `DiscardResource` reaches the host only if the texture's host texture already exists. Otherwise the first use discards it. - Renamed: the `HostTexture` field `placement` is now `aliased: Option<alias::Placement>`, because upstream's heaps of textures use `placement`. The constructor is `HostTexture::with_alias`. - The second commit gives host heaps a high residency priority. It is set on the heap, not on the placed textures: `SetResidencyPriority` on a placed texture removed the device at the next submission. ### Triage follow-up - Rebased onto 63bcca4. The `spot` refactor 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. - Works on `main` alone: #2221 was closed, superseded by upstream's host textures made on first use, and `spot` works from the resource alone. #2222 is not needed either. Its only interaction is the `make_texture` priority condition noted in the comments.
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 #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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:59:03 +00:00
Author
Owner

@⁠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 ID3D12Heap per title heap at 9/8 of their offsets (new crates/victory-gpu/src/alias.rs, make_texture in resource.rs), with null aliasing barriers and discards tracked per list and judged at submission (host.rs). Title aliasing barriers become null aliasing barriers and title DiscardResource (0x1b8, list.rs discard) is forwarded for placed RT/DS textures. The measured saving is large (304 -> 142 MiB at 4K in transient_targets_video_memory). CI check passes 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_texture covers planar D32S8/D24S8/D16S8, mips and arrays, and alias::region_fits drops 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 on main without #2221/#2222, with the make_texture priority 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

**@⁠Marvisak** on GitHub · 2026-11-25 13:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2226#issuecomment-7163868590) · edited 2026-11-26 00:22 UTC <!-- victory-triage v1 head=df7d53222c63acd1bef6cb64ae7f7374c95a473f verdict=merge-candidate at=2026-11-26T00:22:49Z --> 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 `ID3D12Heap` per title heap at 9/8 of their offsets (new `crates/victory-gpu/src/alias.rs`, `make_texture` in `resource.rs`), with null aliasing barriers and discards tracked per list and judged at submission (`host.rs`). Title aliasing barriers become null aliasing barriers and title `DiscardResource` (0x1b8, `list.rs` `discard`) is forwarded for placed RT/DS textures. The measured saving is large (304 -> 142 MiB at 4K in `transient_targets_video_memory`). CI `check` passes 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_texture` covers planar D32S8/D24S8/D16S8, mips and arrays, and `alias::region_fits` drops 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 on `main` without #2221/#2222, with the `make_texture` priority 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](https://claude.ai/code)_
Author
Owner

@⁠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.

  • #2222 gives every texture that isn't in a heap of textures (placement.is_none()) its own residency priority.
  • #2226 places GPU-written title textures in the title heap's host heap (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_clears and placed_targets_at_overlapping_offsets_share_one_host_heap fail, as does upstream's only_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 fourth make_texture argument (None) once #2226 is in. I'll make both changes in whichever branch lands second.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 20:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/2226#issuecomment-7174396766) 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. - #2222 gives every texture that isn't in a heap of textures (`placement.is_none()`) its own residency priority. - #2226 places GPU-written title textures in the title heap's host heap (`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_clears` and `placed_targets_at_overlapping_offsets_share_one_host_heap` fail, as does upstream's `only_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 fourth `make_texture` argument (`None`) once #2226 is in. I'll make both changes in whichever branch lands second.
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-26 00:13 UTC · original

Thanks. I rebased onto 63bcca4. The head is now df7d5322, in three commits: 66ac5e1a places host textures in host heaps (with alias tracking, the barrier change and discard forwarding), fcf07a41 adds the residency priority, and df7d5322 follows 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:

  • Mips and slices. host_desc (resource.rs:1131) copies the title description and changes only layout, alignment, flags and format. Dimension, width, height, DepthOrArraySize and MipLevels stay the title's. A mip count of 0 resolves to the full chain on both sides, by the same formula (mip_count resource.rs:301 and the console layout library's Texture::new).
  • Planes. The console layout gives formats 19–22, 44–47 and 118–120 a stencil plane (victory-formats texture.rs:763, :766), and every other format one plane. host_desc changes the format in only three ways, and each keeps the plane count:
    • pc_format 118–120 → 20–22 (98c654b). Two planes before, two after.
    • The typeless map in DEPTH_FORMATS: 20→19 and 45→44 have two planes, 40→39 and 55→53 one.
    • sRGB UAV → the format's family: colour, one plane.
  • Shared host textures. A host texture shared through 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.

df7d5322 adds title_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 from D3D12_FEATURE_FORMAT_INFO, mips and slices from GetDesc. It then discards the last subresource and the whole second plane (or two slices) through the title list. It passes, also under --features diagnostics with VICTORY_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 if alias::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:

  • At record time (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 with recorded = false, and nothing global is read or written.
  • At submission, Host::execute (host.rs:1159) runs under the submitted lock. It builds each list's prelude in the order the lists go to ExecuteCommandLists (host.rs:1249). prelude calls alias::at_submission (host.rs:1952, alias.rs:573), which judges each pending event against the host heap's held. held holds what the lists submitted before left. After judging, at_submission updates held with what this list leaves.
  • Single host queue. Every title queue's work reaches Host::execute through 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.
  • The list's own events can't skew the judgement. An event with recorded = false overlaps none of the list's earlier events. So when at_submission updates held with the list's own earlier events, that can't change how the later events are judged.

df7d5322 adds lists_recorded_together_are_judged_in_the_order_they_are_submitted, using two aliased render targets:

  • Lists recorded a, b and submitted b, a are judged as b first (new memory: discard, no barrier), then a (b held it: barrier and discard).
  • Lists then recorded b, a and submitted a, b are judged as a first (its own memory: nothing), then b (a held it: barrier and discard).

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 main alone. #2221 was closed, superseded by a7381ed (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 needs placement.is_none() && aliased.is_none() in make_texture, as noted in my earlier comment. I reworded the residency commit (fcf07a41) so it no longer claims a dependency on either PR. Here, on 63bcca4, cargo test -p victory-gpu --lib passes 236 tests. The two that fail, descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views, fail the same way on unchanged main on this machine. Clippy reports no warnings with and without diagnostics, and cargo xtask policy passes.

4. Splitting. It splits cleanly into three PRs, and I can open them if you prefer:

  1. Host-heap placement with its own alias tracking: alias.rs without keep_resident, spot/shares_heap/make_texture in resource.rs, and HostList::track plus the prelude in host.rs. The tracking can't be split off: without it, placed aliases would go without barriers and discards.
  2. Title barrier and discard forwarding (about 60 lines in list.rs, plus region_fits and the discard test): aliasing barriers become barriers on any resource, and DiscardResource (0x1b8) is forwarded. PR 1 doesn't depend on it, because its own tracking already records the barriers and discards that placement needs.
  3. Residency priority on host heaps (keep_resident, about 25 lines).

The branch already keeps 3 as its own commit (fcf07a41).

**@⁠0xkn0wh3r3** on GitHub · 2026-11-26 00:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2226#issuecomment-7178524432) Thanks. I rebased onto 63bcca4. The head is now `df7d5322`, in three commits: `66ac5e1a` places host textures in host heaps (with alias tracking, the barrier change and discard forwarding), `fcf07a41` adds the residency priority, and `df7d5322` follows 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: - **Mips and slices.** `host_desc` (resource.rs:1131) copies the title description and changes only layout, alignment, flags and format. Dimension, width, height, `DepthOrArraySize` and `MipLevels` stay the title's. A mip count of 0 resolves to the full chain on both sides, by the same formula (`mip_count` resource.rs:301 and the console layout library's `Texture::new`). - **Planes.** The console layout gives formats 19–22, 44–47 and 118–120 a stencil plane (victory-formats texture.rs:763, :766), and every other format one plane. `host_desc` changes the format in only three ways, and each keeps the plane count: - `pc_format` 118–120 → 20–22 (98c654b). Two planes before, two after. - The typeless map in `DEPTH_FORMATS`: 20→19 and 45→44 have two planes, 40→39 and 55→53 one. - sRGB UAV → the format's family: colour, one plane. - **Shared host textures.** A host texture shared through `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. `df7d5322` adds `title_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 from `D3D12_FEATURE_FORMAT_INFO`, mips and slices from `GetDesc`. It then discards the last subresource and the whole second plane (or two slices) through the title list. It passes, also under `--features diagnostics` with `VICTORY_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 if `alias::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: - **At record time** (`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 with `recorded = false`, and nothing global is read or written. - **At submission**, `Host::execute` (host.rs:1159) runs under the `submitted` lock. It builds each list's prelude in the order the lists go to `ExecuteCommandLists` (host.rs:1249). `prelude` calls `alias::at_submission` (host.rs:1952, alias.rs:573), which judges each pending event against the host heap's `held`. `held` holds what the lists submitted before left. After judging, `at_submission` updates `held` with what this list leaves. - **Single host queue.** Every title queue's work reaches `Host::execute` through 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. - **The list's own events can't skew the judgement.** An event with `recorded = false` overlaps none of the list's earlier events. So when `at_submission` updates `held` with the list's own earlier events, that can't change how the later events are judged. `df7d5322` adds `lists_recorded_together_are_judged_in_the_order_they_are_submitted`, using two aliased render targets: - Lists recorded a, b and submitted b, a are judged as b first (new memory: discard, no barrier), then a (b held it: barrier and discard). - Lists then recorded b, a and submitted a, b are judged as a first (its own memory: nothing), then b (a held it: barrier and discard). 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 `main` alone. #2221 was closed, superseded by a7381ed (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 needs `placement.is_none() && aliased.is_none()` in `make_texture`, as noted in my earlier comment. I reworded the residency commit (`fcf07a41`) so it no longer claims a dependency on either PR. Here, on 63bcca4, `cargo test -p victory-gpu --lib` passes 236 tests. The two that fail, `descriptor::host::tests::dynamic_slots_are_held_until_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views`, fail the same way on unchanged `main` on this machine. Clippy reports no warnings with and without `diagnostics`, and `cargo xtask policy` passes. **4. Splitting.** It splits cleanly into three PRs, and I can open them if you prefer: 1. **Host-heap placement with its own alias tracking:** `alias.rs` without `keep_resident`, `spot`/`shares_heap`/`make_texture` in `resource.rs`, and `HostList::track` plus the prelude in `host.rs`. The tracking can't be split off: without it, placed aliases would go without barriers and discards. 2. **Title barrier and discard forwarding** (about 60 lines in `list.rs`, plus `region_fits` and the discard test): aliasing barriers become barriers on any resource, and `DiscardResource` (0x1b8) is forwarded. PR 1 doesn't depend on it, because its own tracking already records the barriers and discards that placement needs. 3. **Residency priority on host heaps** (`keep_resident`, about 25 lines). The branch already keeps 3 as its own commit (`fcf07a41`).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 00:38 UTC · original

Code review and RTX 5090 + WARP + D3D12 Debug Layer verification at head df7d53222c63 merged cleanly onto main (63bcca43c6a0):

  • Code review: Each title heap scales by 9/8 for host ID3D12Heap creation (split into RT/DS vs non-RT/DS heaps on Resource Heap Tier 1, with D3D12_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_submission prelude injection) paths emit D3D12_RESOURCE_BARRIER_TYPE_ALIASING barriers and transition RT/DS targets before DiscardResource, and title DiscardResource forwarding validates plane/mip/slice bounds via alias::region_fits.
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1, Rust 1.98.1):
    • RTX 5090 (alias:: draw::tests resource::tests twin::tests): 47/47 passed, 1 ignored (transient_targets_video_memory), 0 D3D12 Debug Layer warnings/errors
    • WARP (--features diagnostics, same filter): 47/47 passed, 1 ignored, 0 D3D12 Debug Layer warnings/errors
    • cargo 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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 00:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2226#issuecomment-7178968822) Code review and RTX 5090 + WARP + D3D12 Debug Layer verification at head `df7d53222c63` merged cleanly onto `main` (`63bcca43c6a0`): - **Code review**: Each title heap scales by `9/8` for host `ID3D12Heap` creation (split into RT/DS vs non-RT/DS heaps on Resource Heap Tier 1, with `D3D12_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_submission` prelude injection) paths emit `D3D12_RESOURCE_BARRIER_TYPE_ALIASING` barriers and transition RT/DS targets before `DiscardResource`, and title `DiscardResource` forwarding validates plane/mip/slice bounds via `alias::region_fits`. - **Verified (Windows 11, NVIDIA RTX 5090 + WARP, `VICTORY_D3D12_DEBUG=1`, Rust 1.98.1)**: - RTX 5090 (`alias:: draw::tests resource::tests twin::tests`): **47/47 passed**, 1 ignored (`transient_targets_video_memory`), **0 D3D12 Debug Layer warnings/errors** - WARP (`--features diagnostics`, same filter): **47/47 passed**, 1 ignored, **0 D3D12 Debug Layer warnings/errors** - `cargo 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.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2226/head:github-bot/gh-2226'
git switch 'github-bot/gh-2226'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2226'
git switch 'github-bot/gh-2226'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2226'
git switch 'github-bot/gh-2226'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2226'
git switch 'main'
git merge --squash 'github-bot/gh-2226'
git switch 'main'
git merge --ff-only 'github-bot/gh-2226'
git switch 'main'
git merge 'github-bot/gh-2226'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2226
No description provided.