GPU: fix PresentX subresource copy and plane format handling #3257

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

@⁠fuzeofficlal on GitHub · 2026-11-26 14:48 UTC · original
fuzeofficlal:fix/gpu-present-formats-subresource → main · +491 −13 · 1 files · 1 commits · open

Summary

Fixes three D3D12 contract and rendering bugs in Host::present_with_compositor (crates/victory-gpu/src/host.rs) when presenting valid D3D12.X textures:

  1. Single-plane copy of mipmapped or array textures: present_with_compositor called CopyResource(&back, texture), which violates D3D12's matching-dimensions rule whenever the presented texture has MipLevels > 1 or DepthOrArraySize > 1 (the DXGI swap-chain back buffer always has 1 mip and 1 slice). This emitted D3D12 Debug Layer error #944 on hardware and WARP and aborted the process (0xc0000409) on retail WARP. Switching to CopyTextureRegion of subresource 0 matches capture::read_back / capture::probe and presents mip 0 slice 0 cleanly.
  2. Numeric format conversion for UNORM/SNORM targets into FLOAT/UNORM swap chains: swap_format maps R16G16B16A16_UNORM and R16G16B16A16_SNORM to R16G16B16A16_FLOAT (and R8G8B8A8_SNORM to R8G8B8A8_UNORM). Previously, single-plane presents raw-copied UNORM bits directly into the float swap chain (turning [1.0, 0.5, 0.0, 1.0] into half-float NaNs [0xffff, 0x7fff, 0x0000, 0xffff]), and multi-plane presents created an R16G16B16A16_FLOAT SRV over R16G16B16A16_UNORM, which either produced 0x7fff NaNs on castable textures or triggered permanent device removal (DXGI_ERROR_INVALID_CALL = 0x887A0001, Debug Layer #28 / #232) on non-castable textures. Single-plane format-converting targets now route through Compositor, and compositor_srv_format preserves each typed float/UNORM/SNORM plane's own format for sampling.
  3. Typeless and unsampleable overlay planes: swap_format(d.Format).unwrap_or(d.Format) passed typeless formats outside swap_format (such as B8G8R8X8_TYPELESS, produced by resource::host_desc for B8G8R8X8_UNORM_SRGB textures with ALLOW_UNORDERED_ACCESS) directly to CreateShaderResourceView, immediately removing the host D3D12 device (0x887A0001) on both retail hardware and WARP. compositor_srv_format maps typeless color families to concrete float/UNORM formats and skips unsampleable planes (such as integer formats) instead of issuing an invalid SRV.

Verification

  • RED on 63bcca43:
    • Retail WARP: present_single_plane_copies_subresource_zero_of_mipmapped_and_array_textures aborted (0xc0000409); RTX 5090 + WARP Debug Layer reported D3D12 error #944.
    • Retail RTX 5090: present_converts_unorm16_planes_without_nan_or_device_removal read back raw UNORM bits [65535, 32767, 0, 65535] (NaN) in single-plane and removed non-castable devices (0x887A0001) in multi-plane.
    • Retail RTX 5090: present_composites_typeless_bgrx_overlay_without_device_removal aborted (0xc0000409, 0x887A0001 device removal).
  • GREEN after fix:
    • Targeted tests (compositor_srv_format_preserves_typed_formats_and_resolves_typeless and present_plane_tests) pass on RTX 5090 (default and diagnostics + Debug Layer) and WARP (retail and diagnostics + Debug Layer).
    • Full victory-gpu --lib passes on RTX 5090 default (230 passed), RTX 5090 diagnostics + Debug Layer serial (247 passed), and WARP diagnostics + Debug Layer serial (247 passed).
    • cargo clippy --workspace --all-targets --locked -- -D warnings, --all-features, git diff --check, rustfmt --edition 2024 --check on modified hunks, and cargo run --locked -p xtask -- policy all pass.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 14:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/3257) `fuzeofficlal:fix/gpu-present-formats-subresource` → `main` · +491 −13 · 1 files · 1 commits · open ### Summary Fixes three D3D12 contract and rendering bugs in `Host::present_with_compositor` (`crates/victory-gpu/src/host.rs`) when presenting valid D3D12.X textures: 1. **Single-plane copy of mipmapped or array textures**: `present_with_compositor` called `CopyResource(&back, texture)`, which violates D3D12's matching-dimensions rule whenever the presented texture has `MipLevels > 1` or `DepthOrArraySize > 1` (the DXGI swap-chain back buffer always has 1 mip and 1 slice). This emitted D3D12 Debug Layer error `#944` on hardware and WARP and aborted the process (`0xc0000409`) on retail WARP. Switching to `CopyTextureRegion` of subresource `0` matches `capture::read_back` / `capture::probe` and presents mip 0 slice 0 cleanly. 2. **Numeric format conversion for `UNORM`/`SNORM` targets into `FLOAT`/`UNORM` swap chains**: `swap_format` maps `R16G16B16A16_UNORM` and `R16G16B16A16_SNORM` to `R16G16B16A16_FLOAT` (and `R8G8B8A8_SNORM` to `R8G8B8A8_UNORM`). Previously, single-plane presents raw-copied UNORM bits directly into the float swap chain (turning `[1.0, 0.5, 0.0, 1.0]` into half-float `NaN`s `[0xffff, 0x7fff, 0x0000, 0xffff]`), and multi-plane presents created an `R16G16B16A16_FLOAT` SRV over `R16G16B16A16_UNORM`, which either produced `0x7fff` `NaN`s on castable textures or triggered permanent device removal (`DXGI_ERROR_INVALID_CALL = 0x887A0001`, Debug Layer `#28` / `#232`) on non-castable textures. Single-plane format-converting targets now route through `Compositor`, and `compositor_srv_format` preserves each typed float/UNORM/SNORM plane's own format for sampling. 3. **Typeless and unsampleable overlay planes**: `swap_format(d.Format).unwrap_or(d.Format)` passed typeless formats outside `swap_format` (such as `B8G8R8X8_TYPELESS`, produced by `resource::host_desc` for `B8G8R8X8_UNORM_SRGB` textures with `ALLOW_UNORDERED_ACCESS`) directly to `CreateShaderResourceView`, immediately removing the host D3D12 device (`0x887A0001`) on both retail hardware and WARP. `compositor_srv_format` maps typeless color families to concrete float/UNORM formats and skips unsampleable planes (such as integer formats) instead of issuing an invalid SRV. ### Verification - **RED on `63bcca43`**: - Retail WARP: `present_single_plane_copies_subresource_zero_of_mipmapped_and_array_textures` aborted (`0xc0000409`); RTX 5090 + WARP Debug Layer reported D3D12 error `#944`. - Retail RTX 5090: `present_converts_unorm16_planes_without_nan_or_device_removal` read back raw UNORM bits `[65535, 32767, 0, 65535]` (`NaN`) in single-plane and removed non-castable devices (`0x887A0001`) in multi-plane. - Retail RTX 5090: `present_composites_typeless_bgrx_overlay_without_device_removal` aborted (`0xc0000409`, `0x887A0001` device removal). - **GREEN after fix**: - Targeted tests (`compositor_srv_format_preserves_typed_formats_and_resolves_typeless` and `present_plane_tests`) pass on RTX 5090 (default and diagnostics + Debug Layer) and WARP (retail and diagnostics + Debug Layer). - Full `victory-gpu --lib` passes on RTX 5090 default (230 passed), RTX 5090 diagnostics + Debug Layer serial (247 passed), and WARP diagnostics + Debug Layer serial (247 passed). - `cargo clippy --workspace --all-targets --locked -- -D warnings`, `--all-features`, `git diff --check`, `rustfmt --edition 2024 --check` on modified hunks, and `cargo run --locked -p xtask -- policy` all pass.
