feat(vk): bias D24 kept as D32 in D24 units (VK_EXT_depth_bias_control) #1052

Open
jcabarca wants to merge 3 commits from jcabarca/Longshot:feat/vk-d24-depth-bias into main
Contributor

Type: feat · Risk: low · Tested on: Windows, AMD Radeon RX 9070 XT · Needs: none

Why

When a DEPTH24 or DEPTH24_STENCIL8 depth buffer is kept as D32_SFLOAT / D32_SFLOAT_S8_UINT, the game's depth bias, written for 24-bit unorm units, is applied in float units that shrink with the depth's exponent, so shadows show acne. VK_EXT_depth_bias_control lets the bias be given in unorm units on a float format.

How to reproduce

Seen on: reading gpu/vk/vk_draw.cpp: dynamic_state() calls vkCmdSetDepthBias with the game's factors whatever the image's format. On main vk_format() maps DEPTH24 and DEPTH24_STENCIL8 to the D24 formats on every GPU, so this path acts only where they are kept as D32
Settings and switches: defaults
Steps: game-free: python -I -B tests/test_d24_depth_bias.py --source <main checkout> (the test from this PR)
Expected: with the extension and its leastRepresentableValueForceUnormRepresentation feature, a D24 kept as D32 is biased with FORCE_UNORM; without it, vkCmdSetDepthBias as before
Actual: on main the test fails its 13 checks, from "vk_loader.h loads vkCmdSetDepthBias2EXT" to "vkCmdSetDepthBias without the extension"

What changed

The device asks for VK_EXT_depth_bias_control and, where it has the feature, sets the bias of a D24 kept as D32 in 24-bit unorm units.

  • vk: create_device() in gpu/vk/vk_main.cpp: optional(VK_EXT_DEPTH_BIAS_CONTROL_EXTENSION_NAME, dev.depth_bias_control); VkPhysicalDeviceDepthBiasControlFeaturesEXT in the features chain; kept only if depthBiasControl and leastRepresentableValueForceUnormRepresentation are both supported; floatRepresentation and depthBiasExact are set to VK_FALSE before the device is created.
  • vk: gpu/vk/vk_internal.h: Device::depth_bias_control. gpu/vk/vk_loader.h: loads vkCmdSetDepthBias2EXT.
  • vk: dynamic_state() in gpu/vk/vk_draw.cpp: DynState::bias_unorm, true for an NVN DEPTH24 / DEPTH24_STENCIL8 target whose image is D32_SFLOAT / D32_SFLOAT_S8_UINT, on a device with the extension. The bias is set again when bias or bias_unorm changes: vkCmdSetDepthBias2EXT with VkDepthBiasRepresentationInfoEXT (LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT for bias_unorm, LEAST_REPRESENTABLE_VALUE_FORMAT_EXT otherwise); without the extension, vkCmdSetDepthBias as on main.
  • tests: tests/test_d24_depth_bias.py (new).

How it works, step by step:

  1. On a floating-point depth attachment there is no single minimum resolvable difference: it is r = 2^(e-n), with e the maximum exponent of the depths the primitive spans and n the mantissa bits (primsrast.adoc, Depth Bias Computation). On a fixed-point attachment r is constant over the whole range, at most 2 x 2^-n with n the depth bits (2^-24 scale for X8_D24_UNORM_PACK32).
  2. The game's factors are for a 24-bit unorm buffer. Kept as D32, they under-bias: shadow acne.
  3. With LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT, r is constant over the whole range as for a fixed-point attachment, with n "the number of mantissa bits plus one when using a floating-point attachment" (primsrast.adoc, Depth Bias Computation): 24 for D32_SFLOAT, the same n as the game's 24-bit unorm depth.
  4. Other targets keep LEAST_REPRESENTABLE_VALUE_FORMAT_EXT, the default unit, so their bias is unchanged.

