GPU: prepare and upload only dirty texture bands (opt-in) #2358

Open
github-bot wants to merge 3 commits from github-bot/gh-2358 into main AGit
Owner

@⁠nicolasveilleux on GitHub · 2026-11-25 11:44 UTC · original
nicolasveilleux:perf/texture-upload-bands → main · +409 −18 · 3 files · 3 commits · open

What changes

When a tracked, single-mip 2D texture is reached through the descriptor heap, a sparse update can now read and detile only the affected tile rows and copy just that band to the GPU. The first upload, dense changes and unsupported layouts keep the existing full path. This is opt-in (VICTORY_TEXTURE_UPLOAD_BANDS=1) and off by default.

The scope is within a subresource. #1135 skips unaffected mips and slices on the CPU but still uploads the full texture. This PR does not change the eager upload timing addressed by #230 and #1891.

Validation

On Windows 11, RTX 2070 Super (driver 610.60), 24 paired runs of a synthetic 4096 × 4096 RGBA8 texture:

Sparse update Off On
End-to-end median 36.81 ms 1.37 ms
CPU preparation median 30.04 ms 0.91 ms
End-to-end p95 43.11 ms 1.96 ms
GPU upload 64 MiB 2 MiB

Timing includes the CPU write, preparation, and submission through queue completion. The partial path won 24/24 pairs. Dense updates kept the full 64 MiB copy in both modes (45.31 vs. 43.53 ms median). Full GPU readback matched expected bytes in both modes for both patterns. No game files or gameplay measurements.

  • Formats: 38 passed, 5 ignored. GPU: 145 passed, 2 ignored, with the same two descriptor/memory failures on the baseline. All six texture tests passed on hardware and WARP. Clippy (both crates, all features) and the asset-policy check passed.
  • Separately ran the synthetic #1891 regression: the same four outcomes (16/16, 0/16, 0/16, 16/16) on main (940d32f) and on this branch with bands off and on. The test was not included in this PR.

AI-assisted (OpenAI Codex).

**@⁠nicolasveilleux** on GitHub · 2026-11-25 11:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/2358) `nicolasveilleux:perf/texture-upload-bands` → `main` · +409 −18 · 3 files · 3 commits · open ## What changes When a tracked, single-mip 2D texture is reached through the descriptor heap, a sparse update can now read and detile only the affected tile rows and copy just that band to the GPU. The first upload, dense changes and unsupported layouts keep the existing full path. This is opt-in (`VICTORY_TEXTURE_UPLOAD_BANDS=1`) and off by default. The scope is within a subresource. #1135 skips unaffected mips and slices on the CPU but still uploads the full texture. This PR does not change the eager upload timing addressed by #230 and #1891. ## Validation On Windows 11, RTX 2070 Super (driver 610.60), 24 paired runs of a synthetic 4096 × 4096 RGBA8 texture: | Sparse update | Off | On | |---|---:|---:| | End-to-end median | 36.81 ms | 1.37 ms | | CPU preparation median | 30.04 ms | 0.91 ms | | End-to-end p95 | 43.11 ms | 1.96 ms | | GPU upload | 64 MiB | 2 MiB | Timing includes the CPU write, preparation, and submission through queue completion. The partial path won 24/24 pairs. Dense updates kept the full 64 MiB copy in both modes (45.31 vs. 43.53 ms median). Full GPU readback matched expected bytes in both modes for both patterns. No game files or gameplay measurements. - Formats: 38 passed, 5 ignored. GPU: 145 passed, 2 ignored, with the same two descriptor/memory failures on the baseline. All six texture tests passed on hardware and WARP. Clippy (both crates, all features) and the asset-policy check passed. - Separately ran the [synthetic #1891 regression](https://git.gtahub.st/github/Marvisak--VIctory/issues/1891): the same four outcomes (16/16, 0/16, 0/16, 16/16) on `main` (`940d32f`) and on this branch with bands off and on. The test was not included in this PR. AI-assisted (OpenAI Codex).
Keep full copies for the first upload and ineligible layouts. Use tracked tile-row ranges only for bindless uploads, and validate the D3D12 copy with synthetic readback.
Read the complete tiled row band and detile into only those staging rows. Keep the full fallback and validate band bounds and pixel parity for linear, swizzled and block-compressed layouts.
Port optional bands to the submission upload pass and allocate a compact aligned footprint from the staging pool. Retain full uploads on first use and for unsupported or dense updates. Validate RGBA8 and padded BC3 by reading back the entire texture, including two bands in the same submission.

AI-assisted (OpenAI Codex).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:03:22 +00:00
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-25 11:51 UTC · original

