Fix #2638: texture subresource in untracked memory never uploaded #3103

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

@⁠tharun-37 on GitHub · 2026-11-26 08:09 UTC · original
tharun-37:fix/texture-untracked-refresh → main · +78 −4 · 1 files · 1 commits · open

Staging::refresh_now only used t.take() results, which returns changed tracked pages. Pages in t.untracked() (memory outside the runtime) were never returned, so subresources lying wholly in untracked pages were never read or uploaded - their host texture stayed zero forever.

Now untracked ranges are fetched via t.untracked() and merged with tracked changed ranges, so subresources touching untracked pages are always re-read and re-uploaded, matching how buffer copies handle untracked memory (copied whole at each use).

**@⁠tharun-37** on GitHub · 2026-11-26 08:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/3103) `tharun-37:fix/texture-untracked-refresh` → `main` · +78 −4 · 1 files · 1 commits · open Staging::refresh_now only used t.take() results, which returns changed tracked pages. Pages in t.untracked() (memory outside the runtime) were never returned, so subresources lying wholly in untracked pages were never read or uploaded - their host texture stayed zero forever. Now untracked ranges are fetched via t.untracked() and merged with tracked changed ranges, so subresources touching untracked pages are always re-read and re-uploaded, matching how buffer copies handle untracked memory (copied whole at each use).
write_physical and PageWindow called kernel_will_write (watch::writing)
after writing through our own views. The watch must be told before the
write so it saves the page's original bytes and keeps the guarded blocks
open during the write.

Now report_written returns Writing guards that stay alive during the
write, write_physical reports current views after the write, and
PageWindow holds pre-write guards until dropped and reports views
currently showing the pages on drop.
Staging::refresh_now only used t.take() results, which returns changed
tracked pages. Pages in t.untracked() (memory outside the runtime) were
never returned, so subresources lying wholly in untracked pages were
never read or uploaded - their host texture stayed zero forever.

Now untracked ranges are fetched via t.untracked() and merged with
tracked changed ranges, so subresources touching untracked pages are
always re-read and re-uploaded, matching how buffer copies handle
untracked memory (copied whole at each use).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:24:26 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 08:24 UTC · original

Automated triage for the maintainers.

Proposed close: duplicate of #2639, and it bundles #3063.

  • The texture fix (crates/victory-gpu/src/texture.rs, Staging::refresh_now) addresses #2638, which open PR #2639 already fixes. #2639 is a better fit:

    • It keeps the whole-changed-page shortcut on tracked pages only, so untracked subresources go through the per-subresource hash and are uploaded when their bytes change.
    • It adds a regression test (draw::tests::a_mip_off_the_runtimes_memory_is_uploaded).

    Here, untracked ranges feed the whole-page shortcut, so a subresource covering an untracked page is re-detiled and re-uploaded at every refresh, and there is no test. The added t.clean() && untracked.is_empty() check also has no effect: a tracker with untracked parts has no clean bit and is never clean (watch::track_as).

  • The crates/victory-hle/src/modules/xmem.rs change (commit 3ce6a89, not mentioned in the description) is the same commit as your #3063. That PR is already proposed for close as a duplicate of #2504.

This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the triage: proposed close label. Anything #2639 misses is best raised as a review comment there.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 08:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3103#issuecomment-7186560145) <!-- victory-triage v1 head=17bb212c6484525e98b1025e1b3e284efc9c01a1 verdict=proposed-close at=2026-11-26T08:18:11Z --> Automated triage for the maintainers. **Proposed close: duplicate of #2639, and it bundles #3063.** - **The texture fix** (`crates/victory-gpu/src/texture.rs`, `Staging::refresh_now`) addresses #2638, which open PR #2639 already fixes. #2639 is a better fit: - It keeps the whole-changed-page shortcut on tracked pages only, so untracked subresources go through the per-subresource hash and are uploaded when their bytes change. - It adds a regression test (`draw::tests::a_mip_off_the_runtimes_memory_is_uploaded`). Here, untracked ranges feed the whole-page shortcut, so a subresource covering an untracked page is re-detiled and re-uploaded at every refresh, and there is no test. The added `t.clean() && untracked.is_empty()` check also has no effect: a tracker with untracked parts has no clean bit and is never clean (`watch::track_as`). - **The `crates/victory-hle/src/modules/xmem.rs` change** (commit 3ce6a89, not mentioned in the description) is the same commit as your #3063. That PR is already proposed for close as a duplicate of #2504. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the `triage: proposed close` label. Anything #2639 misses is best raised as a review comment there. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 08:25 UTC · original · requested changes