The Vulkan rules for the calls and structures this adds, from validusage.json:

  • VUID-VkDepthBiasRepresentationInfoEXT-leastRepresentableValueForceUnormRepresentation-08947: "If the leastRepresentableValueForceUnormRepresentation feature is not enabled, depthBiasRepresentation must not be VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT": met, dev.depth_bias_control is true only when the feature is supported and then enabled.
  • VUID-VkDepthBiasRepresentationInfoEXT-floatRepresentation-08948: "If the floatRepresentation feature is not enabled, depthBiasRepresentation must not be VK_DEPTH_BIAS_REPRESENTATION_FLOAT_EXT": met, FLOAT_EXT is never used.
  • VUID-VkDepthBiasRepresentationInfoEXT-depthBiasExact-08949: "If the depthBiasExact feature is not enabled, depthBiasExact must be VK_FALSE": met, rep is value-initialized, so depthBiasExact is VK_FALSE.
  • VUID-VkDepthBiasInfoEXT-depthBiasClamp-08950: "If the depthBiasClamp feature is not enabled, depthBiasClamp must be 0.0": the same value vkCmdSetDepthBias received on main (VUID-vkCmdSetDepthBias-depthBiasClamp-00790 has the same text).
  • VUID-VkDepthBiasInfoEXT-pNext-pNext: "pNext must be NULL or a pointer to a valid instance of VkDepthBiasRepresentationInfoEXT": met.
  • VUID-vkCmdSetDepthBias2EXT-commandBuffer-cmdpool: "The VkCommandPool that commandBuffer was allocated from must support VK_QUEUE_GRAPHICS_BIT operations": met, the same draw command buffer vkCmdSetDepthBias is recorded into.

Before (dynamic_state()):

    if (DYN_CHANGED(bias)) vkCmdSetDepthBias(cmd, d.bias[0], d.bias[1], d.bias[2]);

After:

    d.bias_unorm = dev.depth_bias_control && depth &&
                   (at.depth->nvn_format == NVN_FORMAT_DEPTH24 || at.depth->nvn_format == NVN_FORMAT_DEPTH24_STENCIL8) &&
                   (at.depth_format == VK_FORMAT_D32_SFLOAT || at.depth_format == VK_FORMAT_D32_SFLOAT_S8_UINT);
...
    if (DYN_CHANGED(bias) || DYN_CHANGED(bias_unorm)) {
        if (dev.depth_bias_control && vkCmdSetDepthBias2EXT) {
            VkDepthBiasRepresentationInfoEXT rep{VK_STRUCTURE_TYPE_DEPTH_BIAS_REPRESENTATION_INFO_EXT};
            rep.depthBiasRepresentation = d.bias_unorm ? VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT
                                                       : VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT;
            VkDepthBiasInfoEXT bi{VK_STRUCTURE_TYPE_DEPTH_BIAS_INFO_EXT, &rep};
            bi.depthBiasConstantFactor = d.bias[0], bi.depthBiasClamp = d.bias[1], bi.depthBiasSlopeFactor = d.bias[2];
            vkCmdSetDepthBias2EXT(cmd, &bi);
        } else
            vkCmdSetDepthBias(cmd, d.bias[0], d.bias[1], d.bias[2]);
    }

create_device(), after the features are queried:

    dev.depth_bias_control = dev.depth_bias_control && dbc.depthBiasControl &&
                             dbc.leastRepresentableValueForceUnormRepresentation;
    dbc.depthBiasControl = dbc.leastRepresentableValueForceUnormRepresentation = dev.depth_bias_control;
    dbc.floatRepresentation = VK_FALSE, dbc.depthBiasExact = VK_FALSE;

Second commit, "set no depth bias clamp where the depthBiasClamp feature is off":

  • vk: dev.depth_bias_clamp in gpu/vk/vk_internal.h, set in gpu/vk/vk_main.cpp from f.features.depthBiasClamp.
  • vk: gpu/vk/vk_draw.cpp: if (!dev.depth_bias_clamp) d.bias[1] = 0.0f; before the clamp is passed to the depth bias command.
  • tests: tests/test_d24_depth_bias.py: two checks for the gate.

The clamp was passed as the game set it. VUID-vkCmdSetDepthBias-depthBiasClamp-00790 and VUID-VkDepthBiasInfoEXT-depthBiasClamp-08950: "If the depthBiasClamp feature is not enabled, depthBiasClamp must be 0.0".

Measurements

Verdict: it fixes the bug: test_d24_depth_bias fails on main and passes here. Both interleaved runs gave the same result. No speed change is expected.

Hardware: AMD Radeon RX 9070 XT, Windows; the tests are game-free (they read source or build a cut-out fixture, they do not use the GPU); Python 3.12
Scene: none, game-free
Method: the tests from this PR run against each side's checkout, 2 runs each, interleaved (main, PR, main, PR); the result is pass/fail, so the median is the result both runs gave
How to reproduce: python -I -B tests/<test>.py with --source <checkout> (and --cxx/--headers where the test asks for them) on each side

