Skip to content

Shaders: five translation fixes from cool_fox and VIctory-NVIDIA-RT (image queries, scalar destinations, CalculateLOD on arrays, partial stores, LDS negated adds) - #3064

Open
Adriwin06 wants to merge 7 commits into
trustno1-coder:mainfrom
Adriwin06:shader-fixes
Open

Adriwin06 wants to merge 7 commits into
trustno1-coder:mainfrom
Adriwin06:shader-fixes

Conversation

@Adriwin06

Copy link
Copy Markdown

What it changes

5 small changes of the same kind, one commit each, so each can be reviewed, reverted or left out on its own:

Shaders: an image query's unused extents read zero on non-cube views

The size query lowered every extent a view lacks (!present[ch]) to
one, the cube depth fallback. The console returns zero for a non-cube
view's unused extents, and a shader that multiplies or tests them saw
one instead. Only cube views (kind 5) still read one there.

Ported from DoubleGhosty/cool_fox@0e525f1 (Dathinel), GPL-3.0-or-later.

Shaders: a VALU scalar destination past the machine's registers is refused at decode

A VOP3 compare's mask, and v_readlane_b32's and v_readfirstlane_b32's
value, are an 8-bit scalar destination. No register has a code from 128
on (the SGPRs, VCC, the trap temporaries, M0, null and EXEC end at 127),
so a compiler never writes one, and the IR would take such a code for a
parked scalar's. Decoding now refuses the instruction with an ISA error
instead of translating it into a wrong program.

Test: gfx10::a_scalar_destination_past_the_registers_is_refused.

Ported from DoubleGhosty/cool_fox@200319b, GPL-3.0-or-later.

Shaders: CalculateLOD on a 1D or 2D array takes spatial coordinates only

The LOD query was given every coordinate of the sample, the array slice
included. CalculateLOD takes the spatial coordinates only; array
samples still need the slice, but the query now leaves that operand
undefined.

Tests: cube_lod_tests (array CalculateLOD).

Ported from Kemerd/Broadside-RT@7526692, GPL-3.0-or-later.

Shaders: image and typed-buffer stores of fewer channels write the rest as zero

