GPU: a remap under an uploaded texture uploads it again (#574) #606

Open
laptopnotebook wants to merge 3 commits from upstream-pr/606 into main
laptopnotebook commented 2026-11-25 03:06:46 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by laptopnotebook on 2026-11-25T03:06:46Z.


Fixes #574.

A title texture that was uploaded and found unchanged since is only checked when a list samples it (texture::upload): the copy into its host texture is not recorded, and a change the check finds is uploaded by the next list. A remap of the texture's memory did not reset that state, so the first list that sampled the texture after the remap read its old texels. Since placed textures are keyed without their filler words (c96b4f2), a view with new filler after a remap reuses the old texture, which made this common.

Now watch::title_memory_remapped calls a new texture::remapped, which marks every staged texture overlapping the range dirty. Its next upload records the copy, and the check at that list's submission reads the new memory into the staging buffer first, so the first list after the remap gets the new texels. Staged textures are indexed by address (weak entries, pruned when let go) and the search is bounded by the largest staged texture, so a remap looks only at textures that can overlap it instead of scanning all of them. Textures still share one host copy while their memory stays mapped, as #574 asks.

Validation:

  • New test texture::remap_tests::a_remap_under_a_staged_texture_makes_it_upload_again stages a texture on the GPU and remaps memory next to it (left alone), an empty range (left alone) and memory under it (marked). It fails with the fix disabled.
  • cargo test --workspace --locked: all pass (Windows 11, NVIDIA).
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean. The run without --all-features fails only on placed_filler_twins being unused, which main fails too; #530 addresses that.
  • A run of the title on this branch with a temporary counter (not in this PR): 8-15 remaps hit uploaded, unchanged textures (1 KiB to 2.7 MB) through the menus and into the prologue, each of which would have been stale for one list before. Texture preparation stayed at 10-28 ms a frame; no crash or device loss. Not shown: a visible difference in a scene, since the stale window is one list.
<!-- greyfinch-sync:fxceless/victory-fork:issue:6596265518 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/606). Originally posted by [laptopnotebook](https://github.com/laptopnotebook) on 2026-11-25T03:06:46Z. --- Fixes #574. A title texture that was uploaded and found unchanged since is only checked when a list samples it (`texture::upload`): the copy into its host texture is not recorded, and a change the check finds is uploaded by the next list. A remap of the texture's memory did not reset that state, so the first list that sampled the texture after the remap read its old texels. Since placed textures are keyed without their filler words (c96b4f2), a view with new filler after a remap reuses the old texture, which made this common. Now `watch::title_memory_remapped` calls a new `texture::remapped`, which marks every staged texture overlapping the range dirty. Its next upload records the copy, and the check at that list's submission reads the new memory into the staging buffer first, so the first list after the remap gets the new texels. Staged textures are indexed by address (weak entries, pruned when let go) and the search is bounded by the largest staged texture, so a remap looks only at textures that can overlap it instead of scanning all of them. Textures still share one host copy while their memory stays mapped, as #574 asks. Validation: - New test `texture::remap_tests::a_remap_under_a_staged_texture_makes_it_upload_again` stages a texture on the GPU and remaps memory next to it (left alone), an empty range (left alone) and memory under it (marked). It fails with the fix disabled. - `cargo test --workspace --locked`: all pass (Windows 11, NVIDIA). - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean. The run without `--all-features` fails only on `placed_filler_twins` being unused, which `main` fails too; #530 addresses that. - A run of the title on this branch with a temporary counter (not in this PR): 8-15 remaps hit uploaded, unchanged textures (1 KiB to 2.7 MB) through the menus and into the prologue, each of which would have been stale for one list before. Texture preparation stayed at 10-28 ms a frame; no crash or device loss. Not shown: a visible difference in a scene, since the stale window is one list.
yualk commented 2026-11-25 05:08:58 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by yualk on 2026-11-25T04:15:37Z.


Independent verification of a45374449912db2dabbe0dc999501dfa522ed47e against the original #574 fixture, no title assets or title process. Locked MSVC diag, Windows, four fresh processes on RTX 5070 Ti (10de:2c05) and D3D12 WARP (1414:008c), each with default normalization and VICTORY_PLACED_FILLER=1.

  • Default retains one backing for two padding encodings (raw mode keeps two). A different-format view remains distinct.
  • After decommit/recommit at the same VA under the mapping write guard, the first list recorded after remap, through draw::readable, returns all 64 expected a5 bytes on both adapters; the next list also returns a5. The original default base returned 5a on the first list.
  • An unrelated recommit records zero uploads. Cumulative first/second/third recorded uploads are 1/2/2, same as independent cold creation. Replaying the held pre-remap upload list does not restore the old 5a data; this is not a claim about a previously recorded refresh-only list.

This verifies completed texture bytes, not only the dirty flag. It does not cover indexed-slot reads, title visuals, or FPS. AI-assisted testing and write-up.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7152679298 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/606#issuecomment-7152679298). Originally posted by [yualk](https://github.com/yualk) on 2026-11-25T04:15:37Z. --- Independent verification of `a45374449912db2dabbe0dc999501dfa522ed47e` against the original #574 fixture, no title assets or title process. Locked MSVC `diag`, Windows, four fresh processes on RTX 5070 Ti (`10de:2c05`) and D3D12 WARP (`1414:008c`), each with default normalization and `VICTORY_PLACED_FILLER=1`. - Default retains one backing for two padding encodings (raw mode keeps two). A different-format view remains distinct. - After decommit/recommit at the same VA under the mapping write guard, the first list **recorded after remap**, through `draw::readable`, returns all 64 expected `a5` bytes on both adapters; the next list also returns `a5`. The original default base returned `5a` on the first list. - An unrelated recommit records zero uploads. Cumulative first/second/third recorded uploads are `1/2/2`, same as independent cold creation. Replaying the held pre-remap **upload** list does not restore the old `5a` data; this is not a claim about a previously recorded refresh-only list. This verifies completed texture bytes, not only the dirty flag. It does not cover indexed-slot reads, title visuals, or FPS. AI-assisted testing and write-up.
SantannaCarlos commented 2026-11-25 05:09:01 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by SantannaCarlos on 2026-11-25T04:38:15Z.


Tested a453744 with two remap tests, on an RTX 4070 and on WARP: both pass, including with the host copy held across the remap.

The tests follow yualk's reproducer from #574 step by step, through the host device:

  1. 64 KiB reserved, committed and filled with 0x5a. A placed SRV through descriptor::host::placed_texture (linear 4x4 RGBA8, one mip), first with filler 17, then 31. Each variant gets texture::upload, a copy-source transition and a fenced readback.
  2. Decommit, title_memory_remapped, commit, title_memory_remapped again, all under title_memory_remapping, then fill with 0xa5.
  3. A view with filler 47, read in two lists.

The second test is the same, except that a host_copy of the texture is held across the remap, the way a descriptor slot that still shows it or a list not yet reset would hold it.

First list after the remap (5a = old bytes):

Tree Nothing holds the copy Copy held
c96b4f2 fails (5a) fails (5a)
c96b4f2 + #432 passes fails (5a)
#606 passes passes
#606 + #432 passes passes
#606, VICTORY_PLACED_FILLER=1 (WARP) passes passes

The RTX 4070 runs use a diagnostics build. On the card, the PR's own remap_tests::a_remap_under_a_staged_texture_makes_it_upload_again passes as well. #606 and #432 apply together cleanly; each adds one line to title_memory_remapped.

So #606 also covers the case #432 leaves open: a host copy that stays alive across the remap.

One case these tests don't reach, from reading refresh_timed: the guarded path is fine, since the remap takes the blocks out of protected and clean, so the next guard reports them written. But a texture that is still only partly mapped after the remap takes the partial-read branch. That branch returns early for 30 frames after the last partial read (last.partial), so even with dirty set the upload copies the staging buffer as it was, and the pages the remap brought in show up as late as the shortcut allows. Clearing last.partial along with the dirty mark would let a remap end that pause. This is the streaming case the shortcut already accepts, not the stale first list from #574. I have not measured it.

The two tests can go in as a commit on top of this if that is useful.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7153026113 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/606#issuecomment-7153026113). Originally posted by [SantannaCarlos](https://github.com/SantannaCarlos) on 2026-11-25T04:38:15Z. --- **Tested `a453744` with two remap tests, on an RTX 4070 and on WARP: both pass, including with the host copy held across the remap.** The tests follow yualk's reproducer from #574 step by step, through the host device: 1. 64 KiB reserved, committed and filled with `0x5a`. A placed SRV through `descriptor::host::placed_texture` (linear 4x4 RGBA8, one mip), first with filler 17, then 31. Each variant gets `texture::upload`, a copy-source transition and a fenced readback. 2. Decommit, `title_memory_remapped`, commit, `title_memory_remapped` again, all under `title_memory_remapping`, then fill with `0xa5`. 3. A view with filler 47, read in two lists. The second test is the same, except that a `host_copy` of the texture is held across the remap, the way a descriptor slot that still shows it or a list not yet reset would hold it. First list after the remap (`5a` = old bytes): | Tree | Nothing holds the copy | Copy held | |---|---|---| | `c96b4f2` | fails (`5a`) | fails (`5a`) | | `c96b4f2` + #432 | passes | fails (`5a`) | | #606 | passes | passes | | #606 + #432 | passes | passes | | #606, `VICTORY_PLACED_FILLER=1` (WARP) | passes | passes | The RTX 4070 runs use a diagnostics build. On the card, the PR's own `remap_tests::a_remap_under_a_staged_texture_makes_it_upload_again` passes as well. #606 and #432 apply together cleanly; each adds one line to `title_memory_remapped`. So #606 also covers the case #432 leaves open: a host copy that stays alive across the remap. One case these tests don't reach, from reading `refresh_timed`: the guarded path is fine, since the remap takes the blocks out of `protected` and `clean`, so the next `guard` reports them written. But a texture that is still only partly mapped after the remap takes the partial-read branch. That branch returns early for 30 frames after the last partial read (`last.partial`), so even with `dirty` set the upload copies the staging buffer as it was, and the pages the remap brought in show up as late as the shortcut allows. Clearing `last.partial` along with the `dirty` mark would let a remap end that pause. This is the streaming case the shortcut already accepts, not the stale first list from #574. I have not measured it. The two tests can go in as a commit on top of this if that is useful.
laptopnotebook commented 2026-11-25 05:09:01 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by laptopnotebook on 2026-11-25T04:41:06Z.


Thanks, this is really thorough. The held-copy case is a good one to have covered, and good to know it stacks cleanly with #432.

Yes please on the tests. Since you can't push to my branch, the easiest is probably a PR against laptopnotebook/victory-fork:fix/574-remapped-staged-texture (or just paste them here and I'll add them with you as the author).

