Shaders: lower image_gather4_c_lz(_o) and offset sample variants #1535
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#1535
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@davi713albano-coder on GitHub · 2026-11-24 18:52 UTC · original
Summary
In
emit::lower::image:image_gather4_c_lz(0x04f) andimage_gather4_c_lz_o(0x05f) were unsupported, even thoughimage_gather4_lz(_o)and comparison samplers (image_sample_c(_lz)) were already lowered._o) variants of the already-lowered sample opcodes (image_sample_lz_o,image_sample_l_o,image_sample_b_o,image_sample_d_o,image_sample_c_o,image_sample_c_lz_o) were unsupported, because constant-offset decoding lived only inside theop == 60arm andbias/lodindexing assumedoffset_word == false(anda16address unpacking did not separate whole-dword leading address words from packed 16-bit gradients/coordinates/LOD).This branch lowers all of them cleanly to DXIL SM 6.6.
Changes (
shader/image-gather-cmp-and-sample-offsets, commit572bcbe)crates/victory-shader/src/emit/lower.rs:image_gather4_c_lzandimage_gather4_c_lz_otodx.op.textureGatherCmp.f32(opcode74), marking the sampler as a comparison sampler (0x8000), supporting programmable 2D offsets (_o) via sign-extended 6-bit X/Y extraction, passingdmask.trailing_zeros()and the comparison reference, and writing all 4 gathered channels (matches!(op, 73 | 74)).image_sample_lz_o,image_sample_l_o,image_sample_b_o,image_sample_d_o,image_sample_c_o(pixel shaders), andimage_sample_c_lz_oby lifting constant texel-offset decoding (-8..=7) ahead ofmatch op(rejecting cube samples/gathers with texel offsets).offset,bias,cmp) froma16-packed gradients (dx/dy) and coordinates/LOD to matchgfx10::fields::image_addr_dwords, fixingbiasandlodindexing when_ois present.crates/victory-shader/src/emit/valu_tests.rs:image_gather4_c_lz_and_offset_match_d3d12: synthetic compute tests forimage_gather4_c_lz(dmask:0x1anddmask:0x2) andimage_gather4_c_lz_o(runtime positive(+2,+1)and negative(-1,-1)offsets) withdxil.dllvalidation + container hash check and live D3D12 WARP readback.image_sample_offset_variants_match_d3d12: synthetic compute tests with live D3D12 WARP readback forimage_sample_lz_o,image_sample_l_o,image_sample_c_lz_o, andimage_sample_d_o, plus synthetic pixel shaderdxil.dllvalidation and live D3D12 graphics PSO creation forimage_sample_b_oandimage_sample_c_o.Branch & Verification
main(ffe310e): https://github.com/Marvisak/VIctory/compare/main...davi713albano-coder:VIctory:shader/image-gather-cmp-and-sample-offsetswindows-latest): https://github.com/davi713albano-coder/VIctory/actions/runs/45463144180cargo clippy --workspace --all-targets --locked -- -D warnings: passedcargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passedcargo test --workspace --locked(includingxtaskasset-policy check,dxil.dllvalidation, and D3D12 WARP tests): 344 passed, 0 failed (image_gather4_c_lz_and_offset_match_d3d12 ... ok,image_sample_offset_variants_match_d3d12 ... ok)(No game data used. AI-assisted.)
@Paull007 on GitHub · 2026-11-24 19:28 UTC · original
Shaders: lower image_gather4_c_lz(_o) and the _o sample variants
Refs #1535
image_gather4_c_lz / _c_lz_o → textureGatherCmp (comparison sampler, programmable 2D offsets, all four channels)
image_sample_lz_o, _l_o, _b_o, _d_o, _c_o, _c_lz_o are now lowered, with the constant offset decoded for every sample; offsets on cubes are refused
Bias and LOD are read after the offset word
a16: offset, bias and compare words stay whole dwords, and gradients and coordinates pack per group, matching image_addr_dwords. This fixes wrong coordinates for a16 image_sample_o / image_gather4_lz_o and wrong a16 1D/3D gradients for image_sample_d
Testing: cargo test -p victory-shader passes (6 new tests in emit/image_tests.rs), and I checked the emitted DXIL by hand. Not yet validated with dxil.dll or on a GPU or WARP. AI-assisted, no game data used.
AI assisted
0001-Shaders-comparison-gathers-and-the-offset-variants-o.patch
@DrDarkDK on GitHub · 2026-11-24 19:57 UTC · original
I checked
image_sample_d_oon572bcbewith a 4×4 point-sampled texture. The shader uses UV(0.625, 0.625), zero gradients, and texel offset(+1,+1). Both versions passed DXIL validation.a16off: sampled texel(3,3), returning the expected15.0.a16on, opcode still non-G16: sampled texel(1,1), returning5.0. The coordinates are exactly representable in either format, so the expected value is still15.0.The RTX 4070 Ti and WARP agreed. This is the #1116 packing issue showing up in the new offset path:
a16packs the coordinates, while this opcode still takes four full-width gradient registers.AI-assisted with Codex.
@Paull007 on GitHub · 2026-11-24 20:02 UTC · original
Shaders: lower image_gather4_c_lz(_o) and _o sample variants
Refs #1535, #1116
Comparison gathers → textureGatherCmp; _lz_o, _l_o, _b_o, _d_o, _c_o, _c_lz_o samples now lowered with constant offsets
a16 and _g16 packed independently, so gradients stay whole f32 under a16 (fixes a16 image_sample_d_o sampling the wrong texel)
Tests pass, including a regression test for the a16 case. AI-assisted, no game data.
0001-Shaders-comparison-gathers-and-the-offset-variants-o.patch
@Marvisak on GitHub · 2026-11-25 10:26 UTC · original
Automated triage for the maintainers.
In scope. On
main(940d32f), image lowering incrates/victory-shader/src/emit/lower.rstakesimage_sample_o,image_gather4_lz_oandimage_gather4_l_o, but notimage_gather4_c_lz(_o)or the other_osample variants; those are refused by name.Open PRs already carry this: #1687 has the same title, and #1489 lowers
image_gather4_c_lz(_o)alone. PRs are open to everyone now; @davi713albano-coder and @Paull007, please bring your branch and patch onto one of those, or open one PR, rather than adding a third.@DrDarkDK's check above (an
a16image_sample_d_osampling the wrong texel) is the gradient packing problem in #1116; itsfields.rshalf is #1209, and the lowering half should land with it.Generated by Claude Code