Good catch on #2638 — Staging::refresh_now indeed misses subresources lying solely in t.untracked(...). However, there are a few issues in the current patch that should be fixed before merging:

1. Unconditional re-detile / re-upload on every submission for untracked >=64 KiB subresources (crates/victory-gpu/src/texture.rs)

Merging t.untracked(start, start + size) into ranges feeds static untracked spans into the skip-hash shortcut at line 610:

if ranges.iter().any(|&(f, e)| f.max(a0).next_multiple_of(page) + page <= e.min(b0)) {
    last.hashes[i] = None;
    return true;
}

That shortcut assumes every entry in ranges came from t.take(...) (pages confirmed written by the write watch). Because t.untracked(...) returns the same spans on every refresh even when nothing changed, any subresource covering at least one full 64 KiB page of untracked memory will clear last.hashes[i], skip blake3::hash, and re-detile/re-upload on every submission forever — worse than the fully untracked path (self.tracked.is_none() at lines 653-658), which hashes with blake3 and skips unchanged subresources.

Please keep tracked = t.take(start, start + size) and untracked = t.untracked(start, start + size) separate:

  • Use tracked.iter().chain(&untracked) for the touched check (which also removes the need to sort/merge into an extra Vec).
  • Apply the skip-hash shortcut at line 610 only to tracked, so untracked subresources fall through to the blake3 comparison and only re-upload when their bytes actually change.

2. Avoid allocating t.untracked(...) before if t.clean() (crates/victory-gpu/src/texture.rs)

t.untracked(start, start + size) is currently called before if t.clean(), which is on the ~123,000 calls/frame fast path. In watch.rs (Tracked::new), any tracker with non-empty untracked gets bit = None, so t.clean() is already guaranteed to return false whenever untracked is non-empty. Leaving if t.clean() { return (0, None); } first preserves the zero-allocation fast path for clean tracked textures.

3. Unrelated crates/victory-hle/src/modules/xmem.rs changes

The changes in xmem.rs are not mentioned in the PR title/description and appear unrelated to #2638. They also introduce regressions:

  • View::map writes through a separate kernel view rather than the guarded title views, so holding per-page KernelWrite guards open across the lifetime of PageWindow (which spans DirectStorage decompression) keeps GUARDS.busy entries and extra VirtualProtect churn alive unnecessarily.
  • In PageWindow::drop, calling drop(kernel_will_write(addr, PAGE)) per page and then dropping self._writing acquires GUARDS four times per page.
  • In write_physical, calling report_written(&shown) before View::map(slice, *n) mutates write-watch state even if View::map fails mid-loop and returns false.

Please revert crates/victory-hle/src/modules/xmem.rs from this PR (and open a separate PR with a reproducer if there is an independent xmem write-watch issue).

4. Missing regression test

