Read placed R9G9B9E5 views from the R32_UINT texture itself (no alias copies) #107

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

@⁠SousaTrashBin on GitHub · 2026-11-26 03:32 UTC · original
SousaTrashBin:rdna4/alias-cast-rgb9e5 → main · +552 −2 · 5 files · 1 commits · open

Placed R9G9B9E5 views read the R32_UINT texture the host writes, without a copy

Every texture alias in a gameplay frame had the same pair of formats: the title writes a texture as R32_UINT through unordered access, and reads the same memory through a view it places there as R9G9B9E5_SHAREDEXP. That format can be neither an unordered-access view nor a render target, so texture::alias copied the texture into a buffer and back into the placed view's own texture, level by level. That was 87 copies a frame and 8.7 ms of the card's time (RX 9070 XT, timing run), on textures up to 2560×1440.

With relaxed format casting (D3D12_OPTIONS12.RelaxedFormatCastingSupported):

  • Castable textures. 2D R32_UINT textures with unordered access are made with CreateCommittedResource3, listing R9G9B9E5_SHAREDEXP as a castable format, in the layout their legacy initial state corresponds to (COMMON, RENDER_TARGET or UNORDERED_ACCESS). They are tagged with private data, so a freed address that comes back can never be mistaken for one. If one cannot be made, it is made as before.
  • Views on the texture itself. A shader view of a placed texture of that format over such a texture (alias_of) gets its descriptor on that texture, in R9G9B9E5_SHAREDEXP, and the draw moves that texture to a shader-resource state. No copy is made.
  • No stale reads. If any descriptor of the view was ever made showing its own copy (before the texture existed, say), that view keeps being copied into as before, since the old descriptor may still be in a slot.

VICTORY_ALIAS_CAST=0 turns it off.

Measured in the title: 1,060 such reads a frame now go to the texture itself and 10 copies a frame remain; the alias copies' time went from 8.7 ms to 0.1 ms a frame.

Tests

  • On the card, under the D3D12 debug layer: a castable texture filled as R32_UINT under legacy barriers and read through an R9G9B9E5_SHAREDEXP view decodes exactly as the format's definition says; the same texture still reads as R32_UINT; a null view is no alias.
  • cargo test -p victory-gpu --lib passes apart from timeline::report::tests::real_waits_are_recorded_with_who_ended_them, which fails the same way on main.

Not checked yet

I have not compared the picture with the copy path. The view now reads the texture as it is at the draw instead of at the last copy, so differences would point at a copy that used to be stale. Worth a look at HDR-heavy places (sky, emissive surfaces) before merging.

A first version crashed at start-up on null shader views (a null This reached resource()); that is fixed and covered by the test.

🤖 Generated with Claude Code

**@⁠SousaTrashBin** on GitHub · 2026-11-26 03:32 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/107) `SousaTrashBin:rdna4/alias-cast-rgb9e5` → `main` · +552 −2 · 5 files · 1 commits · open ## Placed R9G9B9E5 views read the R32_UINT texture the host writes, without a copy Every texture alias in a gameplay frame had the same pair of formats: the title writes a texture as `R32_UINT` through unordered access, and reads the same memory through a view it places there as `R9G9B9E5_SHAREDEXP`. That format can be neither an unordered-access view nor a render target, so `texture::alias` copied the texture into a buffer and back into the placed view's own texture, level by level. That was 87 copies a frame and 8.7 ms of the card's time (RX 9070 XT, timing run), on textures up to 2560×1440. With relaxed format casting (`D3D12_OPTIONS12.RelaxedFormatCastingSupported`): - **Castable textures.** 2D `R32_UINT` textures with unordered access are made with `CreateCommittedResource3`, listing `R9G9B9E5_SHAREDEXP` as a castable format, in the layout their legacy initial state corresponds to (COMMON, RENDER_TARGET or UNORDERED_ACCESS). They are tagged with private data, so a freed address that comes back can never be mistaken for one. If one cannot be made, it is made as before. - **Views on the texture itself.** A shader view of a placed texture of that format over such a texture (`alias_of`) gets its descriptor on that texture, in `R9G9B9E5_SHAREDEXP`, and the draw moves that texture to a shader-resource state. No copy is made. - **No stale reads.** If any descriptor of the view was ever made showing its own copy (before the texture existed, say), that view keeps being copied into as before, since the old descriptor may still be in a slot. `VICTORY_ALIAS_CAST=0` turns it off. Measured in the title: 1,060 such reads a frame now go to the texture itself and 10 copies a frame remain; the alias copies' time went from 8.7 ms to 0.1 ms a frame. ### Tests - On the card, under the D3D12 debug layer: a castable texture filled as `R32_UINT` under legacy barriers and read through an `R9G9B9E5_SHAREDEXP` view decodes exactly as the format's definition says; the same texture still reads as `R32_UINT`; a null view is no alias. - `cargo test -p victory-gpu --lib` passes apart from `timeline::report::tests::real_waits_are_recorded_with_who_ended_them`, which fails the same way on `main`. ### Not checked yet I have not compared the picture with the copy path. The view now reads the texture as it is at the draw instead of at the last copy, so differences would point at a copy that used to be stale. Worth a look at HDR-heavy places (sky, emissive surfaces) before merging. A first version crashed at start-up on null shader views (a null `This` reached `resource()`); that is fixed and covered by the test. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
With relaxed format casting, 2D R32_UINT textures with unordered access are made
castable to R9G9B9E5_SHAREDEXP, and shader views the title places over them in
that format show the texture itself: no copy through a buffer each time
(VICTORY_ALIAS_CAST). A view that ever had a descriptor showing its own copy
keeps being copied into.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:24:43 +00:00
Author
Owner

@⁠bordersky on GitHub · 2026-11-26 05:45 UTC · original

A regression report from Linux, in case the host matters here: with this PR the main characters lose their faces, and VICTORY_ALIAS_CAST=0 alone brings them back.

Setup: RX 7900 XT, Mesa/RADV, Wine with vkd3d-proton master (which reports relaxed format casting), b0cfe2b + this PR + #98 + #108, play.ps1 settings with VICTORY_RELAY=1 VICTORY_CARD_STEPS=0 VICTORY_LAND_ECHO=0, VICTORY_BVH_BUILDER=1.

run faces of the main characters
b0cfe2b without the three PRs present
with #98, #107, #108 gone: eyes, teeth and hair drawn, no face
the same build with VICTORY_ALIAS_CAST=0 present, every character

Every run started from a new game with the checkpoint save (SARC0015) removed beforehand, so it is not the bad-save case of #67/#13. One run each, same scene (the prologue's cells), looked at by eye.

So the R32_UINT-as-R9G9B9E5 read seems to give something the face shading or deformation cannot use on this host. I have not looked further into which view it is; if a log line or a capture of a slot would help, say which and I can run it.

Timing here did not move with the three PRs together (~155 ms a frame against ~150 ms at ~6,800 draws, builder on), so I cannot say anything about the speed side of this one on its own.

**@⁠bordersky** on GitHub · 2026-11-26 05:45 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/107#issuecomment-7183773680) A regression report from Linux, in case the host matters here: with this PR the main characters lose their faces, and `VICTORY_ALIAS_CAST=0` alone brings them back. **Setup:** RX 7900 XT, Mesa/RADV, Wine with vkd3d-proton master (which reports relaxed format casting), `b0cfe2b` + this PR + #98 + #108, `play.ps1` settings with `VICTORY_RELAY=1 VICTORY_CARD_STEPS=0 VICTORY_LAND_ECHO=0`, `VICTORY_BVH_BUILDER=1`. | run | faces of the main characters | |---|---| | `b0cfe2b` without the three PRs | present | | with #98, #107, #108 | **gone**: eyes, teeth and hair drawn, no face | | the same build with `VICTORY_ALIAS_CAST=0` | present, every character | Every run started from a new game with the checkpoint save (`SARC0015`) removed beforehand, so it is not the bad-save case of #67/#13. One run each, same scene (the prologue's cells), looked at by eye. So the R32_UINT-as-R9G9B9E5 read seems to give something the face shading or deformation cannot use on this host. I have not looked further into which view it is; if a log line or a capture of a slot would help, say which and I can run it. Timing here did not move with the three PRs together (~155 ms a frame against ~150 ms at ~6,800 draws, builder on), so I cannot say anything about the speed side of this one on its own.
Author
Owner

