Skip to content

d3d12: refuse a shader-visible sampler heap above 2048 samplers, as the host does - #4925

Closed
bunbeans2-arch wants to merge 1 commit into
ItsNotRexed:mainfrom
bunbeans2-arch:sampler-heap-limit
Closed

bunbeans2-arch wants to merge 1 commit into
ItsNotRexed:mainfrom
bunbeans2-arch:sampler-heap-limit

Conversation

@bunbeans2-arch

Copy link
Copy Markdown

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

What and why

ID3D12Device::CreateDescriptorHeap accepted a D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER heap with D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE and any NumDescriptors. D3D12 caps a shader-visible sampler heap at D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE (2048), the size the layer reports in OPTIONS19 and builds its bindless set for. The host runtime refuses 2049 with E_INVALIDARG; d3d12_vulkan_device_test already lists it on main:
descriptor heap: shader-visible 2049 samplers: ours 0x00000000, host 0x80070057.

Fix: refuse it with E_INVALIDARG after the existing flag and node checks (a null output still answers S_FALSE first, as on the host). A CPU-only sampler heap keeps no limit, as on the host.

Not known: whether the Xbox runtime lets a title make a shader-visible sampler heap above 2048. The layer could not hold one anyway (its bindless set is 2048 + the fallback).

Tested

Windows 11, MSVC 14.51 (VS 2026), Release, AMD Radeon RX 9070 XT, AMD Software 26.10.1 (Vulkan driver 2.0.416):

  • d3d12_descriptor_test: fails on main (98fa503) at the new 2049 case (create(limit + 1, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE) == E_INVALIDARG), passes with this change. The test's sampling shader was not built here (no glslangValidator), so its GPU sampling part did not run; it does not touch heap creation.
  • d3d12_vulkan_device_test: the 2049-sampler mismatch is gone. It still fails on mismatches main already has on this GPU (HARDWARE_PROTECTED committed texture, resource flag 0x400 on a buffer and a texture, format 67 as a render target), not touched here.
  • ctest -R d3d12: 46 of 48 pass. The other failure, d3d12_typeless_rtv (line 301, CreateCommittedResource3 of an MSAA texture with castable formats), fails the same way with main's d3d12_vulkan_device.cpp.

AI-assisted: yes (Claude Code, Claude Opus 5.5)

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. (No translator change.)

🤖 Generated with Claude Code

…he host does

CreateDescriptorHeap accepted a shader-visible SAMPLER heap of any size.
D3D12 caps it at D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE (2048), the
size the layer reports in OPTIONS19 and builds its bindless set for, and
the host runtime refuses 2049 with E_INVALIDARG. Refuse it after the
existing flag and node checks; a CPU-only sampler heap keeps no limit.

d3d12_descriptor_test now creates sampler heaps of 2048 (shader-visible,
S_OK), 2049 (shader-visible, E_INVALIDARG) and 2049 (CPU-only, S_OK).

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

Copy link
Copy Markdown
Author

Closing this: it goes the wrong way. As #4667 shows, refusing 2049 shader-visible samplers is what older host runtimes do (Windows 10 and Windows 11 23H2, which this was tested on: 10.0.22631); newer runtimes accept it, as the layer already does. Sorry for the noise.

@tupacfan04

Copy link
Copy Markdown
Contributor

Request changes: the new cap is defensible, but the host-agreement test now fails on NVIDIA.

Built Release/Ninja with MSVC 19.51 and Vulkan SDK 1.4.363 on an RTX 5070:
ctest -R "d3d12_descriptor|d3d12_vulkan_device" gives d3d12_descriptor Passed and d3d12_vulkan_device FAILED:
invalid arguments descriptor heap: shader-visible 2049 samplers: ours 0x80070057, host 0x00000000 / line 5324: argument_mismatches <= 0 (exit 1).
On current origin/main (3faac557) the same binary exits 0 with no mismatch, so main matches the host. The PR's new case on main's shim does fail at runtime/test/d3d12_descriptor_test.cpp:371, so the case bites - NVIDIA's runtime returns S_OK for 2049, unlike the AMD box.

The bindless set is 2049 including the fallback (runtime/shims/d3d12_vulkan_device.cpp:4477), so refusing is defensible, but :5062-5070 assumes every host refuses. Either gate the host-agreement case per vendor or make the test expect our cap only when the host accepts, and document the cap in docs/d3d12_vulkan.md:1765.

Not run: multi-vendor sweep.

AI-assisted review, no game files.

@bunbeans2-arch

Copy link
Copy Markdown
Author

Thanks for testing it: that matches why I closed it. Newer runtimes accept 2049 shader-visible samplers, so main is right; the old 23H2 refusal is handled by #4667.

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.

2 participants