Skip to content

dxil: image_sample_o under implicit LOD offsets each mip by its texels - #1940

Draft
mastrr9 wants to merge 1 commit into
xcl-dev:mainfrom
mastrr9:fix/dxil-image-sample-o-per-mip-lod
Draft

mastrr9 wants to merge 1 commit into
xcl-dev:mainfrom
mastrr9:fix/dxil-image-sample-o-per-mip-lod

Conversation

@mastrr9

@mastrr9 mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

For image_sample_o in a pixel shader with an implicit LOD and a linear mip filter, the HLSL path samples both blended mips, each offset by its own texels. The direct translator offset the coordinates once, by the rounded LOD's mip size, so the other mip could read a texel off. This ports the HLSL form.

TRANSLATOR_VERSION goes from 7 to 8. #1793 and other changes to the direct translator also set 8; identical edits merge silently, so whichever lands later should take the next free number.

Draft: the head commit has not been built or tested yet.

What is in it

  • gpu/dxil/lower_image.rs: the two-mip form, and a texel-offset helper shared with the existing path
  • gpu/dxil/kernel.rs: TRANSLATOR_VERSION 8
  • gpu/recomp/tests.rs: gpu_ps_image_sample_offset_implicit_lod_between_mips now also draws through the direct translator

Tested
These runs are from before the final rebase, on a combined branch (376f968, based on main 689f2db; it holds this change, both halves of the differential mode and five other direct-translator parity fixes; this change's code is the same there), not on this PR's head commit.

  • Windows 11 x64, NVIDIA GeForce RTX 5080 16 GB, cargo test debug build. Driver, CPU and Rust versions were not recorded.
  • cargo test -p xcl --lib gpu_ps_image_sample_offset_implicit_lod_between_mips -- --nocapture --test-threads=1: passed.

Regression run
Not run: there are no xcl-smoke blocks for this change.

Not tested

AI use

  • Code and tests: written by Claude Opus 5.5 in an agent session (Duet) with no Windows or GPU.
  • RTX 5080 test runs above: a Claude Sonnet 5.5 agent.
  • Overlap check, rebase and this description: Claude Code, Claude Sonnet 5.5.

The HLSL path's image_sample_o in a pixel shader with an implicit LOD and
a linear mip filter samples the two blended mips with SampleLevel, each
moved by the offset in its own texels, and blends them by the LOD's
fraction (20271d4). The direct translator still moved the coordinates
once, by the offset over the size of the rounded LOD's mip, so the
second mip read a texel off when the offset was half its texel or less.

Port that form: LOD = the clamped implicit LOD (raised by the _cl clamp,
capped at the view's last mip), mips floor(LOD) and the next one (capped
too), each with its own texel offset, lerp by the fraction. It is taken
under the same conditions read from the S#: MIP_FILTER linear, not
anisotropic, and LOD >= 1 or min = mag filter; otherwise the single
Sample as before. The texel-offset computation moves into a helper
shared with the existing path.

TRANSLATOR_VERSION 7 -> 8: the emitted containers change for these
programs. Open PR xcl-dev#1793 also bumps TRANSLATOR_VERSION. Identical
edits merge silently in git, so check the bump by hand at merge time:
the later change takes the next free number, or the pipeline cache
could serve containers of another translator under the same version.

The existing test gpu_ps_image_sample_offset_implicit_lod_between_mips
now also draws its pixel shader through the direct translator and
expects the same result.
@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, 54269d7 merged onto main 20cf130. Tests matching sample_o: 3 passed, with and without XCL_DIRECT_DXIL=1. Merged together with #1935, its XCL_DXIL_DIFF=1 run of gpu_ps_image_sample_offset_implicit_lod_between_mips now finds no difference between the backends; on main alone it finds 48 of 256 pixels (details on #1935).

AI-assisted (Claude Code). Synthetic tests only.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants