Skip to content

d3d12: a 4x depth-only array is resolved slice by slice in a render pass; AMD's driver read slice 0 for every slice (D3D-417) - #3977

Merged
ItsNotRexed merged 912 commits into
ItsNotRexed:mainfrom
zzEmmazz:d3d-417-msaa-depth-array-slices
Nov 23, 2026
Merged

ItsNotRexed merged 912 commits into
ItsNotRexed:mainfrom
zzEmmazz:d3d-417-msaa-depth-array-slices

Conversation

@zzEmmazz

Copy link
Copy Markdown
Contributor

D3D-417, claimed in the coordination issue: #3796 (comment)
Depends on: #3835

What and why

On the Radeon iGPU, a 4x D32 2D-array texture read back slice by slice (ResolveSubresourceRegion with MIN, then a copy) showed slice 0 for every slice: a clear of slice 0 alone came back as all four slices, a clear of slice 1 alone as none. The clear is right. The readback is wrong: the layer resolves one depth layer in a dynamic-rendering scope whose multisampled attachment view starts at that layer, and the AMD driver resolves from layer 0 of the image instead. The calls are valid Vulkan as far as the validation layers can tell (no validation or synchronization-validation message about them), and the NVIDIA driver resolves the right layer, so this is a driver workaround, not a fix of wrong calls.

The workaround: a depth resolve whose source is a depth-only image and whose source layer is above 0 runs in a VkRenderPass (VkSubpassDescriptionDepthStencilResolve) with a VkFramebuffer of the same two one-layer views, instead of the rendering scope. That path gives the right layer on the AMD driver. It is taken on every GPU, so both GPUs run the same code; layer 0, which every existing test uses, keeps the rendering scope. The render pass is cached by what it describes (format, sample count, the two layouts, the mode) and the framebuffer by its images and views; both are retired with the image, like its views (runtime/src/vulkan_backend.h). Layouts, barriers, the render area and the scratch copy around a rectangle are unchanged (runtime/src/vulkan_replay.h).

Not fixed here: a depth-stencil source (D24S8, D32S8) above layer 0 still uses the rendering scope, so a 4x array of those formats is still read back as its slice 0 on that driver (measured). Its two planes can be in different layouts when the resolve is recorded, which one attachment description cannot express without knowing them, so it needs more than this change.

