Recompiler: image_sample_o under an implicit LOD moves each blended mip by its own texels #229

Manually merged
github merged 1 commit from gh-pr/229/head into gh-pr/229/base 2026-11-26 04:16:47 +00:00
Owner

@⁠artor410 on GitHub · 2026-11-23 21:24 UTC · original
artor410:recomp/sample-offset-per-mip → main · +203 −38 · 3 files · 1 commits · merged 2026-11-23 21:31 UTC

HANDOFF "Next steps" 5: image_sample_o with an offset from a VGPR. A pixel shader's implicit LOD with a linear mip filter blends two mips; the console moves each one by the offset in its own texels. XCL moved both by offset / size of the rounded LOD's mip, so the second mip read one texel off whenever the offset was half its texel or less.

Summary

 image_sample_o, PS, implicit LOD
-  o = offset / size(round(L))
-  Sample(coord + o)
+  L  = min(max(LOD, clamp), last mip);  l0 = floor(L)
+  m0 = SampleLevel(coord + offset / size(l0),     l0)
+  m1 = SampleLevel(coord + offset / size(l0 + 1), l0 + 1)
+  per_mip = MIP_FILTER linear
+            && not anisotropic (as desc::sampler_d3d12 decides)
+            && (l0 >= 1 || min filter == mag filter)   // level-0 SampleLevel uses the mag filter
+  per_mip ? lerp(m0, m1, frac(L)) : Sample(coord + o)  // the old form, unchanged
  • emit.rs: texel_offset / sample_coord / moved_coords, shared with the existing offset path (no second copy of the GetDimensions / sign-extension code).
  • runner.rs: ViewTexture uploads every mip level (data = the levels one after the other); draw_views = draw with textures and samplers. draw now goes through draw_on_multi.
  • tests.rs: draw_console_views (SGPRs + textures) and the new test.

Evidence

gpu_ps_image_sample_offset_implicit_lod_between_mips: a PS draw, 8² / 4² / 2² / 1² texture (level k texel x = 100·k + x), point min/mag, linear mip, clamp, uv = pixel centre · 2^0.25 / 8 (LOD 0.25), offset (+1, 0). Expected per pixel, from the console rule: 0.75 · texel₈(⌊8u⌋+1) + 0.25 · (100 + texel₄(⌊4u⌋+1)).

  • Before: pixel (0,0) = 25.75, expected 26 (mip 1 read texel 0 instead of 1)
    After: passes; gpu_image_sample_offset (lz) still passes.

