feat(vk): fall back to D32 depth where the GPU lacks D24 #1033

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

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_PACK32 or D24_UNORM_S8_UINT as depth attachments, so on them the game's DEPTH24 and DEPTH24_STENCIL8 depth buffers had no usable Vulkan format. Vulkan guarantees the D32_SFLOAT / D32_SFLOAT_S8_UINT twin 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): vkGetPhysicalDeviceFormatProperties reports no DEPTH_STENCIL_ATTACHMENT for both D24 formats; the same holds on RDNA 2 and 3
Settings 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 reads vk_formats.cpp and vk_texture.cpp and runs depth24_or_32() against made-up GPUs
Expected: on a GPU without D24 depth attachments, DEPTH24 maps to D32_SFLOAT and DEPTH24_STENCIL8 to D32_SFLOAT_S8_UINT, and their uploads turn the guest's 24-bit words into floats
Actual: 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).

  • vk: new depth24_or_32() in gpu/vk/vk_formats.cpp: asks the GPU once per format; keeps the D24 format if it has DEPTH_STENCIL_ATTACHMENT and SAMPLED_IMAGE; else uses the D32 twin only if the twin has those plus TRANSFER_SRC and TRANSFER_DST; else keeps the D24 format. One log line says which.
  • vk: 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).
  • vk: upload_inner() in gpu/vk/vk_texture.cpp:
    • DEPTH24 kept as D32_SFLOAT: each 32-bit guest word's low 24 bits become v / 16777215.0f.
    • DEPTH24_STENCIL8 kept as 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: tests/test_d24_fallback.py (new); test_pipeline_state_portable, test_pipeline_states and test_texture_staging_publication follow the new code (the cut-out vk_format now needs depth24_or_32; the regex reads a wrapped format; the cut-out upload slice declares the new locals).

How it works, step by step:

  1. vk_format() is asked for DEPTH24 or DEPTH24_STENCIL8; depth24_or_32() queries optimalTilingFeatures of the D24 format once and caches the answer.
  2. If the D24 format can be a depth attachment and be sampled, it is kept: nothing changes on GPUs that have it (NVIDIA, Intel).
  3. Otherwise the twin is queried. D32_SFLOAT must support depth attachments, sampling and transfers whenever X8_D24 does not (formats.adoc, the mandatory table), but D32_SFLOAT_S8_UINT need 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.
  4. Upload of DEPTH24 into D32_SFLOAT: the buffer for a depth aspect copy is laid out in the aspect's format (copies.adoc, Depth/Stencil Aspect Copy: D32_SFLOAT depth reads as D32_SFLOAT), so the guest's unorm words are converted to floats on the CPU first.
  5. Upload of DEPTH24_STENCIL8 into D32_SFLOAT_S8_UINT: the same table says the stencil aspect is copied as S8_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 with aspectMask = STENCIL.

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

  • VUID-vkCmdCopyBufferToImage-dstImage-01997: "The format features of dstImage must contain VK_FORMAT_FEATURE_TRANSFER_DST_BIT": met, the twin is used only when it has TRANSFER_DST (and TRANSFER_SRC for the copies out).
  • VUID-VkBufferImageCopy-aspectMask-09103: "The aspectMask member of imageSubresource must only have a single bit set": met, the depth copy has DEPTH only and the stencil copy STENCIL only (before, a D24S8 image had both bits and was dropped).
  • VUID-vkCmdCopyBufferToImage-imageSubresource-09105: "For each element of pRegions, imageSubresource.aspectMask must specify aspects present in dstImage": met, D32_SFLOAT_S8_UINT has both aspects.
  • VUID-vkCmdCopyBufferToImage-dstImage-07978: "If dstImage has a depth/stencil format, the bufferOffset member of any element of pRegions must be a multiple of 4": met, staging offsets are 16-byte aligned and the stencil area starts at s_off, the depth size rounded up to 16.
  • vkGetPhysicalDeviceFormatProperties: no new rule beyond a valid physical device, which dev.physical is (as elsewhere on main).

