DirectStorage: gate BC7 rotation by mode #3081

Open
mokkamokacaffe wants to merge 1 commit from upstream-pr/3081 into main
mokkamokacaffe commented 2026-11-27 23:09:39 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by mokkamokacaffe on 2026-11-27T23:09:39Z.


Part of #3011.

BC7 control bits 3–4 encode channel rotation only in modes 4 and 5. The existing XCL BCPack port reads them as rotation in every mode; in the other modes those bits have different meanings, so this can swap alpha with a colour channel.

This ports the mode gate from ScarlettPort #108, which credits fxceless/victory-fork 06702fe via VIscosity b8e7001d.

What is in it

  • crates/xcl/src/hle/bcpack/victory.rs: read BC7 rotation only for modes 4 and 5 in both precision selection and block packing.
  • crates/xcl/src/hle/bcpack/victory.rs: add a regression covering modes 0–7 and confirm rotation bits do not alter precision in modes 0–3, 6, or 7.
  • THIRD_PARTY.md: record the ScarlettPort provenance and upstream credits.

Tested

  • Foniass’s contributor report reported a successful workspace build and 2,901 passed, 0 failed, 51 ignored, with 28 explicit skips on the integration of 197d9872 onto 493dbd3d. The table audit found zero out-of-mode rotation bits among 512 CTRL7 entries and 255 BC7 dictionary entries. The synthetic control-word tests leave bc7_pack coverage open.

  • Hardware: NVIDIA GeForce RTX 4080 SUPER, driver 617.14; Intel Core i9-14900KF; 63.7 GiB RAM.

  • Windows 11 Pro 10.0.26100.

  • Rust 1.100.0, Cargo 1.100.0, x86_64-pc-windows-msvc.

  • DXC/DXIL 1.9.2609.5; D3D12 Agility SDK 1.620.2.

  • Debug and release profiles.

  • Tested head: 197d9872eb27da31ba7ede7185131624170d2696.

  • Tested main: 2c717a043c8488938179fca81da4bb9e7913a358.

  • cargo build --workspace: passed.

  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1,467 passed, 0 failed, 47 ignored.

  • Focused exact regression: 1 passed, 0 failed.

  • BCPack tests: 7 passed, 0 failed.

  • python -B -m unittest discover -s scripts -p "test_*.py" -v: 25 passed, 0 failed.

  • cargo build --release --locked -p xcl: passed separately on main and this head.

  • git diff --check: passed.

  • Explicit GPU SKIPPED results:

    • 21: no wave64.
    • 1: no heap windows.
    • 1 each: unsupported V_MUL_F16, V_PK_MUL_F16 VOP3 modifiers, and V_CVT_F16_F32 semantics.
  • Paired retail smokes used clean worktrees and separate copies of the same 33,752-file starting shader cache. Both exited normally with no device removal or crash.

  • Windows/NVIDIA integration check by @Kalmarv for head 197d9872: the merge-check used base fa204595a4, passed cargo build --workspace, and reported 2,600 passed, 0 failed, 49 ignored and 9 filtered, including all nine BCPack tests. Earlier, upipibi independently inspected the shipped tables on 2c717a0. Both source audits found zero shipped CTRL7 or BC7-dictionary entries with rotation bits set outside modes 4/5, supporting this as spec/fuzzer hardening rather than an expected title-visible change.

Regression run

main:

xcl-smoke v1
commit: 2c717a043c8488938179fca81da4bb9e7913a358
gpu: NVIDIA GeForce RTX 4080 SUPER
title: retail-local
seconds: 60
exit: 0x0
frames shown: 1230 (PresentX 1230)
presents per 2 s (last 3): 39 37 42
device removals: 0
crashes: 0
peak commit: 15008 MB

PR:

xcl-smoke v1
commit: 197d9872eb27da31ba7ede7185131624170d2696
gpu: NVIDIA GeForce RTX 4080 SUPER
title: retail-local
seconds: 60
exit: 0x0
frames shown: 1176 (PresentX 1176)
presents per 2 s (last 3): 42 34 29
device removals: 0
crashes: 0
peak commit: 14961 MB

