Skip to content

d3d12: CreateCommittedResource answers a null output before it allocates anything - #6035

Open
dracbat wants to merge 1 commit into
ItsNotRexed:mainfrom
dracbat:fix/null-output-capability
Open

dracbat wants to merge 1 commit into
ItsNotRexed:mainfrom
dracbat:fix/null-output-capability

Conversation

@dracbat

@dracbat dracbat commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #5256 (comment)

What and why

A null ppvResource makes CreateCommittedResource and CreateCommittedResource1/2/3 a capability check. I measured the host runtime on an RX 5700:

  • a description that passes the checks gets S_FALSE, whatever the riid, and nothing is created;
  • an invalid one gets the refusal it gets with an output;
  • the host answers S_FALSE even where creation could never succeed: a UINT64_MAX-byte buffer (E_OUTOFMEMORY with an output), default-heap buffers of 4 GiB, 64 GiB and 1 TiB, a 64 GiB upload buffer, and an 8 TiB texture.

The layer's create_committed built the resource first (an arena range, or a VkBuffer or VkImage and its memory), then released it and returned S_FALSE. So the check failed wherever creation fails for lack of room:

  • E_OUTOFMEMORY with a full GPU address arena, for a default-heap buffer larger than the arena, or for a texture larger than any memory heap;
  • E_INVALIDARG for a buffer within 64 KiB of UINT64_MAX.

create_committed now makes every argument check first, and returns S_FALSE for a null output before it creates or allocates anything. That includes the Vulkan device's answer for a texture's image with its castable-format list. The image setup moves out of create_texture into prepare_image, which create_texture and a new Resource::texture_supported share, so both ask the device the same question. With an output, nothing changes.

CreatePlacedResource/1/2 and CreateReservedResource/1/2 were audited for the same problem:

  • they never build anything before answering a null output;
  • the host's answer there is E_UNEXPECTED, not S_FALSE, for a valid description and a wrong riid alike, and the layer already gave it;
  • one check came too late: CreatePlacedResource2 and CreateReservedResource2 checked their castable-format list only after that E_UNEXPECTED. The host refuses a format of another texel size, UNKNOWN, or a list on a buffer with E_INVALIDARG without an output too. Both now check the list first, and answers with an output are unchanged.

CreateHeap is untouched: #1846 makes the same fix there. The two PRs change no adjacent lines and merge cleanly. docs/d3d12_vulkan.md has the rules and the test descriptions. This branch is based on main 3faac55 and merges cleanly with main 561b65a.

Tested

Windows 11, AMD Radeon RX 5700, AMD driver 32.0.21045.29003, MSVC 14.44, Vulkan SDK 1.4.363.1.

  • Host probe: a scratch probe (not committed) asked the RX 5700's host D3D12 device each method above with and without an output, for valid and invalid descriptions and with riid = ID3D12Fence. It gave the answers above, which the new tests compare with the host live.
  • d3d12_method_variants_test:
    • null-output edge cases for CreateCommittedResource1/2/3, CreatePlacedResource1/2 and CreateReservedResource1/2 (valid, invalid, castable lists, wrong interface), compared with the host runtime live;
    • check_no_room: an 8 TiB texture on a device without the GPU address arena and on one with it, and a 4 GiB default-heap buffer (larger than any arena), through all four committed variants. With an output each gives E_OUTOFMEMORY with nothing handed out; without one, S_FALSE, matching the host's own S_FALSE;
    • compare_creation now requires every creation case's null-output answer to be S_FALSE where creation succeeds and its refusal where creation fails. A new D32_FLOAT render-target case is one the Vulkan device refuses.
  • d3d12_vulkan_device_test: all against the host.
    • six null-output cases in compare_invalid_arguments: wrong interface, a render target with a clear value, a plain texture with one, a texture on an upload heap, 4x MSAA without RT or DS, and a UINT64_MAX-byte buffer;
    • two in compare_placed_reserved: wrong interface, placed and reserved.
  • Negative controls, each rebuilt with one part of the fix reverted:
    • the base create_committed fails all 12 check_no_room rows (E_OUTOFMEMORY without an output) and the UINT64_MAX case (E_INVALIDARG, host S_FALSE);
    • the base create_placed and create_reserved each fail their castable null-output case (E_UNEXPECTED, host E_INVALIDARG);
    • the whole base shim fails both tests.
    • Not covered by a test: a castable list the Vulkan device refuses inside texture_supported, as this driver accepted all 16 lists tried.
  • The two affected tests: d3d12_method_variants and d3d12_vulkan_device pass, and d3d12_method_variants passes under LEONIDA_VK_VALIDATION=1 with no validation messages.
  • Full suite: cmake --build <build> --parallel 6, then ctest -j 2 -E "d3d12_present|vk_presenter_sync|xbox_present": 175 tests, 166 passed, 9 skipped, 0 failed.

AI-assisted: yes (Claude Code).

Checklist

  • 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

…tes anything

