Skip to content

d3d12: a CPU-only descriptor heap too large to allocate is E_OUTOFMEMORY, not a throw - #7950

Closed
nullmarsh wants to merge 4 commits into
ProjectLeonida:mainfrom
nullmarsh:descheap-oom
Closed

nullmarsh wants to merge 4 commits into
ProjectLeonida:mainfrom
nullmarsh:descheap-oom

Conversation

@nullmarsh

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #7694 (comment) (tedin7's released item: #7496 (comment))

Depends on: none. It may conflict textually with #5582, which edits the same DescriptorHeap class; whichever lands second rebases.

What and why

CreateDescriptorHeap with a CPU-only heap (RTV, DSV, or a CBV/SRV/UAV heap that is not shader-visible) of 0xFFFFFFFF descriptors threw std::bad_alloc out of the DescriptorHeap constructor's new std::byte[]. That's 128 GiB of host memory at 32 bytes per descriptor. The allocation is now new (std::nothrow); a failed one leaves ok() false, so the existing path returns E_OUTOFMEMORY.

The test checks that the layer returns (E_OUTOFMEMORY or S_OK) for the three heap types. It doesn't compare with the host, because the host's answer depends on the driver:

  • the native runtime on an RX 9060 XT gives E_OUTOFMEMORY for all three;
  • WARP gives E_OUTOFMEMORY for RTV and S_OK for DSV and CBV/SRV/UAV.

The check is skipped under Wine, whose allocator can hand out that much address space, which the heap's zero fill would then touch.

Tested

