Skip to content

d3d12: ArraySize -1 in 2D-array RTVs and DSVs is every slice from the first on (the layer nulled or refused such views) - #3835

Open
zzEmmazz wants to merge 2 commits into
ItsNotRexed:mainfrom
zzEmmazz:d3d12-view-arraysize-remaining-slices
Open

zzEmmazz wants to merge 2 commits into
ItsNotRexed:mainfrom
zzEmmazz:d3d12-view-arraysize-remaining-slices

Conversation

@zzEmmazz

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #3796 (comment) (new D3D item; found while checking #3594)

What and why

ArraySize = -1 (UINT_MAX) in a TEXTURE2DARRAY or TEXTURE2DMSARRAY render-target or depth-stencil view means "every slice from FirstArraySlice on". CreateRenderTargetView and CreateDepthStencilView stored the -1 as the layer count, so the view was never usable: a typeless or castable RGBA8 RTV was nulled at creation (Close returned E_INVALIDARG), and every other RTV and DSV made the list fail at replay with invalid_subresource, so nothing in that ExecuteCommandLists was submitted.

The fix resolves -1 to the remaining slice count when the view is created (view_slices, four call sites in runtime/shims/d3d12_vulkan_device.cpp). Nothing else changes: -1 with a first slice past the array, a count of 0, a count longer than what is left and UINT_MAX - 1 are kept as given and refused exactly as before (an explicit over-long range still fails at replay, not at creation, which d3d12_vulkan_device_test expects).

1D-array RTVs and DSVs (line_target_view) and 3D RTVs (volume_rtv) already resolved -1, and SRVs and UAVs clamp the count; those are not touched.

d3d12_typeless_rtv_test listed {FirstArraySlice 1, ArraySize UINT_MAX} on a four-slice texture among the views the layer must reject. That expectation was never compared with the host, which accepts the view, so the entry now uses first slice 4 (past the array), which the host refuses too.

Measured

Host, D3D12 debug layer, error messages per Create*View call (RTX 3070, Radeon iGPU and WARP give the same answers): -1 is accepted with first slice 0, 1 and 3 of 4 for RTV and DSV TEXTURE2DARRAY, TEXTURE2DMSARRAY and TEXTURE1DARRAY, at mip 0 and mip 1, typed and typeless. Refused with an error: first slice 4 or UINT_MAX with -1, ArraySize 0, 2 slices from slice 3, 5 slices from slice 0, and UINT_MAX - 1.

Host, clear and readback (d3d12_view_slices_test, same adapter as the layer and WARP): a clear through a view with -1 reaches every slice from the first on, in the view's mip only. 39 host clears per run match that (7 texture kinds x 3 first slices x 2 references, less the 3 that would need a depth resolve on WARP).

Layer, before (f847748c), both GPUs: all 21 clears through a -1 view fail. 6 (typeless RGBA8, 1x and 4x) with Close failed 0x80070057, 12 with the layer refused the list (ReplayResult 3), and the 3 of the 4x depth array on the descriptor check.

Layer, after, both GPUs: 21 of 21 pass, and the 42 out-of-range views (6 ranges x 7 texture kinds) are still refused.

GPU d3d12_view_slices before after ctest -R "^d3d12_" before after
Radeon iGPU (Ryzen 7 9700X, AMD 32.0.21042.62) 21 failures 0 failures 57 of 57 pass 58 of 58 pass
RTX 3070 (NVIDIA 610.74) 21 failures 0 failures 57 of 57 pass 58 of 58 pass

The only difference between the two ctest runs is the new test. Skipped in both: d3d12_first_light (both GPUs) and d3d12_rgb9e5_rtv (RTX 3070).

One thing the new test works around: the layer's 4x depth array is checked by its descriptor (the same bytes as the view that counts the remaining slices, and the list runs) instead of by readback. Read through the layer's depth resolve on the Radeon, every slice of such a texture shows slice 0, with a counted ArraySize as well (a clear of slice 0 alone reads back as all four slices, a clear of slice 1 alone as none); on the RTX 3070 the same readback is right. That is a separate problem in the multisampled depth clear or resolve path, not in the view, and is reported as a finding in the same coordination comment as the claim.

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   # no validation errors
ctest --test-dir runtime\build -C RelWithDebInfo --output-on-failure --timeout 300 -R "^d3d12_"
python -I tests/test_ctest_registration.py
python -I tests/test_ci_registration.py
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

The new test built against the layer without the fix fails on both GPUs (21 failures, none on the host side). The unchanged d3d12_typeless_rtv_test fails with the fix at line 263: list->Close() == E_INVALIDARG (run on the Radeon), which is the entry changed here.

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: draws through a -1 view (only clears), stencil clears, the Xbox-ABI proxy, Wine, and any GPU other than the two above. SRV and UAV handling of -1 was read, not run.

