GPU: refresh written-to textures by rows of layout blocks #4809

Closed
github-bot wants to merge 15 commits from github-bot/gh-4808 into main AGit
Owner

@⁠Jineggegg on GitHub · 2026-12-01 09:33 UTC · original
Jineggegg:texture-partial-update → main · +1100 −24 · 3 files · 15 commits · closed without merging

Based on main at e1251c31; one commit.

Problem

A title texture in write-watched memory is refreshed as a whole whenever any of its pages is written:

  • Staging::refresh_timed asks watch::writes_since only whether anything changed.
  • It then reads the whole texture through copy_mapped, and Staging::detile detiles every subresource.
  • The next list that samples the texture copies every subresource into the host texture (record_upload, CopyTextureRegion(..., None)).

So a title that streams a texture in, or draws into an atlas a page at a time, pays for the whole texture on every change. Take one 64 KiB page written into a 1024×1024 RGBA8 texture with a full mip chain (about 5.3 MiB): it costs a 5.3 MiB read, a 5.3 MiB detile and a 5.3 MiB upload copy. The module doc already marks this as a shortcut: "a change detiles the whole texture, not the pages written".

Reproduction

  1. Place a 2D tiled colour texture (for example RGBA8, 1024×1024, all mips) in write-watched title memory and sample it every frame.
  2. Each frame, write a few KiB into one region of mip 0.
  3. With diagnostics, TexWatched grows by the texture's whole size every frame, and the upload records one copy per subresource.

The ignored measurement texture::gpu_row_tests::texture_row_refresh_costs (see Performance) reproduces this without a title.

How it works

Where the bytes live (victory-formats)

  • Layout::subresource_bytes(mip, slice) describes where a subresource's tiled bytes lie in a 2D layout:
    • outside the mip tail: rows of layout blocks, each stride bytes and rows element rows high (a linear layout has one element row per block row);
    • inside the tail: the slice's shared tail block.
  • Layout::detile_rows(tiled, mip, slice, rows, linear, pitch) detiles only the requested element rows. It goes through the same walk as Layout::detile, now with an optional row range, so the bytes are identical and no addressing code is duplicated.
  • 3D, thick, multisampled, XOR and render-XOR layouts return None or Unsupported.

What changed since the last refresh

  • In the write-watched branch of refresh_timed, the new watch::pages_since asks the same journal as writes_since (the page epoch table where the journal keeps one). It also returns which pages were written after the previous asking (since).
  • Those pages become byte ranges (written_ranges). This happens only when the staging buffer still holds the whole memory as of since (Last::complete).
  • row_plan maps the byte ranges onto parts:
    • a mip outside the tail re-reads and re-detiles only the block rows those bytes touch, merged into one band per part;
    • a mip in the tail is re-detiled whole;
    • untouched subresources are skipped.
  • RowParts::detile writes the rows in place in the resident staging buffer, at the offsets the whole detile would use.
  • If the band would read at least 3/4 of the texture, the code falls back to the existing whole path.

What gets copied

  • Staging::changed (Changed) collects the rows detiled since a submitted copy last took them.
  • When a list records an upload, copy_plan captures (serial, rows):
    • it copies only those rows, with a D3D12_BOX, when the host rows match the title's row for row (boxed);
    • otherwise it copies every part whole, as before.
  • The submission-time closure that used to clear dirty now calls Changed::taken(serial, whole):
    • rows detiled after the copy was recorded keep dirty set for the next list;
    • a whole copy takes everything.
  • A refresh notes its rows only after writing them, so a copy is never planned over rows that are still being written.
  • Lists recorded in one order and submitted in another cannot drop rows. At worst they copy some rows twice.

What keeps the old path

  • These still detile the whole texture: the first upload, bakes (BAKING), levels on demand, exact refreshes, once textures, guarded or hashed (view) memory, partly mapped memory, unlocked refreshes, VICTORY_REFRESH_LOCKLESS, and the card's detiling (VICTORY_GPU_DETILE, which needs the raw bytes). Every whole detile calls Changed::note_all.
  • Copies stay whole for:
    • block-compressed formats (their rows are still detiled by band on the CPU);
    • depth and stencil formats;
    • promoted formats, where the host row size differs from the title's;
    • any footprint whose width, height or row count differs from the title mip's.
  • Prelude uploads (VICTORY_PRELUDE_UPLOADS=1, off by default) still copy every part whole. PreludeUpload::finish_refresh clears what is pending under the same lock as claim_upload. Row copies from the prelude would be a natural follow-up, since there the plan is known exactly at submission.