Before: main @ c167ec67 After: this PR @ 7690969f
tests/test_d24_depth_bias.py, run 1 fails passes
tests/test_d24_depth_bias.py, run 2 fails passes
tests/test_d24_depth_bias.py, median fails passes
run 1, main @ c167ec67:
FAIL vk_loader.h loads vkCmdSetDepthBias2EXT
FAIL Device has depth_bias_control
FAIL create_device asks for VK_EXT_depth_bias_control
FAIL its features are queried and enabled
FAIL kept only with depthBiasControl and leastRepresentableValueForceUnormRepresentation (08947)
FAIL floatRepresentation and depthBiasExact are not enabled (08948, 08949)
FAIL the features are trimmed after they are queried
FAIL DynState has bias_unorm
FAIL bias_unorm only for an NVN D24 kept as D32, on a device with the extension
FAIL the bias is set again when its unit changes
FAIL vkCmdSetDepthBias2EXT with the extension
FAIL FORCE_UNORM for bias_unorm, the format's unit otherwise
FAIL vkCmdSetDepthBias without the extension
FAIL the depthBiasClamp feature is read from the enabled features
FAIL the game's bias clamp is 0 on a device without depthBiasClamp (00790, 08950)
15 check(s) failed
test_d24_depth_bias                  exit 1
run 1, this PR @ 7690969f:
ok   vk_loader.h loads vkCmdSetDepthBias2EXT
ok   Device has depth_bias_control
ok   create_device asks for VK_EXT_depth_bias_control
ok   its features are queried and enabled
ok   kept only with depthBiasControl and leastRepresentableValueForceUnormRepresentation (08947)
ok   floatRepresentation and depthBiasExact are not enabled (08948, 08949)
ok   the features are trimmed after they are queried
ok   DynState has bias_unorm
ok   bias_unorm only for an NVN D24 kept as D32, on a device with the extension
ok   the bias is set again when its unit changes
ok   vkCmdSetDepthBias2EXT with the extension
ok   FORCE_UNORM for bias_unorm, the format's unit otherwise
ok   vkCmdSetDepthBias without the extension
ok   the depthBiasClamp feature is read from the enabled features
ok   the game's bias clamp is 0 on a device without depthBiasClamp (00790, 08950)
all checks passed
test_d24_depth_bias                  exit 0
run 2, main @ c167ec67:
FAIL vk_loader.h loads vkCmdSetDepthBias2EXT
FAIL Device has depth_bias_control
FAIL create_device asks for VK_EXT_depth_bias_control
FAIL its features are queried and enabled
FAIL kept only with depthBiasControl and leastRepresentableValueForceUnormRepresentation (08947)
FAIL floatRepresentation and depthBiasExact are not enabled (08948, 08949)
FAIL the features are trimmed after they are queried
FAIL DynState has bias_unorm
FAIL bias_unorm only for an NVN D24 kept as D32, on a device with the extension
FAIL the bias is set again when its unit changes
FAIL vkCmdSetDepthBias2EXT with the extension
FAIL FORCE_UNORM for bias_unorm, the format's unit otherwise
FAIL vkCmdSetDepthBias without the extension
FAIL the depthBiasClamp feature is read from the enabled features
FAIL the game's bias clamp is 0 on a device without depthBiasClamp (00790, 08950)
15 check(s) failed
test_d24_depth_bias                  exit 1
run 2, this PR @ 7690969f:
ok   vk_loader.h loads vkCmdSetDepthBias2EXT
ok   Device has depth_bias_control
ok   create_device asks for VK_EXT_depth_bias_control
ok   its features are queried and enabled
ok   kept only with depthBiasControl and leastRepresentableValueForceUnormRepresentation (08947)
ok   floatRepresentation and depthBiasExact are not enabled (08948, 08949)
ok   the features are trimmed after they are queried
ok   DynState has bias_unorm
ok   bias_unorm only for an NVN D24 kept as D32, on a device with the extension
ok   the bias is set again when its unit changes
ok   vkCmdSetDepthBias2EXT with the extension
ok   FORCE_UNORM for bias_unorm, the format's unit otherwise
ok   vkCmdSetDepthBias without the extension
ok   the depthBiasClamp feature is read from the enabled features
ok   the game's bias clamp is 0 on a device without depthBiasClamp (00790, 08950)
all checks passed
test_d24_depth_bias                  exit 0

Flags and settings

None.

Testing

Tested: on this branch, Windows, Python 3.12: test_d24_depth_bias passes (fails on main).

Built and played: this commit builds on Windows (llvm-mingw back end) and on Linux (longshot_vk.so, without and with AMD FSR 4). Played on Windows, AMD Radeon RX 9070 XT: the game runs normally.

Not tested: shadows of a D24 kept as D32 were not compared with main; on main D24 is never kept as D32, so the FORCE_UNORM path does not run there. A GPU without VK_EXT_depth_bias_control was not run (the fallback is the call main makes). Linux was built, not run.

Must be tested: None.

Risks

What could break: on a device with the extension every bias is now set with vkCmdSetDepthBias2EXT; for targets other than a D24 kept as D32 it carries LEAST_REPRESENTABLE_VALUE_FORMAT_EXT, which is the unit vkCmdSetDepthBias uses, so their bias is the same.

Turning it off: revert the commit.

Compatibility: One more optional device extension, enabled only with its two features; nothing changes on devices without it.

Checklist

Everyone

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched). (no issue fits)
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main.
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named). (the check that reads the changed code, on this PR, Windows: test_d24_depth_bias passes)
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • A game-free test added for the fix, failing on main and passing here. (tests/test_d24_depth_bias.py)
  • A check under tests/ that reads changed source updated in this PR, not weakened. (tests/test_d24_depth_bias.py reads the four changed files)
  • Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths. (built on Windows with llvm-mingw and on Linux, longshot_vk.so without and with AMD FSR 4)
