Skip to content

d3d12: separate front and back stencil masks (D3D-STENCIL-FACE-MASKS) - #878

Merged
aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
kawaii-shakal:d3d-stencil-face-masks
Nov 24, 2026
Merged

aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
kawaii-shakal:d3d-stencil-face-masks

Conversation

@kawaii-shakal

@kawaii-shakal kawaii-shakal commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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 8f05e09.

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

A DEPTH_STENCIL2 subobject whose FrontFace and BackFace masks differ was
refused with E_NOTIMPL, and OPTIONS14 reported
IndependentFrontAndBackStencilRefMaskSupported = FALSE although the
per-face references of OMSetFrontAndBackStencilRef already reach the
draw. Vulkan has a compare and a write mask per face in VkStencilOpState.

parse_pipeline_stream keeps the front face's masks in the description and
the back face's beside it (PipelineStream::back_stencil), create_graphics
takes them as an optional argument for depth.back, and OPTIONS14 now
reports the cap. The classic CreateGraphicsPipelineState path and its
cached-PSO key are unchanged: D3D12_DEPTH_STENCIL_DESC has one mask pair.

d3d12_state_sweep_test builds 16 more PSOs from a stream with
DEPTH_STENCIL2 (same, split, front-only and back-only masks; one reference
or two through OMSetFrontAndBackStencilRef; front- and back-facing) and
compares the colour and stencil readback with the host D3D12 device: 498
cases, 0 differ on an RTX 5070 Ti. Giving the back face the front face's
masks makes 6 of them differ. d3d12_vulkan_device_test expects the cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Timon360SB

Copy link
Copy Markdown
Contributor

Independent testing results

Verified the expanded stencil state sweep on NVIDIA Blackwell hardware under native Windows, including the additional coverage introduced by this PR.

Tested revisions

  • BASE: 8f05e09e224656740e8a53f5047e1338d7a52588
  • HEAD: a7d86d8c769f944de0e1c406e41795ca1753707d

Test environment

Component Configuration
CPU AMD Ryzen 7 7800X3D
GPU NVIDIA GeForce RTX 5070 (Blackwell)
VRAM 12227 MiB
RAM 31.11 GiB
GPU driver 621.14
OS Windows 11 Pro, build 26200
Vulkan SDK 1.4.363.0
MSVC 19.44.35230
Windows SDK 10.0.26100.0

Test configuration

  • RelWithDebInfo, Ninja Multi-Config.
  • Selected CTest targets.
  • Vulkan core, GPU-assisted and synchronization validation enabled.
  • Three repetitions per revision.
  • Synthetic fixtures only.

Both revisions compiled successfully in the completed attempt.

CTest results

Test BASE HEAD
d3d12_state_sweep 3/3 3/3
d3d12_vulkan_device 3/3 3/3
d3d12_gcl8 3/3 3/3
d3d12_com 3/3 3/3
vk_sync_validation 3/3 3/3
Total 15/15 15/15

Combined: 30/30 PASS, with no failed or skipped CTest executions.

Stencil state sweep

The state sweep reported the following results in every repetition:

Property BASE HEAD
Cases compared with host 482 498
Differences 0 0
Skipped 0 0

BASE diagnostic:

482 cases compared with NVIDIA GeForce RTX 5070, 0 differ; 0 skipped

HEAD diagnostic:

498 cases compared with NVIDIA GeForce RTX 5070, 0 differ; 0 skipped

The 16 additional cases introduced by HEAD completed successfully in all three repetitions, corresponding to 48 additional case executions without reported differences.

Across the three state sweep invocations per revision:

Metric BASE HEAD Total
State sweep invocations 3 3 6
Case comparisons 1446 1494 2940
Reported differences 0 0 0
Skipped cases 0 0 0

Graphics command list 8

All d3d12_gcl8 executions reported:

GCL8: QueryInterface, OMSetFrontAndBackStencilRef(1, 2), refcount balanced

This confirms successful execution of the existing GCL8 interface and separate front/back stencil reference test.

Additional regression coverage

The COM test reported that all 16 colour, depth and stencil texels matched and that the queue wait held the GPU as expected.

The Vulkan device test reported unchanged results between BASE and HEAD:

Verification BASE HEAD
Copy cases compared 75 75
Copy differences 0 0
Resolve cases compared 60 60
Resolve mismatches 0 0
Unsupported or host-unavailable resolve cases skipped 10 10
Heap descriptions compared 20 20
Heap description differences 0 0

The placed-clear comparisons also remained unchanged: 16 plain bytes and zero sRGB-cast bytes differed from the host by one code, within the reported 0.6 ULP tolerance.

The internal resolve skips are distinct from CTest-level skips.

Vulkan validation

The synchronization validation self-test produced the expected intentional hazard without a barrier and zero validation errors with a barrier.

Test execution note

The initial attempt was interrupted before testing by a Git connection failure to github.com:443 (exit code 128).

The subsequent attempt completed successfully. The initial connection failure is excluded from the functional test totals.

Limitations

  • Tested on one NVIDIA Blackwell GPU.
  • Only the selected CTest targets and synthetic fixtures were exercised.
  • No independent feature-query verification beyond the recorded test coverage was performed.
  • No real-title execution or performance benchmark was performed.

Conclusion

Result: PASS — no regressions detected within the tested scope.

The expanded state sweep successfully exercised all 498 cases with zero differences against the host and zero skipped cases across all HEAD repetitions.

The additional front/back stencil coverage passed consistently, while the existing GCL8, COM, Vulkan device and synchronization tests remained successful.

AI-assisted log analysis and report preparation.

@aslan2142
aslan2142 merged commit 39bd93a into ProjectLeonida:main Nov 24, 2026
1 check passed
@aslan2142

Copy link
Copy Markdown
Collaborator

Merged. This was compared with #799 for D3D-STENCIL-FACE-MASKS, and it is the better fix:

  • The device code is equivalent, but only this PR also sets OPTIONS14.IndependentFrontAndBackStencilRefMaskSupported to TRUE.
  • Its 16 host-compared sweep cases check the per-face masks and references, and they fail when the back face gets the front face's masks.
  • Evidence: Timon360SB's native Windows run on an RTX 5070 at a7d86d8c7: 30/30 CTest executions, 498 cases compared with the host, 0 differ. Locally the compile check and the docs tests are clean; the tests themselves are Windows-only.
  • The claim is valid and first.

One caveat worth a follow-up: the device test fails on a host whose driver reports the capability as FALSE.

AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants