Skip to content

D3D12: expose ID3D12Heap1/ID3D12Resource1 and implement CreateHeap1 without a protected session - #3374

Closed
kapitche wants to merge 1 commit into
ProjectLeonida:mainfrom
kapitche:d3d12-heap1-resource1
Closed

kapitche wants to merge 1 commit into
ProjectLeonida:mainfrom
kapitche:d3d12-heap1-resource1

Conversation

@kapitche

Copy link
Copy Markdown
Collaborator

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

What and why

  • Heaps and committed/placed resources did not answer QueryInterface for ID3D12Heap1 / ID3D12Resource1 (the log showed unknown IID {9d5e227a-...}), so an application that asks for them to call GetProtectedResourceSession got E_NOINTERFACE. The host D3D12 runtime and WARP answer DXGI_ERROR_NOT_FOUND with a null output for an unprotected object, whatever IID is asked for. The two interfaces are now generated (runtime/CMakeLists.txt stub list) and implemented that way: the layer has no protected sessions (D3D12_FEATURE_PROTECTED_RESOURCE_SESSION_SUPPORT is NONE), so no object belongs to one.
  • ID3D12Device4::CreateHeap1 was a generated stub that returned E_NOTIMPL for every call. With a null protected session it is CreateHeap (host and WARP: same HRESULTs for the same arguments, including S_FALSE for a null output, E_NOINTERFACE for a wrong IID, E_INVALIDARG for size 0). A non-null session is refused with E_INVALIDARG, as CreateCommittedResource1-3 already refuse one.

Repro: heap->QueryInterface(IID_PPV_ARGS(&heap1)) fails on main; device4->CreateHeap1(&desc, nullptr, IID_PPV_ARGS(&heap)) returns 0x80004001 on main.

Docs: ID3D12Device4::CreateHeap1 (pProtectedSession is optional), ID3D12Resource1::GetProtectedResourceSession. The NOT_FOUND answer is measured on the host runtime and WARP.

Tested

Eight new rows in compare_heap_neighbours of d3d12_vulkan_device_test (standalone device with the GPU address arena, each answer compared with the host): CreateHeap1 with no session (plain, ID3D12Heap1 asked, null output, wrong interface, size 0, size 1000), ID3D12Heap1::GetProtectedResourceSession and ID3D12Resource1::GetProtectedResourceSession.

  • Windows 11, MSVC 18 (VS 2026), Ninja RelWithDebInfo, d3d12_vulkan_device_test: pass on RTX 4080 SUPER and on Intel UHD 770 (VK_LOADER_DRIVERS_DISABLE=*nv*).
  • Negative control (same test, shim reverted to main): all 8 rows fail (for example ours 0x80004001, host 0x00000000), exit 1.

AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • No translator rule.

@slint6614-dev

Copy link
Copy Markdown
Contributor

Tested c37e7a2 on AMD Radeon RX 9070 (RDNA4; subgroup 32..64, default 64), AMD proprietary driver 26.10.1 (LLPC), Vulkan device API 1.4.349, Windows 10.0.26300.9974. Built with MSVC 19.44.35230.0 and Vulkan SDK 1.4.363.1.

With LEONIDA_VK_VALIDATION=1, ctest -R "^d3d12_vulkan_device$" --output-on-failure passed (1/1). The eight added CreateHeap1 / GetProtectedResourceSession comparisons produced no mismatch against the Windows D3D12 runtime on this AMD adapter.

Synthetic D3D12 tests only; no game files.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested c37e7a2 on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:

  • Full ctest: 141/141.
  • d3d12_vulkan_device: pass 20 of 20 runs, and pass under LEONIDA_VK_VALIDATION=1 with 0 validation messages.
  • Warnings: none new in the files this PR changes.

AI-assisted (Claude Code).

@oVolkra

oVolkra commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested c37e7a2 (merged onto main aa2988c) on RTX 3060 (Ampere), driver 617.14, Windows 11, MSVC 14.44, RelWithDebInfo: pass

  • ctest: 153/153 pass, also with LEONIDA_VK_VALIDATION=1 (153/153).
  • scripts/run_gpu_tests.py: native 164/210 (46 skipped), with LEONIDA_W64_EMULATE=1 195/210 (15 skipped). Same as main at aa2988c.
  • Eight *_test.exe programs that ctest does not register (d3d12_clear, tiny_game_exit_code, vk_bindless, vk_compute, vk_sampler, vk_store, vk_texture, vk_xdxr_build) were run by hand, with and without validation: same results as on main.
  • No game files used.