Switch. VICTORY_TEXTURE_ROWS=0 restores the previous behaviour.

Tests

No GPU needed:

  • victory-formats:
    • rows_of_blocks_detile_as_the_whole_mip_does_from_their_own_bytes. Covers RGBA8 arrays at odd sizes, BC (8 and 16 bytes per block), SW_256B, 4 KiB, 64 KiB, S and D modes, linear, and mip tails. For every subresource it checks that a whole detile reads nothing outside subresource_bytes; that detile_rows from a buffer where only its block rows are real matches the whole mip byte for byte; that rows_in round-trips; and that non-tail subresources do not overlap.
    • a_byte_range_names_the_rows_of_blocks_it_touches.
    • row_detiling_refuses_what_it_cannot_do, including a configured XOR layout (it must refuse: XOR picks the pipe with address bits above the block).
  • victory-gpu (texture::row_tests, no device):
    • rows_detiled_since_are_kept_until_a_copy_takes_them: Changed's serial, union and keep rules.
    • written_pages_become_ranges_from_the_texture_start: unaligned start, merged runs, a page past the end.
    • a_plan_reads_rows_of_blocks_and_whole_tails.
    • rows_detiled_after_page_writes_match_a_whole_detile_and_their_copies_the_host: simulates page writes on four layouts (RGBA8 array with tail, BC, 4 KiB array, linear) in a texture that starts partway into a page. After the row refresh, the staging buffer equals a fresh whole detile, and applying the planned row copies to a "host" image makes every visible row equal.

