Skip to content

GPU: streamed textures take video memory only for the levels the title holds (opt-in; 0.4-1.4 GB less on current main) - #2389

Open
desplmfao wants to merge 8 commits into
Marvisak:mainfrom
desplmfao:perf/texture-levels-on-demand
Open

desplmfao wants to merge 8 commits into
Marvisak:mainfrom
desplmfao:perf/texture-levels-on-demand

Conversation

@desplmfao

Copy link
Copy Markdown
Contributor

Problem

Every host texture takes video memory for all its mip levels, including the levels the title hasn't streamed in yet. In Grand Theft Auto VI's world that is gigabytes of memory nothing reads: the title's streaming holds most textures at their small levels, and the large ones arrive later or never. It's a large part of why the world doesn't fit a 12 GB card.

Change

Opt-in, with VICTORY_LEVELS_ON_DEMAND=1. It needs tiled resources tier 2 or higher.

  • Which textures. A placed or streamed 2D title texture, one layer, of at least 1 MiB (VICTORY_LEVELS_MIN_KB), that is not a render target, depth or unordered-access texture, gets a reserved host texture (CreateReservedResource, or CreateReservedResource2 when it needs castable formats).
  • Which levels get memory. Only the levels whose title memory is committed get tiles, at the staging refresh that uploads them (UpdateTileMappings). Small levels that share the packed tail go together. The tiles come from a pool of 64 MiB heaps (tiles.rs).
  • Levels without tiles read as zeros. That is what main's upload of unmapped title memory already gives, so the picture doesn't change.
  • Host writes. Before the host GPU writes a reserved texture (copy, resolve, alias copy), host_written gives it every level first.
  • Status. A line next to the host textures line shows the textures alive, the MB given, the MB not allocated, and the UpdateTileMappings calls.

Measured

Grand Theft Auto VI Series X 1.0.2.1, the first mission's prison yard. RTX 5080 on Linux, Proton with vkd3d-proton 3.2.0, on our stack (this PR plus other open PRs). Same exe, with the switch off and on:

switch off switch on
Video memory in use (whole card) ~14.5 GB ~9.5 GB
Levels not allocated – 3.9–4.6 GB
Frame time, same phase of the scene ~1,100–1,200 ms ~1,100–1,230 ms early, 946 settled
Picture – identical
  • Cost. The texture side (staging refresh including the held-level checks and UpdateTileMappings) costs about 1 ms per frame. There were 140 UpdateTileMappings calls in all, about 0.25 ms in total, and none after streaming settled. The rest of the frame-time spread is the scene's own streaming, which looks the same with the switch off.
  • Not tried: native Windows, and AMD. Under vkd3d-proton, UpdateTileMappings becomes sparse binding, and that path is what I measured.

How it was found

507KAZ (who doesn't use GitHub; shared with permission) tuned fxceless/victory-fork on an RTX 4070 12 GB with 16 GB of RAM to get the world running. Of the fork's memory switches, this one made the difference: about 2.2–3.0 GB freed on his card. The mechanism is fxceless's (tiles.rs in fxceless/victory-fork at 9376fd6), ported onto main's texture design.

Differences from the fork:

The measurement above is ours.

Related

Tested

  • cargo test -p victory-gpu --lib --features diagnostics tiles:: (Windows build under Proton, RTX 5080): 4 passed. This includes the GPU test levels_take_tiles_when_given_and_give_them_back, which gives tiles to levels of a real reserved texture.
  • texture::: 3 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings, with and without --features diagnostics: clean.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

desplmfao and others added 2 commits November 25, 2026 07:30
…vel (opt-in)

With VICTORY_LEVELS_ON_DEMAND=1, a placed or streamed 2D title texture of
1 MiB or more (no render target, depth or unordered access) gets a
reserved host texture. Only the mip levels whose title memory is
committed get tiles, from a pool of 64 MiB heaps, through
UpdateTileMappings at the staging refresh that uploads them. Levels the
title has not streamed in take no video memory; they read as zeros, as
upstream's upload of unmapped memory already gives. Needs tiled
resources tier 2.

In Grand Theft Auto VI's world (RTX 5080, Linux, Proton, vkd3d-proton
3.2.0), the same exe with the switch off and on: about 14.5 GB of video
memory in use against about 9.5 GB, about 3.9-4.6 GB of levels not
allocated, the same picture, and no measurable frame time (the texture
side costs about 1 ms a frame).

