Skip to content

d3d12: GetCopyableFootprints aligns from BaseOffset - #2498

Open
iasmitionsalvatore wants to merge 1 commit into
ItsNotRexed:mainfrom
iasmitionsalvatore:pr/footprint-base-offset
Open

iasmitionsalvatore wants to merge 1 commit into
ItsNotRexed:mainfrom
iasmitionsalvatore:pr/footprint-base-offset

Conversation

@iasmitionsalvatore

@iasmitionsalvatore iasmitionsalvatore commented Nov 22, 2026 •

Copy link
Copy Markdown

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

What and why

Problem. GetCopyableFootprints returns the wrong offsets and total when BaseOffset is not a multiple of D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT (512). Against the PC runtime on an RX 7600:

base 513, R8G8B8A8_UNORM 8x6x16 volume, 5 mips subresource 0 subresource 1 subresource 2 total
host (PC runtime) 513 25089 31233 32260
layer on main 1024 25600 31744 32771
layer with this PR 513 25089 31233 32260

An application that sizes an upload buffer from the total and writes at the returned offsets writes past its allocation whenever the base is not a multiple of 512.

Cause. The layout started at BaseOffset, and every subresource was aligned to 512 as an absolute address. The PC runtime lays the subresources out from 0 and then adds the base, so the whole layout moves by the base and the total does not depend on it. Offsets wrap past 2^64, as the host's do.

Fix. Lay out from 0, add base to each Offset, and return the total without the base. GetCopyableFootprints1 wraps the same function and needs no separate change. compare_footprints now also runs bases 513 and 2^32 + 1 next to 0 and 1024: with only 0 and 1024, the old code passes, which is why this went unnoticed. docs/d3d12_vulkan.md records the rule.

Scope change since the first version. This PR is now one commit.

Tested (this version)

AMD Radeon RX 7600 (gfx1102, 8 GB), driver 26.11.2 (LLPC, Vulkan 1.4.359), Windows 10 22H2 (in-box d3d12core 10.0.19041), Ryzen 5 5600, MSVC 14.44, RelWithDebInfo. main 561b65a8 against this branch on the same machine and in the same build tree. The "before" build only reverts the runtime hunk.

  • compare_footprints: 652 mismatching fields before, 0 after. On main, with only bases 0 and 1024, it passes with the same runtime, so all 652 are at the two unaligned bases.

  • Local comparison program (described below): 5140 of 6204 calls differ from the host before, 0 after, also with LEONIDA_VK_VALIDATION=1. Every texture case differs at 514 of 517 bases before; the buffer never does. At UINT64_MAX - 255, before gives 0, 6144 and the host gives 18446744073709551360, 5888; after gives the host's values.

  • Runtime tests that call GetCopyableFootprints, with and without validation:

    • d3d12_vulkan_device gets past compare_footprints.
    • The 20 others give 19/20 on main and on this branch alike. The one failure, d3d12_clear, is the WARP host lacking ID3D12Device10 on Windows 10.
  • Local comparison program (not part of this PR):

    • It calls GetCopyableFootprints and GetCopyableFootprints1 on our device and on the native D3D12 device.
    • Bases: every residue 0..511 at 2^48 + r, as @duudiis ran, plus 0, 513, 1024, 2^32 + 1 and UINT64_MAX - 255.
    • Cases: an RGBA8 volume, a BC1 2D array, a two-plane D24S8 array, an RGBA16F 2D texture with mips, and a buffer.
    • It compares Offset, Format, Width, Height, Depth, RowPitch, NumRows, RowSizeInBytes and TotalBytes.

Not changed by this PR, and known. On a Windows 10 host, d3d12_vulkan_device_test on main stops in compare_invalid_arguments on cases that have nothing to do with this PR:

  • a buffer in state 0x80000000;
  • a buffer in RENDER_TARGET | UNORDERED_ACCESS;
  • an R9G9B9E5 render target.

compare_footprints runs before that, so it runs here. On Windows 11 23H2, the +device10 gates of HARDWARE_PROTECTED, resource flag 0x400 and the 2049-sampler heap are not enough, as @CharlyRien reported. Those cases are on main and are not touched here.

Reviews of the previous head (750cf45, on older main)

Thank you, everyone who tested the first version. These results are for 750cf457, not this rebased commit. The runtime change is identical.