Needs a D3D12 device (marked #[ignore]):

  • texture::gpu_row_tests::rows_the_title_writes_reach_the_host_texture_and_are_copied_alone. The texture is an RGBA8 1024×512 with three mips and two array slices, in write-watched memory. The test writes into mip 0 of slice 1; then into mip 1 and the last texel of mip 0 of slice 0; then into the last row of mip 2. After each write it checks that the plan names exactly the written parts, that the next list copies them and clears dirty, and that a full readback of every subresource equals a CPU detile of the title bytes.
  • texture::gpu_row_tests::texture_row_refresh_costs: the measurement below.

Results on Windows (toolchain pinned in rust-toolchain.toml, Rust 1.98.1; RTX 5090, driver 621.14):

  • Clippy. main (e1251c31) does not pass -D warnings at the moment: 4 warnings without --all-features (field loop_caps is never read in crates/victory-shader/src/emit/lower.rs; manual implementation of .is_multiple_of() in crates/victory-gpu/src/host.rs; match can be simplified with .unwrap_or_default() in crates/victory-hle/src/modules/xmem.rs; method ranged is never used in crates/victory-gpu/src/shadow.rs) and 5 with it (also function mb is never used in crates/victory-gpu/src/copystat.rs). Both CI configurations were therefore run without -D and compared with main's diagnostics. This branch adds none, in either configuration.
  • cargo test --workspace --locked --no-fail-fast on the GPU: 2527 passed, 5 failed, 98 ignored (main: 2520 passed, 5 failed, 96 ignored). No new failure: the failures are the ones main has itself (list::thin::tests::bindings_record_no_work, shader_cache::tests::every_switch_of_the_translator_is_in_the_key, modules::xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it, emit::bitcode::opt::tests::hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity, policy::tests::repository_passes_policy).
  • texture::gpu_row_tests::rows_the_title_writes_reach_the_host_texture_and_are_copied_alone (ignored, run by name on the GPU): passed (1 passed, 0 failed).

Performance

In short:

  • A few KiB written into textures (texture_partial): with rows on, the mean time per iteration drops by 26% (small textures), 88% (medium) and 94% (large), lower in every pair, and each run reads 4× (small), 21× (medium) and 85× (large) fewer bytes.
  • Textures rewritten whole (texture_whole): rows on is within half a percent of rows off and of main for the small and medium loads (the intervals touch or cross zero). For the large load its mean is 9% lower, with the same p95 and p99.
  • VICTORY_TEXTURE_ROWS=0 (A) matches main (M) within 2% in every case, so the switch restores the previous behaviour.
  • One tail to note: in the large load, the partial-update p99 with rows on is still 18.5 ms, from a few slow iterations per run. It is 55% below rows off.
Load Case A: rows off, median of run means (p50 / p95 / p99), ms B: rows on, same M: main B vs A, run means: median Δ (95% CI) B vs A, run p99 Bytes read per run (A → B)
small: 64 × 256², 1 mip (30 pairs) texture_partial 1.441 (1.415 / 1.637 / 2.009) 1.059 (1.039 / 1.244 / 1.550) 1.424 (1.405 / 1.659 / 2.756) -26.2% (-27.3%, -25.4%) -25.1% (-27.1%, -19.6%) 1,073,741,824 → 268,435,456
small: 64 × 256², 1 mip (30 pairs) texture_whole 5.525 (5.049 / 6.376 / 7.139) 5.434 (5.193 / 6.402 / 6.756) 5.641 (5.273 / 6.419 / 6.742) +0.5% (-2.1%, +2.1%) +1.0% (-1.6%, +5.5%) 1,073,741,824 → 1,073,741,824
texture_whole, B vs M (main) -0.7% (-2.8%, +0.3%)
medium: 16 × 1024², 11 mips (30 pairs) texture_partial 6.356 (6.273 / 7.000 / 8.656) 0.728 (0.724 / 0.871 / 1.117) 6.381 (6.301 / 7.055 / 8.389) -88.4% (-88.8%, -87.9%) -87.2% (-88.4%, -86.4%) 5,729,419,264 → 268,435,456
medium: 16 × 1024², 11 mips (30 pairs) texture_whole 25.637 (25.481 / 26.547 / 29.576) 25.677 (25.558 / 26.646 / 28.778) 25.677 (25.513 / 26.757 / 30.100) +0.2% (+0.0%, +0.5%) +0.1% (-2.7%, +3.9%) 5,729,419,264 → 5,729,419,264
texture_whole, B vs M (main) -0.1% (-0.2%, +0.4%)
large: 4 × 4096², 13 mips (29 pairs) texture_partial 29.650 (28.985 / 36.569 / 40.861) 1.731 (0.914 / 3.077 / 18.546) 29.822 (29.068 / 36.721 / 41.131) -94.2% (-94.2%, -94.1%) -54.6% (-54.9%, -54.4%) 22,907,191,296 → 268,435,456
large: 4 × 4096², 13 mips (29 pairs) texture_whole 184.637 (215.455 / 228.260 / 233.546) 168.909 (169.510 / 227.273 / 232.476) 185.972 (217.490 / 227.775 / 232.985) -9.0% (-10.1%, -7.1%) -0.4% (-1.4%, +0.6%) 22,907,191,296 → 22,907,191,296
texture_whole, B vs M (main) -10.3% (-10.8%, -7.6%)

Method:

  • One release build of this branch. A = VICTORY_TEXTURE_ROWS=0, B = default.
  • M = a release build of main that carries only this measurement. It shows that the whole-rewrite case did not get slower.
  • Each run is a fresh process of the ignored test: 64 iterations per case.
    • texture_partial: each iteration writes 8 KiB into mip 0 of every texture, then submits the list whose check finds the write and the list that copies it.
    • texture_whole: the same, but each iteration rewrites every texture whole.
  • 30 pairs per load, in alternating order (A B M, then M B A).
  • For the whole window, one sampler recorded who used the GPU's engines and the Windows CPU every 5 s, and another the CPU of the WSL side every second (the runs were driven from WSL, where other builds could run). A pair was dropped and measured once more if, during any of its runs, another process used the GPU's 3D/Compute engines (2% or more), named Windows processes other than the measurement used 15% CPU or more, or the WSL side averaged more than 15% (or passed 25% in any second).
  • Reported per load:
    • the median over runs of each run's mean;
    • p50, p95 and p99 over all iterations;
    • the median of the paired differences of the run means and of the run p99s, with a distribution-free 95% interval (order statistics).

For reference only: the original implementation in another tree, measured on its own hot-path fixture, made the same 8 KiB title write copy 1 MiB instead of 32 MiB and cut partial-update time by about 90%. Those numbers do not carry over to this tree's resident staging buffer and record-time copies.

Risks

  • Write-watch completeness. Row refreshes trust that every changed page is reported after since. These are the same askings the existing skip (w <= last.asked) already trusts. Anything that changes the bytes without a reported write leaves complete = false and takes the whole path. A remap is one such case (it resets asked); so are guarded memory and partly mapped memory.
  • In-flight copies. As before, the staging buffer is written while an earlier submission's copy may still read it (TexInAir). Row refreshes write less of it, and a planned copy covers only rows whose writes have finished.
  • One frame later in one case. Before this change, a list that recorded a whole copy also carried rows its own submission-time check found. A row copy leaves those rows for the next list, which is the latency the clean path already has.
  • D3D12_BOX copies. Box copies are limited to colour formats with one texel per element and native row sizes. The GPU readback test above covers them.

Provenance and credits

This reimplements the partial texture upload from Jineggegg/VIctory (commits 72c2620, "stream tracked texture uploads by dirty rows of swizzle blocks", and c6301f4, "require native plane rows for partial texture copies") for this tree's resident staging buffer and record-time copies. It is not a cherry-pick.

The original also packed compact copy footprints, following Marvisak/VIctory#3136. That part does not apply here, because staging buffers are resident.

Related work with a different scope:

  • Marvisak/VIctory#2985 marks dirty element rows but still stages the whole texture.
  • Marvisak/VIctory#2358 is opt-in and handles a single mip and slice.
  • In this repository, open #4546 changes the order in which Layout::detile walks wide non-XOR textures (block columns), in the same walk this branch extends with a row range. The two conflict textually there (checked with git merge-tree), so whichever lands second needs a small rebase; they do not overlap in purpose. Open #4031 changes the partly-mapped refresh path, which this branch leaves on the whole path; it merges with this branch cleanly.

AI assistance: the change, its tests and this description were prepared with an AI coding assistant (Claude Code) and checked by the results above.

🤖 Generated with Claude Code

**@⁠Jineggegg** on GitHub · 2026-12-01 09:33 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4808) `Jineggegg:texture-partial-update` → `main` · +1100 −24 · 3 files · 15 commits · closed without merging Based on `main` at `e1251c31`; one commit. ## Problem A title texture in write-watched memory is refreshed as a whole whenever any of its pages is written: - `Staging::refresh_timed` asks `watch::writes_since` only whether anything changed. - It then reads the whole texture through `copy_mapped`, and `Staging::detile` detiles every subresource. - The next list that samples the texture copies every subresource into the host texture (`record_upload`, `CopyTextureRegion(..., None)`). So a title that streams a texture in, or draws into an atlas a page at a time, pays for the whole texture on every change. Take one 64 KiB page written into a 1024×1024 RGBA8 texture with a full mip chain (about 5.3 MiB): it costs a 5.3 MiB read, a 5.3 MiB detile and a 5.3 MiB upload copy. The module doc already marks this as a shortcut: "a change detiles the whole texture, not the pages written". ## Reproduction 1. Place a 2D tiled colour texture (for example RGBA8, 1024×1024, all mips) in write-watched title memory and sample it every frame. 2. Each frame, write a few KiB into one region of mip 0. 3. With `diagnostics`, `TexWatched` grows by the texture's whole size every frame, and the upload records one copy per subresource. The ignored measurement `texture::gpu_row_tests::texture_row_refresh_costs` (see Performance) reproduces this without a title. ## How it works **Where the bytes live** (`victory-formats`) - `Layout::subresource_bytes(mip, slice)` describes where a subresource's tiled bytes lie in a 2D layout: - outside the mip tail: rows of layout blocks, each `stride` bytes and `rows` element rows high (a linear layout has one element row per block row); - inside the tail: the slice's shared tail block. - `Layout::detile_rows(tiled, mip, slice, rows, linear, pitch)` detiles only the requested element rows. It goes through the same `walk` as `Layout::detile`, now with an optional row range, so the bytes are identical and no addressing code is duplicated. - 3D, thick, multisampled, XOR and render-XOR layouts return `None` or `Unsupported`. **What changed since the last refresh** - In the write-watched branch of `refresh_timed`, the new `watch::pages_since` asks the same journal as `writes_since` (the page epoch table where the journal keeps one). It also returns which pages were written after the previous asking (`since`). - Those pages become byte ranges (`written_ranges`). This happens only when the staging buffer still holds the whole memory as of `since` (`Last::complete`). - `row_plan` maps the byte ranges onto parts: - a mip outside the tail re-reads and re-detiles only the block rows those bytes touch, merged into one band per part; - a mip in the tail is re-detiled whole; - untouched subresources are skipped. - `RowParts::detile` writes the rows in place in the resident staging buffer, at the offsets the whole detile would use. - If the band would read at least 3/4 of the texture, the code falls back to the existing whole path. **What gets copied** - `Staging::changed` (`Changed`) collects the rows detiled since a submitted copy last took them. - When a list records an upload, `copy_plan` captures `(serial, rows)`: - it copies only those rows, with a `D3D12_BOX`, when the host rows match the title's row for row (`boxed`); - otherwise it copies every part whole, as before. - The submission-time closure that used to clear `dirty` now calls `Changed::taken(serial, whole)`: - rows detiled after the copy was recorded keep `dirty` set for the next list; - a whole copy takes everything. - A refresh notes its rows only after writing them, so a copy is never planned over rows that are still being written. - Lists recorded in one order and submitted in another cannot drop rows. At worst they copy some rows twice. **What keeps the old path** - These still detile the whole texture: the first upload, bakes (`BAKING`), levels on demand, `exact` refreshes, `once` textures, guarded or hashed (view) memory, partly mapped memory, unlocked refreshes, `VICTORY_REFRESH_LOCKLESS`, and the card's detiling (`VICTORY_GPU_DETILE`, which needs the raw bytes). Every whole detile calls `Changed::note_all`. - Copies stay whole for: - block-compressed formats (their rows are still detiled by band on the CPU); - depth and stencil formats; - promoted formats, where the host row size differs from the title's; - any footprint whose width, height or row count differs from the title mip's. - Prelude uploads (`VICTORY_PRELUDE_UPLOADS=1`, off by default) still copy every part whole. `PreludeUpload::finish_refresh` clears what is pending under the same lock as `claim_upload`. Row copies from the prelude would be a natural follow-up, since there the plan is known exactly at submission. **Switch.** `VICTORY_TEXTURE_ROWS=0` restores the previous behaviour. ## Tests No GPU needed: - `victory-formats`: - `rows_of_blocks_detile_as_the_whole_mip_does_from_their_own_bytes`. Covers RGBA8 arrays at odd sizes, BC (8 and 16 bytes per block), SW_256B, 4 KiB, 64 KiB, S and D modes, linear, and mip tails. For every subresource it checks that a whole detile reads nothing outside `subresource_bytes`; that `detile_rows` from a buffer where only its block rows are real matches the whole mip byte for byte; that `rows_in` round-trips; and that non-tail subresources do not overlap. - `a_byte_range_names_the_rows_of_blocks_it_touches`. - `row_detiling_refuses_what_it_cannot_do`, including a configured XOR layout (it must refuse: XOR picks the pipe with address bits above the block). - `victory-gpu` (`texture::row_tests`, no device): - `rows_detiled_since_are_kept_until_a_copy_takes_them`: `Changed`'s serial, union and keep rules. - `written_pages_become_ranges_from_the_texture_start`: unaligned start, merged runs, a page past the end. - `a_plan_reads_rows_of_blocks_and_whole_tails`. - `rows_detiled_after_page_writes_match_a_whole_detile_and_their_copies_the_host`: simulates page writes on four layouts (RGBA8 array with tail, BC, 4 KiB array, linear) in a texture that starts partway into a page. After the row refresh, the staging buffer equals a fresh whole detile, and applying the planned row copies to a "host" image makes every visible row equal. Needs a D3D12 device (marked `#[ignore]`): - `texture::gpu_row_tests::rows_the_title_writes_reach_the_host_texture_and_are_copied_alone`. The texture is an RGBA8 1024×512 with three mips and two array slices, in write-watched memory. The test writes into mip 0 of slice 1; then into mip 1 and the last texel of mip 0 of slice 0; then into the last row of mip 2. After each write it checks that the plan names exactly the written parts, that the next list copies them and clears `dirty`, and that a full readback of every subresource equals a CPU detile of the title bytes. - `texture::gpu_row_tests::texture_row_refresh_costs`: the measurement below. Results on Windows (toolchain pinned in `rust-toolchain.toml`, Rust 1.98.1; RTX 5090, driver 621.14): - Clippy. `main` (`e1251c31`) does not pass `-D warnings` at the moment: 4 warnings without `--all-features` (field `loop_caps` is never read in `crates/victory-shader/src/emit/lower.rs`; manual implementation of `.is_multiple_of()` in `crates/victory-gpu/src/host.rs`; match can be simplified with `.unwrap_or_default()` in `crates/victory-hle/src/modules/xmem.rs`; method `ranged` is never used in `crates/victory-gpu/src/shadow.rs`) and 5 with it (also function `mb` is never used in `crates/victory-gpu/src/copystat.rs`). Both CI configurations were therefore run without `-D` and compared with `main`'s diagnostics. This branch adds none, in either configuration. - `cargo test --workspace --locked --no-fail-fast` on the GPU: 2527 passed, 5 failed, 98 ignored (`main`: 2520 passed, 5 failed, 96 ignored). No new failure: the failures are the ones `main` has itself (`list::thin::tests::bindings_record_no_work`, `shader_cache::tests::every_switch_of_the_translator_is_in_the_key`, `modules::xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it`, `emit::bitcode::opt::tests::hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity`, `policy::tests::repository_passes_policy`). - `texture::gpu_row_tests::rows_the_title_writes_reach_the_host_texture_and_are_copied_alone` (ignored, run by name on the GPU): passed (1 passed, 0 failed). ## Performance In short: - **A few KiB written into textures** (`texture_partial`): with rows on, the mean time per iteration drops by 26% (small textures), 88% (medium) and 94% (large), lower in every pair, and each run reads 4× (small), 21× (medium) and 85× (large) fewer bytes. - **Textures rewritten whole** (`texture_whole`): rows on is within half a percent of rows off and of `main` for the small and medium loads (the intervals touch or cross zero). For the large load its mean is 9% lower, with the same p95 and p99. - `VICTORY_TEXTURE_ROWS=0` (A) matches `main` (M) within 2% in every case, so the switch restores the previous behaviour. - One tail to note: in the large load, the partial-update p99 with rows on is still 18.5 ms, from a few slow iterations per run. It is 55% below rows off. | Load | Case | A: rows off, median of run means (p50 / p95 / p99), ms | B: rows on, same | M: `main` | B vs A, run means: median Δ (95% CI) | B vs A, run p99 | Bytes read per run (A → B) | |---|---|---|---|---|---|---|---| | small: 64 × 256², 1 mip (30 pairs) | `texture_partial` | 1.441 (1.415 / 1.637 / 2.009) | 1.059 (1.039 / 1.244 / 1.550) | 1.424 (1.405 / 1.659 / 2.756) | -26.2% (-27.3%, -25.4%) | -25.1% (-27.1%, -19.6%) | 1,073,741,824 → 268,435,456 | | small: 64 × 256², 1 mip (30 pairs) | `texture_whole` | 5.525 (5.049 / 6.376 / 7.139) | 5.434 (5.193 / 6.402 / 6.756) | 5.641 (5.273 / 6.419 / 6.742) | +0.5% (-2.1%, +2.1%) | +1.0% (-1.6%, +5.5%) | 1,073,741,824 → 1,073,741,824 | | | `texture_whole`, B vs M (main) | | | | -0.7% (-2.8%, +0.3%) | | | | medium: 16 × 1024², 11 mips (30 pairs) | `texture_partial` | 6.356 (6.273 / 7.000 / 8.656) | 0.728 (0.724 / 0.871 / 1.117) | 6.381 (6.301 / 7.055 / 8.389) | -88.4% (-88.8%, -87.9%) | -87.2% (-88.4%, -86.4%) | 5,729,419,264 → 268,435,456 | | medium: 16 × 1024², 11 mips (30 pairs) | `texture_whole` | 25.637 (25.481 / 26.547 / 29.576) | 25.677 (25.558 / 26.646 / 28.778) | 25.677 (25.513 / 26.757 / 30.100) | +0.2% (+0.0%, +0.5%) | +0.1% (-2.7%, +3.9%) | 5,729,419,264 → 5,729,419,264 | | | `texture_whole`, B vs M (main) | | | | -0.1% (-0.2%, +0.4%) | | | | large: 4 × 4096², 13 mips (29 pairs) | `texture_partial` | 29.650 (28.985 / 36.569 / 40.861) | 1.731 (0.914 / 3.077 / 18.546) | 29.822 (29.068 / 36.721 / 41.131) | -94.2% (-94.2%, -94.1%) | -54.6% (-54.9%, -54.4%) | 22,907,191,296 → 268,435,456 | | large: 4 × 4096², 13 mips (29 pairs) | `texture_whole` | 184.637 (215.455 / 228.260 / 233.546) | 168.909 (169.510 / 227.273 / 232.476) | 185.972 (217.490 / 227.775 / 232.985) | -9.0% (-10.1%, -7.1%) | -0.4% (-1.4%, +0.6%) | 22,907,191,296 → 22,907,191,296 | | | `texture_whole`, B vs M (main) | | | | -10.3% (-10.8%, -7.6%) | | | Method: - One release build of this branch. A = `VICTORY_TEXTURE_ROWS=0`, B = default. - M = a release build of `main` that carries only this measurement. It shows that the whole-rewrite case did not get slower. - Each run is a fresh process of the ignored test: 64 iterations per case. - `texture_partial`: each iteration writes 8 KiB into mip 0 of every texture, then submits the list whose check finds the write and the list that copies it. - `texture_whole`: the same, but each iteration rewrites every texture whole. - 30 pairs per load, in alternating order (A B M, then M B A). - For the whole window, one sampler recorded who used the GPU's engines and the Windows CPU every 5 s, and another the CPU of the WSL side every second (the runs were driven from WSL, where other builds could run). A pair was dropped and measured once more if, during any of its runs, another process used the GPU's 3D/Compute engines (2% or more), named Windows processes other than the measurement used 15% CPU or more, or the WSL side averaged more than 15% (or passed 25% in any second). - Reported per load: - the median over runs of each run's mean; - p50, p95 and p99 over all iterations; - the median of the paired differences of the run means and of the run p99s, with a distribution-free 95% interval (order statistics). For reference only: the original implementation in another tree, measured on its own hot-path fixture, made the same 8 KiB title write copy 1 MiB instead of 32 MiB and cut partial-update time by about 90%. Those numbers do not carry over to this tree's resident staging buffer and record-time copies. ## Risks - **Write-watch completeness.** Row refreshes trust that every changed page is reported after `since`. These are the same askings the existing skip (`w <= last.asked`) already trusts. Anything that changes the bytes without a reported write leaves `complete = false` and takes the whole path. A remap is one such case (it resets `asked`); so are guarded memory and partly mapped memory. - **In-flight copies.** As before, the staging buffer is written while an earlier submission's copy may still read it (`TexInAir`). Row refreshes write less of it, and a planned copy covers only rows whose writes have finished. - **One frame later in one case.** Before this change, a list that recorded a whole copy also carried rows its own submission-time check found. A row copy leaves those rows for the next list, which is the latency the clean path already has. - **`D3D12_BOX` copies.** Box copies are limited to colour formats with one texel per element and native row sizes. The GPU readback test above covers them. ## Provenance and credits This reimplements the partial texture upload from `Jineggegg/VIctory` (commits `72c2620`, "stream tracked texture uploads by dirty rows of swizzle blocks", and `c6301f4`, "require native plane rows for partial texture copies") for this tree's resident staging buffer and record-time copies. It is not a cherry-pick. The original also packed compact copy footprints, following `Marvisak/VIctory#3136`. That part does not apply here, because staging buffers are resident. Related work with a different scope: - `Marvisak/VIctory#2985` marks dirty element rows but still stages the whole texture. - `Marvisak/VIctory#2358` is opt-in and handles a single mip and slice. - In this repository, open #4546 changes the order in which `Layout::detile` walks wide non-XOR textures (block columns), in the same `walk` this branch extends with a row range. The two conflict textually there (checked with `git merge-tree`), so whichever lands second needs a small rebase; they do not overlap in purpose. Open #4031 changes the partly-mapped refresh path, which this branch leaves on the whole path; it merges with this branch cleanly. AI assistance: the change, its tests and this description were prepared with an AI coding assistant (Claude Code) and checked by the results above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`slots_showing` took the slot's `Made` key with `?`, but `Made` has keys
for the title's `count` slots only while `kept` also has the dynamic
ones: a host texture shown by a dynamic slot was no longer reported, so
it was no longer blocked and could be chosen (freeing nothing, as the
dynamic slot holds a reference, while the title made a second copy).
Those slots are reported again with key 0, as before the key was carried;
they are never put back to waiting, only counted as blocking. Test:
`a_dynamic_slot_showing_a_texture_still_blocks_its_eviction`.