The mechanism is fxceless/victory-fork's (tiles.rs at 9376fd6), ported
onto main's texture design. Based on work by 507KAZ, who found it is the
switch that makes the title fit a 12 GB card.

Co-Authored-By: fxceless <36782933+fxceless@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cked mips)

CI's adapter packs no mips for the 2048x2048 BC1 test texture, so giving
the 1x1 level gives only that level. The test expected the packed tail on
every host; it now expects either.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Streamed textures take video memory only for the levels the title maps (tiles module, +868). 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. Large feature: tiled resource wiring with queue-ordered tile mappings. Needs hardware validation.

@DrDarkDK

Copy link
Copy Markdown

I ran levels_take_tiles_when_given_and_give_them_back at 0db32bd on native Windows with an RTX 4070 Ti (621.01, tiled resources tier 4) and WARP (tier 3).

Both adapters passed with the debug layer off. With VICTORY_D3D12_DEBUG=1, both reached the final mapping step, then the test process exited with code 2173 before reporting a result. I added a test-only queue wait by submitting an empty list through host.execute before dropping the tiled texture. With that wait, the test passed on both adapters with the debug layer enabled.

Could the fixture wait for the mapping work before teardown? This checks synthetic tile mappings and their cleanup. It doesn’t measure streaming or VRAM savings in the title.

AI-assisted with Codex.

Found by DrDarkDK: with the D3D12 debug layer on (VICTORY_D3D12_DEBUG=1),
levels_take_tiles_when_given_and_give_them_back dropped the tiled texture
while its UpdateTileMappings were still queued, and the test process exited
with code 2173. An empty submission now waits for them first. The title is
not affected: Tiled::give runs only while uploading for a list, and that list
holds the texture past the mappings queued ahead of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@desplmfao

Copy link
Copy Markdown
Contributor Author

@DrDarkDK thanks, that was a real gap in the fixture. Fixed in 8c896eb, the way you suggested: an empty submission through host.execute, which submits and waits, now runs before the tiled texture is dropped. That way the queued UpdateTileMappings are done before the heaps go back to the pool.

I also checked whether the title can hit the same thing, and it can't. Tiled lives inside the host texture, and Tiled::give only runs while uploading for a list (texture.rs). That list keeps the texture alive, and its mappings are queued on the same queue ahead of it, so in the game the heaps never go back while a mapping is pending. Only the test dropped the texture right after mapping.

On the RTX 5080 under Wine with vkd3d-proton, tiles:: gives 4 passed, and clippy is clean. I couldn't reproduce the debug-layer exit here, since there's no D3D12 debug layer under vkd3d. A rerun on your 4070 Ti with VICTORY_D3D12_DEBUG=1 would confirm it.

desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
…el (VICTORY_LEVELS_ON_DEMAND)

# Conflicts:
#	crates/victory-gpu/src/texture.rs
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
…#2389 merge

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
…EVELS_ON_DEMAND in the run command

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pickles976

Copy link
Copy Markdown

Independent RTX 4060 Laptop / Wine check of 8c896ebb1650d1575fee2a1689a03804e4e04a83, including the mapping-wait fixture fix. The initial test runs used an isolated, unmodified copy of this exact head, not our title integration tree.