Before (vk_format() in vk_formats.cpp):

    case NVN_FORMAT_DEPTH24: return {VK_FORMAT_X8_D24_UNORM_PACK32, false, 1, 1};
    case NVN_FORMAT_DEPTH32F: return {VK_FORMAT_D32_SFLOAT, false, 1, 1};
    case NVN_FORMAT_DEPTH24_STENCIL8: return {VK_FORMAT_D24_UNORM_S8_UINT, false, 1, 1};

After:

VkFormat depth24_or_32(VkFormat d24, VkFormat d32) {
    static signed char known[2] = {-1, -1};
    signed char& k = known[d24 == VK_FORMAT_D24_UNORM_S8_UINT ? 1 : 0];
    if (k < 0) {
        const VkFormatFeatureFlags need = VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT |
                                          VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
        const VkFormatFeatureFlags twin = need | VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
                                          VK_FORMAT_FEATURE_TRANSFER_DST_BIT;
        VkFormatProperties p{}, q{};
        vkGetPhysicalDeviceFormatProperties(dev.physical, d24, &p);
        k = (p.optimalTilingFeatures & need) == need ? 1 : 0;
        if (!k) {
            vkGetPhysicalDeviceFormatProperties(dev.physical, d32, &q);
            k = (q.optimalTilingFeatures & twin) == twin ? 0 : 1;
            ...
        }
    }
    return k ? d24 : d32;
}
...
    case NVN_FORMAT_DEPTH24: return {depth24_or_32(VK_FORMAT_X8_D24_UNORM_PACK32, VK_FORMAT_D32_SFLOAT), false, 1, 1};
    case NVN_FORMAT_DEPTH32F: return {VK_FORMAT_D32_SFLOAT, false, 1, 1};
    case NVN_FORMAT_DEPTH24_STENCIL8: return {depth24_or_32(VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT), false, 1, 1};

upload_inner() in vk_texture.cpp, after (the conversion, and the stencil copy):

                } else if (tex.nvn_format == NVN_FORMAT_DEPTH24 && tex.format == VK_FORMAT_D32_SFLOAT) {
                    for (uint64_t i = 0; i + 4 <= out_bytes; i += 4) {
                        uint32_t v;
                        std::memcpy(&v, out + i, 4);
                        const float f = (float)(v & 0xffffffu) / 16777215.0f;
                        std::memcpy(out + i, &f, 4);
                    }
                } else if (d24s8_as_d32) {
                    uint8_t* sten = out + s_off;
                    for (uint64_t i = 0; i + 4 <= out_bytes; i += 4) {
                        ...
                        sten[i / 4] = (uint8_t)(v >> 24);
                    }
                }
...
                copies.push_back(c);
                if (d24s8_as_d32) {
                    c.bufferOffset = st.offset + s_off;
                    c.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
                    copies.push_back(c);
                }

Measurements

Verdict: it adds the fallback: tests/test_d24_fallback.py fails 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.py from this PR with --source set 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 gave
How to reproduce: python -I -B tests/test_d24_fallback.py --source <checkout> --headers <Vulkan headers> --cxx clang++ for each side

Before: main @ cefce0d1 After: this PR @ 114b1d58
tests/test_d24_fallback.py, run 1 fails passes
tests/test_d24_fallback.py, run 2 fails passes
Median fails passes
run 1, main @ cefce0d1:
vk_format keeps the D24 formats on every GPU: no depth24_or_32
exit 1
run 1, this PR @ 114b1d58:
DEPTH24 / DEPTH24_STENCIL8 fall back to D32 and are uploaded converted: ok
exit 0
run 2, main @ cefce0d1:
vk_format keeps the D24 formats on every GPU: no depth24_or_32
exit 1
run 2, this PR @ 114b1d58:
DEPTH24 / DEPTH24_STENCIL8 fall back to D32 and are uploaded converted: ok
exit 0