On last.partial: agreed it's a real gap, but I'd rather keep this PR to the stale first list and do that separately. One thing to watch when someone does it: remapped() runs while the runtime holds the mapping write guard, and refresh_timed takes last and then waits on title_memory_reading, so locking last from remapped() can deadlock. It'll need an atomic on Staging (something like a "remapped" flag that refresh_timed swaps and uses to clear partial) rather than touching last directly. I'll look at it after this one, with a measurement of how often a remap actually lands on a partly mapped texture.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7153069799 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/606#issuecomment-7153069799). Originally posted by [laptopnotebook](https://github.com/laptopnotebook) on 2026-11-25T04:41:06Z. --- Thanks, this is really thorough. The held-copy case is a good one to have covered, and good to know it stacks cleanly with #432. Yes please on the tests. Since you can't push to my branch, the easiest is probably a PR against `laptopnotebook/victory-fork:fix/574-remapped-staged-texture` (or just paste them here and I'll add them with you as the author). On `last.partial`: agreed it's a real gap, but I'd rather keep this PR to the stale first list and do that separately. One thing to watch when someone does it: `remapped()` runs while the runtime holds the mapping write guard, and `refresh_timed` takes `last` and then waits on `title_memory_reading`, so locking `last` from `remapped()` can deadlock. It'll need an atomic on `Staging` (something like a "remapped" flag that `refresh_timed` swaps and uses to clear `partial`) rather than touching `last` directly. I'll look at it after this one, with a measurement of how often a remap actually lands on a partly mapped texture.
laptopnotebook commented 2026-11-25 05:09:01 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by laptopnotebook on 2026-11-25T04:42:56Z.