Tested

  • RTX 4060 Laptop, 8 GiB VRAM; Intel i7-13620H; 16 GiB system RAM; NVIDIA 590.48.01; Linux 6.17.0-40-generic; Wine 11.0, DXVK 3.1.1-209, stock vkd3d-proton 3.2.0 (2576c0b4adfae4a). Rust 1.98.1, debug, Windows MSVC cross-build with Wine as the Cargo runner; VICTORY_ADAPTER=nvidia.
  • Commands after configuring the Windows SDK linker environment:
    cargo +1.98.1 test --locked --target x86_64-pc-windows-msvc -p victory-gpu --lib --features diagnostics tiles:: -- --test-threads=1 --nocapture
    cargo +1.98.1 test --locked --target x86_64-pc-windows-msvc -p victory-gpu --lib --features diagnostics texture:: -- --test-threads=1 --nocapture
    Results: 4 passed / 0 failed / 0 ignored, then 3 passed / 0 failed / 0 ignored.
  • To rule out the GPU fixture's silent early-return paths, I separately replaced only its missing-host and insufficient-tier returns with test assertions in a temporary checkout and reran levels_take_tiles_when_given_and_give_them_back. 1 passed; reported tiled-resource tier 4. The real reserved-texture mapping, packed-tail, repeated-give and teardown assertions were reached. No runtime code was changed for that probe.

Not tested
Full workspace suite, native Windows, the D3D12 debug layer, AMD/Intel, or title streaming on this exact head. No claim of measured VRAM savings, playable world rendering, or fitting the game into 8 GiB follows from these synthetic tests.

AI use
omp with openai-codex/gpt-6-astra prepared the isolated checkouts, ran the checks and temporary no-skip probe, and drafted this report from the output.

