[PR #878] [MERGED] d3d12: separate front and back stencil masks (D3D-STENCIL-FACE-MASKS) #916

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/878
Author: @kawaii-shakal
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @aslan2142

Base: main ← Head: d3d-stencil-face-masks


📝 Commits (1)

  • a7d86d8 d3d12: separate front and back stencil masks (D3D-STENCIL-FACE-MASKS)

📊 Changes

4 files changed (+142 additions, -20 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+10 -6)
📝 runtime/shims/d3d12_vulkan_device.cpp (+23 -10)
📝 runtime/test/d3d12_state_sweep_test.cpp (+105 -2)
📝 runtime/test/d3d12_vulkan_device_test.cpp (+4 -2)

📄 Description

Claimed in the coordination issue as: D3D-STENCIL-FACE-MASKS (claim)

What and why

On main, a D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL2 subobject whose FrontFace and BackFace masks differ is refused with E_NOTIMPL ("separate front and back stencil masks are not supported yet"). D3D12_FEATURE_D3D12_OPTIONS14 also reports IndependentFrontAndBackStencilRefMaskSupported = FALSE, although ID3D12GraphicsCommandList8::OMSetFrontAndBackStencilRef's per-face references already reach the draw (vkCmdSetStencilReference with a face mask). Vulkan has a compare mask and a write mask per face in VkStencilOpState, so no device feature is needed.

runtime/shims/d3d12_vulkan_device.cpp:

  • parse_pipeline_stream keeps the front face's masks in the D3D12_GRAPHICS_PIPELINE_STATE_DESC. The back face's go beside it in PipelineStream::back_stencil.
  • create_graphics takes them as an optional argument, used only for depth.back.
  • OPTIONS14.IndependentFrontAndBackStencilRefMaskSupported is TRUE.

The classic CreateGraphicsPipelineState path and its cached-PSO key are unchanged, since D3D12_DEPTH_STENCIL_DESC has one mask pair. The stream path takes no cached-PSO key.

Tests

d3d12_state_sweep_test compares against the host D3D12 device on the same adapter. It builds 16 more PSOs from a stream with DEPTH_STENCIL2, covering:

  • masks: the same on both faces, split, front-only and back-only;
  • one reference, or two through OMSetFrontAndBackStencilRef;
  • front- and back-facing triangles.

Each draw passes EQUAL with REPLACE and fails with INVERT, over stored 0xa5. The colour and stencil readbacks must be byte-identical with the host's. d3d12_vulkan_device_test now expects the cap to be TRUE. Its host comparison checks that the cap does not exceed the host's.

Tested

Windows 11 Pro 26300, MSVC 19.50.35721.0, Vulkan SDK 1.4.363.0, rebased on main 8f05e09e2.

  • d3d12_state_sweep: 498 cases compared with the host on the RTX 5070 Ti, 0 differ, 0 skipped. Same result with LEONIDA_VK_VALIDATION=1 (synchronization validation).
  • Mutation check: with the back face given the front face's masks, 6 of the 16 new cases differ, all back-facing.
  • ctest -R "d3d12_state_sweep|d3d12_vulkan_device$|gcl8|d3d12_com$|d3d12_depth24|d3d12_m3_frame|d3d12_draw": 6/6 passed, without and with validation.
  • Whole ctest -C RelWithDebInfo (before the rebase, on 5606eab23): 293 run, 292 passed. The only failure is d3d12_execute_indirect_validation, which fails on main too (#337 / #306).
  • d3d12_mesh with LEONIDA_VK_VALIDATION=1 on the rebased branch: passes with 0 validation errors (the VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076 errors seen on the older base were fixed on main by #540).
  • python -I scripts/check_no_game_data.py on the changed files: clean. tests/test_docs_*.py: all pass except test_docs_links, which flags docs/boot_leads.md → CONTRIBUTING.md. That file is not touched here; the failure comes from main.

GPUs tested: NVIDIA GeForce RTX 5070 Ti (Blackwell, PCI 10de:2c05), driver 617.42, Vulkan 1.4.351, Windows 11 Pro 26300

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code


🔄 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/878 **Author:** [@kawaii-shakal](https://github.com/kawaii-shakal) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `d3d-stencil-face-masks` --- ### 📝 Commits (1) - [`a7d86d8`](https://github.com/ubiquitarianism/leonida/commit/a7d86d8c769f944de0e1c406e41795ca1753707d) d3d12: separate front and back stencil masks (D3D-STENCIL-FACE-MASKS) ### 📊 Changes **4 files changed** (+142 additions, -20 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+10 -6) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+23 -10) 📝 `runtime/test/d3d12_state_sweep_test.cpp` (+105 -2) 📝 `runtime/test/d3d12_vulkan_device_test.cpp` (+4 -2) </details> ### 📄 Description Claimed in the coordination issue as: D3D-STENCIL-FACE-MASKS ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7131896009)) ### What and why On `main`, a `D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL2` subobject whose `FrontFace` and `BackFace` masks differ is refused with `E_NOTIMPL` ("separate front and back stencil masks are not supported yet"). `D3D12_FEATURE_D3D12_OPTIONS14` also reports `IndependentFrontAndBackStencilRefMaskSupported = FALSE`, although `ID3D12GraphicsCommandList8::OMSetFrontAndBackStencilRef`'s per-face references already reach the draw (`vkCmdSetStencilReference` with a face mask). Vulkan has a compare mask and a write mask per face in `VkStencilOpState`, so no device feature is needed. `runtime/shims/d3d12_vulkan_device.cpp`: - `parse_pipeline_stream` keeps the front face's masks in the `D3D12_GRAPHICS_PIPELINE_STATE_DESC`. The back face's go beside it in `PipelineStream::back_stencil`. - `create_graphics` takes them as an optional argument, used only for `depth.back`. - `OPTIONS14.IndependentFrontAndBackStencilRefMaskSupported` is TRUE. The classic `CreateGraphicsPipelineState` path and its cached-PSO key are unchanged, since `D3D12_DEPTH_STENCIL_DESC` has one mask pair. The stream path takes no cached-PSO key. ### Tests `d3d12_state_sweep_test` compares against the host D3D12 device on the same adapter. It builds 16 more PSOs from a stream with `DEPTH_STENCIL2`, covering: - masks: the same on both faces, split, front-only and back-only; - one reference, or two through `OMSetFrontAndBackStencilRef`; - front- and back-facing triangles. Each draw passes `EQUAL` with `REPLACE` and fails with `INVERT`, over stored `0xa5`. The colour and stencil readbacks must be byte-identical with the host's. `d3d12_vulkan_device_test` now expects the cap to be TRUE. Its host comparison checks that the cap does not exceed the host's. ### Tested Windows 11 Pro 26300, MSVC 19.50.35721.0, Vulkan SDK 1.4.363.0, rebased on `main` 8f05e09e2. - `d3d12_state_sweep`: 498 cases compared with the host on the RTX 5070 Ti, 0 differ, 0 skipped. Same result with `LEONIDA_VK_VALIDATION=1` (synchronization validation). - Mutation check: with the back face given the front face's masks, 6 of the 16 new cases differ, all back-facing. - `ctest -R "d3d12_state_sweep|d3d12_vulkan_device$|gcl8|d3d12_com$|d3d12_depth24|d3d12_m3_frame|d3d12_draw"`: 6/6 passed, without and with validation. - Whole `ctest -C RelWithDebInfo` (before the rebase, on 5606eab23): 293 run, 292 passed. The only failure is `d3d12_execute_indirect_validation`, which fails on `main` too (#337 / #306). - `d3d12_mesh` with `LEONIDA_VK_VALIDATION=1` on the rebased branch: passes with 0 validation errors (the `VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076` errors seen on the older base were fixed on `main` by #540). - `python -I scripts/check_no_game_data.py` on the changed files: clean. `tests/test_docs_*.py`: all pass except `test_docs_links`, which flags `docs/boot_leads.md` → `CONTRIBUTING.md`. That file is not touched here; the failure comes from `main`. GPUs tested: NVIDIA GeForce RTX 5070 Ti (Blackwell, PCI 10de:2c05), driver 617.42, Vulkan 1.4.351, Windows 11 Pro 26300 AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:19: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#916
No description provided.