Repository navigation
shader: support image_sample_o and image_sample_lz_o texel offset opcodes - #360
bitzin-dev wants to merge 2 commits into
Conversation
|
Four distinct compute shaders still rejected in our saved story trace reach 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 |
…odes image_sample_o and image_sample_lz_o were unhandled in the instruction lowerer, causing translation failures for shaders using texel offset words. Extract the signed 6-bit texel offsets across sampling ops when an offset word is present. Reverts tentative image_gather4_l / image_gather4_l_o mapping as noted by @ifBars, keeping the diagnostic until explicit mip-level lowering is preserved. All 69 victory-shader tests pass and cargo xtask policy is clean.
dbd6b6a to
67a2ee8
Compare
|
Great catch and explanation @ifBars, thank you! You're completely right: DXIL's standard Updated the branch (
|
|
Review notes, three places where this can run and return the wrong texels:
From the documents and reading the diff; I have no copy of the title and have not run this on console hardware. |
|
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. |
|
Measured on the full retail shader pack (26,503 containers) with Both clear the 4
|
mercuryVM
left a comment
There was a problem hiding this comment.
Tested 38ac9ef on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (264 passed, 0 failed). victory translate <title exe> --validate --pipelines gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. None of the 12 embedded programs uses _o samples.
The offset decoding is right. Bits 0–5, 8–13 and 16–21 of the offset VGPR are sign-extended with (w << at) >> 26 for at = 26, 18 and 10, and the sample paths already pass os to sample/sampleLevel/sampleBias/sampleGrad. Two things before I can approve:
- DXIL requires immediate offsets on
Sample*. The validator rejects texture-access offsets that aren't constant in -8..7 ("Offsets to texture access operations must be immediate values").Gatherallows programmable offsets, which is why the old code only did this for gathers. Hereos[k]is computed from a VGPR (addr_val(self, 0)), so unless the bitcode builder folds it to a constant (only when the VGPR holds a literal), a realimage_sample_owould emit DXIL that fails validation. Could you add a test that lowers animage_sample_oand runs it throughemit::validator(asemit/mod.rsdoes), both with a literal offset and with one computed at run time? If run-time offsets can't validate, they need a refusal, or a fallback that applies the offset to the coordinates (coord + offset / size). - The description says
image_gather4_landimage_gather4_l_oare now recognized, but the diff doesn't touch the gather match arm. Line 5436 still lists onlyimage_gather4,_lzand_lz_o. Either that part is missing from the commit, or the description should drop it.
AI-assisted (Claude Code).
|
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. |
Summary
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.