Shaders: lower image_store with contiguous partial channel masks (dmask 0x1, 0x3, 0x7) #920

Open
opened 2026-11-26 04:14:09 +00:00 by github-bot · 4 comments
Owner

@⁠davi713albano-coder on GitHub · 2026-11-24 14:10 UTC · original

### Summary

Lowers image_store with contiguous partial channel masks (dmask = 0x1, 0x3, 0x7, and no-op 0x0, both 32-bit float and d16 packed 16-bit) in crates/victory-shader/src/emit/lower.rs, unlocking shaders that store to 1-, 2-, and 3-channel float/unorm/snorm UAVs (RWTexture*<float>, float2, float3) instead of failing with an image store of some channels.

Because external PR creation is restricted (collaborators_only), the CI-green branch is ready on my fork:

Changes

  • crates/victory-shader/src/emit/lower.rs:
    • Preserves dmask == 0 for image_store (emitting a no-op instead of defaulting to channel 0 as loads/samples do).
    • Accepts contiguous masks 0x1, 0x3, 0x7, 0xF (rejecting sparse/non-contiguous masks such as 0x5 because DXIL typed UAV stores cannot perform partial read-modify-write stores without clobbering lower channels).
    • Reads only the dmask.count_ones() packed VGPRs (or half-VGPRs for d16), zero-pads trailing channels with 0.0f32, and emits dx.op.textureStore.f32 with write mask 0xF as required by the DXIL validator (store on typed uav must write to all four components of the UAV); host D3D12 drops extra components according to the bound UAV format.
  • crates/victory-shader/src/emit/valu_tests.rs: adds image_store_partial_dmask_writes_expected_channels.

Tests & Verification

image_store_partial_dmask_writes_expected_channels exercises:

  • Rejection of non-contiguous dmask = 0x5 with Unsupported("an image store of some channels").
  • Full DXIL validation (dxil.dll) and live D3D12 UAV readback across dmask = 0x0, 0x1, 0x3, 0x7 (32-bit float) and 0x1, 0x3, 0x7 (d16 packed f16).

Verified on GitHub Actions (windows-latest) using upstream ci.yml (cargo clippy --workspace --all-targets --locked -- -D warnings, --all-features, and cargo test --workspace --locked including xtask asset-policy check):

Not tested: live title execution.
No game data used. AI-assisted.