Please add a unit test covering a texture spanning both tracked and untracked memory (matching #2638) that verifies:

  1. the subresource in untracked memory is uploaded on first refresh,
  2. a subsequent refresh without writes does not re-upload it, and
  3. mutating its bytes triggers a re-upload on the next refresh.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 08:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/3103#pullrequestreview-6070654871) · **requested changes** Good catch on `#2638` — `Staging::refresh_now` indeed misses subresources lying solely in `t.untracked(...)`. However, there are a few issues in the current patch that should be fixed before merging: ### 1. Unconditional re-detile / re-upload on every submission for untracked >=64 KiB subresources (`crates/victory-gpu/src/texture.rs`) Merging `t.untracked(start, start + size)` into `ranges` feeds static untracked spans into the skip-hash shortcut at line 610: ```rust if ranges.iter().any(|&(f, e)| f.max(a0).next_multiple_of(page) + page <= e.min(b0)) { last.hashes[i] = None; return true; } ``` That shortcut assumes every entry in `ranges` came from `t.take(...)` (pages confirmed written by the write watch). Because `t.untracked(...)` returns the same spans on every refresh even when nothing changed, any subresource covering at least one full 64 KiB page of untracked memory will clear `last.hashes[i]`, skip `blake3::hash`, and re-detile/re-upload on **every submission forever** — worse than the fully untracked path (`self.tracked.is_none()` at lines 653-658), which hashes with `blake3` and skips unchanged subresources. Please keep `tracked = t.take(start, start + size)` and `untracked = t.untracked(start, start + size)` separate: - Use `tracked.iter().chain(&untracked)` for the `touched` check (which also removes the need to sort/merge into an extra `Vec`). - Apply the skip-hash shortcut at line 610 only to `tracked`, so untracked subresources fall through to the `blake3` comparison and only re-upload when their bytes actually change. ### 2. Avoid allocating `t.untracked(...)` before `if t.clean()` (`crates/victory-gpu/src/texture.rs`) `t.untracked(start, start + size)` is currently called before `if t.clean()`, which is on the ~123,000 calls/frame fast path. In `watch.rs` (`Tracked::new`), any tracker with non-empty `untracked` gets `bit = None`, so `t.clean()` is already guaranteed to return `false` whenever `untracked` is non-empty. Leaving `if t.clean() { return (0, None); }` first preserves the zero-allocation fast path for clean tracked textures. ### 3. Unrelated `crates/victory-hle/src/modules/xmem.rs` changes The changes in `xmem.rs` are not mentioned in the PR title/description and appear unrelated to `#2638`. They also introduce regressions: - `View::map` writes through a separate kernel view rather than the guarded title views, so holding per-page `KernelWrite` guards open across the lifetime of `PageWindow` (which spans DirectStorage decompression) keeps `GUARDS.busy` entries and extra `VirtualProtect` churn alive unnecessarily. - In `PageWindow::drop`, calling `drop(kernel_will_write(addr, PAGE))` per page and then dropping `self._writing` acquires `GUARDS` four times per page. - In `write_physical`, calling `report_written(&shown)` before `View::map(slice, *n)` mutates write-watch state even if `View::map` fails mid-loop and returns `false`. Please revert `crates/victory-hle/src/modules/xmem.rs` from this PR (and open a separate PR with a reproducer if there is an independent `xmem` write-watch issue). ### 4. Missing regression test Please add a unit test covering a texture spanning both tracked and untracked memory (matching `#2638`) that verifies: 1. the subresource in untracked memory is uploaded on first refresh, 2. a subsequent refresh without writes does **not** re-upload it, and 3. mutating its bytes triggers a re-upload on the next refresh.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 08:28 UTC · original

Independent Windows WARP verification of PR #3103 at 17bb212c6484525e98b1025e1b3e284efc9c01a1 (claim: #1633). This is a factual test report only; it makes no source-review judgment.

Compared: head 17bb212c against its exact parent 3ce6a893 (the head commit changes only crates/victory-gpu/src/texture.rs). Parent source was tested by swapping only that file, with the same tests.

Environment: Windows 11 26200, Rust 1.98.1, cargo --locked -j 4 -p victory-gpu --features diagnostics, VICTORY_D3D12_WARP=1, VICTORY_DXIL = Windows SDK 10.0.26100.0 dxil.dll (the new tests compile DXBC cs_5_1 via D3DCompile, so that dll was set but not exercised by them). The adapter was checked before any GPU-backed test: the host device's LUID equals EnumWarpAdapter's, with Microsoft Basic Render Driver, vendor 0x1414, DXGI_ADAPTER_FLAG_SOFTWARE; every new test re-asserts it. No physical GPU was used. Inputs are synthetic only (byte-pattern fills of anonymous memory); no game files, dumps, shader names or hashes.

Method: local-only tests (not part of the PR) build a 512x512 RGBA8, two-mip linear texture over adjacent 64 KiB pages, some write-watched (tracked) and the rest ordinary committed memory (untracked). The title-side bytes are written, a D3D12 compute shader samples 64 texels per mip through the host SRV, and the readback is compared to an oracle computed from the memory bytes. The pages of each mip come from the layout (here mip 1 is pages 0..4, mip 0 is pages 4..20). After the first submit, each case does an unchanged resubmit, then rewrites mip 1 pages, mip 0 pages, and everything.

Results on WARP (D3D12 upload + readback):

case parent 3ce6a893 head 17bb212c
mip 1 wholly untracked, mip 0 tracked FAIL: mip 1 wrong in 64/64 samples in all 5 steps (stays zero) pass
mip 0 wholly untracked, mip 1 tracked FAIL: mip 0 wrong 64/64 in all 5 steps pass
mip 0 straddles tracked/untracked, mip 1 untracked FAIL: mip 1 wrong 64/64 pass
4-page untracked hole inside mip 0 pass pass
control: all pages tracked pass pass
control: no pages tracked (hash path) pass pass

Upload counts on an unchanged resubmit (no title writes), as reported by the staging counters:

  • all-tracked control: 0 subresources at parent and head
  • no-tracking control: 0 subresources at parent and head
  • hole: parent 0; head 1 subresource
  • mip 1 untracked: parent 0; head 1 subresource
  • mip 0 untracked: parent 0; head 1 subresource (the untracked mip 0)
  • mip 0 straddling: parent 0; head 2 subresources

So at head the subresources that touch untracked pages were re-uploaded on every submission here, even with no writes; the tracked and untracked controls re-uploaded nothing. I did not assert on this count, only observed it.

Also run: the existing victory-gpu lib suite on WARP at head, --test-threads=1: 254 passed, 0 failed, 1 ignored (includes the 8 new local tests and the existing texture upload tests such as a_write_into_one_mip_uploads_that_mip_alone). The review's request for a no-re-upload assertion and #2639 were not tested here.

CPU-only coverage (no D3D12): zz_cpu_tracker_classification checks Tracked::untracked for a mixed range returns exactly the untracked run, take never returns it, and the tracker is never clean. Everything in the table above ran on D3D12 under WARP.

AI use: Claude Code (Claude Sonnet 5.5, claude-sonnet-5-5) ran the verification and wrote this report; per the claim, Codex (gpt-6.2-sol) coordinated it. Test patch is local; I can attach it on request. Build output on D: was kept under the 40 GB floor.

**@⁠oni-swr** on GitHub · 2026-11-26 08:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/3103#issuecomment-7186628004) Independent Windows WARP verification of PR #3103 at `17bb212c6484525e98b1025e1b3e284efc9c01a1` (claim: https://git.gtahub.st/github/Marvisak--VIctory/issues/1633). This is a factual test report only; it makes no source-review judgment. **Compared:** head `17bb212c` against its exact parent `3ce6a893` (the head commit changes only `crates/victory-gpu/src/texture.rs`). Parent source was tested by swapping only that file, with the same tests. **Environment:** Windows 11 26200, Rust 1.98.1, `cargo --locked -j 4 -p victory-gpu --features diagnostics`, `VICTORY_D3D12_WARP=1`, `VICTORY_DXIL` = Windows SDK 10.0.26100.0 `dxil.dll` (the new tests compile DXBC `cs_5_1` via `D3DCompile`, so that dll was set but not exercised by them). The adapter was checked before any GPU-backed test: the host device's LUID equals `EnumWarpAdapter`'s, with `Microsoft Basic Render Driver`, vendor 0x1414, `DXGI_ADAPTER_FLAG_SOFTWARE`; every new test re-asserts it. No physical GPU was used. Inputs are synthetic only (byte-pattern fills of anonymous memory); no game files, dumps, shader names or hashes. **Method:** local-only tests (not part of the PR) build a 512x512 RGBA8, two-mip linear texture over adjacent 64 KiB pages, some write-watched (tracked) and the rest ordinary committed memory (untracked). The title-side bytes are written, a D3D12 compute shader samples 64 texels per mip through the host SRV, and the readback is compared to an oracle computed from the memory bytes. The pages of each mip come from the layout (here mip 1 is pages 0..4, mip 0 is pages 4..20). After the first submit, each case does an unchanged resubmit, then rewrites mip 1 pages, mip 0 pages, and everything. **Results on WARP (D3D12 upload + readback):** | case | parent `3ce6a893` | head `17bb212c` | |---|---|---| | mip 1 wholly untracked, mip 0 tracked | **FAIL**: mip 1 wrong in 64/64 samples in all 5 steps (stays zero) | pass | | mip 0 wholly untracked, mip 1 tracked | **FAIL**: mip 0 wrong 64/64 in all 5 steps | pass | | mip 0 straddles tracked/untracked, mip 1 untracked | **FAIL**: mip 1 wrong 64/64 | pass | | 4-page untracked hole inside mip 0 | pass | pass | | control: all pages tracked | pass | pass | | control: no pages tracked (hash path) | pass | pass | Upload counts on an unchanged resubmit (no title writes), as reported by the staging counters: - all-tracked control: 0 subresources at parent and head - no-tracking control: 0 subresources at parent and head - hole: parent 0; **head 1** subresource - mip 1 untracked: parent 0; **head 1** subresource - mip 0 untracked: parent 0; **head 1** subresource (the untracked mip 0) - mip 0 straddling: parent 0; **head 2** subresources So at head the subresources that touch untracked pages were re-uploaded on every submission here, even with no writes; the tracked and untracked controls re-uploaded nothing. I did not assert on this count, only observed it. **Also run:** the existing `victory-gpu` lib suite on WARP at head, `--test-threads=1`: 254 passed, 0 failed, 1 ignored (includes the 8 new local tests and the existing texture upload tests such as `a_write_into_one_mip_uploads_that_mip_alone`). The review's request for a no-re-upload assertion and #2639 were not tested here. **CPU-only coverage (no D3D12):** `zz_cpu_tracker_classification` checks `Tracked::untracked` for a mixed range returns exactly the untracked run, `take` never returns it, and the tracker is never clean. Everything in the table above ran on D3D12 under WARP. **AI use:** Claude Code (Claude Sonnet 5.5, `claude-sonnet-5-5`) ran the verification and wrote this report; per the claim, Codex (gpt-6.2-sol) coordinated it. Test patch is local; I can attach it on request. Build output on `D:` was kept under the 40 GB floor.
github-bot force-pushed github-bot/gh-3103 from 17bb212c64 to 619285aee6 2026-11-26 08:46:42 +00:00 Compare
Author
Owner

@⁠tharun-37 on GitHub · 2026-11-26 08:46 UTC · original

Responding to review:

  1. Untracked kept separate from tracked - racked and untracked are now separate variables. racked goes through the hash-based skip path; untracked only feeds the ouched filter so subresources are re-read but still hash-checked before re-upload.

  2. Fast path preserved - .clean() is checked before .untracked(), so no allocation on the ~123k calls/frame path. A tracker with untracked parts has clean() == false (per watch.rs), so the fast path correctly skips when untracked is empty.

  3. Unrelated xmem.rs changes removed - this PR now only touches crates/victory-gpu/src/texture.rs.

  4. Regression test added - untracked_memory_pages_are_refreshed_like_buffer_copies verifies untracked pages are reported separately, ake() excludes them, and tracker is never clean.

CI is passing and clippy is clean. Please re-review.

**@⁠tharun-37** on GitHub · 2026-11-26 08:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/3103#issuecomment-7186994131) Responding to review: 1. **Untracked kept separate from tracked** - racked and untracked are now separate variables. racked goes through the hash-based skip path; untracked only feeds the ouched filter so subresources are re-read but still hash-checked before re-upload. 2. **Fast path preserved** - .clean() is checked before .untracked(), so no allocation on the ~123k calls/frame path. A tracker with untracked parts has clean() == false (per watch.rs), so the fast path correctly skips when untracked is empty. 3. **Unrelated xmem.rs changes removed** - this PR now only touches crates/victory-gpu/src/texture.rs. 4. **Regression test added** - untracked_memory_pages_are_refreshed_like_buffer_copies verifies untracked pages are reported separately, ake() excludes them, and tracker is never clean. CI is passing and clippy is clean. Please re-review.
This pull request can be merged automatically.
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/3103/head:github-bot/gh-3103'
git switch 'github-bot/gh-3103'

Merge

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