GPU: placed copies take the bytes a GPU write leaves in their memory #1724

Closed
Nixitov wants to merge 2 commits from upstream-pr/1725 into main
Nixitov commented 2026-11-24 21:24:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Nixitov on 2026-11-24T21:24:13Z.


A texture the title places in its own memory is read through a placed view whose DXGI format differs from the format of the resource that writes it: the fog volumes are written as R32_UINT through a UAV and sampled as the console's packed R9G9B9E5 through a placed SRV. The host makes one texture per (address, description), so those are two host textures here, and the reader's copy never receives what the GPU wrote.

The console is allowed this because the format lives in the view and the shader packs RGBE by hand; nothing in title memory changes between the write and the read.

Before. sky_scattering:CS_AerialPerspectiveVolumes wrote the volumes and scattering_transmittance_system:CS_Gather_Classified_0 sampled them empty: density 0, transmittance 1.0, and the shader marched to its own 9999-iteration cap. That was 83.99 ms a dispatch, 280-320 ms a frame, 67 % of the GPU frame, and the frame washed white.

After. On the first bind of a placed copy that another resource at the same title address writes (same size, texel width and mip count, a different format, a UAV), the reader's list copies the writer's host texture into it through a staging buffer, with the writer's format at one end and the placed copy's at the other, since the host refuses a texture copy between the two families. The writer comes from a by-address map of title textures with host copies, filled at creation and emptied at release. The copy is recorded before the draw or dispatch that reads it, once per list and placed copy, and replaces the upload of title memory that holds none of the bytes. VICTORY_PLACED_SYNC=0 turns it off, and the frame line counts the copies.

Same dispatch: 0.2 ms. Five 80x45x64 volumes (1.47 MB each) synced from f42 to f67, the white wash is gone, about 30 ms a frame better, and the texture-upload time in steady state is halved.

Hardening (83c7bb4). The staged copy took the pair's footprints from a cache keyed by the two host textures' addresses. A released host texture's address comes back for another one and the old footprints then describe the wrong pair — a copy past the buffer's end, or between a format a texture no longer has — which is an invalid command the host answers with device removal (the one DRED stop seen at CopyTextureRegion). The cell now carries the descriptions it was made for and is remade when either differs. Both ends must be single-sample textures of one dimension in the plain layout, with formats the adapter can copy as a texture of that dimension (CheckFeatureSupport) and the same texel size; each end's footprints are taken and must lie in the same places, inside the buffer, or nothing is recorded. Each copy names a box inside both textures' subresource at that mip and uses the host's row sizes for 3D textures. Both host copies and the staging buffer are held across the recording and kept by the list until it is reset.

The experiment worth skipping. Making one resource per address instead of one per (address, description) does not work: D3D12 refuses a view of the other format family and the device is removed.

Not covered. Placed UAV views, directly indexed (non-table) reads, and a single pre-change DRED report that named CopyTextureRegion and was never reproduced once the guards above were in.

Tested

