[PR #1183] [CLOSED] Runtime: serve a multisampled depth-stencil SRV's depth plane #1215

Closed
opened 2026-11-26 20:20:29 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1183
Author: @roanh47
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: pr/msaa-depth-srv


📝 Commits (2)

  • abfe559 Runtime: sample a typeless colour texture's multisample SRV
  • 9fd3270 Runtime: serve a multisampled depth-stencil SRV's depth plane

📊 Changes

6 files changed (+1139 additions, -10 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+15 -2)
📝 runtime/CMakeLists.txt (+39 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+55 -7)
➕ runtime/test/d3d12_msaa_depth_srv_test.cpp (+512 -0)
➕ runtime/test/d3d12_msaa_typeless_srv_test.cpp (+504 -0)
📝 runtime/test/glsl/cs_sample.comp (+14 -1)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1183 **Author:** [@roanh47](https://github.com/roanh47) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/msaa-depth-srv` --- ### 📝 Commits (2) - [`abfe559`](https://github.com/ubiquitarianism/leonida/commit/abfe55934cf638e221d0fe0adef4dec9468ce817) Runtime: sample a typeless colour texture's multisample SRV - [`9fd3270`](https://github.com/ubiquitarianism/leonida/commit/9fd32707c49265d925f5d86f7600deba0fc35836) Runtime: serve a multisampled depth-stencil SRV's depth plane ### 📊 Changes **6 files changed** (+1139 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+15 -2) 📝 `runtime/CMakeLists.txt` (+39 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+55 -7) ➕ `runtime/test/d3d12_msaa_depth_srv_test.cpp` (+512 -0) ➕ `runtime/test/d3d12_msaa_typeless_srv_test.cpp` (+504 -0) 📝 `runtime/test/glsl/cs_sample.comp` (+14 -1) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:20:29 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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
starred/leonida#1215
No description provided.