Skip to content

D3D12: CreateHeap1 on the Vulkan device (answers as CreateHeap, refuses a protected session) - #1846

Open
dracbat wants to merge 3 commits into
ItsNotRexed:mainfrom
dracbat:createheap1
Open

dracbat wants to merge 3 commits into
ItsNotRexed:mainfrom
dracbat:createheap1

Conversation

@dracbat

@dracbat dracbat commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #1548 (comment) (new D3D item)

What and why

ID3D12Device4::CreateHeap1 was still a generated stub on main, so CreateHeap1(desc, nullptr, …) returned E_NOTIMPL where the PC runtime creates the heap. Without a protected session, the PC runtime answers CreateHeap1 exactly as it answers CreateHeap. Probes of the host runtime on an RX 5700 (Adrenalin 26.11.2) and on WARP agreed for every case tried:

  • valid: a 64 KiB default heap, 1000 bytes, 4 MiB MSAA alignment, UPLOAD/READBACK, CUSTOM write-combine L0, ALLOW_ONLY_BUFFERS;
  • refused with E_INVALIDARG: zero size, 4 KiB alignment, CUSTOM with an UNKNOWN page property, all three DENY_* flags, heap type 0;
  • E_NOINTERFACE with a nulled output for the wrong riid;
  • with a null output (RX 5700): S_FALSE for a valid description, whatever the interface, and E_INVALIDARG for a refused one, as with an output.

Changes:

  • CreateHeap1 wraps CreateHeap. It refuses a session as CreateCommittedResource1–3 and CreateReservedResource1/2 do (E_INVALIDARG, nothing handed out), since the layer reports no D3D12_FEATURE_PROTECTED_RESOURCE_SESSION_SUPPORT. The session is refused before the null-output check, so a session with a null output is E_INVALIDARG too.
  • CreateHeap answers a null output after its description checks and before it uses the GPU address arena (@Flyander's review). Before, it reserved the heap and released it again, so the capability check was E_NOTIMPL on a device without the arena and E_OUTOFMEMORY on a full one. Now nothing is created or reserved.
  • docs/d3d12_vulkan.md: the CreateHeap1 line, the null-output rule in the heap bullet, and the test description.

Since #1820 (D3D-238), main's CreateHeap refuses the heap descriptions D3D-238 measured the host refusing. #1820 left CreateHeap1 to this PR, and CreateHeap1 gets those checks through CreateHeap.

#3374 also adds CreateHeap1, with ID3D12Heap1/ID3D12Resource1. Whichever lands first, the other drops its override; the CreateHeap capability-check change here applies either way.

The claim also named ID3D12GraphicsCommandList3::SetProtectedResourceSession. I left it as a stub. Three tests (d3d12_com_test, d3d12_gcl8_test, check_d3d12_trace.py) use it as their example of a generated stub. And with no session support, its only valid call, nullptr, does what the stub does anyway.

Tested

Windows 11, AMD Radeon RX 5700 (Adrenalin 26.11.2, Vulkan 1.4.315), MSVC 14.44, Ninja RelWithDebInfo, Vulkan SDK 1.4.363.1, on this branch merged with main 3faac55:

  • d3d12_method_variants_test runs on the test's device, which has no GPU address arena, and on a standalone device, which has one. CreateHeap1 must give CreateHeap's answer and description for nine heaps (four refused) and the host runtime's answers, live. Without an output, both methods must give S_FALSE or the refusal on both devices, matching the host. That includes the cases where no heap can be made: no arena (E_NOTIMPL with an output), and a 4 GiB heap the arena cannot hold (E_OUTOFMEMORY with an output; not run on the host). A session is refused with or without an output.
  • Negative controls, each rebuilt and run. The test fails in each:
    • main's order (reserve, then S_FALSE): at the first valid heap on the device without the arena;
    • short-circuiting only when there is no arena: at the 4 GiB heap;
    • S_FALSE before the description checks: at the zero-size heap;
    • the session checked after the null output: at the session case.
  • The other heap tests pass: d3d12_vulkan_device, d3d12_buffer_tiles, d3d12_sparse_queue_family, d3d12_placed_dimensions, d3d12_residency, d3d12_heap_properties.
  • Full runtime ctest without the window tests (d3d12_present, vk_presenter_sync, xbox_present): 165 passed, 9 skipped and 1 failed. The failure was loader's 25 ms timing guard (33 ms during the parallel run); it passed alone twice.

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.)

AI-assisted (Claude Code).

🤖 Generated with Claude Code

