Skip to content

d3d12: a UAV clear rectangle that covers nothing no longer fails the list - #8373

Closed
Maraco91 wants to merge 1 commit into
ProjectLeonida:mainfrom
Maraco91:fix/uav-clear-inside-out-rect
Closed

Maraco91 wants to merge 1 commit into
ProjectLeonida:mainfrom
Maraco91:fix/uav-clear-inside-out-rect

Conversation

@Maraco91

Copy link
Copy Markdown
Contributor

Claim: #8186 (comment)

@ItsNotRexed: an exe PR, as you asked.

What

ClearUnorderedAccessViewUint / ClearUnorderedAccessViewFloat with a rectangle that covers nothing (inside out: right < left or bottom < top) no longer fails the command list.

CommandList::clear_unordered_access (runtime/src/command_list.h) returned false for such a rectangle. In d3d12_com.cpp that marks the list invalid, so Close answers E_INVALIDARG and the whole ExecuteCommandLists call is dropped: one degenerate rectangle cost every command in the submission.

The recorder now leaves out rectangles that are inside out or empty and records the rest. When no rectangle is left it records no command, because a command without rectangles clears the whole view. The other refusals are unchanged (no resource, an empty buffer range, no layers, a closed list).

Empty rectangles (right == left or bottom == top) were already accepted by the recorder and skipped at replay; they are now dropped at the same place as the inside-out ones, so both kinds take one path. One visible difference follows: on a texture that cannot be a colour attachment, a clear whose rectangles are all empty used to reach replay and fail there as unsupported; it is now the no-op D3D12 makes of it.

Why

Real D3D12 accepts these calls. Measured on this machine without the debug layer, the same on the NVIDIA device and on WARP:

call host D3D12 main
ClearUnorderedAccessViewUint, texture view, rect {6,6,2,2} only Close S_OK Close E_INVALIDARG
same, rect {4,4,4,8} (empty) only Close S_OK Close S_OK
8x8 R32_UINT: whole view = 5, then 9 into {6,6,2,2}, 9 into {4,4,4,8}, 7 into {0,0,2,2}, executed 60 texels of 5, 4 of 7, none of 9; no device removal list refused
buffer view, rect {5,0,2,1} only Close S_OK Close E_INVALIDARG
64-element buffer: whole = 5, then 9 into {5,0,2,1}, 7 into [8,12), executed 60 of 5, 4 of 7, none of 9 list refused

ClearRenderTargetView with an inverted rectangle is already accepted by the layer (d3d12_close_parity_test, marked match), so the two clears disagreed.

