GPU: share live host textures across aliased addresses and canonicalize view descriptors #643

Closed
github-bot wants to merge 3 commits from gh-pr/643/head into gh-pr/643/base
Owner

@⁠nathanbzrr on GitHub · 2026-11-24 06:06 UTC · original
nathanbzrr:gpu/alias-live-host-textures → main · +1025 −30 · 2 files · 3 commits · closed without merging

Summary

Two texture aliasing and view deduplication bugs cause aliased render targets and placed SRVs to read back zeros and leak duplicate host resources/views:

  1. hand_out_resource creates a fresh all-zero HostTexture even when a live Resource at the same virtual address already owns the rendered GPU copy. Downstream CreatePlacedShaderResourceViewX (texture_at) or aliased CreatePlacedResource* calls then see flags == 0, causing texture::title_written to overwrite the separate host copy with CPU zeros and isolating state tracking.
  2. ResourceDesc, D3D12_SHADER_RESOURCE_VIEW_DESC, and D3D12_UNORDERED_ACCESS_VIEW_DESC contain struct padding words and unused union tail words; uncanonicalized stack bytes break PLACED_TEXTURES and VIEWS.index deduplication.

Changes (crates/victory-gpu/src/resource.rs, crates/victory-gpu/src/descriptor.rs)

  • Add canonical_resource_desc (zeroing offsets 4..8 and 52..56), canonical_srv_desc (zeroing d[3] alignment padding and per-ViewDimension unused union words), canonical_uav_desc, and canonical_placed_desc, verified with compile-time offset_of! / size_of! assertions against windows-0.62.2.
  • Apply canonicalization in texture_at, create_srv, create_uav, create_placed_srv, and create_placed_uav while preserving placed desc[10..16].
  • Add a Windows LIVE_TEXTURES VA registry (TextureKey, LiveTexture, find_live_texture, register_live_texture, unregister_live_texture) in resource.rs:
    • hand_out_resource reuses a compatible live Arc<HostTexture> at the same VA (preferring GPU-writable targets, enforcing geometry/family, usage-flag, typed-depth SRV, and non-typeless writable format compatibility) without resetting HostTexture::state.
    • Drop for Resource unregisters dropped resources from LIVE_TEXTURES.
    • texture_at upgrades non-writable PLACED_TEXTURES hits if a compatible live GPU-writable HostTexture becomes active at that VA (without freeing prior This pointers, maintaining PLACED_TEXTURES -> LIVE_TEXTURES lock order).

Verification

Isolated verification on branch gpu/alias-live-host-textures (5cab0f1):

  • rustfmt --edition 2024 --config skip_children=true --check crates/victory-gpu/src/resource.rs crates/victory-gpu/src/descriptor.rs (passed)
  • cargo test -p victory-gpu -- --test-threads=1 (46 passed, 0 failed, 1 ignored; includes canonicalization_deduplicates_padding_and_unused_union_words, placed_srv_and_aliased_resource_see_rendered_target_pixels, and incompatible_alias_flags_or_geometry_do_not_share_host_texture)
  • VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics -- --test-threads=1 (48 passed, 0 failed, 1 ignored; zero D3D12 debug layer errors)
  • cargo clippy -p victory-gpu --all-targets (0 warnings in resource.rs and descriptor.rs; 1 pre-existing warning at host.rs:267)
  • cargo xtask policy (151 files ok)

No game files. AI-assisted; reviewed and verified with the tests above.

