Skip to content

d3d12: D24-as-D32 depth: triangle-only bias, slope term only with a slope factor (D3D-309 follow-up) - #3797

Open
JustDownTV wants to merge 1 commit into
ItsNotRexed:mainfrom
JustDownTV:d3d-309/d24-depth-on-d32
Open

JustDownTV wants to merge 1 commit into
ItsNotRexed:mainfrom
JustDownTV:d3d-309/d24-depth-on-d32

Conversation

@JustDownTV

@JustDownTV JustDownTV commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D-309 (claim; @marquezinii passed on it, @UlteriorMotive00 released it)

Depends on: none (based on main 0db7fed5).

Status: the first version of this PR (654e6664) is already on main (merge 0a9b3ff3). This PR now carries only the review follow-up on top of it, rebased on main 0db7fed5 as b4f9cfd9: no bias on points and lines (@kacper-serewis), the slope term and its derivatives only with a non-zero slope factor (@whattheflop), NoContraction on the bias and NMin/NMax before the conversion, the D24-as-D32 check computed once, the stricter test and the doc's bound and "not covered" notes (@CharlyRien). Retested after the rebase with LEONIDA_VK_VALIDATION=1: AMD gfx1036 iGPU (D32 path) d3d12_depth24_draw_test 83 of 83, 0 validation errors, and d3d12_m3_frame_test passes; RTX 5070 Ti (native D24) 65 pass, 0 failures. The description below is the whole change as reviewed.

What and why