`SLOT_LOOKING` is now cleared by a drop guard, so a look that panics does
not stop every later look.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit b23c0c4038)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A texture in write-watched memory was read and detiled whole whenever
any of its pages was written, and every subresource was copied again.
A title that streams or draws into a large texture a page at a time paid
for the whole texture on each change.

The pages written since the staging buffer last held all of the memory
now name the rows of layout blocks to read again: only those element
rows are detiled into the resident staging buffer, and a mip in the
tail is detiled whole. The next copy takes only those rows, with a box,
where the host texture's rows are the title's (one texel an element, no
depth or promoted formats); block-compressed and other formats keep the
whole copy but still detile only the rows. Rows detiled after a copy was
recorded stay pending for the next one, so none are lost when lists are
recorded and submitted in a different order. First uploads, bakes,
levels on demand, guarded or hashed memory and exact refreshes keep the
whole path, as do the card's detiling (VICTORY_GPU_DETILE) and prelude
uploads (VICTORY_PRELUDE_UPLOADS=1), which copy every part and so take
whatever is pending. VICTORY_TEXTURE_ROWS=0 restores the old behaviour.
watch::pages_since gives the pages written after an asking from the
same journal writes_since reads.

victory-formats gains Layout::detile_rows and Layout::subresource_bytes;
tests check that rows detile byte for byte as the whole mip does while
reading only their own bytes, and simulate page writes, the row refresh
and the copies against a whole detile. A readback test and a measurement
(texture_row_refresh_costs) need a D3D12 device and are marked ignored.

