Skip to content

Runtime: bind multisampled 2D and array shader-resource views (D3D-72) - #763

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
cemalyakla:d3d-72-msaa-srv
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
cemalyakla:d3d-72-msaa-srv

Conversation

@cemalyakla

@cemalyakla cemalyakla commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Implements D3D-72 on top of 067d3e8, including the merged single-sampled volume views from #672 and the copy-ordering fix from #782. Coordination claim

What changed

The Vulkan-backed device registers default and explicit TEXTURE2DMS and TEXTURE2DMSARRAY shader-resource views so a shader can read individual samples. A non-array view of an array reads layer zero. An array view can select a slice range or all remaining layers.

Floating-point, unsigned and signed bindings are enabled according to format support and descriptor limits. Devices that only fit the existing layout retain it. MULTISAMPLE_LOAD follows the available binding and format. This change supports matching typed color formats. Multisampled depth/stencil views, typeless reinterpretation and shader-translator lowering are separate work.

The multisample SRV path uses texture_storage_format for the underlying image format. A separate synthetic probe checked 11 format capability masks, rejected 4× A8 and XR-bias resource creation, and verified six invalid multisample view cases.

Verification on 50bf027

  • On Windows 11 with an NVIDIA RTX 4070 Ti SUPER, driver 610.88 and Vulkan validation enabled, all 448 multisample RGBA reads, 512 integer and fallback reads and 128 volume reads matched. The A8/R8 component mapping, A8 mip selection, BC1 and packed-format checks also passed. The volume fixture uses slots 8–9, the six minimum-LOD views use 10–15, and the eight multisample views follow at 16–23. All 384 minimum-LOD texels matched. In an earlier negative control, moving multisample back to 10–17 made the minimum-LOD test fail on its first texel. The A8/R8 views use their own heap.
  • All 14 standalone bindless draws passed with zero bad pixels. The shader-free build passed its descriptor checks. All six hand-written test shader variants passed spirv-val. Earlier negative controls detected deliberate sample-index, array-layer and fixture-slot errors. Native D3D12 WARP confirmed the view-range and component-mapping cases.
  • CMake builds passed on Windows and Linux. All 34 enabled Windows CTest cases passed with optional SDL3 GameInput disabled. All 11 Linux CTest cases passed. On llvmpipe, 65 of 101 native tests passed with 36 capability skips. Wave64 compute passed 43 of 47 with 4 skips. Both runs matched pristine 067d3e8.
  • The standalone Windows clear test reported three Vulkan/WARP differences, in RGBA8 UNORM, RGBA8 SNORM and D16. The same cases differed at the same bytes on pristine upstream. The volume clear matched all 648 texels.
  • Python compilation, CLI smoke, all 106 standard-library test scripts (9 individual cases skipped on Windows), 1,020 semantic unittests on each of Windows and Linux, 708 pytest cases plus 20 subtests, 29 viewer tests, the rpf9dump Release build and all three .NET diagnostic groups passed. Six of the nine skipped Windows cases passed on Linux. Three audio filename tests require filesystem behavior unavailable on these hosts. These checks use the same source on the branch and its base.

Independent runs on b3e2f38 covered the RX 7900 XTX and 8× multisampling on an RTX 5080 and AMD Radeon Graphics. At 8× both adapters matched all 448 reads. Deliberately indexing only four samples produced exactly 224 mismatches on each. RX 7900 XTX report · 8× validation and negative control

An independent RTX 4090 tester reported 32/32 CTest cases and a clean descriptor test on b10b56a. RTX 4090 report

Independent testers also reported passing descriptor readbacks on the earlier revision e05d48d or its identical tree. RTX 3060 · RTX 3070 · RTX 5070

AI-assisted with OpenAI Codex. All test inputs were synthetic. The tracked-file scan found no game data.

@evilclanker9000

Copy link
Copy Markdown
Contributor

