Skip to content

Runtime: MSAA PSOs take the standard sample pattern; draws check attachment sample counts - #831

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
TheHoracio:msaa-draws
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
TheHoracio:msaa-draws

Conversation

@TheHoracio

@TheHoracio TheHoracio commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in #634: #634 (comment)

Narrowed after rebase. Most of what this PR first did, multisampled PSOs and draws, landed on main in @Vonsek's 445f796. This branch is now one commit on main 003e7812 with the two pieces main still lacks.

What and why

  • PSO sample quality (d3d12_vulkan_device.cpp): CreateGraphicsPipelineState refused every SampleDesc.Quality except 0. Native D3D12 accepts the two pattern values too, measured with a standalone D3D12 program (no Leonida code), 1× and 4× RGBA8:

    Quality RX 7800 XT, Radeon iGPU, Basic Render Driver, WARP
    0 S_OK
    1 (past NumQualityLevels = 1) E_INVALIDARG
    D3D12_STANDARD_MULTISAMPLE_PATTERN S_OK
    D3D12_CENTER_MULTISAMPLE_PATTERN S_OK

    The standard pattern is Vulkan's standard sample positions, so it is now accepted. The resource side already accepted it, so a standard-pattern target can now be drawn with a matching PSO. The centre pattern needs custom sample locations, which is Runtime: SetSamplePositions and the centre sample pattern on VK_EXT_sample_locations #848's area, so for now it is refused with a log (E_NOTIMPL) rather than drawn with the wrong positions.

  • Attachment sample counts at replay (vulkan_replay.h): every bound render target and depth target must have the PSO's count. D3D12 leaves a mismatch undefined, and Vulkan's dynamic rendering forbids it. Such a draw now fails the list with invalid_subresource instead of reaching the driver.

Tested

AMD Radeon RX 7800 XT (RDNA3), driver 26.10.1 (32.0.32015.7029), Windows 11 Pro (26300), MSVC 14.44, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, Ninja RelWithDebInfo, LEONIDA_VK_VALIDATION=1:

  • d3d12_msaa_draw_test (now in ctest, SKIP_RETURN_CODE 77), 0 validation errors:
    • 4× colour and depth targets, a SampleMask 0x1 draw and ResolveSubresource. All 4,096 pixels match, and 64 edge pixels are partial.
    • Quality 1 and 3 samples are E_INVALIDARG; the standard pattern is accepted.
    • A 4× PSO drawing into a 1× target gives invalid_subresource.
  • Negative controls:
    • Without the sample-count check, validation reports the 1× attachment against rasterizationSamples 4×.
    • With main's quality rule, the standard-pattern PSO is refused.
  • Regression: ctest -j4 102/104. The two failures are d3d12_vulkan_device (line 3403) and d3d12_draw (VUID-vkDestroyPipeline-pipeline-00765); both fail the same way on clean main 003e7812 on this machine.

@Vonsek also tested alpha-to-coverage per-sample depth on the previous head (see above); that behaviour comes from main now.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. All fixtures are synthetic.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A: runtime only.)

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independent Windows readback at 3a47c38886b0c7a82ef996f63e13c01229b5fa4d. A sample mask with the correct population can still select the wrong samples. I tested bit identity at three vertical edges through the 4× RGBA8 UNORM draw and ResolveSubresource path.

I drew the same left-hand quad twice into a 64×64 target (sample quality 0), red 200 with mask M and green 160 with mask 0xf ^ M, over a blue 240 clear, alpha 255 throughout. The right edge was at x = 32.25, 32.5 or 32.75. M took each of 1,2,4,8,5,10 (decimal). The CPU reference used x offsets (6,14,2,10)/16 in sample-index order: each covered red sample contributes 50 to R, each covered green sample contributes 40 to G, and each uncovered sample contributes 60 to B.

All 18 images per path matched in every channel, covering 368,640 pixels over five paths: Leonida Vulkan on RTX 5080 and AMD Radeon Graphics, and native D3D12 on the same adapters and WARP. Both Vulkan runs had validation enabled and counted zero errors. At x = 32.5, swapping the equal-population masks 0x5 and 0xa changed exactly the 64 edge pixels from RGBA (100,0,120,255) to (0,80,120,255). All other 4,032 pixels stayed identical. The PR's stock MSAA draw test also passed on both Vulkan adapters.

Source-built fixtures only. AI-assisted verification.

@totonicpu totonicpu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick heads-up on the PR diff: this branch currently includes the full M0/M1/presenter diff (README.md, docs/d3d12_vulkan.md, vulkan_present.h, d3d12_compute_test, d3d12_draw_test, d3d12_present_test) on top of an older main, which makes the MSAA-specific changes hard to isolate and will conflict with recent main.

Rebasing onto current main (or setting the PR base branch to the dependency PR if it stacks on #291) will make the MSAA PSO/draw diff much cleaner to review.

@TheHoracio

Copy link
Copy Markdown
Contributor Author

@totonicpu, thanks. I can't set the base to #291's branch: it lives in @Ryx69's fork, and a PR here can only target a branch of this repository. Rebasing onto main alone isn't possible either, because the MSAA change needs #291's draw path, which isn't on main yet. Until #291 lands, each of my stacked PRs comes down to its own commits:

Once #291 is merged I'll rebase all four onto main, so only these commits remain. AI-assisted.

@TheHoracio

Copy link
Copy Markdown
Contributor Author

Rebased all four onto #291's new head 2aed144 (now on main 4a36bb1). The own commits are now: #819 961c754, #831 512c85d, #848 f1f9a4c (on top of #831), #873 c0c7b2d (squashed into one commit). The new base reports enabled core features in VulkanDeviceInfo::features, so #819 uses features.depthBounds instead of its own field. Retested on the RX 7800 XT with validation: every new test passes, and so do the draw/compute/present tests. ctest is 32/33; the one failure is d3d12_vulkan_device (OPTIONS19.SupportedSampleCountsWithNoOutputs), which #854 reports on main too. AI-assisted.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

At 512c85db100288df56399b7b44ce6bf50eeb373e, alpha-to-coverage also gave the expected per-sample depth writes when the fragment shader's color output was masked off.

My source-built test cleared a 4× D32 DSV to 1 and a 4× RGBA8 RTV to blue 240. Two full-screen indexed draws used z=0 and LESS. The first enabled depth writes, disabled all RTV color channels, and returned alpha 0 or 1 with the PSO sample mask shown below. The second disabled alpha-to-coverage, enabled all four samples and wrote green 160. It could color exactly those samples where the first draw had left depth at 1. I resolved the RTV and checked all 4,096 pixels.

First draw's sample mask Alpha-to-coverage on, alpha 0 On, alpha 1 Off, alpha 0 (negative control)
0x0 green 160 green 160 green 160
0x5 green 160 green 80 + blue 120 green 80 + blue 120
0xF green 160 blue 240 blue 240

Unlisted RGB channels were zero and resolved alpha was 255. The Vulkan layer on RTX 5080 and Radeon 1002:13c0 and native D3D12 on both adapters and WARP matched exactly in all nine cases. Zero Vulkan validation errors. Using alpha endpoints avoids assuming how a particular GPU distributes fractional alpha over its four samples. Windows 11 build 26200, NVIDIA 616.92 and AMD 26.10.1.

@TheHoracio TheHoracio changed the title Runtime: multisampled graphics PSOs and draws Runtime: MSAA PSOs take the standard sample pattern; draws check attachment sample counts Nov 22, 2026
…chment sample counts

CreateGraphicsPipelineState refused every SampleDesc.Quality but 0. Native
D3D12 (RX 7800 XT, a Radeon iGPU and WARP) accepts 0,
D3D12_STANDARD_MULTISAMPLE_PATTERN and D3D12_CENTER_MULTISAMPLE_PATTERN and
refuses 1 (past NumQualityLevels). The standard pattern is Vulkan's standard
positions, so it is accepted; the centre pattern needs custom sample
locations and is refused with a log until those exist.

At replay every bound render target and depth target must have the PSO's
sample count (D3D12 leaves a mismatch undefined, Vulkan's dynamic rendering
forbids it), so a mismatched draw fails the list with invalid_subresource
instead of reaching the driver.

d3d12_msaa_draw_test (in ctest): 4x draws with a depth target, SampleMask 0x1
and ResolveSubresource; the quality rules; a 4x PSO into a 1x target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

4 participants