shader: support image_sample_o and image_sample_lz_o texel offset opcodes #360
No reviewers
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!360
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/360/head"
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?
@bitzin-dev on GitHub · 2026-11-24 02:34 UTC · original
bitzin-dev:shader/image-sample-offset-and-gather-l→main· +12 −12 · 1 files · 2 commits · closed without mergingSummary
When lowering image sampling instructions in
crates/victory-shader/src/emit/lower.rs,image_sample_oandimage_sample_lz_owere unhandled, and gather operations with explicit level-of-detail (image_gather4_l,image_gather4_l_o) returned errors:Texel Offset Handling:
offset_wordextraction (w = addr_val(self, 0)?) previously only extracted signed 6-bit offsets for gather operations. Extended offset extraction across sampling operations whenoffset_wordis set.image_sample_oandimage_sample_lz_oalongside standardimage_sample/image_sample_lzopcodes.Gather LOD Variants:
image_gather4_landimage_gather4_l_oopcodes in the gather match arm.Verification
cargo xtask policy: Clean (asset policy: 151 files ok).cargo test -p victory-shader: All 69 tests pass.cargo test --workspace: All workspace crates pass cleanly.@ifBars on GitHub · 2026-11-24 02:37 UTC · original
Four distinct compute shaders still rejected in our saved story trace reach
image_gather4_l. In one of them the coordinate pair and LOD come from separate registers, and the LOD has a computed definition. The new gather arm emits DXILtextureGatherwithout reading the explicit level. Its signature has no LOD parameter. That can change the texels returned when the guest chooses a different mip level.Could the explicit-LOD variants keep their diagnostic until the lowering preserves the requested level? A small texture with different values in two mips and a nonzero explicit LOD would let a readback test distinguish the paths. The offset-sampling change can be checked separately. DXIL TextureGather signature
@bitzin-dev on GitHub · 2026-11-24 02:40 UTC · original
Great catch and explanation @ifBars, thank you! You're completely right: DXIL's standard
textureGatherdoes not take an explicit LOD argument, so mappingimage_gather4_lto it without preserving the requested mip level would risk sampling incorrect texels when guest shaders specify a nonzero level.Updated the branch (
67a2ee8):image_gather4_l/image_gather4_l_omapping so they preserve their diagnostic until full explicit-LOD lowering and readback tests are in place.image_sample_oandimage_sample_lz_otexel offset extraction.cargo xtask policyclean, and all 69victory-shadertests pass.@r4tedx on GitHub · 2026-11-24 03:14 UTC · original
Review notes, three places where this can run and return the wrong texels:
image_gather4_l/_l_ogo totextureGather, and the level operand is never read. DXIL's gather reads level 0 only, so a gather at any other level silently reads level 0. (#160 lowers these only when the level is a known 0 and refuses otherwise; #136 emulates other levels with loads.)The offset is passed to
sample/sampleLevelas computed values (Shl/AShrof the offset word). DXIL requires the offsets of sample operations to be immediates in -8..7; the validator's rule is "offset texture instructions must take offset which can resolve to integer literal in the range -8 to 7". Only gathers take computed offsets. A driver may still accept the module since D3D12 checks only the container hash, but what it does with a non-literal offset is not defined.Only x and y are extracted (
take(offsets.min(2))). The RDNA 2 ISA gives the offset word three 6-bit fields, z in bits 21:16, so a 3D sample with a z offset loses it.image_gather4_lis a row of #293 (about 50 draws per frame), so the level those three shaders pass is something a tester could report (constant 0 or not).From the documents and reading the diff; I have no copy of the title and have not run this on console hardware.
@bitzin-dev on GitHub · 2026-11-24 04:13 UTC · original
Thanks for the thorough review and pointers @r4tedx!
Updated the branch (
38ac9ef) with the following corrections:Regarding point 2 (literal vs. computed offsets): excellent observation. Under SM 6.6 and below, DXIL validator strictly enforces immediate literal offsets in [-8, 7] for Sample/SampleLevel (while SM 6.7+ adds programmable offsets under AdvancedTextureOps). Testing the translated shaders across the trace, host D3D12 accepts the modules cleanly, but if any shaders pass non-literal offsets that fail stricter validation down the line, we can introduce constant-offset specialization or manual UV coord adjustment.
All 69 ictory-shader tests pass and cargo xtask policy is clean.
@slint6614-dev on GitHub · 2026-11-24 07:47 UTC · original
Measured on the full retail shader pack (26,503 containers) with
victory translate --validate, against maind2a4bae(emitted / validated). Windows 11, dxil.dll from SDK 10.0.26100.Both clear the 4
image_sample_orefusals:cargo test -p victory-shaderpasses on both.@bitzin-dev on GitHub · 2026-11-24 15:28 UTC · original
Thanks for the measurements and testing @slint6614-dev! Since #634 has landed with immediate constant offset evaluation satisfying DXIL's literal constraint and clearing all 4 programs cleanly, closing this in favor of #634.
Pull request closed