fix(vk): stage ASTC layers at an aligned pitch, zero their padding and rebind after the decoder #920

Open
jcabarca wants to merge 3 commits from jcabarca/Longshot:fix/vk-astc-staging-align into main
Contributor

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

Why

The GPU ASTC decoder staged a texture's layers back to back, so each layer after the first started at k * tail, and that storage buffer offset breaks VUID-VkWriteDescriptorSet-descriptorType-00328 whenever the layer size is not a multiple of minStorageBufferOffsetAlignment. The driver may then read the layer's blocks from the wrong place: array and cube ASTC textures can show garbage in their later layers.

How to reproduce

Seen on: not seen in the game: found by reading upload_astc_gpu() in gpu/vk/vk_texture.cpp; it happens for any ASTC array or cube texture decoded on the GPU whose layer tail is not a multiple of the device's minStorageBufferOffsetAlignment
Settings and switches: defaults
Steps: game-free: python -I -B tests/test_texture_staging_publication.py --cxx clang++ --headers <Vulkan-Headers include> with --source pointing at a main checkout (the test from this PR); it compiles upload_astc_gpu()'s staging out of the source
Expected: each layer is staged at an offset that is a multiple of minStorageBufferOffsetAlignment, padded with zeros, and the draw state knows the decoder replaced its compute bindings
Actual: on main the layers sit at k * tail and the decoder's bind does not mark the bound descriptors disturbed; the test fails

What changed

upload_astc_gpu() now stages each layer at a pitch: the layer tail rounded up to minStorageBufferOffsetAlignment (at least 4). The bytes between a layer's end and the next pitch are zeroed, and the decoder's bind now calls descriptors_disturbed().

  • vk: upload_astc_gpu() in gpu/vk/vk_texture.cpp:
    • pitch = (tail + align - 1) / align * align replaces tail as the stride everywhere a layer is placed or found: the staging size, the copy into staging, staged, pc.layer_stride (both decoder paths) and the descriptor offsets from.
    • The copy zeroes pitch - n bytes after each layer, also for a layer past the end of the guest data (before, such a layer was skipped and kept the staging's old bytes).
    • A pitch over UINT32_MAX (it does not fit layer_stride) fails the upload with "its layout", as other unusable layouts do.
    • align is computed once, before the staging, instead of after the bind.
    • descriptors_disturbed() right after vkCmdBindPipeline(..., astc_pipe), so the next draw or dispatch binds its own pipeline and descriptors again.
  • tests: tests/test_texture_staging_publication.py and tests/texture_staging_publication_test.cpp (extended): a new astc-pitch case and the descriptors_disturbed() check (details under Measurements).

Second commit, "clamp the decoders' storage buffer ranges to maxStorageBufferRange":

  • vk: upload_astc_gpu() (two places) and upload_unswizzle_gpu() in gpu/vk/vk_texture.cpp: the VkDescriptorBufferInfo range is std::min<uint64_t>(..., dev.props.limits.maxStorageBufferRange).
  • tests: tests/test_storage_buffer_range.py (new) checks the three ranges.

The range was the staged size with no upper bound; a large ASTC array can pass 2^27 bytes, the limit's required minimum. VUID-VkWriteDescriptorSet-descriptorType-00333: "If descriptorType is VK_DESCRIPTOR_TYPE_STORAGE_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, and the shader64BitIndexing feature is not enabled, the range member of each element of pBufferInfo, or the effective range if range is VK_WHOLE_SIZE, must be less than or equal to VkPhysicalDeviceLimits::maxStorageBufferRange" (shader64BitIndexing is not enabled).

The bug, step by step:

  1. upload_astc_gpu() copies the encoded blocks of every dirty layer into one staging buffer, layer k at s.data + k * tail.
  2. For each layer and level it writes a storage buffer descriptor with offset s.offset + k * tail + off for the decoder.
  3. The staging itself is aligned (std::max(256, minStorageBufferOffsetAlignment)), and off must already be a multiple of align (if (... || (off % align)) continue;), but k * tail is not: with a tail of 1552 bytes and an alignment of 256, layer 1 starts at 1552.
  4. That descriptor breaks the rule below.
  5. Separately, the decoder binds astc_pipe and pushes its descriptors on the upload command buffer, which is also where the draws record (upload_cmd() returns the recording's command buffer). The draw state's push-descriptor cache (pushed()) still thought its own were bound.

The rule, from Khronos validusage.json:

  • VUID-VkWriteDescriptorSet-descriptorType-00328: "If descriptorType is VK_DESCRIPTOR_TYPE_STORAGE_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, the offset member of each element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minStorageBufferOffsetAlignment"

Before:

    const Staging s = staging(tail * layers.size(), std::max<uint64_t>(256, dev.props.limits.minStorageBufferOffsetAlignment));
    ...
        if (at >= total) continue;
        const uint64_t n = std::min(tail, total - at);
        std::memcpy(s.data + k * tail, guest_bytes(tex.gpu + at, n, scratch), n);
    }
    const uint64_t staged = tail * layers.size();
    ...
    vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, astc_pipe);
    const uint64_t align = std::max<uint64_t>(dev.props.limits.minStorageBufferOffsetAlignment, 4);
    ...
            const uint64_t from = (all ? 0 : k * tail) + off;