@cemalyakla I tested #763 at 039c2301cc8902f7545c46684f1f15b0d5d32590 together with #672 at 94616fef20a9ba5a8f0915007dc07f2e54071ba7 in a detached worktree. git merge-tree --write-tree 94616fe 039c230 reports conflicts in the device, descriptor test, sample shader and D3D12/Vulkan doc.

One collision survives a textual resolution. Both fixtures use heap slots 8/9 for live descriptors. Keeping that numbering changed the MS T# in slot 8 to a volume T# before dispatch. A type assertion at that point failed. I kept your slots 8–15, moved the two volume views to 16/17 and sized the test heap to 18. I also kept out.depth and out.samples in the encoder, preserved both default/explicit dimension paths, and put the binding-6 volume sampler inside the ordinary (non-MS) shader variant.

With those local resolutions, the combined descriptor executable passed on RTX 5080 / 616.92 with Khronos validation enabled. All 128 volume samples and 448 multisample RGBA values matched, and both integer MS formats passed their 2D/array and fallback reads. No validation errors. Whichever PR lands second can reuse this slot split.

AI-assisted verification.

@evilclanker9000

Copy link
Copy Markdown
Contributor

I also checked descriptor lifetime on the exact PR head 039c230. On Windows 11 / RTX 5080 / driver 616.92 with validation enabled, I sampled an integer MS array, saved its T# bytes, released its final resource reference, then created a different array of the same type and wrote its view into the same D3D12 CPU descriptor slot. After an ordinary ExecuteCommandLists and fence, I used the PR's integer compute shader against set 0.

32-bit readback Still-live 2DMS Saved old array key, now released Replacement array Unknown array key
R32_UINT f1234567 00000000 f1885753 00000000
R32_SINT, shown as bits ffed2979 00000000 ff463b4d 00000000

All 512 words matched. Each column represents 64 repeated loads of the same texel/sample; the old and unknown keys used layer 0, texel (0,0), sample 0, which also exist on the fallback. The stock per-sample descriptor test passed separately.

For the negative control I kept one extra COM reference to the original array across the descriptor rewrite. The saved keys then returned their original values (f1234568 and ffed297a); exactly 64/256 words changed for each format. This distinguishes destruction from rewriting the CPU slot and checks that the old key cannot start sampling the replacement.

@cemalyakla

Copy link
Copy Markdown
Contributor Author

Thanks for the combined run and the independent descriptor-lifetime check. Commit f63f866 reserves slots 8–9 for the volume fixture in #672 and puts the multisample views in named slots 10–17. The test now checks its descriptors immediately before dispatch.

I integrated #672 at 94616fe locally, keeping both dimension paths, both encoded fields and the binding-6 volume sampler in the ordinary shader variant. On RTX 4070 Ti SUPER, driver 610.88, the combined fixture matched all 128 volume samples, 448 multisample color values and 512 integer words with Vulkan validation enabled. Restoring the slot collision made the new assertion fail. Standalone Windows CTest passed 30/30.

The branches still have four textual conflicts if merged together. Whichever lands second can retain #672’s original slots and this PR’s new range. Your saved-key and extra-reference controls also confirm the expected descriptor lifetime on the RTX 5080.

Could a maintainer approve the fork workflows for this PR and #706? GitHub shows action_required on both updated heads. This PR’s CI run · #706 CI run

@cemalyakla

Copy link
Copy Markdown
Contributor Author

Rebased onto 8df277f in d9587d4. The merged #672 volume views and the multisample views now run together directly on this branch. On RTX 4070 Ti SUPER, driver 610.88, with Vulkan validation enabled, the fixture matched all 128 volume samples, 448 multisample color values and 512 integer words. Restoring the old slot collision failed the pre-dispatch check.

Windows CTest passed 32/32 and Linux CTest passed 11/11. The llvmpipe suites matched pristine upstream, and the standalone bindless test passed all 14 draws. The separate RGBA8 clear comparison reproduced the same one-byte Vulkan/WARP difference on the base.

@cemalyakla

Copy link
Copy Markdown
Contributor Author

Rebased onto dedd75c in e05d48d as requested. Both commits replayed cleanly. With Vulkan validation enabled on RTX 4070 Ti SUPER, driver 610.88, the fixture matched 128 volume samples, 448 multisample color values and 512 integer words. The newly merged BC1 test also matched all 64 samples.

Windows CTest passed all 33 enabled cases, with optional SDL3 GameInput disabled. Linux CTest passed 11/11. Both llvmpipe GPU suites matched pristine upstream.

@quackottu quackottu 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.

Tested e05d48d on NVIDIA GeForce RTX 5070, driver 621.24, Windows 11 Pro (26300), VS 2022 Build Tools, Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1 and LEONIDA_D3D12=vulkan: pass

  • ctest -C RelWithDebInfo: 100% tests passed, 0 tests failed out of 32
  • d3d12_descriptor_test (changed here): exit=0 validation=0 | [rt] d3d12_xs: device slot 36 (forwarded) first call
  • 32 test programs in the build pass with 0 validation errors
  • d3d12_clear_test fails (format 28 case 0 byte 2: Vulkan 7f, WARP 80) exactly as on main 67204bf, so not from this PR: NVIDIA rounds a 0.5 UNORM clear to 0x7f, which #521 addresses

Implicit Vulkan layers (overlays) were off through an empty VK_IMPLICIT_LAYER_PATH.

@oVolkra

oVolkra commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested e05d48d on NVIDIA GeForce RTX 3060, driver 617.14, Windows 11: pass

Setup: Windows 11 Pro (10.0.26100), RTX 3060 (Ampere, subgroup 32), NVIDIA 617.14, MSVC 14.44.35207 + Windows SDK 10.0.26100, Ninja RelWithDebInfo, Khronos Vulkan-Headers, VK_LAYER_KHRONOS_validation 1.4.357. I built d9587d4 merged onto main dedd75c, a tree identical to the rebased e05d48d (git diff is empty), and compared it against main dedd75c.

d3d12_descriptor_test, run by hand, with and without LEONIDA_VK_VALIDATION=1: exit 0.

  • MSAA SRVs: 448 per-sample values matched through 2D, full-array and sliced-array views
  • MSAA format 42 and MSAA format 43: 2D and array integer reads and zero fallbacks matched
  • volume SRVs: 0 of 128 sampled RGBA texels differ (Runtime: bind 3D shader-resource views through set 0 (D3D-72) #672's views still pass next to the new slots)
  • The B4G4R4A4/B5G5R5A1 and fallback checks pass, as on main.

ctest: 32/32, also with LEONIDA_VK_VALIDATION=1 (the same as main dedd75c).

scripts/run_gpu_tests.py vs main, native and with LEONIDA_W64_EMULATE=1: the same result for every test. Native: 71/98 passed, 27 skipped (wave64 on a 32-wide GPU). Emulated: 98/98. ps_tex: bindless: 14 draws read back, 0 bad pixels. 100 shaders translated, all pass spirv-val.

The build has 0 errors and the PR adds no new warnings.

On the previous head d9587d4 (base 8df277f), d3d12_vulkan_device failed under validation with 10 WRITE_AFTER_WRITE copy hazards. That came from the old base (8df277f alone gives the same 10) and no longer shows up on the rebased head.

No game files; only the repository's own synthetic tests.

AI-assisted: the build and test runs were done with an AI coding assistant (Claude Code) on my machine; the numbers above are its unedited output.

@Parakeet-Wheat

Parakeet-Wheat commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Update: the rebased head e05d48d is the same tree, byte for byte, as d9587d4 merged onto dedd75c, which is the second run below. So the clean result (both tests exit 0, 0 hazards, 0 VUID messages) applies to the current head, and the rebase I mention is already done.

Tested d9587d4 on an NVIDIA GeForce RTX 3070, driver 610.88, Windows 11 (26300), MSVC 2022 (VS generator, RelWithDebInfo), Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1: pass

  • Full runtime build passes. ctest -C RelWithDebInfo: 25/25.
  • d3d12_descriptor_test: exit 0, no validation messages. MSAA SRVs: 448 per-sample values matched through 2D, full-array and sliced-array views. Formats 42 and 43: 2D and array integer reads and zero fallbacks matched. Volume, B4G4R4A4, B5G5R5A1 and descriptor-copy checks also pass.
  • d3d12_com_test and vk_command_replay_test (parts A to E): pass, no validation messages.

One thing to know, which doesn't come from this PR: on the PR head as-is, d3d12_vulkan_device_test exits 1 with validation on, reporting 10 synchronization-validation WRITE_AFTER_WRITE hazards between back-to-back vkCmdCopyImage calls in the copy comparison. This reproduces every run on this branch, and current main (dedd75c) is clean. The fix is #782 (5ec780c), which landed after this branch's base (8df277f). Merged onto dedd75c (no conflicts), both d3d12_vulkan_device_test and d3d12_descriptor_test exit 0 with 0 hazards and 0 VUID messages, and the MSAA results are unchanged. A rebase would pick the fix up, but it isn't needed for this PR's own changes.

Code read: the device changes look right to me. A multisample SRV now has to match the resource's sample count both ways, only takes typed colour formats, and is refused when no set-0 binding exists for its numeric class. MULTISAMPLE_LOAD is reported only when that binding exists. Refusing ALLOW_UNORDERED_ACCESS on multisample textures matches D3D12. The CMake change only compiles the six test shaders with glslangValidator.

AI-assisted (Claude Code).

@cemalyakla

Copy link
Copy Markdown
Contributor Author

Thanks for testing the previous revision on the RTX 3060, 3070 and 5070. I rebased onto 4a36bb1 as requested. The new head is b10b56a. It keeps the merged A8/R8 descriptor heap, the volume views and the multisample views together. The base includes the copy-ordering fix from #782.

On RTX 4070 Ti SUPER, driver 610.88, all 448 multisample color reads, 512 integer and fallback reads, and 128 volume reads matched with Vulkan validation enabled. The A8/R8 tests passed too. All 33 enabled Windows CTest cases and all 11 Linux cases passed. The standalone clear test reported the same three differences from WARP on the branch and pristine upstream.

@MrCheese5

Copy link
Copy Markdown
Contributor

Tested b10b56a on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass (no regression against main).

  • Clean RelWithDebInfo Ninja build of runtime/ (Vulkan SDK 1.4.363.0), then ctest: 32/32 pass.
  • GPU tests with LEONIDA_VK_VALIDATION=1 and the Khronos validation layer: d3d12_com_test, d3d12_descriptor_test, d3d12_gcl8_test, d3d12_method_variants_test, d3d12_resource_desc_test, d3d12_sampler2_test, d3d12_state_map_test, d3d12_typeless_rtv_test, d3d12_uav_clear_test, d3d12_vulkan_device_test, vk_command_replay_test pass, with 0 validation messages (no VUIDs).
  • d3d12_clear_test fails, the same as on plain main 4a36bb1 on this GPU (NVIDIA rounds the 0.5 clear on 8-bit UNORM/SNORM down: Vulkan 7f, WARP 80, plus one depth-format-55 case that main shows too). This is not caused by this PR; Runtime: clears match WARP on every format class: tie rounding, and the SNORM/SINT/R8/R16 formats (D3D-45) #521 fixes the rounding.

The vk_* harness tests that need translated SPIR-V weren't run. No game files used. AI-assisted run (Claude Code).

@cemalyakla

Copy link
Copy Markdown
Contributor Author

Rebased onto d1211d0 in b3e2f38. The new upstream minimum-LOD fixture uses six slots that the previous multisample fixture also used. The multisample descriptors now start after those six views. With the old slot numbering restored in a scratch build, the first minimum-LOD texel failed. The rebase also preserves the new subgroup feature query and XR-bias format handling.

On RTX 4070 Ti SUPER, driver 610.88, all 384 minimum-LOD texels, 128 volume reads, 448 multisample color reads and 512 integer and fallback reads matched with synchronization validation enabled. All 33 enabled Windows CTest cases and all 11 Linux cases passed. The standalone clear comparison reproduced the same three differences on pristine main.

Thanks for the RTX 4090 run on the previous head.

@bobcatchris

Copy link
Copy Markdown
Contributor

Tested b3e2f38 on an AMD RDNA3 desktop GPU. Pass, including the MSAA SRV paths this PR adds.

Setup: RX 7900 XTX (RDNA3, gfx1100), AMD driver 26.10.1 (LLPC), Vulkan 1.4.359, Windows 11 build 26200, Ryzen 7 7800X3D, MSVC 19.39, llvm-mc 21.1.8, CMake/Ninja. The device supports 2/4/8/16 MSAA and VK_EXT_custom_border_color; validation on throughout (LEONIDA_VK_VALIDATION=1).

  • Build: 172 targets, clean.
  • d3d12_descriptor_test: exit 0 — MSAA SRVs: 448 per-sample values matched through 2D, full-array and sliced-array views; MSAA format 42 and format 43 2D and array integer reads plus zero fallbacks matched; the B4G4R4A4 / B5G5R5A1 sampled cases matched; T#/S# bindless lookup, the fallback for an unknown descriptor and for a destroyed texture, and the UINT black/white and float white borders all matched.
  • LEONIDA_VK_VALIDATION=1 d3d12_vulkan_device_test: exit 0, 0 validation hazards. MSAA-relevant lines: MSAA64KB=1, Depth/stencil MSAA quality queries: 12 compared, 8 host-unsupported skipped, 0 mismatches, and the allocation info ... MSAA cases match.
  • LEONIDA_VK_VALIDATION=1 ctest: 32/32 pass, 0 failed (one test disabled).

One observation, not a failure: allocation info 1024x1024 4x MSAA small: alignment 65536, size ours 17039360 host 16842752 — ours is 192 KiB larger there. The test accepts it, so it may be intended padding, but it is the only size line in that block that differs, and worth a look if that case was meant to be byte-exact.

Environment caveat, not this PR: main still carries #854 (OPTIONS19.SupportedSampleCountsWithNoOutputs: ours 0xf not subset of host 0x1d); I applied #855's four-line mask to my working copy only, nothing committed or pushed. Without it the only failure is that unrelated line.

AI-assisted.

@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested b3e2f389c970593c0216993c7567f53b3ebc5c12 at 8× MSAA on Windows RTX 5080 and AMD Radeon Graphics with Vulkan validation enabled. Each target layer received eight draws' worth of distinct per-sample values via eight masked triangle instances. The source-built compute shader read sample indices 0–7 through the 2D, full-array and sliced-array set-0 views. I also put the shader's textureSamples result in the output alpha byte, expected 8.

Both adapters matched 448/448 RGBA results, with zero validation errors. Changing only the load index to i % 4 repeated samples 0–3 in place of 4–7, giving exactly 224/448 wrong results on each GPU. The sample count still read 8 in the negative control.

I also checked integration with #897. Its first test revision overwrote the first two multisample descriptor slots when the branches were combined. I moved the two new volume descriptors to a private CPU heap on my branch (482aa3c). With the two PRs combined locally, both GPUs now pass the 256 volume, 448 four-sample color and 512 integer/fallback checks together. Git merges the runtime and test sources automatically at those two heads; the shared known-gaps sentence in the documentation needs to retain both edits.

AI-assisted independent verification with synthetic shaders and textures.

@JavierBlanco23

Copy link
Copy Markdown
Contributor

Tested #763 at b3e2f38 on Windows 11, RTX 5080 (Blackwell), driver 616.56, Vulkan 1.4.x, MSVC 19.44.

d3d12_vulkan_device_test: All host comparisons match

  • FORMAT_INFO: 195 queries, 0 mismatches
  • CheckFeatureSupport options: 15 queries, 0 mismatches
  • Copy comparison: 0/69 cases differ (known BC mip differences documented)
  • MSAA quality: 12 compared, 8 skipped, 0 mismatches
  • Resolve: 60/60 matched, 10 skipped
  • WriteToSubresource/ReadFromSubresource: both paths matched
  • GetCopyableFootprints, GetResourceTiling: matched

ctest: 32/33 PASS with LEONIDA_VK_VALIDATION=1 (gameinput disabled)

Note: Exit code 1 from d3d12_vulkan_device_test with validation due to 1 pre-existing ReShade layer load error, not from this PR.

AI-assisted.

@cemalyakla

Copy link
Copy Markdown
Contributor Author

Thanks for the RX 7900 XTX report. For the 1024×1024, 4× MSAA texture, the test checks that the alignment matches native D3D12 and that the layer's size is a multiple of that alignment and covers the top mip. The layer rounds the Vulkan driver's image memory requirement up to the D3D12 placement alignment. Both of your reported sizes meet those conditions. The 192 KiB difference is within the test's contract. I reran the case on pristine d1211d0 and b3e2f38 on an RTX 4070 Ti SUPER, driver 610.88. Both runs reported 64 KiB alignment and 16 MiB on both APIs. Allocation comparison · Size calculation

Thanks also for the 8× check and the sample-index negative control on both GPUs. I tested b3e2f38 together with #897 at 482aa3c on the RTX 4070 Ti SUPER with synchronization validation enabled. The combined fixture passed all 256 volume, 448 four-sample color and 512 integer and fallback reads. The runtime and tests merge cleanly. The only textual conflict is the known-gaps paragraph. When the second PR lands, it should retain both updates. #897 covers UNORM and sRGB views of RGBA8 typeless volumes, and #763 covers typed multisampled color SRVs. 8× and integration report

@cemalyakla

Copy link
Copy Markdown
Contributor Author

Rebased onto 067d3e8 as requested. In 50bf027, the multisample SRV code uses texture_storage_format for the resource's underlying image format, matching the new upstream path. A separate synthetic probe verified 11 format capability masks, both A8 and XR-bias 4× quality queries, rejection of 4× resources for those formats, and six invalid 4× SRV cases.

With synchronization validation enabled on an RTX 4070 Ti SUPER, driver 610.88, the descriptor test matched all 448 multisample color reads, 512 integer and fallback reads, 128 volume reads and 384 minimum-LOD texels. The device test also passed its 1D-array, XR-bias and typeless-depth cases. All 34 enabled Windows CTest cases and all 11 Linux CTest cases passed. The standalone clear test reproduced the same three Vulkan/WARP differences as pristine upstream. Coordinator’s rebase request

@evilclanker9000

Copy link
Copy Markdown
Contributor

Retested the 8× per-sample indexing control on the rebased head 50bf02723db2200abfc4974528960e3a9546faf1. On both RTX 5080 (616.92) and Radeon Graphics (26.10.1), the compute read through 2D, full-array and sliced-array views returned all 448/448 expected RGBA values, including textureSamples == 8. Changing only the requested sample from i % 8 to i % 4 again changed exactly 224/448 values. Both drivers ran with Vulkan validation on.

The same positive runs passed the A8 mip-1 and default/remapped A8/R8 pixel comparisons. The rebased device tests passed on both GPUs with the host adapter matched; the XR-bias 16×16 allocation reported 65,536-byte size and alignment on the RTX. The 8× pixel result concerns the float MSAA views. AI-assisted, synthetic inputs only.

@ItsNotRexed
ItsNotRexed merged commit 7a406cc into ItsNotRexed:main Nov 22, 2026
11 checks passed
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.

9 participants