gpu(native): fix depth-twin SRV formats, mips/slices, remirrors, and render sync (#436) #439

Merged
Sheffy007 merged 1 commit from upstream-pr/439 into main 2026-11-28 00:38:42 +00:00
Sheffy007 commented 2026-11-27 18:31:50 +00:00 (Migrated from github.com)

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


Summary

Fixes the four depth-twin causes behind VICTORY_DEPTH_TWINS=1 leaving the world ~95% dark (#258, #issuecomment-7225008641):

  1. Decode DXGI 21 / 46 and console 119 depth-plane SRVs (descriptors::format & NativeHost::depth_twin):
    • Maps DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS (21, and console 119 = R16_UNORM_X8_TYPELESS via pc_format) and DXGI_FORMAT_R24_UNORM_X8_TYPELESS (46) to Format::R32Float (plus 44 alongside 19 | 20 | 45 => Format::D32FloatS8). Previously descriptors::format(21) returned None, causing depth-plane SRVs of D32_FLOAT_S8X24_UINT (19/20) and D16_UNORM_S8_UINT (118) to bypass depth_twin and read the unwritten depth texture while UAVs (41 / 56) wrote twin.texture. Also redirects whole-texture (None format) and depth-typed SRVs of twinned depth textures onto twin.texture.
  2. Full mip-chain & 2D-array DepthTwin (NativeHost::depth_twin & NativeHost::twin_blits):
    • Creates twin.texture with desc.dim (TexDim::D2 | TexDim::D2Array) and all host mip levels and array slices (honouring dropped top levels), laying out sequential 256-byte-aligned TwinRoute regions in stage so high-mip UAVs (e.g. Hierarchical-Z depth pyramids), full-chain SRVs, and array shadow maps mirror and copy every (slice, mip) subresource bit for bit.
  3. Placed UAVs & immediate bindless/alias re-mirroring (NativeHost::mirror):
    • Allows View::Placed(true, ..) depth UAVs to create twins (placed_info_of), and immediately re-mirrors any previously mirrored heap entries (including bindless slots outside Root::Table spans and placed-view alias keys sharing the same Rc<B::Texture>) onto the new twin.
  4. 3-state TwinNewer { Depth, Twin, Both } & render-sampled sync (NativeHost::twin_copies):
    • Copies depth -> twin (Both) before Group::Render passes for twins not bound as targets.depth, so pixel/vertex/mesh shaders sampling a shadow map or scene depth with no intervening compute pass read fresh depth once without forcing redundant reverse copies. Leaves stencil-only clears (z.is_none()) and read-only copies (Both) from clobbering the newer depth side.

Verification

  • Unit test descriptors::tests::depth_stencil_shader_view_formats_decode_to_float_depth_plane.
  • Metal GPU subresource + bindless/placed tests texture_tests::multi_mip_array_and_placed_depth_twins_preserve_all_subresources_and_remirror_immediately (4-mip D32_FLOAT_S8X24_UINT, 2-slice x 3-mip D16_UNORM D2Array, bindless index 24 immediate remirror, and View::Placed(true, ..) twin creation).
  • End-to-end Metal GPU pipeline test tests::depth_plane_srvs_and_render_sampled_twins_read_compute_and_depth_writes (compute writes R16_UNORM UAV on DXGI 118 -> stencil-only clear -> tri_ps samples DXGI 119 SRV; then depth clear -> tri_ps samples DXGI 21 SRV with no compute pass in between).
  • cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask
  • cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo xtask policy

Closes #436
Refs #258

cc @Olima34

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5531409102 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/439). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T18:31:50Z. --- ## Summary Fixes the four depth-twin causes behind `VICTORY_DEPTH_TWINS=1` leaving the world ~95% dark (`#258`, `#issuecomment-7225008641`): 1. **Decode DXGI `21` / `46` and console `119` depth-plane SRVs (`descriptors::format` & `NativeHost::depth_twin`):** - Maps `DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS` (`21`, and console `119 = R16_UNORM_X8_TYPELESS` via `pc_format`) and `DXGI_FORMAT_R24_UNORM_X8_TYPELESS` (`46`) to `Format::R32Float` (plus `44` alongside `19 | 20 | 45 => Format::D32FloatS8`). Previously `descriptors::format(21)` returned `None`, causing depth-plane SRVs of `D32_FLOAT_S8X24_UINT` (`19`/`20`) and `D16_UNORM_S8_UINT` (`118`) to bypass `depth_twin` and read the unwritten `depth` texture while UAVs (`41` / `56`) wrote `twin.texture`. Also redirects whole-texture (`None` format) and depth-typed SRVs of twinned depth textures onto `twin.texture`. 2. **Full mip-chain & 2D-array `DepthTwin` (`NativeHost::depth_twin` & `NativeHost::twin_blits`):** - Creates `twin.texture` with `desc.dim` (`TexDim::D2 | TexDim::D2Array`) and all host mip levels and array slices (honouring `dropped` top levels), laying out sequential 256-byte-aligned `TwinRoute` regions in `stage` so high-mip UAVs (e.g. Hierarchical-Z depth pyramids), full-chain SRVs, and array shadow maps mirror and copy every `(slice, mip)` subresource bit for bit. 3. **Placed UAVs & immediate bindless/alias re-mirroring (`NativeHost::mirror`):** - Allows `View::Placed(true, ..)` depth UAVs to create twins (`placed_info_of`), and immediately re-mirrors any previously mirrored heap entries (including bindless slots outside `Root::Table` spans and placed-view alias keys sharing the same `Rc<B::Texture>`) onto the new twin. 4. **3-state `TwinNewer { Depth, Twin, Both }` & render-sampled sync (`NativeHost::twin_copies`):** - Copies `depth -> twin` (`Both`) before `Group::Render` passes for twins not bound as `targets.depth`, so pixel/vertex/mesh shaders sampling a shadow map or scene depth with no intervening compute pass read fresh depth once without forcing redundant reverse copies. Leaves stencil-only clears (`z.is_none()`) and read-only copies (`Both`) from clobbering the newer depth side. ## Verification - Unit test `descriptors::tests::depth_stencil_shader_view_formats_decode_to_float_depth_plane`. - Metal GPU subresource + bindless/placed tests `texture_tests::multi_mip_array_and_placed_depth_twins_preserve_all_subresources_and_remirror_immediately` (4-mip `D32_FLOAT_S8X24_UINT`, 2-slice x 3-mip `D16_UNORM` `D2Array`, bindless index 24 immediate remirror, and `View::Placed(true, ..)` twin creation). - End-to-end Metal GPU pipeline test `tests::depth_plane_srvs_and_render_sampled_twins_read_compute_and_depth_writes` (compute writes `R16_UNORM` UAV on `DXGI 118` -> stencil-only clear -> `tri_ps` samples `DXGI 119` SRV; then depth clear -> `tri_ps` samples `DXGI 21` SRV with no compute pass in between). - `cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask` - `cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo xtask policy` Closes #436 Refs #258 cc @Olima34
alexballvideos-netizen commented 2026-11-27 20:37:21 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by alexballvideos-netizen on 2026-11-27T20:37:21Z.


A/B of this PR on an M3 Max, 36 GB, macOS 27.2.1, Series X profile (the preview note says Series X wasn't run). Headless, 300 s each, warm cache, VICTORY_TRACE_TARGETS=1 VICTORY_DUMP_TARGETS=…,110,20. "Lit" is the logged lit= fraction of the F10 1280x720 scene colour target, taking the highest per dump. Counts only.

run scene lit, per dump (from world entry) peak mesh draws end
main b998bb65, twins on 0.00 0.12 0.06 0.02 0.01 0.01 0.29 0.29 3,938 timer, 0 GPU errors
main b998bb65, VICTORY_DEPTH_TWINS=0 0.58 0.73 0.84 0.51 0.22 0.03 0.03 0.84 4,138 crash at about 270 s (below)
this PR (30511a9d), twins on 0.11 0.09 0.01 0.09 0.23 0.26 0.06 0.42 0.66 0.66 6,376 timer, 0 GPU errors
  • The PR lights the scene with twins on. Peak 0.66 against main's 0.29, close to twins-off's 0.84, with no switch needed. The 2560x1440 upscaled target follows: 0.47 against 0.25 on main.
  • Caveat: the timelines aren't aligned. World entry lands at a different second in each run, and the prologue cuts between scenes, so a single dump isn't a like-for-like frame. The trend is clear, but these are three single runs.
  • In both lit runs, the bright frames show the large flat shards across the picture that the preview note already lists, so this PR doesn't touch those.
  • Twins off went dark again from about 60 s into the world (0.03), then crashed. The first fault was at image+0x2215c35: not the watchdog write at image+0x23cf683 from #404, and with no never reported on GPU stall before it. Then came the usual secondary fault in the crash reporter at 0x55e56f8. That's one run, so I can't say yet whether it's caused by twins off.
  • The PR run reached frame 2176 and main reached 2688 in the same 300 s. World fps is about the same; the difference is mostly how long the load took.

I haven't checked: Series S, a windowed run, or the corpus. If a single fixed frame would help (for example, with VICTORY_TRACE_PASSES at a set world present), say which, and I'll rerun all three on it.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7227682648 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/439#issuecomment-7227682648). Originally posted by [alexballvideos-netizen](https://github.com/alexballvideos-netizen) on 2026-11-27T20:37:21Z. --- A/B of this PR on an M3 Max, 36 GB, macOS 27.2.1, **Series X** profile (the preview note says Series X wasn't run). Headless, 300 s each, warm cache, `VICTORY_TRACE_TARGETS=1 VICTORY_DUMP_TARGETS=…,110,20`. "Lit" is the logged `lit=` fraction of the F10 1280x720 scene colour target, taking the highest per dump. Counts only. | run | scene lit, per dump (from world entry) | peak | mesh draws | end | |---|---|---|---|---| | main b998bb65, twins on | 0.00 0.12 0.06 0.02 0.01 0.01 0.29 | 0.29 | 3,938 | timer, 0 GPU errors | | main b998bb65, `VICTORY_DEPTH_TWINS=0` | 0.58 0.73 0.84 0.51 0.22 0.03 0.03 | 0.84 | 4,138 | crash at about 270 s (below) | | **this PR (30511a9d), twins on** | 0.11 0.09 0.01 0.09 0.23 0.26 0.06 0.42 0.66 | 0.66 | **6,376** | timer, 0 GPU errors | - **The PR lights the scene with twins on.** Peak 0.66 against main's 0.29, close to twins-off's 0.84, with no switch needed. The 2560x1440 upscaled target follows: 0.47 against 0.25 on main. - **Caveat: the timelines aren't aligned.** World entry lands at a different second in each run, and the prologue cuts between scenes, so a single dump isn't a like-for-like frame. The trend is clear, but these are three single runs. - In both lit runs, the bright frames show the large flat shards across the picture that the preview note already lists, so this PR doesn't touch those. - **Twins off went dark again from about 60 s into the world** (0.03), then crashed. The first fault was at `image+0x2215c35`: not the watchdog write at `image+0x23cf683` from #404, and with no `never reported on` GPU stall before it. Then came the usual secondary fault in the crash reporter at `0x55e56f8`. That's one run, so I can't say yet whether it's caused by twins off. - The PR run reached frame 2176 and main reached 2688 in the same 300 s. World fps is about the same; the difference is mostly how long the load took. I haven't checked: Series S, a windowed run, or the corpus. If a single fixed frame would help (for example, with `VICTORY_TRACE_PASSES` at a set world present), say which, and I'll rerun all three on it.
alexballvideos-netizen commented 2026-11-27 21:08:18 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by alexballvideos-netizen on 2026-11-27T21:08:18Z.


Correction to my A/B above: the twins-off crash at image+0x2215c35 is the #456 freeze (a job thread spinning in title code, no GPU stall; see #404). It's not related to depth twins, so this PR's comparison is unaffected.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7228169507 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/439#issuecomment-7228169507). Originally posted by [alexballvideos-netizen](https://github.com/alexballvideos-netizen) on 2026-11-27T21:08:18Z. --- Correction to my A/B above: the twins-off crash at `image+0x2215c35` is the #456 freeze (a job thread spinning in title code, no GPU stall; see #404). It's not related to depth twins, so this PR's comparison is unaffected.
Sign in to join this conversation.
No reviewers
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!439
No description provided.