Rebased on d4f17ca (draw_gs from #199 and draw_views share one draw_gs_views). cargo test --workspace --no-fail-fast: lib 606 passed, every other target green except e2e::test_title_draws_with_a_root_signature_under_the_debug_layer, which fails the same way on main here: my checkout's path is over 260 characters and the test title's overlay file writes hit os error 3. Tested on an NVIDIA RTX 3070 Ti (driver 610.88, 32-lane waves); not run on AMD.

Merge Danger

Door: two-way

Blast Radius: PS image_sample*_o with an implicit LOD

Only that form changes; every other sample keeps its HLSL. Its HLSL now has three samples instead of one (the fallback Sample is always emitted; DXC folds the select only for static samplers) – I could not count how many pack programs use it without the pack. Not covered / not verified:

  • CalculateLevelOfDetail and the sampler's MipLODBias: not checked that it adds the bias as the hardware does (the test uses bias 0).
  • _l_o with a fractional LOD and _b_o outside a PS still use the one-mip form.

Overlap: none of the open PRs that touch emit.rs (#128, #134, #138, #152, #174, #187, #199, #202, #214) change the MIMG sample code.

AI-assisted (Claude Code), synthetic inputs only, no game data.

🤖 Generated with Claude Code

**@⁠artor410** on GitHub · 2026-11-23 21:24 UTC · [original](https://github.com/xcl-dev/xcl/pull/229) `artor410:recomp/sample-offset-per-mip` → `main` · +203 −38 · 3 files · 1 commits · merged 2026-11-23 21:31 UTC HANDOFF "Next steps" 5: `image_sample_o` with an offset from a VGPR. A pixel shader's implicit LOD with a linear mip filter blends two mips; the console moves each one by the offset in **its own** texels. XCL moved both by offset / size of the rounded LOD's mip, so the second mip read one texel off whenever the offset was half its texel or less. ## Summary ```diff image_sample_o, PS, implicit LOD - o = offset / size(round(L)) - Sample(coord + o) + L = min(max(LOD, clamp), last mip); l0 = floor(L) + m0 = SampleLevel(coord + offset / size(l0), l0) + m1 = SampleLevel(coord + offset / size(l0 + 1), l0 + 1) + per_mip = MIP_FILTER linear + && not anisotropic (as desc::sampler_d3d12 decides) + && (l0 >= 1 || min filter == mag filter) // level-0 SampleLevel uses the mag filter + per_mip ? lerp(m0, m1, frac(L)) : Sample(coord + o) // the old form, unchanged ``` - `emit.rs`: `texel_offset` / `sample_coord` / `moved_coords`, shared with the existing offset path (no second copy of the GetDimensions / sign-extension code). - `runner.rs`: `ViewTexture` uploads every mip level (`data` = the levels one after the other); `draw_views` = `draw` with textures and samplers. `draw` now goes through `draw_on_multi`. - `tests.rs`: `draw_console_views` (SGPRs + textures) and the new test. ## Evidence `gpu_ps_image_sample_offset_implicit_lod_between_mips`: a PS draw, 8² / 4² / 2² / 1² texture (level k texel x = 100·k + x), point min/mag, linear mip, clamp, uv = pixel centre · 2^0.25 / 8 (LOD 0.25), offset (+1, 0). Expected per pixel, from the console rule: `0.75 · texel₈(⌊8u⌋+1) + 0.25 · (100 + texel₄(⌊4u⌋+1))`. - **Before:** `pixel (0,0) = 25.75, expected 26` (mip 1 read texel 0 instead of 1) **After:** passes; `gpu_image_sample_offset` (lz) still passes. Rebased on `d4f17ca` (`draw_gs` from #199 and `draw_views` share one `draw_gs_views`). `cargo test --workspace --no-fail-fast`: lib 606 passed, every other target green except `e2e::test_title_draws_with_a_root_signature_under_the_debug_layer`, which fails the same way on `main` here: my checkout's path is over 260 characters and the test title's overlay file writes hit `os error 3`. Tested on an NVIDIA RTX 3070 Ti (driver 610.88, 32-lane waves); not run on AMD. ## Merge Danger **Door:** two-way **Blast Radius:** PS `image_sample*_o` with an implicit LOD Only that form changes; every other sample keeps its HLSL. Its HLSL now has three samples instead of one (the fallback `Sample` is always emitted; DXC folds the select only for static samplers) – I could not count how many pack programs use it without the pack. Not covered / not verified: - `CalculateLevelOfDetail` and the sampler's `MipLODBias`: not checked that it adds the bias as the hardware does (the test uses bias 0). - `_l_o` with a fractional LOD and `_b_o` outside a PS still use the one-mip form. Overlap: none of the open PRs that touch `emit.rs` (#128, #134, #138, #152, #174, #187, #199, #202, #214) change the MIMG sample code. AI-assisted (Claude Code), synthetic inputs only, no game data. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A pixel shader's image_sample_o with an implicit LOD and a linear mip filter blends two
mips; the console moves each one's texel coordinate by the offset in that mip's texels.
XCL moved both by the offset / 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. Now both mips are sampled with
SampleLevel (each offset by its own size) and blended by the LOD's fraction.

The per-mip form is taken when it is exact: MIP_FILTER linear, not anisotropic (as
desc::sampler_d3d12 decides), and LOD >= 1 or min = mag filter (a level-0 SampleLevel
filters with the mag filter). Otherwise the single Sample is kept as before. A clamp
past the last mip samples the last mip.

texel_offset / sample_coord / moved_coords are shared with the existing offset path.
Test harness: draw textures with several mips (runner::draw_views, ViewTexture data =
the levels one after the other).

Test: gpu_ps_image_sample_offset_implicit_lod_between_mips (LOD 0.25 between 8x8 and
4x4, offset +1).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:16:45 +00:00
github manually merged commit 8a98da6b96 into gh-pr/229/base 2026-11-26 04:16:47 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-23 21:31 UTC · original

Merged (main 60565c4), your rebased head; main had merged the earlier head with draw_views(vs, gs, ...), the runner now has your draw_gs_views form. Checked on an RX 9070 (RDNA4): cargo build --workspace && cargo test --workspace -- --test-threads=4 - 611 unit tests passed, 0 failed; the retail game still reaches its first menu at 30 fps.

**@⁠ivall** on GitHub · 2026-11-23 21:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/229#issuecomment-7114584774) Merged (main 60565c4), your rebased head; main had merged the earlier head with `draw_views(vs, gs, ...)`, the runner now has your `draw_gs_views` form. Checked on an RX 9070 (RDNA4): `cargo build --workspace && cargo test --workspace -- --test-threads=4` - 611 unit tests passed, 0 failed; the retail game still reaches its first menu at 30 fps.
This discussion has been locked. Commenting is limited to contributors.
No description provided.