@⁠pokces on GitHub · 2026-11-26 06:50 UTC · original · edited 2026-11-26 07:07 UTC

I reproduced a stale packed-texture read on Windows 11 build 26300 with an RX 9070 XT (driver 32.0.32029.2010) on this PR’s d6b7fdf. The reproducer uses a generated 4×4 texture and a one-thread compute shader. Test-only commit

The test copies the SRV into a shader-visible table once, samples writer A, then replaces it with writer B at the same guest address and samples again through the original descriptor. With VICTORY_ALIAS_CAST=1, B should return RGB (0.265625, 0.390625, 7.1875), but the shader still reads A’s (2, 2, 2). With VICTORY_ALIAS_CAST=0, the same executable reads A, B, and the subsequent CPU upload correctly. A local variant that retains a separate texture for views whose writer can change also passes all three samples with casting enabled.

To reproduce from a checkout of this repository:

git fetch https://github.com/pokces/VIctory-7900XTX.git test/pr107-copied-packed-view
git worktree add --detach ../victory-packed-srv-test FETCH_HEAD
cd ../victory-packed-srv-test
foreach ($cast in '1','0') {
    $env:VICTORY_ALIAS_CAST = $cast
    cargo test --locked --profile diag -p victory-gpu --features diagnostics --lib a_published_packed_view_survives_writer_replacement_and_cpu_upload -- --nocapture --test-threads=1
}

This isolates a writer-lifetime case in the Windows D3D12 path. Whether it also explains the face rendering reported on Wine is still open.


The added regression test and this report were generated by GPT 6.2 Astra. The reported samples were read back on the RX 9070 XT.

**@⁠pokces** on GitHub · 2026-11-26 06:50 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/107#issuecomment-7184828135) · edited 2026-11-26 07:07 UTC I reproduced a stale packed-texture read on Windows 11 build 26300 with an RX 9070 XT (driver 32.0.32029.2010) on this PR’s `d6b7fdf`. The reproducer uses a generated 4×4 texture and a one-thread compute shader. [Test-only commit](https://github.com/pokces/VIctory-7900XTX/commit/7f8741e6b1b85a9cb939d6b35cff515e7e5de7b0) The test copies the SRV into a shader-visible table once, samples writer A, then replaces it with writer B at the same guest address and samples again through the original descriptor. With `VICTORY_ALIAS_CAST=1`, B should return RGB `(0.265625, 0.390625, 7.1875)`, but the shader still reads A’s `(2, 2, 2)`. With `VICTORY_ALIAS_CAST=0`, the **same executable** reads A, B, and the subsequent CPU upload correctly. A local variant that retains a separate texture for views whose writer can change also passes all three samples with casting enabled. To reproduce from a checkout of this repository: ```powershell git fetch https://github.com/pokces/VIctory-7900XTX.git test/pr107-copied-packed-view git worktree add --detach ../victory-packed-srv-test FETCH_HEAD cd ../victory-packed-srv-test foreach ($cast in '1','0') { $env:VICTORY_ALIAS_CAST = $cast cargo test --locked --profile diag -p victory-gpu --features diagnostics --lib a_published_packed_view_survives_writer_replacement_and_cpu_upload -- --nocapture --test-threads=1 } ``` This isolates a writer-lifetime case in the Windows D3D12 path. Whether it also explains the face rendering reported on Wine is still open. --- The added regression test and this report were generated by GPT 6.2 Astra. The reported samples were read back on the RX 9070 XT.
Author
Owner

@⁠avatarmanz on GitHub · 2026-11-26 07:35 UTC · original

Left open: VICTORY_ALIAS_CAST is on by default wherever relaxed format casting exists (the 7900 XTX too); needs an in-game check there first.

**@⁠avatarmanz** on GitHub · 2026-11-26 07:35 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/107#issuecomment-7185627478) Left open: VICTORY_ALIAS_CAST is on by default wherever relaxed format casting exists (the 7900 XTX too); needs an in-game check there first.
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/107/head:github-bot/gh-107'
git switch 'github-bot/gh-107'

Merge

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