Skip to content

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

Open
davi713albano-coder wants to merge 1 commit into
fxceless:mainfrom
davi713albano-coder:shader/image-store-partial-dmask
Open

davi713albano-coder wants to merge 1 commit into
fxceless:mainfrom
davi713albano-coder:shader/image-store-partial-dmask

Conversation

@davi713albano-coder

Copy link
Copy Markdown

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

JustDownTV pushed a commit to JustDownTV/victory-gta6 that referenced this pull request Nov 24, 2026
@HAL9000RELOADED

Copy link
Copy Markdown

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

Castyan added a commit to Castyan/VIctory that referenced this pull request Nov 26, 2026
Port of fxceless/victory-fork#146 (67f7ff0) by davi713albano-coder.

image_store packs the channels its dmask enables into consecutive VGPRs
(16-bit halves with d16), in channel order, and writes 0 to the others.
DXIL's typed textureStore writes all four channels, and the host format
drops those past its width, so the disabled ones are written as 0.0.
A store with dmask 0 writes nothing.

Before, only dmask 0xF was taken, and the 0x218 programs' partial
stores were refused ("an image store of some channels", 60 of the 200
descriptions captured in game). Of those 200, 64 now reach a hardware
pipeline (24 before).

The channel order and the zeroed channels follow AMD's MIMG description
as the PR and other RDNA2 translators read it; the test checks this
lowering (10 masks, sparse and d16 ones included) on the host, not the
console's hardware. Adapted here: the test's HostShader takes the two
fields this tree adds.

Co-Authored-By: Castyan <120135015+Castyan@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Castyan

Castyan commented Nov 26, 2026

Copy link
Copy Markdown

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: DexNom/VIctory#64 (comment)

🤖 Generated with Claude Code

HAL9000RELOADED added a commit to HAL9000RELOADED/victory-fork that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants