GPU/texture: detile only the pages written since the last refresh (VICTORY_TEXTURE_PAGES) #1130

Open
github-bot wants to merge 1 commit from github-bot/gh-1130 into main AGit
Owner

@⁠Lkxex on GitHub · 2026-11-25 21:04 UTC · original
Lkxex:texture-page-detile → main · +437 −123 · 2 files · 1 commits · open

GPU/texture: detile only the pages written since the last refresh (VICTORY_TEXTURE_PAGES)

Problem

crates/victory-gpu/src/texture.rs documented its own shortcut: "a change
detiles the whole texture, not the pages written." In the write-watched
refresh path, refresh_timed read the entire texture (copy_mapped of
size bytes) and detiled all of it (self.detile(read)), even when the
title had written only a handful of 64 KiB pages. On 8 GB cards this is a
large part of the "preparing" time (issue reports ~1.6 s/frame) and of the
bytes touched per refresh. The write-watch already reported which pages
changed (watch::writes returns per-page write times), but that information
was only used as an all-or-nothing "did anything change" gate.

Change

  • victory-formats: add Layout::detile_window, which detiles a window of
    the texture's tiled memory (starting at byte window, shorter than the
    whole texture) into the staging buffer, leaving bytes outside the window
    untouched. The walk is restricted per row and per run, so only elements
    whose tiled address falls in the window are written.
  • victory-gpu: record, per staging buffer, the byte range each subresource
    (mip + slice * mips) occupies in title memory (ranges), including the
    shared tail block. Add refresh_pages, which merges the pages written
    since the last asking into 64 KiB runs, reads each run once, and detiles
    the overlapping subresources via detile_window. Wire it into
    refresh_timed's write-watched branch (only when previous != 0), falling
    back to the whole-texture path on 3D textures, on-demand levels, missing
    range tables, or VICTORY_TEXTURE_PAGES=0.

Correctness

  • The first refresh (previous == 0) and the partly-mapped (hash) path keep
    the whole-texture behaviour, so a texture's first sight and streaming-in
    mips are unaffected.
  • 3D textures, on-demand levels, XOR/MSAA and count mismatches keep
    ranges = None and take the existing whole-texture path.
  • VICTORY_TEXTURE_PAGES=0 restores the previous behaviour.
  • Formats crate: 25 tests pass, including the existing bijection/round-trip
    tests; detile_window of a whole window reproduces detile.
  • victory-gpu: 183 lib tests pass; build clean.

Limitations

  • GPU runtime / real hardware not available; the claim is about bytes read
    and detiled in the synthetic CPU path, not measured frame time.
  • The host-texture upload still copies every subresource; subresource-
    granular GPU copies are a separate follow-up.

Assisted By NetherySiloX