**@⁠nathanbzrr** on GitHub · 2026-11-24 06:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/643) `nathanbzrr:gpu/alias-live-host-textures` → `main` · +1025 −30 · 2 files · 3 commits · closed without merging ## Summary Two texture aliasing and view deduplication bugs cause aliased render targets and placed SRVs to read back zeros and leak duplicate host resources/views: 1. `hand_out_resource` creates a fresh all-zero `HostTexture` even when a live `Resource` at the same virtual address already owns the rendered GPU copy. Downstream `CreatePlacedShaderResourceViewX` (`texture_at`) or aliased `CreatePlacedResource*` calls then see `flags == 0`, causing `texture::title_written` to overwrite the separate host copy with CPU zeros and isolating state tracking. 2. `ResourceDesc`, `D3D12_SHADER_RESOURCE_VIEW_DESC`, and `D3D12_UNORDERED_ACCESS_VIEW_DESC` contain struct padding words and unused union tail words; uncanonicalized stack bytes break `PLACED_TEXTURES` and `VIEWS.index` deduplication. ### Changes (`crates/victory-gpu/src/resource.rs`, `crates/victory-gpu/src/descriptor.rs`) - Add `canonical_resource_desc` (zeroing offsets 4..8 and 52..56), `canonical_srv_desc` (zeroing `d[3]` alignment padding and per-`ViewDimension` unused union words), `canonical_uav_desc`, and `canonical_placed_desc`, verified with compile-time `offset_of!` / `size_of!` assertions against `windows-0.62.2`. - Apply canonicalization in `texture_at`, `create_srv`, `create_uav`, `create_placed_srv`, and `create_placed_uav` while preserving placed `desc[10..16]`. - Add a Windows `LIVE_TEXTURES` VA registry (`TextureKey`, `LiveTexture`, `find_live_texture`, `register_live_texture`, `unregister_live_texture`) in `resource.rs`: - `hand_out_resource` reuses a compatible live `Arc<HostTexture>` at the same VA (preferring GPU-writable targets, enforcing geometry/family, usage-flag, typed-depth SRV, and non-typeless writable format compatibility) without resetting `HostTexture::state`. - `Drop for Resource` unregisters dropped resources from `LIVE_TEXTURES`. - `texture_at` upgrades non-writable `PLACED_TEXTURES` hits if a compatible live GPU-writable `HostTexture` becomes active at that VA (without freeing prior `This` pointers, maintaining `PLACED_TEXTURES` -> `LIVE_TEXTURES` lock order). ## Verification Isolated verification on branch `gpu/alias-live-host-textures` (`5cab0f1`): - `rustfmt --edition 2024 --config skip_children=true --check crates/victory-gpu/src/resource.rs crates/victory-gpu/src/descriptor.rs` (passed) - `cargo test -p victory-gpu -- --test-threads=1` (46 passed, 0 failed, 1 ignored; includes `canonicalization_deduplicates_padding_and_unused_union_words`, `placed_srv_and_aliased_resource_see_rendered_target_pixels`, and `incompatible_alias_flags_or_geometry_do_not_share_host_texture`) - `VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics -- --test-threads=1` (48 passed, 0 failed, 1 ignored; zero D3D12 debug layer errors) - `cargo clippy -p victory-gpu --all-targets` (0 warnings in `resource.rs` and `descriptor.rs`; 1 pre-existing warning at `host.rs:267`) - `cargo xtask policy` (151 files ok) No game files. AI-assisted; reviewed and verified with the tests above.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:11:14 +00:00
github-bot closed this pull request 2026-11-26 04:11:14 +00:00
Author
Owner

@⁠nathanbzrr on GitHub · 2026-11-24 06:34 UTC · original

Thanks @⁠LAKSHYA-cmd-tech for catching the 0.5 * 255.0 = 127.5 float-to-UNORM rounding variance!

Updated clear in placed_srv_and_aliased_resource_see_rendered_target_pixels (commit e7b2182) to [64.0f32 / 255.0, 128.0 / 255.0, 191.0 / 255.0, 1.0] so all channels hit exact integers regardless of hardware rounding vs truncation on 0.5 ties.

Re-verified on branch gpu/alias-live-host-textures:

  • cargo test -p victory-gpu -- --test-threads=1 (46 passed, 0 failed, 1 ignored)
  • VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics -- --test-threads=1 (48 passed, 0 failed, 1 ignored)
  • cargo clippy -p victory-gpu --all-targets (0 warnings in resource.rs)
  • cargo xtask policy (151 files ok)