An image store whose dmask leaves channels out, and a typed buffer
store of fewer than four channels, were refused ("an image store of
some channels", "a typed buffer store of some channels or at an
offset"), so their programs did not translate. The console writes the
channels the mask leaves out, and those past a typed store's last, as
zero rather than keeping the texel's old values, so no read of the texel
is needed: they are now filled with zero (a d16 image store packs the
channels it does write two to a VGPR, as before). Still refused: an
image store of no channels, a partial store into a view the program
also counts in, and a typed store at an offset. Also adds a test for
s_pack_ll_b32_b16.

Tests: size_tests (zero-padded partial stores), valu_tests (s_pack_ll_b32_b16).

Ported from Kemerd/Broadside-RT@6d9c88a, GPL-3.0-or-later.

Shaders: an LDS atomic add of a negated value is lowered so NVIDIA cannot fold it into a subtract

A group-shared atomic add of sub 0, x was emitted as written, and
NVIDIA's D3D12 compiler folds it back into a group-shared atomic
subtract, which it refuses (CreateComputePipelineState returns
E_OUTOFMEMORY, so the pipeline is never made). Such an add is now
written as an add of x * WaveReadLaneFirst(-1), which the compiler
cannot see through. Explicit ds_sub_u32 keeps its compare-exchange loop
(#1623).

Tests: emit::lds_sub_tests (hardware GPU; skipped where none is present).

Ported from DoubleGhosty/cool_fox@5b8e20c, GPL-3.0-or-later.

How it was tested

  • GPU and profile: RTX 4070 SUPER, Ryzen 7 5800X. Not measured in the title on these commits by themselves: they come from a fork of mine that carries them with the rest of this set, and the title ran there. What is below is the unit tests on this branch.
  • Before: n/a (no in-title measurement on this branch)
  • After: n/a
  • For shader changes, the wave sizes tested: the unit tests named in each commit (32- and 64-lane programs where they translate both)
  • cargo test passed for the crates it touches:
    • image-query-extents: yes, cargo test -p victory-shader --lib -- image size_tests: 10 passed
    • gfx10-scalar-dest: yes, cargo test -p victory-shader --lib -- gfx10::: 17 passed
    • calculate-lod-array: yes, cargo test -p victory-shader --lib -- cube_lod: 3 passed
    • partial-stores: yes, cargo test -p victory-shader --lib -- size_tests s_pack_ll: 10 passed
    • lds-negated-add: yes, cargo test -p victory-shader --lib -- lds_sub: 2 passed
  • cargo clippy --workspace --all-targets --locked: no finding that main does not already have (main has 34 of its own, which is why the Clippy step of CI is red on main itself).
  • cargo xtask policy: no new finding (main fails it on crates/victory-loader/src/heap_sites/frame_users.rs).
  • With all eleven of my pull requests merged together: cargo clippy also with --all-features adds no finding, and cargo test --workspace --locked fails only tests main also fails on this machine: the five shader tests that fail on main here too (WARP's SM 6.2 and the validator) (barycentric_tests::first_half_values_render_on_hardware_and_warp, hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity, intersect_tests::flat_global_stores_and_atomics_fence_uavs_at_group_barriers_across_waves, rect::tests::rectangles_are_drawn_whole, rect::tests::the_rectangle_stage_is_a_geometry_shader) and xtask's repository_passes_policy (frame_users.rs). 2208 passed, including five that fail on main (three BCPack oracle tests, the menu save race, the shader key test).

Checked for overlap

🤖 Generated with Claude Code

Adriwin06 and others added 5 commits November 29, 2026 20:29
The size query lowered every extent a view lacks (`!present[ch]`) to
one, the cube depth fallback. The console returns zero for a non-cube
view's unused extents, and a shader that multiplies or tests them saw
one instead. Only cube views (kind 5) still read one there.

Ported from DoubleGhosty/cool_fox@0e525f1 (Dathinel), GPL-3.0-or-later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fused at decode

A VOP3 compare's mask, and v_readlane_b32's and v_readfirstlane_b32's
value, are an 8-bit scalar destination. No register has a code from 128
on (the SGPRs, VCC, the trap temporaries, M0, null and EXEC end at 127),
so a compiler never writes one, and the IR would take such a code for a
parked scalar's. Decoding now refuses the instruction with an ISA error
instead of translating it into a wrong program.

Test: gfx10::a_scalar_destination_past_the_registers_is_refused.

Ported from DoubleGhosty/cool_fox@200319b, GPL-3.0-or-later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The LOD query was given every coordinate of the sample, the array slice
included. CalculateLOD takes the spatial coordinates only; array
samples still need the slice, but the query now leaves that operand
undefined.

Tests: cube_lod_tests (array CalculateLOD).

Ported from Kemerd/Broadside-RT@7526692, GPL-3.0-or-later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…st as zero

An image store whose dmask leaves channels out, and a typed buffer
store of fewer than four channels, were refused ("an image store of
some channels", "a typed buffer store of some channels or at an
offset"), so their programs did not translate. The console writes the
channels the mask leaves out, and those past a typed store's last, as
zero rather than keeping the texel's old values, so no read of the texel
is needed: they are now filled with zero (a d16 image store packs the
channels it does write two to a VGPR, as before). Still refused: an
image store of no channels, a partial store into a view the program
also counts in, and a typed store at an offset. Also adds a test for
s_pack_ll_b32_b16.

Tests: size_tests (zero-padded partial stores), valu_tests (s_pack_ll_b32_b16).

Ported from Kemerd/Broadside-RT@6d9c88a, GPL-3.0-or-later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nnot fold it into a subtract

A group-shared atomic add of `sub 0, x` was emitted as written, and
NVIDIA's D3D12 compiler folds it back into a group-shared atomic
subtract, which it refuses (CreateComputePipelineState returns
E_OUTOFMEMORY, so the pipeline is never made). Such an add is now
written as an add of `x * WaveReadLaneFirst(-1)`, which the compiler
cannot see through. Explicit ds_sub_u32 keeps its compare-exchange loop
(trustno1-coder#1623).

Tests: emit::lds_sub_tests (hardware GPU; skipped where none is present).

Ported from DoubleGhosty/cool_fox@5b8e20c, GPL-3.0-or-later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 29, 2026 19:52
@github-actions github-actions Bot added the pr-fix Pull request: fixes a bug label Nov 29, 2026
@github-actions github-actions Bot changed the title [pr-fix] Shaders: five translation fixes from cool_fox and VIctory-NVIDIA-RT (image queries, scalar destinations, CalculateLOD on arrays, partial stores, LDS negated adds) Shaders: five translation fixes from cool_fox and VIctory-NVIDIA-RT (image queries, scalar destinations, CalculateLOD on arrays, partial stores, LDS negated adds) Nov 29, 2026

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.

🟡 Changes recommended

Zero-mask image stores bypass rejection and can clear unintended channels, while partial typed stores ignore scalar and descriptor-derived byte offsets and may write to the wrong element.

2 open issues
What changed in this PR

Ports five fixes into the RDNA2-to-DXIL shader translator, improving instruction validation, texture operations, and NVIDIA pipeline compatibility.

Changes:

  • Rejects out-of-range scalar destinations and corrects unused image-query extents.
  • Uses spatial coordinates for array LOD queries and zero-fills omitted store channels.
  • Adds a workaround for negated LDS atomic adds, plus targeted regression tests.
File Description
crates/​victory-shader/​src/​gfx10/​mod.rs Validates scalar destinations during decoding and adds tests.
crates/​victory-shader/​src/​emit/​valu_tests.rs Tests scalar packing and partial typed-buffer stores.
crates/​victory-shader/​src/​emit/​size_tests.rs Tests sparse and packed image-store zero filling.
crates/​victory-shader/​src/​emit/​mod.rs Registers Windows-only LDS subtraction tests.
crates/​victory-shader/​src/​emit/​lower.rs Implements image, LOD, partial-store, and LDS lowering changes.
crates/​victory-shader/​src/​emit/​lds_sub_tests.rs Checks hardware pipeline creation and atomic return values.
crates/​victory-shader/​src/​emit/​cube_lod_tests.rs Adds DXIL validation tests for array LOD queries.
crates/​victory-shader/​src/​emit/​bitcode.rs Recognizes integer negation for the LDS workaround.

Review effort: Balanced

Comment thread crates/victory-shader/src/emit/lower.rs Outdated
let counter = *dmask == 1 && self.is_counter(src);
if *dmask != 0xF && !counter {
return Err("an image store of some channels");
if !counter && *dmask == 0 {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch, fixed in 58173c4: the store branch now checks the instruction's own mask (no_channels, taken before the normalisation), so a dmask-0 image_store is refused. Loads and samples still treat 0 as 1. Regression test: an_image_store_of_no_channels_is_refused.

Comment thread crates/victory-shader/src/emit/lower.rs Outdated
if count != 4 || *offen || *offset != 0 {
return Err("a typed buffer store of some channels or at an offset");
// shortcut: typed stores are taken to write a float format.
if *offen || *offset != 0 {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 99cfa48: a typed store of fewer than four channels is now refused unless the whole byte offset off is the constant 0. That covers a scalar soffset and the descriptor's base as well as offen/offset. An inline-0 soffset is still no offset, and four-channel stores keep their old rule. Regression test: typed_stores_of_some_channels_at_a_scalar_offset_are_refused (inline 0 accepted, s20 refused).

Adriwin06 and others added 2 commits November 30, 2026 02:09
The mask of every image access with no channel enabled was made 1 before
the store branch, for loads and samples (which return the first channel),
so the store's "no channels" refusal could never be reached: a dmask-0
image_store was translated as a store of X that cleared Y, Z and W, or
took the counter-store path, though it writes nothing. The store branch
now checks the instruction's own mask. Test:
an_image_store_of_no_channels_is_refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…set is refused

A typed store goes to bufferStore at its element index alone. A store of
fewer than four channels, taken since stores of four only, was refused
only for offen and the instruction's offset, while a scalar soffset or
the descriptor's base also add to the byte offset (off): such a store
wrote the wrong element. It is now refused unless off is the constant 0
(an inline 0 soffset is no offset); stores of four keep their old
rule. Test: typed_stores_of_some_channels_at_a_scalar_offset_are_refused.

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

Labels

pr-fix Pull request: fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants