xg_x: lay out stencil-only views 22/47/120 as full depth-stencil planar surfaces #124

Closed
github-bot wants to merge 1 commit from gh-pr/124/head into gh-pr/124/base
Owner

@⁠adriaespii on GitHub · 2026-11-22 13:26 UTC · original
adriaespii:contrib/xg-x-stencil-views → main · +57 −10 · 2 files · 1 commits · closed without merging

Summary

This PR enables texture layout computation for stencil-only view formats (\DXGI_FORMAT_X32_TYPELESS_G8X24_UINT\ 22, \DXGI_FORMAT_X24_TYPELESS_G8_UINT\ 47, and \DXGI_FORMAT_X16_TYPELESS_G8_UINT\ 120) with the depth-stencil flag, resolving the blocker identified in \docs/BLOCKERS.md:243.

Context & Problem

In \docs/BLOCKERS.md:243:

The console also accepts the stencil-only views 22/47/120 with the depth flag, laying them out as full depth+stencil. Ours still returns E_INVALIDARG for those (open). Both planes are byte-identical to the console's for 2x/4x/8x, arrays 1/6, and hardware versions 0 and 2 (\depth_bind_planar_msaa_planes_match_console).

In \crates/compat/xg_x/src/layout.rs:

  • \is_depth_stencil_planar\ checked
    [4] == 1 && r[5] != 0 && r[6] != 0.
  • In \ROWS, formats 22, 47, and 120 have
    [5] == 0\ (they declare no depth component in the row table, only stencil in
    [6]).
  • Consequently, \XGCreateTextureComputerWithPitch\ skipped \compute_depth_msaa\ and returned \E_INVALIDARG.

Key Changes

  1. Parent Depth Format Mapping (\crates/compat/xg_x/src/layout.rs):
    • Added \depth_parent_format(dxgi: u32) -> u32:
      • 22 (\X32_TYPELESS_G8X24_UINT) -> 20 (\D32_FLOAT_S8X24_UINT)
      • 47 (\X24_TYPELESS_G8_UINT) -> 45 (\D24_UNORM_S8_UINT)
      • 120 (\X16_TYPELESS_G8_UINT) -> 118
    • Updated \is_depth_stencil_planar\ to evaluate the parent depth-stencil format.
  2. Layout Computation (\compute_depth_msaa):
    • Computes the full 2-plane planar layout (depth + stencil) using the parent format attributes while preserving the caller-requested DXGI format in \Layout.dxgi.
  3. Unit Tests:
    • Added offline unit test \compute_depth_msaa_stencil_views_match_parent_layouts\ in \layout_oracle_tests.rs\ testing formats 22, 47, 120 across 2x, 4x, and 8x MSAA.
    • Updated \depth_bind_planar_msaa_planes_match_console\ to verify that formats 22, 47, and 120 succeed and match console planes, offsets, and alignments.

Verification

  • \cargo check -p xg_x: Clean (0 errors).
  • \cargo test -p xg_x --lib compute_depth_msaa: 2 passed, 0 failed.
  • \cargo test -p xg_x --lib -- --skip oracle --skip console --skip built_dll: 11 passed, 0 failed.