**@⁠nathanbzrr** on GitHub · 2026-11-24 06:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/643#issuecomment-7124072288) Thanks @⁠LAKSHYA-cmd-tech for catching the `0.5 * 255.0 = 127.5` float-to-UNORM rounding variance! Updated `clear` in `placed_srv_and_aliased_resource_see_rendered_target_pixels` (commit `e7b2182`) to `[64.0f32 / 255.0, 128.0 / 255.0, 191.0 / 255.0, 1.0]` so all channels hit exact integers regardless of hardware rounding vs truncation on 0.5 ties. Re-verified on branch `gpu/alias-live-host-textures`: - `cargo test -p victory-gpu -- --test-threads=1` (46 passed, 0 failed, 1 ignored) - `VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics -- --test-threads=1` (48 passed, 0 failed, 1 ignored) - `cargo clippy -p victory-gpu --all-targets` (0 warnings in `resource.rs`) - `cargo xtask policy` (151 files ok)
Author
Owner

@⁠YouKnowWh on GitHub · 2026-11-24 06:35 UTC · original

Tested 5cab0f1 on Windows 11 with an RTX 5070 Ti (driver 621.14), using synthetic textures in a diagnostics build.

I used two identical 4×4 placed textures in one guest heap, initialized B to a sentinel, uploaded a known pattern to A, and read 64 bytes back from B. This comparison checks host backing identity without issuing an aliasing barrier. On the d2a4bae + #322 baseline, B retained its sentinel at the same offset. On this PR it returned all 64 bytes of A's pattern for both R10G10B10A2_UNORM and R8G8B8A8_UNORM. The different-offset control retained the sentinel, and the same-object control returned the pattern on both versions. The incompatible-alias test also passed on the PR.

One test portability finding: the unchanged assertion in placed_srv_and_aliased_resource_see_rendered_target_pixels failed at pixel (0,0): got [64,127,191,255], expected [64,128,191,255]. Changing only the clear to [1.0,0.0,1.0,1.0] and the expected bytes to [255,0,255,255] made the full 16×16 test pass on the same machine. Endpoint colors keep the exact equality check while avoiding the midpoint conversion in this aliasing test.

This verifies the synthetic case. We haven't established that the two textures seen during gameplay overlap in guest memory. AI-assisted test setup and reporting.

**@⁠YouKnowWh** on GitHub · 2026-11-24 06:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/643#issuecomment-7124090826) Tested 5cab0f1 on Windows 11 with an RTX 5070 Ti (driver 621.14), using synthetic textures in a diagnostics build. I used two identical 4×4 placed textures in one guest heap, initialized B to a sentinel, uploaded a known pattern to A, and read 64 bytes back from B. This comparison checks host backing identity without issuing an aliasing barrier. On the d2a4bae + #322 baseline, B retained its sentinel at the same offset. On this PR it returned all 64 bytes of A's pattern for both R10G10B10A2_UNORM and R8G8B8A8_UNORM. The different-offset control retained the sentinel, and the same-object control returned the pattern on both versions. The incompatible-alias test also passed on the PR. One test portability finding: the unchanged assertion in `placed_srv_and_aliased_resource_see_rendered_target_pixels` failed at pixel (0,0): got [64,127,191,255], expected [64,128,191,255]. Changing only the clear to [1.0,0.0,1.0,1.0] and the expected bytes to [255,0,255,255] made the full 16×16 test pass on the same machine. Endpoint colors keep the exact equality check while avoiding the midpoint conversion in this aliasing test. This verifies the synthetic case. We haven't established that the two textures seen during gameplay overlap in guest memory. AI-assisted test setup and reporting.
Author
Owner

@⁠nathanbzrr on GitHub · 2026-11-24 06:49 UTC · original

Thanks @⁠YouKnowWh for verifying aliased host backing identity on RTX 5070 Ti across both R10G10B10A2_UNORM and R8G8B8A8_UNORM and the controls!

Note that commit e7b2182 (pushed right before your comment on 5cab0f1) already updated clear in placed_srv_and_aliased_resource_see_rendered_target_pixels from [0.25, 0.5, 0.75, 1.0] to exact [64.0f32 / 255.0, 128.0 / 255.0, 191.0 / 255.0, 1.0] so the green channel lands on an exact integer regardless of driver 0.5-tie rounding vs truncation.

