Skip to content

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

Open
nicolasveilleux wants to merge 3 commits into
Marvisak:mainfrom
nicolasveilleux:perf/texture-upload-bands
Open

nicolasveilleux wants to merge 3 commits into
Marvisak:mainfrom
nicolasveilleux:perf/texture-upload-bands

Conversation

@nicolasveilleux

Copy link
Copy Markdown

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

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

Copy link
Copy Markdown

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.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up to my earlier static note: the victory-formats side (detile_rows partial detiling) tested locally — merged into main 940d32f, 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).

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

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

Copy link
Copy Markdown

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.

AntoninMichelq added a commit to AntoninMichelq/VIctory-forkAMD that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants