fix(vk): make a sparse BC image with the usage its sparse residency was checked for #671

Open
jcabarca wants to merge 3 commits from jcabarca/Longshot:fix/vk-sparse-bc-usage into main
Contributor

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

Why

A 2D array texture too big to keep whole is made as a sparse image, but for BC formats the driver is asked whether it supports sparse residency with transfer and sampled usage only, and the image is then made with storage and color attachment usage too. That is a combination the driver never said it supports sparse; a driver that refuses it loses the texture (vk: sparse image ... not made).

How to reproduce

Seen on: not seen in the game: found by reading create() in gpu/vk/vk_texture.cpp; it can happen whenever a BC 2D array bigger than the texture budget's limit is made sparse on a GPU with sparse residency
Settings and switches: defaults
Steps: game-free: python -I -B tests/test_sparse_bc_usage.py on main (copy the test from this PR); it reads the sparse residency query and the sparse image's creation in vk_texture.cpp
Expected: the sparse image is made with the usage its sparse residency was asked with
Actual: on main a sparse BC image is made with STORAGE and COLOR_ATTACHMENT usage, which the query left out; the test fails

What changed

A sparse BC image now drops STORAGE and COLOR_ATTACHMENT from its usage before vkCreateImage, so it is made with the usage its sparse residency was asked with. A compressed image the driver refuses already loses these two usages a few lines below, and its raw block views then follow x.usage and are not made; the sparse BC image now does the same from the start.

  • vk: create() in gpu/vk/vk_texture.cpp: inside if (x.sparse), before vkCreateImage, if (is_bc(x.format)) ci.usage &= ~(VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT), x.usage = ci.usage;. Non-BC sparse images and non-sparse images are unchanged.
  • tests: tests/test_sparse_bc_usage.py (new) fails if the sparse BC image is made without dropping these two usages.

Second commit, "make a sparse image only within its format's limits for the sparse flags and usage":

  • vk: create() in gpu/vk/vk_texture.cpp: before vkCreateImage for a sparse image, vkGetPhysicalDeviceImageFormatProperties is called with the image's format, type, tiling, usage and flags (the sparse ones included); the image is made only if the call succeeds and its extent, levels, layers and samples fit the answer; otherwise it takes the existing path for a sparse image that could not be made.
  • tests: tests/test_sparse_bc_usage.py checks the query and the gate.

The sparse path asked only vkGetPhysicalDeviceSparseImageFormatProperties, which says nothing of the image limits for those flags and that usage. VUID-VkImageCreateInfo-imageCreateMaxMipLevels-02251: "Each of the following values (as described in Image Creation Limits) must not be undefined : imageCreateMaxMipLevels, imageCreateMaxArrayLayers, imageCreateMaxExtent, and imageCreateSampleCounts", and 02252-02256 for the extent, levels, layers and samples.

The bug, step by step:

  1. A 2D array with more than one layer, not ASTC, not depth, single-sample and bigger than max_bytes is a candidate for a sparse image (dev.sparse_images).
  2. Its sparse residency is asked with vkGetPhysicalDeviceSparseImageFormatProperties and the usage u: TRANSFER_SRC | TRANSFER_DST | SAMPLED, plus COLOR_ATTACHMENT | STORAGE only if (!is_bc(x.format)). For a BC format the driver is never asked about storage or attachment usage.
  3. x.sparse is set when the driver returns any properties for that usage.
  4. The image is then made with ci.usage, built from x.usage, which for BC formats can hold STORAGE and COLOR_ATTACHMENT (the raw block views written as uncompressed data).
  5. So vkCreateImage gets SPARSE_BINDING | SPARSE_RESIDENCY with a usage the sparse query did not cover. A driver that does not support it fails the call, the code logs vk: sparse image %ux%u x%u levels %u format %d not made and returns nullptr: the texture is lost.

The query, unchanged:

VkImageUsageFlags u = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
if (!is_bc(x.format)) u |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
uint32_t np = 0;
vkGetPhysicalDeviceSparseImageFormatProperties(dev.physical, x.format, VK_IMAGE_TYPE_2D, VK_SAMPLE_COUNT_1_BIT,
                                               u, VK_IMAGE_TILING_OPTIMAL, &np, nullptr);