**@⁠nathanbzrr** on GitHub · 2026-11-24 06:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/643#issuecomment-7124321947) Thanks @⁠YouKnowWh for verifying aliased host backing identity on RTX 5070 Ti across both `R10G10B10A2_UNORM` and `R8G8B8A8_UNORM` and the controls! Note that commit `e7b2182` (pushed right before your comment on `5cab0f1`) already updated `clear` in `placed_srv_and_aliased_resource_see_rendered_target_pixels` from `[0.25, 0.5, 0.75, 1.0]` to exact `[64.0f32 / 255.0, 128.0 / 255.0, 191.0 / 255.0, 1.0]` so the green channel lands on an exact integer regardless of driver 0.5-tie rounding vs truncation.
Author
Owner

@⁠DeerSilver on GitHub · 2026-11-24 10:36 UTC · original

Tested the current head e7b2182e5 (with the exact n / 255.0 clear) merged onto main ffe310e (clean merge) on NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell), driver 621.24, Windows 11 26300, Rust 1.98.1: pass. The earlier RTX 5070 Ti check was of 5cab0f1. No game files: the test suite only.

  • The PR's three tests pass:
    • canonicalization_deduplicates_padding_and_unused_union_words
    • placed_srv_and_aliased_resource_see_rendered_target_pixels
    • incompatible_alias_flags_or_geometry_do_not_share_host_texture
  • The two resource::tests cases return early without a host GPU. Here they ran on the RTX 5060 (DXGI adapter 0 on this laptop). So the rendered-target pixels read through the placed SRV and the aliased resource match exactly on NVIDIA with the new clear values.
  • cargo test --workspace --locked: 345 passed, 0 failed, 6 ignored, against 342 / 6 on main at the same commit.
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean.

AI-assisted (Claude Code).

**@⁠DeerSilver** on GitHub · 2026-11-24 10:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/643#issuecomment-7129004013) Tested the current head `e7b2182e5` (with the exact `n / 255.0` clear) merged onto `main` `ffe310e` (clean merge) on **NVIDIA GeForce RTX 5060 Laptop GPU** (Blackwell), driver 621.24, Windows 11 26300, Rust 1.98.1: **pass.** The earlier RTX 5070 Ti check was of `5cab0f1`. No game files: the test suite only. - The PR's three tests pass: - `canonicalization_deduplicates_padding_and_unused_union_words` - `placed_srv_and_aliased_resource_see_rendered_target_pixels` - `incompatible_alias_flags_or_geometry_do_not_share_host_texture` - The two `resource::tests` cases return early without a host GPU. Here they ran on the RTX 5060 (DXGI adapter 0 on this laptop). So the rendered-target pixels read through the placed SRV and the aliased resource match exactly on NVIDIA with the new clear values. - `cargo test --workspace --locked`: **345 passed, 0 failed, 6 ignored**, against 342 / 6 on `main` at the same commit. - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. AI-assisted (Claude Code).
Author
Owner

@⁠rpmaster2 on GitHub · 2026-11-24 14:20 UTC · original

@⁠nathanbzrr an AMD data point for this PR, because it changes what reaches the screen and I have not seen RDNA4 numbers in this thread.

I tested main @⁠ffe310e with #878 + #585 + this PR + #581 stacked (all four merge cleanly; one semantic fix needed: #581 still says UNORDERED where this PR renamed it UNORDERED_FLAG). Diag build, VICTORY_D3D12_DRED=1, RX 9070 XT, Adrenalin 26.11.2, one 600 s run.

What changed on screen for the first time with this stack:

  • the "Rockstar Games presents" card appears at all;
  • subtitle text is sharp and, more telling, stops drawing on top of itself - before the stack the same cutscene piled subtitle lines into an unreadable smear at the same frame rate, so that was the wrong texture winning an alias, not a missing clear;
  • animal silhouettes (snake, crocodile) and a blue/red line below centre appear in the cutscene.

