Skip to content

d3d12: GetResourceAllocationInfo follows the PC runtime's 4 KiB, totals and flag rules - #1204

Merged
ItsNotRexed merged 1 commit into
ProjectLeonida:mainfrom
quackottu:allocation-info-host-rules
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ProjectLeonida:mainfrom
quackottu:allocation-info-host-rules

Conversation

@quackottu

Copy link
Copy Markdown
Contributor

GetResourceAllocationInfo disagreed with the PC runtime in three ways. Each one is measured against the host D3D12 runtime on an RTX 5070 (621.24) and on WARP in compare_allocation_info (d3d12_vulkan_device_test), and the two hosts agree on every case.

  1. 4 KiB alignment (D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT). The host allows it when at most 16 tiles of 4 KiB cover the top mip of one array slice. Mips and array slices don't count, but a volume's depth does. We tested whether the whole resource fit in 64 KiB, so we wrongly refused full mip chains, arrays, 1D 16384 and small volumes, and accepted a 100x100 volume (49 tiles) that the host refuses. A byte rule doesn't match either: 33x480 RGBA8 (63,360 bytes, 30 tiles) is refused by the host.
    • The tile shapes per element size are the new leonida::small_tile_shape() in runtime/src/resource_tiling.h, pinned with exactly-16-tile and one-more-texel cases.
    • BC formats are counted in blocks, and 1D textures count 4096 bytes of the row.
    • 3- and 12-byte formats keep the old rule, marked shortcut:.
  2. Totals over several resources (place()):
    • the total is rounded up to the largest alignment;
    • it saturates at the last multiple of that alignment instead of wrapping to 0;
    • an empty query returns {0, 1} instead of alignment 0, which would make a caller's align-up divide by zero.
  3. Refused descriptions: ALLOW_SIMULTANEOUS_ACCESS with depth-stencil or MSAA, and a depth-stencil volume.
case main host (RTX 5070 and WARP)
128x128 RGBA8 full chain, 4 KiB refused 90112 / 4096
64x64 array of 8, 4 KiB refused 131072 / 4096
R8 32x32x64 volume, 4 KiB refused 4096-aligned
100x100x1 volume, 4 KiB (49 tiles) 49152 / 4096 refused
{buffer 300, 16x16 4 KiB texture} 69632 131072 / 65536
{4x MSAA 64x64, buffer} 4259840 8388608 / 4 MiB
two 2^63 buffers 0 0xFFFFFFFFFFFF0000 / 65536
no resources 0 / 0 0 / 1
depth + simultaneous access; MSAA + simultaneous access; D32 volume accepted refused

Test: compare_allocation_info gets these cases plus the exact-16-tile/one-more boundaries for every element size. With main's d3d12_vulkan_device.cpp and resource_tiling.h: 17 mismatches against the host, on both the default adapter and LEONIDA_HOST_ADAPTER=warp. With this change: 0 on both. Full ctest with LEONIDA_VK_VALIDATION=1 and LEONIDA_D3D12=vulkan: 56/56.

Resource creation is unchanged: CreateCommittedResource doesn't use this path, and CreatePlacedResource isn't implemented on main. A follow-up could make CreateCommittedResource refuse the three flag combinations too; #558 (D3D-49) is adding the creation-side rules.

AI-assisted.

…ls and flag rules