Reviewer Setup Result
@duudiis RTX 5070, Windows 11 26300 Swept all 512 residues at 2^48 + r and UINT64_MAX - 255 through both methods: 513/513 match the host. With the runtime hunk reverted, 512/513 differ.
@towade RX 9070 XT, Windows 11 26H2, Vulkan validation Passes. With the old runtime: 1024 vs 513 at base 513.
@FaKL-Code RTX 4060 Ti, Windows 11 26200 116/116, no new warnings.
@JRamos1993 RTX 5090, Windows 11 125/125. d3d12_vulkan_device 20/20, 0 validation messages.
@marquezinii RTX 5070, Windows 11 26H2, validation 116/116.
@CharlyRien RTX 3090, Windows 11 23H2 Footprints fine. The failures were the +device10 gates above, which are outside this PR.

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

🤖 Generated with Claude Code

@duudiis

duudiis commented Nov 22, 2026

Copy link
Copy Markdown

Independent Windows 11 build 26300 / RTX 5070 / driver 621.24 check of 750cf45. The stock d3d12_vulkan_device CTest passed against native NVIDIA D3D12. I used the local #2453 compatibility patch to build with SDK 10.0.26100.0.

I added a temporary comparison for the same 8×6×16 RGBA8 volume, asking for three subresources starting at index 1. For each of GetCopyableFootprints and GetCopyableFootprints1 (Device8), I swept all 512 offsets at 2^48 + residue, plus UINT64_MAX - 255. I compared offsets, dimensions, format, row pitches, row counts, row sizes and total bytes against the host. All 513 cases matched for both methods. At the wrap boundary both native and patched calls returned a first offset of 18446744073709551360 and a second offset of 5888.

Reversing only the footprint implementation hunk left the same test running and produced 512/513 mismatches per method. Only residue zero matched. The CTest then failed at the expected footprint gate. I restored the temporary compatibility, probe, and reversal changes. Synthetic descriptors only. AI-assisted review.

@MeNoSkills

Copy link
Copy Markdown
Contributor

Heads-up on overlap: the second commit here (the A4B4G4R4 / new_format_round_trips host comparison on a Windows 10 host) is the same test-only change as #2438, which I claimed at #2300 (comment) and opened earlier. Mine compares with the host only when CheckFeatureSupport(FORMAT_SUPPORT) succeeds and reports TEXTURE2D, so it also covers the E_INVALIDARG answer you describe, and a host that reports the format and still refuses it keeps failing. Suggestion: keep this PR to the GetCopyableFootprints fix and add Depends on: #2438, or drop that commit if #2438 lands first. Your GetCopyableFootprints base-offset finding looks separate and useful; I have not tested it. AI-assisted (Claude Code).

@towade

towade commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 750cf457 on Windows 11 26H2 (26300.10075), MSVC 19.44 Release, Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.0, AMD Radeon RX 9070 XT (driver 32.0.32029.2010): pass.

ctest -R '^d3d12_vulkan_device$' passed with Vulkan validation enabled, including the native D3D12 comparisons at unaligned BaseOffset values.

In a separate build I kept the PR tests and restored the old runtime implementation. The footprint comparison failed as expected: for the first subresource of the 8×6×16 R8G8B8A8_UNORM texture with BaseOffset=513, the old layer returned 1024, while native D3D12 returned 513.

Synthetic tests only. AI-assisted (Codex).

@CharlyRien

Copy link
Copy Markdown

Tested 750cf45 (merged on current main) on RTX 3090, driver 616.56, Windows 11 23H2 (22631, in-box d3d12.dll 10.0.22621.5415): fail. This is the NVIDIA/older-Windows-11 data point the PR's limitations mention. MSVC 19.44 / Ninja, Vulkan SDK 1.4.363.

What the gates fix here: new_format_round_trips now reports A4B4G4R4 render target not reported, skipped, 0 failures, and GetResourceTiling cases 2, 6 and 8 are skipped because the host refuses them. FORMAT_INFO, CheckFeatureSupport (37 queries) and FORMAT_SUPPORT (93 formats) show 0 mismatches.

What still fails: d3d12_vulkan_device stops at line 4244: argument_mismatches <= 0 on four cases where this runtime refuses and the layer accepts:

invalid arguments committed: heap flag HARDWARE_PROTECTED on a texture: ours 0x00000000, host 0x80070057
invalid arguments committed: resource flag 0x400 on a buffer: ours 0x00000000, host 0x80070057
invalid arguments committed: resource flag 0x400 on a texture: ours 0x00000000, host 0x80070057
invalid arguments descriptor heap: shader-visible 2049 samplers: ours 0x00000000, host 0x80070057
  • HARDWARE_PROTECTED is gated by +device10, but the 23H2 runtime does expose ID3D12Device10 and still refuses the flag, so that gate isn't enough here.
  • resource flag 0x400 and the 2049-sampler heap have no gate. The first is probably a flag the 22621 runtime doesn't know.
  • The 2049-sampler case may be worth checking against the spec rather than only gated. 2048 is the documented shader-visible sampler heap limit, so the layer accepting 2049 could be a real difference, not just a runtime-version one.