Not tested

  • AMD, Intel, or native wave64 GPU hardware.
  • Heap-window mode.
  • A visual retail before/after scene containing affected BC7 data.
  • The retail smoke logs showed thousands of successful DirectStorage requests but no BCPack first-use message, so the smokes are regression coverage rather than proof that the corrected BC7 path was reached.
  • No performance conclusion is drawn from the two single 60-second runs.

AI use

  • OpenAI Codex with GPT-6.2 Astra identified the upstream divergence, ported the mode gate and regression/provenance, ran the local validation, and drafted this description under my supervision. I reviewed the diff and the reported results.
<!-- greyfinch-sync:ivall/xcl:issue:5534265545 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3081). Originally posted by [mokkamokacaffe](https://github.com/mokkamokacaffe) on 2026-11-27T23:09:39Z. --- Part of #3011. BC7 control bits 3–4 encode channel rotation only in modes 4 and 5. The existing XCL BCPack port reads them as rotation in every mode; in the other modes those bits have different meanings, so this can swap alpha with a colour channel. This ports the mode gate from [ScarlettPort #108](https://github.com/ZigZagBoi1/ScarlettPort/pull/108), which credits fxceless/victory-fork `06702fe` via VIscosity `b8e7001d`. **What is in it** - `crates/xcl/src/hle/bcpack/victory.rs`: read BC7 rotation only for modes 4 and 5 in both precision selection and block packing. - `crates/xcl/src/hle/bcpack/victory.rs`: add a regression covering modes 0–7 and confirm rotation bits do not alter precision in modes 0–3, 6, or 7. - `THIRD_PARTY.md`: record the ScarlettPort provenance and upstream credits. **Tested** - [Foniass’s contributor report](https://github.com/xcl-dev/xcl/pull/3081#issuecomment-7309823921) reported a successful workspace build and 2,901 passed, 0 failed, 51 ignored, with 28 explicit skips on the integration of 197d9872 onto 493dbd3d. The table audit found zero out-of-mode rotation bits among 512 CTRL7 entries and 255 BC7 dictionary entries. The synthetic control-word tests leave bc7_pack coverage open. - Hardware: NVIDIA GeForce RTX 4080 SUPER, driver 617.14; Intel Core i9-14900KF; 63.7 GiB RAM. - Windows 11 Pro 10.0.26100. - Rust 1.100.0, Cargo 1.100.0, x86_64-pc-windows-msvc. - DXC/DXIL 1.9.2609.5; D3D12 Agility SDK 1.620.2. - Debug and release profiles. - Tested head: `197d9872eb27da31ba7ede7185131624170d2696`. - Tested main: `2c717a043c8488938179fca81da4bb9e7913a358`. - `cargo build --workspace`: passed. - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 1,467 passed, 0 failed, 47 ignored. - Focused exact regression: 1 passed, 0 failed. - BCPack tests: 7 passed, 0 failed. - `python -B -m unittest discover -s scripts -p "test_*.py" -v`: 25 passed, 0 failed. - `cargo build --release --locked -p xcl`: passed separately on main and this head. - `git diff --check`: passed. - Explicit GPU `SKIPPED` results: - 21: `no wave64`. - 1: `no heap windows`. - 1 each: unsupported `V_MUL_F16`, `V_PK_MUL_F16` VOP3 modifiers, and `V_CVT_F16_F32` semantics. - Paired retail smokes used clean worktrees and separate copies of the same 33,752-file starting shader cache. Both exited normally with no device removal or crash. - Windows/NVIDIA integration check by @Kalmarv for head `197d9872`: the [merge-check](https://github.com/xcl-dev/xcl/pull/3081#issuecomment-7251641081) used base fa204595a488c60c6c5f905244f0172072c9c2a9, passed cargo build --workspace, and reported 2,600 passed, 0 failed, 49 ignored and 9 filtered, including all nine BCPack tests. Earlier, [upipibi independently inspected the shipped tables](https://github.com/xcl-dev/xcl/pull/3081#issuecomment-7229997181) on `2c717a0`. Both source audits found zero shipped CTRL7 or BC7-dictionary entries with rotation bits set outside modes 4/5, supporting this as spec/fuzzer hardening rather than an expected title-visible change. **Regression run** main: ``` xcl-smoke v1 commit: 2c717a043c8488938179fca81da4bb9e7913a358 gpu: NVIDIA GeForce RTX 4080 SUPER title: retail-local seconds: 60 exit: 0x0 frames shown: 1230 (PresentX 1230) presents per 2 s (last 3): 39 37 42 device removals: 0 crashes: 0 peak commit: 15008 MB ``` PR: ``` xcl-smoke v1 commit: 197d9872eb27da31ba7ede7185131624170d2696 gpu: NVIDIA GeForce RTX 4080 SUPER title: retail-local seconds: 60 exit: 0x0 frames shown: 1176 (PresentX 1176) presents per 2 s (last 3): 42 34 29 device removals: 0 crashes: 0 peak commit: 14961 MB ``` **Not tested** - AMD, Intel, or native wave64 GPU hardware. - Heap-window mode. - A visual retail before/after scene containing affected BC7 data. - The retail smoke logs showed thousands of successful DirectStorage requests but no BCPack first-use message, so the smokes are regression coverage rather than proof that the corrected BC7 path was reached. - No performance conclusion is drawn from the two single 60-second runs. **AI use** - OpenAI Codex with GPT-6.2 Astra identified the upstream divergence, ported the mode gate and regression/provenance, ran the local validation, and drafted this description under my supervision. I reviewed the diff and the reported results.
upipibi commented 2026-11-27 23:15:22 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-27T23:15:22Z.


The fix is right for BC7. One thing reviewers may want to know: with the tables xcl ships, it changes no decoded block. I checked by reading the tables, not by running anything.

A BC7 control word comes from CTRL7 (tables.rs:154 on main 2c717a0), indexed by stream bits at victory.rs:617, or from a dictionary entry's Bc7Ep.ctrl (tables.rs:1440). I counted the words with bits 3-4 set outside modes 4 and 5:

table words modes rotation bits outside 4/5
CTRL7 512 0: 243, 1: 64, 2: 64, 3: 64, 4: 8, 5: 4, 6: 1, 7: 64 0
BC7 dictionary 255 0: 1, 1: 1, 4: 1, 5: 1, 6: 251 0

So, with the shipped tables, the alpha/colour swap the description mentions doesn't happen. The same holds for the other effect of the old read. In mode 1, a rotation swaps alpha's precision of 0 into red, so field(row, 0, prec[0]) (victory.rs:734) shifts a u16 right by 16 (:717), which panics in a debug build. On VIctory#3111, which makes the same fix upstream, gabrielvbraga reached that panic with a fuzzer only after overwriting table bytes, and noted that the built-in tables never set these bits (comment).

That makes this a low-risk hardening, worth keeping for its test, with no visible change to expect in a title.

AI-assisted (Claude Code, Claude Opus 5.5 read the code and counted the table words).

<!-- greyfinch-sync:ivall/xcl:comment:7229997181 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3081#issuecomment-7229997181). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-27T23:15:22Z. --- The fix is right for BC7. One thing reviewers may want to know: with the tables xcl ships, it changes no decoded block. I checked by reading the tables, not by running anything. A BC7 control word comes from `CTRL7` (`tables.rs:154` on `main` `2c717a0`), indexed by stream bits at `victory.rs:617`, or from a dictionary entry's `Bc7Ep.ctrl` (`tables.rs:1440`). I counted the words with bits 3-4 set outside modes 4 and 5: | table | words | modes | rotation bits outside 4/5 | |---|---|---|---| | `CTRL7` | 512 | 0: 243, 1: 64, 2: 64, 3: 64, 4: 8, 5: 4, 6: 1, 7: 64 | 0 | | `BC7` dictionary | 255 | 0: 1, 1: 1, 4: 1, 5: 1, 6: 251 | 0 | So, with the shipped tables, the alpha/colour swap the description mentions doesn't happen. The same holds for the other effect of the old read. In mode 1, a rotation swaps alpha's precision of 0 into red, so `field(row, 0, prec[0])` (`victory.rs:734`) shifts a `u16` right by 16 (`:717`), which panics in a debug build. On VIctory#3111, which makes the same fix upstream, gabrielvbraga reached that panic with a fuzzer only after overwriting table bytes, and noted that the built-in tables never set these bits ([comment](https://github.com/Marvisak/VIctory/pull/3111#issuecomment-7199337769)). That makes this a low-risk hardening, worth keeping for its test, with no visible change to expect in a title. AI-assisted (Claude Code, Claude Opus 5.5 read the code and counted the table words).
Kalmarv commented 2026-11-29 06:05:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T06:05:26Z.


merge-check
base: fa204595a4
head: 197d9872eb
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests:: -> 2600 passed, 0 failed, 49 ignored, 9 filtered (26 SKIPPED: 21 no wave64, 3 wave32 per-lane #1426 semantics, 2 no heap windows); failing: none (all 9 bcpack tests including bc7_rotation_tests::rotation_is_read_only_in_modes_4_and_5 passed)
review: none blocking. Whole diff read (THIRD_PARTY.md provenance note + crates/xcl/src/hle/bcpack/victory.rs bc7_rotation, bc7_precision, bc7_pack, and bc7_rotation_tests). Confirmed by inspecting tables.rs that shipped CTRL7 (512 entries) and BC7 dictionary (255 entries) already have 0 entries outside modes 4/5 with rotation bits [4:3] set, so this changes no decoded blocks with shipped tables and acts as clean BC7 spec/fuzzer hardening. Note: GitHub Build and test (Windows, no GPU) has not yet been approved to run on this head.
performance: zero measurable impact by default (reasoned: one branch on ctrl & 7 in bc7_rotation inside BC7 block unpack).
verdict: safe to merge
hardware / tool and model: Windows 11 Pro (build 26200), NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074, wave32), AMD Ryzen 9 9950X, rustc 1.99.0 (b940084d7 2026-09-28), DXC 1.9.2609; Antigravity (reviewed full diff, audited tables.rs, ran merge/build/workspace suite).

<!-- greyfinch-sync:ivall/xcl:comment:7251641081 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3081#issuecomment-7251641081). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T06:05:26Z. --- merge-check base: fa204595a488c60c6c5f905244f0172072c9c2a9 head: 197d9872eb27da31ba7ede7185131624170d2696 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests:: -> 2600 passed, 0 failed, 49 ignored, 9 filtered (26 SKIPPED: 21 no wave64, 3 wave32 per-lane #1426 semantics, 2 no heap windows); failing: none (all 9 bcpack tests including bc7_rotation_tests::rotation_is_read_only_in_modes_4_and_5 passed) review: none blocking. Whole diff read (`THIRD_PARTY.md` provenance note + `crates/xcl/src/hle/bcpack/victory.rs` `bc7_rotation`, `bc7_precision`, `bc7_pack`, and `bc7_rotation_tests`). Confirmed by inspecting `tables.rs` that shipped `CTRL7` (512 entries) and `BC7` dictionary (255 entries) already have 0 entries outside modes 4/5 with rotation bits [4:3] set, so this changes no decoded blocks with shipped tables and acts as clean BC7 spec/fuzzer hardening. Note: GitHub `Build and test (Windows, no GPU)` has not yet been approved to run on this head. performance: zero measurable impact by default (reasoned: one branch on `ctrl & 7` in `bc7_rotation` inside BC7 block unpack). verdict: safe to merge hardware / tool and model: Windows 11 Pro (build 26200), NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074, wave32), AMD Ryzen 9 9950X, rustc 1.99.0 (b940084d7 2026-09-28), DXC 1.9.2609; Antigravity (reviewed full diff, audited tables.rs, ran merge/build/workspace suite).
Foniass commented 2026-12-01 09:27:56 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:27:56Z.


Triage (#1607) – head 197d987

No open or merged PR changes the BC7 rotation handling in bcpack/victory.rs; the other PRs on #3011 are unrelated (ray tracing / wave-local work).
The gate does not change any decode today: every BC7 control word comes from tables::CTRL7, and all of its entries for modes 0-3, 6 and 7 have bits 3-4 = 0, so the alpha/colour swap the description mentions cannot happen with XCL's tables. The description should say this is hardening with no behaviour change; the test only uses synthetic control words not in the table.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7306739544 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3081#issuecomment-7306739544). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:27:56Z. --- **Triage (#1607)** – head 197d987 No open or merged PR changes the BC7 rotation handling in `bcpack/victory.rs`; the other PRs on #3011 are unrelated (ray tracing / wave-local work). The gate does not change any decode today: every BC7 control word comes from `tables::CTRL7`, and all of its entries for modes 0-3, 6 and 7 have bits 3-4 = 0, so the alpha/colour swap the description mentions cannot happen with XCL's tables. The description should say this is hardening with no behaviour change; the test only uses synthetic control words not in the table. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Foniass commented 2026-12-01 11:34:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T11:34:13Z.


merge-check
base: 493dbd3dd0
head: 197d9872eb
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2901 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (+37/-2). Rotation bits now count only in BC7 modes 4 and 5, which is what the format defines. Findings: (1) No block decodes differently today. The control word always comes from a table, and I counted rotation bits outside modes 4 / 5: 0 of 512 in CTRL7 and 0 of 255 in the BC7 dictionary. So the description's "can swap alpha with a colour channel" doesn't happen with these tables; it's hardening, and the description should say so. (2) The test checks bc7_rotation / bc7_precision on made-up control words, while bc7_pack (victory.rs ~713) isn't covered. (3) Build and test (Windows, no GPU) hasn't run on this head (only PR description and triage are listed); the run below covers that. Fine: the p-bit +1 applies again in modes 0 / 1 / 3 / 6 / 7, the mode-4 index-selection bit is written unchanged, and the 2-bit-then-3-bit index order is right either way. No smoke run: the retail title's runs log no BCPack use, and the output would be identical anyway.
performance: no smoke run (the default path doesn't reach this change); not measured. No block from the current tables has rotation bits outside modes 4 / 5, so output is identical.
verdict: safe to merge (hardening: no block from the current tables decodes differently; the description could say so)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7309823921 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3081#issuecomment-7309823921). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T11:34:13Z. --- merge-check base: 493dbd3dd0cd50b4c3e8d28f73ab9b504fcd8158 head: 197d9872eb27da31ba7ede7185131624170d2696 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2901 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none review: read the whole diff (+37/-2). Rotation bits now count only in BC7 modes 4 and 5, which is what the format defines. Findings: (1) **No block decodes differently today.** The control word always comes from a table, and I counted rotation bits outside modes 4 / 5: 0 of 512 in `CTRL7` and 0 of 255 in the `BC7` dictionary. So the description's "can swap alpha with a colour channel" doesn't happen with these tables; it's hardening, and the description should say so. (2) The test checks `bc7_rotation` / `bc7_precision` on made-up control words, while `bc7_pack` (`victory.rs` ~713) isn't covered. (3) `Build and test (Windows, no GPU)` hasn't run on this head (only `PR description` and `triage` are listed); the run below covers that. Fine: the p-bit +1 applies again in modes 0 / 1 / 3 / 6 / 7, the mode-4 index-selection bit is written unchanged, and the 2-bit-then-3-bit index order is right either way. No smoke run: the retail title's runs log no BCPack use, and the output would be identical anyway. performance: no smoke run (the default path doesn't reach this change); not measured. No block from the current tables has rotation bits outside modes 4 / 5, so output is identical. verdict: safe to merge (hardening: no block from the current tables decodes differently; the description could say so) hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 AI-written and posted by Foniass without a human check of each point.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3081:upstream-pr/3081'
git switch 'upstream-pr/3081'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3081'
git switch 'upstream-pr/3081'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3081'
git switch 'upstream-pr/3081'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3081'
git switch 'main'
git merge --squash 'upstream-pr/3081'
git switch 'main'
git merge --ff-only 'upstream-pr/3081'
git switch 'main'
git merge 'upstream-pr/3081'
git push origin 'main'
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!3081
No description provided.