After:

    const uint64_t align = std::max<uint64_t>(dev.props.limits.minStorageBufferOffsetAlignment, 4);
    // (each layer staged at an aligned pitch: at k * tail, a layer's storage buffer offset could miss
    // minStorageBufferOffsetAlignment, VUID-VkWriteDescriptorSet-descriptorType-00328)
    const uint64_t pitch = (tail + align - 1) / align * align;
    if (pitch > UINT32_MAX) {
        astc_fail = "its layout";
        return false;
    }
    const Staging s = staging(pitch * layers.size(), std::max<uint64_t>(256, align));
    ...
        const uint64_t n = at < total ? std::min(tail, total - at) : 0;
        if (n) std::memcpy(s.data + k * pitch, guest_bytes(tex.gpu + at, n, scratch), n);
        if (n < pitch) std::memset(s.data + k * pitch + n, 0, pitch - n);   // (zeros past the guest's bytes, not the staging's old ones)
    }
    const uint64_t staged = pitch * layers.size();
    ...
    vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, astc_pipe);
    descriptors_disturbed();   // (the next draw or dispatch binds its own pipeline and descriptors again)
    ...
            const uint64_t from = (all ? 0 : k * pitch) + off;

pc.layer_stride (both the BC3 and the direct decoder paths) and the BC3 path's from = k0 * pitch + off change the same way. Start reading at bool upload_astc_gpu( in vk_texture.cpp.

Measurements

