gpu(native): depth twins drop DXGI 21/119 depth-plane SRVs, mips > 1, bindless remirrors, and render-sampled copies #436

Closed
opened 2026-11-27 18:15:32 +00:00 by Sheffy007 · 2 comments
Sheffy007 commented 2026-11-27 18:15:32 +00:00 (Migrated from github.com)
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T18:15:32Z.


In #258 (#issuecomment-7225008641), setting VICTORY_DEPTH_TWINS=0 brought the lit world scene from ~5% of pixels filled to ~99%.

Tracing NativeHost::depth_twin (crates/victory-gpu/src/native/host.rs) and descriptors::format (crates/victory-gpu/src/native/descriptors.rs) shows four concrete causes in how depth twins interact with the title's depth-plane views and passes:

  1. DXGI 21 (R32_FLOAT_X8X24_TYPELESS) and console 119 (R16_UNORM_X8_TYPELESS, mapped to 21 by pc_format) return None from descriptors::format:
    • Depth-stencil textures (DXGI 19/20 scene depth and DXGI 118 material depth) use R32_FLOAT (41) or R16_UNORM (56) for their depth-plane UAVs, which decode to Some(Format::R32Float) / Some(Format::R16Unorm) and create/write twin.texture.
    • However, D3D12/console depth-plane SRVs of those exact same depth-stencil textures use DXGI 21 (R32_FLOAT_X8X24_TYPELESS) and 119 (pc_format(119) == 21, as in draw.rs:2678), plus 46 (R24_UNORM_X8_TYPELESS). descriptors::format(21) returns None, so format.and_then(|f| self.depth_twin(...)) skips depth_twin completely and binds the SRV to the unwritten depth texture while UAVs write to twin.texture (and ignores mip/slice ranges on non-twinned depth-stencil SRVs as well).
  2. Multi-mip (desc.mips > 1, e.g. Hierarchical-Z depth pyramids) and D2Array (desc.depth_or_layers > 1) depth textures:
    • depth_twin hardcodes mips: 1 and depth_or_layers: 1 (and rejects TexDim::D2Array). Once a twin is created for a multi-mip depth texture, every view at mip >= 1 fails Metal::create_texture_view ("view (m, 1) ... is past the texture"), full-chain SRVs ((0, mips)) are truncated to mip 0 only, and twin_blits only copies mip 0, slice 0.
  3. Bindless SRVs created before the first UAV are never re-written in the Metal heap:
    • When depth_twin creates a twin, it removes heap.take_entries(resource) from heap.mirrored without re-mirroring them immediately (and without checking placed-view alias keys sharing the same Rc<B::Texture>). remirror_tablesonly visitsRoot::Tablespans, so bindless entries indexed viaResourceDescriptorHeapkeep pointing todepthinstead oftwin.texture. Also, placed UAVs (View::Placed(true, ..)`) do not trigger twin creation.
  4. Render passes sampling a twinned depth texture without a compute pass in between (twin_copies):
    • Group::Render calls twin_copies(false, ...), so if a depth texture (shadow map or scene depth) is rendered into (Newer::Depth) and then sampled as a colour SRV by a later Group::Render pass with no Group::Compute pass in between, depth -> twin is never copied and the pixel shader reads stale/zero twin.texture. Tracking 3 states (Depth, Twin, Both, as in twin.rs) copies depth -> twin once before the first sampling Render or Compute pass without redundant round-trip blits.

Refs #258

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6652230867 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/436). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T18:15:32Z. --- In `#258` (`#issuecomment-7225008641`), setting `VICTORY_DEPTH_TWINS=0` brought the lit world scene from ~5% of pixels filled to ~99%. Tracing `NativeHost::depth_twin` (`crates/victory-gpu/src/native/host.rs`) and `descriptors::format` (`crates/victory-gpu/src/native/descriptors.rs`) shows four concrete causes in how depth twins interact with the title's depth-plane views and passes: 1. **DXGI `21` (`R32_FLOAT_X8X24_TYPELESS`) and console `119` (`R16_UNORM_X8_TYPELESS`, mapped to `21` by `pc_format`) return `None` from `descriptors::format`:** - Depth-stencil textures (`DXGI 19`/`20` scene depth and `DXGI 118` material depth) use `R32_FLOAT` (`41`) or `R16_UNORM` (`56`) for their depth-plane UAVs, which decode to `Some(Format::R32Float)` / `Some(Format::R16Unorm)` and create/write `twin.texture`. - However, D3D12/console depth-plane SRVs of those exact same depth-stencil textures use DXGI `21` (`R32_FLOAT_X8X24_TYPELESS`) and `119` (`pc_format(119) == 21`, as in `draw.rs:2678`), plus `46` (`R24_UNORM_X8_TYPELESS`). `descriptors::format(21)` returns `None`, so `format.and_then(|f| self.depth_twin(...))` skips `depth_twin` completely and binds the SRV to the unwritten `depth` texture while UAVs write to `twin.texture` (and ignores mip/slice ranges on non-twinned depth-stencil SRVs as well). 2. **Multi-mip (`desc.mips > 1`, e.g. Hierarchical-Z depth pyramids) and `D2Array` (`desc.depth_or_layers > 1`) depth textures:** - `depth_twin` hardcodes `mips: 1` and `depth_or_layers: 1` (and rejects `TexDim::D2Array`). Once a twin is created for a multi-mip depth texture, every view at `mip >= 1` fails `Metal::create_texture_view` (`"view (m, 1) ... is past the texture"`), full-chain SRVs (`(0, mips)`) are truncated to mip `0` only, and `twin_blits` only copies mip `0`, slice `0`. 3. **Bindless SRVs created before the first UAV are never re-written in the Metal heap:** - When `depth_twin` creates a twin, it removes `heap.take_entries(resource)` from `heap.mirrored` without re-mirroring them immediately (`and without checking placed-view alias keys sharing the same `Rc<B::Texture>`). `remirror_tables` only visits `Root::Table` spans, so bindless entries indexed via `ResourceDescriptorHeap` keep pointing to `depth` instead of `twin.texture`. Also, placed UAVs (`View::Placed(true, ..)`) do not trigger twin creation. 4. **Render passes sampling a twinned depth texture without a compute pass in between (`twin_copies`):** - `Group::Render` calls `twin_copies(false, ...)`, so if a depth texture (shadow map or scene depth) is rendered into (`Newer::Depth`) and then sampled as a colour SRV by a later `Group::Render` pass with no `Group::Compute` pass in between, `depth -> twin` is never copied and the pixel shader reads stale/zero `twin.texture`. Tracking 3 states (`Depth`, `Twin`, `Both`, as in `twin.rs`) copies `depth -> twin` once before the first sampling `Render` or `Compute` pass without redundant round-trip blits. Refs #258
Sheffy007 commented 2026-11-27 18:15:33 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T18:15:33Z.


/claim

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7225299750 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/436#issuecomment-7225299750). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T18:15:33Z. --- /claim
github-actions[bot] commented 2026-11-27 18:16:08 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-27T18:16:08Z.


Claimed by @Sheffy007. Open a draft pull request with Refs #436 in its description within 24 hours, or the claim expires.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7225309953 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/436#issuecomment-7225309953). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-27T18:16:08Z. --- Claimed by @Sheffy007. Open a draft pull request with `Refs #436` in its description within 24 hours, or the claim expires.
Sign in to join this conversation.
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
LakshanSivakumar/Native-Victory-macOS#436
No description provided.