Reach: a title gets here by passing a rectangle it clipped to nothing. Whether the retail executable does that is not measured (I did not read the executable, and no report in #7154 names it), but when it happens the cost is a whole frame's submission, not one clear.

Separate from #7105 (argument validation on the COM side; it keeps the E_INVALIDARG expectation this PR changes, so the two will conflict on that one test line) and #5170 (rectangle clears on volumes).

Tested

Windows 11 (10.0.26200), MSVC 19.42 (VS 2022 Build Tools), RelWithDebInfo, NVIDIA RTX 3080 Ti, driver 616.56, Vulkan SDK 1.4.363.0. No game files.

cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON
cmake --build runtime/build --target command_list_test d3d12_uav_clear_test
runtime/build/command_list_test.exe
runtime/build/d3d12_uav_clear_test.exe
  • Before (the new tests on main@47428cc22's command_list.h):
    • command_list_test: line 374: uav.clear_unordered_access(texture_view, false, nine, inside_out), exit 1.
    • d3d12_uav_clear_test: typed buffer, an inside-out rectangle: Close 80070057, replay 0, exit 1.
  • After: command_list_test exit 0; d3d12_uav_clear_test prints ... whole views and rectangles, all matched, exit 0. The new buffer and texture cases are executed on the Vulkan device and read back: the degenerate rectangles write nothing, the rectangle beside them is cleared.
  • Negative controls in command_list_test: a view with no resource, a texture view with no layers, a buffer view with no bytes and any clear on a closed list are still refused; a clear without rectangles is still recorded as a whole-view clear; of {inside out, {0,0,2,2}, empty} exactly {0,0,2,2} is recorded. In d3d12_uav_clear_test the three recording-time refusals next to the changed line still answer E_INVALIDARG, and the execution-time refusals (including a real rectangle on a volume) are unchanged.
  • Still passing: d3d12_close_parity_test (113 cases, 0 failures), d3d12_clear_test, d3d12_short_uav_clear_test, replay_uav_clear_offset_test, d3d12_predicated_copy_test, d3d12_r9g9b9e5_uav_test, d3d12_buffer_uav_test, d3d12_com_test.
  • python -I scripts/check_no_game_data.py on the three changed files: exit 0.

Not tested: AMD or Intel GPUs, Linux/Wine, a volume or a non-attachment format with a degenerate rectangle on the host, and no boot of the title.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…list

clear_unordered_access refused a rectangle with right < left or
bottom < top. The refusal marks the list invalid, Close answers
E_INVALIDARG and the whole ExecuteCommandLists is dropped. D3D12 closes
and runs such a list and writes nothing for that rectangle (measured on
WARP and an NVIDIA device without the debug layer, for a texture view and
a buffer view), and ClearRenderTargetView already accepts it here.

The recorder now leaves out rectangles that are inside out or empty, and
records no command when none is left, since a command without rectangles
clears the whole view.

command_list_test covers the recorder; d3d12_uav_clear_test runs a
buffer and a texture case and no longer expects E_INVALIDARG.

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

@al3xar al3xar 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 3c90de234 on NVIDIA GeForce RTX 3060 (Ampere), driver 621.24 (Vulkan 1.4.357, Vulkan SDK 1.4.363.0), Windows 11 x64, MSVC 19.44.35230.0, CMake + Ninja RelWithDebInfo (no game files): pass (including Khronos validation layer).

  • Merges cleanly onto upstream/main (dfe4e4ad3).
  • Built command_list_test, d3d12_uav_clear_test, and d3d12_close_parity_test cleanly with zero new warnings in the modified files.
  • command_list_test.exe: exit 0.
  • d3d12_uav_clear_test.exe (LEONIDA_VK_VALIDATION=1, RTX 3060): exit 0, 0 Vulkan validation errors (ClearUnorderedAccessViewUint/Float: raw, structured and typed buffers and 2D, array and volume textures, whole views and rectangles, all matched).
  • d3d12_close_parity_test.exe (LEONIDA_VK_VALIDATION=1, RTX 3060): exit 0 (113 cases, 78 match WARP, 20 known layer-stricter, 15 known layer-looser, 0 failures).
  • python -I scripts/check_no_game_data.py runtime/src/command_list.h runtime/test/command_list_test.cpp runtime/test/d3d12_uav_clear_test.cpp: clean (exit 0).
  • Diff review: filtering out non-covering rectangles (r.left < r.right && r.top < r.bottom) and returning !closed_ when rects was non-empty but covering is empty cleanly treats degenerate/empty rect lists as no-ops without turning them into whole-view clears and without accepting clears on a closed list or invalid view.

AI-assisted.

@lohant27-netizen

Copy link
Copy Markdown

Tested 3c90de234 on Windows 11 (10.0.26300), NVIDIA GeForce RTX 5070 (driver 32.0.16.2101, subgroup 32), MSVC with SDK 10.0.26100, Release, merged onto main 2a3b3b554 together with #8457, #8454, #8373, #8364 and #8340 (no conflicts between them): pass.

@tiagonleal

Copy link
Copy Markdown

Tested 3c90de234 on native Windows 11 Pro (10.0.26300), NVIDIA GeForce RTX 5070 Ti (driver 617.42), MSVC 14.44.35207, RelWithDebInfo via scripts\build_runtime.ps1, Vulkan SDK 1.4.363.0, merged onto main dfe4e4ad3: pass.

  • command_list and d3d12_uav_clear pass with LEONIDA_VK_VALIDATION=0 and =1 (0 validation errors; the A4B4G4R4_UNORM clears are skipped, this device has no typed UAV for it).
  • Control: the PR's tests with runtime/src/command_list.h taken from main both fail (command_list_test line 376, clear_unordered_access(texture_view, false, nine, inside_out); d3d12_uav_clear_test line 313, close == S_OK && result == leonida::ReplayResult::success), so the tests catch the old refusal.
  • Code read of the recorder change: dropping inside-out and empty rectangles, and recording nothing when none is left (an empty list would clear the whole view), looks right to me.

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

@h0useadv

Copy link
Copy Markdown

Tested 3c90de234 (base 47428cc22) on AMD Radeon RX 9070 XT (RDNA4), AMD Windows driver 32.0.32029.2010, Windows 11 Pro build 26300: pass, no new failures. Built with clang-cl 23.1.6 + lld-link against an xwin splat (MSVC 14.44, SDK 10.0.26100), RelWithDebInfo; synthetic, no game files.

  • command_list and d3d12_uav_clear (both with the new inside-out rectangle cases): pass.
  • d3d12_short_uav_clear and replay_uav_clear_offset: pass.
  • Full ctest -j8, failures rerun with -j1: 262/268; the failures are the ones main has on this GPU, plus d3d12_indirect_dispatch_count, which fails because this base predates its fix on main.

AI-assisted (Claude Code).

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested 3c90de23 on Linux, GCC, CPU only (no GPU, no Windows API), merged onto main 867d922f: pass

  • Built only the command_list test target(s) from the merged tree and ran them through CTest: 100% tests passed out of 1.
  • With the PR's runtime/src files reverted to main and rebuilt: 0% tests passed, 1 tests failed out of 1.
    • line 376: uav.clear_unordered_access(texture_view, false, nine, inside_out)

So the new test depends on the change.

The PR's runtime/test/d3d12_uav_clear_test.cpp is a Windows target and was not built here; the portable evidence is the command_list test. The agent also built the test under ASan/UBSan and reports it clean; I did not repeat the sanitizer build.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting.

@MiguelMatMar

Copy link
Copy Markdown

Tested 3c90de2 on NVIDIA GeForce RTX 4080 SUPER, driver 621.24 (Vulkan 1.4.357), Windows 11 Pro 26300, MSVC 14.44, Ninja RelWithDebInfo, applied on main 6dda063, no game data: pass.

  • command_list and d3d12_uav_clear pass (d3d12_uav_clear 3/3 incremental and 1/1 in a fresh build folder). The new inside-out and empty rectangle cases write nothing on this NVIDIA device, as the description says.
  • Negative control: only the test-side files applied (no source change): both fail (typed buffer, an inside-out rectangle: Close 80070057).

(AI-assisted check, Claude Code.)

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.

8 participants