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

Closed
github-bot wants to merge 2 commits from gh-pr/1725/head into gh-pr/1725/base
Owner

@⁠Nixitov on GitHub · 2026-11-24 21:24 UTC · original
Nixitov:gpu/placed-copy → main · +939 −11 · 5 files · 2 commits · closed without merging

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).

**@⁠Nixitov** on GitHub · 2026-11-24 21:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/1725) `Nixitov:gpu/placed-copy` → `main` · +939 −11 · 5 files · 2 commits · closed without merging 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).
A texture the title placed in its own memory is read through a placed view
whose DXGI format differs from the format the resource that writes it has
(the fog volumes: written as R32 UAV, read as the console's packed
R9G9B9E5). The host makes one texture per (address, description), so the
reader's copy never saw the GPU's writes: the gather read an empty volume,
marched to its own iteration cap and cost ~84 ms a dispatch.

On the first bind of a placed copy that another resource at the same title
address writes (same size, texel width and mip count, 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 (the host refuses a texture copy between the two
families). The writer is found from a by-address map of title textures
with host copies, filled at creation and emptied at release. The copy is
recorded in the list 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.

Also: fix the draw test that built a victory_shader Container by value
(the field is private now), and count placed copies in the frame line.
The staged copy from a placed copy's writer 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,
formats and buffer size then describe the wrong pair: a copy past the
buffer's end, or between a format a texture no longer has, is an invalid
command the host answers with a device removal (the 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; the
footprints are taken at each end 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 (its own last row is not padded to the pitch).

The writer is skipped when it is the placed copy's own texture, at
another layout or texel size. Both host copies and the staging buffer are
held across the recording and kept by the list until it is reset, so a
concurrent release cannot free what the recorded copy names. A test
covers the same-texels-only rule for the buffer layout.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:42:50 +00:00
github-bot closed this pull request 2026-11-26 04:42:50 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:25 UTC · original

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** on GitHub · 2026-11-25 01:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/1725#issuecomment-7149525094) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:35 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 01:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/1725#issuecomment-7149716268) <!-- 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

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!1725
No description provided.