**@⁠Lkxex** on GitHub · 2026-11-25 21:04 UTC · [original](https://github.com/fxceless/victory-fork/pull/1130) `Lkxex:texture-page-detile` → `main` · +437 −123 · 2 files · 1 commits · open GPU/texture: detile only the pages written since the last refresh (VICTORY_TEXTURE_PAGES) Problem ------- `crates/victory-gpu/src/texture.rs` documented its own shortcut: "a change detiles the whole texture, not the pages written." In the write-watched refresh path, `refresh_timed` read the *entire* texture (`copy_mapped` of `size` bytes) and detiled all of it (`self.detile(read)`), even when the title had written only a handful of 64 KiB pages. On 8 GB cards this is a large part of the "preparing" time (issue reports ~1.6 s/frame) and of the bytes touched per refresh. The write-watch already reported *which* pages changed (`watch::writes` returns per-page write times), but that information was only used as an all-or-nothing "did anything change" gate. Change ------ - `victory-formats`: add `Layout::detile_window`, which detiles a window of the texture's tiled memory (starting at byte `window`, shorter than the whole texture) into the staging buffer, leaving bytes outside the window untouched. The walk is restricted per row and per run, so only elements whose tiled address falls in the window are written. - `victory-gpu`: record, per staging buffer, the byte range each subresource (mip + slice * mips) occupies in title memory (`ranges`), including the shared tail block. Add `refresh_pages`, which merges the pages written since the last asking into 64 KiB runs, reads each run once, and detiles the overlapping subresources via `detile_window`. Wire it into `refresh_timed`'s write-watched branch (only when `previous != 0`), falling back to the whole-texture path on 3D textures, on-demand levels, missing range tables, or `VICTORY_TEXTURE_PAGES=0`. Correctness ----------- - The first refresh (`previous == 0`) and the partly-mapped (hash) path keep the whole-texture behaviour, so a texture's first sight and streaming-in mips are unaffected. - 3D textures, on-demand levels, XOR/MSAA and count mismatches keep `ranges = None` and take the existing whole-texture path. - `VICTORY_TEXTURE_PAGES=0` restores the previous behaviour. - Formats crate: 25 tests pass, including the existing bijection/round-trip tests; `detile_window` of a whole window reproduces `detile`. - victory-gpu: 183 lib tests pass; build clean. Limitations ----------- - GPU runtime / real hardware not available; the claim is about bytes read and detiled in the synthetic CPU path, not measured frame time. - The host-texture upload still copies every subresource; subresource- granular GPU copies are a separate follow-up. Assisted By NetherySiloX
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:04 +00:00
Author
Owner

@⁠LeonardoS11 on GitHub · 2026-11-25 23:44 UTC · original

Measured here carried over an integration branch (current main plus a few open PRs), RTX 3080 Ti 12 GB, Windows 11 26200, Series S profile, the fixed room of the prologue, 300 s runs with pipelines cached.

  • Merges cleanly and runs; no image change in our screenshots of that room.
  • Frame time stayed within run-to-run spread (107–120 ms a frame before and after). Texture refresh is about 6 ms of our frame in that scene, so there was little for it to take; a scene that streams textures harder should show more than ours does.

Written with Claude Code.

**@⁠LeonardoS11** on GitHub · 2026-11-25 23:44 UTC · [original](https://github.com/fxceless/victory-fork/pull/1130#issuecomment-7177975561) Measured here carried over an integration branch (current main plus a few open PRs), RTX 3080 Ti 12 GB, Windows 11 26200, Series S profile, the fixed room of the prologue, 300 s runs with pipelines cached. - Merges cleanly and runs; no image change in our screenshots of that room. - Frame time stayed within run-to-run spread (107–120 ms a frame before and after). Texture refresh is about 6 ms of our frame in that scene, so there was little for it to take; a scene that streams textures harder should show more than ours does. Written with Claude Code.
Author
Owner

@⁠LeonardoS11 on GitHub · 2026-11-26 05:52 UTC · original

A correction to my comment above, and a defect report. I wrote that the image did not change in our room; that room has almost no texture the title rewrites, so it could not have shown this. Reading the code since (not yet confirmed by a picture; we are checking that now):

In 4720e4c (VICTORY_TEXTURE_PAGES, on by default), refresh_pages() in crates/victory-gpu/src/texture.rs intersects each subresource's range with a run of written pages (let a = rs.max(run_start as u64); let b = re.min((run_start + run_len) as u64);, around line 1344), but the ranges are built as offsets in the texture's memory (base + start, base = slice * slice_size, around line 1741) while run_start is an absolute title address (page * PAGE, clamped to self.memory). The two never meet, so a >= b for every subresource and no page is detiled, yet the function still marks the texture dirty and returns Some(read). A watched texture the title rewrites would keep its old texels from its second refresh on, and the frame stops paying for the detile it skips, which also flatters any timing taken with the switch on.

The fix we carry: intersect in the texture's offsets — let run_at = run_start - self.memory as usize;, then a = rs.max(run_at), b = re.min(run_at + run_len), slicing buf[(a - run_at)..(b - run_at)] — and pass that offset a to detile_window(), which takes the window's offset within the texture. VICTORY_TEXTURE_PAGES=0 reads the whole texture as before.

Written with Claude Code.

**@⁠LeonardoS11** on GitHub · 2026-11-26 05:52 UTC · [original](https://github.com/fxceless/victory-fork/pull/1130#issuecomment-7183890633) A correction to my comment above, and a defect report. I wrote that the image did not change in our room; that room has almost no texture the title rewrites, so it could not have shown this. Reading the code since (not yet confirmed by a picture; we are checking that now): In 4720e4c (`VICTORY_TEXTURE_PAGES`, on by default), `refresh_pages()` in `crates/victory-gpu/src/texture.rs` intersects each subresource's range with a run of written pages (`let a = rs.max(run_start as u64); let b = re.min((run_start + run_len) as u64);`, around line 1344), but the ranges are built as offsets in the texture's memory (`base + start`, base = slice * slice_size, around line 1741) while `run_start` is an absolute title address (page * PAGE, clamped to `self.memory`). The two never meet, so `a >= b` for every subresource and no page is detiled, yet the function still marks the texture dirty and returns `Some(read)`. A watched texture the title rewrites would keep its old texels from its second refresh on, and the frame stops paying for the detile it skips, which also flatters any timing taken with the switch on. The fix we carry: intersect in the texture's offsets — `let run_at = run_start - self.memory as usize;`, then `a = rs.max(run_at)`, `b = re.min(run_at + run_len)`, slicing `buf[(a - run_at)..(b - run_at)]` — and pass that offset `a` to `detile_window()`, which takes the window's offset within the texture. `VICTORY_TEXTURE_PAGES=0` reads the whole texture as before. Written with Claude Code.
Author
Owner

@⁠D4rkGh057 on GitHub · 2026-11-26 21:21 UTC · original

Hi, I read the diff of this PR (code only, I have not built or run it). I am looking at it for the plan in avatarmanz/VIctory-7900XTX#358, and the page-granular detile looks like a better fit than the per-mip split proposed there. Two questions I could not answer from the diff:

  1. Row skip in walk. The check row_base + bytes <= start treats a row as bytes contiguous bytes of tiled memory. In a swizzled layout the elements of one row are spread over several blocks, so the runs of a row can sit well past row_base + bytes. Could a row whose runs fall inside the window be skipped and keep stale data? Was it tried with a partial window on a texture wider than one block?
  2. Tests. I could not find a new test in the diff. A whole window cannot reach the row skip, so a test that detiles in two or three partial windows and compares with the full detile would settle question 1. Also, Swizzle::SW_256B_S disappears from the list in tiled_chunks_match_element_offsets_with_odd_row_pitches: is that intended?

Smaller notes: copy_runs (the 8/16/32-byte chunked path) is removed and the full detile used it, which may be an artifact of the branch base; and last.asked is set before detiling, so pages whose detile fails are logged but not retried.

**@⁠D4rkGh057** on GitHub · 2026-11-26 21:21 UTC · [original](https://github.com/fxceless/victory-fork/pull/1130#issuecomment-7203643776) Hi, I read the diff of this PR (code only, I have not built or run it). I am looking at it for the plan in avatarmanz/VIctory-7900XTX#358, and the page-granular detile looks like a better fit than the per-mip split proposed there. Two questions I could not answer from the diff: 1. **Row skip in `walk`.** The check `row_base + bytes <= start` treats a row as `bytes` contiguous bytes of tiled memory. In a swizzled layout the elements of one row are spread over several blocks, so the runs of a row can sit well past `row_base + bytes`. Could a row whose runs fall inside the window be skipped and keep stale data? Was it tried with a partial window on a texture wider than one block? 2. **Tests.** I could not find a new test in the diff. A whole window cannot reach the row skip, so a test that detiles in two or three partial windows and compares with the full `detile` would settle question 1. Also, `Swizzle::SW_256B_S` disappears from the list in `tiled_chunks_match_element_offsets_with_odd_row_pitches`: is that intended? Smaller notes: `copy_runs` (the 8/16/32-byte chunked path) is removed and the full detile used it, which may be an artifact of the branch base; and `last.asked` is set before detiling, so pages whose detile fails are logged but not retried.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/texture.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1130/head:github-bot/gh-1130'
git switch 'github-bot/gh-1130'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1130'
git switch 'github-bot/gh-1130'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1130'
git switch 'github-bot/gh-1130'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1130'
git switch 'main'
git merge --squash 'github-bot/gh-1130'
git switch 'main'
git merge --ff-only 'github-bot/gh-1130'
git switch 'main'
git merge 'github-bot/gh-1130'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.