Skip to content

Shaders: lower partial-channel image_store - #332

Open
tarcisioads wants to merge 1 commit into
Marvisak:mainfrom
tarcisioads:shader/image-store-partial-dmask
Open

tarcisioads wants to merge 1 commit into
Marvisak:mainfrom
tarcisioads:shader/image-store-partial-dmask

Conversation

@tarcisioads

@tarcisioads tarcisioads commented Nov 24, 2026 •

Copy link
Copy Markdown

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)

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.

@tarcisioads

Copy link
Copy Markdown
Author

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

@fuzeofficlal

Copy link
Copy Markdown
Contributor

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.

@DrDarkDK

Copy link
Copy Markdown

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.

tecnofifamobile-ai added a commit to tecnofifamobile-ai/XEMSS that referenced this pull request Nov 24, 2026
* Lower nonzero RDNA2 image store channel masks

Follow the RDNA2 DMASK semantics and the DXIL typed UAV store contract. Exercise every nonzero mask with f32 and packed f16 stores on D3D12. Related to Marvisak/VIctory#920 and Marvisak/VIctory#332.

* Record image-store verification and shader timing scope

---------

Co-authored-by: tecnofifamobile-ai <255379004+tecnofifamobile-ai@users.noreply.github.com>
@tarcisioads

Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work. The lowering in Lower::image (crates/victory-shader/src/emit/lower.rs) follows the RDNA2 ISA text quoted in review (enabled channels from consecutive VGPRs, missing ones written as 0, DXIL mask 0xF). Remaining:

  1. The PR body still describes undef channels and dmask as the write mask; please update it.
  2. The d16 case isn't tested: the test sets d16 with << 15, but bit 15 of MIMG word 0 is R128 (gfx10/fields.rs); the decoder takes d16 from bit 31 of word 1, and 1 << 7 is DLC, not unorm (bit 12). The test also only checks that lower returns Ok.
  3. dmask == 0 now returns early and writes nothing; by the ISA text you rely on, all four channels would be written as 0. Please cite a source or readback, or keep refusing dmask == 0 stores.

Overlaps #160, which lowers partial image stores the same way with GPU-checked tests.

CI: no check runs on the head commit.


Generated by Claude Code

@tarcisioads
tarcisioads force-pushed the shader/image-store-partial-dmask branch from 7b68d7b to 5a5c155 Compare November 25, 2026 00:35
@tarcisioads

Copy link
Copy Markdown
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants