GPU: harden untracked texture refresh against TOCTOU and zero-size layouts #641
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/641"
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?
Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-24T06:06:03Z.
Summary
Commit
c75fdbamovedCopyPageMappingsBatchXphysical-page views (MEM_MAPPED) and placeholders (MEM_RESERVE) onto thetrackedpath (watch::track(..., true)+host::copy_mapped), resolving the original streamed-texture motivation of this PR.This PR has been narrowed (rebased on
main4118f33, head2ef9a75) to address the remaining gaps in thetracked: Nonefallback path ofStaging::refresh_nowincrates/victory-gpu/src/texture.rs:size == 0: short-circuit zero-sized layouts inStaging::refresh_now()before locking or touchingself.memory.VirtualQuery: replacecommitted(self.memory, size)+unsafe { std::slice::from_raw_parts(self.memory, size) }withread_mapped(self.memory, &mut last.read):crate::host::read_into(ReadProcessMemory) in a single call with zeroVirtualQueryoverhead and no raw-pointer TOCTOU race against concurrent unmaps/decommits.[src, src + len)viaVirtualQuery(withchecked_addoverflow guard andProtect == 0 | PAGE_NOACCESS | PAGE_GUARDrejection), copies readable regions viaread_into(falling back to 4 KiB pages on mid-region concurrent unmap), and zeroes unreadable gaps so partially committed non-runtimeMEM_PRIVATEallocations still read safely without stale bytes.resident == 0, resetlast.hash = Noneso remapping identical bytes re-uploads cleanly.self.trackedpath andpub(crate) fn committed(...)unchanged.Verification
Verified on
2ef9a75(based onmain4118f33, Windows MSVC):cargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleancargo test --workspace --locked: 700 passed, 0 failed, 10 ignored (includes new teststexture::tests::read_mapped_handles_unmapped_partial_eviction_and_overflowandtexture::tests::untracked_refresh_now_handles_zero_size_partial_residency_and_remap)VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked -- --test-threads=1: 146 passed, 0 failed, 2 ignoredcargo xtask policy: 182 files okNo game files. AI-assisted; reviewed and verified with the checks above.
Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T06:18:59Z.
Review: APPROVED
Tested on native Windows 11 with Rust 1.98.1 (x86_64-pc-windows-msvc).
Imported from Marvisak/VIctory. Originally posted by DeerSilver on 2026-11-24T10:31:08Z.
Tested head
f887f6a3fmerged ontomainffe310e(clean merge) on NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell), driver 621.24, Windows 11 26300, Rust 1.98.1: pass. No game files: the test suite only.cargo test -p victory-gpu partial):partial_residency_reads_only_mapped_regions_and_detects_new_mipspartially_resident_mip_tail_uploads_to_host_texturepartially_resident_mip_tail_uploads_to_host_texturereturns early when there is no host GPU. Here it ran on the RTX 5060, which is DXGI adapter 0 on this laptop, so the mip-tail upload into a real D3D12 texture is checked on NVIDIA.cargo test --workspace --locked: 344 passed, 0 failed, 6 ignored, against 342 passed / 6 ignored onmainat the same commit. The difference is the two new tests.cargo clippy --workspace --all-targets --locked -- -D warnings: clean.I didn't run a negative control: the new tests call the new
read_resident/Residencycode, so they don't build againstmain'stexture.rs. I don't have the title, so I can't confirm that the black streamed textures in the world are fixed.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T13:52:47Z.
Review: APPROVED
Tested merged cleanly onto
main(ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC) with NVIDIA GeForce RTX 5090 (Blackwell) and WARP (VICTORY_D3D12_WARP=1):cargo test -p victory-gpu(RTX 5090): 52 passed, 0 failed, 1 ignoredVICTORY_D3D12_WARP=1 cargo test -p victory-gpu(WARP): 52 passed, 0 failed, 1 ignoredcargo clippy -p victory-gpu --all-targets: 0 warningscargo xtask policy: okClean merge, compiles and passes all GPU tests on both Blackwell hardware and WARP with zero warnings. Approving.
AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-24T22:08:16Z.
Rebased onto
origin/main(70564ae, new headf96c56f):origin/main'strackedwrite-watch/mapped copy path (c75fdba) inStaging::refresh_now() -> (usize, bool)alongsidepub(crate) fn committed(...).Staging::refresh_now() -> (usize, bool)to handleResidency::Unmapped,Residency::Full, andResidency::Partial, hashing only resident intervals and zeroing evicted gaps before detiling.texture::tests::refresh_now_reports_resident_bytes_and_changed_flagcoveringUnmapped -> (0, false),Partial -> (resident_bytes, true/false), andFull -> (size, true/false)withtracked: None.Verified on
f96c56f(Windows MSVC):rustfmt --edition 2024 --check crates/victory-gpu/src/texture.rs: all rebased/new hunks clean (only pre-existingorigin/maindiffs inhost_written/alias_copy).cargo clippy --workspace --all-targets --locked -- -D warnings: clean.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.cargo test --workspace --locked:479 passed, 0 failed, 7 ignored(victory-gpu:81 passed, 0 failed, 1 ignored;xtask:4 passed).[PR #641] GPU: upload partially-resident streamed texturesto [PR #641] GPU: harden untracked texture refresh against TOCTOU and zero-size layoutsImported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:26:45Z.
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-25T00:49:07Z.
Good catch by triage —
c75fdba(watch::track(..., true)+host::copy_mapped) already resolved the originalCopyPageMappingsBatchX/MEM_MAPPEDstreamed-texture case onmain.However, the
tracked: Nonefallback path inStaging::refresh_now(crates/victory-gpu/src/texture.rs) still had a few remaining gaps onmain:committed(self.memory, size)and then dereferencesunsafe { std::slice::from_raw_parts(self.memory, size) }, which can fault if another thread unmaps/decommits the private allocation betweenVirtualQueryandblake3::hash/detile(and incursVirtualQueryon every submission).size == 0guard:refresh_now()does not short-circuitsize == 0before callingcommitted()/from_raw_parts().MEM_PRIVATErange has a committed first page (tracked == None) and uncommitted/unreadable tail pages,committed()rejects the whole texture, and full unmaps do not resetlast.hash = None.I have narrowed the PR scope to only these remaining items, rebased cleanly onto
main(4118f33), updated the PR title/description, and pushed2ef9a75:tracked: Noneraw-slice path withread_mapped()(singlecrate::host::read_intofast path,VirtualQuery+ 4 KiB page fallback zeroing unreadable gaps,checked_addoverflow guard, andlast.hash = Nonewhenresident == 0).size == 0.read_mapped_handles_unmapped_partial_eviction_and_overflowanduntracked_refresh_now_handles_zero_size_partial_residency_and_remap.Verified on
2ef9a75(Windows MSVC):cargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleancargo test --workspace --locked: 700 passed, 0 failed, 10 ignoredVICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked -- --test-threads=1: 146 passed, 0 failed, 2 ignoredcargo xtask policy: 182 files okIf you'd like these remaining hardening fixes in the
tracked: Nonefallback, please feel free to reopen and take another look.Pull request closed