@yualk thanks for running your original fixture against it, and on WARP too. Good to see the first list after the remap come back with the new bytes, and that the unrelated recommit stays at zero uploads. That was the part I couldn't check from a unit test.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7153097977 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/606#issuecomment-7153097977). Originally posted by [laptopnotebook](https://github.com/laptopnotebook) on 2026-11-25T04:42:56Z. --- @yualk thanks for running your original fixture against it, and on WARP too. Good to see the first list after the remap come back with the new bytes, and that the unrelated recommit stays at zero uploads. That was the part I couldn't check from a unit test.
SantannaCarlos commented 2026-11-25 06:06:37 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by SantannaCarlos on 2026-11-25T05:26:11Z.


The two tests are laptopnotebook/victory-fork#1, against your branch.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7153767992 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/606#issuecomment-7153767992). Originally posted by [SantannaCarlos](https://github.com/SantannaCarlos) on 2026-11-25T05:26:11Z. --- The two tests are laptopnotebook/victory-fork#1, against your branch.
laptopnotebook commented 2026-11-25 06:06:38 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by laptopnotebook on 2026-11-25T05:27:32Z.


Merged @SantannaCarlos's two tests into this branch (638afd2). I ran them here too: both pass with the fix and both fail at the first list after the mapping with it reverted, so they pin down #574, including the case where the host copy is held across the remap.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7153794933 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/606#issuecomment-7153794933). Originally posted by [laptopnotebook](https://github.com/laptopnotebook) on 2026-11-25T05:27:32Z. --- Merged @SantannaCarlos's two tests into this branch (638afd2). I ran them here too: both pass with the fix and both fail at the first list after the mapping with it reverted, so they pin down #574, including the case where the host copy is held across the remap.
laptopnotebook commented 2026-11-25 19:09:46 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by laptopnotebook on 2026-11-25T18:44:25Z.


