Shaders: read DXIL bitcode with abbreviations and BLOCKINFO #1953

Open
github-bot wants to merge 1 commit from github-bot/gh-1953 into main AGit
Owner

@⁠sombraSoft on GitHub · 2026-11-24 23:51 UTC · original
sombraSoft:shaders/dxil-bitreader → main · +439 −1 · 2 files · 1 commits · draft

Part of #1269. xcl shaders --explain (later in this stack) reports the structure of the DXIL a console program becomes (blocks, phis, values), the numbers the thread uses to explain driver compile cost. XCL can write DXIL bitcode but not read the abbreviated bitcode DXC emits; this adds a reader.

What is in it

  • Shaders: read DXIL bitcode with abbreviations and BLOCKINFO – crates/xcl/src/gpu/dxil/bitreader.rs: LLVM bitstream reader (fixed, VBR, char6, arrays, blobs, local and BLOCKINFO abbreviations). Iterative, and every length is checked against the bits left in its block, so malformed input is an Err, never a panic. No code from other DXIL readers (Kalmarv/dx is GPL-3.0 and was not used).

Tested

  • NVIDIA GeForce RTX 3060 Ti (driver 32.0.16.2124), AMD Ryzen 9 5900X, Windows 11 Pro 10.0.26300, rustc 1.97.1; tests in debug, smoke run in release; DXC 1.8.2502.11 (Windows SDK 10.0.26100)
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 852bb2d: 977 passed, 0 failed, 45 ignored
  • SKIPPED (all from existing tests): 18 × no wave64, 1 × no heap windows, 1 × cannot disable the driver cache (Developer Mode off), 3 × per-lane form refused (f16 / VOP3 modifiers)
  • unit tests: a hand-built stream with BLOCKINFO and local abbreviations, char6 arrays and a blob decodes exactly; every prefix and single-bit flip of it returns Ok or Err

Regression run

main:

xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: NVIDIA GeForce RTX 3060 Ti
title: 55118d47
seconds: 60
exit: 0x0
frames shown: 1075 (PresentX 1075)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15431 MB

this PR (852bb2d):

xcl-smoke v1
commit: 852bb2de707efab2910f4d2bfc7bb37cc2a428bf
gpu: NVIDIA GeForce RTX 3060 Ti
title: 55118d47
seconds: 60
exit: 0x0
frames shown: 1169 (PresentX 1170)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15335 MB

Not tested

  • AMD and Intel GPUs, GPUs with native wave64, DXC 1.9, Linux / vkd3d-proton
  • the title run does not use the reader (nothing calls it yet); it checks only that nothing else changed

AI use

  • Claude Code with Claude Opus 5.5: a subagent wrote the reader and its tests; the main session reviewed it and wrote this description. The tests and the smoke runs were run on the hardware above.
**@⁠sombraSoft** on GitHub · 2026-11-24 23:51 UTC · [original](https://github.com/xcl-dev/xcl/pull/1953) `sombraSoft:shaders/dxil-bitreader` → `main` · +439 −1 · 2 files · 1 commits · draft Part of #1269. `xcl shaders --explain` (later in this stack) reports the structure of the DXIL a console program becomes (blocks, phis, values), the numbers the thread uses to explain driver compile cost. XCL can write DXIL bitcode but not read the abbreviated bitcode DXC emits; this adds a reader. **What is in it** - `Shaders: read DXIL bitcode with abbreviations and BLOCKINFO` – `crates/xcl/src/gpu/dxil/bitreader.rs`: LLVM bitstream reader (fixed, VBR, char6, arrays, blobs, local and `BLOCKINFO` abbreviations). Iterative, and every length is checked against the bits left in its block, so malformed input is an `Err`, never a panic. No code from other DXIL readers (Kalmarv/dx is GPL-3.0 and was not used). **Tested** - NVIDIA GeForce RTX 3060 Ti (driver 32.0.16.2124), AMD Ryzen 9 5900X, Windows 11 Pro 10.0.26300, rustc 1.97.1; tests in debug, smoke run in release; DXC 1.8.2502.11 (Windows SDK 10.0.26100) - `cargo test --workspace --no-fail-fast -- --test-threads=4` on 852bb2d: 977 passed, 0 failed, 45 ignored - `SKIPPED` (all from existing tests): 18 × no wave64, 1 × no heap windows, 1 × cannot disable the driver cache (Developer Mode off), 3 × per-lane form refused (f16 / VOP3 modifiers) - unit tests: a hand-built stream with BLOCKINFO and local abbreviations, char6 arrays and a blob decodes exactly; every prefix and single-bit flip of it returns Ok or Err **Regression run** main: ``` xcl-smoke v1 commit: 689f2db477c3c062cf162649781640ef8a977c18 gpu: NVIDIA GeForce RTX 3060 Ti title: 55118d47 seconds: 60 exit: 0x0 frames shown: 1075 (PresentX 1075) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15431 MB ``` this PR (852bb2d): ``` xcl-smoke v1 commit: 852bb2de707efab2910f4d2bfc7bb37cc2a428bf gpu: NVIDIA GeForce RTX 3060 Ti title: 55118d47 seconds: 60 exit: 0x0 frames shown: 1169 (PresentX 1170) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15335 MB ``` **Not tested** - AMD and Intel GPUs, GPUs with native wave64, DXC 1.9, Linux / vkd3d-proton - the title run does not use the reader (nothing calls it yet); it checks only that nothing else changed **AI use** - Claude Code with Claude Opus 5.5: a subagent wrote the reader and its tests; the main session reviewed it and wrote this description. The tests and the smoke runs were run on the hardware above.
A compile-cost report needs to read the DXIL that DXC emits, and the only
reader in the tree (bitreader_tests.rs) handles the unabbreviated records
our own writer produces. DXC's LLVM 3.7 writer uses abbreviations defined
in BLOCKINFO and locally, char6 arrays and blobs.

BitReader walks the bitstream one entry at a time (enter block, end block,
record) with the block stack on the heap, so nesting depth costs no
recursion. BLOCKINFO is consumed internally; skip_block jumps over blocks a
caller does not need. Every count read from the stream (operands, array
elements, blob bytes, block lengths) is checked against the bits left in
its block before anything is read or allocated, and bitcode that is not
whole 32-bit words is refused, so corrupt input is an Err, not a panic or
a large allocation.

Tested: a hand-assembled stream with a BLOCKINFO abbreviation (literal
code, fixed, VBR, char6 array) and a local one (fixed code, blob) decodes
to the expected records; every prefix and every single-bit flip of it
reads without a panic.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:11:24 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 02:59 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 02:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/1953#issuecomment-7151471697) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This pull request can be merged automatically.
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 origin '+refs/pull/1953/head:github-bot/gh-1953'
git switch 'github-bot/gh-1953'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1953'
git switch 'github-bot/gh-1953'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1953'
git switch 'github-bot/gh-1953'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1953'
git switch 'main'
git merge --squash 'github-bot/gh-1953'
git switch 'main'
git merge --ff-only 'github-bot/gh-1953'
git switch 'main'
git merge 'github-bot/gh-1953'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.