Main now makes title textures on first use, places them in heaps made
ahead, and uploads only the subresources that changed, from shared
staging space, in one upload list per submission. The reserved texture
for levels on demand is made in make_texture ahead of the heap placement
(Resource::host passes whether the title placed the texture); with the
switch off nothing changes. Tiles are given in Staging::refresh, which
now runs from bindless::uploads before the upload list is recorded and
executed, so the mappings still reach the host queue first; since an
upload no longer copies every level, levels just given tiles (and those
host_writes gives before a host copy or resolve, which it records as a
pending upload into the submission's upload list) are detiled and
uploaded whether their bytes changed or not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. bb9ab45 addresses both points from the last triage. In crates/victory-gpu/src/resource.rs, HostTexture::held_bytes() returns the allocation for an ordinary texture and Tiled::given_bytes() (the tiles its levels hold) for a tiled one. evict_among/choose and give_up now use it, so giving up a tiled texture is credited with what it frees. evict_unused subtracts tiles::free_bytes() next to placement::free_bytes(). The default path is unchanged when VICTORY_LEVELS_ON_DEMAND is unset: reserved_texture returns None, and tiles::status() returns early when no tiled texture was made. CI check passes and the PR merges cleanly.

On your latest reply: thanks. The title now gives the current figure ("0.4-1.4 GB less on current main"). That matches your Linux A/B (about 1.4 GB less peak video memory) and the native Windows RTX 5070 Ti run in the thread (about 0.4-0.6 GB, tier 4, clean exit). Nothing is left open from triage.


Generated by Claude Code

desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
The previous main (old upstream base) is the first parent; the second is
upstream main with the current heads of our pull requests merged in:
Marvisak#2143, Marvisak#1849 (carried onto main's per-region runtime_pages), Marvisak#259, Marvisak#491,
Marvisak#2153, Marvisak#2099, Marvisak#2071 (main covers it), Marvisak#2162, Marvisak#2218, Marvisak#2088, Marvisak#2389, Marvisak#177's
element-type key on main's three handle maps, and the README. Marvisak#2112
(opt-in, in place) stays in the renderer branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@desplmfao

Copy link
Copy Markdown
Contributor Author

Merged main in ef1dcd6 and 29f572a (merge commits, no rebase). main had reworked texture creation in the meantime: textures fed from title memory are placed in heaps made ahead, made on first use and several at a time, uploads come from large staging buffers, and only subresources whose bytes changed are uploaded. The hooks moved:

  • resource.rs: with VICTORY_LEVELS_ON_DEMAND=1, an eligible streamed texture is made reserved before main's heap placement, so it never goes into a heap made ahead. If the reserved texture can't be made, it falls through to main's placement or committed path unchanged. With the switch off, reserved_texture returns None immediately and creation is exactly main's.
  • texture.rs: main now uploads only changed subresources, but a level that just got tiles has to be uploaded whether it changed or not (its tiles may hold a previous owner's data). A pending level mask on Staging covers those levels. They're detiled and uploaded at the next refresh, and they go back into the mask if a detile fails. host_written became main's host_writes: a reserved texture a host copy writes gets every level its tiles before that submission's upload list, which runs ahead of the copy.
  • list.rs: identical to main.
  • tiles.rs: Tiled::without is no longer test-only, and the module note describes the new flow.

tiles::, texture:: and resource:: give 24 passed under Wine on an RTX 5080, and clippy is clean with and without --features diagnostics. The in-title check on this merged head (picture and video memory) is still to come. I'll post it here.

Pierrot1398 added a commit to Pierrot1398/VIctory that referenced this pull request Nov 25, 2026
# Conflicts:
#	crates/victory-gpu/src/lib.rs
desplmfao and others added 2 commits November 25, 2026 20:28
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HostTexture::tiled records 0 bytes, so evict_among/choose and give_up
credited nothing for a tiled texture: past BUDGET_HIGH the loop gave up
every older tiled texture to free 'over' bytes, and they were made, mapped
and uploaded again. Eviction now uses held_bytes(): the allocation, or the
tiles a tiled texture's levels have (Tiled::given_bytes). evict_unused
also no longer counts the pool's free tiles as used, as it already does
for free space in the heaps of textures.

Found by the maintainer's triage of Marvisak#2389.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@desplmfao

Copy link
Copy Markdown
Contributor Author

Both points are fixed in bb9ab45, on top of a fresh merge of main (67a6614):

  • Eviction: HostTexture::held_bytes() returns the allocation for an ordinary texture. For a tiled one, it returns the bytes of the tiles its levels have (Tiled::given_bytes, which was test-only and isn't any more). evict_among/choose and give_up use it, so giving up a tiled texture is credited with what it really frees.
  • Free tiles: tiles::free_bytes() is subtracted in evict_unused, next to placement::free_bytes().

The tile test now also checks the pool's free bytes as a level takes its tiles. tiles::, texture:: and resource:: give 25 passed under Wine (RTX 5080), and clippy is clean with and without diagnostics.

From an in-title A/B on this branch (fork build, before this fix; ~3 min in the world each, medians):

VICTORY_LEVELS_ON_DEMAND ms/frame GPU peak video memory
1 741 399 11,047 MiB
0 788 416 12,434 MiB

So no frame-time cost, and about 1.4 GB less.

@desplmfao

Copy link
Copy Markdown
Contributor Author

A note on the size of the saving, since the title still says about 5 GB. That figure was measured on the older base, before main's texture rework: heaps made ahead, uploads from staging buffers, and only changed subresources uploaded. On current main, the in-title A/B above gives about 1.4 GB less peak video memory (11,047 against 12,434 MiB) with no frame-time cost. So main itself now spends much less on streamed textures, and the switch saves correspondingly less on top of it.

desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
… new base

The renderer README of the old branch (5fff8e0, f44ae53, eb4918e,
9a41398, b673d84, f711b62, 9b32e6f), carried over as one change since
main's README moved under each of them: the renderer section with the run
command (raw access chains off, VICTORY_PIPELINE_JOURNAL=1,
VICTORY_LEVELS_ON_DEMAND=1), and the stack's rows after main's. Adapted:
upstream base 67e8ae1; no Marvisak#2366 row (main's 8ff7913 replaces it), no Marvisak#67
row (not in this rebuild); Marvisak#1152 and Marvisak#2389 kept. The journal and soft-crash
notes (e543c44) and the breadcrumbs row (1f0d6c3) are not repeated:
Marvisak#491's and Marvisak#2292's current heads put them in the variables table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
The previous renderer (old upstream base 940d32f) is the first parent and
is also kept as the branch renderer-2026-11-25-oldbase; the second parent
is the rebuild: fork main (upstream main 63bcca4 + our pull requests) with
the renderer stack merged on it: Marvisak#439 (on main: update/439-main's
resolution), Marvisak#2309, Marvisak#2167, Marvisak#2118, Marvisak#2311, Marvisak#1722, Marvisak#1751, Marvisak#688, Marvisak#1872, Marvisak#2292,
Marvisak#2310, Marvisak#2112 (opt-in), Marvisak#2230 (latch on by default), Marvisak#2389, Marvisak#2088 (small
windows opt-in), Marvisak#2099's new head, and tonight's Marvisak#491 journal fixes.
Merged upstream since: Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906, Marvisak#1152; superseded by
main: Marvisak#1769, Marvisak#1763, Marvisak#2366.

The picture on this base still shows the overlay that plain upstream main
shows too; that is being looked into.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pickles976

pickles976 commented Nov 26, 2026 •

Copy link
Copy Markdown

@/tmp/v2389c.md

@kawaii-shakal

Copy link
Copy Markdown

Measured on native Windows, which the description lists as not tried: Windows 11 26300, RTX 5070 Ti 16 GB (tiled resources tier 4), title 1.0.2.1 with the default console (Series X). Two diagnostics builds, one of main 63bcca4 and one of main + this PR (bb9ab45) with VICTORY_LEVELS_ON_DEMAND=1. Same save, standing still in the world. The numbers come from the process's own report lines (video memory: via QueryVideoMemoryInfo and GetProcessMemoryInfo, host textures:, this PR's line), read 120 s after the first report where textures used by lists pass 1 GB.