**Type:** feat · **Risk:** low · **Tested on:** Windows, AMD Radeon RX 9070 XT · **Needs:** none ## Why When a DEPTH24 or DEPTH24_STENCIL8 depth buffer is kept as `D32_SFLOAT` / `D32_SFLOAT_S8_UINT`, the game's depth bias, written for 24-bit unorm units, is applied in float units that shrink with the depth's exponent, so shadows show acne. `VK_EXT_depth_bias_control` lets the bias be given in unorm units on a float format. ## How to reproduce **Seen on:** reading `gpu/vk/vk_draw.cpp`: `dynamic_state()` calls `vkCmdSetDepthBias` with the game's factors whatever the image's format. On main `vk_format()` maps DEPTH24 and DEPTH24_STENCIL8 to the D24 formats on every GPU, so this path acts only where they are kept as D32 **Settings and switches:** defaults **Steps:** game-free: `python -I -B tests/test_d24_depth_bias.py --source <main checkout>` (the test from this PR) **Expected:** with the extension and its `leastRepresentableValueForceUnormRepresentation` feature, a D24 kept as D32 is biased with `FORCE_UNORM`; without it, `vkCmdSetDepthBias` as before **Actual:** on main the test fails its 13 checks, from "vk_loader.h loads vkCmdSetDepthBias2EXT" to "vkCmdSetDepthBias without the extension" ## What changed The device asks for `VK_EXT_depth_bias_control` and, where it has the feature, sets the bias of a D24 kept as D32 in 24-bit unorm units. - vk: `create_device()` in `gpu/vk/vk_main.cpp`: `optional(VK_EXT_DEPTH_BIAS_CONTROL_EXTENSION_NAME, dev.depth_bias_control)`; `VkPhysicalDeviceDepthBiasControlFeaturesEXT` in the features chain; kept only if `depthBiasControl` and `leastRepresentableValueForceUnormRepresentation` are both supported; `floatRepresentation` and `depthBiasExact` are set to `VK_FALSE` before the device is created. - vk: `gpu/vk/vk_internal.h`: `Device::depth_bias_control`. `gpu/vk/vk_loader.h`: loads `vkCmdSetDepthBias2EXT`. - vk: `dynamic_state()` in `gpu/vk/vk_draw.cpp`: `DynState::bias_unorm`, true for an NVN DEPTH24 / DEPTH24_STENCIL8 target whose image is `D32_SFLOAT` / `D32_SFLOAT_S8_UINT`, on a device with the extension. The bias is set again when `bias` or `bias_unorm` changes: `vkCmdSetDepthBias2EXT` with `VkDepthBiasRepresentationInfoEXT` (`LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT` for `bias_unorm`, `LEAST_REPRESENTABLE_VALUE_FORMAT_EXT` otherwise); without the extension, `vkCmdSetDepthBias` as on main. - tests: `tests/test_d24_depth_bias.py` (new). How it works, step by step: 1. On a floating-point depth attachment there is no single minimum resolvable difference: it is r = 2^(e-n), with e the maximum exponent of the depths the primitive spans and n the mantissa bits (primsrast.adoc, Depth Bias Computation). On a fixed-point attachment r is constant over the whole range, at most 2 x 2^-n with n the depth bits (2^-24 scale for `X8_D24_UNORM_PACK32`). 2. The game's factors are for a 24-bit unorm buffer. Kept as D32, they under-bias: shadow acne. 3. With `LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT`, r is constant over the whole range as for a fixed-point attachment, with n "the number of mantissa bits plus one when using a floating-point attachment" (primsrast.adoc, Depth Bias Computation): 24 for `D32_SFLOAT`, the same n as the game's 24-bit unorm depth. 4. Other targets keep `LEAST_REPRESENTABLE_VALUE_FORMAT_EXT`, the default unit, so their bias is unchanged. The Vulkan rules for the calls and structures this adds, from `validusage.json`: - VUID-VkDepthBiasRepresentationInfoEXT-leastRepresentableValueForceUnormRepresentation-08947: "If the leastRepresentableValueForceUnormRepresentation feature is not enabled, depthBiasRepresentation must not be VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT": met, `dev.depth_bias_control` is true only when the feature is supported and then enabled. - VUID-VkDepthBiasRepresentationInfoEXT-floatRepresentation-08948: "If the floatRepresentation feature is not enabled, depthBiasRepresentation must not be VK_DEPTH_BIAS_REPRESENTATION_FLOAT_EXT": met, `FLOAT_EXT` is never used. - VUID-VkDepthBiasRepresentationInfoEXT-depthBiasExact-08949: "If the depthBiasExact feature is not enabled, depthBiasExact must be VK_FALSE": met, `rep` is value-initialized, so `depthBiasExact` is `VK_FALSE`. - VUID-VkDepthBiasInfoEXT-depthBiasClamp-08950: "If the depthBiasClamp feature is not enabled, depthBiasClamp must be 0.0": the same value `vkCmdSetDepthBias` received on main (VUID-vkCmdSetDepthBias-depthBiasClamp-00790 has the same text). - VUID-VkDepthBiasInfoEXT-pNext-pNext: "pNext must be NULL or a pointer to a valid instance of VkDepthBiasRepresentationInfoEXT": met. - VUID-vkCmdSetDepthBias2EXT-commandBuffer-cmdpool: "The VkCommandPool that commandBuffer was allocated from must support VK_QUEUE_GRAPHICS_BIT operations": met, the same draw command buffer `vkCmdSetDepthBias` is recorded into. Before (`dynamic_state()`): ```cpp if (DYN_CHANGED(bias)) vkCmdSetDepthBias(cmd, d.bias[0], d.bias[1], d.bias[2]); ``` After: ```cpp d.bias_unorm = dev.depth_bias_control && depth && (at.depth->nvn_format == NVN_FORMAT_DEPTH24 || at.depth->nvn_format == NVN_FORMAT_DEPTH24_STENCIL8) && (at.depth_format == VK_FORMAT_D32_SFLOAT || at.depth_format == VK_FORMAT_D32_SFLOAT_S8_UINT); ... if (DYN_CHANGED(bias) || DYN_CHANGED(bias_unorm)) { if (dev.depth_bias_control && vkCmdSetDepthBias2EXT) { VkDepthBiasRepresentationInfoEXT rep{VK_STRUCTURE_TYPE_DEPTH_BIAS_REPRESENTATION_INFO_EXT}; rep.depthBiasRepresentation = d.bias_unorm ? VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT : VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT; VkDepthBiasInfoEXT bi{VK_STRUCTURE_TYPE_DEPTH_BIAS_INFO_EXT, &rep}; bi.depthBiasConstantFactor = d.bias[0], bi.depthBiasClamp = d.bias[1], bi.depthBiasSlopeFactor = d.bias[2]; vkCmdSetDepthBias2EXT(cmd, &bi); } else vkCmdSetDepthBias(cmd, d.bias[0], d.bias[1], d.bias[2]); } ``` `create_device()`, after the features are queried: ```cpp dev.depth_bias_control = dev.depth_bias_control && dbc.depthBiasControl && dbc.leastRepresentableValueForceUnormRepresentation; dbc.depthBiasControl = dbc.leastRepresentableValueForceUnormRepresentation = dev.depth_bias_control; dbc.floatRepresentation = VK_FALSE, dbc.depthBiasExact = VK_FALSE; ``` Second commit, "set no depth bias clamp where the depthBiasClamp feature is off": - vk: `dev.depth_bias_clamp` in `gpu/vk/vk_internal.h`, set in `gpu/vk/vk_main.cpp` from `f.features.depthBiasClamp`. - vk: `gpu/vk/vk_draw.cpp`: `if (!dev.depth_bias_clamp) d.bias[1] = 0.0f;` before the clamp is passed to the depth bias command. - tests: `tests/test_d24_depth_bias.py`: two checks for the gate. The clamp was passed as the game set it. VUID-vkCmdSetDepthBias-depthBiasClamp-00790 and VUID-VkDepthBiasInfoEXT-depthBiasClamp-08950: "If the depthBiasClamp feature is not enabled, depthBiasClamp must be 0.0". ## Measurements **Verdict:** it fixes the bug: `test_d24_depth_bias` fails on main and passes here. Both interleaved runs gave the same result. No speed change is expected. Hardware: AMD Radeon RX 9070 XT, Windows; the tests are game-free (they read source or build a cut-out fixture, they do not use the GPU); Python 3.12 Scene: none, game-free Method: the tests from this PR run against each side's checkout, 2 runs each, interleaved (main, PR, main, PR); the result is pass/fail, so the median is the result both runs gave How to reproduce: `python -I -B tests/<test>.py` with `--source <checkout>` (and `--cxx`/`--headers` where the test asks for them) on each side | | Before: main @ c167ec67 | After: this PR @ 7690969f | |---|---|---| | `tests/test_d24_depth_bias.py`, run 1 | fails | passes | | `tests/test_d24_depth_bias.py`, run 2 | fails | passes | | `tests/test_d24_depth_bias.py`, median | fails | passes | ``` run 1, main @ c167ec67: FAIL vk_loader.h loads vkCmdSetDepthBias2EXT FAIL Device has depth_bias_control FAIL create_device asks for VK_EXT_depth_bias_control FAIL its features are queried and enabled FAIL kept only with depthBiasControl and leastRepresentableValueForceUnormRepresentation (08947) FAIL floatRepresentation and depthBiasExact are not enabled (08948, 08949) FAIL the features are trimmed after they are queried FAIL DynState has bias_unorm FAIL bias_unorm only for an NVN D24 kept as D32, on a device with the extension FAIL the bias is set again when its unit changes FAIL vkCmdSetDepthBias2EXT with the extension FAIL FORCE_UNORM for bias_unorm, the format's unit otherwise FAIL vkCmdSetDepthBias without the extension FAIL the depthBiasClamp feature is read from the enabled features FAIL the game's bias clamp is 0 on a device without depthBiasClamp (00790, 08950) 15 check(s) failed test_d24_depth_bias exit 1 run 1, this PR @ 7690969f: ok vk_loader.h loads vkCmdSetDepthBias2EXT ok Device has depth_bias_control ok create_device asks for VK_EXT_depth_bias_control ok its features are queried and enabled ok kept only with depthBiasControl and leastRepresentableValueForceUnormRepresentation (08947) ok floatRepresentation and depthBiasExact are not enabled (08948, 08949) ok the features are trimmed after they are queried ok DynState has bias_unorm ok bias_unorm only for an NVN D24 kept as D32, on a device with the extension ok the bias is set again when its unit changes ok vkCmdSetDepthBias2EXT with the extension ok FORCE_UNORM for bias_unorm, the format's unit otherwise ok vkCmdSetDepthBias without the extension ok the depthBiasClamp feature is read from the enabled features ok the game's bias clamp is 0 on a device without depthBiasClamp (00790, 08950) all checks passed test_d24_depth_bias exit 0 run 2, main @ c167ec67: FAIL vk_loader.h loads vkCmdSetDepthBias2EXT FAIL Device has depth_bias_control FAIL create_device asks for VK_EXT_depth_bias_control FAIL its features are queried and enabled FAIL kept only with depthBiasControl and leastRepresentableValueForceUnormRepresentation (08947) FAIL floatRepresentation and depthBiasExact are not enabled (08948, 08949) FAIL the features are trimmed after they are queried FAIL DynState has bias_unorm FAIL bias_unorm only for an NVN D24 kept as D32, on a device with the extension FAIL the bias is set again when its unit changes FAIL vkCmdSetDepthBias2EXT with the extension FAIL FORCE_UNORM for bias_unorm, the format's unit otherwise FAIL vkCmdSetDepthBias without the extension FAIL the depthBiasClamp feature is read from the enabled features FAIL the game's bias clamp is 0 on a device without depthBiasClamp (00790, 08950) 15 check(s) failed test_d24_depth_bias exit 1 run 2, this PR @ 7690969f: ok vk_loader.h loads vkCmdSetDepthBias2EXT ok Device has depth_bias_control ok create_device asks for VK_EXT_depth_bias_control ok its features are queried and enabled ok kept only with depthBiasControl and leastRepresentableValueForceUnormRepresentation (08947) ok floatRepresentation and depthBiasExact are not enabled (08948, 08949) ok the features are trimmed after they are queried ok DynState has bias_unorm ok bias_unorm only for an NVN D24 kept as D32, on a device with the extension ok the bias is set again when its unit changes ok vkCmdSetDepthBias2EXT with the extension ok FORCE_UNORM for bias_unorm, the format's unit otherwise ok vkCmdSetDepthBias without the extension ok the depthBiasClamp feature is read from the enabled features ok the game's bias clamp is 0 on a device without depthBiasClamp (00790, 08950) all checks passed test_d24_depth_bias exit 0 ``` ### Flags and settings None. ## Testing **Tested:** on this branch, Windows, Python 3.12: `test_d24_depth_bias` passes (fails on main). **Built and played:** this commit builds on Windows (llvm-mingw back end) and on Linux (`longshot_vk.so`, without and with AMD FSR 4). Played on Windows, AMD Radeon RX 9070 XT: the game runs normally. **Not tested:** shadows of a D24 kept as D32 were not compared with main; on main D24 is never kept as D32, so the `FORCE_UNORM` path does not run there. A GPU without `VK_EXT_depth_bias_control` was not run (the fallback is the call main makes). Linux was built, not run. **Must be tested:** None. ## Risks **What could break:** on a device with the extension every bias is now set with `vkCmdSetDepthBias2EXT`; for targets other than a D24 kept as D32 it carries `LEAST_REPRESENTABLE_VALUE_FORMAT_EXT`, which is the unit `vkCmdSetDepthBias` uses, so their bias is the same. **Turning it off:** revert the commit. **Compatibility:** One more optional device extension, enabled only with its two features; nothing changes on devices without it. ## Checklist ### Everyone - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). (no issue fits) - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main`. - [x] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). (the check that reads the changed code, on this PR, Windows: `test_d24_depth_bias` passes) - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] A game-free test added for the fix, failing on `main` and passing here. (`tests/test_d24_depth_bias.py`) - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. (`tests/test_d24_depth_bias.py` reads the four changed files) - [x] Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths. (built on Windows with llvm-mingw and on Linux, `longshot_vk.so` without and with AMD FSR 4)
feat(vk): bias D24 kept as D32 in D24 units (VK_EXT_depth_bias_control)
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 3s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
1f9064e9f6
A float depth format's bias unit follows the depth's exponent, so a D24 depth the device keeps as D32_SFLOAT got the game's D24 bias too small (shadow acne). With VK_EXT_depth_bias_control (depthBiasControl and leastRepresentableValueForceUnormRepresentation) the bias of those draws is set with vkCmdSetDepthBias2EXT and FORCE_UNORM; without it vkCmdSetDepthBias as before.

