DirectStorage: requests with swizzle modes 1–4 are interleaved on the CPU #3310

Closed
Foniass wants to merge 1 commit from upstream-pr/3310 into main
Foniass commented 2026-11-29 06:58:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T06:58:49Z.


Draft: rayy (raylitebull, who wrote it), can you confirm the group layouts (or where they were checked)? The code and tests are clean, but nothing here can verify the interleaving against a real title.

A DirectStorage request may ask for one of the BCn swizzle modes, in
which the stream holds each block component as its own array and the
destination wants them interleaved in 16 KiB or 32 KiB groups (mode 1
4K_4K_8K: BC1 endpoints and indices; 2 4K_4K_24K: BC4; 3 4K_12K_4K_4K_8K:
BC3 alpha and colour; 4 4K_12K_4K_12K: BC5). XCL refused every swizzled
request (E_DECOMPRESSION). Modes 1–4 are now interleaved after zlib and
BCPack (swizzle_interleave); a destination that is not a whole number of
groups is E_DESTINATION_SIZE; modes above 4 are still refused.

The group layouts come from the mode names; they were not checked
against a title or the console here (the retail title tested never asks
for a swizzle mode).

Ported from amd-dev 081da4b9 (raylitebull).

What is in it

  • crates/xcl/src/hle/dstorage.rs: swizzle_chunks, swizzle_group_size, swizzle_interleave; the request check accepts modes 1–4 with a whole number of groups; the decompress path interleaves after zlib and BCPack; test swizzle_interleave_all_four_modes_and_validation and updated request-check asserts

