GPU: resolve initial texture uploads and host_written at submission (#1891) #1934

Open
github-bot wants to merge 1 commit from github-bot/gh-1934 into main AGit
Owner

@⁠zondy1i on GitHub · 2026-11-25 01:10 UTC · original
zondy1i:fix/texture-upload-recording-order → main · +500 −1 · 2 files · 1 commits · open

Fixes #1891.

Problem

f68442f (GPU: a texture a host copy writes is the host's from the copy's submission) moved texture::host_writes to submission time and made bindless::uploads skip textures already written by an earlier submission. One piece of #1891 remained: a partial CopyTextureRegion into a title_written texture 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: add is_partial_copy and call crate::texture::upload(list, dst.resource, &to) before crate::texture::host_writes(list, dst.resource) in copy_texture_region when to is title_written and the copy does not cover every texel of every subresource.
    • Because bindless::uploads runs before the submission's defer_host (host_writes) and skips textures already marked host_written by 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: add texture_uploads_follow_submission_order_not_recording_order covering:
    1. Overlapping 2×2 partial copies (both buffer and texture sources) into a 4×4 title_written texture, 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).
    2. Reverse-recorded read-after-write (list_b recorded before list_a, submitted [list_a, list_b]).
    3. Unsubmitted writer recorded before reader (reader still uploads initial title memory).
    4. Same-list read before buffer copy into the texture's backing memory.

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_released and memory::tests::lists_share_a_table_and_copies_keep_their_views — are pre-existing on main on this GPU due to the HEAP_VIEWS descriptor-heap size assertion).
**@⁠zondy1i** on GitHub · 2026-11-25 01:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1934) `zondy1i:fix/texture-upload-recording-order` → `main` · +500 −1 · 2 files · 1 commits · open Fixes #1891. ### Problem `f68442f` (`GPU: a texture a host copy writes is the host's from the copy's submission`) moved `texture::host_writes` to submission time and made `bindless::uploads` skip textures already written by an earlier submission. One piece of #1891 remained: a partial `CopyTextureRegion` into a `title_written` texture 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`**: add `is_partial_copy` and call `crate::texture::upload(list, dst.resource, &to)` before `crate::texture::host_writes(list, dst.resource)` in `copy_texture_region` when `to` is `title_written` and the copy does not cover every texel of every subresource. - Because `bindless::uploads` runs before the submission's `defer_host` (`host_writes`) and skips textures already marked `host_written` by 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`**: add `texture_uploads_follow_submission_order_not_recording_order` covering: 1. Overlapping 2×2 partial copies (both buffer and texture sources) into a 4×4 `title_written` texture, 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). 2. Reverse-recorded read-after-write (`list_b` recorded before `list_a`, submitted `[list_a, list_b]`). 3. Unsubmitted writer recorded before reader (reader still uploads initial title memory). 4. Same-list read before buffer copy into the texture's backing memory. ### 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_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views` — are pre-existing on `main` on this GPU due to the `HEAP_VIEWS` descriptor-heap size assertion).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:49:16 +00:00
Author
Owner

@⁠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 is copy_texture_region in crates/victory-gpu/src/list.rs: for a title_written destination, it now calls texture::upload before host_writes whenever is_partial_copy says 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 D3D12 CopyTextureRegion, which leaves texels outside the region untouched. upload skips a texture that is already is_host_written, and bindless.rs checks host_written again at submission. So the first partial copy keeps the title-memory background and later copies keep the GPU's texels, which is what texture_uploads_follow_submission_order_not_recording_order asserts. Optional tidy-up: check dst.kind == 0 before is_partial_copy, because for a footprint destination with a host buffer upload does nothing but uses up the list's first_use key.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 02:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1934#issuecomment-7150563976) · edited 2026-11-26 09:20 UTC <!-- victory-triage v1 head=a4a2dc4f858ad9c2c0c9f8873c61aa6b95267894 verdict=merge-candidate at=2026-11-26T09:22:00Z --> Automated triage for the maintainers. **Merge candidate (after the rebase onto `63bcca4`).** What is left is `copy_texture_region` in `crates/victory-gpu/src/list.rs`: for a `title_written` destination, it now calls `texture::upload` before `host_writes` whenever `is_partial_copy` says 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 D3D12 `CopyTextureRegion`, which leaves texels outside the region untouched. `upload` skips a texture that is already `is_host_written`, and `bindless.rs` checks `host_written` again at submission. So the first partial copy keeps the title-memory background and later copies keep the GPU's texels, which is what `texture_uploads_follow_submission_order_not_recording_order` asserts. Optional tidy-up: check `dst.kind == 0` before `is_partial_copy`, because for a footprint destination with a host buffer `upload` does nothing but uses up the list's `first_use` key. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠zondy1i on GitHub · 2026-11-25 06:34 UTC · original

