feat(vk): fall back to D32 depth where the GPU lacks D24 #1033
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!1033
Loading…
Reference in a new issue
No description provided.
Delete branch "jcabarca/Longshot:feat/vk-d24-fallback"
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: medium · Tested on: Windows, AMD Radeon RX 9070 XT · Needs: none
Why
AMD GPUs (RDNA 2, 3 and 4) cannot use
X8_D24_UNORM_PACK32orD24_UNORM_S8_UINTas depth attachments, so on them the game's DEPTH24 and DEPTH24_STENCIL8 depth buffers had no usable Vulkan format. Vulkan guarantees theD32_SFLOAT/D32_SFLOAT_S8_UINTtwin instead (formats.adoc, mandatory depth-stencil features: "at least one of X8_D24_UNORM_PACK32 and D32_SFLOAT ... at least one of D24_UNORM_S8_UINT and D32_SFLOAT_S8_UINT").How to reproduce
Seen on: AMD Radeon RX 9070 XT, Windows (RDNA 4):
vkGetPhysicalDeviceFormatPropertiesreports noDEPTH_STENCIL_ATTACHMENTfor both D24 formats; the same holds on RDNA 2 and 3Settings and switches: defaults
Steps: game-free:
python -I -B tests/test_d24_fallback.py --source <main checkout> --headers <Vulkan headers> --cxx clang++(the test from this PR); it readsvk_formats.cppandvk_texture.cppand runsdepth24_or_32()against made-up GPUsExpected: on a GPU without D24 depth attachments, DEPTH24 maps to
D32_SFLOATand DEPTH24_STENCIL8 toD32_SFLOAT_S8_UINT, and their uploads turn the guest's 24-bit words into floatsActual: on main
vk_format()returns the D24 formats on every GPU; the test fails with "vk_format keeps the D24 formats on every GPU: no depth24_or_32"What changed
Where the GPU cannot render to or sample a D24 depth format, DEPTH24 and DEPTH24_STENCIL8 use their 32-bit float twin, and uploads convert the guest's packed 24-bit depth (and split out the stencil byte).
depth24_or_32()ingpu/vk/vk_formats.cpp: asks the GPU once per format; keeps the D24 format if it hasDEPTH_STENCIL_ATTACHMENTandSAMPLED_IMAGE; else uses the D32 twin only if the twin has those plusTRANSFER_SRCandTRANSFER_DST; else keeps the D24 format. One log line says which.vk_format(): DEPTH24 ->depth24_or_32(X8_D24_UNORM_PACK32, D32_SFLOAT), DEPTH24_STENCIL8 ->depth24_or_32(D24_UNORM_S8_UINT, D32_SFLOAT_S8_UINT).upload_inner()ingpu/vk/vk_texture.cpp:D32_SFLOAT: each 32-bit guest word's low 24 bits becomev / 16777215.0f.D32_SFLOAT_S8_UINT(non-sparse) is no longer dropped: the depth floats and the stencil bytes (v >> 24) go into the same staging, and two copies are queued, one per aspect.tests/test_d24_fallback.py(new);test_pipeline_state_portable,test_pipeline_statesandtest_texture_staging_publicationfollow the new code (the cut-outvk_formatnow needsdepth24_or_32; the regex reads a wrapped format; the cut-out upload slice declares the new locals).How it works, step by step:
vk_format()is asked for DEPTH24 or DEPTH24_STENCIL8;depth24_or_32()queriesoptimalTilingFeaturesof the D24 format once and caches the answer.D32_SFLOATmust support depth attachments, sampling and transfers wheneverX8_D24does not (formats.adoc, the mandatory table), butD32_SFLOAT_S8_UINTneed not be sampled nor copied, so the twin is used only when it has all four features; else the D24 format is kept and logged.D32_SFLOAT: the buffer for a depth aspect copy is laid out in the aspect's format (copies.adoc, Depth/Stencil Aspect Copy:D32_SFLOATdepth reads asD32_SFLOAT), so the guest's unorm words are converted to floats on the CPU first.D32_SFLOAT_S8_UINT: the same table says the stencil aspect is copied asS8_UINT, one byte a texel in its own plane, so the top byte of each word goes to a second area after the floats and gets its own copy withaspectMask = STENCIL.The Vulkan rules for the calls and structures this adds, from
validusage.json:TRANSFER_DST(andTRANSFER_SRCfor the copies out).DEPTHonly and the stencil copySTENCILonly (before, a D24S8 image had both bits and was dropped).D32_SFLOAT_S8_UINThas both aspects.s_off, the depth size rounded up to 16.vkGetPhysicalDeviceFormatProperties: no new rule beyond a valid physical device, whichdev.physicalis (as elsewhere on main).Before (
vk_format()invk_formats.cpp):After:
upload_inner()invk_texture.cpp, after (the conversion, and the stencil copy):Measurements
Verdict: it adds the fallback:
tests/test_d24_fallback.pyfails on main and passes with this PR, in both interleaved runs. On GPUs that support D24 depth nothing changes (the test checks that the D24 formats are kept there).Hardware: AMD Radeon RX 9070 XT, Windows; the test itself is game-free (it reads source and runs
depth24_or_32()against made-up GPUs, it does not use the real one); Python 3.12, clang++ (llvm-mingw)Scene: none, game-free
Method:
tests/test_d24_fallback.pyfrom this PR with--sourceset to 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 gaveHow to reproduce:
python -I -B tests/test_d24_fallback.py --source <checkout> --headers <Vulkan headers> --cxx clang++for each sidecefce0d1114b1d58tests/test_d24_fallback.py, run 1tests/test_d24_fallback.py, run 2What the test checks:
vk_format()maps DEPTH24 and DEPTH24_STENCIL8 throughdepth24_or_32().upload_inner()converts DEPTH24 words to floats, no longer drops DEPTH24_STENCIL8 kept asD32_SFLOAT_S8_UINT, splits the stencil byte, queues the stencil copy and flushes the stencil bytes.depth24_or_32(), compiled against three made-up GPUs: one without D24 depth (AMD-like) gets both twins; one with D24 keeps both D24 formats; one whoseD32_SFLOAT_S8_UINTcannot be copied keepsD24_UNORM_S8_UINT. Three log lines in total.Flags and settings
None.
Testing
Tested: on this branch, Windows, Python 3.12, clang++ (llvm-mingw):
test_d24_fallbackpasses (fails on main), and the other checks that read the changed code pass:test_pipeline_state_portable,test_pipeline_states,test_texture_staging_publication.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: a GPU that has the D24 formats (NVIDIA, Intel): there
depth24_or_32()keeps them, which the test covers on a made-up GPU but nobody ran on real hardware. A scene was not compared side by side with main for depth precision. Linux was built, not run.Must be tested: None: on GPUs with D24 depth the formats are unchanged; the made-up-GPU cases in the test cover the choice.
Risks
What could break: depth tests and shadow maps on AMD GPUs now run on 32-bit float depth instead of having no depth format; a value the game compares bit-for-bit against 24-bit depth could differ slightly. DEPTH24_STENCIL8 textures that were dropped on upload are now uploaded. Copies of these textures out to buffers still return floats (that conversion is a separate change).
Turning it off: revert the commit.
Compatibility: On AMD GPUs the pipelines with these depth formats are made again (their attachment format changes); the pipeline cache rebuilds them on first use. Nothing changes on GPUs with D24 depth.
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 checks that read the changed code, on this PR, Windows:test_d24_fallback,test_pipeline_state_portable,test_pipeline_states,test_texture_staging_publicationpass)third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here. (tests/test_d24_fallback.py)tests/that reads changed source updated in this PR, not weakened. (test_pipeline_state_portable,test_pipeline_statesandtest_texture_staging_publicationfollow the new code; nothing they checked was removed)longshot_vk.sowithout and with AMD FSR 4; no OS-specific code or paths)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 (this GPU supports D24, so it keeps the D24 formats), no rendering errors or crashes seen.
Possibly related, for context:
WIP: feat(vk): fall back to D32 depth where the GPU lacks D24to feat(vk): fall back to D32 depth where the GPU lacks D24View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.