GPU: reserve upload space only for dirty texture subresources #3134

Open
yyc160 wants to merge 1 commit from upstream-pr/3136 into main
yyc160 commented 2026-11-26 09:43:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by yyc160 on 2026-11-26T09:43:59Z.


The texture refresh already detiles and copies just the subresources affected by a write (#1135). It still takes upload space for the entire texture on every refresh. A burst of updates to small mips therefore leaves most of multiple 32 MiB upload chunks unused.

This change packs the selected footprints in subresource order. The detiler and CopyTextureRegion use the same offsets; a footprint keeps the driver's placement padding and the final footprint keeps its short final row. Full uploads keep their original size. It changes neither texture residency nor which mips are sampled, and it does not discard uploads, add a queue or change any fence.

Measurement

Windows, physical GeForce RTX 5070 Ti (10de:2c05), one process per arm. Synthetic 2048x2048 RGBA8, 12 mips, 12 calls to the actual detiler in one upload burst before recycling. The selected mip was 256x256. Counted distinct D3D12 staging resources and summed GetDesc().Width:

Subresources per update main This change
Mip 3 only 12 chunks / 384 MiB 1 chunk / 32 MiB
All 12 mips 12 chunks / 384 MiB 12 chunks / 384 MiB

For the partial case, the change in Windows private bytes was 384.75 versus 32.06 MiB. DXGI non-local usage increased by 384 versus 32 MiB, local usage by zero in both. The measurement excludes the input buffer, created before the baseline in each process. This is an upload burst, not a game memory or FPS benchmark.

Tests

  • Hardware readback checks both mip 0 (unchanged) and mip 1 (updated) of a two-mip texture. A layout test covers non-contiguous slices, the last slice alone and a full upload.
  • cargo clippy --workspace --all-targets --locked -- -D warnings and the --all-features variant pass; cargo xtask policy passes.
  • cargo test --workspace --locked --offline --profile diag stops on two NVIDIA heap assertions in victory-gpu: dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views. Both fail with the same assertions on unmodified 63bcca4. In the patched GPU suite 230 passed, 2 failed and 1 was ignored. The four targeted tests also pass with diagnostics.

AI-assisted by GPT-6.2 Astra.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5507646624 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3136). Originally posted by [yyc160](https://github.com/yyc160) on 2026-11-26T09:43:59Z. --- The texture refresh already detiles and copies just the subresources affected by a write (#1135). It still takes upload space for the *entire texture* on every refresh. A burst of updates to small mips therefore leaves most of multiple 32 MiB upload chunks unused. This change packs the selected footprints in subresource order. The detiler and `CopyTextureRegion` use the same offsets; a footprint keeps the driver's placement padding and the final footprint keeps its short final row. Full uploads keep their original size. It changes neither texture residency nor which mips are sampled, and it does not discard uploads, add a queue or change any fence. ### Measurement Windows, physical GeForce RTX 5070 Ti (`10de:2c05`), one process per arm. Synthetic 2048x2048 RGBA8, 12 mips, 12 calls to the actual detiler in one upload burst before recycling. The selected mip was 256x256. Counted distinct D3D12 staging resources and summed `GetDesc().Width`: | Subresources per update | main | This change | | --- | ---: | ---: | | Mip 3 only | 12 chunks / 384 MiB | 1 chunk / 32 MiB | | All 12 mips | 12 chunks / 384 MiB | 12 chunks / 384 MiB | For the partial case, the change in Windows private bytes was 384.75 versus 32.06 MiB. DXGI non-local usage increased by 384 versus 32 MiB, local usage by zero in both. The measurement excludes the input buffer, created before the baseline in each process. This is an upload burst, not a game memory or FPS benchmark. ### Tests - Hardware readback checks both mip 0 (unchanged) and mip 1 (updated) of a two-mip texture. A layout test covers non-contiguous slices, the last slice alone and a full upload. - `cargo clippy --workspace --all-targets --locked -- -D warnings` and the `--all-features` variant pass; `cargo xtask policy` passes. - `cargo test --workspace --locked --offline --profile diag` stops on two NVIDIA heap assertions in `victory-gpu`: `dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`. Both fail with the same assertions on unmodified `63bcca4`. In the patched GPU suite 230 passed, 2 failed and 1 was ignored. The four targeted tests also pass with `diagnostics`. AI-assisted by GPT-6.2 Astra.
smaxxey commented 2026-11-26 11:03:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by smaxxey on 2026-11-26T10:13:21Z.


Ran this on an RTX 4060 Laptop GPU (Ada, 8 GB, driver 32.0.16.1742), Windows 11 26300, Rust 1.98.1. No game files. Head 656a143 merged locally onto main 63bcca4.

  • draw::tests::a_write_into_one_mip_uploads_that_mip_alone passes on the hardware device, with the new check that mip 1 reads back 128/255. The two texture::tests cases pass too.
  • cargo test -p victory-gpu --lib --locked: 230 passed, 2 failed, same as main 63bcca4 on this card: only the two NVIDIA failures of #1835 (descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views), nothing new.

Tested with Claude Code's help.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7189072177 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3136#issuecomment-7189072177). Originally posted by [smaxxey](https://github.com/smaxxey) on 2026-11-26T10:13:21Z. --- Ran this on an **RTX 4060 Laptop GPU** (Ada, 8 GB, driver 32.0.16.1742), Windows 11 26300, Rust 1.98.1. No game files. Head `656a143` merged locally onto `main` 63bcca4. - `draw::tests::a_write_into_one_mip_uploads_that_mip_alone` passes on the hardware device, with the new check that mip 1 reads back `128/255`. The two `texture::tests` cases pass too. - `cargo test -p victory-gpu --lib --locked`: 230 passed, 2 failed, same as `main` 63bcca4 on this card: only the two NVIDIA failures of #1835 (`descriptor::host::tests::dynamic_slots_are_held_until_released`, `memory::tests::lists_share_a_table_and_copies_keep_their_views`), nothing new. Tested with Claude Code's help.
steven-seagull27 commented 2026-11-26 12:05:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T11:18:07Z.


For anyone taking #3174 alongside this change, the tested merge keeps the packed offsets and passes the packed size to the retry-aware allocator. On the RTX 5080 and inbox WARP the retry reserved 128 KiB for nonadjacent slices 0 and 2, kept slice 1 intact, and recovered all 49,152 destination texels. Falling back to a full-texture reservation preserved the pixels but requested 192 KiB. Merge, regression and both controls on #3174

<!-- greyfinch-sync:Marvisak/VIctory:comment:7190549691 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3136#issuecomment-7190549691). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-26T11:18:07Z. --- For anyone taking #3174 alongside this change, the tested merge keeps the packed offsets and passes the packed size to the retry-aware allocator. On the RTX 5080 and inbox WARP the retry reserved 128 KiB for nonadjacent slices 0 and 2, kept slice 1 intact, and recovered all 49,152 destination texels. Falling back to a full-texture reservation preserved the pixels but requested 192 KiB. [Merge, regression and both controls on #3174](https://github.com/Marvisak/VIctory/pull/3174#issuecomment-7190543930)
Dukestar69 commented 2026-11-26 12:31:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T12:31:03Z.

Review: APPROVED


Verified on RTX 5090 against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib texture:: -- --test-threads=1: 3/3 passed (including sparse_upload_omits_clean_slices_and_keeps_the_short_last_row).
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly reserves staging upload space only for dirty texture subresources.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6074157514 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3136#pullrequestreview-6074157514). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T12:31:03Z. **Review:** APPROVED --- Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib texture:: -- --test-threads=1`: 3/3 passed (including `sparse_upload_omits_clean_slices_and_keeps_the_short_last_row`). - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 20/20 passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly reserves staging upload space only for dirty texture subresources. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
TheGrayOrange commented 2026-11-27 05:15:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TheGrayOrange on 2026-11-27T05:15:24Z.


I've completed and independently verified a local integration of #2985 and #3136, preserving both commit histories and using a shared packed footprint plan for detiling and GPU copies.

Verified on WARP and RTX 4070 Ti SUPER:

Fixture Staging reservation reduction Image comparison
RGBA8 sparse mips 19.0% Exact
BC1 partial bands 28.6% Exact
RGBA8 sparse array slices 33.3% Exact

Successive partial updates preserve untouched regions, and the CPU detiler and GPU copy use matching packed offsets. No integration-specific D3D12 validation errors were observed.

The combined branch is ready locally. Would you prefer that I publish it as an integration reference or provide the conflict-resolution changes separately?

Synthetic tests only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7210481313 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3136#issuecomment-7210481313). Originally posted by [TheGrayOrange](https://github.com/TheGrayOrange) on 2026-11-27T05:15:24Z. --- I've completed and independently verified a local integration of #2985 and #3136, preserving both commit histories and using a shared packed footprint plan for detiling and GPU copies. Verified on WARP and RTX 4070 Ti SUPER: | Fixture | Staging reservation reduction | Image comparison | |---|---:|---| | RGBA8 sparse mips | 19.0% | Exact | | BC1 partial bands | 28.6% | Exact | | RGBA8 sparse array slices | 33.3% | Exact | Successive partial updates preserve untouched regions, and the CPU detiler and GPU copy use matching packed offsets. No integration-specific D3D12 validation errors were observed. The combined branch is ready locally. Would you prefer that I publish it as an integration reference or provide the conflict-resolution changes separately? Synthetic tests only.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3136:upstream-pr/3136'
git switch 'upstream-pr/3136'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3136'
git switch 'upstream-pr/3136'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3136'
git switch 'upstream-pr/3136'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3136'
git switch 'main'
git merge --squash 'upstream-pr/3136'
git switch 'main'
git merge --ff-only 'upstream-pr/3136'
git switch 'main'
git merge 'upstream-pr/3136'
git push origin 'main'
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!3134
No description provided.