Shaders: lower partial-channel image_store #332

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

@⁠tarcisioads on GitHub · 2026-11-24 02:21 UTC · original
tarcisioads:shader/image-store-partial-dmask → main · +106 −9 · 1 files · 1 commits · open

Support partial-channel image_store (dmask != 0xF, dmask != 0) in crates/victory-shader/src/emit/lower.rs:

  • Read enabled channels sequentially from consecutive v[reg..] registers (for both 32-bit and d16 packed f16), pad missing channels with 0.0f (self.s.m.f32(0)), and pass 0xF as the writeMask argument of dx.op.textureStore.f32 (matching RDNA2 MIMG DMASK semantics and the DXIL validator's typed-UAV rule).
  • Refuse image_store with dmask == 0 explicitly ("an image store with no channels").
  • Add unit test partial_channel_image_store_lowers covering 0x0 refusal, 32-bit partial masks (0x1, 0x3, 0x5), and d16 partial mask (0x7, encoded at word 1 bit 31) with unorm = 1 (word 0 bit 12), verifying SFI0 RESOURCE_HEAP emission.

Verification

  • cargo test -p victory-shader (119 passed, 0 failed, 1 ignored benchmark on macOS; Windows dxil.dll validation not run)
  • cargo xtask policy (ok)
**@⁠tarcisioads** on GitHub · 2026-11-24 02:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/332) `tarcisioads:shader/image-store-partial-dmask` → `main` · +106 −9 · 1 files · 1 commits · open Support partial-channel `image_store` (`dmask != 0xF`, `dmask != 0`) in `crates/victory-shader/src/emit/lower.rs`: - Read enabled channels sequentially from consecutive `v[reg..]` registers (for both 32-bit and `d16` packed f16), pad missing channels with `0.0f` (`self.s.m.f32(0)`), and pass `0xF` as the `writeMask` argument of `dx.op.textureStore.f32` (matching RDNA2 `MIMG DMASK` semantics and the DXIL validator's typed-UAV rule). - Refuse `image_store` with `dmask == 0` explicitly (`"an image store with no channels"`). - Add unit test `partial_channel_image_store_lowers` covering `0x0` refusal, 32-bit partial masks (`0x1`, `0x3`, `0x5`), and `d16` partial mask (`0x7`, encoded at word 1 bit 31) with `unorm = 1` (word 0 bit 12), verifying `SFI0` `RESOURCE_HEAP` emission. ### Verification - `cargo test -p victory-shader` (119 passed, 0 failed, 1 ignored benchmark on macOS; Windows `dxil.dll` validation not run) - `cargo xtask policy` (ok)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:59:35 +00:00
Author
Owner

@⁠r4tedx on GitHub · 2026-11-24 03:14 UTC · original

Review note: the partial mask is passed through to DXIL (args.push(self.s.m.i8(*dmask))), and the DXIL validator rejects that for a typed UAV. Adding validation to this PR's own fixture (dxil.dll from the Windows SDK, RTX 5070 machine) fails on the first store, mask 1, with

store on typed uav must write to all four components of the UAV

The console's rule for the channels left out is in the RDNA 2 ISA (MIMG DMASK): "Writes: defines which components are written with data from VGPRs (missing components get 0). Enabled components come from consecutive VGPRs." So the DXIL store needs mask 0xF with zeros in the channels the dmask leaves out, and the data VGPRs are the enabled channels in order (for dmask = 0x5, red is in VGPRn and blue in VGPRn+1). #160 does it that way.

D3D12 only checks the container hash, so a driver may still take the module; that is why the test passes without the validator.

From the documents and synthetic tests only; I have no copy of the title and have not run this on console hardware.

**@⁠r4tedx** on GitHub · 2026-11-24 03:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/332#issuecomment-7120904021) Review note: the partial mask is passed through to DXIL (`args.push(self.s.m.i8(*dmask))`), and the DXIL validator rejects that for a typed UAV. Adding validation to this PR's own fixture (dxil.dll from the Windows SDK, RTX 5070 machine) fails on the first store, mask `1`, with ``` store on typed uav must write to all four components of the UAV ``` The console's rule for the channels left out is in the RDNA 2 ISA (MIMG `DMASK`): "Writes: defines which components are written with data from VGPRs (missing components get 0). Enabled components come from consecutive VGPRs." So the DXIL store needs mask `0xF` with zeros in the channels the dmask leaves out, and the data VGPRs are the enabled channels in order (for `dmask = 0x5`, red is in VGPRn and blue in VGPRn+1). #160 does it that way. D3D12 only checks the container hash, so a driver may still take the module; that is why the test passes without the validator. From the documents and synthetic tests only; I have no copy of the title and have not run this on console hardware.
Author
Owner

@⁠tarcisioads on GitHub · 2026-11-24 11:18 UTC · original

Rebased onto main (ffe310e) and addressed @⁠r4tedx's DXIL validator feedback in a5b0dcb:

  • Fill disabled channels in dmask with 0.0f (self.s.m.f32(0)) and pass 0xF as the writeMask of dx.op.textureStore.f32.
  • cargo test -p victory-shader (97 passed, 0 failed on macOS; dxil.dll validation still needs Windows).
**@⁠tarcisioads** on GitHub · 2026-11-24 11:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/332#issuecomment-7129937577) Rebased onto `main` (`ffe310e`) and addressed @⁠r4tedx's DXIL validator feedback in `a5b0dcb`: - Fill disabled channels in `dmask` with `0.0f` (`self.s.m.f32(0)`) and pass `0xF` as the `writeMask` of `dx.op.textureStore.f32`. - `cargo test -p victory-shader` (97 passed, 0 failed on macOS; `dxil.dll` validation still needs Windows).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 14:20 UTC · original

I retested a5b0dcb on Windows with Microsoft’s DXIL validator and a 1×1 RGBA32F UAV initialized to [7, 8, 9, 10]. Both shaders validated and produced the same results on the default hardware adapter and explicit WARP.

  • dmask=0x9, f32: [1.5, 0, 0, -2.25]
  • dmask=0xb, d16: [1.5, -2, 0, 4]

Test commit checks all channels against a nonzero starting texel to distinguish clearing from leaving a channel untouched. It also corrects the existing lowering test’s d16 selector to bit 31 of MIMG word 1. Bit 15 of word 0 controls R128. The changes are confined to tests and the test harness. victory-shader --lib passed 122 tests with one ignored, and Clippy and the asset check passed.

**@⁠fuzeofficlal** on GitHub · 2026-11-24 14:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/332#issuecomment-7134205530) I retested `a5b0dcb` on Windows with Microsoft’s DXIL validator and a 1×1 RGBA32F UAV initialized to `[7, 8, 9, 10]`. Both shaders validated and produced the same results on the default hardware adapter and explicit WARP. - `dmask=0x9`, f32: `[1.5, 0, 0, -2.25]` - `dmask=0xb`, d16: `[1.5, -2, 0, 4]` [Test commit](https://github.com/fuzeofficlal/VIctory/commit/a5541cd17bb3e7692681d13f63867cde5057c8e1) checks all channels against a nonzero starting texel to distinguish clearing from leaving a channel untouched. It also corrects the existing lowering test’s d16 selector to bit 31 of MIMG word 1. Bit 15 of word 0 controls R128. The changes are confined to tests and the test harness. `victory-shader --lib` passed 122 tests with one ignored, and Clippy and the asset check passed.
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-24 15:01 UTC · original

I extended the initialized RGBA32F readback from a5541cd with dmask=0x0 and 0x1, then ran the same inputs on this PR (a5b0dcb) and the #920 branch (f1c423f). The starting texel was [7, 8, 9, 10].

Mask #332 #920
0x0 [1.5, 0, 0, 0] [7, 8, 9, 10]
0x1 [1.5, 0, 0, 0] [1.5, 0, 0, 0]

The results were identical for f32 and packed d16 on native Windows, RTX 4070 Ti and WARP. All compared shaders passed DXIL validation.

On #332, the shared zero-mask normalization changes 0x0 to 0x1 before store lowering. The #920 branch preserves zero for stores and emits no write. A native RDNA2 readback would settle which behavior to carry forward.

AI-assisted with Codex.

**@⁠DrDarkDK** on GitHub · 2026-11-24 15:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/332#issuecomment-7135330885) I extended the initialized RGBA32F readback from `a5541cd` with `dmask=0x0` and `0x1`, then ran the same inputs on this PR (`a5b0dcb`) and the #920 branch (`f1c423f`). The starting texel was `[7, 8, 9, 10]`. | Mask | #332 | #920 | | --- | --- | --- | | `0x0` | `[1.5, 0, 0, 0]` | `[7, 8, 9, 10]` | | `0x1` | `[1.5, 0, 0, 0]` | `[1.5, 0, 0, 0]` | The results were identical for f32 and packed d16 on native Windows, RTX 4070 Ti and WARP. All compared shaders passed DXIL validation. On #332, the shared zero-mask normalization changes `0x0` to `0x1` before store lowering. The #920 branch preserves zero for stores and emits no write. A native RDNA2 readback would settle which behavior to carry forward. *AI-assisted with Codex.*
Author
Owner

@⁠tarcisioads on GitHub · 2026-11-24 15:43 UTC · original

Updated shader/image-store-partial-dmask so image_store with dmask == 0 is treated as a no-op (returns Ok(()) without emitting dx.op.textureStore.f32, matching RDNA2 IMAGE_STORE DMASK = 0 semantics), instead of being normalized to dmask = 1. Added dmask = 0x0 to partial_channel_image_store_lowers; cargo test -p victory-shader (97 passed, 0 failed on macOS).

**@⁠tarcisioads** on GitHub · 2026-11-24 15:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/332#issuecomment-7136494654) Updated `shader/image-store-partial-dmask` so `image_store` with `dmask == 0` is treated as a no-op (returns `Ok(())` without emitting `dx.op.textureStore.f32`, matching RDNA2 `IMAGE_STORE` `DMASK = 0` semantics), instead of being normalized to `dmask = 1`. Added `dmask = 0x0` to `partial_channel_image_store_lowers`; `cargo test -p victory-shader` (97 passed, 0 failed on macOS).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:28 UTC · original · edited 2026-11-25 22:22 UTC

Automated triage for the maintainers.

Needs rebase. main has moved since the last triage, and this PR no longer merges cleanly into it (conflict in crates/victory-shader/src/emit/lower.rs). It will be reviewed again once it is rebased onto current main.

Previous verdict for this head: merge candidate.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/332#issuecomment-7148545491) · edited 2026-11-25 22:22 UTC <!-- victory-triage v1 head=0915bf5c1f588aea20a07c0b4ce982f9bcb8e119 verdict=needs-rebase at=2026-11-25T22:22:10Z --> Automated triage for the maintainers. **Needs rebase.** `main` has moved since the last triage, and this PR no longer merges cleanly into it (conflict in `crates/victory-shader/src/emit/lower.rs`). It will be reviewed again once it is rebased onto current `main`. Previous verdict for this head: merge candidate. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠tarcisioads on GitHub · 2026-11-25 00:35 UTC · original

Addressed all three triage points:

  1. Updated the PR description to accurately describe 0.0f padding and 0xF writeMask.
  2. Fixed the MIMG test encoding (d16 at word 1 bit 31, unorm at word 0 bit 12) and added assertions on the emitted SFI0 RESOURCE_HEAP flag and dmask == 0 refusal.
  3. Reverted dmask == 0 to refuse ("an image store with no channels") rather than no-op.
  • cargo test -p victory-shader (119 passed, 0 failed on macOS).
**@⁠tarcisioads** on GitHub · 2026-11-25 00:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/332#issuecomment-7148666222) Addressed all three triage points: 1. Updated the PR description to accurately describe `0.0f` padding and `0xF` writeMask. 2. Fixed the MIMG test encoding (`d16` at word 1 bit 31, `unorm` at word 0 bit 12) and added assertions on the emitted `SFI0` `RESOURCE_HEAP` flag and `dmask == 0` refusal. 3. Reverted `dmask == 0` to refuse (`"an image store with no channels"`) rather than no-op. - `cargo test -p victory-shader` (119 passed, 0 failed on macOS).
Author
Owner

@⁠Machad3x on GitHub · 2026-11-25 22:02 UTC · original

Hardware result: tested at head 0915bf5c. One host: RTX 3080 Ti, driver 621.24, Windows 11, a fork stacking open PRs, Series X mode. Cherry-picked together with #2816 and #2831: the shader tests pass apart from one failure the stack had before (a view heap cap test), and one 7-minute run in play had no device removal. Offline refused containers across the three went from 214 to 213 (not attributed to one PR). On the stack, the added test needed the stack's extra Parts fields.

Ran with AI assistance (Claude Code).

**@⁠Machad3x** on GitHub · 2026-11-25 22:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/332#issuecomment-7175851884) Hardware result: tested at head 0915bf5c. One host: RTX 3080 Ti, driver 621.24, Windows 11, a fork stacking open PRs, Series X mode. Cherry-picked together with #2816 and #2831: the shader tests pass apart from one failure the stack had before (a view heap cap test), and one 7-minute run in play had no device removal. Offline refused containers across the three went from 214 to 213 (not attributed to one PR). On the stack, the added test needed the stack's extra `Parts` fields. Ran with AI assistance (Claude Code).
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.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/332/head:github-bot/gh-332'
git switch 'github-bot/gh-332'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-332'
git switch 'github-bot/gh-332'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-332'
git switch 'github-bot/gh-332'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-332'
git switch 'main'
git merge --squash 'github-bot/gh-332'
git switch 'main'
git merge --ff-only 'github-bot/gh-332'
git switch 'main'
git merge 'github-bot/gh-332'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!332
No description provided.