4 KiB alignment now counts the 4 KiB tiles covering the top mip of one
slice (at most 16; a volume's depth counts), instead of fitting the whole
image in 64 KiB. Multi-resource totals round up to the largest alignment,
saturate instead of wrapping, and an empty query is {0, 1}. Simultaneous
access with depth-stencil or MSAA, and a depth-stencil volume, are refused.
All measured against the host runtime on an RTX 5070 and WARP.
@dcastell1

Copy link
Copy Markdown
Contributor

Tested 15aa49c on an RTX 5090 (Blackwell), Windows 11 Pro 10.0.26300.9974, NVIDIA 621.24, MSVC 19.44, clean RelWithDebInfo Ninja build:

  • d3d12_vulkan_device_test: exit 0, LEONIDA_VK_VALIDATION=1 with the 1.4.363 layer, 0 VUID-/validation errors.
  • The full device test matches: clears, uploads, texture/buffer/BC copies, resolve, reserved resources, queries, GetCopyableFootprints, GetResourceTiling, and the MSAA quality and allocation-info comparisons.
  • New GetResourceAllocationInfo rules (4 KiB alignment, totals and flag handling) match the host D3D12 runtime on this GPU.

No game files were used.

@kapitche

Copy link
Copy Markdown
Collaborator

Tested 15aa49c on Windows 11 with two GPUs on one machine (MSVC 14.51): pass.

@marquezinii

Copy link
Copy Markdown
Contributor

Tested 15aa49c on NVIDIA GeForce RTX 5070, driver 621.24 (32.0.16.2124), Windows 11 26H2 (26300), MSVC 14.52 (VS Build Tools 18), Ninja, RelWithDebInfo, under validation (VK_LAYER_KHRONOS_validation from Vulkan-ValidationLayers main, LEONIDA_VK_VALIDATION=1): pass.

  • ctest --test-dir runtime/build -C RelWithDebInfo: 56/56 passed, including d3d12_vulkan_device with its host-comparison block (gameinput disabled, no SDL3). No validation errors.
  • Build clean, 0 warnings.

@undeadhuman37

Copy link
Copy Markdown
Contributor

Tested 15aa49c on NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11 Home 25H2 (26200.9974), VS 2022 Build Tools, Vulkan SDK 1.4.363.1: pass.

  • Build: 0 warnings. ctest: 57/57 passed.
  • d3d12_vulkan_device_test: all matched, including GetCopyableFootprints and GetResourceTiling, exit 0, also with LEONIDA_VK_VALIDATION=1 and 0 validation errors.

AI-assisted. No game files.

@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 15aa49c on AMD Radeon RX 9070 (RDNA4), AMD 26.11.2 + WARP, Windows 11 Pro 26300, MSVC 14.44: pass. The allocation rules now have an AMD host behind them as well.

d3d12_vulkan_device_test
this PR exit 0; 38 allocation info cases, ours = host on every one
control: merge-base (2e5c0f2) d3d12_vulkan_device.cpp + resource_tiling.h, this PR's test exit 1; the small-placement cases (full chains, arrays, the volumes) come back ours size 18446744073709551615 alignment 65536 where the host gives 4096-aligned sizes, simultaneous access with depth and with 4x MSAA is accepted where the host refuses, and two 2^63 buffers: ours size 0 vs host 18446744073709486080

One difference between the vendors, for the record: AMD's runtime sizes 128x128 full chain small at 131072 / 4096. Your table has 90112 on the RTX 5070. The layer matched the host on this card too, so whatever it derives from the device handles that. 64x64 array of 8 is 131072 on both.

AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit 9055393 into ProjectLeonida:main Nov 22, 2026
11 checks passed
ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
… 2^64; ours stays saturated

compare_allocation_info required the host's answer for two totals that
overflow 2^64 (two 2^63 buffers; the largest buffer plus one). WARP and
the hosts of #1204 saturate at 0xFFFFFFFFFFFF0000, but the Intel Raptor
Lake-S (101.7092) and RTX 5060 Laptop (621.24) hosts on Windows
26300.9974 (D3D12Core 10.0.26100.9818) wrap, to 0 and 65536, while WARP
on the same PC saturates. d3d12_vulkan_device_test failed there on both
GPUs.

Ours is now pinned to the saturated answer, which can't make a caller
allocate less than one of its resources. A host whose total is below its
largest resource has wrapped and is reported, not compared. Any other
host answer is still a mismatch.
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.

7 participants