Repository navigation
vulkan_replay: no zero-size viewport on the one-viewport path, viewport depths in [0, 1] (RT-REPLAY-VIEWPORT-ZERO-AND-DEPTH-CLAMP) - #2485
Conversation
…rt depths in [0, 1] The path for pipelines without VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT (no multiViewport) passed an empty viewport 0 straight to vkCmdSetViewport (VUID-VkViewport-width-01770) with its scissor still on, although the draw is kept when a later viewport slot is non-empty. It now uses the same 1x1 viewport and empty scissor as the counted path. Both paths clamp minDepth/maxDepth to [0, 1] (NaN to the range's end) unless VK_EXT_depth_range_unrestricted is on (VUID-VkViewport-minDepth-01234, VUID-VkViewport-maxDepth-01235), as clears and depth bounds already do. Reported by kevincommits in ProjectLeonida#1608 (RT-REPLAY-VIEWPORT-ZERO-AND-DEPTH-CLAMP). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lixonik
left a comment
There was a problem hiding this comment.
Reviewed 1377575be (runtime/src/vulkan_replay.h, runtime/test/replay_viewport_test.cpp) and tested:
- One-viewport path (
!graphics.viewport_with_count) now maps empty/NaN D3D12 viewports to the 1x1 dummy viewport paired with an empty scissor, matching theviewport_with_countpath and avoiding VUID-VkViewport-width-01770 / -height-01773. - Both paths clamp
minDepth/maxDepthto[0, 1](withNaN->0.0f/1.0f,±Infclamped cleanly) unlessvk.depth_range_unrestrictedis set. - Tested on Windows 11 (MSVC 19.44):
replay_viewportpassed (0.03 s).
Looks good to merge.
AI-assisted (Antigravity, Gemini).
|
Reviewed at head Verification
Notes (non-blocking)
Approve. AI-assisted review + local MSVC verification. |
|
#2485 | head 1377575 (merged cleanly with main 4a54aed) | |
Claimed in the coordination issue as: RT-REPLAY-VIEWPORT-ZERO-AND-DEPTH-CLAMP (#1608 (comment)). This is item 2 of @kevincommits' finding in #1608 (#1608 (comment)). Thank you for the exact repro, which the new test follows.
Depends on: none. #499 (stale,
needs rebase) moves this viewport code into a helper. Whichever lands second needs a small textual rebase. The two changes share no logic.What and why
In
emit()(runtime/src/vulkan_replay.h), the draw's viewport state:!graphics.viewport_with_count, used when the device lacksmultiViewportorvkCmdSetViewportWithCount). It passeddraw->viewportstraight tovkCmdSetViewport. The draw is kept when any viewport slot is non-empty (any_nonempty_viewport()), so viewport 0 can be empty. That gave a0 x -0viewport (VUID-VkViewport-width-01770 / -height-01773) with the full scissor still on. This path now does what the counted path already does for an empty D3D12 viewport: a 1x1 dummy viewport paired with an empty scissor, so nothing rasterizes, as D3D12 behaves.minDepth/maxDepthwere forwarded unclamped. WithoutVK_EXT_depth_range_unrestrictedVulkan requires them in [0, 1] (VUID-VkViewport-minDepth-01234, VUID-VkViewport-maxDepth-01235), which is also D3D12's range. They are now clamped, with NaN going to 0 and 1, the same wayClearDepthStencilandset_depth_boundsalready handle depths. With the extension enabled, the values pass through unchanged.The viewport build is now one lambda shared by both paths, plus one shared dummy viewport.
Tested
New CPU test
replay_viewport(runtime/test/replay_viewport_test.cpp, no GPU). It records thevkCmdSetViewport*/vkCmdSetScissor*calls fromemit()and checks every recorded viewport against the three VUIDs above. Cases:depth_range_unrestricted. Expected: depths kept as given.d3d12_multi_viewport_testcase). Counted path: slot 0 is the dummy, and slot 1 draws with its depths held. One-viewport path: valid.On main (
c0201a806, header reverted) the test fails with 9FAILlines and 8 invalid viewports, the first beingw 0 h -0 depth [-0.5, 2]. With the change it passes.The one-viewport path cannot be reached on a real device here, because the RTX 4070 SUPER has
multiViewport. The counted path was also run on the GPU underLEONIDA_VK_VALIDATION=1:d3d12_multi_viewport(4/4 exact match vs host D3D12), the depth tests (d3d12_depth*,d3d12_clear_restricted_depth,d3d12_typeless_depth,xbox_depth_storage) and thereplay_*/d3d12_state_maptests. All pass with validation on.Full suite (
ctest -C Release -j 3): 503/505. The two failures,xbox_presentandd3d12_set_descriptor_heaps, also fail on main unchanged.No game files.
GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a)🤖 Generated with Claude Code