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

Merged
artor410 merged 1 commit from upstream-pr/229 into main 2026-11-23 21:31:53 +00:00
artor410 commented 2026-11-23 21:24:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by artor410 on 2026-11-23T21:24:50Z.


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

<!-- greyfinch-sync:ivall/xcl:issue:6569137756 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/229). Originally posted by [artor410](https://github.com/artor410) on 2026-11-23T21:24:50Z. --- 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)
upstream-sync closed this pull request 2026-11-24 06:57:45 +00:00
ivall commented 2026-11-24 07:04:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T21:31:57Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7114584774 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/229#issuecomment-7114584774). Originally posted by [ivall](https://github.com/ivall) on 2026-11-23T21:31:57Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!226
No description provided.