GPU: resolve initial texture uploads and host_written at submission (#1891) #1934
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!1934
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1934"
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?
@zondy1i on GitHub · 2026-11-25 01:10 UTC · original
zondy1i:fix/texture-upload-recording-order→main· +500 −1 · 2 files · 1 commits · openFixes #1891.
Problem
f68442f(GPU: a texture a host copy writes is the host's from the copy's submission) movedtexture::host_writesto submission time and madebindless::uploadsskip textures already written by an earlier submission. One piece of #1891 remained: a partialCopyTextureRegioninto atitle_writtentexture that has not yet been uploaded does not schedule an initial upload from title memory before the copy, leaving untouched texels / subresources uninitialized instead of preserving the initial title-memory background.Solution
crates/victory-gpu/src/list.rs: addis_partial_copyand callcrate::texture::upload(list, dst.resource, &to)beforecrate::texture::host_writes(list, dst.resource)incopy_texture_regionwhentoistitle_writtenand the copy does not cover every texel of every subresource.bindless::uploadsruns before the submission'sdefer_host(host_writes) and skips textures already markedhost_writtenby an earlier submission, a first partial copy uploads the initial title-memory background before writing its sub-region, while a second partial copy (even if recorded in reverse order) keeps the earlier submission's GPU texels.crates/victory-gpu/src/resource.rs: addtexture_uploads_follow_submission_order_not_recording_ordercovering:title_writtentexture, recorded both A-then-B and B-then-A and submitted A-then-B (all 16/16 pixels match: untouched background + A's 3 unique pixels + B's 4 pixels).list_brecorded beforelist_a, submitted[list_a, list_b]).Tested
cargo clippy --workspace --all-targets -- -D warnings: 0 warnings, 0 errors.cargo test -p victory-gpu texture_uploads_follow_submission_order_not_recording_order: 1 passed, 0 failed (RTX 3060 Ti, Windows 11, Rust 1.98.1).cargo test -p victory-gpu -- --test-threads=1: 230 passed, 2 failed, 1 ignored (the 2 failures —descriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views— are pre-existing onmainon this GPU due to theHEAP_VIEWSdescriptor-heap size assertion).@Marvisak on GitHub · 2026-11-25 02:18 UTC · original · edited 2026-11-26 09:20 UTC
Automated triage for the maintainers.
Merge candidate (after the rebase onto
63bcca4). What is left iscopy_texture_regionincrates/victory-gpu/src/list.rs: for atitle_writtendestination, it now callstexture::uploadbeforehost_writeswheneveris_partial_copysays the copy does not cover the whole texture (more than one subresource, a non-zero offset, or a box or footprint smaller than the destination). That matches D3D12CopyTextureRegion, which leaves texels outside the region untouched.uploadskips a texture that is alreadyis_host_written, andbindless.rscheckshost_writtenagain at submission. So the first partial copy keeps the title-memory background and later copies keep the GPU's texels, which is whattexture_uploads_follow_submission_order_not_recording_orderasserts. Optional tidy-up: checkdst.kind == 0beforeis_partial_copy, because for a footprint destination with a host bufferuploaddoes nothing but uses up the list'sfirst_usekey.CI:
checkpassing.Generated by Claude Code
@zondy1i on GitHub · 2026-11-25 06:34 UTC · original
Addressed both points in
c07dcb7:Step::Texture(Arc<HostTexture>, Arc<Staging>)inHostList::run_deferred, pushed fromHostList::texture_readat the list's first read of the texture (before any laterStep::Copy/Step::Runin the same list). At submission,Step::Texturechecks!copy.host_written && batch.texture_due(staging)and refreshesstagingat that step's position, before later deferred steps can overwrite the texture's title memory. Added a regression test (texture_uploads_follow_submission_order_not_recording_order, case 4) placing a texture and buffer on the same heap, recordingCopyResourcebeforeCopyBufferRegioninto the texture's memory in one list, and verifying that the first list observes pre-copy bytes while a subsequent list observes post-copy bytes.Staging::needs_upload: AtomicBoolflag (set wheneverStaging::refreshdetiles newer bytes, consumed byStaging::take_uploadwhen a GPU copy is actually emitted inHostList::preludeortexture::upload_changed). That way:refresh()returnsfalse),take_upload()is stilltrueand the first reading list still emits the initial GPU upload (covered by case 5 of the regression test).Verification:
VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics— 147 passed, 0 failed (2 ignored)texture_uploads_follow_submission_order_not_recording_orderpassed on RTX 3060 Ti and WARP, both with and withoutVICTORY_D3D12_DEBUG=1cargo clippy -p victory-gpu --no-deps --all-targets --lockedand--all-features— cleancargo test -p xtask --locked— 6/6 passedc07dcb71cetoa4a2dc4f85@catminou4 on GitHub · 2026-11-25 02:10 UTC · original · reviewed
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Initial texture uploads and host_written resolved at subresource…: upload-resolution fix.
@AndyLatimer on GitHub · 2026-11-25 10:29 UTC · original · reviewed
Tested
c07dcb7on Windows 11, NVIDIA, MSVC (rustc 1.98.1):texture_uploads_follow_submission_order_not_recording_order: 10/10 runs passed on hardware.cargo test -p victory-gpu --locked --no-fail-fast: 142 passed, 2 failed.main(940d32f) on this machine gives 141 passed and the same 2 failures (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views: the descriptor-heap cap assert from #1744/#1835).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean, default and--all-features.Two notes from reading the diff, beyond what the triage covered:
main, every list that samples a title texture records a staging-to-texture copy, whether the memory changed or not. Here the copy is made only whenrefreshdetiled new bytes (needs_upload). That is right as long as nothing but a host copy writes a title-written host texture. I checked:title_writtenleaves out target, depth and UAV textures (so UAV clears and twins don't apply). Outside tests, the otherCopyTextureRegion/CopyResource/Resolve*calls in the crate write buffers (readbacks, captures) or twins. The ones that write a title texture (copy_resource,copy_texture_region,resolve,alias_copy) all callhost_written.texture.rs. And it would need more than conflict resolution: hereuploadno longer readshost_writtenat recording time, and the flag is only read at submission (Step::Texture, the prelude'salready_host,upload_changed). #1547 checks and clears it inuploadat recording time (copy_host_written), so that check would have to move to those submission-side reads. Whichever lands second will need that rework.@zondy1i on GitHub · 2026-11-26 08:33 UTC · original
Rebased onto current
main(63bcca4) ina4a2dc4.Since
f68442falready landed deferredtexture::host_writesand submission-timehost_writtenchecks inbindless::uploads, the PR is now much smaller (2 files): it keeps only theis_partial_copyinitial-background upload inlist.rs::copy_texture_region(so partial copies into atitle_writtentexture preserve untouched texels) plus the#1891regression testtexture_uploads_follow_submission_order_not_recording_orderinresource.rs.Verified locally:
cargo clippy --workspace --all-targets -- -D warningsis clean andtexture_uploads_follow_submission_order_not_recording_orderpasses.@fuzeofficlal on GitHub · 2026-11-26 09:51 UTC · original · approved these changes
Reviewed
a4a2dc4f(list.rs+resource.rs), cleangit merge-treeagainstorigin/main(63bcca43).is_partial_copyis appropriately conservative across multi-subresource destinations, non-zero(x, y, z)offsets, explicitsource_boxsubregions, smaller buffer footprints (src.kind == 1), multi-mip texture sources, and smaller texture sources, so initial title memory is queued for upload before a partialCopyTextureRegionwhile preserving submission-orderhost_writtensemantics. The 4-scenario regression test inresource.rscovers buffer and texture sources in both recording orders, reverse-recorded RAW/WAR, and same-list read beforeCopyBufferRegion.Verified locally on Windows 11 (RTX 5090 + WARP +
VICTORY_D3D12_DEBUG=1):cargo clippy --workspace --all-targets [--all-features] -- -D warnings: clean;cargo xtask policy:191 files okresource::tests::: 19/19 passedVICTORY_D3D12_DEBUG=1texture_uploads_follow_submission_order_not_recording_order: passed--features diagnostics,VICTORY_D3D12_WARP=1) +VICTORY_D3D12_DEBUG=1resource::tests::: 19/19 passedOne minor non-blocking note: for 2-plane formats (e.g. NV12 or depth/stencil),
MipLevels * DepthOrArraySizecan be1while a singleCopyTextureRegionwrites only one plane; checking plane count could cover that if planar partial copies ever rely on initial title memory.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.