I adapted the GPU band-copy fixture on 8da78cf to a 260×516 BC3 texture with a padded row pitch. A dirty page at the bottom selected texel rows 512..516, exactly one BC3 block row.

On native Windows with an RTX 4070 Ti (621.01) and WARP, the full readback matched on both adapters: the last block row held the new pattern, and all 128 preceding block rows kept their original bytes.

This exercises dirty_band and the GPU copy with prefilled staging data. Synthetic only.

AI-assisted with Codex.

**@⁠DrDarkDK** on GitHub · 2026-11-25 11:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2358#issuecomment-7161591339) I adapted the GPU band-copy fixture on `8da78cf` to a 260×516 BC3 texture with a padded row pitch. A dirty page at the bottom selected texel rows `512..516`, exactly one BC3 block row. On native Windows with an RTX 4070 Ti (621.01) and WARP, the full readback matched on both adapters: the last block row held the new pattern, and all 128 preceding block rows kept their original bytes. This exercises `dirty_band` and the GPU copy with prefilled staging data. Synthetic only. *AI-assisted with Codex.*
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:34 UTC · original · edited 2026-11-25 16:19 UTC

Automated triage for the maintainers.

Recommendation: merge candidate (rebased; reviewed again against current main).

With VICTORY_TEXTURE_UPLOAD_BANDS=1, a later sparse change to a tracked single-mip, single-slice 2D texture is uploaded differently. Only the tile rows covering the dirty byte envelope are read and detiled (texture.rs: dirty_band, Staging::detile_band), and one boxed CopyTextureRegion copies them (record_band). The first upload, dense changes (more than half the height), mip tails and other layouts keep the existing full path. Default behaviour is unchanged.

I checked these points:

  • The band is conservative: it covers whole rows of swizzle blocks, so a dirty byte can only widen it.
  • Layout::detile_rows reuses walk with a row range and keeps the existing callers on None. Its new test compares a band with a full detile for linear, 4 KB and 64 KB swizzles.
  • After a band upload, last.hashes is cleared, so the next full refresh redetiles everything.

CI check passes on this head. A synthetic BC3 check was independently confirmed in the thread.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2358#issuecomment-7167040960) · edited 2026-11-25 16:19 UTC <!-- victory-triage v1 head=3159aa41703dcc55ee17a3958464d9d82aee8a43 verdict=merge-candidate at=2026-11-25T16:19:02Z --> Automated triage for the maintainers. Recommendation: **merge candidate** (rebased; reviewed again against current `main`). With `VICTORY_TEXTURE_UPLOAD_BANDS=1`, a later sparse change to a tracked single-mip, single-slice 2D texture is uploaded differently. Only the tile rows covering the dirty byte envelope are read and detiled (`texture.rs`: `dirty_band`, `Staging::detile_band`), and one boxed `CopyTextureRegion` copies them (`record_band`). The first upload, dense changes (more than half the height), mip tails and other layouts keep the existing full path. Default behaviour is unchanged. I checked these points: - The band is conservative: it covers whole rows of swizzle blocks, so a dirty byte can only widen it. - `Layout::detile_rows` reuses `walk` with a row range and keeps the existing callers on `None`. Its new test compares a band with a full detile for linear, 4 KB and 64 KB swizzles. - After a band upload, `last.hashes` is cleared, so the next full refresh redetiles everything. CI `check` passes on this head. A synthetic BC3 check was independently confirmed in the thread. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠CocoBeans64 on GitHub · 2026-11-25 19:29 UTC · original