x.sparse = np > 0;

Before:

if (x.sparse) {
    ci.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT;
    bool ok = vkCreateImage(dev.device, &ci, nullptr, &x.image) == VK_SUCCESS;

After:

if (x.sparse) {
    ci.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT;
    // (a compressed one with the usage its sparse residency was asked with, above: no raw storage or attachment views,
    // which the driver did not say it can make sparse; as a compressed image refused without them, below)
    if (is_bc(x.format))
        ci.usage &= ~(VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT), x.usage = ci.usage;
    bool ok = vkCreateImage(dev.device, &ci, nullptr, &x.image) == VK_SUCCESS;

Start reading at the comment "a 2D array too big to keep whole, in a format with sparse residency" in create(), then the if (x.sparse) block below it.

Measurements

Verdict: it fixes the bug: test_sparse_bc_usage 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 @ d64920d0
tests/test_sparse_bc_usage.py, run 1 fails passes
tests/test_sparse_bc_usage.py, run 2 fails passes
tests/test_sparse_bc_usage.py, median fails passes
run 1, main @ c167ec67:
test_sparse_bc_usage                 exit 1
a sparse BC image is made with STORAGE/COLOR_ATTACHMENT, which its sparse residency was not asked with
run 1, this PR @ d64920d0:
a sparse BC image is made with the usage its sparse residency was asked with, within the format's limits
test_sparse_bc_usage                 exit 0
run 2, main @ c167ec67:
test_sparse_bc_usage                 exit 1
a sparse BC image is made with STORAGE/COLOR_ATTACHMENT, which its sparse residency was not asked with
run 2, this PR @ d64920d0:
a sparse BC image is made with the usage its sparse residency was asked with, within the format's limits
test_sparse_bc_usage                 exit 0

Flags and settings

None.

Testing

Tested: on this branch, Windows, Python 3.12: test_sparse_bc_usage passes (fails on main), and the other checks that read texture creation pass: test_bc_raw_targets, test_astc_bc_policy, test_compressed_over_rt, test_image_view_retry, test_3d_view_create_flags, test_drawn_page_map, test_low_vram_texture_mips, test_native_astc_texture_count, test_target_image_pool, test_vram_compact, test_vulkan_clear_mip.

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 sparse BC image being made in the game: not checked in the game (it needs a BC 2D array bigger than the texture budget's limit). Linux was built, not run.

Must be tested: None: the change is the same on every GPU and OS, and the game-free test covers it.

Risks

What could break: a sparse BC texture no longer gets its raw block views (storage and attachment), so a draw or compute that writes BC blocks as raw data into such a texture would not have that view. Non-sparse BC textures refused by the driver already lose them the same way, and before this PR a driver that refused the sparse image lost the whole texture.

Turning it off: revert the commit.

Compatibility: Nothing changes.

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: all 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.
  • A check under tests/ that reads changed source updated in this PR, not weakened. (tests/test_sparse_bc_usage.py new)
  • 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:** fix · **Risk:** low · **Tested on:** Windows, AMD Radeon RX 9070 XT · **Needs:** none ## Why A 2D array texture too big to keep whole is made as a sparse image, but for BC formats the driver is asked whether it supports sparse residency with transfer and sampled usage only, and the image is then made with storage and color attachment usage too. That is a combination the driver never said it supports sparse; a driver that refuses it loses the texture (`vk: sparse image ... not made`). ## How to reproduce **Seen on:** not seen in the game: found by reading `create()` in `gpu/vk/vk_texture.cpp`; it can happen whenever a BC 2D array bigger than the texture budget's limit is made sparse on a GPU with sparse residency **Settings and switches:** defaults **Steps:** game-free: `python -I -B tests/test_sparse_bc_usage.py` on main (copy the test from this PR); it reads the sparse residency query and the sparse image's creation in `vk_texture.cpp` **Expected:** the sparse image is made with the usage its sparse residency was asked with **Actual:** on main a sparse BC image is made with `STORAGE` and `COLOR_ATTACHMENT` usage, which the query left out; the test fails ## What changed A sparse BC image now drops `STORAGE` and `COLOR_ATTACHMENT` from its usage before `vkCreateImage`, so it is made with the usage its sparse residency was asked with. A compressed image the driver refuses already loses these two usages a few lines below, and its raw block views then follow `x.usage` and are not made; the sparse BC image now does the same from the start. - vk: `create()` in `gpu/vk/vk_texture.cpp`: inside `if (x.sparse)`, before `vkCreateImage`, `if (is_bc(x.format)) ci.usage &= ~(VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT), x.usage = ci.usage;`. Non-BC sparse images and non-sparse images are unchanged. - tests: `tests/test_sparse_bc_usage.py` (new) fails if the sparse BC image is made without dropping these two usages. Second commit, "make a sparse image only within its format's limits for the sparse flags and usage": - vk: `create()` in `gpu/vk/vk_texture.cpp`: before `vkCreateImage` for a sparse image, `vkGetPhysicalDeviceImageFormatProperties` is called with the image's format, type, tiling, usage and flags (the sparse ones included); the image is made only if the call succeeds and its extent, levels, layers and samples fit the answer; otherwise it takes the existing path for a sparse image that could not be made. - tests: `tests/test_sparse_bc_usage.py` checks the query and the gate. The sparse path asked only `vkGetPhysicalDeviceSparseImageFormatProperties`, which says nothing of the image limits for those flags and that usage. VUID-VkImageCreateInfo-imageCreateMaxMipLevels-02251: "Each of the following values (as described in Image Creation Limits) must not be undefined : imageCreateMaxMipLevels, imageCreateMaxArrayLayers, imageCreateMaxExtent, and imageCreateSampleCounts", and 02252-02256 for the extent, levels, layers and samples. The bug, step by step: 1. A 2D array with more than one layer, not ASTC, not depth, single-sample and bigger than `max_bytes` is a candidate for a sparse image (`dev.sparse_images`). 2. Its sparse residency is asked with `vkGetPhysicalDeviceSparseImageFormatProperties` and the usage `u`: `TRANSFER_SRC | TRANSFER_DST | SAMPLED`, plus `COLOR_ATTACHMENT | STORAGE` only `if (!is_bc(x.format))`. For a BC format the driver is never asked about storage or attachment usage. 3. `x.sparse` is set when the driver returns any properties for that usage. 4. The image is then made with `ci.usage`, built from `x.usage`, which for BC formats can hold `STORAGE` and `COLOR_ATTACHMENT` (the raw block views written as uncompressed data). 5. So `vkCreateImage` gets `SPARSE_BINDING | SPARSE_RESIDENCY` with a usage the sparse query did not cover. A driver that does not support it fails the call, the code logs `vk: sparse image %ux%u x%u levels %u format %d not made` and returns `nullptr`: the texture is lost. The query, unchanged: ```cpp VkImageUsageFlags u = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; if (!is_bc(x.format)) u |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_STORAGE_BIT; uint32_t np = 0; vkGetPhysicalDeviceSparseImageFormatProperties(dev.physical, x.format, VK_IMAGE_TYPE_2D, VK_SAMPLE_COUNT_1_BIT, u, VK_IMAGE_TILING_OPTIMAL, &np, nullptr); x.sparse = np > 0; ``` Before: ```cpp if (x.sparse) { ci.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT; bool ok = vkCreateImage(dev.device, &ci, nullptr, &x.image) == VK_SUCCESS; ``` After: ```cpp if (x.sparse) { ci.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT; // (a compressed one with the usage its sparse residency was asked with, above: no raw storage or attachment views, // which the driver did not say it can make sparse; as a compressed image refused without them, below) if (is_bc(x.format)) ci.usage &= ~(VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT), x.usage = ci.usage; bool ok = vkCreateImage(dev.device, &ci, nullptr, &x.image) == VK_SUCCESS; ``` Start reading at the comment "a 2D array too big to keep whole, in a format with sparse residency" in `create()`, then the `if (x.sparse)` block below it. ## Measurements **Verdict:** it fixes the bug: `test_sparse_bc_usage` 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 @ d64920d0 | |---|---|---| | `tests/test_sparse_bc_usage.py`, run 1 | fails | passes | | `tests/test_sparse_bc_usage.py`, run 2 | fails | passes | | `tests/test_sparse_bc_usage.py`, median | fails | passes | ``` run 1, main @ c167ec67: test_sparse_bc_usage exit 1 a sparse BC image is made with STORAGE/COLOR_ATTACHMENT, which its sparse residency was not asked with run 1, this PR @ d64920d0: a sparse BC image is made with the usage its sparse residency was asked with, within the format's limits test_sparse_bc_usage exit 0 run 2, main @ c167ec67: test_sparse_bc_usage exit 1 a sparse BC image is made with STORAGE/COLOR_ATTACHMENT, which its sparse residency was not asked with run 2, this PR @ d64920d0: a sparse BC image is made with the usage its sparse residency was asked with, within the format's limits test_sparse_bc_usage exit 0 ``` ### Flags and settings None. ## Testing **Tested:** on this branch, Windows, Python 3.12: `test_sparse_bc_usage` passes (fails on main), and the other checks that read texture creation pass: `test_bc_raw_targets`, `test_astc_bc_policy`, `test_compressed_over_rt`, `test_image_view_retry`, `test_3d_view_create_flags`, `test_drawn_page_map`, `test_low_vram_texture_mips`, `test_native_astc_texture_count`, `test_target_image_pool`, `test_vram_compact`, `test_vulkan_clear_mip`. **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 sparse BC image being made in the game: not checked in the game (it needs a BC 2D array bigger than the texture budget's limit). Linux was built, not run. **Must be tested:** None: the change is the same on every GPU and OS, and the game-free test covers it. ## Risks **What could break:** a sparse BC texture no longer gets its raw block views (storage and attachment), so a draw or compute that writes BC blocks as raw data into such a texture would not have that view. Non-sparse BC textures refused by the driver already lose them the same way, and before this PR a driver that refused the sparse image lost the whole texture. **Turning it off:** revert the commit. **Compatibility:** Nothing changes. ## 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: all 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. - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. (`tests/test_sparse_bc_usage.py` new) - [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)
fix(vk): make a sparse BC image with the usage its residency was checked for
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 15s
Website / Website on Cloudflare (pull_request_target) Has been skipped
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
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
cafd484b68
texture create asks vkGetPhysicalDeviceSparseImageFormatProperties whether a too-big 2D array can be sparse, and for BC formats it asks with TRANSFER_SRC | TRANSFER_DST | SAMPLED only. The image was then created with x.usage, which for BC may also hold STORAGE and COLOR_ATTACHMENT for the raw block views: a combination the driver never said it supports sparse. AMD's driver refused it and the texture was lost. The sparse BC image now drops those two usages before vkCreateImage, as a refused compressed image already does below; its raw views follow x.usage and are not made.

tests/test_sparse_bc_usage.py fails on main and passes with the fix.

Assisted-by: GitHub Copilot
jcabarca changed title from WIP: fix(vk): make a sparse BC image with the usage its sparse residency was checked for to fix(vk): make a sparse BC image with the usage its sparse residency was checked for 2026-11-15 03:21:29 +00:00
HumanBean left a comment

Code review only; I did not run the checks. A question and a suggestion, no hard block.

The mismatch is real: the sparse residency query leaves STORAGE and COLOR_ATTACHMENT out for BC, and vkCreateImage then uses x.usage with them in. The raw views are gated on tex->usage (vk_texture.cpp:570-575), so dropping the bits in x.usage as well is consistent.

Concern: the drop is unconditional for every sparse BC image on every driver. A driver that accepts the larger usage today, and so has the raw storage and attachment views on its sparse BC textures, loses them with this change. The PR says the bug was not seen in the game, and the "Risks" section concedes that the raw views are gone. The non-sparse path in create() does it the other way: it creates the image with the usage and only strips the bits after the driver refuses (vk_texture.cpp:2229-2231).

Suggestion: do the same here. Try vkCreateImage with the full usage, and on failure retry with STORAGE and COLOR_ATTACHMENT removed (or ask vkGetPhysicalDeviceImageFormatProperties with the sparse flag and the full usage first). That fixes the loss where it happens and costs nothing where it works. If you would rather keep the unconditional drop, please say in the description why losing the raw block views on drivers that accept them does not matter (sparse BC 2D arrays that the game's BC encoders write into). A run on a driver that takes the full usage would settle it.

Smaller point: the test docstring says "AMD's driver refused it, and the texture was lost", but the PR says it was never seen in the game. Please word them the same.

Code review only; I did not run the checks. A question and a suggestion, no hard block. The mismatch is real: the sparse residency query leaves STORAGE and COLOR_ATTACHMENT out for BC, and `vkCreateImage` then uses `x.usage` with them in. The raw views are gated on `tex->usage` (`vk_texture.cpp:570-575`), so dropping the bits in `x.usage` as well is consistent. Concern: the drop is unconditional for every sparse BC image on every driver. A driver that accepts the larger usage today, and so has the raw storage and attachment views on its sparse BC textures, loses them with this change. The PR says the bug was not seen in the game, and the "Risks" section concedes that the raw views are gone. The non-sparse path in `create()` does it the other way: it creates the image with the usage and only strips the bits after the driver refuses (`vk_texture.cpp:2229-2231`). Suggestion: do the same here. Try `vkCreateImage` with the full usage, and on failure retry with STORAGE and COLOR_ATTACHMENT removed (or ask `vkGetPhysicalDeviceImageFormatProperties` with the sparse flag and the full usage first). That fixes the loss where it happens and costs nothing where it works. If you would rather keep the unconditional drop, please say in the description why losing the raw block views on drivers that accept them does not matter (sparse BC 2D arrays that the game's BC encoders write into). A run on a driver that takes the full usage would settle it. Smaller point: the test docstring says "AMD's driver refused it, and the texture was lost", but the PR says it was never seen in the game. Please word them the same.
@ -2189,1 +2189,4 @@
ci.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT;
// (a compressed one with the usage its sparse residency was asked with, above: no raw storage or attachment views,
// which the driver did not say it can make sparse; as a compressed image refused without them, below)
if (is_bc(x.format))
Owner

This drops the raw views on every driver, including ones that accept the full usage for a sparse image. The non-sparse path below tries first and strips the bits only when the driver refuses; a retry without them here would do the same.

This drops the raw views on every driver, including ones that accept the full usage for a sparse image. The non-sparse path below tries first and strips the bits only when the driver refuses; a retry without them here would do the same.
Member

Code-only review of cafd484b68; informational findings, with final approval left to another reviewer.

No additional production defect found beyond the still-unanswered raw-view compatibility concern already raised. I checked the sparse eligibility query, usage construction, image creation and make_view() guard; the mismatch exists on current main, and the new mask also consistently prevents storage/attachment views through tex->usage.

The remaining validation gap is specific: the reported RX 9070 XT play session did not exercise a sparse BC image. It therefore does not establish whether dropping the raw views preserves the affected texture's contents. A run that actually reaches sparse BC creation and checks its content, including any guest raw-block writes, would resolve that gap alongside the existing compatibility question.

One useful test improvement: tests/test_sparse_bc_usage.py:29-30 only searches for strings. Changing if (is_bc(x.format)) to if (!is_bc(x.format)) would still satisfy every assertion, although BC images would retain the unsupported usages and non-BC images would lose required usages. Add behavioral coverage of BC/non-BC usage selection and synchronization of ci.usage with x.usage; a stubbed creation call can capture the actual flags without a game or GPU. The current source check does not prove the driver failure is fixed.

PR 925 handles sparse upload residency in a different path; it complements this change rather than replacing it. No source changes, tests, builds or game runs performed in this review.

Code-only review of cafd484b6805c2896a435a1fdf7b85a09bc7049e; informational findings, with final approval left to another reviewer. No additional production defect found beyond the still-unanswered [raw-view compatibility concern already raised](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/671#issuecomment-28191). I checked the sparse eligibility query, usage construction, image creation and `make_view()` guard; the mismatch exists on current main, and the new mask also consistently prevents storage/attachment views through `tex->usage`. The remaining validation gap is specific: the reported RX 9070 XT play session did not exercise a sparse BC image. It therefore does not establish whether dropping the raw views preserves the affected texture's contents. A run that actually reaches sparse BC creation and checks its content, including any guest raw-block writes, would resolve that gap alongside the existing compatibility question. One useful test improvement: `tests/test_sparse_bc_usage.py:29-30` only searches for strings. Changing `if (is_bc(x.format))` to `if (!is_bc(x.format))` would still satisfy every assertion, although BC images would retain the unsupported usages and non-BC images would lose required usages. Add behavioral coverage of BC/non-BC usage selection and synchronization of `ci.usage` with `x.usage`; a stubbed creation call can capture the actual flags without a game or GPU. The current source check does not prove the driver failure is fixed. [PR 925](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/925) handles sparse upload residency in a different path; it complements this change rather than replacing it. No source changes, tests, builds or game runs performed in this review.
Author
Contributor

New commit, "make a sparse image only within its format's limits for the sparse flags and usage" (d64920d0); the branch is rebased onto main @ c167ec67.

The sparse path asked only vkGetPhysicalDeviceSparseImageFormatProperties, which says nothing of the image limits for those flags and that usage. VUID-VkImageCreateInfo-imageCreateMaxMipLevels-02251: "Each of the following values (as described in Image Creation Limits) must not be undefined : imageCreateMaxMipLevels, imageCreateMaxArrayLayers, imageCreateMaxExtent, and imageCreateSampleCounts", and 02252-02256 for the extent, levels, layers and samples.

  • vk: create() in gpu/vk/vk_texture.cpp: before vkCreateImage for a sparse image, vkGetPhysicalDeviceImageFormatProperties is called with the image's format, type, tiling, usage and flags (the sparse ones included); the image is made only if the call succeeds and its extent, levels, layers and samples fit the answer; otherwise it takes the existing path for a sparse image that could not be made.
  • tests: tests/test_sparse_bc_usage.py checks the query and the gate.

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

New commit, "make a sparse image only within its format's limits for the sparse flags and usage" (d64920d0); the branch is rebased onto main @ c167ec67. The sparse path asked only `vkGetPhysicalDeviceSparseImageFormatProperties`, which says nothing of the image limits for those flags and that usage. VUID-VkImageCreateInfo-imageCreateMaxMipLevels-02251: "Each of the following values (as described in Image Creation Limits) must not be undefined : imageCreateMaxMipLevels, imageCreateMaxArrayLayers, imageCreateMaxExtent, and imageCreateSampleCounts", and 02252-02256 for the extent, levels, layers and samples. - vk: `create()` in `gpu/vk/vk_texture.cpp`: before `vkCreateImage` for a sparse image, `vkGetPhysicalDeviceImageFormatProperties` is called with the image's format, type, tiling, usage and flags (the sparse ones included); the image is made only if the call succeeds and its extent, levels, layers and samples fit the answer; otherwise it takes the existing path for a sparse image that could not be made. - tests: `tests/test_sparse_bc_usage.py` checks the query and the gate. `test_sparse_bc_usage` fails on main and passes here. Run twice each side, interleaved; What changed and Measurements in the description are updated.
jcabarca force-pushed fix/vk-sparse-bc-usage from cafd484b68
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 15s
Website / Website on Cloudflare (pull_request_target) Has been skipped
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
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 d64920d050
Some checks failed
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
Website / Website on Cloudflare (pull_request) Has been cancelled
2026-11-16 10:31:18 +00:00
Compare
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 fix/vk-sparse-bc-usage
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
07fba26778
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 'fix/vk-sparse-bc-usage:jcabarca-fix/vk-sparse-bc-usage'
git switch 'jcabarca-fix/vk-sparse-bc-usage'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 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!671
No description provided.