Addressed both points in c07dcb7:

  1. Refresh position relative to same-list title-memory writes: Restored Step::Texture(Arc<HostTexture>, Arc<Staging>) in HostList::run_deferred, pushed from HostList::texture_read at the list's first read of the texture (before any later Step::Copy / Step::Run in the same list). At submission, Step::Texture checks !copy.host_written && batch.texture_due(staging) and refreshes staging at 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, recording CopyResource before CopyBufferRegion into 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.
  2. Already-current staging on first read: Added a Staging::needs_upload: AtomicBool flag (set whenever Staging::refresh detiles newer bytes, consumed by Staging::take_upload when a GPU copy is actually emitted in HostList::prelude or texture::upload_changed). That way:
    • If a texture's staging was already refreshed before any list uploaded it to the host texture (refresh() returns false), take_upload() is still true and the first reading list still emits the initial GPU upload (covered by case 5 of the regression test).
    • Once uploaded to the persistent host texture, subsequent lists that read the texture without title memory changing skip redundant GPU copies (and still observe the uploaded contents, also verified in case 5).

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_order passed on RTX 3060 Ti and WARP, both with and without VICTORY_D3D12_DEBUG=1
  • cargo clippy -p victory-gpu --no-deps --all-targets --locked and --all-features — clean
  • cargo test -p xtask --locked — 6/6 passed
**@⁠zondy1i** on GitHub · 2026-11-25 06:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/1934#issuecomment-7154926661) Addressed both points in `c07dcb7`: 1. **Refresh position relative to same-list title-memory writes:** Restored `Step::Texture(Arc<HostTexture>, Arc<Staging>)` in `HostList::run_deferred`, pushed from `HostList::texture_read` at the list's first read of the texture (before any later `Step::Copy` / `Step::Run` in the same list). At submission, `Step::Texture` checks `!copy.host_written && batch.texture_due(staging)` and refreshes `staging` at 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, recording `CopyResource` before `CopyBufferRegion` into 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. 2. **Already-current staging on first read:** Added a `Staging::needs_upload: AtomicBool` flag (set whenever `Staging::refresh` detiles newer bytes, consumed by `Staging::take_upload` when a GPU copy is actually emitted in `HostList::prelude` or `texture::upload_changed`). That way: - If a texture's staging was already refreshed before any list uploaded it to the host texture (`refresh()` returns `false`), `take_upload()` is still `true` and the first reading list still emits the initial GPU upload (covered by case 5 of the regression test). - Once uploaded to the persistent host texture, subsequent lists that read the texture without title memory changing skip redundant GPU copies (and still observe the uploaded contents, also verified in case 5). **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_order` passed on RTX 3060 Ti and WARP, both with and without `VICTORY_D3D12_DEBUG=1` - `cargo clippy -p victory-gpu --no-deps --all-targets --locked` and `--all-features` — clean - `cargo test -p xtask --locked` — 6/6 passed
github-bot force-pushed github-bot/gh-1934 from c07dcb71ce to a4a2dc4f85 2026-11-26 08:34:57 +00:00 Compare
Author
Owner

@⁠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.

**@⁠catminou4** on GitHub · 2026-11-25 02:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1934#pullrequestreview-6050612109) · **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.
Author
Owner

@⁠AndyLatimer on GitHub · 2026-11-25 10:29 UTC · original · reviewed