What the test checks:

  • vk_format() maps DEPTH24 and DEPTH24_STENCIL8 through depth24_or_32().
  • upload_inner() converts DEPTH24 words to floats, no longer drops DEPTH24_STENCIL8 kept as D32_SFLOAT_S8_UINT, splits the stencil byte, queues the stencil copy and flushes the stencil bytes.
  • The real 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 whose D32_SFLOAT_S8_UINT cannot be copied keeps D24_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_fallback passes (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

  • 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 checks that read the changed code, on this PR, Windows: test_d24_fallback, test_pipeline_state_portable, test_pipeline_states, test_texture_staging_publication pass)
  • 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_fallback.py)
  • A check under tests/ that reads changed source updated in this PR, not weakened. (test_pipeline_state_portable, test_pipeline_states and test_texture_staging_publication follow the new code; nothing they checked was removed)
  • 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; no OS-specific code or paths)
**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_PACK32` or `D24_UNORM_S8_UINT` as depth attachments, so on them the game's DEPTH24 and DEPTH24_STENCIL8 depth buffers had no usable Vulkan format. Vulkan guarantees the `D32_SFLOAT` / `D32_SFLOAT_S8_UINT` twin 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): `vkGetPhysicalDeviceFormatProperties` reports no `DEPTH_STENCIL_ATTACHMENT` for both D24 formats; the same holds on RDNA 2 and 3 **Settings 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 reads `vk_formats.cpp` and `vk_texture.cpp` and runs `depth24_or_32()` against made-up GPUs **Expected:** on a GPU without D24 depth attachments, DEPTH24 maps to `D32_SFLOAT` and DEPTH24_STENCIL8 to `D32_SFLOAT_S8_UINT`, and their uploads turn the guest's 24-bit words into floats **Actual:** 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). - vk: new `depth24_or_32()` in `gpu/vk/vk_formats.cpp`: asks the GPU once per format; keeps the D24 format if it has `DEPTH_STENCIL_ATTACHMENT` and `SAMPLED_IMAGE`; else uses the D32 twin only if the twin has those plus `TRANSFER_SRC` and `TRANSFER_DST`; else keeps the D24 format. One log line says which. - vk: `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)`. - vk: `upload_inner()` in `gpu/vk/vk_texture.cpp`: - DEPTH24 kept as `D32_SFLOAT`: each 32-bit guest word's low 24 bits become `v / 16777215.0f`. - DEPTH24_STENCIL8 kept as `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: `tests/test_d24_fallback.py` (new); `test_pipeline_state_portable`, `test_pipeline_states` and `test_texture_staging_publication` follow the new code (the cut-out `vk_format` now needs `depth24_or_32`; the regex reads a wrapped format; the cut-out upload slice declares the new locals). How it works, step by step: 1. `vk_format()` is asked for DEPTH24 or DEPTH24_STENCIL8; `depth24_or_32()` queries `optimalTilingFeatures` of the D24 format once and caches the answer. 2. If the D24 format can be a depth attachment and be sampled, it is kept: nothing changes on GPUs that have it (NVIDIA, Intel). 3. Otherwise the twin is queried. `D32_SFLOAT` must support depth attachments, sampling and transfers whenever `X8_D24` does not (formats.adoc, the mandatory table), but `D32_SFLOAT_S8_UINT` need 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. 4. Upload of DEPTH24 into `D32_SFLOAT`: the buffer for a depth aspect copy is laid out in the aspect's format (copies.adoc, Depth/Stencil Aspect Copy: `D32_SFLOAT` depth reads as `D32_SFLOAT`), so the guest's unorm words are converted to floats on the CPU first. 5. Upload of DEPTH24_STENCIL8 into `D32_SFLOAT_S8_UINT`: the same table says the stencil aspect is copied as `S8_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 with `aspectMask = STENCIL`. The Vulkan rules for the calls and structures this adds, from `validusage.json`: - VUID-vkCmdCopyBufferToImage-dstImage-01997: "The format features of dstImage must contain VK_FORMAT_FEATURE_TRANSFER_DST_BIT": met, the twin is used only when it has `TRANSFER_DST` (and `TRANSFER_SRC` for the copies out). - VUID-VkBufferImageCopy-aspectMask-09103: "The aspectMask member of imageSubresource must only have a single bit set": met, the depth copy has `DEPTH` only and the stencil copy `STENCIL` only (before, a D24S8 image had both bits and was dropped). - VUID-vkCmdCopyBufferToImage-imageSubresource-09105: "For each element of pRegions, imageSubresource.aspectMask must specify aspects present in dstImage": met, `D32_SFLOAT_S8_UINT` has both aspects. - VUID-vkCmdCopyBufferToImage-dstImage-07978: "If dstImage has a depth/stencil format, the bufferOffset member of any element of pRegions must be a multiple of 4": met, staging offsets are 16-byte aligned and the stencil area starts at `s_off`, the depth size rounded up to 16. - `vkGetPhysicalDeviceFormatProperties`: no new rule beyond a valid physical device, which `dev.physical` is (as elsewhere on main). Before (`vk_format()` in `vk_formats.cpp`): ```cpp case NVN_FORMAT_DEPTH24: return {VK_FORMAT_X8_D24_UNORM_PACK32, false, 1, 1}; case NVN_FORMAT_DEPTH32F: return {VK_FORMAT_D32_SFLOAT, false, 1, 1}; case NVN_FORMAT_DEPTH24_STENCIL8: return {VK_FORMAT_D24_UNORM_S8_UINT, false, 1, 1}; ``` After: ```cpp VkFormat depth24_or_32(VkFormat d24, VkFormat d32) { static signed char known[2] = {-1, -1}; signed char& k = known[d24 == VK_FORMAT_D24_UNORM_S8_UINT ? 1 : 0]; if (k < 0) { const VkFormatFeatureFlags need = VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT; const VkFormatFeatureFlags twin = need | VK_FORMAT_FEATURE_TRANSFER_SRC_BIT | VK_FORMAT_FEATURE_TRANSFER_DST_BIT; VkFormatProperties p{}, q{}; vkGetPhysicalDeviceFormatProperties(dev.physical, d24, &p); k = (p.optimalTilingFeatures & need) == need ? 1 : 0; if (!k) { vkGetPhysicalDeviceFormatProperties(dev.physical, d32, &q); k = (q.optimalTilingFeatures & twin) == twin ? 0 : 1; ... } } return k ? d24 : d32; } ... case NVN_FORMAT_DEPTH24: return {depth24_or_32(VK_FORMAT_X8_D24_UNORM_PACK32, VK_FORMAT_D32_SFLOAT), false, 1, 1}; case NVN_FORMAT_DEPTH32F: return {VK_FORMAT_D32_SFLOAT, false, 1, 1}; case NVN_FORMAT_DEPTH24_STENCIL8: return {depth24_or_32(VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT), false, 1, 1}; ``` `upload_inner()` in `vk_texture.cpp`, after (the conversion, and the stencil copy): ```cpp } else if (tex.nvn_format == NVN_FORMAT_DEPTH24 && tex.format == VK_FORMAT_D32_SFLOAT) { for (uint64_t i = 0; i + 4 <= out_bytes; i += 4) { uint32_t v; std::memcpy(&v, out + i, 4); const float f = (float)(v & 0xffffffu) / 16777215.0f; std::memcpy(out + i, &f, 4); } } else if (d24s8_as_d32) { uint8_t* sten = out + s_off; for (uint64_t i = 0; i + 4 <= out_bytes; i += 4) { ... sten[i / 4] = (uint8_t)(v >> 24); } } ... copies.push_back(c); if (d24s8_as_d32) { c.bufferOffset = st.offset + s_off; c.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; copies.push_back(c); } ``` ## Measurements **Verdict:** it adds the fallback: `tests/test_d24_fallback.py` fails 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.py` from this PR with `--source` set 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 gave How to reproduce: `python -I -B tests/test_d24_fallback.py --source <checkout> --headers <Vulkan headers> --cxx clang++` for each side | | Before: main @ cefce0d1 | After: this PR @ 114b1d58 | |---|---|---| | `tests/test_d24_fallback.py`, run 1 | fails | passes | | `tests/test_d24_fallback.py`, run 2 | fails | passes | | Median | fails | passes | ``` run 1, main @ cefce0d1: vk_format keeps the D24 formats on every GPU: no depth24_or_32 exit 1 run 1, this PR @ 114b1d58: DEPTH24 / DEPTH24_STENCIL8 fall back to D32 and are uploaded converted: ok exit 0 run 2, main @ cefce0d1: vk_format keeps the D24 formats on every GPU: no depth24_or_32 exit 1 run 2, this PR @ 114b1d58: DEPTH24 / DEPTH24_STENCIL8 fall back to D32 and are uploaded converted: ok exit 0 ``` What the test checks: - `vk_format()` maps DEPTH24 and DEPTH24_STENCIL8 through `depth24_or_32()`. - `upload_inner()` converts DEPTH24 words to floats, no longer drops DEPTH24_STENCIL8 kept as `D32_SFLOAT_S8_UINT`, splits the stencil byte, queues the stencil copy and flushes the stencil bytes. - The real `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 whose `D32_SFLOAT_S8_UINT` cannot be copied keeps `D24_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_fallback` passes (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 - [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 checks that read the changed code, on this PR, Windows: `test_d24_fallback`, `test_pipeline_state_portable`, `test_pipeline_states`, `test_texture_staging_publication` pass) - [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_fallback.py`) - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. (`test_pipeline_state_portable`, `test_pipeline_states` and `test_texture_staging_publication` follow the new code; nothing they checked was removed) - [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; no OS-specific code or paths)
AMD RDNA 2-4 have neither X8_D24_UNORM_PACK32 nor D24_UNORM_S8_UINT as depth attachments. depth24_or_32 asks the GPU and gives D32_SFLOAT / D32_SFLOAT_S8_UINT there; upload() turns the guest's 24-bit unorm words into floats and splits DEPTH24_STENCIL8 into depth floats and stencil bytes (second copy).

