Skip to content

Runtime: invalid-argument HRESULTs as the host runtime (D3D-49) - #558

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
omar-akermi:d3d-49-invalid-arguments
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
omar-akermi:d3d-49-invalid-arguments

Conversation

@omar-akermi

@omar-akermi omar-akermi commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D-49 (#374 (comment))

Depends on: none. Overlaps textually (small, mechanical rebases either way): #286, #291, #317, #333, #335, #367 (new DescriptorHeap(...) in CreateDescriptorHeap), #306 (CreateCommandQueue), #459 (the next compare function in d3d12_vulkan_device_test.cpp).

What and why

CreateCommittedResource, CreateDescriptorHeap, CreateCommandQueue, CreateFence and Map on the Vulkan device now return the host PC runtime's HRESULTs (no debug layer) for invalid arguments.

  • Test: compare_invalid_arguments in d3d12_vulkan_device_test runs 157 named cases (invalid descriptions and their valid neighbours, so a check can't reject too much) plus ALLOW_RENDER_TARGET/ALLOW_DEPTH_STENCIL on every DXGI format both devices create, on both devices, and compares HRESULTs. Calls that fault are caught and reported, not crashed on.
  • On main it fails: 25 mismatches in the first 55 cases, two of them access violations in the layer (a zero-width buffer, a zero-size texture array), then the process dies creating a 2049-layer texture. Main also refused zero-descriptor heaps and answered E_POINTER where the host treats a null output as a capability check.
  • Layer: committed_resource_refusal() holds the heap-property, heap-flag, resource-flag, state, format-family and clear-value rules; texture extents/mips/samples/alignment reuse allocation() (GetResourceAllocationInfo's rules). Queue, fence, descriptor-heap and Map checks are in their methods; the slot-14 proxy now forwards a null output as a capability check. CreateDescriptorHeap answers a null output before its flag, type and node rules (S_FALSE even for a shader-visible RTV heap, as @quackottu measured); committed resources and fences check their arguments first (measured here too).
  • GPU upload heaps: the layer reports OPTIONS16.GPUUploadHeapSupported FALSE, so it now refuses D3D12_HEAP_TYPE_GPU_UPLOAD, as a host without GPU upload heaps does. The test compares that case only when the host also reports no support (Resizable BAR off, as on @kotorvr's RTX 4090); on a host with them it is printed, not compared.
  • Each new refusal is logged once with its reason, so a resource the game can't get shows up in the log.
  • The comparison uses upstream's host device (LEONIDA_HOST_ADAPTER); LEONIDA_D3D49_VERBOSE=1 prints every case.
  • The measured rules and everything deliberately not compared are written up in docs/d3d12_vulkan.md §4.2.

Measured on three hosts that agree on every compared rule: RX 9070 XT, an integrated Radeon, and WARP. Answers that differ between them are left out of the hard comparison: R32G32B32 render targets, 2D textures wider than 16384, L1 custom heaps, 16x MSAA, and video formats and queues.

Not compared:

  • The host faults: a null heap-properties or descriptor-heap description, and more than 16 mips on a 16×16 texture. The RX 9070 XT runtime keeps up to 16 mips there; the layer refuses mips beyond the full chain, as allocation() already did.
  • Cross-adapter resources: the layer has no sharing.
  • Formats the host accepts that the Vulkan driver can't make: D32_FLOAT/D16_UNORM render targets and R32/R16 colour depth buffers. The sweep prints these instead of failing; only "host refuses, layer accepts" fails it, so other Vulkan drivers don't break the test.

Question for the maintainers: Xbox slot 76

Xbox texture creation (slot 76) goes through CreateCommittedResource, so these PC rules now apply to it too. If the console accepts heap or resource flags the PC runtime refuses, those resources would now fail. Nothing measured says the game passes any, and each refusal is logged with its reason. If Xbox-only bits turn up, I'd normalise them in proxy_create_resource, next to the layout word, rather than loosen the PC checks.

Sample quality

allocation() (GetResourceAllocationInfo) refuses every texture whose sample quality isn't 0. On CreateCommittedResource the host accepts a quality on a single-sampled texture and the two standard MSAA patterns (all three hosts; cases 1x quality 1, 4x MSAA quality standard/center pattern), so create_committed uses that rule and the size/mip/alignment check runs on a copy with quality 0. GetResourceAllocationInfo keeps its rule.

Also changed in an upstream test

d3d12_vulkan_device_test's slot-14 _COM_Outptr_ check used a zero-descriptor heap as its failing call. The host accepts zero descriptors, so it now uses an unknown heap flag, which fails on both.

Tested

Windows 11 Pro 26200, MSVC 14.44 (VS 2022 Build Tools), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, Ninja RelWithDebInfo.

  • Vulkan device: AMD Radeon RX 9070 XT, driver 32.0.31044.16.
  • Host D3D12 devices: the same RX 9070 XT; AMD Radeon(TM) Graphics (integrated), driver 32.0.13018.6; WARP.
  • d3d12_vulkan_device_test with LEONIDA_VK_VALIDATION=1, once per host: exit 0, every invalid-argument comparison matches, zero validation messages. All three hosts have GPU upload heaps, so the guarded case was printed, not compared, here.
  • d3d12_descriptor_test (shader built with the SDK's glslangValidator), d3d12_com_test and d3d12_uint_clear_test under validation: pass.
  • ctest: 88/88 pass. python -m compileall -q make_game.py tools tests: clean.
  • No game files used or needed.

AI-assisted (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

@MrCheese5

Copy link
Copy Markdown
Contributor

Tested 4226c5b on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: d3d12_vulkan_device_test fails on the new comparison case.

  • Clean RelWithDebInfo Ninja build, ctest --test-dir runtime/build --output-on-failure: 27/27 passed.
  • d3d12_vulkan_device_test with LEONIDA_VK_VALIDATION=1 exits 1:
    invalid arguments committed: GPU upload heap buffer: ours 0x00000000, host 0x80070057
    line 1889: argument_mismatches <= 0
    
    This machine has Resizable BAR off: the only DEVICE_LOCAL|HOST_VISIBLE heap is 214 MiB. Without it, the host runtime refuses D3D12_HEAP_TYPE_GPU_UPLOAD. The case needs a guard. Either compare it only when the host's D3D12_FEATURE_D3D12_OPTIONS16.GPUUploadHeapSupported is TRUE, or have the layer give E_INVALIDARG when it reports no GPU upload heap support. Which one depends on what the layer reports for OPTIONS16. This comes from the PR's new case; it isn't a flake.
  • d3d12_com_test, d3d12_descriptor_test, d3d12_method_variants_test, d3d12_sampler2_test, d3d12_typeless_rtv_test, vk_command_replay_test, with validation: exit 0, with 0 validation messages.
  • d3d12_clear_test exits 1 (format 28 case 0 byte 2: Vulkan 7f, WARP 80). That isn't this PR: it's the test Runtime: SNORM/SINT render targets and clear conversion (D3D-45) #525 put on main, and it fails the same way on every branch based on current main on this GPU. NVIDIA's clear writes 127 for 0.5 on 8-bit UNORM, where D3D rounds to 128. Runtime: clears match WARP on every format class: tie rounding, and the SNORM/SINT/R8/R16 formats (D3D-45) #521 fixes it.

No game files used. AI-assisted run (Claude Code).

@VeTkN

VeTkN commented Nov 22, 2026

Copy link
Copy Markdown

Tested 4226c5b on RTX 5070 (Blackwell), NVIDIA 621.01, Windows 11 Pro (10.0.26200), MSVC 19.51 (VS 2026 Build Tools), with Resizable BAR on: pass.

BAR1 total:  16384 MiB (VRAM 12227 MiB), so Resizable BAR is enabled
d3d12_vulkan_device_test, LEONIDA_VK_VALIDATION=1: exit 0, 0 VUID messages
ctest --test-dir runtime/build: 27/27 passed

This is the other side of the RTX 4090 result above: with Resizable BAR on, the GPU upload heap case matches the host and the whole test passes. That supports guarding the case on the host's GPUUploadHeapSupported (or the layer's OPTIONS16 answer) rather than a real mismatch in the layer.

The run also printed six notes, not failures: formats 40, 54 and 55 (RT/DS) and 41, 42, 43 (DS), "the host accepts it, this Vulkan driver can't". No game files.

AI-assisted (Claude)

@matheuskshn

Copy link
Copy Markdown
Contributor

Code review at 4226c5b following the two Resizable BAR reports. I checked the head: it accepts GPU_UPLOAD in the heap-type range check, but CheckFeatureSupport has no OPTIONS16 case. For the existing oracle, query the host capability and check this argument separately. Otherwise the test treats a capability difference as a mismatch in invalid-argument behavior. AI-assisted code review.

@omar-akermi
omar-akermi force-pushed the d3d-49-invalid-arguments branch from 4226c5b to a6639b8 Compare November 22, 2026 03:11

@quackottu quackottu 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 a6639b8 on NVIDIA GeForce RTX 5070, driver 621.24, Windows 11 Pro (26300), VS 2022 Build Tools, Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1 and LEONIDA_D3D12=vulkan: pass

  • ctest -C RelWithDebInfo: 97% tests passed, 1 tests failed out of 31
  • d3d12_vulkan_device_test (changed here): exit=1 validation=0 | 10 validation errors
  • 30 test programs in the build pass with 0 validation errors
  • d3d12_clear_test fails (format 28 case 0 byte 2: Vulkan 7f, WARP 80) exactly as on main 67204bf, so not from this PR: NVIDIA rounds a 0.5 UNORM clear to 0x7f, which #521 addresses
  • d3d12_vulkan_device_test reports 10 synchronization-validation WRITE_AFTER_WRITE hazards on back-to-back copies (so ctest's d3d12_vulkan_device fails). main 8df277f shows the same 10 here, so not from this PR: it's @guimsolutions's finding in #634, which #782 addresses

Implicit Vulkan layers (overlays) were off through an empty VK_IMPLICIT_LAYER_PATH.

@quackottu

Copy link
Copy Markdown
Contributor

One more pair for this PR, if you want it. On main 43d4703 (runtime/shims/d3d12_xs_device.cpp), two Xbox device slots also start with if (!out) return E_POINTER;:

  • slot 62, proxy_create_compute_pipeline_state (line 365);
  • slot 76, proxy_create_resource (line 376).

Measured on this machine, the host answers S_FALSE for a null output on both. I tried CreateComputePipelineState with an empty root signature and a trivial cs_5_0, and CreateCommittedResource with a 256-byte buffer, on WARP and on an RTX 5070. That is the same capability-check rule this PR applies to slot 14.

Deleting the two lines gives S_FALSE on both slots, and a call with an output still works. A device_proxy_test case next to the slot-76 buffer check would cover it. I can send it as a separate PR instead if you would rather keep this one as it is.

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

One ordering detail in CreateDescriptorHeap, measured on Windows D3D12 (RTX 5070 driver 621.24, and WARP; no debug layer):

desc output host this PR
RTV heap, SHADER_VISIBLE null S_FALSE E_INVALIDARG
RTV heap, SHADER_VISIBLE non-null E_INVALIDARG E_INVALIDARG

The host answers a null output (the capability check) before it applies the flag/type rules. Moving if (!out) return ... S_FALSE; above the flags check matches both devices. Everything else I compared (DSV + SHADER_VISIBLE, flag 0x4, NodeMask 2, a 2049-entry shader-visible sampler heap) matches your table.

CreateCommittedResource, CreateDescriptorHeap, CreateCommandQueue, CreateFence
and Map now return the host PC runtime's HRESULTs for invalid arguments.
compare_invalid_arguments in d3d12_vulkan_device_test checks the invalid
descriptions and their valid neighbours, plus ALLOW_RENDER_TARGET and
ALLOW_DEPTH_STENCIL on every format both devices create, against the host
device.

On main the new test found 25 mismatches in its first 55 cases (invalid
heap properties and flags, buffer layouts, upload/readback states, clear
values and texture flags accepted; two access violations, on a zero-width
buffer and a zero-size texture array), then the process died creating a
2049-layer texture. main also refused zero-descriptor heaps and answered
E_POINTER where the host treats a null output as a capability check.

CreateDescriptorHeap answers a null output before its flag, type and node
rules, as the host does; committed resources and fences check their
arguments first. A GPU_UPLOAD heap is refused, matching the layer's
OPTIONS16.GPUUploadHeapSupported FALSE; the test compares that case only on
a host without GPU upload heaps (Resizable BAR off).

CreateCommittedResource accepts a sample quality on a single-sampled texture
and the two standard MSAA patterns, as the host does.

The flag and format rules were measured on an RX 9070 XT, an integrated Radeon
GPU and WARP. Answers that differ between them, or that the layer can't follow,
are not compared and are listed in docs/d3d12_vulkan.md. Each new refusal is
logged once with its reason.

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

Copy link
Copy Markdown
Contributor Author

Thanks for testing and reviewing. Rebased onto 99f9989 (squashed into one commit, cb33e81), with both findings fixed:

  • GPU upload heaps (@kotorvr, @VeTkN, @matheuskshn): main now has the layer report OPTIONS16.GPUUploadHeapSupported FALSE, so the layer refuses D3D12_HEAP_TYPE_GPU_UPLOAD to match that answer, as a host without GPU upload heaps does. The test compares the case only when the host's OPTIONS16 also says FALSE; with Resizable BAR on it's printed, not compared. All three of my hosts have GPU upload heaps, so the compared branch is only exercised on a machine like the RTX 4090 one.
  • CreateDescriptorHeap ordering (@quackottu): a null output now answers S_FALSE before the flag, type and node rules. I added cases for a shader-visible RTV heap, flag 0x80 and node mask 2 with a null output (host S_FALSE on all three), and the same for committed resources and fences, where the host checks the arguments first (E_INVALIDARG). The layer matches all of them.
  • Slots 62 and 76 (@quackottu): please go ahead with the separate PR, it's the same rule and fits better on its own.

Retested on the RX 9070 XT, the integrated Radeon and WARP as hosts: d3d12_vulkan_device_test with LEONIDA_VK_VALIDATION=1 exits 0 with zero validation messages on each, and ctest passes 88/88. One upstream check changed: the slot-14 _COM_Outptr_ case used a zero-descriptor heap as its failing call, which the host accepts, so it now uses an unknown flag.

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.

6 participants