Verdict: it fixes the bug: test_storage_buffer_range fails on main and passes here; test_texture_staging_publication (the first commit's test) 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 @ 1b210b6a
tests/test_storage_buffer_range.py, run 1 fails passes
tests/test_texture_staging_publication.py, run 1 fails passes
tests/test_storage_buffer_range.py, run 2 fails passes
tests/test_texture_staging_publication.py, run 2 fails passes
tests/test_storage_buffer_range.py, median fails passes
tests/test_texture_staging_publication.py, median fails passes
run 1, main @ c167ec67:
test_storage_buffer_range            exit 1
test_texture_staging_publication     exit 1
bool upload_astc_gpu( binds {s.buffer, s.offset + from, staged - from} without clamping it to maxStorageBufferRange (VUID 00333)
bool upload_astc_gpu( binds {s.buffer, s.offset + from, staged - from} without clamping it to maxStorageBufferRange (VUID 00333)
bool upload_unswizzle_gpu( binds {src.buffer, src.offset + g.offset, total - g.offset} without clamping it to maxStorageBufferRange (VUID 00333)
    main()
    assert astc[:stop].count(bind + "    descriptors_disturbed();") == 1, "upload_astc_gpu does not call descriptors_disturbed after binding astc_pipe"
AssertionError: upload_astc_gpu does not call descriptors_disturbed after binding astc_pipe
run 1, this PR @ 1b210b6a:
the decoders' storage buffer ranges are within maxStorageBufferRange: ok
test_storage_buffer_range            exit 0
test_texture_staging_publication     exit 0
run 2, main @ c167ec67:
test_storage_buffer_range            exit 1
test_texture_staging_publication     exit 1
bool upload_astc_gpu( binds {s.buffer, s.offset + from, staged - from} without clamping it to maxStorageBufferRange (VUID 00333)
bool upload_astc_gpu( binds {s.buffer, s.offset + from, staged - from} without clamping it to maxStorageBufferRange (VUID 00333)
bool upload_unswizzle_gpu( binds {src.buffer, src.offset + g.offset, total - g.offset} without clamping it to maxStorageBufferRange (VUID 00333)
    main()
    assert astc[:stop].count(bind + "    descriptors_disturbed();") == 1, "upload_astc_gpu does not call descriptors_disturbed after binding astc_pipe"
AssertionError: upload_astc_gpu does not call descriptors_disturbed after binding astc_pipe
run 2, this PR @ 1b210b6a:
the decoders' storage buffer ranges are within maxStorageBufferRange: ok
test_storage_buffer_range            exit 0
test_texture_staging_publication     exit 0

Flags and settings

None.

Testing

Tested: on this branch, Windows, Python 3.12, clang++ from llvm-mingw: test_texture_staging_publication passes (fails on main), and the other checks that read upload_astc_gpu() pass: test_bc_upload_retry, test_mem_trim.

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: an ASTC array texture with a layer size that is not a multiple of the alignment, decoded in the game and looked at layer by layer: not checked in the game. 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: the staging grows by at most align - 1 bytes per layer, so a texture right at the staging's limit could now fall back to its CPU path ("no staging memory for its ASTC blocks"), which already handles that case. A layer with a pitch over 4 GiB now fails with "its layout" instead of being truncated into layer_stride. The next draw after a decode re-pushes its descriptors once.

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: test_texture_staging_publication, test_bc_upload_retry, test_mem_trim, 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. (tests/test_texture_staging_publication.py and its fixture extended)
  • A check under tests/ that reads changed source updated in this PR, not weakened. (tests/test_texture_staging_publication.py: one check and one fixture case added, none 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)
**Type:** fix · **Risk:** low · **Tested on:** Windows, AMD Radeon RX 9070 XT · **Needs:** none ## Why The GPU ASTC decoder staged a texture's layers back to back, so each layer after the first started at `k * tail`, and that storage buffer offset breaks VUID-VkWriteDescriptorSet-descriptorType-00328 whenever the layer size is not a multiple of minStorageBufferOffsetAlignment. The driver may then read the layer's blocks from the wrong place: array and cube ASTC textures can show garbage in their later layers. ## How to reproduce **Seen on:** not seen in the game: found by reading `upload_astc_gpu()` in `gpu/vk/vk_texture.cpp`; it happens for any ASTC array or cube texture decoded on the GPU whose layer tail is not a multiple of the device's minStorageBufferOffsetAlignment **Settings and switches:** defaults **Steps:** game-free: `python -I -B tests/test_texture_staging_publication.py --cxx clang++ --headers <Vulkan-Headers include>` with `--source` pointing at a main checkout (the test from this PR); it compiles `upload_astc_gpu()`'s staging out of the source **Expected:** each layer is staged at an offset that is a multiple of minStorageBufferOffsetAlignment, padded with zeros, and the draw state knows the decoder replaced its compute bindings **Actual:** on main the layers sit at `k * tail` and the decoder's bind does not mark the bound descriptors disturbed; the test fails ## What changed `upload_astc_gpu()` now stages each layer at a pitch: the layer tail rounded up to minStorageBufferOffsetAlignment (at least 4). The bytes between a layer's end and the next pitch are zeroed, and the decoder's bind now calls `descriptors_disturbed()`. - vk: `upload_astc_gpu()` in `gpu/vk/vk_texture.cpp`: - `pitch = (tail + align - 1) / align * align` replaces `tail` as the stride everywhere a layer is placed or found: the staging size, the copy into staging, `staged`, `pc.layer_stride` (both decoder paths) and the descriptor offsets `from`. - The copy zeroes `pitch - n` bytes after each layer, also for a layer past the end of the guest data (before, such a layer was skipped and kept the staging's old bytes). - A pitch over `UINT32_MAX` (it does not fit `layer_stride`) fails the upload with "its layout", as other unusable layouts do. - `align` is computed once, before the staging, instead of after the bind. - `descriptors_disturbed()` right after `vkCmdBindPipeline(..., astc_pipe)`, so the next draw or dispatch binds its own pipeline and descriptors again. - tests: `tests/test_texture_staging_publication.py` and `tests/texture_staging_publication_test.cpp` (extended): a new `astc-pitch` case and the `descriptors_disturbed()` check (details under Measurements). Second commit, "clamp the decoders' storage buffer ranges to maxStorageBufferRange": - vk: `upload_astc_gpu()` (two places) and `upload_unswizzle_gpu()` in `gpu/vk/vk_texture.cpp`: the `VkDescriptorBufferInfo` range is `std::min<uint64_t>(..., dev.props.limits.maxStorageBufferRange)`. - tests: `tests/test_storage_buffer_range.py` (new) checks the three ranges. The range was the staged size with no upper bound; a large ASTC array can pass 2^27 bytes, the limit's required minimum. VUID-VkWriteDescriptorSet-descriptorType-00333: "If descriptorType is VK_DESCRIPTOR_TYPE_STORAGE_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, and the shader64BitIndexing feature is not enabled, the range member of each element of pBufferInfo, or the effective range if range is VK_WHOLE_SIZE, must be less than or equal to VkPhysicalDeviceLimits::maxStorageBufferRange" (shader64BitIndexing is not enabled). The bug, step by step: 1. `upload_astc_gpu()` copies the encoded blocks of every dirty layer into one staging buffer, layer `k` at `s.data + k * tail`. 2. For each layer and level it writes a storage buffer descriptor with offset `s.offset + k * tail + off` for the decoder. 3. The staging itself is aligned (`std::max(256, minStorageBufferOffsetAlignment)`), and `off` must already be a multiple of `align` (`if (... || (off % align)) continue;`), but `k * tail` is not: with a tail of 1552 bytes and an alignment of 256, layer 1 starts at 1552. 4. That descriptor breaks the rule below. 5. Separately, the decoder binds `astc_pipe` and pushes its descriptors on the upload command buffer, which is also where the draws record (`upload_cmd()` returns the recording's command buffer). The draw state's push-descriptor cache (`pushed()`) still thought its own were bound. The rule, from Khronos `validusage.json`: - VUID-VkWriteDescriptorSet-descriptorType-00328: "If descriptorType is VK_DESCRIPTOR_TYPE_STORAGE_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, the offset member of each element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minStorageBufferOffsetAlignment" Before: ```cpp const Staging s = staging(tail * layers.size(), std::max<uint64_t>(256, dev.props.limits.minStorageBufferOffsetAlignment)); ... if (at >= total) continue; const uint64_t n = std::min(tail, total - at); std::memcpy(s.data + k * tail, guest_bytes(tex.gpu + at, n, scratch), n); } const uint64_t staged = tail * layers.size(); ... vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, astc_pipe); const uint64_t align = std::max<uint64_t>(dev.props.limits.minStorageBufferOffsetAlignment, 4); ... const uint64_t from = (all ? 0 : k * tail) + off; ``` After: ```cpp const uint64_t align = std::max<uint64_t>(dev.props.limits.minStorageBufferOffsetAlignment, 4); // (each layer staged at an aligned pitch: at k * tail, a layer's storage buffer offset could miss // minStorageBufferOffsetAlignment, VUID-VkWriteDescriptorSet-descriptorType-00328) const uint64_t pitch = (tail + align - 1) / align * align; if (pitch > UINT32_MAX) { astc_fail = "its layout"; return false; } const Staging s = staging(pitch * layers.size(), std::max<uint64_t>(256, align)); ... const uint64_t n = at < total ? std::min(tail, total - at) : 0; if (n) std::memcpy(s.data + k * pitch, guest_bytes(tex.gpu + at, n, scratch), n); if (n < pitch) std::memset(s.data + k * pitch + n, 0, pitch - n); // (zeros past the guest's bytes, not the staging's old ones) } const uint64_t staged = pitch * layers.size(); ... vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, astc_pipe); descriptors_disturbed(); // (the next draw or dispatch binds its own pipeline and descriptors again) ... const uint64_t from = (all ? 0 : k * pitch) + off; ``` `pc.layer_stride` (both the BC3 and the direct decoder paths) and the BC3 path's `from = k0 * pitch + off` change the same way. Start reading at `bool upload_astc_gpu(` in `vk_texture.cpp`. ## Measurements **Verdict:** it fixes the bug: `test_storage_buffer_range` fails on main and passes here; `test_texture_staging_publication` (the first commit's test) 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 @ 1b210b6a | |---|---|---| | `tests/test_storage_buffer_range.py`, run 1 | fails | passes | | `tests/test_texture_staging_publication.py`, run 1 | fails | passes | | `tests/test_storage_buffer_range.py`, run 2 | fails | passes | | `tests/test_texture_staging_publication.py`, run 2 | fails | passes | | `tests/test_storage_buffer_range.py`, median | fails | passes | | `tests/test_texture_staging_publication.py`, median | fails | passes | ``` run 1, main @ c167ec67: test_storage_buffer_range exit 1 test_texture_staging_publication exit 1 bool upload_astc_gpu( binds {s.buffer, s.offset + from, staged - from} without clamping it to maxStorageBufferRange (VUID 00333) bool upload_astc_gpu( binds {s.buffer, s.offset + from, staged - from} without clamping it to maxStorageBufferRange (VUID 00333) bool upload_unswizzle_gpu( binds {src.buffer, src.offset + g.offset, total - g.offset} without clamping it to maxStorageBufferRange (VUID 00333) main() assert astc[:stop].count(bind + " descriptors_disturbed();") == 1, "upload_astc_gpu does not call descriptors_disturbed after binding astc_pipe" AssertionError: upload_astc_gpu does not call descriptors_disturbed after binding astc_pipe run 1, this PR @ 1b210b6a: the decoders' storage buffer ranges are within maxStorageBufferRange: ok test_storage_buffer_range exit 0 test_texture_staging_publication exit 0 run 2, main @ c167ec67: test_storage_buffer_range exit 1 test_texture_staging_publication exit 1 bool upload_astc_gpu( binds {s.buffer, s.offset + from, staged - from} without clamping it to maxStorageBufferRange (VUID 00333) bool upload_astc_gpu( binds {s.buffer, s.offset + from, staged - from} without clamping it to maxStorageBufferRange (VUID 00333) bool upload_unswizzle_gpu( binds {src.buffer, src.offset + g.offset, total - g.offset} without clamping it to maxStorageBufferRange (VUID 00333) main() assert astc[:stop].count(bind + " descriptors_disturbed();") == 1, "upload_astc_gpu does not call descriptors_disturbed after binding astc_pipe" AssertionError: upload_astc_gpu does not call descriptors_disturbed after binding astc_pipe run 2, this PR @ 1b210b6a: the decoders' storage buffer ranges are within maxStorageBufferRange: ok test_storage_buffer_range exit 0 test_texture_staging_publication exit 0 ``` ### Flags and settings None. ## Testing **Tested:** on this branch, Windows, Python 3.12, clang++ from llvm-mingw: `test_texture_staging_publication` passes (fails on main), and the other checks that read `upload_astc_gpu()` pass: `test_bc_upload_retry`, `test_mem_trim`. **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:** an ASTC array texture with a layer size that is not a multiple of the alignment, decoded in the game and looked at layer by layer: not checked in the game. 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:** the staging grows by at most `align - 1` bytes per layer, so a texture right at the staging's limit could now fall back to its CPU path ("no staging memory for its ASTC blocks"), which already handles that case. A layer with a pitch over 4 GiB now fails with "its layout" instead of being truncated into `layer_stride`. The next draw after a decode re-pushes its descriptors once. **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: `test_texture_staging_publication`, `test_bc_upload_retry`, `test_mem_trim`, 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. (`tests/test_texture_staging_publication.py` and its fixture extended) - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. (`tests/test_texture_staging_publication.py`: one check and one fixture case added, none 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)
fix(vk): stage ASTC layers at an aligned pitch, zero their padding and rebind after the decoder
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
22e276c725
Assisted-by: GitHub Copilot
jcabarca changed title from WIP: fix(vk): stage ASTC layers at an aligned pitch, zero their padding and rebind after the decoder to fix(vk): stage ASTC layers at an aligned pitch, zero their padding and rebind after the decoder 2026-11-15 20:45:13 +00:00
Member

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

No introduced correctness defect found in the changes. I followed the aligned pitch through staging allocation, copies, flush ranges, both decoder push constants and descriptor offsets, including partial dirty-layer uploads. The descriptor-cache invalidation uses the existing mechanism, and the staging arena's submission lifetime remains unchanged.

Validation limit: the new fixture exercises actual staging bytes and padding, but stops before the decoder branches. It cannot catch a regression that changes either decoder's layer_stride or descriptor offset back to tail; descriptor invalidation is checked as source text rather than by observing a subsequent dispatch. Extending the fixture to capture descriptor offsets/push constants for direct and BC decoding, plus a same-layout dispatch after decoding, would strengthen regression coverage. The reported Windows RX 9070 XT playthrough and Windows/Linux builds are useful smoke evidence; the misaligned multilayer case has not been checked in-game, as the description acknowledges.

Merge coordination: the ASTC batching work tracked in issue 813 names this fix as a dependency. Preserve this pitch and invalidation work when integrating that prototype; the sparse-unswizzle fix in PR 925 changes a different upload path.

Read the full diff, staging allocator/publication fixture, decoder shader addressing, descriptor cache invalidation and surrounding upload code. No tests, builds or game runs performed for this review.

Code-only review of 22e276c7256619888779ab8dd96a3f7df8a4a1e2; informational findings, with final approval left to another reviewer. No introduced correctness defect found in the changes. I followed the aligned pitch through staging allocation, copies, flush ranges, both decoder push constants and descriptor offsets, including partial dirty-layer uploads. The descriptor-cache invalidation uses the existing mechanism, and the staging arena's submission lifetime remains unchanged. Validation limit: the new fixture exercises actual staging bytes and padding, but stops before the decoder branches. It cannot catch a regression that changes either decoder's `layer_stride` or descriptor offset back to `tail`; descriptor invalidation is checked as source text rather than by observing a subsequent dispatch. Extending the fixture to capture descriptor offsets/push constants for direct and BC decoding, plus a same-layout dispatch after decoding, would strengthen regression coverage. The reported Windows RX 9070 XT playthrough and Windows/Linux builds are useful smoke evidence; the misaligned multilayer case has not been checked in-game, as the description acknowledges. Merge coordination: the ASTC batching work tracked in [issue 813](https://git.magicbean.dev/MagicBeanDev/Longshot/issues/813) names this fix as a dependency. Preserve this pitch and invalidation work when integrating that prototype; the sparse-unswizzle fix in [PR 925](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/925) changes a different upload path. Read the full diff, staging allocator/publication fixture, decoder shader addressing, descriptor cache invalidation and surrounding upload code. No tests, builds or game runs performed for this review.
Author
Contributor

New commit, "clamp the decoders' storage buffer ranges to maxStorageBufferRange" (1b210b6a); the branch is rebased onto main @ c167ec67.

The range was the staged size with no upper bound; a large ASTC array can pass 2^27 bytes, the limit's required minimum. VUID-VkWriteDescriptorSet-descriptorType-00333: "If descriptorType is VK_DESCRIPTOR_TYPE_STORAGE_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, and the shader64BitIndexing feature is not enabled, the range member of each element of pBufferInfo, or the effective range if range is VK_WHOLE_SIZE, must be less than or equal to VkPhysicalDeviceLimits::maxStorageBufferRange" (shader64BitIndexing is not enabled).

  • vk: upload_astc_gpu() (two places) and upload_unswizzle_gpu() in gpu/vk/vk_texture.cpp: the VkDescriptorBufferInfo range is std::min<uint64_t>(..., dev.props.limits.maxStorageBufferRange).
  • tests: tests/test_storage_buffer_range.py (new) checks the three ranges.

test_storage_buffer_range fails on main and passes here; test_texture_staging_publication (the first commit's test) fails on main and passes here. Run twice each side, interleaved; What changed and Measurements in the description are updated.

New commit, "clamp the decoders' storage buffer ranges to maxStorageBufferRange" (1b210b6a); the branch is rebased onto main @ c167ec67. The range was the staged size with no upper bound; a large ASTC array can pass 2^27 bytes, the limit's required minimum. VUID-VkWriteDescriptorSet-descriptorType-00333: "If descriptorType is VK_DESCRIPTOR_TYPE_STORAGE_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, and the shader64BitIndexing feature is not enabled, the range member of each element of pBufferInfo, or the effective range if range is VK_WHOLE_SIZE, must be less than or equal to VkPhysicalDeviceLimits::maxStorageBufferRange" (shader64BitIndexing is not enabled). - vk: `upload_astc_gpu()` (two places) and `upload_unswizzle_gpu()` in `gpu/vk/vk_texture.cpp`: the `VkDescriptorBufferInfo` range is `std::min<uint64_t>(..., dev.props.limits.maxStorageBufferRange)`. - tests: `tests/test_storage_buffer_range.py` (new) checks the three ranges. `test_storage_buffer_range` fails on main and passes here; `test_texture_staging_publication` (the first commit's test) 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-astc-staging-align from 22e276c725
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 1b210b6a14
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 4s
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:32:12 +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-astc-staging-align
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
a7f48ef7fd
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-astc-staging-align:jcabarca-fix/vk-astc-staging-align'
git switch 'jcabarca-fix/vk-astc-staging-align'
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!920
No description provided.