On a GPU without a D24 attachment (AMD) the layer stores D24_UNORM_S8_UINT as D32_SFLOAT_S8_UINT. In draws that breaks the two D3D rules of the finding (@marquezinii, measured by @Vonsek on #291):

  1. RasterizerState.DepthBias is in fixed D24 units, but Vulkan scales a float attachment's constant bias by the primitive's exponent.
  2. Clears are quantised to the D24 code (depth24_clear_value) and fragment depth is not, so an EQUAL test at a cleared value fails.

This builds on @UlteriorMotive00's branch (fix/d3d-309-d24-float-depth, 0ff3f8f6), which they offered when they released the item; they are credited as co-author of the commit. For a single-sampled graphics pipeline with depth enabled on such a target, the pixel stage writes FragDepth = quantise(z + bias):

  • bias = DepthBias / (2^24 - 1) + SlopeScaledDepthBias * max(|dz/dx|, |dz/dy|), clamped by DepthBiasClamp, as the D3D11.3 spec gives it for a UNORM target, for triangles only (wireframe included). POINT and LINE pipelines get the quantisation with no bias, as in D3D; a GS takes and emits triangles here;
  • quantise is depth24_convert.comp's conversion (round to nearest even of z * (2^24 - 1) in float, NaN and negatives to 0), so a fragment holds exactly the float a D24 code reads back as;
  • the slope term (and its derivatives) only when SlopeScaledDepthBias is non-zero, as D3D11.3 15.10 requires (0 times an edge-on triangle's infinite slope would be NaN; review by @whattheflop);

src/depth24_fragment.h edits the translated pixel shader's SPIR-V, or builds a pixel stage for a pipeline that has none. A shader that writes its own depth has it quantised, unbiased, as in D3D.

Not covered (in docs/d3d12_vulkan.md): multisampled targets and shaders with EarlyFragmentTests keep the old path and are logged; the slope term of wireframe triangles comes from the edge's derivatives, not the plane (the constant term is exact); a depth that reaches the viewport's MinDepth..MaxDepth (D3D clamps before quantising, here the quantised value is clamped after and only with DepthClipEnable = FALSE, so an EQUAL test at a bound off the 24-bit grid fails, as on main; measured by @CharlyRien; see #1703); early depth testing is off for these pipelines because of the FragDepth write. The slope term can be about 1 + |SlopeScaledDepthBias| 24-bit steps from D24 hardware's plane-exact one, since the derivative of the interpolated float depth is about one ulp off (measured by @CharlyRien: 13 steps at a factor of 16 on an inexact plane, which the test now reproduces). Computing the slope once per primitive would make it exact; that is a follow-up.

Changes on top of the original branch:

  • Rebased on current main, where graphics PSOs take a geometry shader and link f16 halves before creating the modules (Runtime: geometry shaders in graphics PSOs (VS + GS + PS) #2109, SHADER-378). The patch runs in the module loop, after the f16 link, on stage.words.
  • A VS + GS pipeline without a pixel shader gets the built-in depth stage. The branch tested stage_infos.size() == 1, false once a GS is there, so such a pipeline lost its bias entirely; it now tests for a missing PS.
  • Points and lines are not biased (review by @kacper-serewis).
  • The test is stricter (below), passes every feature the device enabled to the layer, and its global size no longer shadows vulkan_replay.h (C4459). The D24-as-D32 check is computed once in CreateGraphicsPipelineState. The patcher's clamp before OpConvertFToU uses NMin/NMax, defined for a NaN.

Tested

Windows 11, MSVC 14.51, Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0, LEONIDA_VK_VALIDATION=1 (the test now fails on any validation error).

d3d12_depth24_draw_test checks, with no PS, with a PS, and with a pass-through GS and no PS: the finding's LESS cases (bias -1 as positive control, 0, +1, +2) and EQUAL at the cleared 0.15625; flat stored depth for bias 0/3/-5/1000; sloped stored depth with slopes in x, in y and in both with different sizes (so max and not |dz/dx| alone or a sum), slope factors 1, -2, 8 and 16 (the last on a plane whose depth is off the float grid), with and without clamp, and with no constant bias so a native D24 is held to them (only cases with a constant bias may print KNOWN there, D3D-325). Then LINE and POINT pipelines: LESS one step above must pass the same drawn pixels with bias 0, +1 and +2/slope 1, EQUAL at the cleared (off-grid) 0.15625 must pass, bias 1000 must leave the stored code alone. Then a PS writing an off-grid 0.15625 as its depth, with bias 0 and 7: EQUAL against the cleared 0.15625 and the stored code. On the CPU (so also without a GPU): the built-in stage has no derivatives for a constant-only bias.

AMD Radeon iGPU of a Ryzen 7 9800X3D (gfx1036, RDNA2), AMD Windows driver 25.10.30.02 (selected with VK_DRIVER_FILES; D24 stored as D32S8):

  • On main's d3d12_vulkan_device.cpp the finding reproduces: LESS with bias +1/+2 passes 4096 of 4096 (expected 0), EQUAL at the cleared 0.15625 passes 0 of 4096, stored depth with bias 3/-5/1000 is off by -1/+3/-500 codes.
  • With this PR: 83 of 83 pass, 0 validation errors (the slope-16 case reaches 13 steps, within its 17).
  • Each new check was mutated once to see it fail: with the GS condition as in the original branch, the 10 biased GS cases fail (up to 131075 steps off); without the topology check, the 6 line cases fail; with max_slope = |dz/dx|, the y and xy cases fail (up to 65536 steps); without quantising a shader-written depth, both EQUAL checks fail.
  • d3d12_m3_frame_test (translator-shaped shaders on a D24S8 DSV with depth enabled, so the patched path): pass, 0 validation errors.

NVIDIA GeForce RTX 5070 Ti, driver 621.14 (native D24, the new path stays off): 65 pass, 0 failures; KNOWN only for the constant term (D3D-325, #2718); the clamp cases skip because the test device leaves depthBiasClamp off.

Translator output: the 38 pixel-shader fixtures of tests/semantic/fixtures/disasm translated with tools/rdna2spirv.py pass spirv-val --target-env vulkan1.2 before and after depth24_patch_fragment (bias 0, and bias 3 / slope 1.5 / clamp 0.01: 76 of 76), and so does the built-in depth-only stage; a hand-written PS that exports depth (exp mrtz) patches to a valid module with the quantisation before its OpReturn (local checks, not committed).

ctest --test-dir runtime/build on both GPUs: everything passes except d3d12_vulkan_device, d3d12_typeless_rtv and root_signature_oracle, which fail the same way on main on this machine.

Overlap: #2718 (D3D-325, exact bias on native fixed-point targets) edits the same rasterizer lines; the two are complementary, and whichever lands second needs a small rebase. #1451 (RSSetDepthBias as dynamic state) isn't on main; once it is, a D24-as-D32 pipeline with dynamic bias needs its bias passed to the pixel stage instead of baked. #1703 (viewport depth clamp with clipping on) would also clamp the quantised FragDepth.

AI-assisted: yes.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator rule: this is the D3D12 layer; the behaviour is documented in docs/d3d12_vulkan.md.)

@kacper-serewis kacper-serewis 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.

At 654e666 the D32-backed D24 fragment adjustment applies polygon bias to points and ordinary lines. At z=0.15625, +1 changes D24 code 2621440 to 2621441, enough to flip EQUAL and the stencil pass outcome. Keep quantization but select bias by rasterized primitive (GS output where applicable; wireframe triangles still get bias). Also isolate slope and clamp tests with zero constant bias: accepting arbitrary sloped mismatch as KNOWN on native D24 hides other errors. Eight synthetic fragment modules and VS/GS passed Vulkan 1.0 validation. CPU reference and source review, no driver readback. AI-assisted.

@Desamodeth Desamodeth 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 654e666 on Windows 11 / RTX 5070 (621.24), MSVC Release, Vulkan validation on. The unmodified native D24 run had 20 PASS, 12 KNOWN bias differences and 6 clamp skips. To exercise the fallback on the same GPU I masked only the D24 depth/stencil attachment bit in the test fixture's format query. With the PR device implementation all 38 D32S8 cases passed, including GS without PS and shader-written depth; no Vulkan validation errors were reported. With f847748's device implementation under the identical mask, LESS with bias +1/+2 passed all 4096 pixels instead of zero, and EQUAL passed zero instead of 4096. The control stopped later at clamp pipeline creation. Restoring the unmodified fixture reproduced the native result. Synthetic draws only. AI-assisted.

@AC-Storm-YT

Copy link
Copy Markdown
Contributor

Tested 654e666 on Windows 11, Visual Studio 2026, RelWithDebInfo, Vulkan SDK 1.4.363.1, with LEONIDA_VK_VALIDATION=1: pass on two AMD GPUs, both of which store D24 as D32 (D24_UNORM_S8_UINT unavailable, using D32_SFLOAT_S8_UINT).

  • AMD Radeon RX 9070 XT (RDNA4, gfx1201, driver 32.0.31041.1004): d3d12_depth24_draw_test 38 PASS, 0 FAIL, no validation messages.
  • Ryzen 7 9800X3D iGPU (RDNA2, gfx1036, driver 32.0.21045.5002): 38 PASS, 0 FAIL, no validation messages.
  • Negative control: the same test built against main's d3d12_vulkan_device.cpp fails on both GPUs (7 FAIL, 3 PASS), including LESS against 0.15625 + 2^-24 with bias +1/+2 (4096 of 4096 pass, expected 0), EQUAL at the cleared 0.15625 (0 of 4096 pass), and stored depth with bias 3 one code short (5033002 instead of 5033003).

So the fix holds on RDNA4 as well as RDNA2. These are all triangle draws, so they don't cover @kacper-serewis's point/line bias concern.

@whattheflop whattheflop 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.

AI-assisted CPU review at 654e6664. The native MSVC 19.38 build passed. SPIRV-Tools validated ten synthetic inputs, 24 patched outputs, two f16-linked stages and four built-in fragment variants. The patch preserved explicit depth on both live returns, skipped the valid EarlyFragmentTests input, and kept the f16 input locations after the runtime linker relocated them. This complements the existing point/line review.

One additional case: for constant bias +3 with a zero slope factor, the exact helper still emits depth derivatives, their maximum and an OpFMul by 0.0. Direct3D ?15.10 requires skipping that multiply when the factor is zero, specifically because an edge-on wireframe triangle can yield an infinite slope and turn constant-only bias into NaN. Consider constructing the bias from its constant term and emitting slope work only when bias.slope != 0; a structural test can verify the helper emits no derivatives for constant-only bias. I checked the emitted sequence, not the driver-level result for edge-on triangles. Helper ? Direct3D 11.3 specification ?15.10

UlteriorMotive00 added a commit to UlteriorMotive00/Leonida that referenced this pull request Nov 22, 2026
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>
@UlteriorMotive00

Copy link
Copy Markdown
Contributor

Tested 654e6664 on Windows 11 (MSVC 14.44, Vulkan SDK 1.4.363), on its own and merged with #2718 (D3D-325, exact depth bias):

  • AMD Radeon iGPU gfx1036 (2026.04.17, no D24 attachment, so the D32 path): d3d12_depth24_draw 38/38 with LEONIDA_VK_VALIDATION=1, no validation messages, including the new VS + GS cases without a pixel shader.
  • RTX 5070 (617.42, native D24): d3d12_depth24_draw 20/20, validation clean.
  • Full ctest with d3d12: exact depth bias through VK_EXT_depth_bias_control (D3D-325) #2718 merged in: 142/142 on both GPUs (usual game-data skips).

Reviewed the device change against my original branch: the new parts are the GS-without-PS case and the docs, and both look right. The built-in fragment stage goes in after whatever stages exist, so a VS + GS pipeline gets it the same as a VS-only one.

On the overlap with #2718: that PR used to add a test/glsl/vs_depth.vert too, which would have been an add/add conflict and a duplicate CMake rule for generated/vs_depth.spv. I renamed it there (vs_depth_bias.vert, eff6276e), so the two now merge cleanly in either order. The rasterizer lines also merge: on this PR's path depthBiasEnable is false, and #2718 only chains its exact-bias struct when it's true.

Thanks for carrying it, @JustDownTV. AI-assisted (Claude Code).

@Sc4ros

Sc4ros commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 654e666 (based on current main f847748) on AMD Radeon RX 9060 XT (RDNA4, driver 32.0.32029.2010, Vulkan 1.4.359; subgroup 32..64), Windows 11 build 26300, MSVC 19.44 (Visual Studio generator, Release), Vulkan SDK 1.4.363.0: pass.

This GPU has no D24 attachment, so it takes the path the PR changes: the log says D24_UNORM_S8_UINT unavailable, using D32_SFLOAT_S8_UINT.

  • Full build OK. d3d12_depth24_draw: 38 checks pass, 0 fail (the new test, including the vs_depth + gs_depth cases), 5 of 5 direct runs exit 0, and LEONIDA_VK_VALIDATION=1 gives the same 38/0 with no validation message.
  • ctest -R "^(d3d12_|vk_|command_list|queue_proxy|gameinput|xmem|loader)": 65 of 65 pass (2 skipped, as on main); the same selection on main f847748 gave 64 of 64 (2 skipped), so the one extra test is this PR's and nothing else changed. In particular d3d12_vulkan_device passes here (kotorvr and MatyEjsr saw it fail on NVIDIA at 00a0441 for the other D3D-309 change D3D12: validate depth-stencil views like render-target views #3594, which this PR does not touch).
  • Not checked: the cases the author lists as keeping the old path (multisampled targets, EarlyFragmentTests), and no negative control on this machine (the earlier reviews of d3d12: D24-as-D32 depth: triangle-only bias, slope term only with a slope factor (D3D-309 follow-up) #3797's parent did that).

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

@CharlyRien

Copy link
Copy Markdown

AI-assisted review of 654e6664 on RTX 3090 (616.56, Windows 11 23H2). This GPU has native D24, so to run the fallback I made depth_usable(D24) return false in a private copy. With LEONIDA_VK_VALIDATION=1 the PR's d3d12_depth24_draw passed 38/38 with no validation messages. As the reference I used a small native D3D12 program, run on WARP and on the 3090's D3D12 driver.

1. Points and lines (already raised by @kacper-serewis): confirmed on real D3D12. D3D12 applies no bias to them. With a D24 target, a line list at z=0.5 and DepthBias 1000, WARP and the 3090 store exactly code(0.5) on every pixel; a point list gives the same. The forced fallback stores code(0.5)+999 on all 58 px, with or without a PS.

2. Slope-scaled bias error grows with SlopeScaledDepthBias; the doc says "up to two 24-bit steps" (docs/d3d12_vulkan.md:229). The slope comes from dpdx/dpdy of the float FragCoord.z (depth24_fragment.h:395-396). Each derivative can be off by about one float ulp of z, and the slope factor multiplies that error. The test doesn't catch it because its slope (1/128 per pixel) and its z values are exact in float.

I drew a plane z = 0.4 + 0.15·x_clip on a 64×64 target:

SlopeScaledDepthBias Fallback: worst error / px off by more than 2 steps Native D24: worst error
0 1 / 0 1
1 1 / 0 1
4 3 / 64 of 4096 1
16 13 / 3840 of 4096 1

Shadow passes commonly use slope factors in the 2–16 range, so this adds per-quad noise to stored depth. Possible fixes:

  • compute the slope once per primitive, for example from a flat varying of the plane equation or the GS;
  • or, at least, correct the bound in the doc and add a test case with an inexact slope.

3. Wireframe triangles get a wrong slope term (minor, partly older than this PR). The derivatives along a rasterised edge are not the polygon's slope. On a vertical edge with slope 1, the expected term is 131072 steps, and the 3090's D3D12 gives 131066. The fallback gives about 106431. The native Vulkan path is also off here, by about 1.14×.

4. Minor doc point. EQUAL against a depth bound that isn't on the 24-bit grid fails even with zero bias. Case: viewport MaxDepth 0.5, DepthClipEnable FALSE, fragment at 0.5, cleared to 0.5. This happens because quantisation runs before Vulkan's viewport clamp. The result is 0 of 4096 on the fallback and 4096 on native D24. main fails the same way, so this isn't a regression; the "Not covered" note only describes the case where the bias crosses the bound.

Checked and correct:

  • the constant term DepthBias/(2^24−1) and the sign rules of the clamp;
  • quantisation, which matches depth24_quantize/depth24_clear_value bit for bit, including NaN, negatives, values ≥1 and 1.0;
  • SV_Depth, which D3D12 leaves unbiased (measured on WARP and the 3090), and so does the PR;
  • the GS-without-PS case;
  • the D32/D16 and native D24 paths, which are unchanged.

Points 1, 2 and 4 are measured; point 3 is measured against the 3090's D3D12 only.

@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested 654e666 on Windows 11, AMD Radeon iGPU gfx1036 (driver 26.10.1) and RTX 5080 (driver 616.92): ctest -R "^(d3d12_depth24_draw|d3d12_vulkan_device|d3d12_typeless_rtv|depth24_convert|d3d12_depth.*)$" (MSVC, RelWithDebInfo, LEONIDA_VK_DEVICE set per run, device line confirmed, VK_LOADER_LAYERS_DISABLE=~implicit~, no validation layer installed) — pass on both, 5/5 each (depth24_convert, d3d12_vulkan_device, d3d12_typeless_rtv, d3d12_depth_resolve, d3d12_depth24_draw).

  • Radeon: D24_UNORM_S8_UINT: stored as D32_SFLOAT_S8_UINT, so this GPU runs the new path. d3d12_depth24_draw: 38 PASS, 0 KNOWN, 0 SKIP, 0 failure(s), including all the GS/no-PS cases (e.g. flat, GS, no PS, bias 1000 ... 0 of 4096 differ from code 5034000).
  • RTX 5080: native D24, so the D32 path is not used there. 20 PASS, 12 KNOWN (native D24 bias not exact, e.g. code 5033006 where D3D gives 5033003), 6 SKIP (no depthBiasClamp on a native D24), 0 failure(s).
  • d3d12_vulkan_device and d3d12_typeless_rtv pass on both here, so the main-side failures from the PR description don't show up on this machine.

No negative control run.

AI-assisted.

@JustDownTV
JustDownTV force-pushed the d3d-309/d24-depth-on-d32 branch from 654e666 to 1f23faf Compare November 22, 2026 22:08
@JustDownTV

Copy link
Copy Markdown
Contributor Author

Thanks @kacper-serewis, both points were right. Fixed in 1f23fafd (rebased on main 4c52ce27):

  1. Points and lines. The bias now applies to triangles only (wireframe included): POINT and LINE pipelines get the D24 quantisation with a zero bias. A GS takes and emits triangles here (the PSO check requires TRIANGLE with a GS), so those keep it. The test gains LINE and POINT pipelines, with and without a PS: LESS one step above must pass the same drawn pixels with bias 0, +1 and +2/slope 1, EQUAL at the cleared 0.15625 (off the 24-bit grid) must pass, and bias 1000 must leave the stored code alone. With the topology check removed the line cases fail on the AMD iGPU (0 of 64 pass; stored 5034000 instead of 5033000).
  2. Slope and clamp isolated. The slope and clamp cases now have no constant bias, so only the constant term may be KNOWN on a native D24 (D3D-325, d3d12: exact depth bias through VK_EXT_depth_bias_control (D3D-325) #2718); on the RTX 5070 Ti the slope-only cases pass strictly. They also cover slopes in y and in both x and y with different sizes (so max(|dz/dx|, |dz/dy|), not |dz/dx| alone or a sum: that mutation fails up to 65536 steps off), and a slope factor of 8, with the tolerance stated as 1 + |SlopeScaledDepthBias| steps (the derivative of the float depth is about an ulp off the plane).

While at it: the shader-written-depth case now uses EQUAL against an off-grid cleared value (it could not fail before), the test fails on any validation error, the bias arithmetic is NoContraction, and the docs and header say what isn't covered (wireframe slope term, viewport clamp with DepthClipEnable = TRUE).

AMD gfx1036 iGPU (D32S8 path), LEONIDA_VK_VALIDATION=1: 79 of 79 pass, 0 validation errors; d3d12_m3_frame_test (translator-shaped shaders on a D24S8 DSV) passes there too. RTX 5070 Ti: 0 failures. Details in the updated description.

@JustDownTV
JustDownTV force-pushed the d3d-309/d24-depth-on-d32 branch from 1f23faf to 1330310 Compare November 22, 2026 22:11
@JustDownTV

Copy link
Copy Markdown
Contributor Author

Thanks to everyone who tested 654e6664 (RDNA4 9070 XT / 9060 XT, RDNA2 iGPUs, masked-D24 RTX runs). Since then, in 13303108 (on main aa2988cc):

  • @whattheflop: right, a zero slope factor still emitted the derivatives and 0 * max_slope. The slope term and its derivatives are now emitted only when SlopeScaledDepthBias != 0 (D3D11.3 15.10), so an edge-on triangle can't turn a constant-only bias into NaN. The test checks it on the CPU first (so it runs without a GPU too): the built-in stage has no OpDPdx/OpDPdy for a constant-only bias, two with a slope factor.
  • @CharlyRien, 1: fixed in 1f23fafd (points and lines are quantised, unbiased; see the reply above). 2: agreed. The doc and test bound is now about 1 + |SlopeScaledDepthBias| steps, and the test has your kind of case: a factor of 16 on a plane whose depth is off the float grid (dz/dx 0.15). The AMD iGPU reaches 13 steps there, the same as you measured, and the RTX 5070 Ti (native) reaches 1. Making it exact needs the slope once per primitive (a flat varying of the plane, or the GS), which touches the VS side. I'll post it as a follow-up finding rather than grow this PR. 3: the wireframe slope term is listed as not covered in the doc and the header. 4: thanks, the "not covered" note now says that the quantised value is clamped to the viewport range after quantising (and only with DepthClipEnable = FALSE), so an EQUAL test at a bound off the 24-bit grid fails, as it already did on main.
  • @UlteriorMotive00: thanks for renaming vs_depth_bias.vert in d3d12: exact depth bias through VK_EXT_depth_bias_control (D3D-325) #2718 and for checking that the two merge in either order.

AMD gfx1036 iGPU (D32 path), LEONIDA_VK_VALIDATION=1: 83 of 83 pass, 0 validation errors, and d3d12_m3_frame_test passes. RTX 5070 Ti: 65 pass, 0 failures. The description is updated.

@CharlyRien

Copy link
Copy Markdown

Tested 1330310 on RTX 3090 (NVIDIA 616.56, Windows 11 23H2): pass. This confirms the fixes for my points 1 and 2. AI-assisted.

  • Forced D32 path. To exercise it, I added a private hook that makes depth_usable(D24) and the test's format query report no D24. With LEONIDA_VK_VALIDATION=1, d3d12_depth24_draw_test passes 83/83 with no FAIL or KNOWN results and 0 validation errors.
    • Lines and points with bias 1000, with or without a PS, leave the stored code at 5033000.
    • The slope 16 case on dz/dx 0.15 has a largest error of 13 steps, within the new bound of 17, in all three variants (no PS, with PS, and GS without PS).
  • Native D24, unmodified. 65 PASS. The other results are the expected KNOWN results on the constant term (D3D-325) and 6 clamp SKIPs, because depthBiasClamp is off.

@kacper-serewis kacper-serewis 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.

Rechecked 1330310 on Windows RTX 5070, driver 616.56. Native D24 had 65 passes, 12 known constant-bias results and six clamp skips. A private D32-backed override passed all 83. Points and lines retained depth code 5033000 at bias 1000 with and without PS; the constant-only stage emitted zero derivatives and the slope stage two. No unexpected failures or validation errors. Both earlier review findings are resolved. Synthetic tests, AI-assisted.

@tupacfan04

Copy link
Copy Markdown
Contributor

Approved by static review (no build here).

The conversion is right: the bias term scales DepthBias * float(1/(2^24-1)) as D3D's UNORM r, the slope term uses max(|dPdx|,|dPdy|) and is emitted only when the factor is non-zero, the clamp applies to the total for both signs, and quantise matches depth24_quantize (roundEven of z*(2^24-1), NaN/negative/-0.0 -> 0, >= 1 -> 0xffffff) with the NMin/NMax guard on OpConvertFToU. D32S8 and native D24 are untouched: d24_as_float gates everything, and the raster-bias expression and depth-format assignment are identical when it is false. GS-without-PS gets the built-in stage, POINT/LINE get quantisation only, shader-written depth is quantised but unbiased, and the patch runs after the f16 link with the failure path flipping depth24_fragment before raster bias is set.

Only gap, pre-existing and scoped out in the body: the viewport MinDepth..MaxDepth clamp is still wrong for non-default ranges (quantised to 0..1, depth24_fragment.h:262; documented at docs/d3d12_vulkan.md:237).

Approve. AI-assisted review, no game files, no GPU.

…lope factor (D3D-309)

Review follow-up to the D3D-309 change already on main (654e666):

- Points and lines are quantised but not biased, as in D3D (only triangles,
  wireframe ones included, take DepthBias).
- The slope term and its derivatives are emitted only when
  SlopeScaledDepthBias is non-zero (D3D11.3 15.10), so an edge-on triangle
  cannot turn a constant-only bias into NaN. The bias operations carry
  NoContraction, and the clamp before OpConvertFToU uses NMin/NMax.
- The D24-as-D32 check is computed once in CreateGraphicsPipelineState.
- d3d12_depth24_draw_test: slopes in y and in both axes, slope factors -2, 8
  and 16, clamps, no constant bias in the slope cases (so native D24 is held
  to them), LINE and POINT pipelines, a pixel shader writing an off-grid
  depth, the built-in stage's derivatives checked on the CPU, and failure on
  any validation error. The doc states the ~1 + |SlopeScaledDepthBias| step
  bound and what is not covered.
@JustDownTV
JustDownTV force-pushed the d3d-309/d24-depth-on-d32 branch from 1330310 to b4f9cfd Compare November 23, 2026 04:11
@JustDownTV JustDownTV changed the title d3d12: D24 depth stored as D32 gets D24 depth bias and 24-bit depth in draws (D3D-309) d3d12: D24-as-D32 depth: triangle-only bias, slope term only with a slope factor (D3D-309 follow-up) Nov 23, 2026
@evilclanker9000

Copy link
Copy Markdown
Contributor

Tested b4f9cfd on Windows 11 (MSVC BuildTools 2022, Ninja, RelWithDebInfo, -j 4; no Vulkan validation layer installed), one GPU at a time, device line confirmed: AMD Radeon RDNA2 iGPU (driver 26.10.1) and NVIDIA RTX 5080 (driver 616.92). Ran ctest -R "^(d3d12_depth24_draw)$" (the tests this PR adds/changes): pass on both GPUs, 1/1 each. No game files.

AI-assisted.

@nakebx

nakebx commented Nov 23, 2026

Copy link
Copy Markdown

Tested b4f9cfd on NVIDIA GeForce RTX 3070 (Ampere), driver 610.88, Windows 11 Pro 10.0.26200: pass

  • ctest with LEONIDA_VK_VALIDATION=1: 100% tests passed, 0 failed out of 165
  • d3d12_depth24_draw_test run directly with the same setting: exit 0, "0 failure(s)"

Built with MSVC through scripts\build_runtime.ps1, Vulkan SDK 1.4.363.0. DISABLE_RTSS_LAYER=1 and DISABLE_VULKAN_OBS_CAPTURE=1 were set. Run with an AI-assisted script; the numbers are copied from the tool output.

benthomashull-commits added a commit to benthomashull-commits/Leonida that referenced this pull request Nov 23, 2026
…slope term only with a slope factor (D3D-309 follow-up)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.