Assisted-by: GitHub Copilot
Author
Contributor

Tested in game: Windows 11 IoT Enterprise LTSC 24H2 (build 26100.9711), AMD Radeon RX 9070 XT, AMD Software: Adrenalin Edition 26.10.1: played with this change; the game runs normally, no rendering errors or crashes seen.

Tested in game: Windows 11 IoT Enterprise LTSC 24H2 (build 26100.9711), AMD Radeon RX 9070 XT, AMD Software: Adrenalin Edition 26.10.1: played with this change; the game runs normally, no rendering errors or crashes seen.
Collaborator

Possibly related, for context:

  • PR #1033 feat(vk): fall back to D32 depth where the GPU lacks D24 — Adds D32 fallback that activates this bias path
  • PR #1051 WIP: feat(vk): write back DEPTH24 kept as D32_SFLOAT as 24-bit unorm — Adjacent D24-on-D32 readback work; same fallback path
Possibly related, for context: - PR #1033 feat(vk): fall back to D32 depth where the GPU lacks D24 — Adds D32 fallback that activates this bias path - PR #1051 WIP: feat(vk): write back DEPTH24 kept as D32_SFLOAT as 24-bit unorm — Adjacent D24-on-D32 readback work; same fallback path
jcabarca changed title from WIP: feat(vk): bias D24 kept as D32 in D24 units (VK_EXT_depth_bias_control) to feat(vk): bias D24 kept as D32 in D24 units (VK_EXT_depth_bias_control) 2026-11-16 05:04:59 +00:00
jcabarca force-pushed feat/vk-d24-depth-bias from 1f9064e9f6
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 3s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
to 7690969f7e
All checks were successful
PR description / Description follows the template (pull_request_target) Successful in 5s
2026-11-16 10:31:37 +00:00
Compare
Author
Contributor

