Runtime: serve a multisampled depth-stencil SRV's depth plane #1183

Closed
roanh47 wants to merge 2 commits from upstream-pr/1183 into main
roanh47 commented 2026-11-24 19:44:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by roanh47 on 2026-11-24T19:44:54Z.


Claim: RT-MSAA-DEPTH-SRV

Depends on #1014 (the typeless colour fix, "Runtime: sample a typeless colour texture's multisample SRV"). This
branch is stacked on that one, so the diff below #1014's commit includes it; review the top commit for this change.
No game data.

Log source

runtime/shims/d3d12_vulkan_device.cpp, the multisample SRV refusal in image_descriptor:

if (resource.aspects() != VK_IMAGE_ASPECT_COLOR_BIT) {
    log_once("multisample shader view requires a colour texture; format", int(desc.Format));

The retail prototype's 19 is DXGI_FORMAT_R32G8X24_TYPELESS, a D32_SFLOAT_S8_UINT depth-stencil image, so
every multisampled shader-resource view of it was refused and left a null descriptor.

Changes

  • runtime/shims/d3d12_vulkan_device.cpp
    • image_descriptor: a multisampled SRV of a depth-stencil texture is now its depth plane, so it goes through the
      same plane checks single-sampled views use (R32G8X24_TYPELESS takes R32_FLOAT_X8X24_TYPELESS, R24G8_TYPELESS
      R24_UNORM_X8_TYPELESS, D32_FLOAT R32_FLOAT, D16_UNORM R16_UNORM; UNKNOWN only on the typed ones). The
      colour path (#1014) is unchanged. D3D12's TEXTURE2DMS/TEXTURE2DMSARRAY SRVs have no plane field, so plane 1
      is not an SRV shape.
    • DeviceState::multisample_sampleable() takes the texture's aspects: a depth texture is queried as a depth
      attachment (sampled, copied) at the resource's sample count, a colour texture as a colour attachment.
    • CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT): the depth-plane formats advertise MULTISAMPLE_LOAD when the
      depth image can be sampled at a multisampled count and set 0 has the float pair — the host PC runtime advertises
      it for R32_FLOAT_X8X24_TYPELESS, X32_TYPELESS_G8X24_UINT, R24_UNORM_X8_TYPELESS and
      X24_TYPELESS_G8_UINT (measured with a native device: formats 21, 22, 46, 47) and for the typed formats (41,
      56), and does not for the depth formats themselves (20, 45).
    • CreateShaderResourceView's TEXTURE2DMS/TEXTURE2DMSARRAY paths are unchanged: they name plane 0.
  • runtime/test/glsl/cs_sample.comp: a TEST_MS_DEPTH variant that reads the four samples of a texture2DMS and
    writes their raw float bits.
  • runtime/test/d3d12_msaa_depth_srv_test.cpp, runtime/CMakeLists.txt: new GPU test, ctest d3d12_msaa_depth_srv.
  • runtime/test/d3d12_msaa_typeless_srv_test.cpp: #1014's "an MS view of a depth texture is null" negative becomes
    "a colour format on a depth texture is null", since the depth plane is now served (the depth test covers it).
  • docs/d3d12_vulkan.md: describes the depth-plane MSAA SRV and its MULTISAMPLE_LOAD bit, and removes
    "multisampled depth/stencil SRVs" from the descriptor-path gap list.

Tests

Synthetic only, no game data. d3d12_msaa_depth_srv_test creates a 4x4, 4x R32G8X24_TYPELESS depth target,
clears depth to 0.5 (stencil 0x5a), draws a red triangle with PSO SampleMask 0x1 (its sample 0 writes depth 0,
samples 1-3 keep the clear), creates the SRV with Format = R32_FLOAT_X8X24_TYPELESS and TEXTURE2DMS, and checks
the T# decodes to X24_8_32_FLOAT, a multisampled 2D image with four samples. A compute shader looks the T# up in
set 0's hash table and reads all four depth samples of each 4x4 texel, comparing the raw float bits (0.0 in sample 0
of covered texels, 0.5 from the clear elsewhere; the diagonal's partial pixels are either). It also asserts
MULTISAMPLE_LOAD for the plane format, as the host reports it.

Null descriptors asserted for: a TEXTURE2D view of the 4x texture (non-MSAA), a TEXTURE2DMS view of a
single-sampled depth texture, R24_UNORM_X8_TYPELESS (another family), R32_FLOAT, a colour format, UNKNOWN on
the typeless texture, and R32_FLOAT_X8X24_TYPELESS on a D32_FLOAT texture without a stencil. A 16x creation is
asserted E_INVALIDARG exactly when the GPU's quality-levels query says 16x does not exist.

With #1014's shim (before this commit) the test fails on the retail line:

[rt] d3d12: multisample shader view requires a colour texture; format 19
line 378: image_at(depth_view, image)
exit 1

With this change (MSVC 14.44 / Visual Studio 2022 Build Tools, Ninja, RelWithDebInfo, LEONIDA_VK_VALIDATION=1):

> .\d3d12_msaa_depth_srv_test.exe
device: NVIDIA GeForce RTX 3070 (validation on)
subgroup sizes: 32..32 (default 32), requirable in stages 0x3fff, subgroupSizeControl on, computeFullSubgroups on
MSAA depth SRV: R32G8X24_TYPELESS 4x target cleared and sample-masked drawn, 64 depth samples matched through its R32_FLOAT_X8X24_TYPELESS T#; single-sample, other-family, colour, UNKNOWN and stencil-less plane views and an unsupported sample count were refused
exit 0

The colour test from #1014 still passes:

MSAA typeless SRV: R8G8B8A8_TYPELESS 4x target cleared and drawn, 64 samples matched through its R8G8B8A8_UNORM T#; typeless, foreign-family, UNKNOWN, single-sample and colour-on-depth views stayed null

Related suites, same build and validation layer:

ctest -R "d3d12_(descriptor|msaa|typeless|view_slices|state_map|vulkan_device|clear_formats|resource_desc)"
 1/12 Test #174: d3d12_vulkan_device ..............   Passed   13.33 sec
 2/12 Test #206: d3d12_descriptor .................   Passed    0.58 sec
 3/12 Test #215: d3d12_typeless_rtv ...............   Passed    8.08 sec
 4/12 Test #217: d3d12_view_slices ................   Passed    1.36 sec
 5/12 Test #218: d3d12_typeless_families ..........   Passed    4.33 sec
 6/12 Test #222: d3d12_resource_desc ..............   Passed    0.68 sec
 7/12 Test #223: d3d12_typeless_depth .............   Passed    0.29 sec
 8/12 Test #255: d3d12_msaa_draw ..................   Passed    0.44 sec
 9/12 Test #256: d3d12_msaa_typeless_srv ..........   Passed    0.44 sec
10/12 Test #257: d3d12_msaa_depth_srv .............   Passed    0.43 sec
11/12 Test #269: d3d12_clear_formats ..............   Passed    0.99 sec
12/12 Test #284: d3d12_state_map ..................   Passed    0.02 sec

100% tests passed out of 12

The full ctest -R "^d3d12_" run has two failures on this machine that are not from this change:
d3d12_execute_indirect_validation (5 WARP-vs-NVIDIA argument-validation parity mismatches) and d3d12_clear
(Vulkan validation rejects depth clears outside [0, 1] and NaN without VK_EXT_depth_range_unrestricted). Both fail
identically with the shim reverted to #1014's commit.

python -I scripts/check_no_game_data.py runtime/shims/d3d12_vulkan_device.cpp runtime/CMakeLists.txt runtime/test/d3d12_msaa_typeless_srv_test.cpp runtime/test/d3d12_msaa_depth_srv_test.cpp runtime/test/glsl/cs_sample.comp docs/d3d12_vulkan.md exits 0.

Not in this PR: image_msaa_load lowering

The runtime half is here — the SRV is served, its T# is written and set 0 can sample it, so a translated shader
that lowers image_msaa_load will find it. Lowering the instruction itself is not included: docs/fssm_crosscheck.md
records that image_msaa_load is in no shader of the translated 26,503-shader corpus, and the repository has no
measured disassembly of its operands (its sample index comes from VADDR, and its DMASK/D16/TFE forms are unmeasured),
so writing a rule now would be guessing at a shape nothing can validate. It needs its own item: MS image types and
the 2DMS/2DMS-array bindings (20-25) in the generated module, an image_msaa_load rule with semantic fixtures, and
a GPU test once a translated shader can be built for one. Filed as a finding in the coordination issue.

GPU / driver

NVIDIA GeForce RTX 3070 (8 GiB), NVIDIA driver 610.88 on Windows, Vulkan 1.4.363 SDK.

AI-assisted: DeepSeek v4.1 Flash 1017.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5479138000 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1183). Originally posted by [roanh47](https://github.com/roanh47) on 2026-11-24T19:44:54Z. --- Claim: [RT-MSAA-DEPTH-SRV](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7139661742) **Depends on #1014** (the typeless colour fix, "Runtime: sample a typeless colour texture's multisample SRV"). This branch is stacked on that one, so the diff below #1014's commit includes it; review the top commit for this change. No game data. ## Log source `runtime/shims/d3d12_vulkan_device.cpp`, the multisample SRV refusal in `image_descriptor`: ```cpp if (resource.aspects() != VK_IMAGE_ASPECT_COLOR_BIT) { log_once("multisample shader view requires a colour texture; format", int(desc.Format)); ``` The retail prototype's `19` is `DXGI_FORMAT_R32G8X24_TYPELESS`, a `D32_SFLOAT_S8_UINT` depth-stencil image, so every multisampled shader-resource view of it was refused and left a null descriptor. ## Changes - `runtime/shims/d3d12_vulkan_device.cpp` - `image_descriptor`: a multisampled SRV of a depth-stencil texture is now its depth plane, so it goes through the same plane checks single-sampled views use (`R32G8X24_TYPELESS` takes `R32_FLOAT_X8X24_TYPELESS`, `R24G8_TYPELESS` `R24_UNORM_X8_TYPELESS`, `D32_FLOAT` `R32_FLOAT`, `D16_UNORM` `R16_UNORM`; `UNKNOWN` only on the typed ones). The colour path (#1014) is unchanged. D3D12's `TEXTURE2DMS`/`TEXTURE2DMSARRAY` SRVs have no plane field, so plane 1 is not an SRV shape. - `DeviceState::multisample_sampleable()` takes the texture's aspects: a depth texture is queried as a depth attachment (sampled, copied) at the resource's sample count, a colour texture as a colour attachment. - `CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT)`: the depth-plane formats advertise `MULTISAMPLE_LOAD` when the depth image can be sampled at a multisampled count and set 0 has the float pair — the host PC runtime advertises it for `R32_FLOAT_X8X24_TYPELESS`, `X32_TYPELESS_G8X24_UINT`, `R24_UNORM_X8_TYPELESS` and `X24_TYPELESS_G8_UINT` (measured with a native device: formats 21, 22, 46, 47) and for the typed formats (41, 56), and does not for the depth formats themselves (20, 45). - `CreateShaderResourceView`'s `TEXTURE2DMS`/`TEXTURE2DMSARRAY` paths are unchanged: they name plane 0. - `runtime/test/glsl/cs_sample.comp`: a `TEST_MS_DEPTH` variant that reads the four samples of a `texture2DMS` and writes their raw float bits. - `runtime/test/d3d12_msaa_depth_srv_test.cpp`, `runtime/CMakeLists.txt`: new GPU test, ctest `d3d12_msaa_depth_srv`. - `runtime/test/d3d12_msaa_typeless_srv_test.cpp`: #1014's "an MS view of a depth texture is null" negative becomes "a colour format on a depth texture is null", since the depth plane is now served (the depth test covers it). - `docs/d3d12_vulkan.md`: describes the depth-plane MSAA SRV and its `MULTISAMPLE_LOAD` bit, and removes "multisampled depth/stencil SRVs" from the descriptor-path gap list. ## Tests Synthetic only, no game data. `d3d12_msaa_depth_srv_test` creates a 4x4, 4x `R32G8X24_TYPELESS` depth target, clears depth to 0.5 (stencil 0x5a), draws a red triangle with PSO `SampleMask 0x1` (its sample 0 writes depth 0, samples 1-3 keep the clear), creates the SRV with `Format = R32_FLOAT_X8X24_TYPELESS` and `TEXTURE2DMS`, and checks the T# decodes to `X24_8_32_FLOAT`, a multisampled 2D image with four samples. A compute shader looks the T# up in set 0's hash table and reads all four depth samples of each 4x4 texel, comparing the raw float bits (0.0 in sample 0 of covered texels, 0.5 from the clear elsewhere; the diagonal's partial pixels are either). It also asserts `MULTISAMPLE_LOAD` for the plane format, as the host reports it. Null descriptors asserted for: a `TEXTURE2D` view of the 4x texture (non-MSAA), a `TEXTURE2DMS` view of a single-sampled depth texture, `R24_UNORM_X8_TYPELESS` (another family), `R32_FLOAT`, a colour format, `UNKNOWN` on the typeless texture, and `R32_FLOAT_X8X24_TYPELESS` on a `D32_FLOAT` texture without a stencil. A 16x creation is asserted `E_INVALIDARG` exactly when the GPU's quality-levels query says 16x does not exist. With #1014's shim (before this commit) the test fails on the retail line: ``` [rt] d3d12: multisample shader view requires a colour texture; format 19 line 378: image_at(depth_view, image) exit 1 ``` With this change (MSVC 14.44 / Visual Studio 2022 Build Tools, Ninja, `RelWithDebInfo`, `LEONIDA_VK_VALIDATION=1`): ``` > .\d3d12_msaa_depth_srv_test.exe device: NVIDIA GeForce RTX 3070 (validation on) subgroup sizes: 32..32 (default 32), requirable in stages 0x3fff, subgroupSizeControl on, computeFullSubgroups on MSAA depth SRV: R32G8X24_TYPELESS 4x target cleared and sample-masked drawn, 64 depth samples matched through its R32_FLOAT_X8X24_TYPELESS T#; single-sample, other-family, colour, UNKNOWN and stencil-less plane views and an unsupported sample count were refused exit 0 ``` The colour test from #1014 still passes: ``` MSAA typeless SRV: R8G8B8A8_TYPELESS 4x target cleared and drawn, 64 samples matched through its R8G8B8A8_UNORM T#; typeless, foreign-family, UNKNOWN, single-sample and colour-on-depth views stayed null ``` Related suites, same build and validation layer: ``` ctest -R "d3d12_(descriptor|msaa|typeless|view_slices|state_map|vulkan_device|clear_formats|resource_desc)" 1/12 Test #174: d3d12_vulkan_device .............. Passed 13.33 sec 2/12 Test #206: d3d12_descriptor ................. Passed 0.58 sec 3/12 Test #215: d3d12_typeless_rtv ............... Passed 8.08 sec 4/12 Test #217: d3d12_view_slices ................ Passed 1.36 sec 5/12 Test #218: d3d12_typeless_families .......... Passed 4.33 sec 6/12 Test #222: d3d12_resource_desc .............. Passed 0.68 sec 7/12 Test #223: d3d12_typeless_depth ............. Passed 0.29 sec 8/12 Test #255: d3d12_msaa_draw .................. Passed 0.44 sec 9/12 Test #256: d3d12_msaa_typeless_srv .......... Passed 0.44 sec 10/12 Test #257: d3d12_msaa_depth_srv ............. Passed 0.43 sec 11/12 Test #269: d3d12_clear_formats .............. Passed 0.99 sec 12/12 Test #284: d3d12_state_map .................. Passed 0.02 sec 100% tests passed out of 12 ``` The full `ctest -R "^d3d12_"` run has two failures on this machine that are not from this change: `d3d12_execute_indirect_validation` (5 WARP-vs-NVIDIA argument-validation parity mismatches) and `d3d12_clear` (Vulkan validation rejects depth clears outside [0, 1] and NaN without `VK_EXT_depth_range_unrestricted`). Both fail identically with the shim reverted to #1014's commit. `python -I scripts/check_no_game_data.py runtime/shims/d3d12_vulkan_device.cpp runtime/CMakeLists.txt runtime/test/d3d12_msaa_typeless_srv_test.cpp runtime/test/d3d12_msaa_depth_srv_test.cpp runtime/test/glsl/cs_sample.comp docs/d3d12_vulkan.md` exits 0. ## Not in this PR: `image_msaa_load` lowering The runtime half is here — the SRV is served, its T# is written and set 0 can sample it, so a translated shader that lowers `image_msaa_load` will find it. Lowering the instruction itself is not included: `docs/fssm_crosscheck.md` records that `image_msaa_load` is in no shader of the translated 26,503-shader corpus, and the repository has no measured disassembly of its operands (its sample index comes from VADDR, and its DMASK/D16/TFE forms are unmeasured), so writing a rule now would be guessing at a shape nothing can validate. It needs its own item: MS image types and the 2DMS/2DMS-array bindings (20-25) in the generated module, an `image_msaa_load` rule with semantic fixtures, and a GPU test once a translated shader can be built for one. Filed as a finding in the coordination issue. ## GPU / driver NVIDIA GeForce RTX 3070 (8 GiB), NVIDIA driver 610.88 on Windows, Vulkan 1.4.363 SDK. AI-assisted: DeepSeek v4.1 Flash 1017.
copilot-pull-request-reviewer[bot] commented 2026-11-24 19:45:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T19:45:03Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6046181661 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1183#pullrequestreview-6046181661). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-24T19:45:03Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
madhyn commented 2026-11-24 19:52:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by madhyn on 2026-11-24T19:52:43Z.


Tested 9fd32707c on Arch Linux + Wine 11.22 + NVIDIA RTX 3060 Ti (595.58.03 / clang-cl + xwin cross-build):

  • ctest --test-dir runtime/build/win -R "^d3d12_msaa_depth_srv$" --output-on-failure: Passed (5.47 s)

AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7142715585 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1183#issuecomment-7142715585). Originally posted by [madhyn](https://github.com/madhyn) on 2026-11-24T19:52:43Z. --- Tested `9fd32707c` on Arch Linux + Wine 11.22 + NVIDIA RTX 3060 Ti (595.58.03 / clang-cl + xwin cross-build): - `ctest --test-dir runtime/build/win -R "^d3d12_msaa_depth_srv$" --output-on-failure`: **Passed** (5.47 s) AI-assisted: yes
Deedlyy commented 2026-11-24 20:09:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Deedlyy on 2026-11-24T20:09:21Z.


Recommendation: [WAIT]

Reasoning: Multisampled depth-stencil SRVs now serve the depth plane instead of being refused, with two large new tests. It's stacked on #1014 (typeless colour MSAA SRV), so the diff includes #1014's commit and can't merge first. Verified on Wine + RTX 3060 Ti by madhyn. Merge after #1014 lands and this is rebased to its own commit. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main.

Impact level: 5/10

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7143118437 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1183#issuecomment-7143118437). Originally posted by [Deedlyy](https://github.com/Deedlyy) on 2026-11-24T20:09:21Z. --- **Recommendation:** [WAIT] **Reasoning:** Multisampled depth-stencil SRVs now serve the depth plane instead of being refused, with two large new tests. It's stacked on #1014 (typeless colour MSAA SRV), so the diff includes #1014's commit and can't merge first. Verified on Wine + RTX 3060 Ti by madhyn. Merge after #1014 lands and this is rebased to its own commit. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with `main`. **Impact level:** 5/10

Pull request closed

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
ProjectLeonida/mandy!1183
No description provided.