d3d12_view_slices_test now reads the 4x D32 array back on the layer like every other kind (the descriptor-bytes check from #3835 is gone; it was only there because of this bug), and it has three more cases on that texture with a counted ArraySize: slice 0 alone, slice 1 alone, slices 1-3. docs/d3d12_vulkan.md records the driver behaviour next to the MoltenVK resolve note.

Measured

A raw Vulkan program (no layer of ours), 4x D32_SFLOAT image of 4 layers, 8x8, validation and synchronization validation on: no message about any command (one at exit, about objects the program does not destroy). AMD driver 32.0.21042.62 (Ryzen 7 9700X iGPU) against NVIDIA 610.74 (RTX 3070):

Step AMD NVIDIA
Clear of layers 0, 1, 1-3, 2-3, 3 or 0-3 with vkCmdClearDepthStencilImage, a CLEAR load or vkCmdClearAttachments, read with texelFetch of every sample in a compute shader right, 36 of 36 right, 36 of 36
Read: resolve of all 4 layers in one rendering scope (views from layer 0) right, 36 of 36 right
Read: vkCmdCopyImage of the layer into a one-layer 4x image, then a rendering-scope resolve of that right, 36 of 36 right
Read: rendering-scope resolve through a one-layer view of layer s (what the layer issues): vkCmdBeginRendering with pDepthAttachment = view {baseArrayLayer s, layerCount 1}, resolveMode MIN, resolveImageView = one-layer view of the target, layerCount 1, then vkCmdEndRendering layer 0 for every s: wrong in 30 of 36 (right only when all layers hold the same value) right, 36 of 36
The same with the view type 2D, with store STORE instead of NONE, or with the whole image moved between layouts still wrong, 30 of 36 right
The same with a source view from layer s to the last layer wrong right
Views of layers 1-3 resolved in one scope into layers 1-3 target layers 1-3 get source layers 0-2 (the source view's first layer is ignored, the target's is honoured) right
The same one-layer views in a VkFramebuffer of a VkRenderPass with VkSubpassDescriptionDepthStencilResolve right right

Through the layer, d3d12_view_slices_test as changed here:

GPU layer without the fix layer with the fix
Radeon iGPU (AMD 32.0.21042.62) exit 1, 5 failures, all on the 4x D32 array on the layer: first slice 1 and 3 with ArraySize -1 read as none; slice 0 alone read as all four; slice 1 alone and slices 1-3 read as none exit 0, 0 failures
RTX 3070 (NVIDIA 610.74) exit 0, 0 failures exit 0, 0 failures

Each run: 24 clears on the layer, 42 on the host (same adapter and WARP), 42 out-of-range views refused. With the fix both GPUs also pass with LEONIDA_VK_VALIDATION=1.

The runs above and the two ctest lines below were made on the branch before main aa2988cc was merged into it (base f847748c plus #3835). After the merge (d2e6b31d, full rebuild): d3d12_view_slices_test again 0 failures on both GPUs, plain and with LEONIDA_VK_VALIDATION=1, and ctest -R "^d3d12_(depth_resolve|msaa_draw|view_slices|typeless_rtv|vulkan_device|copy_xfmt|resource_desc)$" 7 of 7 on both. The two full ctest runs were not repeated after the merge.

ctest -R "^d3d12_": 58 of 58 pass on both GPUs, the same result test by test as on #3835, d3d12_depth_resolve and d3d12_msaa_draw included. The other tests (ctest -E "^d3d12_"): 83 of 83 pass on both GPUs.

Tested

Windows 11 (26200), MSVC 14.50 (VS 2026), Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Each command once with LEONIDA_VK_DEVICE=radeon and once with LEONIDA_VK_DEVICE=3070, LEONIDA_HOST_ADAPTER unset.

powershell -NoProfile -ExecutionPolicy Bypass -File scripts\build_runtime.ps1
runtime\build\d3d12_view_slices_test.exe
$env:LEONIDA_VK_VALIDATION = "1"; runtime\build\d3d12_view_slices_test.exe
ctest --test-dir runtime\build -C RelWithDebInfo --output-on-failure --timeout 300 -R "^d3d12_"
ctest --test-dir runtime\build -C RelWithDebInfo --output-on-failure --timeout 300 -E "^d3d12_"
python -I tests/test_docs_links.py
python -I tests/test_docs_repo_paths.py
python -I tests/test_docs_list_items.py
python -I tests/test_docs_design_rows.py
python -I tests/test_ctest_registration.py
python -I tests/test_ci_registration.py

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

Not checked: a resolve of a rectangle from a layer above 0 (the render area and the scratch copy around it are the same code as before, but no test resolves a rectangle from such a layer); MAX and AVERAGE through the render pass (only MIN ran); D16; a stencil resolve; any other AMD driver version or GPU, RADV, Wine. Depth-stencil arrays are not fixed (above). The raw Vulkan program is not part of this pull request.

AI-assisted.

# Conflicts:
#	docs/animation.md
# Conflicts:
#	docs/design.md
# Conflicts:
#	docs/character_skeleton.md
# Conflicts:
#	docs/design.md
# Conflicts:
#	docs/design.md
@Zombins2

Copy link
Copy Markdown

AI-assisted. No game files used.

Tested d2e6b31 with and without the workaround on another AMD Windows driver build: Ryzen 5 7600X iGPU (RDNA2, AMD 32.0.21045.16010 / 26.10.1, against the 32.0.21042.62 in the description), Windows 11 build 26200, MSVC 19.50 Ninja Release, LEONIDA_VK_DEVICE=radeon. This test reproduces the slice-zero readback symptom without the workaround on this driver build; enabling the workaround removes the five observed failures.

d3d12_view_slices_test, 3 runs each, with two builds:

Entries below are slice.mip indices judged cleared, not depth values; -1 is the printed UINT_MAX sentinel for all remaining slices.

DSV D32_FLOAT 4x, mip 0 observed slice.mip indices expected indices
first slice 0, ArraySize 1 0.0 1.0 2.0 3.0 0.0
first slice 1, ArraySize 1 none 1.0
first slice 1, ArraySize 3 none 1.0 2.0 3.0
first slice 1, ArraySize -1 none 1.0 2.0 3.0
first slice 3, ArraySize -1 none 3.0

This matches the described readback symptom for this depth-only array: clearing slice 0 appears to affect all four slices, while the selected clears above slice 0 appear to affect none. It does not independently show that the clear itself is wrong. The invalid-subresource diagnostics also occur in the zero-failure PR runs during the expected refusal checks.

Not run: the D24S8/D32S8 case the description leaves open, an NVIDIA run (MKmajster covered one above), and the rest of ctest.

@0xTehuti 0xTehuti left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and verified on NVIDIA hardware.

Hardware & Environment

  • GPU: NVIDIA GeForce RTX 2070 SUPER (TU104, 8192 MB VRAM)
  • Driver: 595.79 (Vulkan 1.4.329)
  • OS: Windows 11 Pro x64 (Build 26100.3037)
  • Toolchain: MSVC 19.44.35225 (VS 2022 Community), CMake 4.4, Ninja 1.13

Execution & Verification Results

  1. Targeted Native & Validation Tests (LEONIDA_VK_VALIDATION=1):

    • d3d12_view_slices_test.exe:
      • Layer views: 24 clears on the layer, 42 on the host (RTX 2070 SUPER & WARP).
      • Validation: 42 out-of-range views refused as expected.
      • 0 failures, 0 Vulkan validation errors.
    • d3d12_typeless_rtv_test.exe:
      • 1584 mixed-format / automatic-mip / predicate cases.
      • 1730 WARP readbacks matched, descriptor snapshots and format-cache order verified.
      • 27 unsupported/invalid views rejected as expected; 0 failures.
    • d3d12_depth_resolve_test.exe:
      • 45 host comparisons matched, 9 refusals kept destination, 0 unsupported modes refused; 0 failures.
    • d3d12_vulkan_device_test.exe:
      • Full device features, creation, heap allocation, format support, and error paths matched; 0 failures.
    • CTest Suite (d3d12_vulkan_device, d3d12_typeless_rtv, d3d12_view_slices, d3d12_depth_resolve):
      • 4/4 passed (100%) in 20.61s with zero Vulkan validation layer warnings or VUID errors.
  2. Static Documentation & Quality Tests:

    • tests/test_docs_links.py: 6/6 passed.
    • tests/test_docs_repo_paths.py: 2/2 passed.
    • tests/test_docs_list_items.py: 2/2 passed.
    • tests/test_docs_design_rows.py: 2/2 passed.
  3. Code Audit:

    • runtime/shims/d3d12_vulkan_device.cpp: view_slices cleanly resolves UINT_MAX (-1) to resource.DepthOrArraySize - first_layer when first_layer < DepthOrArraySize, while leaving invalid first_layer values unchanged so out-of-bound checks reject them. Applied consistently to TEXTURE2DARRAY and TEXTURE2DMSARRAY in RTV and DSV paths.
    • runtime/src/vulkan_replay.h & runtime/src/vulkan_backend.h: The VkRenderPass / VkFramebuffer fallback for depth-only layer resolves > 0 addresses D3D-417 (AMD driver bug where dynamic rendering resolves layer 0) without regressions on NVIDIA. Framebuffers and passes are properly cached under views_mutex_.
    • Clean-room audit: strictly synthetic tests; no game assets, captured shaders, or proprietary fixtures included.

Disclosure: Review and test verification performed with AI assistance.

@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested d2e6b31 on Windows 11, AMD Radeon iGPU gfx1036 (RDNA2, driver 26.10.1) and RTX 5080 (driver 616.92), MSVC RelWithDebInfo build of this head, LEONIDA_VK_DEVICE set per run with the device line confirmed, VK_LOADER_LAYERS_DISABLE=~implicit~ (no validation layer installed):

  • ctest -R "^d3d12_": Radeon 62/62 passed (1 skipped: d3d12_first_light); RTX 5080 62/62 passed (2 skipped: d3d12_first_light, d3d12_rgb9e5_rtv); 0 failures.
  • d3d12_view_slices on both: array views: 24 clears on the layer, 42 on the host; 42 out-of-range views refused; 0 failures (host reference: the same GPU, and WARP).
  • d3d12_depth_resolve: Radeon 17 of 26 match, 9 host quirks, 5 refusals alike against the AMD host and 21 of 21 against WARP; RTX 5080 31 of 31 and 26 of 26.
  • d3d12_typeless_rtv and d3d12_msaa_draw pass on both.

This is a second AMD Windows driver (26.10.1 on RDNA2 gfx1036). No negative control run; I did not rerun main here to show the slice-0 bug on this GPU.

AI-assisted.

@erickbobd

Copy link
Copy Markdown
Contributor

Tested d2e6b31d on RTX 5070 Ti / NVIDIA 617.14 / Windows 11 26200 (MSVC 14.51, Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0, full rebuild): pass.

  • d3d12_view_slices_test: 24 clears on the layer, 42 on the host; 42 out-of-range views refused; 0 failures, plain and with LEONIDA_VK_VALIDATION=1 (no validation message).
  • ctest -R "^d3d12_": 54 of 54 without failures (2 skipped: d3d12_rgb9e5_rtv, no RGB9E5 render targets on this adapter; d3d12_first_light, no LEONIDA_FIRST_LIGHT_DIR).
  • ctest -E "^d3d12_": 84 passed, 7 skipped (package- or feature-gated), 1 failed: xbox_present, which aborts the same way on a main aa2988cc build on this machine, so it is not from this PR (posted as a finding in the coordination issue; it passes for others on similar GPUs).

Code read: the attachment layouts stay fixed through the pass (initial = reference = final), so the barriers recorded outside it are all the synchronization it needs, and the framebuffer cache is retired with either image under views_mutex_. No issues found. No game files. AI-assisted (Claude Code).

ItsNotRexed and others added 2 commits November 22, 2026 18:52
- replay_cpu_bench: ItsNotRexed#3693 moved a draw's render targets and vertex buffers into Draw::views (D3D-391); the bench
  builds a DrawViews block instead of writing the old inline arrays.
- xgameruntime_user_test links file_system.cpp, which now defines rt::fs::game_dir that xgameruntime.cpp calls.
- check_sparse_queue_family: a vkCreateInstance refused because the api_dump/validation layer is not installed is
  the documented "layer absent" skip (77), not a failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This reverts commit 718f105, reversing
changes made to 9aa16b2.
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested d2e6b31 on NVIDIA GeForce RTX 4090 (driver 32.0.16.2101), Windows 11, MSVC 14.51: pass.

I built the branch with CMake and Ninja, RelWithDebInfo. The build has no Vulkan SDK, thus no validation layers.
d3d12_view_slices_test.exe prints host reference: NVIDIA GeForce RTX 4090, and WARP.
Its result line is array views: 24 clears on the layer, 42 on the host; 42 out-of-range views refused; 0 failures.
ctest --output-on-failure -j 4 gives 134 tests: 132 pass and 2 fail. d3d12_typeless_rtv, which this change also edits, passes.
The 2 failures are d3d12_present and xbox_present. They also fail on main aa2988cc on this computer, because of the window size. Main gives 133 tests with the same 2 failures and the same skipped tests.

Negative control: with vulkan_backend.h, vulkan_replay.h and d3d12_vulkan_device.cpp from main, the test prints 21 failures.

I did not test the condition of the AMD driver. AI-assisted.

ItsNotRexed and others added 6 commits November 22, 2026 21:10
- test_bary_fallback: ItsNotRexed#3647 (BUILD-1046) made a missing input folder exit 2 with "does not exist"; the test from
  ItsNotRexed#1379 still expected exit 1.
- test_format_decode_branch: the f16 reference uses the interpreter's pinned half_to_float (a NaN half widens to
  the canonical quiet NaN) instead of struct's '<e', whose NaN payload changed in Python 3.14 (CPython gh-130317).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merges that each passed alone but clash together:
- v_cmp_class_f64: the earlier cmp_class_f64 (685d16e) (operand-form checks, test_cmp_class_f64) and the later f64 branch
  in cmp_class both handled the opcode; f64 goes to cmp_class_f64 again, f16 stays in cmp_class.
- rdna2spirv CLI tests: spirv-as/spirv-val now run in the output folder with the staging file's bare name, so
  the test doubles resolve it against cwd; assemble_spirv decodes the output only when it is bytes. (The doubles
  had been writing .spirv-*.tmp files into the repository root.)
- ps_w64 fixtures (TEST-722): an 18th fixture (ps_w64_a_discard) landed; its killed lanes export nothing and
  keep the clear value.
- first_light: a run without an OBJ removes mesh.bin, and harness_env reads manifest["files"]; batch_glb's stats
  name failures and dropped textures; run_gpu_tests reports a frame never written as a missing readback
  (TEST-837).
- make_game TRANSLATION_SOURCES and runtime.yml's paths include spirv_opt.py and report_paths.py (and
  wave64_emulate_opt.py), which the translator imports.
