Repository navigation
d3d12: exact depth bias through VK_EXT_depth_bias_control (D3D-325) - #2718
UlteriorMotive00 wants to merge 4 commits into
Conversation
|
Independent Windows/MSVC 19.44 run of I expanded the local test to 39 cases with positive and negative slopes, constant and slope terms together, and PSOs declaring an RTV that is left unbound at draw time while the DSV stays bound. All 9,984 depth texels matched the D3D formula exactly with This exercised the layer on test-created Vulkan devices on one NVIDIA driver. It did not test the standalone device's feature negotiation, another ICD, or Vulkan validation layers. |
|
Independent Windows test of 6d98f33 on Intel integrated GPU 8086:7D41, driver 32.0.101.9150, Windows 11 build 26300. Built d3d12_depth_bias_test with x64 MSVC/Ninja (RelWithDebInfo), then ran ctest --test-dir review-build -R "^d3d12_depth_bias$" -V. The driver reported depthBiasExact unavailable. All 15 readback comparisons still matched the D3D reference on the fallback path, including native D16_UNORM, native D24_UNORM_S8_UINT and D32_FLOAT at biases 0, +1, +3, -5 and +1000. CTest passed 1/1 with zero fixture failures. This adds Intel fallback coverage alongside the RTX exact-path result above. AI-assisted testing and report. |
|
Thanks @duudiis, that's a much wider check than mine. On the gap you named (the standalone device's negotiation), I pushed Ran
That covers the standalone path's device creation, not draws through it. AI-assisted. |
|
Tested
AI-assisted. |
D3D's DepthBias is exactly one step of the depth format. Vulkan lets a fixed-point attachment's step be up to twice that unless the pipeline asks for depthBiasExact, and the RTX 5070 (617.42) uses twice: D24 +3 stored as +6, +1000 as +2000, and the same on D16. Where the GPU has VK_EXT_depth_bias_control with depthBiasExact, the standalone device (and the test device) enable it, VulkanDeviceInfo carries depth_bias_exact, and each PSO with a bias chains VkDepthBiasRepresentationInfoEXT (FORMAT representation, exact) from its recipe, so draw-time variants keep it. d3d12_depth_bias_test draws flat triangles with DepthBias 0, +1, +3, -5, +1000 into D16, D24S8 and D32F targets and compares stored depth with D3D's formula; without the extension it reports what the device does. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Like the other optional features the standalone device negotiates, a GPU without VK_EXT_depth_bias_control's depthBiasExact is named once, since its fixed-point DepthBias then stays the driver's (up to 2x D3D's). AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ulkan_replay.h locals (C4459) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ef931e0 to
37ac244
Compare
ItsNotRexed#3797 (D3D-309) adds its own test/glsl/vs_depth.vert and a generated/vs_depth.spv rule; a second rule for the same output is a CMake error, so this test's shader gets its own name and its CMake block sits elsewhere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Rebased onto
Thanks @duudiis, @yasaiiko and @gkissel for the runs on Turing, Intel and a second RTX 5070. Tested on
AI-assisted (Claude Code). |
|
D3D-327 independent Windows/native D3D12 verification completed on RTX 5060 (Blackwell), NVIDIA 610.88 / 32.0.16.1088, Windows 11 26200, MSVC 19.44, SDK 10.0.26100, RelWithDebInfo. AI-assisted (Codex); synthetic fixtures only. I built the submitted eff6276 test (15/15 pass), then locally instrumented its footprint readback to record every texel. For the native reference I used the same draw/resource setup with a synthetic HLSL VS compiled by system D3DCompile, normal native descriptor handles and the system D3D12 device. The native adapter LUID was checked against Vulkan's deviceLUID before comparing. Each run covers 3 depth formats x 5 constant biases x 256 texels = 3,840 values. Native D16, native D24S8 and D32F were all available.
The eight failures are nonzero constant biases in D16/D24: +1/+3/-5/+1000 become +2/+6/-10/+2000 steps. Zero bias and every D32F case match native even on the parent. The parent and disabled-feature control match each other at every texel. Local instrumentation was removed and the checkout is clean at eff6276. No slope/unbound-RTV expansion, standalone-device negotiation, other adapter, or Khronos-validation run is claimed; validation layers are unavailable here. No implementation change needed for this verification item. |
|
Independent evidence for this PR, from a differential graphics-state fuzzer I'm writing ( Each seeded program clears a colour target and an optional D16/D24S8/D32/D32S8 target. It then draws triangles through PSOs with random blend, depth-stencil and rasterizer state, including a constant
Reduced example from The PR conflicts with |
… scissors per draw Half the draws get a viewport other than the whole target: whole-pixel offsets from -16 to 24, sizes 8 to 48, and a depth range in 64ths. A third get a scissor rect. Vertices stay on pixel corners or half-pixels and depths stay exact. This covers the layer's viewport y-flip and depth range. Over 600 seeds against the RTX 5060 Ti's D3D12, only the DepthBias seeds (ItsNotRexed#2718) differ; with ItsNotRexed#2718, 0 of 600. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A third of the programs draw to two targets (a second random format) through a pixel shader that writes the colour to SV_Target0 and its bgra swizzle to SV_Target1. Half their draws set IndependentBlendEnable with RenderTarget[1]'s own blend state and write mask. Both targets are compared. Over 600 seeds (197 with two targets) against the RTX 5060 Ti's D3D12, only the DepthBias seeds differ; with ItsNotRexed#2718, 0 of 600. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…as behind --all Four UINT target formats (R8G8B8A8, R16G16B16A16, R32G32B32A32, R32) drawn by a pixel shader that writes the colour's bits, so both sides see exact integers; where both devices report OutputMergerLogicOp, half their draws enable one of the sixteen logic ops. UINT texels compare exactly. --verbose names both targets and says whether logic ops run. A nonzero DepthBias is now generated only with --all: on NVIDIA the layer applies about twice D3D12's bias (D3D-325, fixed by ItsNotRexed#2718), and the default run should stay green on main until that lands. With --all and ItsNotRexed#2718, 0 of 600 differ. RTX 5060 Ti against its own D3D12: default 40 seeds and 1,000 seeds under validation, 0 differ, 0 validation messages; --all 600 seeds, 25 differ, all DepthBias. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- ItsNotRexed#2718 (D3D-325, the earlier claim on the depth-bias test name) adds a same-named test for static depth bias; illusionart453-max's review on ItsNotRexed#1451 asked one side to rename, and ItsNotRexed#2718 keeps its name. - File, CMake target, CTest name (d3d12_dynamic_depth_bias), the temp shader-library dir and the comments naming it all move together, so the two suites can coexist without clobbering each other's index.json.
D3D-325 (finding, listed). Depends on: none (based on
main49475796).What and why
D3D's
DepthBiasis exactly one step of the depth format:ris "the minimum representable value > 0 in the depth-buffer format", so 1 / (2^n - 1) for an n-bit UNORM, and 2^(exponent(z) - 23) forD32_FLOAT. Vulkan lets a fixed-point attachment'srbe anywhere up to twice that unless the pipeline setsVkDepthBiasRepresentationInfoEXT::depthBiasExact. The RTX 5070 uses twice. On nativeD24_UNORM_S8_UINTa flat draw stored +6 / -10 / +2000 steps forDepthBias+3 / -5 / +1000, andD16_UNORMbehaves the same way. Shadow-map and decal biases on D16/D24 targets would land at double what the game set.Changes
VulkanDeviceInfo::depth_bias_exact:VK_EXT_depth_bias_controlwithdepthBiasControlanddepthBiasExactis enabled on the device.leastRepresentableValueForceUnormRepresentationandfloatRepresentationstay off; they aren't needed).vktest::Devicedoes the same and reportsdepth_bias_exact.create_graphics: a PSO with a bias chainsVkDepthBiasRepresentationInfoEXT { LEAST_REPRESENTABLE_VALUE_FORMAT, depthBiasExact = VK_TRUE }into its rasterization state. The struct lives in the PSO'sRecipe, next to therasterit hangs from, so draw-time variants (build(unbound)) keep it. The recipe is only ever used by reference.docs/d3d12_vulkan.md: a "Exact depth bias" item next to the PSO feature list.Tests
New
d3d12_depth_bias_test(CTestd3d12_depth_bias, synthetic, no game files). A flat full-screen triangle (newtest/glsl/vs_depth.vert) at a depth on one of the format's steps (so no rounding tie decides the code) is drawn withDepthFuncALWAYS andDepthBias0, +1, +3, -5, +1000 intoD16_UNORM,D24_UNORM_S8_UINTandD32_FLOAT. Stored depth is read back through a footprint and compared with D3D's formula. WithoutdepthBiasExactthe test prints what the device does (INFO) instead of failing. D24 is skipped where the layer stores it as D32 (no D24 on the GPU), because that path's bias is D3D-309's.Tested on Windows 11 Home 26300, MSVC 14.44 (VS 2022 Build Tools), Ninja RelWithDebInfo via
scripts/build_runtime.ps1:depthBiasExactavailable), withLEONIDA_VK_VALIDATION=1: 15/15 exact. D16 and D24 +0/+1/+3/-5/+1000 steps; D32F 0.375 → 0.37500003 / 0.375000089 / 0.374999851 / 0.375029802 for +1/+3/-5/+1000.VK_EXT_depth_bias_control), with validation: D32F exact. D16 reportsINFO+2/+6/-10/+2000 steps (the driver's 2x, which this PR can't change there). D24 is skipped (stored as D32).ctest: 125/125 on both GPUs.Not covered
VK_EXT_depth_bias_controlhere, so its fixed-point bias stays at 2x on D16. A fallback would need the device'srmeasured once (a probe draw) and the constant factor halved; I can file that as a finding if it's wanted. AMD's D24 is stored as D32, so it falls under D3D-309, not this.r, so it isn't affected. Not separately tested here.AI-assisted: yes.
🤖 Generated with Claude Code