Stability is unchanged: the run still lost the device at frame 1349 with the same page fault ... inside freed ["texture 1024x1024 f98 ..."] seen on plain main (that is #597's removal, not this PR's).

One number that may matter to you: in a separate 240 s run with the draw trace on, exactly 20 slots were bound as null views because make found "no host texture and not a buffer" for the view's resource - zero fits refusals, zero texture_at misses, and zero host-texture creation failures in the log. If the alias work is meant to make a view of a re-aliased address resolve to the live host texture, those 20 are the ones that still do not.

Not tested: NVIDIA, other titles, cargo test on the stack. This is a game-run observation, not a correctness claim.

AI-assisted: written by DeepSeek (OpenCode harness) from my run logs; the hardware and the dump are mine.

**@⁠rpmaster2** on GitHub · 2026-11-24 14:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/643#issuecomment-7134217975) @⁠nathanbzrr an AMD data point for this PR, because it changes what reaches the screen and I have not seen RDNA4 numbers in this thread. I tested `main` @⁠ffe310e with #878 + #585 + this PR + #581 stacked (all four merge cleanly; one semantic fix needed: #581 still says `UNORDERED` where this PR renamed it `UNORDERED_FLAG`). Diag build, `VICTORY_D3D12_DRED=1`, RX 9070 XT, Adrenalin 26.11.2, one 600 s run. What changed on screen for the first time with this stack: - the "Rockstar Games presents" card appears at all; - subtitle text is sharp and, more telling, **stops drawing on top of itself** - before the stack the same cutscene piled subtitle lines into an unreadable smear at the same frame rate, so that was the wrong texture winning an alias, not a missing clear; - animal silhouettes (snake, crocodile) and a blue/red line below centre appear in the cutscene. Stability is unchanged: the run still lost the device at frame 1349 with the same `page fault ... inside freed ["texture 1024x1024 f98 ..."]` seen on plain `main` (that is #597's removal, not this PR's). One number that may matter to you: in a separate 240 s run with the draw trace on, exactly 20 slots were bound as null views because `make` found "no host texture and not a buffer" for the view's resource - zero `fits` refusals, zero `texture_at` misses, and zero host-texture creation failures in the log. If the alias work is meant to make a view of a re-aliased address resolve to the live host texture, those 20 are the ones that still do not. Not tested: NVIDIA, other titles, `cargo test` on the stack. This is a game-run observation, not a correctness claim. AI-assisted: written by DeepSeek (OpenCode harness) from my run logs; the hardware and the dump are mine.
Author
Owner

@⁠nathanbzrr on GitHub · 2026-11-24 21:39 UTC · original

Thanks @⁠rpmaster2 for the RX 9070 XT in-game report and for noting the constant rename against #581!

Updated branch gpu/alias-live-host-textures (head 23aace6, rebased onto main ffe310e):

  • Restored the DEPTH, UNORDERED, and DENY_SHADER_RESOURCE constant names in crates/victory-gpu/src/resource.rs so #581 merges cleanly without semantic rename friction.
  • Updated the initial texture_at miss path so a Resource with host.is_none() is released (resource_release(out)) and not inserted into PLACED_TEXTURES, preventing permanent caching of failed host-texture creations.

About those 20 "no host texture and not a buffer" slots in descriptor/host.rs::make: with zero host-texture creation failures and zero texture_at misses, make's View::Shader / View::Unordered fallback hits when resource == 0 (explicit null-resource CreateShaderResourceView(NULL, ...) / CreateUnorderedAccessView(NULL, ...) calls, which also don't go through placed_texture) or a buffer view has desc == None, rather than a missed live-texture alias.

