Repository navigation
Runtime: a pixel's depth is clamped to the viewport range with clipping on, as D3D12 does - #1703
nightmoon1996 wants to merge 1 commit into
Conversation
|
Independently verified commit
AI Assisted. |
|
Tested
AI-assisted (Claude Code). |
|
Built The new test's namespace-scope |
e1a6e4d to
4090bf3
Compare
|
Rebased onto Changes since e1a6e4d:
The three red jobs on the old head were not from this change:
Tested on this head, Windows 11, RTX 4060 Ti: AI-assisted. |
4090bf3 to
6a04421
Compare
|
Rebased onto |
6a04421 to
7966f59
Compare
|
Rebased onto Re-run after the rebase (clang-cl 23.1.6 + xwin SDK 10.0.26100, NVIDIA): AI-assisted (Claude Code); no game files. |
7966f59 to
c1d0984
Compare
|
Rebased onto Re-run (RTX 4060 Ti, driver 32.0.16.2101, clang-cl 23.1.6 + xwin SDK 10.0.26100): AI-assisted (Claude Code); no game files. |
Flyander
left a comment
There was a problem hiding this comment.
The depth-clip extension path matches the reported D3D behavior, and the documented fallback is explicit when the extension is unavailable. The synthetic host-vs-layer readback has independent NVIDIA and AMD results. No additional blocker found in this diff; I did not run tests locally. The current branch still needs to clear its reported merge conflict before it can merge.
…ng on, as D3D12 does D3D12 clamps the depth a pixel ends up with (written by the pixel shader, or moved by depth bias) to the viewport's MinDepth..MaxDepth whether or not DepthClipEnable is set. The layer set depthClampEnable only for DepthClipEnable = FALSE, so with clipping on, the default, such a depth reached the buffer unclamped. Where VK_EXT_depth_clip_enable and depthClamp exist, a pipeline now always clamps and carries DepthClipEnable in the extension's depth-clip state. Without them the old mapping stays, with a log line. d3d12_depth_clamp compares the layer with the PC runtime: D32_FLOAT, a [0.25, 0.5] viewport, SV_Depth above, below and inside the range, depth bias past both ends, and geometry beyond the near and far planes, for both DepthClipEnable values. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Rebased onto Re-run (RTX 4060 Ti, driver 32.0.16.2101, clang-cl 23.1.6 + xwin SDK 10.0.26100): AI-assisted (Claude Code); no game files. |
c1d0984 to
607ead1
Compare
|
Tested
|
|
Tested 607ead1 merged with main 98fa503 on Windows (MSVC 14.51, RelWithDebInfo; RTX 4080 SUPER and UHD 770, driver 32.0.101.6129): pass. GitHub flags it as conflicting but the merge is clean. d3d12_depth_clamp passes on both GPUs; on the UHD 770 the layer lacks depthClamp/VK_EXT_depth_clip_enable, so the 16 'without the extension' cases run and behave as documented. Full ctest: RTX 4080 SUPER 174/174; UHD 770 172/174, the two failures (d3d12_sparse_queue_family, d3d12_present) also fail with main's d3d12_vulkan_device.cpp, so they are not from this PR. Negative control: with main's runtime/shims/d3d12_vulkan_device.cpp (keeping the PR's headers) d3d12_depth_clamp fails on both GPUs; with main's three non-test files the test no longer compiles (depth_clip_enable is missing). |
Claimed in the coordination issue as: #1548 (comment) (new D3D item)
What and why
D3D12 clamps the depth a pixel ends up with (written by the pixel shader, or moved by depth bias) to the viewport's
MinDepth..MaxDepth, whether or notDepthClipEnableis set;DepthClipEnableonly decides whether geometry is clipped at the near and far planes. The layer setdepthClampEnable = !DepthClipEnable, and Vulkan only clamps withdepthClampEnableon. So with clipping on, the default, a depth outside the viewport range reached the depth buffer as it was.Measured on the PC runtime first (D32_FLOAT cleared to 0.75, viewport depth 0.25..0.5, depth test ALWAYS, one full-screen triangle). The RTX 4060 Ti and WARP gave the same value in every cell:
main, TRUEThe change:
VK_EXT_depth_clip_enablewhen the device has it (VulkanDeviceInfo::depth_clip_enable, false by default, so a device handed in by a caller behaves as before).depthClamp, a graphics pipeline always setsdepthClampEnableand carriesDepthClipEnableinVkPipelineRasterizationDepthClipStateCreateInfoEXT. The struct is kept in the pipeline recipe and chained inbuild(), so variant pipelines get it too.DepthClipEnable = FALSEpipelines behave as before (Runtime: DepthClipEnable = FALSE clamps depth instead of clipping #813's half, already onmain).To keep clear of #1451: the "Features" sentence in
docs/d3d12_vulkan.mdis not edited, andvk_test_device.hadds its lines away fromenable.logicOp.Tested
Windows 11, NVIDIA GeForce RTX 4060 Ti (driver 32.0.16.2101), built with clang-cl 23.1.6 and the xwin SDK (10.0.26100) through
runtime/cmake/clang-cl-xwin.cmake, run natively. No game files.d3d12_depth_clamp(built with the other glslangValidator tests): the 8 cases above for bothDepthClipEnablevalues, all 256 pixels, exact float equality between the layer and the PC runtime, and both equal to the table. Passes against the RTX 4060 Ti as host and withLEONIDA_HOST_ADAPTER=warp.depth_clip_enable = false: theFALSEcases and the in-range and clippedTRUEcases still match, and the out-of-rangeTRUEcases stay unclamped, which pins the fallback.main'sd3d12_vulkan_device.cpp, the four out-of-rangeTRUErows differ from the host (last column above).ctest: 94 passed, 0 failed; skipped or disabled here:bink_decode,fsr_dispatch,bvh_builder,bink_audio(need the package),d3d12_rgb9e5_rtv(not a render target on this GPU),gameinput(no SDL3 in this build).d3d12_depth_resolvedoes. That path was written but not run here.One thing measured and left out of the pass/fail set: with an inverted viewport (MinDepth 0.5, MaxDepth 0.25) the two hosts disagree. The RTX 4060 Ti clamps to the range between the two ends (0.9 → 0.5, 0.1 → 0.25, 0.4 → 0.4) and the layer matches it; WARP writes 0.25 for everything. The test prints those rows without judging them.
AI-assisted (Claude Code).
Checklist
docs/design.md, with how it was confirmed. (not a translator change)🤖 Generated with Claude Code