**@⁠adriaespii** on GitHub · 2026-11-22 13:26 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/124) `adriaespii:contrib/xg-x-stencil-views` → `main` · +57 −10 · 2 files · 1 commits · closed without merging ### Summary This PR enables texture layout computation for stencil-only view formats (\DXGI_FORMAT_X32_TYPELESS_G8X24_UINT\ 22, \DXGI_FORMAT_X24_TYPELESS_G8_UINT\ 47, and \DXGI_FORMAT_X16_TYPELESS_G8_UINT\ 120) with the depth-stencil flag, resolving the blocker identified in \docs/BLOCKERS.md:243\. ### Context & Problem In \docs/BLOCKERS.md:243\: > The console also accepts the stencil-only views 22/47/120 with the depth flag, laying them out as full depth+stencil. Ours still returns E_INVALIDARG for those (open). Both planes are byte-identical to the console's for 2x/4x/8x, arrays 1/6, and hardware versions 0 and 2 (\depth_bind_planar_msaa_planes_match_console\). In \crates/compat/xg_x/src/layout.rs\: - \is_depth_stencil_planar\ checked \ [4] == 1 && r[5] != 0 && r[6] != 0\. - In \ROWS\, formats 22, 47, and 120 have \ [5] == 0\ (they declare no depth component in the row table, only stencil in \ [6]\). - Consequently, \XGCreateTextureComputerWithPitch\ skipped \compute_depth_msaa\ and returned \E_INVALIDARG\. ### Key Changes 1. **Parent Depth Format Mapping (\crates/compat/xg_x/src/layout.rs\)**: - Added \depth_parent_format(dxgi: u32) -> u32\: - 22 (\X32_TYPELESS_G8X24_UINT\) -> 20 (\D32_FLOAT_S8X24_UINT\) - 47 (\X24_TYPELESS_G8_UINT\) -> 45 (\D24_UNORM_S8_UINT\) - 120 (\X16_TYPELESS_G8_UINT\) -> 118 - Updated \is_depth_stencil_planar\ to evaluate the parent depth-stencil format. 2. **Layout Computation (\compute_depth_msaa\)**: - Computes the full 2-plane planar layout (depth + stencil) using the parent format attributes while preserving the caller-requested DXGI format in \Layout.dxgi\. 3. **Unit Tests**: - Added offline unit test \compute_depth_msaa_stencil_views_match_parent_layouts\ in \layout_oracle_tests.rs\ testing formats 22, 47, 120 across 2x, 4x, and 8x MSAA. - Updated \depth_bind_planar_msaa_planes_match_console\ to verify that formats 22, 47, and 120 succeed and match console planes, offsets, and alignments. ### Verification - \cargo check -p xg_x\: Clean (0 errors). - \cargo test -p xg_x --lib compute_depth_msaa\: 2 passed, 0 failed. - \cargo test -p xg_x --lib -- --skip oracle --skip console --skip built_dll\: 11 passed, 0 failed.
On the console runtime, texture descriptors with the depth-stencil flag and stencil-only view formats (22 DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, 47 DXGI_FORMAT_X24_TYPELESS_G8_UINT, 120 DXGI_FORMAT_X16_TYPELESS_G8_UINT) are accepted and laid out as full depth+stencil planar surfaces matching their parent formats (20, 45, 118).

Previously, is_depth_stencil_planar checked ROWS for a non-zero depth plane, which stencil-only views do not have in their row definition (r[5] == 0), causing XGCreateTextureComputer to return E_INVALIDARG (docs/BLOCKERS.md:243).

1. layout.rs:
   - Added depth_parent_format mapping 22 -> 20, 47 -> 45, 120 -> 118.
   - Updated is_depth_stencil_planar and compute_depth_msaa to compute the full planar depth+stencil layout from the parent format while preserving the requested dxgi format.
2. layout_oracle_tests.rs:
   - Added offline unit test compute_depth_msaa_stencil_views_match_parent_layouts.
   - Updated depth_bind_planar_msaa_planes_match_console so formats 22/47/120 are verified against console oracle instead of skipped as rejections.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:10:51 +00:00
github-bot closed this pull request 2026-11-26 06:10:51 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:35 UTC · original

Thanks! Gate is clean. A maintainer is checking this against the xg_x console oracle together with #123; we'll follow up here.

**@⁠omonkeyz** on GitHub · 2026-11-22 13:35 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/124#issuecomment-7079919271) Thanks! Gate is clean. A maintainer is checking this against the xg_x console oracle together with #123; we'll follow up here.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 14:28 UTC · original

Checked against the xg_x console oracle (stencil-only views 22/47/120 now byte-identical at 2x/4x/8x, arrays 1/6, hw v0/v2) and applied in 853169c (merged in c8a8a8f) with your authorship kept, thanks! Please rebase #123 onto this.

**@⁠omonkeyz** on GitHub · 2026-11-22 14:28 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/124#issuecomment-7080567107) Checked against the xg_x console oracle (stencil-only views 22/47/120 now byte-identical at 2x/4x/8x, arrays 1/6, hw v0/v2) and applied in 853169c (merged in c8a8a8f) with your authorship kept, thanks! Please rebase #123 onto this.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.