Skip to content

Runtime: compare copies with the host runtime, 69 cases, 0 differences; six missing formats and the BC edge fixed (D3D-46) - #610

Closed
AlxcBTW wants to merge 6 commits into
ProjectLeonida:mainfrom
AlxcBTW:d3d-46-copy-compare
Closed

AlxcBTW wants to merge 6 commits into
ProjectLeonida:mainfrom
AlxcBTW:d3d-46-copy-compare

Conversation

@AlxcBTW

@AlxcBTW AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Member

What and why

D3D-46, claimed in #313. This compares copies against the host runtime, the method #313 asks for. The same scenario runs on the layer and on a host D3D12 device, and the bytes read back are compared. LEONIDA_HOST_ADAPTER picks the host adapter: a GPU name or WARP. A name that matches nothing fails the run instead of silently skipping.

runtime/test/d3d12_copy_compare.h, run from d3d12_vulkan_device_test, covers 69 cases:

  • CopyResource, plus CopyBufferRegion with offsets.
  • CopyTextureRegion texture to texture: whole subresources, boxes and destination offsets, array slices, mips and 3D.
  • Copies between different mips: 30 cases on a 24×24 RGBA8 / BC1 / BC7 texture, including boxes that don't fit. Both sides must refuse those: the host at Close with E_INVALIDARG, the layer at execution.
  • Footprint to texture and back, with placed footprints.
  • Formats: UNORM/SNORM/UINT/SINT/FLOAT in 8/16/32-bit widths, packed (10:10:10:2, 11:11:10, 9:9:9:E5, 5:6:5, 5:5:5:1), BC1–BC7 and depth-stencil.

Every partial copy from an uploaded resource is ordered after the upload by a COPY_DEST → COPY_SOURCE round trip.

Layer fixes the comparison found:

  1. Six texture formats were refused by the format table: R8G8_SNORM, R16_UNORM, R32G32_UINT, R9G9B9E5_SHAREDEXP, B5G6R5_UNORM and B5G5R5A1_UNORM. The packed 16-bit ones map to R5G6B5_UNORM_PACK16 and A1R5G5B5_UNORM_PACK16; the comment in the table explains the naming.
  2. A block-compressed texture-to-texture box that reached the padded edge of a small mip was refused as invalid_copy. In vulkan_replay.h the box is now rounded to whole blocks and must fit the destination's padded mip. The extent is cut only where it reaches an image's edge, and it must be a block multiple or end at the edge of each image separately, which is the Vulkan rule. That keeps vkCmdCopyImage valid: there are no VUIDs under validation.

Known differences, printed by the test and listed in docs/d3d12_vulkan.md:

  • TEXTURE1D.
  • D24 on GPUs without a native D24 format, such as the Radeon 880M. There only copies between two D24 textures are checked (CopyResource, boxes, slices). Upload and readback stay unverified.
  • The D24 X8 padding byte.
  • BC copies the host performs as whole blocks but vkCmdCopyImage can't: a 6×6 mip into a larger mip, or a 4×4 box into a 3×3 mip. These stay invalid_copy until a staging copy through a buffer is added.

Tested

Windows 11, MSVC 17.14 RelWithDebInfo, LEONIDA_VK_VALIDATION=1. Vulkan side on an AMD Radeon 880M (AMD 26.11.2) and an NVIDIA RTX 5070 Laptop (617.42). Host side on the NVIDIA GPU, the AMD GPU and WARP.

  • Copy comparison: 0 of 69 cases differ in all six pairings (Vulkan NV/AMD × host NV/AMD/WARP), with 8 known differences reported.
  • ctest: 24/24 with the NVIDIA host, on both Vulkan GPUs.
  • Pre-existing failure: with the host on AMD or WARP, d3d12_vulkan_device_test still exits 1 because of the existing GetResourceTiling comparison (24 diffs). It does the same on main.
  • CPU suites: pass.

An independent review led to:

  • the separate per-image BC rule;
  • restoring the refusal of oversize boxes;
  • the cross-mip tests;
  • failing loudly on an unknown host adapter;
  • the upload barriers;
  • checking D24 copies on the 880M instead of skipping them.

A test-side fix: the cross-mip cases share one queue per side, since a queue per case made the NVIDIA D3D12 host hang now and then.

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

🤖 Generated with Claude Code

