tombox-xshader: translate image_gather4_l with an explicit LOD #196
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/196"
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?
Imported from omonkeyz/xbox-emulator. Originally posted by GDAgent on 2026-11-23T00:42:05Z.
Library / area:
tombox-xshader(hlsl.rsMIMG gather,tests/exec_mem/mimg.rs)Exports changed (exports.txt rows): none
Source of the behaviour: RDNA2 ISA:
image_gather4_l,image_gather4_l_o,image_gather4_c_l,image_gather4_c_l_ogather the 2x2 footprint of one channel from the mip chosen by an explicit LOD. HLSL has noGatherwith a mip level.These four opcodes on 2D and 2D-array images were refused (
gather4 with explicit LOD/bias unsupported). The existing implicit-LOD path gathers from a per-mip SRV view, whichd3d12_xsdoes not bind yet, so that route is not available.Changes: the explicit-LOD forms are lowered without per-mip views.
i = floor(u * w - 0.5),j = floor(v * h - 0.5)on that mip, plus the texel offset for the_oforms.SampleLevel(SampleCmpLevelfor_c, SM 6.7) at its texel centre on that mip, in gather order (i, j+1), (i+1, j+1), (i+1, j), (i, j), and dmask picks the channel.Sampling at a texel centre with an integer LOD returns that texel for point and linear filters, and the sampler still applies its address mode per texel, so wrap, mirror, clamp and border match a hardware gather.
Known differences, stated rather than hidden: the result differs from a hardware gather when the sampler has a non-zero
MipLODBiasor aMinLOD/MaxLODthat excludes the chosen mip, because the footprint is computed for the unbiased level. Cube, 1D and 3D images and unnormalised coordinates are still refused.Tests:
exec_mem::mimg::image_mimg_gather_explicit_lod, 23 cases on WARP: LOD rounding and clamping, all four channels, wrap addressing at both edges with point and linear filters, texel offsets, a 2D array, and depth compare. Swapping the tap order fails 38 checks.cargo test -p tombox-xshader --no-fail-faston currentmain: 292 passed, 0 failed (WARP).Not verified in a title: in The Matrix Awakens a compute shader with
image_gather4_lwas refused before (PSO creationE_FAIL); it now translates and compiles, and a later run logged no translation failures. The title's sampler settings for that shader (bias, LOD clamps) and the correctness of its output were not checked.cargo test -p tombox-xshaderpassesmissingwith a noteImported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-23T00:55:51Z.
Thanks, this looks right and the tests pass here: exec mimg 12/12 on WARP, and the new test passes with TOMBOX_EXEC_HW=1 too. Two things are needed before it can merge:
Push to this branch when it's ready and I'll apply it the same way (cherry-picked, with your authorship kept).
Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-23T00:56:33Z.
Applied in
2e981c5(merged in2eda8b0) with your authorship kept, thanks. The sampler bias and LOD-clamp gap you described is now an OPEN entry in docs/BLOCKERS.md (9a77dd6). A follow-up PR would be welcome. It should apply the S# LOD_BIAS / MIN_LOD / MAX_LOD to the footprint mip where the descriptor is visible, and log the shader hash once where it isn't. Please include a WARP exec test with a non-zero clamp.Pull request closed