Skip to content

Shaders: image stores of some channels, to mip 0, and to integer views - #1955

Open
RaghavVijayanand wants to merge 4 commits into
Marvisak:mainfrom
RaghavVijayanand:shader/image-stores
Open

RaghavVijayanand wants to merge 4 commits into
Marvisak:mainfrom
RaghavVijayanand:shader/image-stores

Conversation

@RaghavVijayanand

@RaghavVijayanand RaghavVijayanand commented Nov 25, 2026 •

Copy link
Copy Markdown

Three image-store refusals in the translator. Each is its own commit, and each builds and passes tests.

  • Stores of some channels (dmask != 0xF): the data VGPRs hold only the enabled channels, in channel order (d16: two per VGPR). Each dword now goes to its channel, and the channels left out are written as 0. That behavior follows the AMD ISA guides' DMASK description and LLVM's handling; it has not been checked on console hardware. The host store keeps a full 0xF mask, because dxil.dll rejects partial masks on typed UAV stores.
  • image_store_mip: a level that is a constant 0 stores to the view's own level. A non-zero or computed level is still refused, because it would need a view per level.
  • Integer stores: the view's format is in the descriptor, which is only read at run time. When an image atomic in the same program uses the same descriptor, the view must be R32_UINT or R32_SINT, so stores to it now use textureStore.i32. Integer views with no atomic still get a float store; that is documented.
  • The same handle-cache key fix as Shaders: heap handles are reused only for the same resource properties #1953, which is that fix alone, with a test that fails without it. It is needed here so that atomics (U32) and stores (F32x4) on one descriptor get their own handles. Whichever of the two merges second has a trivial conflict on those lines.

Tests: the new emit/image_store_tests.rs (6 tests) covers:

  • all 15 dmasks on RGBA32_FLOAT, and 7 d16 dmasks
  • RGBA32_UINT and R32_UINT views with denormal, NaN and -0 bit patterns
  • mip level 0 accepted, while level 1 and computed levels are refused
  • an atomic plus a store on R32_UINT

Each program is validated with dxil.dll and run on the default hardware adapter and WARP. Each fix was broken on purpose to confirm a test fails. The test host gains View::Uint4TextureUav (RGBA32_UINT) beside main's Uint2TextureUav. The integer-store detection also treats main's 64-bit atomics (R32G32_UINT) as proof of an integer view.

This PR and #1956 (cube/MSAA) both touch image() in emit/lower.rs, so merging both needs a small manual merge.

Rebased onto current main (940d32f). On this machine, 5 tests fail on main itself, with or without this change: descriptor::host::tests::dynamic_slots_are_held_until_released, memory::tests::lists_share_a_table_and_copies_keep_their_views, the two stride_tests::a_heap_buffer_read_* tests, and synthetic_tests::gathers_at_a_level_match_the_hardware. Everything else passes, and clippy passes with -D warnings, with and without --all-features.

Copilot AI balanced review requested due to automatic review settings November 25, 2026 01:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (merge candidate) was for an older state of main.


Generated by Claude Code

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.

144 passed / 0 failed / 2 ignored. Image stores of some channels, to mip 0, and to integer views — partial-channel store lowering.

@StExpeditus

Copy link
Copy Markdown