Re-verified on 23aace6 (Windows MSVC):

  • rustfmt --edition 2024 --check crates\victory-gpu\src\resource.rs: clean
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo test --workspace --locked: 345 passed, 0 failed, 6 ignored (victory-gpu: 53 passed, 0 failed, 1 ignored; xtask: 4 passed)
**@⁠nathanbzrr** on GitHub · 2026-11-24 21:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/643#issuecomment-7145225864) Thanks @⁠rpmaster2 for the RX 9070 XT in-game report and for noting the constant rename against `#581`! Updated branch `gpu/alias-live-host-textures` (head `23aace6`, rebased onto `main` `ffe310e`): - Restored the `DEPTH`, `UNORDERED`, and `DENY_SHADER_RESOURCE` constant names in `crates/victory-gpu/src/resource.rs` so `#581` merges cleanly without semantic rename friction. - Updated the initial `texture_at` miss path so a `Resource` with `host.is_none()` is released (`resource_release(out)`) and not inserted into `PLACED_TEXTURES`, preventing permanent caching of failed host-texture creations. About those 20 `"no host texture and not a buffer"` slots in `descriptor/host.rs::make`: with zero host-texture creation failures and zero `texture_at` misses, `make`'s `View::Shader` / `View::Unordered` fallback hits when `resource == 0` (explicit null-resource `CreateShaderResourceView(NULL, ...)` / `CreateUnorderedAccessView(NULL, ...)` calls, which also don't go through `placed_texture`) or a buffer view has `desc == None`, rather than a missed live-texture alias. Re-verified on `23aace6` (Windows MSVC): - `rustfmt --edition 2024 --check crates\victory-gpu\src\resource.rs`: clean - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean - `cargo test --workspace --locked`: 345 passed, 0 failed, 6 ignored (`victory-gpu`: 53 passed, 0 failed, 1 ignored; `xtask`: 4 passed)
Author
Owner

@⁠ghost on GitHub · 2026-11-24 21:51 UTC · original

AI-assisted (Claude Code). RTX 5080, Windows 11. A data point from the game for this PR; I have read the PR's code at e7b2182 and have not run it.

An alias pair this PR's key leaves separate: resources written as R32_UINT and read by address as R9G9B9E5_SHAREDEXP.

While tracing why the world's light buffers read zero, I added a warning for the case this PR is about: a CreatePlacedShaderResourceViewX view (texture_at) naming an address where a texture the host GPU renders or writes already lives. In the opening world scene it fires for 50 textures in one run (48 in another), and every one has the same shape:

  • the title resource at the address is format 42 (R32_UINT) with ALLOW_UNORDERED_ACCESS (a few also ALLOW_RENDER_TARGET), written by compute passes;
  • the view by address names the same address and the same size with format 67 (R9G9B9E5_SHAREDEXP).

So the title packs shared-exponent colours into a uint texture from compute and samples the same memory as R9G9B9E5. Sizes seen: ten at 2560x1440, 1280x720, 2048x456, 2048x512, 2304x576, mip-like chains from 640x360 down to 40x23, 128x128x6 and 128x128x8, and five 80x45x64 volumes. Among the readers are the tiled-lighting pixel stages (two full-resolution ones each) and the scattering passes.

Why I think this PR does not share them: texture_key compares family(pc_format(desc.format)), and family(42) is 39 while family(67) is 67 (not in FAMILIES), so find_live_texture returns nothing and the view keeps a separate host texture fed from title memory. Sharing one host texture would not work for this pair anyway, since no typeless family holds both formats.

What I tried as an experiment on my own tree (not on this branch): before a list samples such a view, CopyResource from the R32_UINT host texture into the R9G9B9E5 one. The Direct3D 10.1 format-conversion table lists R32_UINT/R32_SINT with R9G9B9E5_SHAREDEXP as a copy that reinterprets the bits. On this card that ran over a thousand copies across 35 addresses with no device removal. I have no evidence yet that it changes the picture: 47 of the 50 source textures are themselves zero in my runs because the passes that fill them are dropped or produce zero, so treat the copy as untested for correctness.

Two questions, if useful to you:

  1. Would you want this pair handled in this PR (a registry lookup that tolerates the 42/67 pair and returns "copy from this live texture" in place of "share it"), or left for a follow-up on top of it? I am glad to send the follow-up.
  2. Does anyone know whether relaxed format casting permits an R9G9B9E5 shader view on an R32_UINT resource? The pages I read do not say, which is why I copied.