ID3D12Device4::CreateHeap1 was a generated stub, so a heap created through it
failed with E_NOTIMPL where the PC runtime creates it. Without a protected
session the PC runtime answers CreateHeap1 exactly as CreateHeap; measured on
an RX 5700 and WARP over valid and invalid sizes, alignments, heap types,
page properties and flags. It now wraps CreateHeap, and a session is refused
as CreateCommittedResource1-3 refuse it, since the layer reports no
protected-session support. refuse_protected_session names the method in its
log line.

d3d12_method_variants_test checks CreateHeap1 against CreateHeap, and against
the host runtime live, on a standalone device; heaps need the GPU address
arena, which the test's main device is not made with.

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

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

CreateHeap1(..., ppvHeap = nullptr) is currently delegated to CreateHeap, which creates/reserves a Heap before hand_out returns S_FALSE. If the arena is unavailable or exhausted, the call can return E_NOTIMPL/E_OUTOFMEMORY instead. Microsoft specifies that a valid pDesc with a null ppvHeap is a capability query: no object is created and S_FALSE is returned. Please validate the descriptor/session, then short-circuit before any heap allocation, and cover the no-capacity case.

This PR also overlaps #1820, which independently adds CreateHeap1 and changes the same device implementation/docs. Please coordinate which branch owns the method to avoid duplicate overrides and merge conflicts.

Reference: ID3D12Device4::CreateHeap1.

tomgamer22 added a commit to tomgamer22/Leonida that referenced this pull request Nov 22, 2026
…p1 to ItsNotRexed#1846

