fix: recompute the container checksum after stripping Xbox shader chunks #49

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

@⁠marquezinii on GitHub · 2026-11-23 12:17 UTC · original
marquezinii:fix/dxbc-checksum-after-strip → main · +140 −3 · 2 files · 1 commits · open

TL;DR

  • Problem: A shader that carries Xbox-private chunks can't be turned into a pipeline state. D3D12 rejects it once the chunks are stripped.
  • Fix: The stripped container gets a new checksum computed over its own bytes.

TranslateXboxShaderToPc rebuilds the DXBC/DXIL container without the XBOX/XS2M/XDBG/XBIN chunks, but copies bytes 4..19 from the input. Those bytes are the container checksum, and the copied one was computed over the old contents. D3D12 checks it, so D3D12XboxCreateGraphicsPipelineState and D3D12XboxCreateComputePipelineState failed for any shader that had something stripped. The raytracing PSO is unaffected because its state object is software-backed and never passes these bytes to D3D12. Shaders without Xbox chunks are passed through unchanged and were never affected.

The rebuilt container now gets its checksum recomputed: MD5 over bytes 20..end with the D3D compiler's own last-block padding. It's about 80 lines in shader_ir.cpp and adds no dependencies.

test_shader_pipeline now takes four fxc-compiled shaders, appends an XBOX chunk with the checksum zeroed, and checks that stripping gives back the original fxc output byte for byte. That also checks the checksum against the compiler's. One of the four shaders is there because of its size: its last block takes the other padding path. The test then builds a graphics PSO on WARP from a VS with an XBOX chunk and a PS with an XS2M chunk. Without the fix the byte comparison fails, and if that check is skipped, WARP's CreateGraphicsPipelineState rejects the PSO. Outside the test I also checked the same algorithm against two signed DXIL containers from dxc (ps_6_0 and lib_6_3), and it matched both.

Verified on Windows 11 with MSVC (VS Build Tools 18), the same way CI runs:

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release   (and Debug)
cmake --build build --parallel
ctest --test-dir build --output-on-failure

26/26 pass in Release and Debug. With only the test change applied, test_shader_pipeline fails.

**@⁠marquezinii** on GitHub · 2026-11-23 12:17 UTC · [original](https://github.com/Freminet/ScarlettX/pull/49) `marquezinii:fix/dxbc-checksum-after-strip` → `main` · +140 −3 · 2 files · 1 commits · open **TL;DR** - **Problem:** A shader that carries Xbox-private chunks can't be turned into a pipeline state. D3D12 rejects it once the chunks are stripped. - **Fix:** The stripped container gets a new checksum computed over its own bytes. `TranslateXboxShaderToPc` rebuilds the DXBC/DXIL container without the `XBOX`/`XS2M`/`XDBG`/`XBIN` chunks, but copies bytes 4..19 from the input. Those bytes are the container checksum, and the copied one was computed over the old contents. D3D12 checks it, so `D3D12XboxCreateGraphicsPipelineState` and `D3D12XboxCreateComputePipelineState` failed for any shader that had something stripped. The raytracing PSO is unaffected because its state object is software-backed and never passes these bytes to D3D12. Shaders without Xbox chunks are passed through unchanged and were never affected. The rebuilt container now gets its checksum recomputed: MD5 over bytes 20..end with the D3D compiler's own last-block padding. It's about 80 lines in `shader_ir.cpp` and adds no dependencies. `test_shader_pipeline` now takes four fxc-compiled shaders, appends an `XBOX` chunk with the checksum zeroed, and checks that stripping gives back the original fxc output byte for byte. That also checks the checksum against the compiler's. One of the four shaders is there because of its size: its last block takes the other padding path. The test then builds a graphics PSO on WARP from a VS with an `XBOX` chunk and a PS with an `XS2M` chunk. Without the fix the byte comparison fails, and if that check is skipped, WARP's `CreateGraphicsPipelineState` rejects the PSO. Outside the test I also checked the same algorithm against two signed DXIL containers from dxc (`ps_6_0` and `lib_6_3`), and it matched both. Verified on Windows 11 with MSVC (VS Build Tools 18), the same way CI runs: ``` cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release (and Debug) cmake --build build --parallel ctest --test-dir build --output-on-failure ``` 26/26 pass in Release and Debug. With only the test change applied, `test_shader_pipeline` fails.
TranslateXboxShaderToPc rebuilt the DXBC/DXIL container without the
Xbox-private chunks but kept the input's checksum, which no longer matched
the contents. D3D12 rejects such a container, so graphics and compute PSOs
could not be created from a shader that had chunks stripped. The rebuilt
container now gets its checksum recomputed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:57:02 +00:00
This pull request can be merged automatically.
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/49/head:github-bot/gh-49'
git switch 'github-bot/gh-49'

Merge

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