**@⁠ghost** on GitHub · 2026-11-24 21:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/643#issuecomment-7145481154) *AI-assisted (Claude Code). RTX 5080, Windows 11. A data point from the game for this PR; I have read the PR's code at `e7b2182` and have not run it.* **An alias pair this PR's key leaves separate: resources written as `R32_UINT` and read by address as `R9G9B9E5_SHAREDEXP`.** While tracing why the world's light buffers read zero, I added a warning for the case this PR is about: a `CreatePlacedShaderResourceViewX` view (`texture_at`) naming an address where a texture the host GPU renders or writes already lives. In the opening world scene it fires for **50 textures in one run (48 in another)**, and every one has the same shape: - the title resource at the address is format 42 (`R32_UINT`) with `ALLOW_UNORDERED_ACCESS` (a few also `ALLOW_RENDER_TARGET`), written by compute passes; - the view by address names the same address and the same size with format 67 (`R9G9B9E5_SHAREDEXP`). So the title packs shared-exponent colours into a uint texture from compute and samples the same memory as `R9G9B9E5`. Sizes seen: ten at 2560x1440, 1280x720, 2048x456, 2048x512, 2304x576, mip-like chains from 640x360 down to 40x23, 128x128x6 and 128x128x8, and five 80x45x64 volumes. Among the readers are the tiled-lighting pixel stages (two full-resolution ones each) and the scattering passes. Why I think this PR does not share them: `texture_key` compares `family(pc_format(desc.format))`, and `family(42)` is 39 while `family(67)` is 67 (not in `FAMILIES`), so `find_live_texture` returns nothing and the view keeps a separate host texture fed from title memory. Sharing one host texture would not work for this pair anyway, since no typeless family holds both formats. What I tried as an experiment on my own tree (not on this branch): before a list samples such a view, `CopyResource` from the `R32_UINT` host texture into the `R9G9B9E5` one. The Direct3D 10.1 format-conversion table lists `R32_UINT`/`R32_SINT` with `R9G9B9E5_SHAREDEXP` as a copy that reinterprets the bits. On this card that ran over a thousand copies across 35 addresses with no device removal. I have no evidence yet that it changes the picture: 47 of the 50 source textures are themselves zero in my runs because the passes that fill them are dropped or produce zero, so treat the copy as untested for correctness. Two questions, if useful to you: 1. Would you want this pair handled in this PR (a registry lookup that tolerates the 42/67 pair and returns "copy from this live texture" in place of "share it"), or left for a follow-up on top of it? I am glad to send the follow-up. 2. Does anyone know whether relaxed format casting permits an `R9G9B9E5` shader view on an `R32_UINT` resource? The pages I read do not say, which is why I copied.
Author
Owner

@⁠nathanbzrr on GitHub · 2026-11-24 22:03 UTC · original

Closing this PR as superseded by recent main (70564ae):

  • 13bbd6f (GPU: one host texture per texture memory, and writable twins for depth textures, decision 0007) now shares one host texture per texture memory across resource objects and placed views via MemoryKey / MEMORY / shared_texture, uses CreateCommittedResource3 castable format lists, adds writable twins for depth+UAV textures (twin.rs), and already clears padding words 1 and 13 in texture_at.
  • 683ad7a bridges textures sharing memory under differing descriptions via host copies.

Thank you @⁠rpmaster2 for the earlier review feedback! The small canonical_srv_desc/canonical_uav_desc padding-zeroing helper from crates/victory-gpu/src/descriptor.rs can be submitted as a standalone follow-up PR on main if descriptor deduplication still needs it.

**@⁠nathanbzrr** on GitHub · 2026-11-24 22:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/643#issuecomment-7145741310) Closing this PR as superseded by recent `main` (`70564ae`): - `13bbd6f` (*GPU: one host texture per texture memory, and writable twins for depth textures*, decision 0007) now shares one host texture per texture memory across resource objects and placed views via `MemoryKey` / `MEMORY` / `shared_texture`, uses `CreateCommittedResource3` castable format lists, adds writable twins for depth+UAV textures (`twin.rs`), and already clears padding words 1 and 13 in `texture_at`. - `683ad7a` bridges textures sharing memory under differing descriptions via host copies. Thank you @⁠rpmaster2 for the earlier review feedback! The small `canonical_srv_desc`/`canonical_uav_desc` padding-zeroing helper from `crates/victory-gpu/src/descriptor.rs` can be submitted as a standalone follow-up PR on `main` if descriptor deduplication still needs it.

Pull request closed

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!643
No description provided.