Skip to content

d3d12: validate CopyBufferRegion, CopyTextureRegion, and CopyResource at recording time - #6178

Open
DenRakEiw wants to merge 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:fix/d3d12-copy-recording-validation
Open

DenRakEiw wants to merge 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:fix/d3d12-copy-recording-validation

Conversation

@DenRakEiw

Copy link
Copy Markdown

Closes all 7 remaining copy-recording Known::layer_looser gaps in runtime/test/d3d12_close_parity_test.cpp so invalid CopyBufferRegion, CopyTextureRegion, and CopyResource calls fail ID3D12GraphicsCommandList::Close() matching native D3D12 / WARP.

Claim: #6089 (comment)

Summary

  • CopyBufferRegion (runtime/shims/d3d12_com.cpp):
    • Rejects non-buffer resources (D3D12_RESOURCE_DIMENSION_BUFFER required for both dst and src).
    • Validates overflow-safe [offset, offset + bytes] <= Width for non-zero copies while preserving live WARP's no-op acceptance for 0-byte copies.
  • CopyTextureRegion (runtime/shims/d3d12_com.cpp, runtime/shims/d3d12_com.h, runtime/shims/d3d12_vulkan_device.cpp):
    • Validates SUBRESOURCE_INDEX locations against texture dimension and MipLevels * ArraySize * PlaneCount (accounting for 3D textures and 2-plane depth/stencil formats).
    • Validates PLACED_FOOTPRINT formats: rejects DXGI_FORMAT_UNKNOWN and verifies compatibility with the texture's typeless family, multi-plane depth/stencil plane formats, or creation-time castable-format list (resource_lists_castable_format).
    • Validates destination (x, y, z) + copy_extent <= dst_mip_extent (block-padded for BC textures, scaled block-for-texel for BC <-> uncompressed cross-format copies, and preserving empty/inverted D3D12_BOX no-ops).
  • CopyResource (runtime/shims/d3d12_com.cpp):
    • Rejects buffer-to-buffer copies when dst.Width != src.Width, while preserving buffer-to-texture CopyResource (where WARP returns S_OK).
  • Tests (runtime/test/d3d12_close_parity_test.cpp):
    • Flips all 7 copy cases from Known::layer_looser to Known::match.
    • Adds CopyBufferRegion UINT64_MAX offset overflow check and 0-byte past-end check, both verified against live WARP.

Verification (Windows 11, NVIDIA GeForce RTX 5090, LEONIDA_VK_VALIDATION=1, 0 Vulkan validation errors)

  • d3d12_close_parity_test: 102 cases, 74 match WARP, 20 known layer-stricter, 8 known layer-looser, 0 not run, 0 where WARP differs from the measured column, 0 failures (exit 0)
  • d3d12_com_test: COM list/queue/fence: 16 colour, depth and stencil texels matched; queue wait held the GPU (exit 0)
  • d3d12_copy_xfmt_test: 46 compared, 0 differ (BC <-> uncompressed, controls), 0 depth <-> colour differ (exit 0)
  • d3d12_subresource_copy_test: 109 steps compared with the host (host image copy & staging copy), 0 mismatches (exit 0)
  • d3d12_noop_copy_test: native WARP & Leonida Vulkan: 5 legal no-op copy submissions, invalid upload copy rejected; pattern mismatches=0 (exit 0)
  • d3d12_vulkan_device_test: full suite passed (exit 0)

AI-assisted (Gemini 4 Neon).

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.

1 participant