Tested

  • NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on cf735734 (rebased onto main 3b6a91ed): 2722 passed, 4 failed, 49 ignored. The 4 failures are gpu::dxil::geometry_tests::msg_gs_done_emits_in_dxil, gpu::dxil::geometry_tests::gpu_geometry_msg_gs_done_records, gpu::dxil::lower_geom::tests::gpu_epilogue_filters_oob_triangles_and_no_store_emits and gpu::dxil::lower_mem::stage_guard_tests::geometry_export_rejected; they fail the same way on main 3b6a91ed (run here, and main's CI fails the two that need no GPU). SKIPPED GPU tests: 45 notices, almost all no wave64.
  • Retail title: 60 s smoke run below (no device removal or crash, frames and peak commit within the limits).

Regression run

main:

xcl-smoke v1
commit: 3b6a91ed096d6d6e0fee52cfb86dc0a7d7c8c1b0
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1193 (PresentX 1193)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15684 MB

this PR:

xcl-smoke v1
commit: cf735734a83ceef280d408d981d64afad0c1499d
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1446 (PresentX 1446)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15365 MB

Not tested

  • the group layouts themselves: they come from the mode names, the unit test checks the code against the same assumed layout, and the retail title tested never asks for a swizzle mode (no log line in any run), so no title data checks them. A wrong layout would turn a clean refusal into wrong textures.
  • AMD GPUs

AI use

  • Claude Code with Claude Opus 5.5: ported this part of the amd-dev commit named above to main, wrote the commit message and this description, ran the tests and the smoke run.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5548449261 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3310). Originally posted by [Foniass](https://github.com/Foniass) on 2026-11-29T06:58:49Z. --- **Draft: rayy (raylitebull, who wrote it), can you confirm the group layouts (or where they were checked)?** The code and tests are clean, but nothing here can verify the interleaving against a real title. A DirectStorage request may ask for one of the BCn swizzle modes, in which the stream holds each block component as its own array and the destination wants them interleaved in 16 KiB or 32 KiB groups (mode 1 4K_4K_8K: BC1 endpoints and indices; 2 4K_4K_24K: BC4; 3 4K_12K_4K_4K_8K: BC3 alpha and colour; 4 4K_12K_4K_12K: BC5). XCL refused every swizzled request (E_DECOMPRESSION). Modes 1–4 are now interleaved after zlib and BCPack (swizzle_interleave); a destination that is not a whole number of groups is E_DESTINATION_SIZE; modes above 4 are still refused. The group layouts come from the mode names; they were not checked against a title or the console here (the retail title tested never asks for a swizzle mode). Ported from amd-dev 081da4b9 (raylitebull). **What is in it** - `crates/xcl/src/hle/dstorage.rs`: `swizzle_chunks`, `swizzle_group_size`, `swizzle_interleave`; the request check accepts modes 1–4 with a whole number of groups; the decompress path interleaves after zlib and BCPack; test `swizzle_interleave_all_four_modes_and_validation` and updated request-check asserts **Tested** - NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke - `cargo test --workspace --no-fail-fast -- --test-threads=4` on cf735734 (rebased onto main 3b6a91ed): 2722 passed, 4 failed, 49 ignored. The 4 failures are `gpu::dxil::geometry_tests::msg_gs_done_emits_in_dxil`, `gpu::dxil::geometry_tests::gpu_geometry_msg_gs_done_records`, `gpu::dxil::lower_geom::tests::gpu_epilogue_filters_oob_triangles_and_no_store_emits` and `gpu::dxil::lower_mem::stage_guard_tests::geometry_export_rejected`; they fail the same way on main 3b6a91ed (run here, and main's CI fails the two that need no GPU). SKIPPED GPU tests: 45 notices, almost all `no wave64`. - Retail title: 60 s smoke run below (no device removal or crash, frames and peak commit within the limits). **Regression run** main: ``` xcl-smoke v1 commit: 3b6a91ed096d6d6e0fee52cfb86dc0a7d7c8c1b0 gpu: NVIDIA GeForce RTX 5070 Ti title: 3cb1d8e0 seconds: 60 exit: 0x0 frames shown: 1193 (PresentX 1193) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15684 MB ``` this PR: ``` xcl-smoke v1 commit: cf735734a83ceef280d408d981d64afad0c1499d gpu: NVIDIA GeForce RTX 5070 Ti title: 3cb1d8e0 seconds: 60 exit: 0x0 frames shown: 1446 (PresentX 1446) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15365 MB ``` **Not tested** - **the group layouts themselves**: they come from the mode names, the unit test checks the code against the same assumed layout, and the retail title tested never asks for a swizzle mode (no log line in any run), so no title data checks them. A wrong layout would turn a clean refusal into wrong textures. - AMD GPUs **AI use** - Claude Code with Claude Opus 5.5: ported this part of the amd-dev commit named above to main, wrote the commit message and this description, ran the tests and the smoke run. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
bmjask commented 2026-12-01 22:45:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T22:45:54Z.

Code review location: crates/xcl/src/hle/dstorage.rs; line 1082

@@ -1022,7 +1078,8 @@ unsafe fn execute(
     } else {
         src
     };
-    let payload = if bc != 0 { Cow::Owned(bcpack_unpack(r, &stage1, n)?) } else { stage1 };
+    let unpacked = if bc != 0 { Cow::Owned(bcpack_unpack(r, &stage1, n)?) } else { stage1 };
+    let payload = if swiz != 0 { Cow::Owned(swizzle_interleave(swiz, &unpacked[..n])?) } else { unpacked };

The swizzle reshuffle also runs on BCPack output, but bcpack_unpack returns ordinary interleaved BCn blocks, not one array per block component, so the same function gets two different input layouts. For BCPack BC1 + swizzle mode 1 with a 32 KiB dest, swizzle_interleave treats bytes 0..8K of 4096 normal 8-byte blocks as the whole-buffer e0 array, 8K..16K as e1, and so on. Each 16 KiB group gets slices of whole blocks in the wrong places, and the request reports S_OK. Either this path or the raw/zlib path is wrong.

<!-- greyfinch-sync:ivall/xcl:review-comment:4762100269 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3310#discussion_r4762100269). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T22:45:54Z. **Code review location:** `crates/xcl/src/hle/dstorage.rs`; line 1082 ~~~~diff @@ -1022,7 +1078,8 @@ unsafe fn execute( } else { src }; - let payload = if bc != 0 { Cow::Owned(bcpack_unpack(r, &stage1, n)?) } else { stage1 }; + let unpacked = if bc != 0 { Cow::Owned(bcpack_unpack(r, &stage1, n)?) } else { stage1 }; + let payload = if swiz != 0 { Cow::Owned(swizzle_interleave(swiz, &unpacked[..n])?) } else { unpacked }; ~~~~ --- The swizzle reshuffle also runs on BCPack output, but `bcpack_unpack` returns ordinary interleaved BCn blocks, not one array per block component, so the same function gets two different input layouts. For BCPack BC1 + swizzle mode 1 with a 32 KiB dest, `swizzle_interleave` treats bytes 0..8K of 4096 normal 8-byte blocks as the whole-buffer e0 array, 8K..16K as e1, and so on. Each 16 KiB group gets slices of whole blocks in the wrong places, and the request reports S_OK. Either this path or the raw/zlib path is wrong.
bmjask commented 2026-12-01 22:45:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T22:45:54Z.

Code review location: crates/xcl/src/hle/dstorage.rs; line 791

@@ -737,9 +788,13 @@ impl Request {
         if self.options & !KNOWN_OPTIONS_MASK != 0 {
             warn_once("DSTORAGE_REQUEST_OPTIONS", format_args!("unknown high option bits {:#x}", self.options & !KNOWN_OPTIONS_MASK));
         }
-        if self.swizzle() != 0 {
-            warn_once("SwizzleMode", format_args!("hardware swizzle mode {} unsupported", self.swizzle()));
+        let swiz = self.swizzle();

Modes 1-4 used to be refused with a warning. They're now on by default with an unverified layout (the PR says the group layouts come only from the mode names), and with no log line at all, not even a first-use info line like BCPack's. If any layout is wrong, every swizzled request returns S_OK with scrambled textures instead of E_DECOMPRESSION, and nothing in the log points here. The "no log line in any run" evidence also can't tell whether the title uses swizzle at all. An env opt-in like XCL_DSTORAGE_BCPACK_FILL, or a first-use log line, would avoid this.

<!-- greyfinch-sync:ivall/xcl:review-comment:4762100272 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3310#discussion_r4762100272). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T22:45:54Z. **Code review location:** `crates/xcl/src/hle/dstorage.rs`; line 791 ~~~~diff @@ -737,9 +788,13 @@ impl Request { if self.options & !KNOWN_OPTIONS_MASK != 0 { warn_once("DSTORAGE_REQUEST_OPTIONS", format_args!("unknown high option bits {:#x}", self.options & !KNOWN_OPTIONS_MASK)); } - if self.swizzle() != 0 { - warn_once("SwizzleMode", format_args!("hardware swizzle mode {} unsupported", self.swizzle())); + let swiz = self.swizzle(); ~~~~ --- Modes 1-4 used to be refused with a warning. They're now on by default with an unverified layout (the PR says the group layouts come only from the mode names), and with no log line at all, not even a first-use info line like BCPack's. If any layout is wrong, every swizzled request returns S_OK with scrambled textures instead of E_DECOMPRESSION, and nothing in the log points here. The "no log line in any run" evidence also can't tell whether the title uses swizzle at all. An env opt-in like XCL_DSTORAGE_BCPACK_FILL, or a first-use log line, would avoid this.
bmjask commented 2026-12-01 22:45:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T22:45:54Z.

Review: COMMENTED


Review of cf735734: 3 finding(s). 2 are inline. These are on lines outside the diff:

crates/xcl/src/hle/dstorage.rs:1075: zlib + swizzle with intermediate_size < destination_size (check() allows this for (true,0)): the inflated data is zero-padded to n before the reshuffle, so the padding is spread across every group. With intermediate=16 KiB, dest=32 KiB and mode 1, bytes 0..8K become e0 for both groups, 8K..16K become e1, and the padding is taken as all the index data. Group 0 gets zero indices and real index bytes are read as endpoints. The padding should come after the reshuffle, or the reshuffle should be limited to the real data.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

<!-- greyfinch-sync:ivall/xcl:review:6141551465 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3310#pullrequestreview-6141551465). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T22:45:54Z. **Review:** COMMENTED --- Review of `cf735734`: 3 finding(s). 2 are inline. These are on lines outside the diff: **`crates/xcl/src/hle/dstorage.rs:1075`**: zlib + swizzle with intermediate_size < destination_size (check() allows this for (true,0)): the inflated data is zero-padded to n before the reshuffle, so the padding is spread across every group. With intermediate=16 KiB, dest=32 KiB and mode 1, bytes 0..8K become e0 for both groups, 8K..16K become e1, and the padding is taken as all the index data. Group 0 gets zero indices and real index bytes are read as endpoints. The padding should come after the reshuffle, or the reshuffle should be limited to the real data. --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
Foniass commented 2026-12-02 08:05:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T08:05:54Z.


Closing: the swizzle group layouts are unverified (they were guessed from the mode names), no title we run asks for swizzle modes 1-4, and BCPack + swizzle would reshuffle already-interleaved blocks (dstorage.rs ~1082), so the request would return S_OK with scrambled data. Reopen, behind an opt-in and with the BCPack case refused, when a title needs these modes.

AI-assisted: Claude Code (Claude Opus 5.5), posted by Foniass.

<!-- greyfinch-sync:ivall/xcl:comment:7338999952 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3310#issuecomment-7338999952). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T08:05:54Z. --- Closing: the swizzle group layouts are unverified (they were guessed from the mode names), no title we run asks for swizzle modes 1-4, and BCPack + swizzle would reshuffle already-interleaved blocks (`dstorage.rs` ~1082), so the request would return S_OK with scrambled data. Reopen, behind an opt-in and with the BCPack case refused, when a title needs these modes. AI-assisted: Claude Code (Claude Opus 5.5), posted by Foniass.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3310
No description provided.