A null ppvResource makes CreateCommittedResource/1/2/3 a capability
check: the host runtime (RX 5700) answers S_FALSE for a valid
description whatever the riid, even for a UINT64_MAX-byte buffer or an
8 TiB texture, and the refusal for an invalid one. create_committed
built the resource and released it, so the check failed with
E_OUTOFMEMORY for a full GPU address arena, a buffer larger than the
arena or a texture larger than any memory heap. It now makes every
argument check first, the Vulkan device's answer for the image and its
castable list included (prepare_image, shared by create_texture and
Resource::texture_supported), and returns S_FALSE before it creates
anything; with an output nothing changes. CreatePlacedResource2 and
CreateReservedResource2, which answer a null output with E_UNEXPECTED as
the host does, now check their castable-format list before that answer,
since the host refuses a bad list without an output too.
d3d12_method_variants_test and d3d12_vulkan_device_test compare the
null-output answers with the host live and check the no-room cases on
devices with and without the arena.

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

Copy link
Copy Markdown
Contributor

Independent NVIDIA check at 055118f4: Windows 11 build 26200, RTX 4080, NVIDIA 621.01, MSVC 19.44 RelWithDebInfo and Khronos validation 1.4.357. d3d12_method_variants and d3d12_vulkan_device both passed (2/2). The committed-resource null-output and no-room cases passed, as did the placed/reserved castable-format checks against native D3D12. The device test selected the RTX 4080 for both Vulkan and the host comparisons. Both tests completed with validation enabled and zero validation errors. Synthetic inputs only. AI-assisted with Codex.

@sennecools

Copy link
Copy Markdown

AMD check at 055118f4, merged onto main 561b65a (merges cleanly). Windows 11, MSVC 14.44 RelWithDebInfo, Vulkan SDK 1.4.363.0, VK_LOADER_LAYERS_DISABLE=~implicit~.

  • RX 9070 XT (RDNA4, AMD 32.0.32029.2010): d3d12_com, d3d12_vulkan_device and d3d12_method_variants passed 3/3, three times without and three times with LEONIDA_VK_VALIDATION=1, with no validation messages.
  • Ryzen 9800X3D iGPU (RDNA2 gfx1036, 32.0.21045): 3/3 passed without validation and with it.

A scratch native D3D12 probe (not committed) on both adapters gives the same answers you measured on the RX 5700:

  • CreateCommittedResource without an output gives S_FALSE for a UINT64_MAX buffer (E_OUTOFMEMORY with an output), for UINT64_MAX - 64 KiB, for default buffers of 4 GiB, 64 GiB and 1 TiB, for a 64 GiB upload buffer, for an 8 TiB texture and for riid = ID3D12Fence.
  • A plain texture with a clear value, and 4x MSAA without RT or DS, give E_INVALIDARG.
  • CreateReservedResource gives E_UNEXPECTED, including with a wrong riid.
  • CreateCommittedResource3 with a castable list of the same texel size gives S_FALSE, including on the 8 TiB texture. A list with another texel size gives E_INVALIDARG.
  • CreateReservedResource2 gives E_UNEXPECTED for the same-size list and E_INVALIDARG for the other one.

So the host behaviour is the same on RDNA1, RDNA2 and RDNA4 AMD drivers. Synthetic inputs only.

AI-assisted.

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 055118f on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass

  • Built d3d12_vulkan_device_test and d3d12_method_variants_test (MSVC 19.44, Ninja, RelWithDebInfo). ctest -R "^(d3d12_method_variants|d3d12_vulkan_device)$" with LEONIDA_VK_VALIDATION 0 and 1: 2/2 pass each time. The device test reports 0 mismatches on 45 feature queries and 0 failures on the new-format checks.
  • Negative control: runtime/shims/d3d12_vulkan_device.cpp reverted to the merge base 3faac55, new tests kept. Both executables exit 1. d3d12_vulkan_device_test: invalid arguments committed: UINT64_MAX-byte buffer, null output: ours 0x80070057, host 0x00000001. d3d12_method_variants_test: CreatePlacedResource2, castable format of another texel size, null output: got 8000ffff, want 80070057. Those are the two behaviours the PR describes.
  • Not done: the measured host answers in the PR (taken on an RX 5700) were not re-measured on this card; the 4 GiB to 8 TiB allocation cases were not run on their own here.

AI-assisted (Claude Code).

@trick-ye

Copy link
Copy Markdown

Tested 055118f4 on AMD Radeon RX 7800 XT (RDNA3), AMD 26.11.2 (Windows driver 32.0.32029.2010), Windows 11 26200: pass.

  • The head is based on 3faac557, and I tested it as it is, not merged with current main.
  • Full build, then ctest -R d3d12_ -j 1: 68 tests, 66 pass, 2 skipped (d3d12_sparse_queue_family_contract, d3d12_first_light), 0 fail. d3d12_method_variants and d3d12_vulkan_device, which hold the PR's checks, pass.
  • I have no run of 3faac557 itself on this card to compare with; the three tests that fail here on main 561b65a8 are either absent at this base or pass on it.
  • MSVC 14.42 (VS 2022), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, llvm-mc 23.1.6, RelWithDebInfo, LEONIDA_VK_DEVICE=7800. A test run, not a code review. Synthetic tests only, no game files.

AI-assisted (Claude Code).

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