Skip to content

d3d12: GetResourceTiling splits NPOT and single-mip textures as AMD does - #7149

Open
gabsilvs wants to merge 1 commit into
ItsNotRexed:mainfrom
gabsilvs:agent/d3d12-tiling-amd-split
Open

gabsilvs wants to merge 1 commit into
ItsNotRexed:mainfrom
gabsilvs:agent/d3d12-tiling-amd-split

Conversation

@gabsilvs

@gabsilvs gabsilvs commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: a new D3D item, claim.

Depends on: none. #5867 edits runtime/src/resource_tiling.h too (validation at the top of resource_tiling()), not these lines; a textual conflict is possible, not a semantic one.

What and why

resource_tiling() models the standard/packed mip split of the AMD PC runtime (D3D-65, #868, #2728): a mip stays standard while it is wider than half the tile or taller than the tile. The 79 AMD layouts in resource_tiling_test all fit that rule. I swept random reserved textures (2D, arrays, volumes, formats 1-115, 1 to 12 mips, MipLevels clamped to the full chain) through GetResourceTiling on the layer and on the AMD PC runtime of the same machine. Two parts of AMD's rule are missing:

  1. The split uses mip sizes rounded up, ceil(size / 2^mip), not the floor size the mip has. An NPOT chain keeps one more standard mip:

    layout AMD (standard / packed / packed start) main
    129x129 RGBA8, 8 mips 2 / 6 / 5 1 / 7 / 4
    128x257 RG32F, 9 mips 3 / 6 / 8 2 / 7 / 7
    257x16 BC6H, 9 mips (and x3) 2 / 7 / 3 1 / 8 / 2
    33x33x33 RGBA8 volume, 6 mips 2 / 4 / 13 1 / 5 / 12

    The total tile count and GetResourceAllocationInfo for the reserved texture change with it.

  2. A single mip is never packed. Every single-mip texture smaller than half a tile, such as 1x1 RGBA8, 1x64 R16, 16x16 RGBA8 x4 or an 8x8x8 R8 volume, reported 0 standard mips and 1 packed tile. AMD and WARP both report 1 standard mip and no packed tail. This also lines the report up with the sparse RGBA8 image path, which maps subresource 0 by tile coordinates (tile_grid in runtime/shims/d3d12_com.cpp).

The standard mips' tile counts still come from the real (floor) sizes, as the host reports. Nothing else reads the split: GetResourceTiling, the reserved size in GetResourceAllocationInfo (total_tiles), and the format check in CreateReservedResource. Reserved textures are otherwise backed fully, so this changes what the application reads and nothing it binds.

For power-of-two tiles, "rounded up" is the same as computing the mips from the power-of-two-padded top level. That AMD pads like this is INFERRED from the numbers, not documented. The console-side texture tools use the same rounded-up block count for their mip tail (compact_surface_layout, see #6802).

Changes

  • runtime/src/resource_tiling.h: the split compares ((size - 1) >> mip) + 1 and treats MipLevels == 1 as standard. This form has no overflow; a texture of width near 2^64 still fails cleanly (new CHECK).
  • runtime/test/resource_tiling_test.cpp: 12 AMD rows measured on this GPU. 9 of them fail on main; the other 3 are controls that split the same way under both rules.
  • docs/d3d12_vulkan.md: the rule and the measurement.

Seen, not changed (host quirk, no third oracle): for packed mips of array slices after the first, the AMD runtime returns StartTileIndexInOverallResource = the packed start of slice 0 (for example 6) instead of D3D12_PACKED_TILE. The layer keeps D3D12_PACKED_TILE, as the D3D12 docs describe. WARP never packs, so there is nothing to compare it with. After this PR it is the only GetResourceTiling difference the sweep finds against AMD (149 subresources over seeds 2 and 3).

Tested

Windows 11 26300, AMD Radeon RX 6750 XT (RDNA2, gfx1031), driver 26.11.2, MSVC 14.44.35207, SDK 10.0.26100.0, Vulkan SDK 1.4.363.0.

check main 1cc6e3c this PR
resource_tiling (12 new AMD rows) FAIL: 9 rows differ (the 3 controls pass) PASS
Sweep vs the AMD runtime, seeds 2 and 3, 3000 descriptions each (2D, arrays, volumes) 127 and 94 classes with a different standard/packed count, packed start or total 0. The only difference left is the packed-slice quirk above
Descriptions the layer refuses with E_INVALIDARG where AMD creates them 11 classes (sRGB/depth formats with UAV/RT flags, A8; see #4493) the same 11

Mutation checks: with the single-mip clause removed, 4 rows fail; with the rounding removed (floor sizes), 5 rows fail.

run result
ctest -R for resource_tiling, d3d12_vulkan_device (compare_tiling), d3d12_texture_tiles, d3d12_sparse_queue_family, d3d12_rgb96, d3d12_r9g9b9e5_uav, d3d12_buffer_tiles 6/7 PASS, with and without LEONIDA_VK_VALIDATION=1, 0 VUIDs. d3d12_texture_tiles fails at line 240 (row-major alias), as on clean main on this GPU: the native AMD CopyTiles quirk (#5951)
full ctest -j 4 253/260. Failing: vk_queue_query_sync (flaky under -j4), d3d12_texture_tiles, d3d12_indirect_dispatch_count (#6162), d3d12_pipeline_library_host (#6088), and d3d12_m2_textured, d3d12_m2_formats, d3d12_m3_frame. Those last three fail the same way with main's rule built in (184 of 4096 pixels differ), so they are not from this change; I am looking at them separately
run_gpu_tests.py (default mode; the translator is untouched) 217/235, 17 skipped, 1 FAIL: ms_wave_info_s3, pre-existing on main (#5741)
tests/test_docs_*.py 11/11 OK
git diff --check clean

NOT RUN: NVIDIA and Intel. Their split is the driver's own, and d3d12_vulkan_device's tiling comparison accepts it. RDNA4 is not re-measured for the 12 new rows.

The sweep itself is not committed. It is a throwaway program (layer vs D3D12CreateDevice on the AMD adapter). Two AMD driver traits it ran into, both host problems: CreateReservedResource with MipLevels past the full chain, or a color format with ALLOW_DEPTH_STENCIL, removes the AMD device (DXGI_ERROR_DRIVER_INTERNAL_ERROR). The sweep clamps the mips and leaves that flag out.

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.)

AI-assisted: yes (Claude Code). Synthetic descriptions only, no game files.

🤖 Generated with Claude Code

https://claude.ai/code/session_015z45kp1NBhQ6foQjyWVFcJ

The standard/packed split follows the AMD PC runtime (D3D-65), but it
compared each mip's floor size with half a tile. AMD rounds the size up,
ceil(size / 2^mip), so an NPOT chain such as 129x129 RGBA8 or a
33x33x33 volume keeps one more standard mip. AMD also never packs a
texture with a single mip, and neither does WARP: a 1x1 RGBA8 or an
8x8x8 R8 volume reported 0 standard mips and 1 packed tile.

Found by a random reserved-texture sweep against the AMD PC runtime on an
RX 6750 XT. Adds the 12 measured layouts to resource_tiling_test (9 fail
before this change).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015z45kp1NBhQ6foQjyWVFcJ
@MatyEjsr

Copy link
Copy Markdown

Verification & Review (60a9c1f0999a5cf9c7726fa25b5c09aae97bffe3)

Verified on Windows 11, NVIDIA GeForce RTX 3090 (driver 617.42), MSVC 14.44.35207 (RelWithDebInfo, Ninja, -j 8) — covering the NVIDIA host comparison and sparse/tiling paths noted as not run in the PR description.

Code & Arithmetic Review

  • Rounded-up split dimensions (runtime/src/resource_tiling.h):
    split_w = mip >= 64 ? 1 : ((desc.width - 1) >> mip) + 1 and split_h = mip >= 32 ? 1u : ((desc.height - 1) >> mip) + 1 compute ceil(size / 2^mip) without intermediate addition overflow. Because desc.width == 0 and desc.height == 0 are rejected at line 131 before the loop, desc.width - 1 and desc.height - 1 cannot underflow.
  • Overflow guard for ~uint64_t{0} width:
    When desc.width == ~uint64_t{0} and mip == 0, split_w evaluates to ((UINT64_MAX - 1) >> 0) + 1 == UINT64_MAX without wrapping, enters the standard branch (split_w > result.shape.width / 2), and fails cleanly when tw = up(w, result.shape.width) exceeds max_tiles, as covered by the new CHECK(!resource_tiling({TiledKind::texture2d, ~std::uint64_t{0}, 1, 1, 2, 4, 1}, t)) test.
  • Single-mip rule (desc.mips == 1):
    Forcing desc.mips == 1 into the standard branch matches both AMD and WARP behavior (1 standard mip, 0 packed mips, packed_start == 0) and keeps single-mip subresource 0 aligned with tile_grid in runtime/shims/d3d12_com.cpp.
  • Standard mip tile counts:
    tw, th, and td continue to use the floor dimensions w, h, d, preserving per-subresource tile counts.

GPU & Runtime Test Results (NVIDIA GeForce RTX 3090, driver 617.42)

Check Result Notes
Negative control (resource_tiling_test with main's resource_tiling.h) FAIL (expected) Fails at first new NPOT case: AMD layout 129x129 RGBA8: standard 1 packed 7 packed tiles 1 start 4, want 2 6 1 5
resource_tiling (with PR changes) PASS (0.01 s) All 91 AMD layouts (79 existing + 12 new) and overflow checks pass
d3d12_vulkan_device (default & LEONIDA_VK_VALIDATION=1) PASS (11.01 s / 10.85 s) compare_tiling passes against the NVIDIA D3D12 host runtime with 0 validation errors
d3d12_texture_tiles (default & LEONIDA_VK_VALIDATION=1) PASS (1.73 s / 2.05 s) Sparse texture tile mapping and CopyTiles pass on RTX 3090
d3d12_sparse_queue_family (default & LEONIDA_VK_VALIDATION=1) PASS (2.36 s / 1.72 s) Sparse binding queue family handoff passes
d3d12_buffer_tiles (default & LEONIDA_VK_VALIDATION=1) PASS (2.62 s / 1.92 s) Reserved buffer tile mappings pass
d3d12_rgb96 & d3d12_r9g9b9e5_uav (default & LEONIDA_VK_VALIDATION=1) PASS Format tiling and UAV checks pass
d3d12_m2_textured, d3d12_m2_formats, d3d12_m3_frame PASS (0.92 s – 0.96 s) All three pass on RTX 3090
python -I tests/test_docs_links.py & tests/test_docs_design_rows.py PASS (11/11) Documentation links and tables clean
git diff --check PASS Clean formatting and LF line endings

AI-assisted verification; synthetic test inputs only, no game data used.

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