Pushed one follow-up (7476e80) for a case the first fix missed.

A partly mapped texture (some pages there, as while it streams in) is read at most every 30 frames. A remap inside that window marked the texture dirty, so the list recorded the copy, but the read at submission still waited its turn and the copy took the old texels.

The texture now remembers that it was remapped, and the next partial read skips the wait once. Otherwise the 30-frame limit works as before.

The new test (a_remap_under_a_partly_mapped_texture_is_read_at_once) fails without the change (the staging buffer still holds the old byte) and passes with it. cargo test --workspace passes (509). I found this by reading the code and haven't seen a visible difference from it in game.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7171328180 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/606#issuecomment-7171328180). Originally posted by [laptopnotebook](https://github.com/laptopnotebook) on 2026-11-25T18:44:25Z. --- Pushed one follow-up (7476e80) for a case the first fix missed. A partly mapped texture (some pages there, as while it streams in) is read at most every 30 frames. A remap inside that window marked the texture dirty, so the list recorded the copy, but the read at submission still waited its turn and the copy took the old texels. The texture now remembers that it was remapped, and the next partial read skips the wait once. Otherwise the 30-frame limit works as before. The new test (`a_remap_under_a_partly_mapped_texture_is_read_at_once`) fails without the change (the staging buffer still holds the old byte) and passes with it. `cargo test --workspace` passes (509). I found this by reading the code and haven't seen a visible difference from it in game.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/606:upstream-pr/606'
git switch 'upstream-pr/606'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/606'
git switch 'upstream-pr/606'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/606'
git switch 'upstream-pr/606'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/606'
git switch 'main'
git merge --squash 'upstream-pr/606'
git switch 'main'
git merge --ff-only 'upstream-pr/606'
git switch 'main'
git merge 'upstream-pr/606'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
fxceless/victory-fork!606
No description provided.