Tested c07dcb7 on 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:

  • Lists no longer re-copy unchanged textures. On 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 when refresh detiled new bytes (needs_upload). That is right as long as nothing but a host copy writes a title-written host texture. I checked: title_written leaves out target, depth and UAV textures (so UAV clears and twins don't apply). Outside tests, the other CopyTextureRegion/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 call host_written.
  • Overlap with #1547 (#758, title writes after a host copy). Merging #1547 on top of this conflicts in texture.rs. And it would need more than conflict resolution: here upload no longer reads host_written at recording time, and the flag is only read at submission (Step::Texture, the prelude's already_host, upload_changed). #1547 checks and clears it in upload at recording time (copy_host_written), so that check would have to move to those submission-side reads. Whichever lands second will need that rework.
**@⁠AndyLatimer** on GitHub · 2026-11-25 10:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1934#pullrequestreview-6055859972) · **reviewed** Tested `c07dcb7` on 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: - **Lists no longer re-copy unchanged textures.** On `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 when `refresh` detiled new bytes (`needs_upload`). That is right as long as nothing but a host copy writes a title-written host texture. I checked: `title_written` leaves out target, depth and UAV textures (so UAV clears and twins don't apply). Outside tests, the other `CopyTextureRegion`/`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 call `host_written`. - **Overlap with #1547** (#758, title writes after a host copy). Merging #1547 on top of this conflicts in `texture.rs`. And it would need more than conflict resolution: here `upload` no longer reads `host_written` at recording time, and the flag is only read at submission (`Step::Texture`, the prelude's `already_host`, `upload_changed`). #1547 checks and clears it in `upload` at recording time (`copy_host_written`), so that check would have to move to those submission-side reads. Whichever lands second will need that rework.
Author
Owner

@⁠zondy1i on GitHub · 2026-11-26 08:33 UTC · original

Rebased onto current main (63bcca4) in a4a2dc4.

Since f68442f already landed deferred texture::host_writes and submission-time host_written checks in bindless::uploads, the PR is now much smaller (2 files): it keeps only the is_partial_copy initial-background upload in list.rs::copy_texture_region (so partial copies into a title_written texture preserve untouched texels) plus the #1891 regression test texture_uploads_follow_submission_order_not_recording_order in resource.rs.

Verified locally: cargo clippy --workspace --all-targets -- -D warnings is clean and texture_uploads_follow_submission_order_not_recording_order passes.

**@⁠zondy1i** on GitHub · 2026-11-26 08:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1934#issuecomment-7186747886) Rebased onto current `main` (`63bcca4`) in `a4a2dc4`. Since `f68442f` already landed deferred `texture::host_writes` and submission-time `host_written` checks in `bindless::uploads`, the PR is now much smaller (2 files): it keeps only the `is_partial_copy` initial-background upload in `list.rs::copy_texture_region` (so partial copies into a `title_written` texture preserve untouched texels) plus the `#1891` regression test `texture_uploads_follow_submission_order_not_recording_order` in `resource.rs`. Verified locally: `cargo clippy --workspace --all-targets -- -D warnings` is clean and `texture_uploads_follow_submission_order_not_recording_order` passes.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 09:51 UTC · original · approved these changes

Reviewed a4a2dc4f (list.rs + resource.rs), clean git merge-tree against origin/main (63bcca43).

is_partial_copy is appropriately conservative across multi-subresource destinations, non-zero (x, y, z) offsets, explicit source_box subregions, smaller buffer footprints (src.kind == 1), multi-mip texture sources, and smaller texture sources, so initial title memory is queued for upload before a partial CopyTextureRegion while preserving submission-order host_written semantics. The 4-scenario regression test in resource.rs covers buffer and texture sources in both recording orders, reverse-recorded RAW/WAR, and same-list read before CopyBufferRegion.

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 ok
  • RTX 5090 resource::tests::: 19/19 passed
  • RTX 5090 + VICTORY_D3D12_DEBUG=1 texture_uploads_follow_submission_order_not_recording_order: passed
  • WARP (--features diagnostics, VICTORY_D3D12_WARP=1) + VICTORY_D3D12_DEBUG=1 resource::tests::: 19/19 passed

One minor non-blocking note: for 2-plane formats (e.g. NV12 or depth/stencil), MipLevels * DepthOrArraySize can be 1 while a single CopyTextureRegion writes only one plane; checking plane count could cover that if planar partial copies ever rely on initial title memory.

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 09:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/1934#pullrequestreview-6071873183) · **approved these changes** Reviewed `a4a2dc4f` (`list.rs` + `resource.rs`), clean `git merge-tree` against `origin/main` (`63bcca43`). `is_partial_copy` is appropriately conservative across multi-subresource destinations, non-zero `(x, y, z)` offsets, explicit `source_box` subregions, smaller buffer footprints (`src.kind == 1`), multi-mip texture sources, and smaller texture sources, so initial title memory is queued for upload before a partial `CopyTextureRegion` while preserving submission-order `host_written` semantics. The 4-scenario regression test in `resource.rs` covers buffer and texture sources in both recording orders, reverse-recorded RAW/WAR, and same-list read before `CopyBufferRegion`. 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 ok` - RTX 5090 `resource::tests::`: 19/19 passed - RTX 5090 + `VICTORY_D3D12_DEBUG=1` `texture_uploads_follow_submission_order_not_recording_order`: passed - WARP (`--features diagnostics`, `VICTORY_D3D12_WARP=1`) + `VICTORY_D3D12_DEBUG=1` `resource::tests::`: 19/19 passed One minor non-blocking note: for 2-plane formats (e.g. NV12 or depth/stencil), `MipLevels * DepthOrArraySize` can be `1` while a single `CopyTextureRegion` writes only one plane; checking plane count could cover that if planar partial copies ever rely on initial title memory. LGTM.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1934/head:github-bot/gh-1934'
git switch 'github-bot/gh-1934'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1934'
git switch 'github-bot/gh-1934'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1934'
git switch 'github-bot/gh-1934'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1934'
git switch 'main'
git merge --squash 'github-bot/gh-1934'
git switch 'main'
git merge --ff-only 'github-bot/gh-1934'
git switch 'main'
git merge 'github-bot/gh-1934'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1934
No description provided.