heap_desc_refusal now also refuses D3D12_HEAP_FLAG_ALLOW_DISPLAY and
HARDWARE_PROTECTED, which the D3D12_HEAP_FLAGS documentation says
CreateHeap does not support (review on ItsNotRexed#1820). Both are host-comparison
cases in compare_invalid_arguments, awaiting a host run, and direct
refusal checks on the standalone device.

CreateHeap1, its heap1 test cases and the heap_create1 helper are
removed: ItsNotRexed#1846 implements CreateHeap1 over CreateHeap and inherits these
checks. The docs keep ItsNotRexed#1846's CreateHeap1 line untouched and describe
the CreateHeap checks under the heap bullet instead.

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

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Windows + GPU check: AMD Radeon RX 9070 (RDNA4), Windows 11, MSVC Release, Vulkan SDK 1.4.363. Tested head 54933c4 merged onto main 4947579 (clean merge), full build, full ctest -C Release -j 4: 100% tests passed out of 116 | new failures vs main: none. The main baseline on the same machine passes 116/116, so nothing regresses here.

AI-assisted (Claude Code); runs on my machine.

dracbat and others added 2 commits November 23, 2026 10:16
Conflicts in runtime/shims/d3d12_vulkan_device.cpp take main's side
(its one-argument refuse_protected_session and the trace-wrapped
CreateCommittedResource1-3), so CreateHeap1's call now uses
refuse_protected_session("CreateHeap1"). The final printf in
runtime/test/d3d12_method_variants_test.cpp combines both sides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A valid description with a null ppvHeap is a capability query: nothing
is created and S_FALSE is returned; a refused description still gives
E_INVALIDARG. CreateHeap used to reserve the heap in the GPU address
arena, release it and then return S_FALSE, so the check answered
E_NOTIMPL without the arena and E_OUTOFMEMORY with a full one. It now
runs its description checks (D3D-238) first and returns S_FALSE before
it touches the arena. CreateHeap1 refuses a protected session before
the check, so a session with a null output is E_INVALIDARG.

d3d12_method_variants_test checks nine descriptions (four refused) on a
device without the arena and on one with it, with and without an
output, against the host runtime live, plus the no-capacity cases (no
arena; a 4 GiB heap) and a session or null description with a null
output. Host answers were measured on an RX 5700 (Adrenalin 26.11.2).

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

dracbat commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Flyander. Both points are handled on the new head.

Capability check. The order came from CreateHeap itself: on main it reserved the heap in the GPU address arena, then released it and returned S_FALSE for a null output. So without the arena the check answered E_NOTIMPL, and with a full arena E_OUTOFMEMORY. CreateHeap now runs its description checks (D3D-238) first, then returns S_FALSE for a null output before it looks at the arena, so nothing is created or reserved. CreateHeap1 gets this through CreateHeap. It refuses a protected session before the check, so a session with a null output is E_INVALIDARG too. An invalid description is refused with or without an output.

I checked the host runtime first (RX 5700, Adrenalin 26.11.2, Windows 11). With a null output, CreateHeap and CreateHeap1 gave:

  • S_FALSE for valid descriptions, also with an interface other than ID3D12Heap;
  • E_INVALIDARG for six refused ones, as with an output: zero size, alignment 4096, type 0, a custom heap with an unknown CPU page property, all three DENY_* flags, and ALLOW_DISPLAY.

Tests (d3d12_method_variants_test). They run on the test's device, which has no arena, and on the standalone device, which has one:

  • Nine descriptions, four of them refused. Without an output, both methods must give S_FALSE or the refusal on both devices, and match the host live.
  • No capacity: a valid heap on the device without the arena is E_NOTIMPL with an output and S_FALSE without one. A 4 GiB heap, larger than any arena (4095 MiB at most), is E_OUTOFMEMORY on the standalone device with an output and S_FALSE without one. That case isn't run on the host, which would make the heap.
  • A session, and a null description, are E_INVALIDARG with a null output.

Negative controls, each rebuilt and run. The test fails in each:

  • main's order (reserve, then S_FALSE): at the first valid heap on the device without the arena (E_NOTIMPL).
  • Short-circuiting only when there is no arena: at the 4 GiB heap (E_OUTOFMEMORY).
  • S_FALSE before the description checks: at the zero-size heap.
  • The session checked after the null output: at the session case.

Overlaps. #1820 merged as D3D-238 and left CreateHeap1 to this PR. #3374, opened after your review, adds the same CreateHeap1 override, along with ID3D12Heap1/ID3D12Resource1. Whichever lands first, the other drops its CreateHeap1. The CreateHeap change here is needed in both cases, since #3374's CreateHeap1 also goes through CreateHeap. This branch now merges main (3faac55) and uses main's one-argument refuse_protected_session.

Tested on Windows 11 with an RX 5700 (Adrenalin 26.11.2, Vulkan 1.4.315), MSVC 14.44, Vulkan SDK 1.4.363.1, Ninja RelWithDebInfo:

  • d3d12_method_variants passes, compared live with the host.
  • The other heap tests pass: d3d12_vulkan_device, d3d12_buffer_tiles, d3d12_sparse_queue_family, d3d12_placed_dimensions, d3d12_residency and d3d12_heap_properties.
  • Full runtime ctest without the three window tests: 165 passed, 9 skipped and 1 failed. The failure was loader's 25 ms timing guard (33 ms during the parallel run). It passed alone twice.

Thanks @Dom-in for the RX 9070 run, and for the main baseline next to it. Since 54933c4 the branch has merged main and changed how CreateHeap and CreateHeap1 answer a null output (Flyander's review), so that run covers the old head. If you have time, a re-run of d3d12_method_variants on the new head would be welcome.

AI-assisted (Claude Code).

@thehollowedone

Copy link
Copy Markdown

Independent Windows check of 123e1e6d on 3faac557. Windows 11 x64 build 26300, RTX 3080 Ti / 621.35, MSVC 19.44.35230, Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.0, RelWithDebInfo.

The focused d3d12_method_variants CTest passed (1/1, zero skips or Vulkan validation errors). CreateHeap and CreateHeap1 matched host D3D12 for five valid heap descriptions, including the returned descriptions. The null-output queries matched host S_FALSE on both layer devices, even without a GPU address arena. On the layer device without an arena, the same ordinary heap request with an output returned E_NOTIMPL and a null result. Both methods also returned S_FALSE for the 4 GiB descriptor with a null output. That descriptor was only queried.

I used the exact PR production code and a scratch fixture limited to the valid heap and capability-query cases. Synthetic inputs only. AI-assisted.

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 123e1e6 on NVIDIA GeForce RTX 4080, driver 617.42: d3d12_method_variants_test exits 0. The log shows the layer refusing CreateHeap for zero size, bad alignment, heap type 0 and DENY flags, and "protected resource session refused (not supported) by CreateHeap1: 1". The test prints no pass summary and no host comparison lines for CreateHeap1, so this run does not show the host-match claims in the description.

AI-assisted.

@dracbat

dracbat commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the run, @gertify.

  • The host comparisons are assertions, not printed lines. When the test finds a host D3D12 device, check_heap1 compares every CreateHeap1 answer with the host's, with and without an output. A mismatch fails the test at that line, so exit 0 on your RTX 4080 means they all matched.
  • No pass summary: right, it doesn't print one. If a line counting the host comparisons would help reviewers, I can add it.

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