Test report: RTX 5060 Ti (Blackwell), Windows 11 Pro 26200, driver 621.24. Branch at 6abd8ff. cargo test --workspace --locked --no-fail-fast -> 702 passed, 5 failed, 10 ignored. The failures are the same 5 pre-existing NVIDIA 1M-view-heap-cap failures (also on main; see my reports on #2030 and #1940). Nothing introduced by this PR fails on this machine.

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 6abd8ff onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

An image_store whose dmask left out a channel stopped the program ("an
image store of some channels"). Its data VGPRs hold the enabled channels
only, in channel order (d16: two per VGPR, low half first), and the
console writes the channels left out as 0 (the ISA guides' DMASK
description; LLVM trims zero channels from image stores on the same
grounds). The store now maps each data dword to its channel and writes 0
to the others. The host's store still writes all four channels with a
0xF mask: dxil.dll refuses a typed UAV store with a narrower mask ("store
on typed uav must write to all four components of the UAV"), which was
checked by emitting the dmask as the mask.

Tests: emit/image_store_tests.rs hand-assembles a compute program that
fills texel (1, 1) of a 2x2 texture UAV with a four-channel store, then
stores to it with the dmask under test; the program is validated by
dxil.dll and run on the default hardware adapter and WARP, and the whole
texture is read back. They cover all fifteen dmasks on RGBA32_FLOAT,
seven d16 dmasks, and RGBA32_UINT and R32_UINT views with denormal, NaN
and negative-zero bit patterns (which reach the integer views unchanged
through the float store on both). The host harness gains an RGBA32_UINT
texture UAV, and texture readback takes each view's format. With each
data dword put in the channel of its index rather than its channel's,
all three tests fail.
image_store_mip stopped the program ("an image store to a mip level").
Its level, the address after the coordinates, counts from the
descriptor's base level, and DXIL's textureStore has no level: a UAV
views a single level. Taking the host's view to be the one the title
made for that base level, a store to level 0 is a store to the view, and
now lowers as image_store does (the level read as a constant, either half
with 16-bit addresses). Another level would need a view per level, which
the title's heap does not hold; it, and a level the program computes,
still stop the program, now with "an image store to a mip level other
than 0 or unknown". The packed stores (image_store_pck, _mip_pck), which
also stopped it under the old message, now stop it with their names.

Tests: in emit/image_store_tests.rs, image_store_mip with an inline 0
level is validated by dxil.dll and run on the default hardware adapter
and WARP (RGBA32_FLOAT dmasks 0xF and 0x9, R32_UINT dmask 0x1), and
levels 1 and a root constant are checked to stop the program. With the
check loosened to accept any constant level, the second test fails.
Every image store went to DXIL's textureStore.f32 on a handle of four
F32 channels, whatever the view's format; the console converts by the
format, which is in the descriptor the program reads when it runs, so
the translator cannot see it. One thing does tell: an image atomic in
the same program on the same descriptor (the same source, or another
load of the same table entry), as the host's typed atomics take only
R32_UINT and R32_SINT views (and R32G32_UINT for main's 64-bit image
atomics). Stores to such a view now go to textureStore.i32 on a handle
of four U32 channels, with the data VGPRs as integers and, with d16,
each 16-bit half zero-extended rather than converted as an f16 (a
shortcut for signed formats wider than 16 bits, noted at the store).

Every other store stays a float store, a shortcut noted at the store:
D3D leaves a float store to an integer view undefined. On the default
hardware adapter and WARP, the tests show such stores writing their
dwords to RGBA32_UINT and R32_UINT views unchanged, denormal and NaN
patterns included; d16 data there is still converted as f16.

Handles were cached per block by descriptor and resource kind only, so
an atomic's U32 handle and a float access's F32 handle of the same
descriptor in one block shared whichever came first (main's atomics
annotate (kind | UAV, 0x105), a store (kind | UAV, 0x409): the same first
dword); the cache key now holds both annotated property dwords.

Tests: in emit/image_store_tests.rs, a program first adds 0 to the
texel with image_atomic_add through a second load of the descriptor,
then stores to an R32_UINT view: dwords with denormal and NaN patterns,
and d16 halves (5 and 0xFFFF), which as f16 would land as 0x34a00000 and
a NaN. Validated with dxil.dll and run on the default hardware
adapter and WARP. With the integer path turned off, or with only the
same-source match kept (not the same table entry), the test fails on
the d16 case.
@RaghavVijayanand

Copy link
Copy Markdown
Author

Rebased onto main 63bcca4. Two adjustments for what main gained since: the test harness's new zeroing of texture UAVs passes the texture's format to footprint_as (which this branch made format-aware), and the handle caches main added (entry block, join block) are keyed on both property dwords, as in #1953. Each commit builds. On an RTX 5060 Laptop: the image store/atomic tests pass (7), clippy is clean, and the rest of victory-shader passes except the three NVIDIA 1M-view-heap-cap tests that fail on unmodified main there too (stride_tests x2, gathers_at_a_level_match_the_hardware).

lower.rs grew past the repository's 512 KiB file limit with this branch on
top of main; the descriptor check moves to lower/images.rs unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

6 participants