The approach follows the partial texture upload work in
Jineggegg/VIctory (72c26201, c6301f46), whose compact staging footprint
is based on Marvisak/VIctory PR #3136; it is reimplemented here for the
resident staging buffer and the record-time copy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 09:39:54 +00:00
main was rewritten after this branch was made: e1251c31 and the 13 commits
before it are no longer on main, so GitHub showed the branch as conflicting
(in host/menu.rs and modules/xmem.rs, which this branch does not change).
This merge takes main as it is now and keeps only this branch's change,
which applies to it without conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠tillo88 on GitHub · 2026-12-01 15:26 UTC · original

Measured this PR (head f029d766, VICTORY_TEXTURE_ROWS at its default, on) merged on top of v2026.11.30.03 (it applied without conflicts), 2 runs, against the release as it is.

fps submitting thread ms refresh ms p95 ms p99 ms
v2026.11.30.03, 21 runs (mean, range) 32.01 (31.49–32.46) 20.51 6.43 48.3 63.7
with #4809, run 1 31.96 20.11 6.22 47.5 59.8
with #4809, run 2 32.13 20.22 6.22 47.1 59.6
  • No measurable difference: 32.05 vs 32.01 fps (+0.1%). Base runs on this route spread 31.49–32.46 fps (sd 0.21).
  • Refresh time was 6.22 ms a frame in both runs against a base mean of 6.43 (about -3%), still inside the base runs' range (6.19–6.93), so not a clear drop. The release build logs no count of row refreshes, so I can't tell how many textures took the row path here.
  • Crashes: the warm-up run stopped with a host command list did not close (0x80070057) at +2:38 after the log starts, about 20 s after the prison → plane cutscene cut. That is the known crash of #2237 (the bare release stops near that cut in 9 of 42 runs on this bench), so it does not point at this PR. Both measured runs completed.