Assisted-by: GitHub Copilot
feat(vk): use the D32 depth twin only where the GPU can render to, sample and copy it
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
114b1d583b
D32_SFLOAT_S8_UINT need not support sampling nor transfers (VUID-vkCmdCopyBufferToImage-dstImage-01997); keep the D24 format where its twin lacks them.

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 (this GPU supports D24, so it keeps the D24 formats), 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 (this GPU supports D24, so it keeps the D24 formats), no rendering errors or crashes seen.
Collaborator

Possibly related, for context:

  • issue #986 Game: AMD driver timeout when loading any save on RX 7900 XTX — AMD save-load driver timeout; potentially addressed by D24 fallback
Possibly related, for context: - issue #986 Game: AMD driver timeout when loading any save on RX 7900 XTX — AMD save-load driver timeout; potentially addressed by D24 fallback
jcabarca changed title from WIP: feat(vk): fall back to D32 depth where the GPU lacks D24 to feat(vk): fall back to D32 depth where the GPU lacks D24 2026-11-16 04:12:48 +00:00
Merge branch 'main' into feat/vk-d24-fallback
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 / The same as upstream (pull_request) Blocked by required conditions
Third-party parts / As their notes say (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 6s
45a2a9970f
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 / The same as upstream (pull_request) Blocked by required conditions
Third-party parts / As their notes say (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 6s
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-fallback:jcabarca-feat/vk-d24-fallback'
git switch 'jcabarca-feat/vk-d24-fallback'
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!1033
No description provided.