Native Windows run as asked, on Windows 10 22H2 (19045), RX 6800 XT (driver 32.0.21045.5002), Ryzen 7 7800X3D. The PR is merged with #2358 on 13f91ca, plus an Agility SDK runtime (#84), diag build.
cargo test -p victory-gpu: 201 passed, 1 failed. The failure, a_texture_written_in_one_format_reads_in_another_through_a_placed_view, fails the same way on 13f91ca without the PR (#1999).
Benchmark: the same saved game in the prologue, menus by hand, then a scripted camera loop. The figures cover the 300 s after the world shows. Two runs per side:

fps (median) ms/frame (mean) preparing copies GPU copying back
13f91ca 1.5 / 1.5 877 / 773 318 / 297 183 / 147 234 / 198 175 / 177
+ #1884 + #2358 1.6 / 1.5 757 / 764 305 / 289 166 / 152 191 / 196 166 / 156

Two identical baseline runs differ by about 6 % in mean frame time.
With VICTORY_TEXTURE_UPLOAD_BANDS=1, texture preparation in the world drops from 43 to 37 ms per frame (−15 %). The worst frame of a manual run fell from 1.3 s to 0.5 s. Overall fps does not change measurably, because textures are about 5 % of the frame here.

**@⁠CocoBeans64** on GitHub · 2026-11-25 19:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2358#issuecomment-7172380364) Native Windows run as asked, on Windows 10 22H2 (19045), RX 6800 XT (driver 32.0.21045.5002), Ryzen 7 7800X3D. The PR is merged with #2358 on `13f91ca`, plus an Agility SDK runtime (#84), diag build. `cargo test -p victory-gpu`: 201 passed, 1 failed. The failure, `a_texture_written_in_one_format_reads_in_another_through_a_placed_view`, fails the same way on `13f91ca` without the PR (#1999). Benchmark: the same saved game in the prologue, menus by hand, then a scripted camera loop. The figures cover the 300 s after the world shows. Two runs per side: | | fps (median) | ms/frame (mean) | preparing | copies | GPU | copying back | |---|---|---|---|---|---|---| | `13f91ca` | 1.5 / 1.5 | 877 / 773 | 318 / 297 | 183 / 147 | 234 / 198 | 175 / 177 | | + #1884 + #2358 | 1.6 / 1.5 | 757 / 764 | 305 / 289 | 166 / 152 | 191 / 196 | 166 / 156 | Two identical baseline runs differ by about 6 % in mean frame time. With `VICTORY_TEXTURE_UPLOAD_BANDS=1`, texture preparation in the world drops from 43 to 37 ms per frame (−15 %). The worst frame of a manual run fell from 1.3 s to 0.5 s. Overall fps does not change measurably, because textures are about 5 % of the frame here.
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 11:52 UTC · original · reviewed

Prepare and upload only dirty texture bands (opt-in VICTORY_TEXTURE_UPLOAD_BANDS): detile_rows partial detiling in victory-formats + GPU wiring (+523). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. The formats-side detile_rows is the portable part — being batch-tested on macOS now, will follow up.

**@⁠catminou4** on GitHub · 2026-11-25 11:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2358#pullrequestreview-6057090870) · **reviewed** Prepare and upload only dirty texture bands (opt-in VICTORY_TEXTURE_UPLOAD_BANDS): detile_rows partial detiling in victory-formats + GPU wiring (+523). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. The formats-side detile_rows is the portable part — being batch-tested on macOS now, will follow up.
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 11:56 UTC · original · reviewed

Follow-up to my earlier static note: the victory-formats side (detile_rows partial detiling) tested locally — merged into main 940d32f69b, cargo test -p victory-formats --locked on macOS arm64: 38 passed, 0 failed, 5 ignored. The portable detiling math is green; the GPU upload wiring remains Windows-only (static).

**@⁠catminou4** on GitHub · 2026-11-25 11:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/2358#pullrequestreview-6057148551) · **reviewed** Follow-up to my earlier static note: the victory-formats side (`detile_rows` partial detiling) tested locally — merged into main 940d32f69b, `cargo test -p victory-formats --locked` on macOS arm64: 38 passed, 0 failed, 5 ignored. The portable detiling math is green; the GPU upload wiring remains Windows-only (static).
Author
Owner

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

Reviewed 3159aa41703d merged cleanly onto 63bcca43.

The opt-in dirty row-band upload path (VICTORY_TEXTURE_UPLOAD_BANDS=1, off by default) is carefully bounded and mathematically sound:

  • victory-formats (crates/victory-formats/src/texture.rs:622-638, 656-735): Layout::detile_rows restricts to single-mip, single-slice 2D textures, validates !rows.is_empty() && rows.end <= m.height, computes exact compact slice_bytes for rows.len(), and shifts linear_row by y - rows.start while indexing tiled from its original origin.
  • Conservative band mapping (crates/victory-gpu/src/texture.rs:512-550, 796-821): Restricting dirty_band to addressable, single-mip, single-slice, single-sample, non-tail, block-aligned 2D textures guarantees via Layout::row/column that every texel in element rows first * group_rows .. end * group_rows lies strictly inside m.offset + first * stride .. m.offset + end * stride. detile_band suballocates from staging_space (512-byte aligned offsets) with block-aligned Footprint.Height and destination top.
  • Full-upload & cache invariants (texture.rs:683-697, 749): Requiring last.full_prepared && self.uploads != 0 ensures a band copy never runs before a complete initial upload (or after a failed full detile or eviction/recreation of HostTexture), and clearing last.hashes.fill(None) after a band upload guarantees a subsequent full fallback re-uploads rather than hitting a stale hash.

Hardware & D3D12 Debug Layer verification (RTX 5090 + Microsoft WARP, VICTORY_D3D12_DEBUG=1):

  • cargo xtask policy and cargo clippy --locked -p victory-formats -p victory-gpu --all-targets -- -D warnings (default and --all-features) pass cleanly.
  • cargo test --locked -p victory-formats passes 47/47 (including compact_detile_rows_match_the_same_rows_from_a_full_detile), and cargo test --locked -p victory-gpu texture::tests:: -- --test-threads=1 passes on both RTX 5090 and WARP under VICTORY_D3D12_DEBUG=1.
  • Verified an additional GPU readback probe under VICTORY_D3D12_DEBUG=1 comparing bands OFF vs ON byte-for-byte across Swizzle::LINEAR 256x512 RGBA8, Swizzle::SW_4KB_S 256x512 RGBA8, and Swizzle::SW_64KB_D 516x1028 BC1 (8-byte 4x4 blocks) through top-row band -> bottom-row band -> far-span (>50%) full fallback, plus dirty_band == None checks for non-block-multiple 258x514 BC3, multi-mip, 2-slice array, empty range, and full-span range: exact row-by-row byte match and host.log_messages() == None on both RTX 5090 and WARP.
  • Verified clean 3-way co-merge with #2314 and #2319 on 63bcca43.

LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 19:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/2358#pullrequestreview-6079268147) · **approved these changes** Reviewed `3159aa41703d` merged cleanly onto `63bcca43`. The opt-in dirty row-band upload path (`VICTORY_TEXTURE_UPLOAD_BANDS=1`, off by default) is carefully bounded and mathematically sound: - **`victory-formats` (`crates/victory-formats/src/texture.rs:622-638`, `656-735`)**: `Layout::detile_rows` restricts to single-mip, single-slice 2D textures, validates `!rows.is_empty() && rows.end <= m.height`, computes exact compact `slice_bytes` for `rows.len()`, and shifts `linear_row` by `y - rows.start` while indexing `tiled` from its original origin. - **Conservative band mapping (`crates/victory-gpu/src/texture.rs:512-550`, `796-821`)**: Restricting `dirty_band` to addressable, single-mip, single-slice, single-sample, non-tail, block-aligned 2D textures guarantees via `Layout::row`/`column` that every texel in element rows `first * group_rows .. end * group_rows` lies strictly inside `m.offset + first * stride .. m.offset + end * stride`. `detile_band` suballocates from `staging_space` (512-byte aligned offsets) with block-aligned `Footprint.Height` and destination `top`. - **Full-upload & cache invariants (`texture.rs:683-697`, `749`)**: Requiring `last.full_prepared && self.uploads != 0` ensures a band copy never runs before a complete initial upload (or after a failed full `detile` or eviction/recreation of `HostTexture`), and clearing `last.hashes.fill(None)` after a band upload guarantees a subsequent full fallback re-uploads rather than hitting a stale hash. **Hardware & D3D12 Debug Layer verification** (RTX 5090 + Microsoft WARP, `VICTORY_D3D12_DEBUG=1`): - `cargo xtask policy` and `cargo clippy --locked -p victory-formats -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`) pass cleanly. - `cargo test --locked -p victory-formats` passes 47/47 (including `compact_detile_rows_match_the_same_rows_from_a_full_detile`), and `cargo test --locked -p victory-gpu texture::tests:: -- --test-threads=1` passes on both RTX 5090 and WARP under `VICTORY_D3D12_DEBUG=1`. - Verified an additional GPU readback probe under `VICTORY_D3D12_DEBUG=1` comparing bands OFF vs ON byte-for-byte across `Swizzle::LINEAR` `256x512` RGBA8, `Swizzle::SW_4KB_S` `256x512` RGBA8, and `Swizzle::SW_64KB_D` `516x1028` BC1 (8-byte 4x4 blocks) through top-row band -> bottom-row band -> far-span (>50%) full fallback, plus `dirty_band == None` checks for non-block-multiple `258x514` BC3, multi-mip, 2-slice array, empty range, and full-span range: exact row-by-row byte match and `host.log_messages() == None` on both RTX 5090 and WARP. - Verified clean 3-way co-merge with `#2314` and `#2319` on `63bcca43`. LGTM.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/2358/head:github-bot/gh-2358'
git switch 'github-bot/gh-2358'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2358'
git switch 'github-bot/gh-2358'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2358'
git switch 'github-bot/gh-2358'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2358'
git switch 'main'
git merge --squash 'github-bot/gh-2358'
git switch 'main'
git merge --ff-only 'github-bot/gh-2358'
git switch 'main'
git merge 'github-bot/gh-2358'
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!2358
No description provided.