Skip to content

D3D-86: answer CheckFeatureSupport OPTIONS2-5, 7, 9, 11, 13-16, 18-21 - #775

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
JavierBlanco23:d3d-86-options
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
JavierBlanco23:d3d-86-options

Conversation

@JavierBlanco23

Copy link
Copy Markdown
Contributor

Item: D3D-86 (CheckFeatureSupport for D3D12_FEATURE_D3D12_OPTIONS2-5, 7, 9, 11, 13-16, 18-21).

Leaves sibling PRs untouched: OPTIONS1 (#745), OPTIONS6/10 (#469), OPTIONS8 (#715), OPTIONS12 (#693), FORMAT_INFO (#706), and SHADER_MODEL/ROOT_SIGNATURE (#704).

Summary

  • runtime/shims/d3d12_vulkan_device.cpp:
    • Caches VkPhysicalDeviceLimits::framebufferNoAttachmentsSampleCounts (masked to D3D12's legal sample counts 1..32) once in Device::Device.
    • Answers D3D12_FEATURE_D3D12_OPTIONS2-5, 7, 9, 11, 13-16, and 18-21 in Device::CheckFeatureSupport with exact struct-size validation (E_INVALIDARG on mismatch or null) and conservative values matching what the layer actually implements (per docs/d3d12_vulkan.md section 4.1):
      • OPTIONS4.MSAA64KBAlignedTextureSupported = TRUE (handled in GetResourceAllocationInfo).
      • OPTIONS19.SupportedSampleCountsWithNoOutputs from framebufferNoAttachmentsSampleCounts, AnisoFilterWithPointMipSupported tied to VulkanDeviceInfo::sampler_anisotropy, and baseline shader-visible heap limits (D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE = 2048, D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_2 = 1000000).
      • OPTIONS21.ExecuteIndirectTier = D3D12_EXECUTE_INDIRECT_TIER_1_0 (baseline enum value; no NOT_SUPPORTED enumerator exists).
      • All unimplemented capabilities/tiers (DepthBounds, CastingFullyTypedFormat, MSAA UAVs, independent stencil masks, render passes, ray tracing, mesh shaders, sampler feedback, wave MMA, work graphs, GPU upload heaps, etc.) stay FALSE / NOT_SUPPORTED / TIER_0.
  • runtime/test/d3d12_vulkan_device_test.cpp:
    • Adds create_host_device_for_physical (matching the Vulkan VkPhysicalDevice via VkPhysicalDeviceIDProperties LUID / PCI IDs using dynamically loaded dxgi.dll, falling back to the default adapter).
    • Adds compare_feature_options: validates nullptr, wrong struct sizes (0, sizeof - 1, sizeof + 1), and unknown feature enum refusal (E_INVALIDARG), checks local invariants and the sampler_anisotropy toggle on OPTIONS19.AnisoFilterWithPointMipSupported, and compares all 15 queries conservatively against the host Windows D3D12 runtime on the same adapter (skipping individual queries if an older host d3d12.dll does not know them).
  • docs/d3d12_vulkan.md:
    • Updates sections 3.2 and 4.1 with the implemented OPTIONS queries and observed RTX 5080 measurements.

Verification

Tested on Windows 11, NVIDIA GeForce RTX 5080 (driver 616.56), MSVC 19.44, Windows SDK 10.0.26100.0, Ninja:

  • python -m compileall -q make_game.py tools tests ? pass.
  • powershell -ExecutionPolicy Bypass -File .\scripts\build_runtime.ps1 ? builds cleanly with 0 warnings.
  • ctest --test-dir runtime/build --output-on-failure ? 28/28 passed.
  • d3d12_vulkan_device_test.exe under LEONIDA_VK_VALIDATION=1 (with VK_LOADER_LAYERS_DISABLE=~implicit~ to suppress an unrelated broken ReShade implicit layer):
    • CheckFeatureSupport options (NVIDIA GeForce RTX 5080): 15 feature queries compared (0 host-unsupported skipped), MSAA64KB=1, NoOutputsSamples=0x1f, MaxViewHeap=1000000, 0 mismatches
    • 0 validation errors, exit 0.
  • Negative control: on main (762893f), all 15 feature queries return E_INVALIDARG from CheckFeatureSupport.

No game files used. AI-assisted.

@JavierBlanco23
JavierBlanco23 force-pushed the d3d-86-options branch 2 times, most recently from d5e0041 to 7463359 Compare November 22, 2026 03:10
ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
# Conflicts:
#	docs/d3d12_vulkan.md

@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 7463359 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: 97% tests passed, 1 tests failed out of 31
  • d3d12_vulkan_device_test (changed here): exit=1 validation=0 | 10 validation errors
  • 30 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
  • d3d12_vulkan_device_test reports 10 synchronization-validation WRITE_AFTER_WRITE hazards on back-to-back copies (so ctest's d3d12_vulkan_device fails). main 8df277f shows the same 10 here, so not from this PR: it's @guimsolutions's finding in #634, which #782 addresses

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

@bobcatchris

Copy link
Copy Markdown
Contributor

Merge hazard with #855, confirmed from the branch itself. A verification run, no code from me.

7463359 still carries the old mask in runtime/shims/d3d12_vulkan_device.cpp:1100-1102:

constexpr VkSampleCountFlags kD3D12SampleCounts =
    VK_SAMPLE_COUNT_1_BIT | VK_SAMPLE_COUNT_2_BIT | VK_SAMPLE_COUNT_4_BIT |
    VK_SAMPLE_COUNT_8_BIT | VK_SAMPLE_COUNT_16_BIT | VK_SAMPLE_COUNT_32_BIT;
state_.no_output_sample_counts =
    static_cast<UINT>(props.limits.framebufferNoAttachmentsSampleCounts & kD3D12SampleCounts);

On an RX 7900 XTX that reports 0xf (Vulkan's no-attachment counts here are 1/2/4/8) against a host 0x1d, which is the red d3d12_vulkan_device_test filed as #854. #855 (462fc35) changes exactly these lines to mask 1|4|8|16; I verified that branch on this card (NoOutputsSamples=0xd, 0 mismatches, ctest 32/32 with and without validation).

So whichever of #775 and #855 lands second needs that mask, or the test goes red again on AMD. A full AMD result for this branch follows in a separate comment.

@bobcatchris

Copy link
Copy Markdown
Contributor

Full AMD result for this branch, as promised — same hardware/setup as the #854 report.

GPU AMD Radeon RX 7900 XTX (RDNA3, gfx1100), AMD proprietary 26.10.1 (LLPC), Vulkan 1.4.359
OS Windows 11 x64 build 26200, MSVC 19.39, Windows SDK 10.0.26100, Vulkan SDK 1.4.341.1, LLVM 21.1.8
Head 7463359, built as-is (156 targets, no errors)

1. As-is: one red test, the OPTIONS19 mask

LEONIDA_VK_VALIDATION=1 ctest: 30/31 passed. The failure is d3d12_vulkan_device, at

OPTIONS19.SupportedSampleCountsWithNoOutputs: ours 0xf not subset of host 0x1d
line 1671: options_mismatches == 0

i.e. the old mask at d3d12_vulkan_device.cpp:1100-1102, not anything this PR adds. On this card framebufferNoAttachmentsSampleCounts is 1/2/4/8, and 2× is not a D3D12 no-output count.

2. With #855's mask applied locally: OPTIONS19 green, but 10 validation errors remain

I applied 462fc35's three-line change on top of your branch locally (not pushed, no commit) and rebuilt. Then:

  • OPTIONS19 matches: NoOutputsSamples=0xd, 15 feature queries compared, 0 mismatches — so all of your new OPTIONS2-5/7/9/11/13-16/18-21 answers agree with the AMD host on this card.
  • Depth/stencil MSAA quality queries: 12 compared, 8 host-unsupported skipped, 0 mismatches
  • Resolve comparison: 60 compared, 60 matched, 10 unsupported or host-unavailable cases skipped, 0 mismatches
  • but 10 validation errors, exit 1 → ctest still 30/31.

All ten are synchronization-validation hazards, not VUID errors:

validation: vkCmdCopyImage(): WRITE_AFTER_WRITE hazard detected. vkCmdCopyImage writes to VkImage 0x1c0..., which was previously written by another vkCmdCopyImage command.
validation: vkCmdCopyBufferToImage(): WRITE_AFTER_WRITE hazard detected. vkCmdCopyBufferToImage writes to VkImage 0x1c2..., which was previously written by another vkCmdCopyBufferToImage command.

(3 images, repeatedly: 0x1be, 0x1c0, 0x1c2.)

3. It is this branch, not the environment

Same shell, same environment, main + #855's mask (L855 build): 0 hazards, exit 0, ctest 32/32 with validation. And on your branch it reproduces with your exact layer setup, VK_LOADER_LAYERS_DISABLE=~implicit~ (still 10, still exit 1), so an implicit layer is not producing them — vk_test_device.h:137 enables SYNCHRONIZATION_VALIDATION_EXT itself.

Your RTX 5080 result says 0 validation errors, so something in this branch takes a different path here than on NVIDIA. Two candidates, both guesses: the repeated vkCmdCopyImage/vkCmdCopyBufferToImage are the format/resolve comparisons reusing a few images without a barrier between submissions, and on AMD D24 is backed by D32_SFLOAT_S8_UINT (#737's area), which selects the other depth path.

Worth a look before this lands, since main is clean here and the branch is not. Happy to rerun the moment you push — it is one build and 10 seconds of tests.

AI-assisted.

@bobcatchris

Copy link
Copy Markdown
Contributor

Root cause of the ten WRITE_AFTER_WRITE hazards, with the trigger in this branch and the fix in the layer. Same hardware and setup as my other comments (RX 7900 XTX, AMD 26.10.1, Windows 11 26200).

What fires

All ten are the same shape, in the copy phase, on three images:

validation: vkCmdCopyImage(): WRITE_AFTER_WRITE hazard detected. ... previously written by another vkCmdCopyImage command.
  extent = {width = 4, height = 5, depth = 1}
  subresource = {aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, mipLevel = 2, baseArrayLayer = 1, layerCount = 1}

Nine are vkCmdCopyImage and one is vkCmdCopyBufferToImage (the upload). One destination subresource is written twice in a single submission with nothing between the writes.

Why this branch and not main

Same shell, main + #855's mask: 68 copy case lines, 0 hazards. This branch: 69, and the extra one is copy case BC7_UNORM_SRGB — the table entry at runtime/test/d3d12_vulkan_device_test.cpp:391 (texture_desc(4, 4, DXGI_FORMAT_BC7_UNORM_SRGB, …, 1, 3), gated by block_compressed() at :324). That case copies into the same 3-layer texture more than once, which is legal D3D12 (copies are ordered on a queue) but needs an explicit Vulkan dependency.

The layer gap

detail::copy_layout (runtime/src/vulkan_replay.h:1077) is the only transition the copy path performs, and it returns without a barrier when the range is already in the destination layout:

if (pieces.size() == 1 && (pieces[0].layout == target || pieces[0].layout == VK_IMAGE_LAYOUT_GENERAL))
    return pieces[0].layout;        // vulkan_replay.h:1083-1084

The copy then runs at :1565 (vk.copy_image) or :1571 (vk.copy_buffer_to_image) with no dependency on the earlier write to that subresource. The first copy into a fresh image gets one from the layout transition just above (:1086-1090); every later copy to the same subresource gets nothing.

So this is pre-existing on main, not something your PR introduces — the BC case is simply the first test that does two copies into one subresource. The file already handles exactly this situation one function later: round_trip (:1103) emits memory_barrier(...) when a piece is already in the target layout. copy_layout lacks the equivalent.

Suggested fix

Minimal, mirroring round_trip:

// runtime/src/vulkan_replay.h:1083, in copy_layout
if (pieces.size() == 1 && (pieces[0].layout == target || pieces[0].layout == VK_IMAGE_LAYOUT_GENERAL)) {
    if (access & VK_ACCESS_TRANSFER_WRITE_BIT)   // a second write to the same range needs a dependency
        memory_barrier(vk, command_buffer, VK_ACCESS_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
                       access, VK_PIPELINE_STAGE_TRANSFER_BIT);
    return pieces[0].layout;
}

Cheaper variant if a barrier before every copy is too much: record the last writer per range in LayoutTracker (:481, which already knows every subresource range) and only emit when that range is written again.

Regression test: two CopyTextureRegion into one subresource in a single command list, run under LEONIDA_VK_VALIDATION=1, expect 0 validation errors — the BC case already has that shape.

I can run a patch through the same build and ctest here in ten minutes if you would rather fix it inside this PR than split it out. Either way, want me to post it as a finding: in #634 so the coordinator has it?

AI-assisted.

@tylerstraub

Copy link
Copy Markdown
Contributor

Replying to @bobcatchris.

@bobcatchris, the ten copy hazards already have a tracker finding and a merged fix: #782 changed detail::copy_layout for consecutive copies to an image that stays in the transfer layout. The merge is 6badcb87. @Vonsek independently checked overlapping image and footprint writes on NVIDIA and AMD; both had the expected texels even before the fix, but only the patched run cleared the synchronization errors. Mixed-copy regression and readbacks

Your 69th BC7 case is a useful test of that fix. When #775 is updated, could you rerun it on the RX 7900 XTX with synchronization validation and confirm the BC7 case actually executes? That would distinguish coverage of this branch's extra case from the 68-case main run.

AI-assisted.

@bobcatchris

Copy link
Copy Markdown
Contributor

main already carries the fix for this: 5ec780c orders back-to-back copies into a texture that is already in the transfer layout, which is exactly the gap in my diagnosis above — your branch simply predates it. Rebasing onto main should take the ten hazards to zero on this card too; that is the same code path d3d12_vulkan_device_test's BC7 copy case walks.

It shipped without a test, so I opened #891: vk_command_replay_test part G does two buffer-to-image copies into one subresource in a single list and reads it back. On my 7900 XTX it is green with 5ec780c and reports vkCmdCopyBufferToImage(): WRITE_AFTER_WRITE hazard detected with the barrier disabled, so it guards the behaviour directly rather than through the differential test. No conflict with this PR.

AI-assisted.

@JavierBlanco23

Copy link
Copy Markdown
Contributor Author

Thanks @AlxcBTW, @bobcatchris, @quackottu and @tylerstraub for the detailed testing and the heads-up!

Rebased onto main to pick up both #855 (1 | 4 | 8 | 16 mask for OPTIONS19.SupportedSampleCountsWithNoOutputs) and #782 (5ec780c, the back-to-back copy layout barrier fix). Verified again on Windows 11, RTX 5080 (driver 616.56) with LEONIDA_VK_VALIDATION=1: NoOutputsSamples=0x1d, 15/15 feature queries compared with 0 mismatches, 0 validation errors, ctest 100% green.

@bobcatchris Ready for a rerun on the RX 7900 XTX whenever you have a minute!

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.

5 participants