Use CopyTextureRegion on subresource 0 instead of CopyResource for single-plane PresentX so mipmapped and array textures present without D3D12 error #944 or WARP process abort.

Route format-converting planes (such as R16G16B16A16_UNORM/SNORM into R16G16B16A16_FLOAT) through the compositor and resolve plane SRV formats without casting across incompatible float/UNORM types or passing typeless/unsampleable formats (such as B8G8R8X8_TYPELESS or integer overlays) to CreateShaderResourceView.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:55:56 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 15:13 UTC · original · approved these changes

Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090 + WARP):

  • Routing format-mismatched planes (R16G16B16A16_{UNORM,SNORM} -> FLOAT, R8G8B8A8_SNORM -> UNORM) through Compositor, resolving typeless/sRGB formats cleanly in compositor_srv_format, and copying subresource 0 via CopyTextureRegion for mipmapped/array textures cleanly fixes PresentX format and subresource handling.
  • cargo test -p victory-gpu --lib host::tests:: -- --test-threads=1 (RTX 5090): all passed (including compositor_srv_format_preserves_typed_formats_and_resolves_typeless).
  • cargo test -p victory-gpu --lib --features diagnostics host::present_plane_tests:: -- --test-threads=1 (RTX 5090): 4 passed, 0 failed (including present_composites_typeless_bgrx_overlay_without_device_removal, present_converts_unorm16_planes_without_nan_or_device_removal, present_single_plane_copies_subresource_zero_of_mipmapped_and_array_textures).
  • VICTORY_FORCE_WARP=1 cargo test -p victory-gpu --lib --features diagnostics host::present_plane_tests:: -- --test-threads=1 (WARP): 4 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 15:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/3257#pullrequestreview-6076557975) · **approved these changes** Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090 + WARP): - Routing format-mismatched planes (`R16G16B16A16_{UNORM,SNORM}` -> `FLOAT`, `R8G8B8A8_SNORM` -> `UNORM`) through `Compositor`, resolving typeless/sRGB formats cleanly in `compositor_srv_format`, and copying subresource 0 via `CopyTextureRegion` for mipmapped/array textures cleanly fixes PresentX format and subresource handling. - `cargo test -p victory-gpu --lib host::tests:: -- --test-threads=1` (RTX 5090): all passed (including `compositor_srv_format_preserves_typed_formats_and_resolves_typeless`). - `cargo test -p victory-gpu --lib --features diagnostics host::present_plane_tests:: -- --test-threads=1` (RTX 5090): 4 passed, 0 failed (including `present_composites_typeless_bgrx_overlay_without_device_removal`, `present_converts_unorm16_planes_without_nan_or_device_removal`, `present_single_plane_copies_subresource_zero_of_mipmapped_and_array_textures`). - `VICTORY_FORCE_WARP=1 cargo test -p victory-gpu --lib --features diagnostics host::present_plane_tests:: -- --test-threads=1` (WARP): 4 passed, 0 failed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
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/3257/head:github-bot/gh-3257'
git switch 'github-bot/gh-3257'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3257'
git switch 'github-bot/gh-3257'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3257'
git switch 'github-bot/gh-3257'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3257'
git switch 'main'
git merge --squash 'github-bot/gh-3257'
git switch 'main'
git merge --ff-only 'github-bot/gh-3257'
git switch 'main'
git merge 'github-bot/gh-3257'
git push origin 'main'
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!3257
No description provided.