RTX 5070, Windows 11 26200.9974, driver 617.14. Base main ffe310e:

  • cargo build --release -p victory: clean.
  • cargo test --release -p victory-gpu: 52 passed, 1 ignored, including resource::tests::a_placed_copy_takes_the_bytes_of_its_writer (a write through the R32 UAV read back through the placed copy as the same values) and texture::tests::a_placed_copy_is_staged_only_between_the_same_texels (the buffer layout's same-texels-only rule).
  • cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features: clean.

No game data.

AI-assisted (DeepSeek V4.1 Flash coding agent).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6591708736 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1725). Originally posted by [Nixitov](https://github.com/Nixitov) on 2026-11-24T21:24:13Z. --- A texture the title places in its own memory is read through a placed view whose DXGI format differs from the format of the resource that writes it: the fog volumes are written as `R32_UINT` through a UAV and sampled as the console's packed `R9G9B9E5` through a placed SRV. The host makes one texture per (address, description), so those are two host textures here, and the reader's copy never receives what the GPU wrote. The console is allowed this because the format lives in the view and the shader packs RGBE by hand; nothing in title memory changes between the write and the read. **Before.** `sky_scattering:CS_AerialPerspectiveVolumes` wrote the volumes and `scattering_transmittance_system:CS_Gather_Classified_0` sampled them empty: density 0, transmittance 1.0, and the shader marched to its own 9999-iteration cap. That was 83.99 ms a dispatch, 280-320 ms a frame, 67 % of the GPU frame, and the frame washed white. **After.** On the first bind of a placed copy that another resource at the same title address writes (same size, texel width and mip count, a different format, a UAV), the reader's list copies the writer's host texture into it through a staging buffer, with the writer's format at one end and the placed copy's at the other, since the host refuses a texture copy between the two families. The writer comes from a by-address map of title textures with host copies, filled at creation and emptied at release. The copy is recorded before the draw or dispatch that reads it, once per list and placed copy, and replaces the upload of title memory that holds none of the bytes. `VICTORY_PLACED_SYNC=0` turns it off, and the frame line counts the copies. Same dispatch: 0.2 ms. Five 80x45x64 volumes (1.47 MB each) synced from f42 to f67, the white wash is gone, about 30 ms a frame better, and the texture-upload time in steady state is halved. **Hardening (`83c7bb4`).** The staged copy took the pair's footprints from a cache keyed by the two host textures' addresses. A released host texture's address comes back for another one and the old footprints then describe the wrong pair — a copy past the buffer's end, or between a format a texture no longer has — which is an invalid command the host answers with device removal (the one DRED stop seen at `CopyTextureRegion`). The cell now carries the descriptions it was made for and is remade when either differs. Both ends must be single-sample textures of one dimension in the plain layout, with formats the adapter can copy as a texture of that dimension (`CheckFeatureSupport`) and the same texel size; each end's footprints are taken and must lie in the same places, inside the buffer, or nothing is recorded. Each copy names a box inside both textures' subresource at that mip and uses the host's row sizes for 3D textures. Both host copies and the staging buffer are held across the recording and kept by the list until it is reset. **The experiment worth skipping.** Making one resource per address instead of one per (address, description) does not work: D3D12 refuses a view of the other format family and the device is removed. **Not covered.** Placed UAV views, directly indexed (non-table) reads, and a single pre-change DRED report that named `CopyTextureRegion` and was never reproduced once the guards above were in. ## Tested RTX 5070, Windows 11 26200.9974, driver 617.14. Base `main` `ffe310e`: - `cargo build --release -p victory`: clean. - `cargo test --release -p victory-gpu`: 52 passed, 1 ignored, including `resource::tests::a_placed_copy_takes_the_bytes_of_its_writer` (a write through the R32 UAV read back through the placed copy as the same values) and `texture::tests::a_placed_copy_is_staged_only_between_the_same_texels` (the buffer layout's same-texels-only rule). - `cargo clippy --workspace --all-targets --locked -- -D warnings`, with and without `--all-features`: clean. No game data. AI-assisted (DeepSeek V4.1 Flash coding agent).
catminou4 commented 2026-11-24 22:02:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T21:37:06Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Placed copies now take the bytes a GPU write leaves in their memory: transition_host/ensure_state_host/record_transition track per-resource state, writer_at finds the latest writer, and layout/row_bytes/placements compute texture footprints for the copy. There is a unit test (a_placed_copy_takes_the_bytes_of_its_writer) but it is Windows-gated with the rest of victory-gpu. 44K diff across draw/host/list/resource/texture — the state-tracking invariants (who owns a byte range when CPU and GPU writes interleave) need the Windows playability runs; statically the design follows the existing shadow-copy model.

<!-- greyfinch-sync:Marvisak/VIctory:review:6047812717 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1725#pullrequestreview-6047812717). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T21:37:06Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Placed copies now take the bytes a GPU write leaves in their memory: transition_host/ensure_state_host/record_transition track per-resource state, writer_at finds the latest writer, and layout/row_bytes/placements compute texture footprints for the copy. There is a unit test (a_placed_copy_takes_the_bytes_of_its_writer) but it is Windows-gated with the rest of victory-gpu. 44K diff across draw/host/list/resource/texture — the state-tracking invariants (who owns a byte range when CPU and GPU writes interleave) need the Windows playability runs; statically the design follows the existing shadow-copy model.
upstream-sync closed this pull request 2026-11-25 02:05:00 +00:00
Marvisak commented 2026-11-25 02:06:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:25:08Z.


Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

Already in main: a memory written as R32_UINT and sampled as R9G9B9E5 shares one host texture through castable formats, with alias copies where the host cannot cast (resource.rs shared_texture, texture.rs alias_copy, 13bbd6fe).

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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149525094 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1725#issuecomment-7149525094). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:25:08Z. --- Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. Already in main: a memory written as R32_UINT and sampled as R9G9B9E5 shares one host texture through castable formats, with alias copies where the host cannot cast (resource.rs shared_texture, texture.rs alias_copy, 13bbd6fe). 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.
Marvisak commented 2026-11-25 02:06:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:35:06Z.


Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-gpu/src/draw.rs, crates/victory-gpu/src/host.rs, crates/victory-gpu/src/resource.rs, crates/victory-gpu/src/texture.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149716268 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1725#issuecomment-7149716268). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:35:06Z. --- <!-- victory-triage v1 head=a6365c376b37418b69dea90e0c008b96a94419f0 verdict=needs-rebase at=2026-11-25T01:35:05Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-gpu/src/draw.rs`, `crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/resource.rs`, `crates/victory-gpu/src/texture.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!1724
No description provided.