**@⁠davi713albano-coder** on GitHub · 2026-11-24 14:10 UTC · [original](https://github.com/Marvisak/VIctory/issues/920) ### Summary Lowers `image_store` with contiguous partial channel masks (`dmask` = `0x1`, `0x3`, `0x7`, and no-op `0x0`, both 32-bit float and `d16` packed 16-bit) in `crates/victory-shader/src/emit/lower.rs`, unlocking shaders that store to 1-, 2-, and 3-channel float/unorm/snorm UAVs (`RWTexture*<float>`, `float2`, `float3`) instead of failing with `an image store of some channels`. Because external PR creation is restricted (`collaborators_only`), the CI-green branch is ready on my fork: - **Branch:** https://github.com/davi713albano-coder/VIctory/commits/shader/image-store-partial-dmask - **Commit:** `f1c423f` (based on `main` `ffe310e`, 2 files, +218/-9) - **Compare:** https://github.com/Marvisak/VIctory/compare/main...davi713albano-coder:shader/image-store-partial-dmask ### Changes - **`crates/victory-shader/src/emit/lower.rs`**: - Preserves `dmask == 0` for `image_store` (emitting a no-op instead of defaulting to channel 0 as loads/samples do). - Accepts contiguous masks `0x1`, `0x3`, `0x7`, `0xF` (rejecting sparse/non-contiguous masks such as `0x5` because DXIL typed UAV stores cannot perform partial read-modify-write stores without clobbering lower channels). - Reads only the `dmask.count_ones()` packed VGPRs (or half-VGPRs for `d16`), zero-pads trailing channels with `0.0f32`, and emits `dx.op.textureStore.f32` with write mask `0xF` as required by the DXIL validator (`store on typed uav must write to all four components of the UAV`); host D3D12 drops extra components according to the bound UAV format. - **`crates/victory-shader/src/emit/valu_tests.rs`**: adds `image_store_partial_dmask_writes_expected_channels`. ### Tests & Verification `image_store_partial_dmask_writes_expected_channels` exercises: - Rejection of non-contiguous `dmask = 0x5` with `Unsupported("an image store of some channels")`. - Full DXIL validation (`dxil.dll`) and live D3D12 UAV readback across `dmask` = `0x0`, `0x1`, `0x3`, `0x7` (32-bit float) and `0x1`, `0x3`, `0x7` (`d16` packed f16). Verified on GitHub Actions (`windows-latest`) using upstream `ci.yml` (`cargo clippy --workspace --all-targets --locked -- -D warnings`, `--all-features`, and `cargo test --workspace --locked` including `xtask` asset-policy check): - `victory-shader`: 121 passed, 0 failed (full workspace: 343 passed, 0 failed, 6 ignored) - CI run: https://github.com/davi713albano-coder/VIctory/actions/runs/45409892529 **Not tested:** live title execution. No game data used. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:09 +00:00
Author
Owner

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

RDNA 2 defines sparse image_store masks such as 0x9. The selected components are packed into consecutive VGPRs and unselected components are written as zero. AMD RDNA 2 ISA, Table 41 and section 8.2.5

#332 already implements this for sparse masks while emitting the full 0xF write required by DXIL. I verified its current head (a5b0dcb) with 0x9 f32 and 0xb d16 against an initialized RGBA32F UAV. Windows hardware and WARP both overwrote the disabled channels with zero, and both shaders passed DXIL validation. The test and results cover nonzero masks.

**@⁠fuzeofficlal** on GitHub · 2026-11-24 14:20 UTC · [original](https://github.com/Marvisak/VIctory/issues/920#issuecomment-7134218589) RDNA 2 defines sparse `image_store` masks such as `0x9`. The selected components are packed into consecutive VGPRs and unselected components are written as zero. [AMD RDNA 2 ISA, Table 41 and section 8.2.5](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture) #332 already implements this for sparse masks while emitting the full `0xF` write required by DXIL. I verified its current head (`a5b0dcb`) with `0x9` f32 and `0xb` d16 against an initialized RGBA32F UAV. Windows hardware and WARP both overwrote the disabled channels with zero, and both shaders passed DXIL validation. The [test and results](https://git.gtahub.st/github/Marvisak--VIctory/pulls/332) cover nonzero masks.
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 14:25 UTC · original

Independent four-channel readback on RTX 4090 under Wine/vkd3d-proton 3.2: exact f1c423f refuses sparse mask 0x5. With sparse lowering added to that branch, the f32 case returned [1.5, 0, -2.25, 0], and packed d16 mask 0xd returned [1.5, 0, -2, 4]. All eleven fixture cases matched their complete expected texels. For the zero-mask control, the shader first stored four distinct nonzero values and all four survived the second store. That checks the branch’s no-op behavior independently of the texture’s initial contents.

The existing #332 Windows hardware and WARP result already verifies nonzero sparse masks against an initialized UAV. These Wine results add different masks and the seeded zero-mask control. We have no title shader or rendered frame attributed to this change.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 14:25 UTC · [original](https://github.com/Marvisak/VIctory/issues/920#issuecomment-7134341789) Independent four-channel readback on RTX 4090 under Wine/vkd3d-proton 3.2: exact f1c423f refuses sparse mask `0x5`. With sparse lowering added to that branch, the f32 case returned `[1.5, 0, -2.25, 0]`, and packed d16 mask `0xd` returned `[1.5, 0, -2, 4]`. All eleven fixture cases matched their complete expected texels. For the zero-mask control, the shader first stored four distinct nonzero values and all four survived the second store. That checks the branch’s no-op behavior independently of the texture’s initial contents. The existing [#332 Windows hardware and WARP result](https://git.gtahub.st/github/Marvisak--VIctory/pulls/332) already verifies nonzero sparse masks against an initialized UAV. These Wine results add different masks and the seeded zero-mask control. We have no title shader or rendered frame attributed to this change.
Author
Owner

@⁠davi713albano-coder on GitHub · 2026-11-24 17:22 UTC · original

Thanks @⁠fuzeofficlal and @⁠MichaelSmithAI for the RDNA 2 ISA reference and the RTX 4090 check!

Updated the branch (0c5a47d) to lower all non-zero image_store channel masks (0x1..=0xF), including sparse masks:

  • Packs enabled channels in ascending channel order from consecutive VGPRs (or 16-bit halves for d16) and fills disabled channels with 0.0f32 before emitting textureStore.f32(..., 0xF).
  • Expanded image_store_partial_dmask_writes_expected_channels to assert full 4-channel RGBA readback across 0x0, 0x1, 0x3, 0x7, sparse 0x5 ([1.5, 0, -2.25, 0]), sparse 0x9 ([1.5, 0, 0, 4.0]), and d16 0x1, 0x3, 0x7, sparse 0xD ([1.5, 0, -2.0, 4.0]).

Verified on GitHub Actions (windows-latest, upstream ci.yml — clippy -D warnings with and without --all-features, cargo test --workspace --locked, asset-policy check):

**@⁠davi713albano-coder** on GitHub · 2026-11-24 17:22 UTC · [original](https://github.com/Marvisak/VIctory/issues/920#issuecomment-7139109871) Thanks @⁠fuzeofficlal and @⁠MichaelSmithAI for the RDNA 2 ISA reference and the RTX 4090 check! Updated the branch (`0c5a47d`) to lower all non-zero `image_store` channel masks (`0x1..=0xF`), including sparse masks: - Packs enabled channels in ascending channel order from consecutive VGPRs (or 16-bit halves for `d16`) and fills disabled channels with `0.0f32` before emitting `textureStore.f32(..., 0xF)`. - Expanded `image_store_partial_dmask_writes_expected_channels` to assert full 4-channel RGBA readback across `0x0`, `0x1`, `0x3`, `0x7`, sparse `0x5` (`[1.5, 0, -2.25, 0]`), sparse `0x9` (`[1.5, 0, 0, 4.0]`), and `d16` `0x1`, `0x3`, `0x7`, sparse `0xD` (`[1.5, 0, -2.0, 4.0]`). Verified on GitHub Actions (`windows-latest`, upstream `ci.yml` — clippy `-D warnings` with and without `--all-features`, `cargo test --workspace --locked`, asset-policy check): - `victory-shader`: 121 passed, 0 failed (full workspace: 343 passed, 0 failed, 6 ignored) - CI run: https://github.com/davi713albano-coder/VIctory/actions/runs/45446795636
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 06:57 UTC · original

Automated triage for the maintainers.

On main, image_store with any mask other than all four channels is still refused with "an image store of some channels" (crates/victory-shader/src/emit/lower.rs). Open PR #332 ("Shaders: lower partial-channel image_store") already lowers these masks, sparse ones included, and has Windows hardware and WARP results, so review can continue there. Your updated branch (0c5a47d) now does the same, so it can be compared with #332; please bring any test it has that #332 lacks to that PR.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 06:57 UTC · [original](https://github.com/Marvisak/VIctory/issues/920#issuecomment-7155327946) <!-- victory-issue-triage v1 verdict=tracked seen=2026-11-24T17:22:58Z at=2026-11-25T06:57:03Z --> Automated triage for the maintainers. On `main`, `image_store` with any mask other than all four channels is still refused with "an image store of some channels" (`crates/victory-shader/src/emit/lower.rs`). Open PR #332 ("Shaders: lower partial-channel image_store") already lowers these masks, sparse ones included, and has Windows hardware and WARP results, so review can continue there. Your updated branch (`0c5a47d`) now does the same, so it can be compared with #332; please bring any test it has that #332 lacks to that PR. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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#920
No description provided.