New commit, "set no depth bias clamp where the depthBiasClamp feature is off" (7690969f); the branch is rebased onto main @ c167ec67.

The clamp was passed as the game set it. VUID-vkCmdSetDepthBias-depthBiasClamp-00790 and VUID-VkDepthBiasInfoEXT-depthBiasClamp-08950: "If the depthBiasClamp feature is not enabled, depthBiasClamp must be 0.0".

  • vk: dev.depth_bias_clamp in gpu/vk/vk_internal.h, set in gpu/vk/vk_main.cpp from f.features.depthBiasClamp.
  • vk: gpu/vk/vk_draw.cpp: if (!dev.depth_bias_clamp) d.bias[1] = 0.0f; before the clamp is passed to the depth bias command.
  • tests: tests/test_d24_depth_bias.py: two checks for the gate.

test_d24_depth_bias fails on main and passes here. Run twice each side, interleaved; What changed and Measurements in the description are updated.

New commit, "set no depth bias clamp where the depthBiasClamp feature is off" (7690969f); the branch is rebased onto main @ c167ec67. The clamp was passed as the game set it. VUID-vkCmdSetDepthBias-depthBiasClamp-00790 and VUID-VkDepthBiasInfoEXT-depthBiasClamp-08950: "If the depthBiasClamp feature is not enabled, depthBiasClamp must be 0.0". - vk: `dev.depth_bias_clamp` in `gpu/vk/vk_internal.h`, set in `gpu/vk/vk_main.cpp` from `f.features.depthBiasClamp`. - vk: `gpu/vk/vk_draw.cpp`: `if (!dev.depth_bias_clamp) d.bias[1] = 0.0f;` before the clamp is passed to the depth bias command. - tests: `tests/test_d24_depth_bias.py`: two checks for the gate. `test_d24_depth_bias` fails on main and passes here. Run twice each side, interleaved; What changed and Measurements in the description are updated.
Author
Contributor