RX 9060 XT (RDNA4), AMD 26.11.2, Windows 11 26200, MSVC 14.44 RelWithDebInfo, d3d12_vulkan_device_test:

  • With this change the three calls return, and the new check passes with the native host and with LEONIDA_HOST_ADAPTER=warp. The test then stops at the later EXPECT(tiles == 1) in the reserved-resource block, which is where main 8575d36e stops on this card too (TEST-1649, d3d12_vulkan_device: check PC CreateReservedResource2 behind the Xbox proxy, not through slot 78 #7125).
  • Negative control (main's d3d12_vulkan_device.cpp, new check kept): CreateDescriptorHeap of 0xFFFFFFFF CPU-only descriptors: 0xc0000005 (the guarded call caught the throw), and the check fails.

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

nullmarsh and others added 2 commits November 23, 2026 12:43
…ORY, not a throw

CreateDescriptorHeap with a CPU-only heap (RTV, DSV or non-shader-visible
CBV/SRV/UAV) of 0xFFFFFFFF descriptors threw std::bad_alloc out of the
DescriptorHeap constructor's `new std::byte[]`, where the host runtime returns
E_OUTOFMEMORY. Allocate with std::nothrow and let the existing ok() path
answer E_OUTOFMEMORY.

compare_invalid_arguments gains the three cases. On an RX 9060 XT (AMD
26.11.2, Windows 11) against the native D3D12 host they fault on main and
match the host with this change, in two runs. A CPU-only sampler heap of that
size is left out: the host answered E_OUTOFMEMORY in one run and S_OK in the
next. Found by tedin7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ost's answer

The host's answer for a CPU-only heap of 0xFFFFFFFF descriptors depends on the
driver: the native runtime on an RX 9060 XT gives E_OUTOFMEMORY for RTV, DSV
and CBV/SRV/UAV, WARP gives E_OUTOFMEMORY for RTV and S_OK for DSV and
CBV/SRV/UAV. So the three cases leave compare_invalid_arguments and become a
check that the layer's CreateDescriptorHeap returns E_OUTOFMEMORY or S_OK
instead of throwing, skipped under Wine (its allocator can hand out the 128
GiB, which the zero fill would touch). The log line gives the size in MiB.

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

@al3xar al3xar 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 fb6c78fe2 on NVIDIA GeForce RTX 3060, driver 621.24 (Vulkan 1.4.357), Windows 11 x64, MSVC 19.44.35230.0, CMake + Ninja RelWithDebInfo (no game files): pass on the new checks.

  • Merges cleanly onto upstream/main (dde82f27e).
  • Built d3d12_vulkan_device_test cleanly with no new warnings in the modified lines.
  • PR head (fb6c78fe2): logs [rt] d3d12: descriptor heap too large for host memory; MiB: 131071, passes all three 0xFFFFFFFF CPU-only descriptor heap checks (RTV, DSV, CBV/SRV/UAV) at line 5562, and continues to the pre-existing main failure at line 6595: tiles == 1 (same as main's line 6564: tiles == 1, #7125).
  • Negative control (runtime/shims/d3d12_vulkan_device.cpp reverted to upstream/main, PR test kept): fails at the new check as expected (CreateDescriptorHeap of 0xFFFFFFFF CPU-only descriptors: 0xc0000005, line 5562: hr == E_OUTOFMEMORY || hr == S_OK, exit 1).
  • python -I scripts/check_no_game_data.py runtime/shims/d3d12_vulkan_device.cpp runtime/test/d3d12_vulkan_device_test.cpp: clean (exit 0).
  • Diff review: new (std::nothrow) + early return leaves cpu_ == nullptr and in_arena_ == false, so ok() is false and CreateDescriptorHeap returns E_OUTOFMEMORY cleanly without throwing.

AI-assisted.

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

The 128 GiB CPU-only storage fix is correct: new (std::nothrow) std::byte[...]() leaves cpu_ == nullptr/in_arena_ == false, ok() is false, and CreateDescriptorHeap returns E_OUTOFMEMORY with normal teardown. Local RTX 5070 checks pass for RTV/DSV/CBV-SRV-UAV; the later line 6595: tiles == 1 exit is the pre-existing main failure noted in the PR.

One residual throw in the same API: runtime/shims/d3d12_vulkan_device.cpp:5691 still allocates the small DescriptorHeap object with the throwing form:

auto* heap = new DescriptorHeap(state_, *desc);

If that object allocation fails under OOM, std::bad_alloc escapes instead of E_OUTOFMEMORY. The new test only drives the large storage_ allocation, so it does not cover this path.

Minimal fix: new (std::nothrow) DescriptorHeap(...), return E_OUTOFMEMORY when null, and only then call attach_device; add a synthetic object-allocation failure if the test harness can inject it. Low severity relative to the 128 GiB-storage defect, but it is the remaining throw in the same method. Synthetic only; no game files. AI-assisted (OpenCode).

@ikurta92-png

Copy link
Copy Markdown

Tested fb6c78fe2 on NVIDIA GeForce RTX 3060 (Ampere), driver 617.42, Windows 11 Pro 10.0.26300, MSVC 19.51 (VS 2026), RelWithDebInfo, 32 GB RAM / 35 GB commit limit: pass, plus the native NVIDIA answer for the description's table.

  • This PR: d3d12_vulkan_device_test gets past the new block (the layer logs descriptor heap too large for host memory; MiB: 131071) and then stops at the existing tiles == 1 line that d3d12_vulkan_device: check PC CreateReservedResource2 behind the Xbox proxy, not through slot 78 #7125 fixes (6595 at this base), which comes after it. No page-file growth or free-space change on the system drive during the run.
  • Control (this test file, d3d12_vulkan_device.cpp from the base dde82f27e): the new check fails, line 5562: hr == E_OUTOFMEMORY || hr == S_OK, so the bad_alloc path is caught by the test on native Windows too.
  • Native drivers (a small standalone probe, CreateDescriptorHeap with 0xFFFFFFFF descriptors and FLAG_NONE, 2 runs each, device not removed afterwards):
Host RTV DSV CBV/SRV/UAV (not shader-visible)
NVIDIA RTX 3060, 617.42 E_OUTOFMEMORY S_OK S_OK
WARP (same machine) E_OUTOFMEMORY S_OK S_OK
RX 9060 XT (from the description) E_OUTOFMEMORY E_OUTOFMEMORY E_OUTOFMEMORY

So NVIDIA answers like WARP, not like the AMD runtime, which supports holding the layer to "returns an HRESULT" rather than to one host.

AI-assisted (Claude Code). Synthetic test only, no game files.

…g too

tupacfan04's review: the DescriptorHeap object itself still came from a
throwing `new`, the last way std::bad_alloc could leave CreateDescriptorHeap.
It is `new (std::nothrow)` now, with E_OUTOFMEMORY when it fails. Not driven
by a test: the harness can't make a small allocation fail.

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

Copy link
Copy Markdown
Contributor Author

@tupacfan04: done in a428f315. The heap object is new (std::nothrow) DescriptorHeap(...) now, and CreateDescriptorHeap returns E_OUTOFMEMORY before attach_device if it fails. It isn't driven by a test, since the harness can't make a small allocation fail. Re-run on the RX 9060 XT: the three 0xFFFFFFFF checks pass and the test again stops at the pre-existing tiles == 1.

@ikurta92-png: thanks for the NVIDIA column. With the native NVIDIA driver answering like WARP, holding the layer to "returns an HRESULT" was the right call.

AI-assisted (Claude Code), no game files.

@h0useadv

Copy link
Copy Markdown

Tested a428f315a (based on main dde82f27e) on AMD Radeon RX 9070 XT (RDNA4), AMD Windows driver 32.0.32029.2010, Windows 11 Pro build 26300: pass, no new failures. Built with clang-cl 23.1.6 + lld-link against an xwin splat (MSVC 14.44, SDK 10.0.26100), RelWithDebInfo; synthetic, no game files.

  • The new 0xFFFFFFFF CPU-only heap check (RTV, DSV, CBV/SRV/UAV) passes: no CreateDescriptorHeap of 0xFFFFFFFF ... line and no EXPECT failure from that block; no bad_alloc escaped.
  • d3d12_vulkan_device as a whole still fails on this GPU, only at line 6595: tiles == 1: the same reserved-resource tiling failure as on main (line 6574 there, shifted by the 21 added lines), already reported for the RX 9070 XT in GPU test results (one comment per GPU and driver) #166.
  • Full ctest -j8, failures rerun with -j1: 262/268; the 6 that fail are the same 6 as on main dde82f27e on this GPU.

AI-assisted (Claude Code).

@Envyre

Envyre commented Nov 23, 2026

Copy link
Copy Markdown

Checked native D3D12 on an RTX 4070 Ti SUPER (driver 621.14, Windows 11; standalone program outside the repo). No size ever returned E_INVALIDARG:

  • RTV, 0xFFFFFFFF (32 B each, 128 GiB): E_OUTOFMEMORY, *ppvHeap null, every run
  • DSV, 0xFFFFFFFF (8 B each, 32 GiB): S_OK
  • RTV, 0x80000000: E_OUTOFMEMORY in one run, S_OK in a later one after the page file grew
  • RTV/DSV, 100M: S_OK
  • non-visible CBV/SRV/UAV, 0xFFFFFFFF: hadn't returned after ~3 min with ~67 GB committed (killed)

So the native answer depends on the commit limit, and holding the layer to "E_OUTOFMEMORY or S_OK" (d3d12_vulkan_device_test.cpp:5562) fits. The failure path checks out: *out nulled at :5679, the constructor leaves nothing half-built (:1666-1671), Release() at :5694, and the size math is 64-bit (:1654); the old code's throw would have failed the guarded EXPECT.

Non-blocking: the value-initialising new (std::nothrow) std::byte[n]() at :1666 touches every page; here a nothrow operator new[] of 64 GiB succeeded, so a heap that does get allocated pages through all of it instead of failing fast, and the 0xFFFFFFFF case can hang on any host whose commit limit exceeds 128 GiB (not only Wine). calloc / VirtualAlloc (fresh pages come zeroed) would avoid that.

AI-assisted (Claude Code).

Value-initialising new std::byte[n]() writes every page, so a huge heap that
does get allocated is zeroed page by page instead of failing fast. calloc
gets zeroed pages from the OS (Envyre's review).

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

Copy link
Copy Markdown
Contributor Author

@Envyre good catch, done in 5a8898ad: the host-memory heap now comes from calloc (at least one byte, with a free deleter), so fresh pages arrive zeroed instead of being written one by one. Re-run on the RX 9060 XT: the 0xFFFFFFFF RTV heap still takes the E_OUTOFMEMORY path, the three checks pass, and the whole test takes 11 s before stopping at the pre-existing tiles == 1.

AI-assisted (Claude Code), no game files.

@milas6669

Copy link
Copy Markdown

Checked head 5a8898ad5 merged onto main 867d922f0 (clean, 2 files, +37/-3). Windows 11 26200, MSVC 19.44 RelWithDebInfo, RTX 3070 (Ampere, 621.24), 31.9 GiB RAM, LEONIDA_VK_VALIDATION=1. The only earlier check is an RX 9060 XT.

  • d3d12_vulkan_device_test exits 1 on this card both with and without this PR (the known red test on main, not from this change), so I checked that the new block is really executed: the run prints [rt] d3d12: descriptor heap too large for host memory; MiB: 131071 (the layer's own new log line for the 0xFFFFFFFF heap, 128 GiB) and none of the three CreateDescriptorHeap of 0xFFFFFFFF CPU-only descriptors: 0x... failure lines.
  • Negative control, only runtime/shims/d3d12_vulkan_device.cpp put back to main's with this PR's test kept: the same run prints CreateDescriptorHeap of 0xFFFFFFFF CPU-only descriptors: 0xc0000005, so the new test catches the old behaviour here too.
  • Standalone check of the allocation itself on this machine (11.0 GiB of free commit): calloc of 1, 16 and 64 GiB returns non-null, calloc(128 GiB) returns null, and new std::byte[128 GiB]() throws std::bad_alloc, which is what escaped before. So the layer answers E_OUTOFMEMORY here for the 128 GiB heap, and a machine with more commit headroom could return S_OK for the same call (the PR's test accepts both).

No defect. No game data. AI-assisted (Claude Code).

@o-psi

o-psi commented Nov 23, 2026

Copy link
Copy Markdown

Thanks for this fix. Cleanup review for #8919 found the final calloc/free and nothrow-object changes plus the huge-heap regression still absent from main 6312c05, with complementary work in #5582 and #8930. The exact-head independent record by milas6669 supports a merge-ready nomination: #7950 (comment). Please retain both allocation paths and all three cases when integrating. Coordination: #8919. agent: yes

PR cleanup: #8919 (comment)

agent: yes

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.

9 participants