Setup: Ryzen 7 9800X3D, RTX 5070 Ti 16 GB (driver 621.40), 32 GB RAM, Windows 11, release build, Series X 1440p, DLSS Quality, frame generation off, ray tracing off. Same save restored before each run (start of the game), prison cutscene, plane cutscene, first boat section, about 6 minutes; warm-up run not counted for speed.

Measured unattended on a replay bench (same save, recorded controller input via VICTORY_INPUT_REPLAY); numbers and text prepared with Claude.

**@⁠tillo88** on GitHub · 2026-12-01 15:26 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4808#issuecomment-7315903650) Measured this PR (head f029d766, `VICTORY_TEXTURE_ROWS` at its default, on) merged on top of **v2026.11.30.03** (it applied without conflicts), 2 runs, against the release as it is. | | fps | submitting thread ms | refresh ms | p95 ms | p99 ms | |---|---|---|---|---|---| | v2026.11.30.03, 21 runs (mean, range) | 32.01 (31.49–32.46) | 20.51 | 6.43 | 48.3 | 63.7 | | with #4809, run 1 | 31.96 | 20.11 | 6.22 | 47.5 | 59.8 | | with #4809, run 2 | 32.13 | 20.22 | 6.22 | 47.1 | 59.6 | - **No measurable difference:** 32.05 vs 32.01 fps (+0.1%). Base runs on this route spread 31.49–32.46 fps (sd 0.21). - Refresh time was 6.22 ms a frame in both runs against a base mean of 6.43 (about -3%), still inside the base runs' range (6.19–6.93), so not a clear drop. The release build logs no count of row refreshes, so I can't tell how many textures took the row path here. - Crashes: the warm-up run stopped with `a host command list did not close (0x80070057)` at +2:38 after the log starts, about 20 s after the prison → plane cutscene cut. That is the known crash of #2237 (the bare release stops near that cut in 9 of 42 runs on this bench), so it does not point at this PR. Both measured runs completed. Setup: Ryzen 7 9800X3D, RTX 5070 Ti 16 GB (driver 621.40), 32 GB RAM, Windows 11, release build, Series X 1440p, DLSS Quality, frame generation off, ray tracing off. Same save restored before each run (start of the game), prison cutscene, plane cutscene, first boat section, about 6 minutes; warm-up run not counted for speed. Measured unattended on a replay bench (same save, recorded controller input via VICTORY_INPUT_REPLAY); numbers and text prepared with Claude.
github-bot closed this pull request 2026-12-01 18:36:28 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:31 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:31 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4808#issuecomment-7321084120) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

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/trustno1-coder--VIctory-NVIDIA!4809
No description provided.