AI-assisted.

… first on

CreateRenderTargetView and CreateDepthStencilView stored ArraySize -1 of a
TEXTURE2DARRAY or TEXTURE2DMSARRAY view as the layer count, so the view was
nulled (typeless and castable RGBA8) or the list was refused at replay. The
host accepts it and clears the remaining slices. Resolve it at creation;
out-of-range views are refused as before. d3d12_view_slices_test compares
clears through such views with the host on the same adapter and WARP.

d3d12_typeless_rtv_test listed {first slice 1, ArraySize -1} on a four-slice
texture among the views the layer must reject; the host accepts that view, so
the entry now uses first slice 4, which the host refuses too.

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

@kacper-serewis kacper-serewis 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.

At 0fa95b9, 40 independent WARP descriptor controls and 18 clear/readback controls passed. UINT_MAX and explicit remaining counts addressed identical slices for single- and multisample RGBA8 RTVs and single-sample D32 DSVs. Multisample D32 coverage was descriptor validation only. No physical GPU. AI-assisted.

@springlesSpri123

Copy link
Copy Markdown

Tested 0fa95b9 on RTX 4070 Ti SUPER (driver 617.42, Windows 11, MSVC 14.42): pass. This is the physical-GPU run the review above didn't have.

  • d3d12_view_slices_test: "21 clears on the layer, 39 on the host; 42 out-of-range views refused; 0 failures". The host reference is the native D3D12 driver on the same RTX 4070 Ti SUPER plus WARP, so NVIDIA's own D3D12 reaches exactly the slices from the first one on for every case, as the test expects.
  • d3d12_typeless_rtv_test: passes on this head and on main f847748 (1730 WARP readbacks, 27 views rejected), so the narrowed {4, UINT_MAX} case is still refused.
  • Negative control: this PR's d3d12_view_slices_test built against main's d3d12_vulkan_device.cpp gives 21 failures, all on the layer and none on the host: "the layer refused the list" for the typed RTV and 1x DSV cases, Close failed 0x80070057 for the two TYPELESS RTV cases, and the descriptor mismatch for the 4x DSV. The test catches the missing fix.

Built with cl.exe at /W4 /permissive-, no warnings. Not run: LEONIDA_VK_VALIDATION=1 (no validation layer installed here) and the full ctest.

AI-assisted.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 0fa95b9 merged onto main 03b09a0 on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:

  • Full ctest: 156/156.
  • d3d12_typeless_rtv and d3d12_view_slices: pass 20 of 20 runs each, and pass under LEONIDA_VK_VALIDATION=1 with 0 validation messages.
  • Warnings: none new in the files this PR changes.

AI-assisted (Claude Code).

@zzEmmazz

Copy link
Copy Markdown
Contributor Author

D3D-416/D3D-418: updated to db0dfa5c with main 3eb4410b; all four remaining-slice normalizations and the regression registration/expectations are preserved.

Both view-slices and typeless-RTV tests pass with Vulkan validation enabled on Radeon (driver 32.0.21042.62) and RTX 3070 (NVIDIA 610.74), with zero validation errors. Each view-slices run checks 21 layer clears, 39 host/WARP clears and rejection of 42 invalid views, with zero failures. Three CPU tests and 23 registration/documentation tests also pass.

The existing limitation remains: 4x depth uses descriptor/list checks rather than per-slice readback. No game files; synthetic inputs. AI-assisted (Codex).

@Vonsek

Vonsek commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested db0dfa5 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 adds/changes): pass on both GPUs, 2/2 each. No game files.

AI-assisted.

@nakebx

nakebx commented Nov 23, 2026

Copy link
Copy Markdown

Tested db0dfa5 on NVIDIA GeForce RTX 3070 (Ampere), driver 610.88, Windows 11 Pro 10.0.26200: pass

  • ctest with LEONIDA_VK_VALIDATION=1: 100% tests passed, 0 failed out of 166
  • d3d12_view_slices_test run directly with the same setting: exit 0, "ArraySize -1 views: 21 clears on the layer, 39 on the host; 42 out-of-range views refused; 0 failures"
  • d3d12_typeless_rtv_test run directly with the same setting: exit 0, "typeless RTV: 1730 WARP readbacks matched, descriptor snapshots and format-cache order checked; 27 unsupported/invalid views rejected"

Built with MSVC through scripts\build_runtime.ps1, Vulkan SDK 1.4.363.0. DISABLE_RTSS_LAYER=1 and DISABLE_VULKAN_OBS_CAPTURE=1 were set. Run with an AI-assisted script; the numbers are copied from the tool output.

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.

6 participants