GPU: bind texture readback to recorded mapping #63

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

@⁠Cuebert on GitHub · 2026-11-26 02:28 UTC · original
Cuebert:fix/texture-copyback-mapping → main · +143 −16 · 3 files · 1 commits · open

I found a lifetime gap in the texture readback path. texture_written retained the resource, but texback::record captured the guest mapping ticket only when the command list closed. If the guest remapped the address between recording the GPU writer and closing the list, the later copyback could target the replacement pages.

This change captures the ResourceRef, layout, guest range and ReadbackMapping when the first writer is recorded. The deferred copy uses that same target and the existing mapping check rejects a stale landing. I kept the copyback behavior and the existing overlap policy intact.

The original water texture copyback came from Geckomacabre’s vx-layer work (commit); the related VIctory integration is fxceless/victory-fork#999. This PR carries that existing path forward and adds recorded-mapping lifetime protection.

I added a Windows D3D12 WARP regression that records a texture writer, remaps the guest address before list close, and checks that replacement bytes survive while ordinary writes still copy back. The supplied validation record reports the focused fixture passing in synchronous and late stage 3 modes. This is synthetic validation; I have not verified a title or gameplay effect.

Could you review whether capturing the mapping at first writer is the right lifetime boundary for this path?

**@⁠Cuebert** on GitHub · 2026-11-26 02:28 UTC · [original](https://github.com/DexNom/VIctory/pull/63) `Cuebert:fix/texture-copyback-mapping` → `main` · +143 −16 · 3 files · 1 commits · open I found a lifetime gap in the texture readback path. `texture_written` retained the resource, but `texback::record` captured the guest mapping ticket only when the command list closed. If the guest remapped the address between recording the GPU writer and closing the list, the later copyback could target the replacement pages. This change captures the `ResourceRef`, layout, guest range and `ReadbackMapping` when the first writer is recorded. The deferred copy uses that same target and the existing mapping check rejects a stale landing. I kept the copyback behavior and the existing overlap policy intact. The original water texture copyback came from Geckomacabre’s `vx-layer` work ([commit](https://github.com/Geckomacabre/vx-layer/commit/eee5667d7119bc4a378214621e1b18a814ebe80f)); the related VIctory integration is [fxceless/victory-fork#999](https://github.com/fxceless/victory-fork/pull/999). This PR carries that existing path forward and adds recorded-mapping lifetime protection. I added a Windows D3D12 WARP regression that records a texture writer, remaps the guest address before list close, and checks that replacement bytes survive while ordinary writes still copy back. The supplied validation record reports the focused fixture passing in synchronous and late stage 3 modes. This is synthetic validation; I have not verified a title or gameplay effect. Could you review whether capturing the mapping at first writer is the right lifetime boundary for this path?
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:33:02 +00:00
Author
Owner

@⁠Artking175 on GitHub · 2026-11-26 05:22 UTC · original

I reproduced this with eefae24 on RTX 2060 / driver 531.41 and WARP. I selected VICTORY_TEXTURE_BACK=64x64f16 and tested VICTORY_LATE_WAIT=0 and 3 on both adapters. All four runs passed with the PR. Keeping the fixture and reverting the production host.rs and texback.rs changes made all four fail at “the old list overwrote replacement pages”.

That supports the first recorded writer as the lifetime boundary for one retained target in this fixture. The test also verifies a later command list can write the replacement mapping. The per-resource dedupe retains the first ticket for the entire list, so the same-list case with a second writer after remapping will need a separate policy if it should publish to the new pages. My test used the PR head based on 2e01ab4.

**@⁠Artking175** on GitHub · 2026-11-26 05:22 UTC · [original](https://github.com/DexNom/VIctory/pull/63#issuecomment-7183429483) I reproduced this with `eefae24` on RTX 2060 / driver 531.41 and WARP. I selected `VICTORY_TEXTURE_BACK=64x64f16` and tested `VICTORY_LATE_WAIT=0` and `3` on both adapters. All four runs passed with the PR. Keeping the fixture and reverting the production `host.rs` and `texback.rs` changes made all four fail at “the old list overwrote replacement pages”. That supports the first recorded writer as the lifetime boundary for one retained target in this fixture. The test also verifies a later command list can write the replacement mapping. The per-resource dedupe retains the first ticket for the entire list, so the same-list case with a second writer after remapping will need a separate policy if it should publish to the new pages. My test used the PR head based on `2e01ab4`.
Author
Owner

@⁠Cuebert on GitHub · 2026-11-26 06:03 UTC · original

Thanks for running the RTX 2060 and WARP matrix, and for calling out the same-list case. Your results independently support the first recorded writer as the target identity for this fixture.

I agree the current per-resource dedupe keeps the first target until list close. If the guest remaps and records another writer to the same texture before that list closes, this patch does not retain a second target or promise publication to the replacement pages. The regression covers rejecting the stale landing and a successful write from a later command list; it does not cover a second write in the same list. I’ll keep that limitation explicit and avoid claiming same-list replacement behavior. A follow-up should add a fixture that records both writers around the remap before closing one list.

**@⁠Cuebert** on GitHub · 2026-11-26 06:03 UTC · [original](https://github.com/DexNom/VIctory/pull/63#issuecomment-7184048470) Thanks for running the RTX 2060 and WARP matrix, and for calling out the same-list case. Your results independently support the first recorded writer as the target identity for this fixture. I agree the current per-resource dedupe keeps the first target until list close. If the guest remaps and records another writer to the same texture before that list closes, this patch does not retain a second target or promise publication to the replacement pages. The regression covers rejecting the stale landing and a successful write from a later command list; it does not cover a second write in the same list. I’ll keep that limitation explicit and avoid claiming same-list replacement behavior. A follow-up should add a fixture that records both writers around the remap before closing one list.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/63/head:github-bot/gh-63'
git switch 'github-bot/gh-63'

Merge

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