This commit (both commits of the PR) builds on Windows (llvm-mingw back end) and on Linux (longshot_vk.so, without and with AMD FSR 4), and was played on Windows, AMD Radeon RX 9070 XT: the game runs normally. The description's Built and played line and the Host code builds box are updated.

This commit (both commits of the PR) builds on Windows (llvm-mingw back end) and on Linux (`longshot_vk.so`, without and with AMD FSR 4), and was played on Windows, AMD Radeon RX 9070 XT: the game runs normally. The description's Built and played line and the Host code builds box are updated.
Author
Contributor

This commit (both commits of the PR) builds on Windows (llvm-mingw back end) and on Linux (longshot_vk.so, without and with AMD FSR 4), and was played on Windows, AMD Radeon RX 9070 XT: the game runs normally. The description's Built and played line and the Host code builds box are updated.

This commit (both commits of the PR) builds on Windows (llvm-mingw back end) and on Linux (`longshot_vk.so`, without and with AMD FSR 4), and was played on Windows, AMD Radeon RX 9070 XT: the game runs normally. The description's Built and played line and the Host code builds box are updated.
Merge branch 'main' into feat/vk-d24-depth-bias
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 5s
8d98d050a1
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 5s
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'feat/vk-d24-depth-bias:jcabarca-feat/vk-d24-depth-bias'
git switch 'jcabarca-feat/vk-d24-depth-bias'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!1052
No description provided.