main this PR
video memory on the card 6,512 MB 6,112 MB
process commit 25,341 MB 24,775 MB
host textures 5,842 MB 5,226 MB
of them used by lists 3,697 MB 3,180 MB
levels not allocated – 218 MB (peak 266)

The switch line reports tier=4 on=true. The PR's own line said 213 alive (267 made so far), 159 MB given to 506 levels alive; 210 MB not allocated (369 MB if every level had memory), with 577 UpdateTileMappings calls in all. There were no refreshes without memory, and the run exited cleanly.

So it works on Windows/NVIDIA, but the saving at this spot is about 0.4–0.6 GB, not ~5 GB. Here all host textures take 5.8 GB, and only 213 of them pass the filter (2D, one layer, ≥1 MiB, not a target). I did not compare the picture side by side.

🤖 Generated with Claude Code (Claude Opus 5.5)

@desplmfao desplmfao changed the title GPU: streamed textures take video memory only for the levels the title holds (opt-in, ~5 GB less) GPU: streamed textures take video memory only for the levels the title holds (opt-in; 0.4-1.4 GB less on current main) Nov 26, 2026
@desplmfao

Copy link
Copy Markdown
Contributor Author

@kawaii-shakal thanks, the first Windows run of this, and it's clean: tier 4, no refreshes without memory, a clean exit. Your 0.4–0.6 GB at that spot agrees with my 1.4 GB on Linux in a busier scene. Since main's texture rework, main itself spends much less on streamed textures, and only the textures that pass the filter can save anything (213 of yours). The "~5 GB" in the title came from the older base, so I've changed the title to "0.4–1.4 GB less on current main".

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The on-demand reserved texture path and eviction accounting (held_bytes, tiles::free_bytes) are well structured, and the existing tests pass on Windows 11 with RTX 5090 (tier 4) and WARP (tier 3) under VICTORY_D3D12_DEBUG=1 and VICTORY_LEVELS_ON_DEMAND=1 (tiles:: 4/4, texture:: 3/3, resource:: 18/18, draw::tests 20/20).

