GPU: textures viewed only from a smaller level are uploaded from it on #2149
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!2149
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2149"
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 06:14 UTC · original
0xkn0wh3r3:gpu/placed-textures-read-levels→main· +449 −33 · 8 files · 2 commits · openProblem
A streamed texture's small mip levels can be all the title keeps of it: on fxceless/victory-fork, Grand Theft Auto VI kept only a texture's small levels and placed the next texture where the larger ones would be. GFX10 stores levels smallest first, so that neighbour lies inside the texture's layout. Today its staging reads, uploads and watches the whole layout: the neighbour's bytes end up in its large levels, and every write to the neighbour re-uploads the whole texture.
Fix
readableindraw.rspasses it totexture::upload).copy_resource,copy_texture_region,read_backpass level 0), or a view of an earlier level, makes it whole again (a staging made from a later level is rebuilt). Arrays and other dimensions are unchanged.--features diagnostics, each staging logs its first level, the bytes read against the whole layout, and how many placed textures start in the unread levels. The first trimmed texture is logged in every build. This is what a run with the game would use to confirm the title's views start above level 0.Not included: saving the VRAM of the unread levels (host textures are still full size), and releasing placed textures.
Testing
draw::tests::a_shader_view_from_a_later_level_uploads_from_it: throughreadablewith aView::Shaderof level 3 on (no host descriptor made), a 256x256, 9-level texture is staged from level 3 and its upload copies 6 subresources; with a view of level 0 on it is staged and copied whole (9). With level 0 passed on that path instead, the test fails.draw::tests::a_list_reading_an_earlier_level_later_uploads_it_whole: one list reads the 9-level texture from level 3, then from level 0; its submission uploads the staging from level 0 once and copies all 9 levels. Without the fix the list submitted only the level-3 staging (the test fails: nothing staged from level 0).cargo test -p victory-gpu --libon an RTX 5070 Ti: all pass except the two tests that already fail onmainfrom the NVIDIA heap cap (#1835).cargo clippy -p victory-gpu --all-targets, with and without--features diagnostics: clean.Rebased onto
13f91cafdf34ab), not one per texture, andupload_changedis gone. The trimming applies on top of that:Staginggainsfirstandprefix, and a staging reads, detiles and watches only those bytes.Triage fix (
c41f3d4)texture::uploadtakes the first level the use reads.readablepasses the view'sfirst_level; the copy and read-back callers pass 0. Before,uploadalways noted level 0, so a texture read through a view on thereadablepath was uploaded whole. Rebased onto63bcca4.Review fix (
d320b87)fuzeofficlal found that a list which read a texture from level 3 and later from level 0 still submitted only the level-3 staging:
uploadreturned atfirst_useafternote_readshad dropped it. The list now notes the earliest level it asked each texture for (HostList::first_use_from) and queues the rebuilt staging when a use reads from an earlier level. Textures queued this way are uploaded by the submission's upload list, which runs before all of the submission's lists, so the order is unchanged.bindless::uploadskeeps one staging per host texture, the one from the earliest level. A staging of uncommitted memory now hashes the zeros of its read prefix, like the committed path.@0xkn0wh3r3 on GitHub · 2026-11-25 07:21 UTC · original
On partial views:
first_leveltakesmax(MostDetailedMip, floor(ResourceMinLODClamp)), reading the clamp from each dimension's own field (2Dw[7], 2D arrayw[9], 1D/3D/cubew[6], 1D array/cube arrayw[8]). The floor is deliberate: a clamp of 1.5 still blends levels 1 and 2.MipLevelsis ignored, because trimming the small end saves nothing worth having.The upload follows the lowest level anything has asked for (
read_from, afetch_min). A later view from a lower level drops the held staging, and the next upload starts from that level. Copies and bound tables count as reading from level 0. Buffers and views with no description also count as level 0.@Marvisak on GitHub · 2026-11-25 11:24 UTC · original · edited 2026-11-26 01:21 UTC
Automated triage for the maintainers.
Merge candidate. Two commits on current
main, merges cleanly.The same-list gap fuzeofficlal reported is closed in
d320b87, as your reply describes.HostList::first_use_from(host.rs) keeps the earliest level a list asked for each texture and returns true again for an earlier one, sotexture::uploadqueues the staging rebuilt from that level;bindless::uploadsnow keeps one staging per host copy, the one with the lowestfirst, so the stale level-3 staging is not uploaded beside it. Deferred texture steps are recorded into the submission's upload list, which runs before the submission's lists, so the order holds. The uncommitted path now hasheszeros[..prefix]like the committed one. The newa_list_reading_an_earlier_level_later_uploads_it_wholetest covers the case.Still open, as before: no title run here showing a texture placed in another's unread levels; the
texture stageddiagnostics event is the way to show it.CI: passing (
check). Recommending a look, not approving.Generated by Claude Code
@0xkn0wh3r3 on GitHub · 2026-11-26 00:06 UTC · original
Thanks. Rebased onto
63bcca4and fixed inc41f3d4(still one commit).readablefalling back to whole uploads. You were right:texture::uploadnoted level 0 for every caller,readableincluded. It now takes the first level the use reads (texture.rs:355, noted at:357):readablepasses the view'sfirst_level(desc)forView::Shaderreads, placed views included onceplaced_texturehas turned them intoView::Shader(draw.rs:1925).copy_resource,copy_texture_regionandread_backpass 0 (list.rs:656,:751,:860).resolvedoesn't callupload.The PR text and commit message no longer say bound tables read the texture whole.
New test
draw::tests::a_shader_view_from_a_later_level_uploads_from_it(draw.rs:2939). It goes throughreadablewith aView::Shaderonly and never makes a host descriptor, somakedoesn't note anything. A 256x256, 9-level texture viewed from level 3 is staged from level 3, reads less than 1/16 of its layout, and its upload copies 6 subresources. Viewed from level 0, it is staged and copied whole (9). I checked that the test fails ("staged from the view's level", left 0, right 3) when that path passes 0 instead.Results on this machine (NVIDIA):
cargo test -p victory-gpu --lib: 233 passed. The 2 failures are the known heap-cap ones that also fail onmain(dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views).cargo clippy -p victory-gpu --all-targets, with and without--features diagnostics: clean.cargo xtask policy: ok.A log or trace from this repo showing a placed texture inside another texture's unread levels. I can't produce that here: it needs a run with the title, and I have no game data. With
--features diagnostics, each staging logs atexture stageddebug event (texture.rs:956) withfirst,read,wholeandneighbours.neighboursisresource::placed_textures_in(resource.rs:2034): the number of placed textures that start between the end of the levels read and the end of the layout. A tester running the title can show the case with an event wherefirst > 0andneighbours > 0. In every build, the first texture uploaded from a later level also logs "textures only viewed from a smaller level are uploaded from it on" once (texture.rs:942).@fuzeofficlal on GitHub · 2026-11-26 00:41 UTC · original
Code review and RTX 5090 + WARP verification at head
c41f3d4a4edbmerged cleanly ontomain(63bcca43c6a0):HostTexture::read_from(AtomicU32), SRVMostDetailedMip/ResourceMinLODClampextraction (first_levelwith NaN/negative fallback to 0), restricting partial-mip upload strictly to single-slice 2D textures (slices == 1 && Dimension::Tex2d), prefix hashing/tracking on[0, mips[first - 1].offset), and passingfirst = 0on copy/readback paths inlist.rsall fit together cleanly.crates/victory-gpu/src/texture.rs:355-385):upload(list, resource, texture, first)callsnote_reads(©, first)first — iffirstis smaller than the previousread_from,note_readslowersread_fromand clearscopy.staging = None— and then immediately checksif !list.first_use(texture.as_raw() as usize) { return; }(host.rs:2271).list.defer_texture(staging, copy)already queued the earlierArc<Staging>(e.g.staging.first = 3) inlist.deferred().copies, and submission (host.rs:1198) consumes that capturedStep::Texture(staging, copy)directly, a singleHostListwhere Draw 1 samples withfirst = 3and a later Draw 2 (orcopy_resource/copy_texture_region/read_back) reads the same texture withfirst = 0will updateread_from/copy.stagingfor future lists, but return early atfirst_useand still submit the stalefirst = 3staging on the current list — leaving mips0..2un-uploaded for that list.Step::Textureentry whenfirst < queued.first(or resolving the latestcopy.stagingat submit time) would close this intra-list gap.texture.rs:677-680),last.hashhashes the full zeroed layout size while the committed path (texture.rs:685) hashesprefix, which causes one harmless extradetileif the memory first becomes committed while all-zero.VICTORY_D3D12_DEBUG=1, Rust 1.98.1):cargo xtask policy:191 files ok;cargo clippy --locked -p victory-gpu --tests -- -D warnings(default +--features diagnostics): 0 warningstexture::tests draw::tests list::tests resource::tests: 48/48 passed on RTX 5090 (default and--features diagnostics) and 48/48 passed on WARP (--features diagnostics), including all 4 new partial-mip tests.@0xkn0wh3r3 on GitHub · 2026-11-26 01:12 UTC · original
Thanks, both points were right. Fixed in
d320b87, a separate commit on top ofc41f3d4.Same-list widening. You're right. Once
note_readshad dropped the level-3 staging,uploadreturned atfirst_use, so the list submitted the staleStep::Textureand levels 0..2 were missing for that list. Now:HostList::first_use_from(key, first)(host.rs:2277) notes the earliest level the list has asked for each texture. It returns true again when a use reads from an earlier level.uploadcalls it with the use's level (texture.rs:378), so the list also queues the staging rebuilt from that level.Step::Textureentries are not run in the list's step order. At submission they are all collected (host.rs:1199) and recorded into the submission's upload list, and that list runs before all of the submission's lists (host.rs:1214). So a step queued later in the list still uploads before any of the list's commands.bindless::uploadskeeps one staging per host texture, the one from the earliest level (bindless.rs:225). The stale level-3 staging is not uploaded alongside it.New test
draw::tests::a_list_reading_an_earlier_level_later_uploads_it_whole(draw.rs:2969). One list reads a 256x256, 9-level texture throughreadablefrom level 3, then from level 0. After submission the texture is staged from level 0 and uploaded once, with all 9 subresources copied. Before the fix it fails: nothing is staged from level 0 (staged_fromisNone), because the dropped staging was never rebuilt for that list.Uncommitted-path hash. Fixed: it now hashes
zeros[..prefix](texture.rs:682), the same bytes the committed path hashes.Results on this machine (NVIDIA):
cargo test -p victory-gpu --lib: 233 passed in each of two full runs, 3 failed in each. Two of them also fail onmainhere (heap cap):dynamic_slots_are_held_until_releasedandlists_share_a_table_and_copies_keep_their_views. The third differed between runs. One run failedwatch::tests::armed_ranges_keep_their_pages_bytes_from_before_the_first_write, which passed in the other full run and 3/3 times alone. The other failedviews_bound_while_another_slot_gets_its_texture_do_not_wait, which is a known flaky test.--features diagnostics.cargo clippy -p victory-gpu --all-targets, with and without--features diagnostics: clean.cargo xtask policy: ok.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.