AlxcBTW and others added 3 commits November 22, 2026 01:47
CopyResource, CopyTextureRegion (texture to texture, footprint to texture and back, boxes, offsets, array slices,
mips, 3D) and CopyBufferRegion run on the layer and on a host D3D12 device (LEONIDA_HOST_ADAPTER picks it) and the
bytes read back are compared, for 39 format/shape cases including BC1-7 and depth-stencil.

Layer fixes it found: texture formats R8G8_SNORM, R16_UNORM, R32G32_UINT, R9G9B9E5, B5G6R5 and B5G5R5A1 were
refused; a block-compressed texture-to-texture box reaching the padded mip edge was refused as invalid_copy.
Known differences (TEXTURE1D, D24 on GPUs without it, D24 X8 byte) are documented.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Block-compressed texture-to-texture copies: the box is rounded to whole blocks, must fit the destination's padded mip
(a 16-wide box into a 4-wide mip is invalid_copy again), and the extent is cut only where it reaches an edge and
must satisfy both images (block multiple or at that image's edge), else invalid_copy.

Test: copies between different mips (RGBA8, BC1, BC7) and boxes that do not fit, with the host's refusal compared;
a LEONIDA_HOST_ADAPTER that matches nothing fails the run; D24 without a native format still checks the
bit-preserving copies; the partial copies are ordered after the uploads by a COPY_SOURCE round trip; <cctype>.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	runtime/test/d3d12_vulkan_device_test.cpp
@Vonsek

Vonsek commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

D3D-46 landing-order check on df0cc48: #562 (b3edaf3) and #587 (6e0d206) each add the same DXGI mapping and block_format case for one of these formats. The byte sizes and Vulkan formats agree. I ran git merge-tree --write-tree against each head. Both auto-merges report success, but each resulting tree has two identical case labels in both switches. A clean Git merge would still fail to compile.

The tests address different behavior. This PR compares copy bytes with the host. #562 samples RGB9E5 via the heap SRV to check its shared exponent, channels and alpha; #587 clears a B5G6R5 RTV and checks the two-byte result inside and outside the rectangle. All three can coexist with one mapping per format.

If #610 lands first, I will merge main into our two branches and remove their redundant switch cases while preserving the tests. If #562 or #587 lands first, please keep the corresponding case from main just once in each switch when updating #610. This only affects those four labels; the other format mappings and the BC edge work are independent.

Verified together on RTX 5080 (driver 616.92, validation on): I applied only the two PRs' test-file diffs to a detached checkout of df0cc48 and built it with #610's unmodified runtime. Both test executables exited 0. The 64 RGB9E5 samples and the 64 B5G6R5 clear words matched their oracles; all 69 copy cases matched native D3D12, including 108 compared regions for each of the two packed formats.

#617 adds the same B5G5R5A1 resource and size mappings on top of #562, with a sampled-alpha oracle. The coordination note on #617 covers that third format and the updated descriptor slots on main.

@AlxcBTW

AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

A note on overlap: three open PRs add some of the same format-table entries as this one.

The Vulkan formats are the same in every case: E5B9G9R9_UFLOAT_PACK32, A1R5G5B5_UNORM_PACK16 and R5G6B5_UNORM_PACK16. Whichever lands first, I'll merge main back in here and drop the duplicate lines. The copy-comparison cases then test those PRs' formats as well. R8G8_SNORM, R16_UNORM and R32G32_UINT are only in this PR.

AI-assisted (Claude Code).

# Conflicts:
#	docs/d3d12_vulkan.md
#	runtime/shims/d3d12_vulkan_device.cpp
#	runtime/src/vulkan_replay.h
@AlxcBTW

AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

I've merged the current main in as 4c5ce1a. The conflicts were additive format-table entries from the PRs that landed meanwhile; I kept both sides and dropped the duplicate case labels. It's mergeable again.

With it, ctest passes 27/27 on both GPUs. Follow-up #654 builds on this PR's LEONIDA_HOST_ADAPTER selection. It makes d3d12_vulkan_device_test pass against Radeon and WARP hosts: the packed-mip split is the driver's choice, per D3D12_PACKED_MIP_INFO.

AI-assisted (Claude Code).

@oVolkra

oVolkra commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested df0cc48 on NVIDIA GeForce RTX 3060, driver 617.14, Windows 11: pass

Setup: Windows 11 Pro 24H2 (10.0.26100), RTX 3060 (Ampere), NVIDIA 617.14, MSVC 14.44.35207 + Windows SDK 10.0.26100, Ninja RelWithDebInfo, Khronos Vulkan-Headers 1.4.369, VK_LAYER_KHRONOS_validation 1.4.357. PR head built as-is (not rebased; it conflicts with main c432cdc now).

Build: 0 errors, 0 warnings. ctest: 24/24, also with LEONIDA_VK_VALIDATION=1.
d3d12_vulkan_device_test with LEONIDA_HOST_ADAPTER=NVIDIA (host side: the same RTX 3060): exit 0, "copy comparison: 0 of 69 cases differ from the host".
With LEONIDA_HOST_ADAPTER=warp it exits 1 on the GetResourceTiling comparison ("the host runtime refuses it (0x80070057)"), as the description says it does on main.
With LEONIDA_VK_VALIDATION=1: 0 messages from the validation layer (see below).
About the LEONIDA_VK_VALIDATION=1 exit code: on this machine the test prints "3 validation errors" and exits 1 on main c432cdc too. All three are Vulkan loader messages ("loader_get_json: Failed to open JSON file") for stale implicit-layer registry entries of uninstalled overlays, not messages from the validation layer. The validation layer itself reported 0 messages, the same as on main.

AI-assisted: the build and test runs were done with an AI coding assistant (Claude Code) on my machine; the numbers above are its unedited output.

@MrCheese5

Copy link
Copy Markdown
Contributor

Tested 4c5ce1a on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass

d3d12_vulkan_device_test (with the copy comparison) passes against the NVIDIA host runtime.

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

AlxcBTW and others added 2 commits November 22, 2026 03:17
…n now has

ItsNotRexed#562/ItsNotRexed#587 landed the same R9G9B9E5_SHAREDEXP and B5G6R5_UNORM mappings this
branch adds. The textual merge was clean but left duplicate case labels
(MSVC C2196) in texture_format and the block-size table; keep one of each.

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

AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

I've merged main again, as bfd0627. #562 and #587 have landed the R9G9B9E5_SHAREDEXP and B5G6R5_UNORM mappings this PR also adds. Git merged that cleanly, but the result had duplicate case labels in texture_format and the block-size table, which is a build error (MSVC C2196). This merge keeps one of each, so this PR now adds only R8G8_SNORM, R16_UNORM, R32G32_UINT and B5G5R5A1_UNORM.

After the merge it builds with MSVC 17.14, and ctest passes 28/28 on the Radeon 880M and on the RTX 5070. Heads-up for #617: it adds B5G5R5A1_UNORM too, so whichever of #610 and #617 lands second will get the same duplicate label even though git reports no conflict.

AI-assisted (Claude Code).

ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
@AlxcBTW

AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

This PR's content landed on main through #654: #654 was built on this branch and carried its commits. The copy comparison (69 cases), the format mappings and the BC-edge fix are all on main now, and your 67204bf removed the duplicate cases. The only thing left on this branch is my second merge, and on today's main that would bring the duplicates back. So I'm closing this rather than merging it. Thanks for merging #654.

AI-assisted (Claude Code).

@AlxcBTW AlxcBTW closed this Nov 22, 2026
ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
The layer stores D24 as D32_SFLOAT_S8_UINT where the GPU has no D24 (the
Radeon 880M, AMD generally). Footprint copies of the depth plane now convert
through a compute pass: an upload turns the 24-bit words into the nearest
floats of d / 16777215, a readback quantises floats back (float multiply by
16777215, round to nearest even, as WARP and AMD's D3D12 driver do) and writes
0 in the unspecified top byte. Clears store the float of the quantised value,
so a texture reads back as D3D's quantisation of the clear value.

- src/depth24.h, vulkan_depth24.h, depth24_convert.comp (+ compiled SPIR-V):
  reference conversion, the converter (pipeline, scratch, descriptors freed
  once the submission completes) and the shader.
- vulkan_replay.h: depth24_as_float binding flag, convert jobs prepared with the
  list and run around the copy, depth clear value.
- depth24_convert_test: all 16777216 words to float and back, 16777216 float
  patterns against the reference, a pitched copy; d3d12_depth24_compare.h:
  5215 clear values (whole-view and rectangle) against the host.
- d3d12_copy_compare.h: the D24 case now compares upload and readback with the
  host instead of only the bit-preserving copies.

Depends on #610.

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.

4 participants