However, two lifetime/synchronization bugs in tile reclamation and host_writes reproduce reliably on RTX 5090 and WARP and need to be fixed before merge:

  1. Blocking — Tiled::drop recycles tiles and destroys ID3D12Heap while ID3D12Resource still has live COM holders (crates/victory-gpu/src/tiles.rs:473-491, 236-247):

    • HostHeap::kept (descriptor/host.rs), host::retire (RETIRED, released only at the end of Host::execute), and HostList::keep hold COM clones of ID3D12Resource (copy.texture), not Arc<HostTexture>. That is why placement.rs defers freeing heap ranges and empty heaps in HostTexture::drop via placement::free(self.texture.clone(), p) until last_holder(&resource) confirms no other COM reference remains.
    • Tiled::drop instead calls give_back immediately when Arc<HostTexture> drops. In normal execution this happens both when the title releases a texture whose descriptor-heap slot still views it, and during evict_unused() -> give_up() (which moves ID3D12Resource into RETIRED via descriptor::evict, then drops Arc<HostTexture> immediately at the start of Host::execute, ahead of bindless::uploads and release_retired()).
    • Reproduced both failure modes live on Windows 11:
      • Silent physical-tile aliasing corruption (RTX 5090 and WARP, zero Debug Layer warnings): filling reserved texture A with 0xAA, keeping a live ID3D12Resource clone (as HostHeap::kept / RETIRED does), dropping Tiled, then allocating texture B and filling it with 0x55 hands A's exact physical tile run (0, 32) to B and silently overwrites A (before=[aa, aa, aa, aa, aa, aa, aa, aa] -> after_B_wrote_0x55=[55, 55, 55, 55, 55, 55, 55, 55]).
      • Premature ID3D12Heap destruction / GPU fault (RTX 5090, both with and without VICTORY_D3D12_DEBUG=1): with two 64 MiB heaps in POOL, dropping the Tiled owners on heap 0 while one ID3D12Resource clone remains live immediately drops heap 0 (pool[index] = None, heaps_mb=128->64, given_back=0->1); a subsequent CopyTextureRegion from that live ID3D12Resource crashes the process on RTX 5090 with 0xc0000409 (STATUS_STACK_BUFFER_OVERRUN) even without the debug layer.
    • Fix: mirror placement.rs by passing (self.texture.clone(), runs) from HostTexture::drop into a pending list in tiles.rs, and only returning tile runs / releasing empty heaps once last_holder(&resource) is true (and after any queued UpdateTileMappings have completed).
  2. Blocking — host_writes calls tiled.give (UpdateTileMappings) at command-list record time (crates/victory-gpu/src/texture.rs:243-264):

    • Calling tiled.give(&copy.texture, every) directly from host_writes (texture.rs:254) queues UpdateTileMappings onto host.queue() from recording threads before Host::execute.
    • If a recorded list is reset or dropped without being executed (or the texture is dropped before a submission drains the queue), Tiled::drop destroys the backing heap while UpdateTileMappings is still in flight on host.queue() — reproduced live with exit code 2173 on both RTX 5090 and WARP under VICTORY_D3D12_DEBUG=1.
    • It also breaks submission ordering: because lists need not execute in recording order, mapping recycled (uninitialized) tiles onto a reserved texture at record time exposes stale previous-owner tile data to any earlier submission that samples the texture before list's upload runs.
    • Fix: defer giving tiles for host_writes (and setting pending) until submission preparation inside Host::execute (ahead of list's upload list, matching Staging::give_held and list.defer_host).

One smaller non-blocking note: in Staging::refresh_now, the untracked !committed(self.memory, size) branch (crates/victory-gpu/src/texture.rs:678-699) returns early with zeros without calling give_held, so an untracked partially-committed reserved texture would never receive tiles for its committed small mips.

…ission

Fixes the two blocking bugs and the minor one from fuzeofficlal's review
of Marvisak#2389, which reproduced them on an RTX 5090 and WARP.

1. Tiles went back to the pool, and an emptied heap to the host GPU, as
   soon as the Arc<HostTexture> dropped. Heap slots (HostHeap::kept),
   retired copies (host::retire) and lists (HostList::keep) hold COM
   clones of the ID3D12Resource past that, so the next reserved texture
   could be given the same physical tiles while a view of the old one
   lived (silent aliasing), and a heap could be released under a live
   mapped resource (0xc0000409 on the next copy from it).
   HostTexture::drop now hands its resource and Tiled to tiles::free, as
   it already does with placement::free for placed textures. tiles::reap
   gives the tiles back (and releases empty heaps) only once
   placement::last_holder says nothing else holds the resource and every
   UpdateTileMappings queued before the texture went has run:
   Host::execute reads tiles::queued() before signalling its fence and
   reports tiles::ran() after waiting for it, then reaps after
   release_retired(). Reaps also run at each take and at free_bytes.

2. host_writes called Tiled::give at record time, queuing
   UpdateTileMappings before Host::execute. A list reset or dropped unrun
   left a mapping in flight for a texture that could then go with its
   heap (exit 2173 under VICTORY_D3D12_DEBUG=1), and a submission made
   before the writing list's saw the new tiles with their last owner's
   bytes. host_writes now only records the texture in the list
   (HostList::defer_tiles); Host::execute gives every level tiles for
   those lists (texture::give_for_host_writes) ahead of the submission's
   upload list, which uploads the levels just given (Staging pending), as
   Staging::give_held does for streamed levels. So every mapping is now
   queued during a submission's preparation and that submission waits for
   it.

3. Staging::refresh_now's untracked, not fully committed branch uploaded
   zeros and never called give_held, so a partly mapped reserved texture
   never got tiles for the small levels it holds. For levels-on-demand
   textures that branch now reads the memory through copy_mapped (zeros
   where unmapped), as the tracked path does, and goes on as a committed
   texture: give_held gives tiles to the held levels and they are
   uploaded with their bytes. Textures made committed keep the zeros.

Tests: tiles::tests::tiles_go_back_only_once_nothing_holds_the_texture_
and_its_mappings_ran (the review's repro: a texture let go of while a
clone of its resource is held keeps its tiles, another texture is not
given them, and they go back once the clone goes and the mapping ran)
and resource::tests::a_host_write_gives_tiles_at_submission_not_when_
recorded (a list dropped unrun gives no tiles; a submitted one makes
every level whole). Both fail with the old behaviour. tiles::FORCED
(tests only) makes the textures of one thread levels on demand without
the process-wide switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@desplmfao

Copy link
Copy Markdown
Contributor Author

@fuzeofficlal thanks, both were real. Fixed in 6b91df4:

  1. Tiles given back under live clones: HostTexture::drop now hands its resource and its Tiled to tiles::free, as it already does with placement::free for placed textures. tiles::reap gives the tiles back, and frees an empty heap, only when placement::last_holder(&resource) is true and every UpdateTileMappings queued before the texture was let go has run. Host::execute reads the mapping counter before signalling its fence and records it as run only after its waits succeed. reap runs after release_retired(), at the start of take(), and in free_bytes(). It releases the resource first and gives the tiles back outside the lock.
  2. Mappings at record time: host_writes now only notes the texture in the list (HostList::defer_tiles, cleared by a reset). Host::execute gives the tiles after sync_heaps and ahead of bindless::uploads (texture::give_for_host_writes). One difference from your suggestion: pending is set there too, not in host_writes. Otherwise a list dropped unrun would leave pending set, and a later refresh would give tiles for a write that never happened. Every mapping is now queued while a submission is prepared, and that submission waits for it.
  3. refresh_now, untracked and partly committed: for levels-on-demand textures it now reads through copy_mapped (zeros where unmapped), then hashes, calls give_held, detiles and uploads like the committed path. So the mapped small levels get their tiles and their bytes. Committed textures keep the old zero upload.

Two new tests, both failing with the old behaviour:

  • tiles::tests::tiles_go_back_only_once_nothing_holds_the_texture_and_its_mappings_ran (your repro: a clone of the resource held, then a new texture given level 0 gets no overlapping tiles)
  • resource::tests::a_host_write_gives_tiles_at_submission_not_when_recorded

Clippy is clean with and without diagnostics. Under Wine (RTX 5080), the full victory-gpu run has the same 30 failures as main there. In the title with VICTORY_LEVELS_ON_DEMAND=1 it runs into the world with no crash and no tile warnings, and video memory is in the same range as before (~10.3 GB). I couldn't confirm that VICTORY_D3D12_DEBUG=1 reaches the debug layer under vkd3d-proton, so a rerun of your RTX 5090/WARP repro would be the real check.

desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants