Skip to content

d3d12: GetResourceAllocationInfo resource flag and sample quality parity (D3D-467) - #4508

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
SHAURYASANYAL3:feat/d3d-467-allocation-info-flag-parity
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
SHAURYASANYAL3:feat/d3d-467-allocation-info-flag-parity

Conversation

@SHAURYASANYAL3

@SHAURYASANYAL3 SHAURYASANYAL3 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed as D3D-467 on #4421.

What and why

Harmonizes GetResourceAllocationInfo resource flag and sample quality checks with host D3D12 and WARP:

  • Buffers: accepts D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET and D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER (along with UAV, DENY_SHADER_RESOURCE, RAYTRACING_ACCELERATION_STRUCTURE and 0x400) returning a valid 64K-aligned allocation size as the host does. Refuses ALLOW_DEPTH_STENCIL, ALLOW_SIMULTANEOUS_ACCESS, VIDEO_DECODE_REFERENCE_ONLY and other unrecognized flags by returning kInvalidAllocation (UINT64_MAX).
  • Textures: accepts single-sample textures with any sample quality (Quality 1, xffffffff, etc.), matching host runtime rules where single-sample quality does not invalidate allocation queries. Only multisample textures (Count > 1) reject quality != 0.
  • Textures: refuses DENY_SHADER_RESOURCE when not combined with ALLOW_DEPTH_STENCIL by returning kInvalidAllocation, as measured against the host runtime.

Testing

  • Extended compare_allocation_info in
    untime/test/d3d12_vulkan_device_test.cpp with 10 differential test cases directly comparing against host D3D12 and WARP.
  • Verified all cases pass and match host D3D12 / WARP allocation sizes and alignments.
  • Ran pytest regression suite on related tests ( est_d3d12_stubs_generation.py, est_d3d12_iid_scan.py).
  • CPU & GPU Windows testing, synthetic cases only, no game files. AI-assisted.

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

Built and ran d3d12_vulkan_device_test at b1fffe83 on Windows 11, RTX 5070 Ti: exit 0; the full device suite passes, including the new GetResourceAllocationInfo resource-flag and sample-quality checks. No blocking issue.

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

[P2] Gate the 0x400 buffer flag on tight-alignment support. In current D3D12 headers this is D3D12_RESOURCE_FLAG_USE_TIGHT_ALIGNMENT; Microsoft specifies that it is valid only when D3D12_FEATURE_D3D12_TIGHT_ALIGNMENT reports support, and that unsupported use is invalid (spec). This mask accepts 0x400 unconditionally and returns a normal allocation result without checking the feature tier. On a host that reports NOT_SUPPORTED, Leonida will disagree with the host result (SizeInBytes == UINT64_MAX on GetResourceAllocationInfo error). Please gate the flag by capability or reject it, and add a differential case for an unsupported tier.

@Parakeet-Wheat

Copy link
Copy Markdown
Contributor

Tested b1fffe8 on Windows 11 26300, MSVC (VS 2022), Windows SDK 10.0.26100, RTX 3070 (610.88), host D3D12 on the same adapter: pass. Full ctest is 154/154 with 0 build warnings, and d3d12_vulkan_device_test has 0 allocation-info mismatches. On this driver the host also gives 65536 for the single-sample Quality = 1 and 0xffffffff cases.

Negative control. With the parent's d3d12_vulkan_device.cpp under this test, 8 of the 10 new cases fail on the 3070 (buffer RT, buffer RT + UAV, simultaneous access, video decode reference, 0x1000, tex2d deny-SR alone, and both single-sample quality cases). Buffer cross-adapter and buffer depth-stencil already matched before. So the new cases separate the change on NVIDIA.

25 more host cases (added locally, not committed). 22 match:

  • Buffers (all match): deny SR alone, UAV + deny SR, 0x80 (video encode reference), 0x100 (RTAS), RTAS + UAV, 0x200, 0x400, 0x800, UAV + cross-adapter, RT + DS, every accepted flag at once, and Quality = 1.
  • Textures that match: deny SR + DS (accepted), deny SR + RT and deny SR + UAV (both refused), 0x400, and single-sample Quality = 1 on a 4 KiB-aligned 2D, a render target, a D32 depth, a 1D and a 3D texture. 4x MSAA with Quality = 1 is refused by both.

On @Flyander's 0x400 point: the layer accepts 0x400 on a buffer, and the host matched, so on this RTX 3070 with the inbox runtime of build 26300 the host accepts it on a buffer. It also accepts it on a 16x16 texture (65536, alignment 64 KiB), and it refuses 0x200 and 0x800. That agrees with the existing committed-resource rule at d3d12_vulkan_device.cpp:1328. I couldn't query D3D12_FEATURE_D3D12_TIGHT_ALIGNMENT here, because SDK 10.0.26100 doesn't define it, so this doesn't show what a host that reports it unsupported does. It only shows that this one accepts the flag.

Three don't match. All three behaved the same before this PR:

case ours host
64x64 4x MSAA RT, Quality = 0xffffffff (D3D12_STANDARD_MULTISAMPLE_PATTERN) refused 4194304, alignment 4 MiB
same, Quality = 0xfffffffe (D3D12_CENTER_MULTISAMPLE_PATTERN) refused 4194304, alignment 4 MiB
16x16 RGBA8 with D3D12_RESOURCE_FLAG_VIDEO_ENCODE_REFERENCE_ONLY 65536 refused

So for multisampled textures, the host's rule is "quality must be 0 or one of the two pattern values", not "quality must be 0". The new comment's "Only multisample textures (Count > 1) reject quality != 0" isn't quite right on NVIDIA. That could be a small follow-up, or part of this PR if you'd like to cover it.

AI-assisted (Claude Code).

@mrbean56

Copy link
Copy Markdown

Reading review (no Windows/D3D12 here), plus the enum documentation and a cross-PR merge check.

Cannot run the Windows test. No game data. AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested b1fffe8 merged with main 03b09a0 (already up to date) on native Windows 11, MSVC 14.51, full runtime/ build: pass on NVIDIA GeForce RTX 4080 SUPER and on Intel UHD 770 (driver 32.0.101.6129, VK_LOADER_DRIVERS_DISABLE=*nv*).

  • ctest -R d3d12_vulkan_device: passed on both (82 s and 6 s). The new cases compare our GetResourceAllocationInfo with the host's.
  • Negative control: d3d12_vulkan_device.cpp from main with the PR's test: FAILED with 8 allocation mismatches against the host: buffer render target and render target + UAV, buffer simultaneous access, video-decode-reference-only and flag 0x1000 (host refuses, we accepted), texture deny-shader-resource alone, and single-sample quality 1 and 0xffffffff (we refused, host accepts).
  • Not covered by a test: the other newly accepted buffer flags (DENY_SHADER_RESOURCE, RAYTRACING_ACCELERATION_STRUCTURE, 0x400), and multisample with Quality != 0, which stays refused. The host here is the NVIDIA D3D12 driver, so the expectations are what that host does.

@Parakeet-Wheat

Copy link
Copy Markdown
Contributor

On @mrbean56's second-adapter question: a small host probe (plain D3D12 GetResourceAllocationInfo, nothing from the layer) on the RTX 3070 and on WARP, same machine (Windows 11 26300, inbox runtime). Both adapters gave the same answer in all 20 cases:

description RTX 3070 and WARP
16x16 RGBA8, 1 sample, Quality 1, 0xffffffff, 0xfffffffe 65536 (each)
same with Quality = 1: render target, D32 depth, 1D, 32x32x8 3D 65536 (each)
buffer, Quality = 1 refused
64x64 RGBA8 4x MSAA RT, Quality 0, 0xffffffff, 0xfffffffe 4194304, alignment 4 MiB
same, Quality 1 and 0xfffffffd refused
texture with 0x400 / buffer with 0x400 65536 / 65536
texture with 0x80 (VIDEO_ENCODE_REFERENCE_ONLY) refused
texture with DENY_SHADER_RESOURCE alone / buffer with it refused / 65536

NumQualityLevels for RGBA8 4x is 1 on both. So the single-sample rule in this PR (any quality accepted for a texture, refused for a buffer) is what both a hardware runtime and WARP do, not an NVIDIA quirk. A comment naming both, as suggested, would keep it from being "fixed" back. The MSAA rows are the follow-up from my earlier comment: both adapters accept the two pattern values there. WARP also accepts 0x400, which is one more data point for @Flyander's question (neither adapter's tight-alignment tier can be queried with SDK 10.0.26100).

AI-assisted (Claude Code).

@memorypressure

Copy link
Copy Markdown

Verified statically on the merged tree (main 3faac55): the buffer-flags refusal now enumerates the accept-set so unnamed flags like 0x400 are rejected (explicitly probed in the new test), the multisample-quality rule relaxes only for count>1, and the DENY_SHADER_RESOURCE-without-DS mirror matches the committed-resource validator already at d3d12_vulkan_device.cpp:1462 — a parity gap-closer, not an invention. The C++ test needs Windows and was not run; the accept-sets are host-measured claims that the pending windows/linux-gpu-tools checks carry. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only review).

@ItsNotRexed
ItsNotRexed merged commit 7cf7fa7 into ItsNotRexed:main Nov 23, 2026
2 of 4 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.

8 participants