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

Open
davi713albano-coder wants to merge 1 commit from upstream-pr/146 into main
davi713albano-coder commented 2026-11-24 21:50:48 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by davi713albano-coder on 2026-11-24T21:50:48Z.


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.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6592117213 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/146). Originally posted by [davi713albano-coder](https://github.com/davi713albano-coder) on 2026-11-24T21:50:48Z. --- ### 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.)*
HAL9000RELOADED commented 2026-11-25 20:09:27 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HAL9000RELOADED on 2026-11-25T19:29:47Z.


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://github.com/fxceless/victory-fork/pull/129#issuecomment-7172358511).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7172376863 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/146#issuecomment-7172376863). Originally posted by [HAL9000RELOADED](https://github.com/HAL9000RELOADED) on 2026-11-25T19:29:47Z. --- 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://github.com/fxceless/victory-fork/pull/129#issuecomment-7172358511).
Castyan commented 2026-11-26 15:04:07 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Castyan on 2026-11-26T14:20:10Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:comment:7194653929 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/146#issuecomment-7194653929). Originally posted by [Castyan](https://github.com/Castyan) on 2026-11-26T14:20:10Z. --- 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 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/146:upstream-pr/146'
git switch 'upstream-pr/146'

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/146'
git switch 'upstream-pr/146'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/146'
git switch 'upstream-pr/146'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/146'
git switch 'main'
git merge --squash 'upstream-pr/146'
git switch 'main'
git merge --ff-only 'upstream-pr/146'
git switch 'main'
git merge 'upstream-pr/146'
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
fxceless/victory-fork!146
No description provided.