Repo rules: stdout guard on six tools; encoding on two opens (gen_gdk_runtime_classes' helper is read_utf8);
newline on one write; anim_skeleton_match's joaat encodes like hashdict.joaat; test_feature_scan's new test is
listed with the others its globals() runner reaches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This reverts commit ce318cd, reversing
changes made to a78f170.
# Conflicts:
#	docs/runtime_imports.md
#	runtime/CMakeLists.txt
#	runtime/shims/xgameruntime.cpp
#	runtime/test/xmem_test.cpp
#	tools/rdna2spirv.py
- rdna2spirv: %fmt_size_tab (main's typed-load size table) registers its length and entry constants when a load
  first uses it; created at assembly, %c128 came after the OpTypeArray naming it and spirv-val refused
  buffer_store_format_d16 modules (test_u16_high_half).
- test_vs_packed_inputs matches main's wording of the same SHADER-644 rule ("mixed component types").
- test_mutations: the v_mul_legacy_f32 anchor follows the SHADER-340 flushes (it had stopped matching on main).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ItsNotRexed#2887 added the fixture to the M2 build; with no entry in OTHER_HARNESS the GPU suite reported it as
"no checker defined".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…che entries and the render pass ones

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@zzEmmazz

Copy link
Copy Markdown
Contributor Author

Merged main 7b7d73f8 (head dddf6aaa). The conflict was the device function list in runtime/src/vulkan_backend.h: main added the two pipeline cache entries on the line this branch extends with the render pass and framebuffer ones; both stay.

Re-run on the merged tree, Windows 11, built with MSVC (444 targets, no errors):

  • d3d12_view_slices_test, Radeon gfx1036 iGPU (AMD 32.0.21042.62) and RTX 3070 (NVIDIA 610.74): array views: 24 clears on the layer, 42 on the host; 42 out-of-range views refused; 0 failures on both, the same line as before the merge.
  • ctest -R "view_slices|resolve|msaa|depth|render_target|replay_" on the Radeon: 13 of 13 passed.

Not re-run: the rest of the ctest suite and the GPU fixture suite.

AI-assisted; measured on my PC.

@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested dddf6aa on Windows 11 (MSVC BuildTools 2022, Ninja, RelWithDebInfo, -j 4; no Vulkan validation layer installed), one GPU at a time, device line confirmed: AMD Radeon RDNA2 iGPU (driver 26.10.1) and NVIDIA RTX 5080 (driver 616.92). Ran ctest -R "^(d3d12_typeless_rtv|d3d12_view_slices)$" (the tests this PR changes): pass on both GPUs, 2/2 each. No game files.

AI-assisted.

@sebashord

Copy link
Copy Markdown

Tested dddf6aaa9af4d16227955ecf0c632ff3690bb13e on Windows 11 Pro build 26300.9974 with two GPUs: Radeon iGPU of a Ryzen 7 9800X3D (gfx1036, 0x1002:0x13c0, AMD proprietary driver 25.10.36 = Windows driver 32.0.21036.18, subgroup 32..64) and RTX 5070 Ti (driver 621.01, subgroup 32..32): pass, 8/8 on each GPU with validation on. This is a re-check after the main merge: on this head I only see d3d12_view_slices and d3d12_typeless_rtv on driver 26.10.1 without the validation layer, and the author's re-run on 32.0.21042.62. This run has the layer on for all seven D3D12 tests, on an AMD driver version that is not among those reported here so far (32.0.21042.62, 32.0.21030.2001, 26.10.1).

MSVC 14.44 build of this head (scripts\build_runtime.ps1), one GPU at a time (LEONIDA_VK_DEVICE=radeon / 5070), LEONIDA_VK_VALIDATION=1:

ctest --test-dir runtime\build -C RelWithDebInfo -V --timeout 600 -R "^(vk_sync_validation|d3d12_(depth_resolve|msaa_draw|view_slices|typeless_rtv|vulkan_device|copy_xfmt|resource_desc))$"
Test Radeon iGPU, 25.10.36 RTX 5070 Ti, 621.01
vk_sync_validation PASS, synchronization validation is active same
d3d12_view_slices array views: 24 clears on the layer, 42 on the host; 42 out-of-range views refused; 0 failures (host reference: the Radeon and WARP) same line (host reference: the RTX and WARP)
d3d12_depth_resolve 38 host comparisons matched, 9 refusals kept the destination, 5 modes the device lacks were refused 57 host comparisons matched, 9 refusals kept the destination, 0 modes the device lacks were refused
d3d12_msaa_draw 4x draws resolved, 4096 pixels matched; 64 of 189 edge pixels are partial same
d3d12_typeless_rtv 1730 WARP readbacks matched, 27 unsupported/invalid views rejected same
d3d12_vulkan_device 45 feature queries compared (1 host-unsupported skipped) ... 0 mismatches; Resolve comparison: 60 compared, 60 matched, 10 unsupported or host-unavailable cases skipped, 0 mismatches 46 feature queries compared (0 host-unsupported skipped) ... 0 mismatches; same Resolve line
d3d12_resource_desc 26 of 26 descriptions match, 0 differ against the Radeon and against WARP same against the RTX and against WARP
d3d12_copy_xfmt 46 compared, 0 differ same

Details that differ between the two GPUs, none of them a failure:

  • d3d12_depth_resolve on the Radeon: against the Radeon's own D3D12 driver 17 of 26 match, 9 host quirks, 5 refusals alike; against WARP 21 of 21 match. On the RTX: 31 of 31 and 26 of 26, 0 host quirks.
  • The Radeon has no VK_EXT_host_image_copy, so that part of d3d12_vulkan_device is skipped there (no VK_EXT_host_image_copy, skipped); the staging-copy part ran and matched. It also prints allocation info tiled 2D 4x MSAA RGBA32F: host unsupported (NumQualityLevels=0), skipped.

Every test prints (validation on) in its device line, and the only validation: line in either log is the hazard that vk_sync_validation provokes on purpose.

Not run: anything outside this ctest pattern (no full GPU suite on this head), D24S8/D32S8 arrays (the PR says those are not fixed), other AMD GPUs.

Tools: llvm-mc 23.1.6 (conda-forge), Vulkan SDK 1.4.363.0, Python 3.11.9, VK_LOADER_LAYERS_DISABLE=~implicit~.

AI-assisted. Synthetic test programs and counts only, no game files.

Created with Perplexity

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.

10 participants