feat(vk): bias D24 kept as D32 in D24 units (VK_EXT_depth_bias_control) #1052
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1052
Loading…
Reference in a new issue
No description provided.
Delete branch "jcabarca/Longshot:feat/vk-d24-depth-bias"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_controllets the bias be given in unorm units on a float format.How to reproduce
Seen on: reading
gpu/vk/vk_draw.cpp:dynamic_state()callsvkCmdSetDepthBiaswith the game's factors whatever the image's format. On mainvk_format()maps DEPTH24 and DEPTH24_STENCIL8 to the D24 formats on every GPU, so this path acts only where they are kept as D32Settings 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
leastRepresentableValueForceUnormRepresentationfeature, a D24 kept as D32 is biased withFORCE_UNORM; without it,vkCmdSetDepthBiasas beforeActual: 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_controland, where it has the feature, sets the bias of a D24 kept as D32 in 24-bit unorm units.create_device()ingpu/vk/vk_main.cpp:optional(VK_EXT_DEPTH_BIAS_CONTROL_EXTENSION_NAME, dev.depth_bias_control);VkPhysicalDeviceDepthBiasControlFeaturesEXTin the features chain; kept only ifdepthBiasControlandleastRepresentableValueForceUnormRepresentationare both supported;floatRepresentationanddepthBiasExactare set toVK_FALSEbefore the device is created.gpu/vk/vk_internal.h:Device::depth_bias_control.gpu/vk/vk_loader.h: loadsvkCmdSetDepthBias2EXT.dynamic_state()ingpu/vk/vk_draw.cpp:DynState::bias_unorm, true for an NVN DEPTH24 / DEPTH24_STENCIL8 target whose image isD32_SFLOAT/D32_SFLOAT_S8_UINT, on a device with the extension. The bias is set again whenbiasorbias_unormchanges:vkCmdSetDepthBias2EXTwithVkDepthBiasRepresentationInfoEXT(LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXTforbias_unorm,LEAST_REPRESENTABLE_VALUE_FORMAT_EXTotherwise); without the extension,vkCmdSetDepthBiasas on main.tests/test_d24_depth_bias.py(new).How it works, step by step:
X8_D24_UNORM_PACK32).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 forD32_SFLOAT, the same n as the game's 24-bit unorm depth.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:dev.depth_bias_controlis true only when the feature is supported and then enabled.FLOAT_EXTis never used.repis value-initialized, sodepthBiasExactisVK_FALSE.vkCmdSetDepthBiasreceived on main (VUID-vkCmdSetDepthBias-depthBiasClamp-00790 has the same text).vkCmdSetDepthBiasis recorded into.Before (
dynamic_state()):After:
create_device(), after the features are queried:Second commit, "set no depth bias clamp where the depthBiasClamp feature is off":
dev.depth_bias_clampingpu/vk/vk_internal.h, set ingpu/vk/vk_main.cppfromf.features.depthBiasClamp.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/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_biasfails 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>.pywith--source <checkout>(and--cxx/--headerswhere the test asks for them) on each sidec167ec677690969ftests/test_d24_depth_bias.py, run 1tests/test_d24_depth_bias.py, run 2tests/test_d24_depth_bias.py, medianFlags and settings
None.
Testing
Tested: on this branch, Windows, Python 3.12:
test_d24_depth_biaspasses (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_UNORMpath does not run there. A GPU withoutVK_EXT_depth_bias_controlwas 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 carriesLEAST_REPRESENTABLE_VALUE_FORMAT_EXT, which is the unitvkCmdSetDepthBiasuses, 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
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named). (the check that reads the changed code, on this PR, Windows:test_d24_depth_biaspasses)third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here. (tests/test_d24_depth_bias.py)tests/that reads changed source updated in this PR, not weakened. (tests/test_d24_depth_bias.pyreads the four changed files)longshot_vk.sowithout and with AMD FSR 4)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.
Possibly related, for context:
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)1f9064e9f67690969f7eNew 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".
dev.depth_bias_clampingpu/vk/vk_internal.h, set ingpu/vk/vk_main.cppfromf.features.depthBiasClamp.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/test_d24_depth_bias.py: two checks for the gate.test_d24_depth_biasfails on main and passes here. Run twice each side, interleaved; What changed and Measurements in the description 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.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.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.