The format NN RT/DS: the host accepts it, this Vulkan driver can't lines (40–43, 54–59, 65) are informational here and not counted.

d3d12_typeless_rtv also fails on this runtime, at its MSAA castable CreateCommittedResource3 (line 301). That's outside this PR, but it's the same "older host runtime" class if you want to gate it too. run_gpu_tests.py: 139/185 passed, 46 skipped (wave64 on a 32-wide GPU).

AI-assisted test run.

@FaKL-Code

Copy link
Copy Markdown
Contributor

Tested 750cf45 (merged onto main 4947579) on NVIDIA GeForce RTX 4060 Ti, driver 610.88 (32.0.16.1088), Windows 11 26200, MSVC 14.51.36231 (VS 2026), Vulkan SDK 1.4.363.0: pass

  • Clean configure + build of runtime/ (Visual Studio generator, RelWithDebInfo): no new warnings (same C4201/C4456/C4996 counts as main).
  • ctest -C RelWithDebInfo -j 4: 116/116 passed (loader run on its own; 7 skipped for missing inputs or optional components, gameinput disabled, as on main).
  • d3d12_vulkan_device, command_list, d3d12_com and d3d12_msaa_draw also pass with LEONIDA_VK_VALIDATION=1.
  • d3d12_vulkan_device, which includes the GetCopyableFootprints BaseOffset cases, passes against the host NVIDIA D3D12 runtime. That adds an NVIDIA/Windows 11 data point to the RX 7600/Windows 10 one in the title.

AI-assisted (Claude).

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 750cf45 (on main 4947579) on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, fresh RelWithDebInfo build:

  • d3d12_vulkan_device: passes 20 of 20 runs, and passes under LEONIDA_VK_VALIDATION=1 with 0 validation messages.
  • Full ctest: 125/125. No new /W4 warnings.

AI-assisted (Claude Code).

@marquezinii

Copy link
Copy Markdown
Contributor

Tested 750cf45 (on main 4947579) on RTX 5070, driver 621.24, Windows 11 26H2 (26300), MSVC 14.52 (VS Build Tools 18), RelWithDebInfo, with VK_LAYER_KHRONOS_validation on (LEONIDA_VK_VALIDATION=1): pass. Full ctest 116/116.

GetCopyableFootprints started the layout at BaseOffset and aligned every
subresource to D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT as an absolute
address. The PC runtime lays the subresources out from 0 and adds the base
afterwards: with base 513 the host returns offset 513 for subresource 0,
ours returned 1024, and the totals differed by the gap.
GetCopyableFootprints1 wraps the same function.

compare_footprints now also runs bases 513 and 2^32 + 1 (both unaligned)
next to 0 and 1024. Against the hardware host device on an AMD Radeon
RX 7600, on main 561b65a, the old code gives 652 mismatching fields
(offsets and totals), all at the two new bases: with only 0 and 1024 it
gives none, which is why this went unnoticed. With the fix there are none
at any base. No caller in the runtime passes an unaligned base (the only
internal caller is GetCopyableFootprints1).

AI-assisted. Tested on AMD Radeon RX 7600, driver 26.11.2 (LLPC),
Windows 10 22H2 (in-box d3d12core 10.0.19041), MSVC 14.44.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@iasmitionsalvatore iasmitionsalvatore changed the title d3d12: GetCopyableFootprints aligns from BaseOffset; d3d12_vulkan_device_test passes on an RX 7600 / Windows 10 d3d12: GetCopyableFootprints aligns from BaseOffset Nov 23, 2026
@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 0a08dbb on NVIDIA GeForce RTX 4080, driver 617.42: d3d12_vulkan_device_test exits 0 with the device line "Vulkan device: NVIDIA GeForce RTX 4080 (maxPushConstantsSize: 256 bytes)". The new GetCopyableFootprints comparison (bases 513 and 2^32+1 against the host) prints no line on a pass, so exit 0 is the only signal for it. I did not run the base.

AI-assisted.

benthomashull-commits added a commit to benthomashull-commits/Leonida that referenced this pull request Nov 23, 2026
…Offset

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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