Shaders: lower image_store with any non-zero channel mask (including sparse) #146

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

@⁠davi713albano-coder on GitHub · 2026-11-24 21:50 UTC · original
davi713albano-coder:shader/image-store-partial-dmask → main · +244 −12 · 2 files · 1 commits · open

Summary

Lowers image_store for all non-zero channel masks (0x1..=0xF, including sparse masks such as 0x5, 0x9, 0xD, both 32-bit float and d16 packed f16) and treats dmask == 0 as a no-op (without normalizing it to 0x1 as loads/samples do).

In RDNA2, image_store packs only the channels enabled by dmask into consecutive VGPRs (or 16-bit halves when d16 is set) and writes 0.0 to disabled channels. DXIL typed UAV dx.op.textureStore.f32 requires a full 0xF write mask on 4-component declarations (the host format drops channels past its width), so disabled channels are zero-padded with 0.0f32.

Changes

  • crates/victory-shader/src/emit/lower.rs:
    • Keep dmask == 0 intact for image_store (returning Ok(()) as a no-op instead of normalizing to &1).
    • Unpack consecutive VGPRs / d16 halves for each enabled bit in dmask (0x1..=0xF), zero-padding unselected channels with 0.0f32, and emit dx.op.textureStore.f32(..., 0xF).
  • crates/victory-shader/src/emit/valu_tests.rs:
    • Add synthetic compute test image_store_partial_dmask_writes_expected_channels testing 10 cases (0x0, 0x1, 0x3, 0x7, sparse 0x5, 0x9, and d16 0x1, 0x3, 0x7, 0xD) against dxil.dll validation and live D3D12 WARP 4-channel RGBA readback.

Verification

  • Fork CI (windows-latest): https://github.com/davi713albano-coder/victory-fork/actions/runs/45494029704
    • cargo clippy --workspace --all-targets --locked -- -D warnings: passed
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed
    • cargo test --workspace --locked (including xtask asset-policy check, dxil.dll validation, and D3D12 WARP readback): 497 passed, 0 failed (emit::valu_tests::image_store_partial_dmask_writes_expected_channels ... ok)

(No title data used. AI-assisted.)

**@⁠davi713albano-coder** on GitHub · 2026-11-24 21:50 UTC · [original](https://github.com/fxceless/victory-fork/pull/146) `davi713albano-coder:shader/image-store-partial-dmask` → `main` · +244 −12 · 2 files · 1 commits · open ### Summary Lowers `image_store` for all non-zero channel masks (`0x1..=0xF`, including sparse masks such as `0x5`, `0x9`, `0xD`, both 32-bit float and `d16` packed f16) and treats `dmask == 0` as a no-op (without normalizing it to `0x1` as loads/samples do). In RDNA2, `image_store` packs only the channels enabled by `dmask` into consecutive VGPRs (or 16-bit halves when `d16` is set) and writes `0.0` to disabled channels. DXIL typed UAV `dx.op.textureStore.f32` requires a full `0xF` write mask on 4-component declarations (the host format drops channels past its width), so disabled channels are zero-padded with `0.0f32`. ### Changes - `crates/victory-shader/src/emit/lower.rs`: - Keep `dmask == 0` intact for `image_store` (returning `Ok(())` as a no-op instead of normalizing to `&1`). - Unpack consecutive VGPRs / `d16` halves for each enabled bit in `dmask` (`0x1..=0xF`), zero-padding unselected channels with `0.0f32`, and emit `dx.op.textureStore.f32(..., 0xF)`. - `crates/victory-shader/src/emit/valu_tests.rs`: - Add synthetic compute test `image_store_partial_dmask_writes_expected_channels` testing 10 cases (`0x0`, `0x1`, `0x3`, `0x7`, sparse `0x5`, `0x9`, and `d16` `0x1`, `0x3`, `0x7`, `0xD`) against `dxil.dll` validation and live D3D12 WARP 4-channel RGBA readback. ### Verification - Fork CI (`windows-latest`): https://github.com/davi713albano-coder/victory-fork/actions/runs/45494029704 - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed - `cargo test --workspace --locked` (including `xtask` asset-policy check, `dxil.dll` validation, and D3D12 WARP readback): 497 passed, 0 failed (`emit::valu_tests::image_store_partial_dmask_writes_expected_channels ... ok`) *(No title data used. AI-assisted.)*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:56 +00:00
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-25 19:29 UTC · original

RX 7900 XTX (RDNA3), Windows 10 + #402 for SM 6.6, main d510ee4: the new test image_store_partial_dmask_writes_expected_channels passes on the card with this PR, and fails with the test alone on the base. No other test changed. Run table: #129 (#129).

**@⁠HAL9000RELOADED** on GitHub · 2026-11-25 19:29 UTC · [original](https://github.com/fxceless/victory-fork/pull/146#issuecomment-7172376863) RX 7900 XTX (RDNA3), Windows 10 + #402 for SM 6.6, main `d510ee4`: the new test `image_store_partial_dmask_writes_expected_channels` passes on the card with this PR, and fails with the test alone on the base. No other test changed. Run table: #129 (https://git.gtahub.st/github/fxceless--victory-fork/pulls/129).
Author
Owner

@⁠Castyan on GitHub · 2026-11-26 14:20 UTC · original

Thanks for this change. It is ported to DexNom/VIctory#64 as 90580ec (authorship kept), with one adaptation: the test's HostShader gets two fields that tree adds (written_root_uavs, writes_guest_memory).

How it does on real code there: the compute programs a title passes to device method 0x218 use partial image_store masks a lot. Of 200 such descriptions captured in game, 60 were refused as "an image store of some channels". With this change all of them get past image stores, and your 10-case test passes on an RTX 5060 and on WARP.

The same rule (given channels first, the others written as 0) was applied to typed buffer stores of fewer than four channels (buffer_store_format_x/xy/xyz/d16_x), with a readback test on a typed RGBA16F buffer. If you find a hardware reference that contradicts the zeroed channels, it would affect both.

Details: https://github.com/DexNom/VIctory/pull/64#issuecomment-7194648018

🤖 Generated with Claude Code

**@⁠Castyan** on GitHub · 2026-11-26 14:20 UTC · [original](https://github.com/fxceless/victory-fork/pull/146#issuecomment-7194653929) Thanks for this change. It is ported to DexNom/VIctory#64 as `90580ec` (authorship kept), with one adaptation: the test's `HostShader` gets two fields that tree adds (`written_root_uavs`, `writes_guest_memory`). How it does on real code there: the compute programs a title passes to device method 0x218 use partial `image_store` masks a lot. Of 200 such descriptions captured in game, 60 were refused as "an image store of some channels". With this change all of them get past image stores, and your 10-case test passes on an RTX 5060 and on WARP. The same rule (given channels first, the others written as 0) was applied to typed buffer stores of fewer than four channels (`buffer_store_format_x/xy/xyz/d16_x`), with a readback test on a typed RGBA16F buffer. If you find a hardware reference that contradicts the zeroed channels, it would affect both. Details: https://github.com/DexNom/VIctory/pull/64#issuecomment-7194648018 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/valu_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/146/head:github-bot/gh-146'
git switch 'github-bot/gh-146'

Merge

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