AI-assisted: this check was run and written with Claude Code (Anthropic) on my machine; the numbers above are its unedited output.

…ithout a protected session

Heaps and resources did not answer QueryInterface for ID3D12Heap1 and ID3D12Resource1, so
GetProtectedResourceSession was unreachable; the host runtime and WARP answer DXGI_ERROR_NOT_FOUND with a null
output for an unprotected object. ID3D12Device4::CreateHeap1 was a generated stub returning E_NOTIMPL; with no
protected session it is CreateHeap (a session is refused, as CreateCommittedResource1-3 refuse one).
Compared with the host in compare_heap_neighbours.
@oVolkra

oVolkra commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 6c0b3c4 (merged onto main 98fa503) on RTX 3060, driver 617.14, Windows 11: pass

Ran: ctest, ctest with LEONIDA_VK_VALIDATION=1, the unregistered *_test.exe, and run_gpu_tests.py native and with LEONIDA_W64_EMULATE=1. Failures that also happen on main 98fa503 are excluded: d3d12_clear (format mismatch vs WARP, see #521).

AI-assisted: the build and test run were done with Claude Code on my machine; the numbers above are its unedited output.

@nakebx

nakebx commented Nov 23, 2026

Copy link
Copy Markdown

Tested 6c0b3c4 on NVIDIA GeForce RTX 3070 (Ampere), driver 610.88, Windows 11 Pro 10.0.26200: pass

  • ctest with LEONIDA_VK_VALIDATION=1: 100% tests passed, 0 failed out of 163
  • d3d12_vulkan_device_test run directly with the same setting: exit 0, last line "Vulkan device behind the Xbox-ABI proxy: clears, zero-filled first use, uploads, texture, buffer and BC copies, a resolve, reserved resources, queries, GetCopyableFootprints, GetResourceTiling and CheckFeatureSupport error paths all matched"

Built with MSVC through scripts\build_runtime.ps1, Vulkan SDK 1.4.363.0. DISABLE_RTSS_LAYER=1 and DISABLE_VULKAN_OBS_CAPTURE=1 were set. Run with an AI-assisted script; the numbers are copied from the tool output.

@Vonsek

Vonsek commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 6c0b3c4 on Windows 11 (MSVC BuildTools 2022, Ninja, RelWithDebInfo, -j 4; no Vulkan validation layer installed), one GPU at a time, device line confirmed: AMD Radeon RDNA2 iGPU (driver 26.10.1) and NVIDIA RTX 5080 (driver 616.92). Ran ctest -R "^(d3d12_vulkan_device)$" (the tests this PR adds/changes): pass on both GPUs, 1/1 each. No game files.

AI-assisted.

@memorypressure

Copy link
Copy Markdown

Verified on Linux: this is the CreateHeap1 gap main's D3D-238 commits explicitly left open (their messages say leave CreateHeap1 to #1846), and main has zero IID_ID3D12Heap1 references (re-checked) — genuinely unlanded work. Two merge notes: the branch conflicts around d3d12_vulkan_device.cpp and its test, and after merging it still calls the old integer form refuse_protected_session(4) while main converted that helper to method-name strings — the CreateHeap1 refusal needs refuse_protected_session("CreateHeap1"), after which the merge is straightforward (adapted and compile-checked that way locally; stubs-generator CMake addition merges cleanly). I could not build the runtime or run the device tests here, so the E_INVALIDARG/DXGI_ERROR_NOT_FOUND behaviour claims rest on CI's legs. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@kapitche

Copy link
Copy Markdown
Collaborator Author

Thanks for checking the merge. Both notes are about the older head: at the current head 6c0b3c49 the CreateHeap1 refusal already calls refuse_protected_session("CreateHeap1") (the method-name form, d3d12_vulkan_device.cpp line 6078 on the branch), and there is no integer-form call left. I also rebased the head onto current main 3faac557 in a scratch worktree: git rebase finishes with no conflicts and git merge-tree reports none, so the d3d12_vulkan_device.cpp / test conflict you saw is not there any more (main moved under the branch; GitHub also shows it as mergeable). I did not push the rebase, to avoid resetting the runs people have already posted on 6c0b3c49. I only checked the merge here, not a build of the rebased tree.

@searyecheesepeaceful

Copy link
Copy Markdown

Tested 6c0b3c4 on NVIDIA GeForce RTX 4080 (driver 617.42), Windows 11, clang-cl cross-build: d3d12_vulkan_device_test exits 0.

The output has no failure lines; the last arena line is "GPU address arena: peak end 24.3 of 256.0 MiB (9.5%), peak live 24.2 MiB (buffers 0.0, descriptor heaps 0.0, shaders 0.0, heaps 24.2), 87 allocations, 0 refused". The new CreateHeap1 and protected-session rows print nothing by name, so this run shows the test passes on this host, not that each new row was reached.

AI-assisted.

@dracbat

dracbat commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Heads-up: #1846 (claimed earlier in #1548) adds the same CreateHeap1 override. It also changes CreateHeap to answer a null output after the description checks and before the GPU address arena (Flyander's review there). Whichever lands first, the other can drop its CreateHeap1. Your heap1: no session, null output row should pass either way.

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Collaborator Author

@dracbat thanks for the heads-up. Compared the two diffs against current upstream/main. The CreateHeap1 bodies are the same (null *out, a session goes to refuse_protected_session("CreateHeap1"), otherwise CreateHeap), so they will conflict textually at that spot whichever lands second. Two differences: #1846 moves the null-output S_FALSE in CreateHeap ahead of the arena check; this PR additionally exposes ID3D12Heap1 and ID3D12Resource1 (GetProtectedResourceSession, DXGI_ERROR_NOT_FOUND) and adds both to the stub generator list, which #1846 does not touch.

To check that our rows hold with their CreateHeap change, I rebased this branch onto current upstream/main (561b65a8), applied #1846's CreateHeap hunk on top (the if (!out) return S_FALSE; before the arena check, with the old one after the allocation removed), and ran d3d12_vulkan_device on Windows 11, MSVC 14.51, RelWithDebInfo, LEONIDA_VK_VALIDATION=1 with the Khronos validation layer loaded: passes on the RTX 4080 SUPER and on the UHD 770 (LEONIDA_VK_DEVICE=Intel). That includes heap1: no session, heap1: no session, ID3D12Heap1 asked and heap1: no session, null output.

Plan: if #1846 lands first, I drop this PR's CreateHeap1 override and keep the ID3D12Heap1/ID3D12Resource1 exposure plus the rows; if this lands first, #1846 can drop its override and keep the CreateHeap null-output change and its tests. I am not changing this PR now to avoid resetting the runs already posted on 6c0b3c49.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 6c0b3c4954ffb5d7e1d8da7f5b6762ae1bbc46fd. Windows 11 26200, MSVC 19.44.35207, Ninja, RelWithDebInfo, Vulkan 1.4.363, RTX 5070 Ti.

d3d12_vulkan_device 1/1; 17 CreateHeap-neighbour cases (8 new), 0 mismatches against the host runtime. New cases: CreateHeap1 S_OK / ID3D12Heap1 / null out (S_FALSE) / wrong IID / size 0 / size 1000, and ID3D12Heap1/ID3D12Resource1::GetProtectedResourceSession = DXGI_ERROR_NOT_FOUND with a null out. git diff --check clean.

Red baseline (revert runtime/shims/d3d12_vulkan_device.cpp only): exit 1, 8 mismatch lines, all E_NOTIMPL/E_NOINTERFACE against the host's S_OK/S_FALSE/E_INVALIDARG/DXGI_ERROR_NOT_FOUND.

Verdict: ready to merge. Additive; CreateHeap, committed resources and the protected-session refusal are unchanged. Overlaps #2590 (ID3D12Resource1/2 + ID3D12Heap1), so whichever lands second rebases the same two class declarations.

First-frame: a title that QIs Heap1/Resource1 during device setup gets S_OK instead of E_NOINTERFACE.

Raxstreams added a commit to Raxstreams/Leonida that referenced this pull request Nov 23, 2026
D3D12: expose ID3D12Heap1/ID3D12Resource1 and implement CreateHeap1 without a protected session

Independent review: ProjectLeonida#3374 (comment)

Fork integration. AI-assisted (Codex).
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.