Formats, GPU: a streamed texture's small mips are read before its large ones are there #2859
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!2859
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2859"
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 22:32 UTC · original
0xkn0wh3r3:formats/smaller-mips-detile-from-their-bytes→main· +300 −8 · 2 files · 2 commits · openWhat
When a title streams a texture, it maps the start of the texture's memory first. In GFX10 layouts the mip tail and the smaller mips lie at the start, and the larger mips come after them. On main:
Layout::detile(andtile) wanted the whole texture's bytes for any mip.This PR changes two things:
victory-formats: newLayout::bytes_from(mip)returns the bytes from the texture's start that the mip and every smaller one take. It returns the whole layout for arrays, thick, 3D and multisampled layouts, where each slice holds its own chain.detileandtilecheck the tiled length against it. The copies were already bounds-checked slice copies, so a short slice still can't be read past.victory-gpu: when such a refresh finds the memory not all committed,first_resident_mipfinds the largest mip whosebytes_fromrange is committed. That mip and the smaller ones are detiled from those bytes and uploaded; the other subresources keep what they hold. A texture with nothing committed still takes the zeros path as before. That costs one extraVirtualQuerypass, over the tail block only. Textures with write tracking already read throughcopy_mapped, which stands in for unmapped pages, so they're unchanged.Where it came from
Layout::bytes_fromand its formats test are from DexNom's fork, DexNom/VIctory@570a941, credited withCo-authored-by: DexNom. Their GPU caller (placed_bytes_from) sits in their own placed-texture code; the refresh-path change here is reworked for this tree.Tested
texture::tests::smaller_mips_need_only_the_start_of_the_texture(formats): for a 1024×1024 BC1SW_4KB_Stexture with 9 mips, each mip detiles from itsbytes_frombytes exactly as from the whole texture, and one byte fewer givesTooSmall. Array textures need the whole layout.texture::tests::a_texture_with_only_its_small_mips_committed_reads_them(GPU): a reservation of that texture's size, committed from the start one mip range at a time, givesfirst_resident_mip= 4, 3, 2, 1. With nothing committed it givesNone.cargo test -p victory-formats: 47 passed, 5 ignored.cargo test -p victory-gpuon Windows 11 with an RTX 5070 Ti: 227 passed. The 2 failures (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views) fail identically on main on NVIDIA; #2121 fixes them.cargo clippy --all-targets -- -D warningsfor victory-formats, and for victory-gpu with and without--features diagnostics: clean.Not tested
Changes after review (
b4d4b4c)Staging::detilenow reserves the staging layout only from the first subresource it detiles. Subresources lie in order, so the small mips are last, and footprint offsets are multiples of 512. It returns where offset 0 of the layout would be, wrapped below the reservation when that starts later;copiesadds footprint offsets with wrapping arithmetic, so each one lands inside. For the 1024×1024 BC1 texture in the test, a refresh of mips 4–8 now reserves 7,688 of the layout's 704,008 bytes, and one from mip 2 on 48,648. The tracked path's partial refreshes reserve less the same way.TexHashedandTexChangedlike the whole-texture path.texture::tests::a_streamed_texture_stages_its_resident_mips_then_the_larger_onesrefreshes a realStagingof that texture in an untracked reservation as its mips arrive (from mip 4, then mip 2, then all). Each refresh stages exactly those mips. The bytes read back from the upload buffer equalvictory-formats' detile of each mip, so the shifted reservation is checked too. It stops at the staging buffer: it doesn't copy into a host texture and sample it, and I haven't measured a live scene.842b0cb).cargo test -p victory-gpu: 228 passed, plus the 2 known NVIDIA failures (#2121). Clippy is clean with and withoutdiagnostics.@fuzeofficlal on GitHub · 2026-11-25 22:54 UTC · original
Reviewed and verified
e0419847on Windows 11 (RTX 5090 + WARP) againstmain(842b0cb):Layout::bytes_from(first)correctly bounds the required resident prefix for tiled non-array 2D textures (falling back to fullself.sizeforfirst == 0, arrays, thick/3D, MSAA, orSwizzle::LINEAR), andwalk()+first_resident_mipsafely hash, detile, and upload onlyi % self.mips >= firstwhile re-uploading automatically as larger mips become committed.victory-formats --lib texture::tests17/17 passed,victory-gpu --lib texture::tests3/3 passed on RTX 5090 and WARP (includinga_texture_with_only_its_small_mips_committed_reads_them),cargo clippy --locked -p victory-formats -p victory-gpu --all-targets(default &--features diagnostics) 0 warnings,cargo xtask policy(190 files ok).first_resident_mipbranch inStaging::refresh_now(texture.rs:636-651) skipscopystat::C::TexHashed/TexChangedaccounting unlike the full-upload path.Looks clean and ready to merge.
@Marvisak on GitHub · 2026-11-26 04:24 UTC · original
Automated triage for the maintainers.
Merge candidate.
Layout::bytes_fromtakes the largest end offset over the requested mip and all smaller ones (mip tail as the first block), so it holds for any mip placement and falls back to the whole size for arrays, 3D, thick and MSAA; invictory-gpu,first_resident_mipand the partial-refresh branch ofStaging::refresh_nowupload the committed small mips instead of zeros, andStaging::detilereserves staging only from the first needed footprint. The offsets stay 512-aligned,footprint.Offset - fromcannot underflow, andcopiesadds them back; the formats test and staged read-back test cover it.CI: passing.
Generated by Claude Code
@kotekompotek on GitHub · 2026-11-25 22:51 UTC · original · reviewed
Sound: the whole-layout fallback for sliced/thick/3D/multisampled textures is the safe direction, and for single-slice 2D the max-over-smaller-mips extent (with tail-block mips needing only bytes, since the tail IS the texture's first block) matches the tile layout where small mips sit near the start. Capping at size keeps malformed descs in bounds. detile accepting bytes_from(mip) instead of size is exactly what a streamed-in-small-mips resource needs. LGTM.
@kotekompotek on GitHub · 2026-11-25 22:52 UTC · original · reviewed
Sound: the whole-layout fallback for sliced/thick/3D/multisampled textures is the safe direction, and for single-slice 2D the max-over-smaller-mips extent (with tail-block mips needing only
alignmentbytes, since the tail IS the texture's first block) matches the tile layout where small mips sit near the start. Capping at size keeps malformed descs in bounds. detile accepting bytes_from(mip) instead of size is exactly what a streamed-in-small-mips resource needs. LGTM.@AwsAli05 on GitHub · 2026-11-25 22:55 UTC · original · reviewed
I ran the two new focused tests on Windows at
e041984. The BC1 prefix detile test and the committed-mip selection test both passed.One memory-budget concern in
Staging::detile: the partial refresh still reservesstaging_space(self.size), so the first upload of just the resident tail still needs the full D3D12 staging footprint. This matters when streaming is memory-limited. The current tests cover prefix layout and residency selection. An end-to-end test that samples a host mip before and after a larger mip arrives would also verify the upload path. Please record the staging bytes when measuring the change in a live scene.AI-assisted review.
@Dukestar69 on GitHub · 2026-11-26 10:07 UTC · original · approved these changes
Verified on RTX 5090 & WARP against
origin/main(63bcca4):cargo test -p victory-formats --lib texture:: -- --test-threads=1: 17/17 passed (includingsmaller_mips_need_only_the_start_of_the_texture).cargo test -p victory-gpu --lib texture:: -- --test-threads=1: passed.cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed on RTX 5090 and WARP.cargo clippy -p victory-formats -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly allows streamed textures' smaller mips to be read before larger mips are mapped.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@fuzeofficlal on GitHub · 2026-11-26 11:04 UTC · original · approved these changes
Verified
b4d4b4c8locally on Windows 11 (RTX 5090 and WARP, withVICTORY_D3D12_DEBUG=1):cargo xtask policyandcargo clippy -p victory-formats -p victory-gpu --tests -- -D warnings(default and--all-features): clean.victory-formats --lib texture::: 17/17 passed (includingsmaller_mips_need_only_the_start_of_the_texture).victory-gpu --lib texture::: 4/4 passed (includinga_texture_with_only_its_small_mips_committed_reads_themanda_streamed_texture_stages_its_resident_mips_then_the_larger_ones) on RTX 5090, RTX 5090 +VICTORY_D3D12_DEBUG=1, and WARP +VICTORY_D3D12_DEBUG=1.victory-gpu --lib draw::tests::(includinga_write_into_one_mip_uploads_that_mip_aloneexercising partial-subresource staging throughCopyTextureRegion): 20/20 passed across all three configurations.Layout::bytes_fromhandles tiled mip tails (self.alignment == block_bytes), regular/linear smallest-first chains, and whole-layout fallbacks (arrays, 3D, thick, MSAA) cleanly, andStaging::detilereservingself.size - fromkeeps 512-byte placement alignment andsubresource_lenbounds intact while cutting staging overhead for partial refreshes. Ready to merge.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.