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
Open
Tyrannys wants to merge 1 commit into
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 ubiquitarianism#1608 (RT-REPLAY-VIEWPORT-ZERO-AND-DEPTH-CLAMP). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lixonik
approved these changes
Nov 27, 2026
lixonik
left a comment
Contributor
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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