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

Closed
github-bot wants to merge 2 commits from gh-pr/1183/head into gh-pr/1183/base
Owner

@⁠roanh47 on GitHub · 2026-11-24 19:44 UTC · original
pr/msaa-depth-srv → main · +1139 −10 · 6 files · 2 commits · closed without merging

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.

**@⁠roanh47** on GitHub · 2026-11-24 19:44 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1183) `pr/msaa-depth-srv` → `main` · +1139 −10 · 6 files · 2 commits · closed without merging Claim: [RT-MSAA-DEPTH-SRV](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) **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.
The MSAA SRV path refused every typeless colour texture with
"multisample shader view requires a matching typed colour format", although
D3D12 requires such a view to name a concrete member of the texture's typeless
family. Resolve the SRV format from that family and write the T# for it, and
refuse a format the GPU does not sample at the texture's sample count. A
typeless or UNKNOWN view format, one from another family, a non-sampleable
format and a depth texture stay null descriptors, each with its own log.

Adds d3d12_msaa_typeless_srv_test: a D3D12 clear and SampleMask draws into an
R8G8B8A8_TYPELESS 4x target, then all four samples of the 4x4 image are read
through its R8G8B8A8_UNORM T# by cs_sample.comp on the bindless set and
compared per sample.

Claim RT-MSAA-TYPELESS-SRV. AI-assisted (DeepSeek v4.1 Flash 1017).
The retail prototype's R32G8X24_TYPELESS (D32_SFLOAT_S8_UINT) depth target
could not take a multisample shader-resource view: the MSAA path accepted
colour textures only, so CreateShaderResourceView logged "multisample shader
view requires a colour texture: 19" and left a null descriptor.

A depth-stencil texture's multisampled SRV is its depth plane, so let it
through to the plane checks single-sampled views already use, and make the
sampleability query use the texture's own aspect (a depth attachment rather
than a colour attachment). The T# names the depth format (X24_8_32_FLOAT for
this family) through the depth aspect, and set 0 samples it through the float
multisample pair. The host advertises MULTISAMPLE_LOAD for the plane formats;
the layer now does where the depth image can be sampled at a multisampled
count.

Adds d3d12_msaa_depth_srv_test: a clear and a sample-masked draw, then all
four depth samples of each texel read through the R32_FLOAT_X8X24_TYPELESS
T#. Negative cases cover a single-sampled view of the MS texture, an MS view
of a single-sampled texture, another family's plane format, R32_FLOAT, a
colour format, UNKNOWN and a stencil-bearing plane format on a texture
without a stencil, and a sample count the GPU does not support.

image_msaa_load lowering for translated shaders is not in this change: no
shader in the translated corpus uses the instruction (docs/fssm_crosscheck.md)
and there is no measured disassembly of it, so it is a follow-up.

Depends on #1014 (the typeless colour fix); this branch is stacked on it.
AI-assisted (DeepSeek v4.1 Flash 1017).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:41:51 +00:00
github-bot closed this pull request 2026-11-26 09:41:51 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-24 19:45 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-24 19:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1183#pullrequestreview-6046181661) · **reviewed** 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.
Author
Owner

@⁠madhyn on GitHub · 2026-11-24 19:52 UTC · original

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

**@⁠madhyn** on GitHub · 2026-11-24 19:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1183#issuecomment-7142715585) 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
Author
Owner

@⁠Deedlyy on GitHub · 2026-11-24 20:09 UTC · original

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

**@⁠Deedlyy** on GitHub · 2026-11-24 20:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1183#issuecomment-7143118437) **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

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