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

Closed
opened 2026-11-27 18:15:56 +00:00 by github-bot · 2 comments
Owner

@⁠Sheffy007 on GitHub · 2026-11-27 18:15 UTC · original

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

**@⁠Sheffy007** on GitHub · 2026-11-27 18:15 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/436) 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
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 18:15:56 +00:00
Author
Owner

@⁠Sheffy007 on GitHub · 2026-11-27 18:15 UTC · original

/claim

**@⁠Sheffy007** on GitHub · 2026-11-27 18:15 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/436#issuecomment-7225299750) /claim
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-27 18:16 UTC · original

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

**@⁠github-actions[bot]** on GitHub · 2026-11-27 18:16 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/436#issuecomment-7225309953) Claimed by @⁠Sheffy007. Open a draft pull request with `Refs #436` in its description within 24 hours, or the claim expires.
This discussion has been locked. Commenting is limited to contributors.
No description provided.