GPU: bound texture upload and capture slices to the allocated buffer #601
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/601"
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 AwsAli05 on 2026-11-24T05:21:00Z.
A 10×6 RGBA8 texture with two mips places its 5×3 mip at byte 1536. Native D3D12 on WARP reports a 256-byte pitch, 20 bytes of pixels per row and a 2068-byte upload buffer. The old detile code formed a 768-byte mutable slice at offset 1536, where the mapping has only 532 bytes of resource data. The texture upload diagnostics reported the same oversized range. Both capture paths also assumed a full pitch after the last row of their readback buffers.
The upload path now caps the pitched subresource span at the end of the staging buffer. Frame captures and render-target dumps use the readback buffer’s declared byte width. Row and depth strides stay intact. The regression test checks both mips so that the final-row fix also preserves the earlier mip’s span.
Verified on Windows with Rust 1.98.1 (GNU target). An independent call to
ID3D12Device::GetCopyableFootprintson the WARP adapter confirmed the offsets and lengths above.cargo check --locked -p victory-gpuVICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --features diagnostics -- --test-threads=1(46 passed, one benchmark ignored)cargo xtask policyTesting covered synthetic resources. Gameplay impact is unmeasured.
upstream-sync referenced this pull request2026-11-24 06:54:08 +00:00
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T08:50:48Z.
Review: APPROVED
Tested
4899516on Windows 11, RTX 5070, MSVC:cargo test --workspace --no-fail-fastpasses (265 passed, 0 failed), includingupload_slice_stops_at_the_end_of_the_buffer.GetCopyableFootprintssizes the buffer so the last row of the last subresource ends at its active bytes, not at a full pitch. Mip 1 of a 10×6 RGBA8 at offset 1536 has 3 × 256 pitched bytes, but only 2 × 256 + 20 = 532 of them are in the buffer, so the oldfrom_raw_parts_mut(.., 768)reached 236 bytes past the mapping. Capping atsize - Offsetfixes both the detile slice and the diagnostics range. The numbers match what #409 computes (total 2068) for the same texture.buffer.GetDesc().Widthfor the capture/dump readbacks is the right bound for the same reason.sizeis no longer diagnostics-only, which is needed now that release builds use it.No issues found.
AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T10:51:46Z.
Independent verification & code review on Windows 11 Pro (build 26100) + AMD Radeon RX 9060 XT (RDNA4, driver
32.0.32029.2010, Rust1.98.1), cleanly merged ontomain(ffe310e):cargo xtask policy: PASS (154 files ok)cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: PASScargo clippy -p victory-gpu --all-targets --features diagnostics --locked -- -D warnings: PASSVICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --locked: 51 passed, 0 failed, 1 ignored (including newtexture::tests::upload_slice_stops_at_the_end_of_the_buffer)VICTORY_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --locked -- texture: 4/4 PASS (1 ignored benchmark)Diff review (
capture.rs,texture.rs):GetCopyableFootprintssizes the allocation to end after the last row's active bytes rather than a fullRowPitch.capture.rs'sto_rgba/saveonly readw * pixel_byteson the last row, so boundingrowstobuffer.GetDesc().Widthis safe and exact.buffer_size.saturating_sub(footprint.Offset)infootprint_lenis slightly more defensive thanbuffer_size - footprint.Offsetif a synthetic/mock footprint ever passes an offset pastbuffer_size.AI-assisted; synthetic tests only, no game files.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T13:48:43Z.
Review: APPROVED
Tested merged cleanly onto
main(ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC, NVIDIA RTX 5090):cargo test -p victory-gpu --features diagnostics: 54 passed, 0 failed, 1 ignored (includingtexture::tests::upload_slice_stops_at_the_end_of_the_buffer)cargo clippy -p victory-gpu --features diagnostics --all-targets: 0 warningscargo xtask policy: okGood safety fix: bounding both capture readback slices (
buffer.GetDesc().Width) and upload staging slices (footprint_len) to the allocated buffer size prevents overrunning past the last row's active bytes returned byGetCopyableFootprints. (Tiny non-blocking nit:buffer_size.saturating_sub(footprint.Offset)infootprint_lenwould guard against a hypothetical bad offset too.) Approving.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Yaekai on 2026-11-24T16:02:40Z.
Independent test & review on Windows 11 + NVIDIA RTX 3070 (Rust 1.98.1) at head
4899516:cargo test -p victory-gpu --lib: 44 passed, 0 failed (includingupload_slice_stops_at_the_end_of_the_buffer).cargo clippy -p victory-gpu -- -D warnings: 0 warnings.footprint_len(): usingbuffer_size.saturating_sub(footprint.Offset)instead ofbuffer_size - footprint.Offsetavoids an underflow panic if a footprint offset ever exceedsbuffer_size.Clean fix for the last-row staging/readback overread — looks ready to merge!
Imported from Marvisak/VIctory. Originally posted by AwsAli05 on 2026-11-24T20:18:05Z.
Thanks for the independent checks. I addressed the out-of-range offset in
839be49. The slice length now uses saturating subtraction, and staging rejects a footprint at or beyond the buffer end before forming a pointer or recording a copy. The regression checks both boundary offsets as well as the two original mips.On the branch merged with current main, the diagnostics suite passed 54 tests with one ignored benchmark. GPU Clippy passed with all targets and features.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:30:17Z.
Automated triage for the maintainers.
Still a merge candidate. The only push since the last triage is
75135d7, a merge of currentmain. The PR's own diff is unchanged: the samesubresource_lenbound for the diagnosticsnote_readrange intexture.rs::copies, the out-of-range footprint rejection instaging, and readback slices sized by the buffer'sWidthincapture.rs(save_read_back,dump_one), plus the device-backed BC4 test. The branch merges cleanly into currentmain, and CI (check) passes on this head.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by tyr0nsur on 2026-11-25T01:49:00Z.
An 8×4 BC4_UNORM texture with two mips gives a useful hardware case for the rebase. I called
GetCopyableFootprintsonmain@940d32fon Windows 11 build 26300, desktop RTX 4060, NVIDIA driver 32.0.16.2114. Offsets were[0, 512], row counts[1, 1], row sizes[16, 8], and the entire upload allocation was 520 bytes.Staging::detilealready returns the correct 8 bytes for the last mip on main. Therecorddiagnostic still computes 256 bytes for that mip, so its reported read extends 248 bytes past the allocation. Using the same bound fornote_readwould bring the trace into line with the copy. Diagnostic calculation on the tested revisionOne locally added device-footprint test passed on that exact main revision with production code unchanged. The linked fixture contains the descriptor and D3D12 query. AI-assisted test and report (Codex). Reproducible BC4 fixture
Imported from Marvisak/VIctory. Originally posted by AwsAli05 on 2026-11-25T05:05:56Z.
Thanks for the measured BC4 case. On current main the PR applies the same bounded length to
note_readand the CPU upload. Commit9235ae1adds an 8×4 BC4 check that queries D3D12 and verifies that the last mip ends after its 8 active bytes. All three texture tests passed on an RTX 5070 Ti.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:20:47Z.
Code review and RTX 5090 + WARP verification at head
75135d7a0448merged cleanly ontomain(63bcca43c6a0):crates/victory-gpu/src/texture.rs:442-448, 697-701, 748-754, 831-834,capture.rs:220-222, 552):subresource_lenclampspitch.saturating_mul(rows).saturating_mul(depth)tototal.saturating_sub(offset), preventing out-of-bounds reads/writes on the unpadded final row of the last subresource (including 3D depth slices and compressed BC mips whereRowPitch > row_bytes), andstagingvalidatesf.Offset < totalacross all footprints before buildingStaging.capture.rs(save_read_back/dump_one) bounds mapped slices tobuffer.GetDesc().Width as usizerather thanRowPitch * Height.VICTORY_D3D12_DEBUG=1, Rust 1.98.1):cargo xtask policy:191 files ok;cargo clippy -p victory-gpu --all-targets -- -D warnings(default +--features diagnostics): 0 warningstexture:: capture::): 3/3 passed; WARP (--features diagnostics,texture:: capture::): 14/14 passed (includingsubresource_len_stays_inside_staging_totalandlast_bc4_mip_ends_after_the_active_block).LGTM.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.