Skip to content

Recompiler: image_sample_b/d/cd/c_o offsets move by the mip they read - #247

Open
Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:fix/sample-o-lod-variants
Open

Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:fix/sample-o-lod-variants

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Follows #229. #229 moves the coordinates by offset / size of the mip the console reads, but it picks that mip only for the plain form (implicit LOD in a PS, or a given LOD). The bias, gradient and comparison forms still take mip 0's size. With a point mip filter, the texel read is then off by up to one texel of the mip actually sampled. This PR picks the mip for those forms too.

What main does today:

  • image_sample_b_o: in a PS, the implicit LOD without the bias; outside a PS, mip 0, though the sample is SampleLevel(bias).
  • image_sample_d_o / cd_o: mip 0 whatever the gradients say.
  • image_sample_c_o in a PS: mip 0, because the plain-form branch excludes comparison samplers. CalculateLevelOfDetail takes no SamplerComparisonState; DXC rejects it.

What is in it

One commit, 227a60a, on main 9e3831e: 287ca93 (on dd2ae9a) with @JGonzalezRodriguez's five review points fixed (the review points are marked below), then rebased onto 9e3831e without conflicts (as c14bd12 on dd2ae9a it is the same patch; git range-diff: =). The rebase is there because a whole-suite run on dd2ae9a stops in the #344 deadlock, whose fix (#443) came later. 287ca93 was a60db9f (on 9ab7d76) rebased without conflicts and without a changed line.

  • crates/xcl/src/gpu/recomp/emit.rs: the offset's level for these forms is:

    • the given LOD (unchanged);
    • else the LOD of the given gradients (log2 of the longer gradient in mip-0 texels), or in a PS the pixel's own LOD (CalculateLevelOfDetailUnclamped, or for comparison samplers the same log2 of ddx / ddy of the coordinates);
    • plus the sampler's LOD_BIAS (S# word 2 [13:0]) where that LOD comes from gradients, as SampleGrad and SampleCmp add it (review point 3; CalculateLevelOfDetailUnclamped already has it);
    • plus the instruction's bias;
    • then clamped as desc makes the view and the sampler: from below by the larger of the S# MIN_LOD and the T#'s MIN_LOD (word 1 [19:8], the SRV's ResourceMinLODClamp; point 2), from above by MAX_LOD, which is MIN_LOD without a mip filter (S# word 2 [27:26] = 0; point 1); rounded, and clamped to the view's last mip.
    • A comparison sample's offset moves by the mip that the emitted sample reads (point 4): mip 0 outside a PS (SampleCmpLevelZero), and in a PS the pixel's own LOD, because SampleCmp takes neither gradients nor a bias in SM 6.6. The level-0 size comes from a new mip_size, which texel_offset also calls (point 5).

    The LOD is unclamped before the bias, so a bias on a magnified pixel starts below 0. @ryotdev found that the first head (fd45f20) got this wrong. The plain form, lz, gather and given-LOD forms take the same path as before.

  • crates/xcl/src/gpu/recomp/tests.rs: nine new GPU tests on a 2-mip texture (8², 4²) with point min, mag and mip filters, so each pixel reads exactly one mip. Four of them are for the review: gpu_ps_image_sample_offset_without_a_mip_filter, …_resource_min_lod, …_sampler_bias, and gpu_image_sample_c_b_d_offset_moves_by_the_mip_read (PS and VS). The last one samples a checkerboard (one in each mip's own texels) at offsets 0 and +1. Moving by one texel of the mip that was read flips every pixel, so the test doesn't depend on which mip that is.

  • Overlap with Recompiler: pixel comparison samples apply their LOD bias #349 and Recompiler: comparison samples use their supplied pixel gradients #350: they make the PS SampleCmp take the bias and the gradients. In a tree with either of them and this PR, the matching line here (lod_bias for Recompiler: pixel comparison samples apply their LOD bias #349, lod_grads for Recompiler: comparison samples use their supplied pixel gradients #350) has to take them too. The two lines are separate, so neither follow-up conflicts with the other.

Tested

  • RTX 5070 Ti, NVIDIA 610.74, Ryzen 9 9950X, Windows 11 Pro 25H2 (build 26200.9711), Rust 1.99.0, debug build, SDK DXC 1.7.2308.16.
  • cargo test --workspace -- --test-threads=4 on 227a60a: 785 passed, 0 failed, 41 ignored (the xcl library: 736 passed, 21 ignored). SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64), and heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows; main's own test).
  • The 11 offset tests (image_sample_offset, and the new comparison test) on c14bd12 (the same patch on dd2ae9a): 11 passed. With emit.rs from 287ca93 (the same tests), the four review tests fail and the other seven pass. Each of their 12 cases run on its own (a scratch test, not in the PR): 11 fail on 287ca93, all 12 pass on c14bd12. The 12th, b_o with the sampler's LOD_BIAS, is a control and passes on both.
  • cargo test --workspace -- --test-threads=4 on 287ca93: 695 passed, 0 failed, 41 ignored (the xcl library: 655 passed, 21 ignored). SKIPPED GPU tests: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware, both "no wave64". The six gpu_ps_image_sample_offset tests (this PR's five and Recompiler: image_sample_o under an implicit LOD moves each blended mip by its own texels #229's): 6 passed.
  • The earlier head a60db9f, on main 9ab7d76: 656 passed, 0 failed, 40 ignored, with the same two SKIPPED tests.
  • The new tests, built from main with and without the emit.rs change (the same test code in both):
test main this PR
gpu_ps_image_sample_offset_point_mip (control, plain sample_o) pass pass
gpu_ps_image_sample_offset_bias_lod (b_o, LOD 0 + bias 1) FAIL: pixel (0,0) = 100, expected 101 pass
gpu_ps_image_sample_offset_bias_lod_magnified (b_o, LOD -1 + bias 1, @ryotdev's case) pass pass (fd45f20: FAIL, (0,0) = 2, expected 1)
gpu_ps_image_sample_offset_gradient_lod (d_o and cd_o, gradient LOD 1) FAIL: pixel (0,0) = 100, expected 101 (cd_o fails the same way, 48 of 256 pixels) pass
gpu_ps_image_sample_offset_compare_lod (c_o, implicit LOD 1, LESS_EQUAL) FAIL: pixel (0,0) = 0, expected 1 pass
gpu_ps_image_sample_offset_implicit_lod_between_mips (#229's) pass pass

Regression run

scripts/smoke.ps1, the same retail title for 60 s each, one after the other on the machine under Tested (RTX 5070 Ti, NVIDIA 610.74), release builds, no uncommitted changes.

main 9e3831e:

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1274 (PresentX 1274)
presents per 2 s (last 3): 8 31 32
device removals: 0
crashes: 0
peak commit: 27459 MB

this PR's head 227a60a:

xcl-smoke v1
commit: 227a60a977b9ab43b1bb77875ec547a5403d3972
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1313 (PresentX 1313)
presents per 2 s (last 3): 6 36 56
device removals: 0
crashes: 0
peak commit: 27471 MB

PR vs main: 1313 / 1274 frames (103 %), peak commit 27471 / 27459 MB (100 %); no device removal and no crash on either run.

Not tested

  • On image_sample_l_o the offset uses the given LOD before the sampler's bias and MIN/MAX_LOD, as on main. Sampler bias on image_sample_b_o follows it on NVIDIA 610.74 (measured); AMD not measured.
  • No title is known to use any of these forms with a VGPR offset. They come from the ISA, not from a shader seen in use.
  • AMD RDNA2 for gpu_ps_image_sample_offset_bias_lod_magnified and for the head a60db9f: the RX 6600 XT run above is of fd45f20. RDNA4 ran a60db9f (@nullmarsh, above).
  • Linear mip filters on these forms. Only the level choice is fixed; the per-mip blend Recompiler: image_sample_o under an implicit LOD moves each blended mip by its own texels #229 does for the plain form is not extended here.
  • b_o and d_o outside a pixel shader, 1D / 3D / array textures, A16 addresses, and a min-LOD clamp (_cl_) together with an offset.
  • A T# with MIN_LOD whose base level isn't 0. The offset applies MIN_LOD in the view's levels; I didn't check whether D3D12 applies ResourceMinLODClamp in the view's levels or the resource's.
  • image_sample_c_l_o in a PS: the offset moves by the given LOD, while SampleCmp reads the pixel's own, as on main.
  • AMD for 227a60a: the AMD runs above are of earlier heads.
  • Anisotropic samplers. The gradient LOD here is the isotropic log2 of the longer gradient, which can differ from the hardware's at a mip boundary. The plain form's CalculateLevelOfDetail has the same limit.

AI use

  • Claude Code (Claude Opus 5.5), code, tests and this description; Claude Code (Claude Fable 5.2), the rebase onto dd2ae9a and its runs; Claude Code (Claude Opus 5.5), the fixes for @JGonzalezRodriguez's review, their tests and the runs on c14bd12 and 227a60a

@ryotdev

ryotdev commented Nov 23, 2026

Copy link
Copy Markdown

I reproduced a magnification edge case on native Windows 11 with an RTX 5070 (driver 32.0.16.1088) and DXC 1.9.2609.5. I applied fd45f206's diff on main@7a033c8c and used the same synthetic test code for both builds.

I duplicated gpu_ps_image_sample_offset_bias_lod, changed the scale from 1/8 to 1/16, kept the instruction bias and offset at +1, and expected texel_moved(0, u). That gives implicit LOD −1, plus bias 1, so the sample and offset should both use mip 0.

Case Main PR
Original LOD 0 + bias 1 (0,0) = 100, expected 101 Pass
Magnification LOD −1 + bias 1 Pass (0,0) = 2, expected 1

Using CalculateLevelOfDetailUnclamped in the biased pixel path let the instruction bias see the raw negative LOD. With that local change, all six gpu_ps_image_sample_offset_ tests passed on the GPU, including the original positive case and the magnification regression. This checks the sampler in the existing fixture. Any sampler and view bounds still need to be applied after bias. Direct3D LOD calculation

Synthetic textures only. Rust 1.100.0, clang-cl/lld 19.1.1 with xwin SDK 10.0.26100. AI-assisted (Codex).

@Kalmarv
Kalmarv force-pushed the fix/sample-o-lod-variants branch from fd45f20 to a60db9f Compare November 23, 2026 22:07
@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @ryotdev, that was a real regression. Your case is now gpu_ps_image_sample_offset_bias_lod_magnified: on fd45f20 it fails as you saw it ((0,0) = 2, expected 1), and on the new head it passes. RTX 5070 Ti, 610.74: all 6 gpu_ps_image_sample_offset_* pass, and gpu::recomp:: gives 187 passed, 0 failed, 18 ignored.

The new head a60db9f (one commit, rebased on 9ab7d76) uses CalculateLevelOfDetailUnclamped in the biased path, as you suggested. The sampler's MIN_LOD / MAX_LOD and the view's last mip are applied after the bias. The gradient log2 and the c_o ddx/ddy LOD were already unclamped before the bias.

🤖 Claude Opus 5.5

@Kalmarv Kalmarv changed the title Recompiler: image_sample_b_o / d_o / cd_o / c_o move the offset by the mip they read Recompiler: image_sample_b/d/cd/c_o offsets move by the mip they read Nov 23, 2026
@WarmMilkCodes

Copy link
Copy Markdown
Contributor

Tested #247 fd45f20 merged onto main 9ab7d76 on AMD Radeon RX 6600 XT (RDNA2), driver 32.0.21045.29003, Windows 11 23H2 (22631.6199): pass

cargo test --workspace --no-fail-fast -- --test-threads=4, no XCL_SAMPLE_* data: main 651 passed / 0 failed; this 655 passed / 0 failed, 0 GPU tests skipped. The PR's 4 new tests pass on RDNA2; no new failures.

@denio4321

Copy link
Copy Markdown

Tested a60db9f merged onto main 9ab7d76 on RTX 3060 12 GB (Ampere, 32-lane waves), NVIDIA 610.88, Windows 11 Pro 23H2 (22631), rustc 1.100.0 MSVC, DXC 1.9.2602.17: pass.

.\scripts\test.ps1 (debug, --test-threads=4), no XCL_SAMPLE_* set. Baseline main 9ab7d76 alone on the same machine: 651 passed, 0 failed, 40 ignored.

  • This PR: 656 passed, 0 failed, 40 ignored.
  • The five new tests pass on this card: gpu_ps_image_sample_offset_point_mip, _bias_lod, _bias_lod_magnified, _gradient_lod and _compare_lod.
  • GPU skips are the same 2 as on main (no wave64).

The magnification case from the comment above (_bias_lod_magnified) passes here too.

Not checked: the negative control, or any game.

AI-assisted (Claude Code).

@PHeitor1

Copy link
Copy Markdown

Tested on RTX 5060 Ti 8 GB, driver 621.24, Ryzen 5 5600X, Windows 11 Pro 26300 (native), Rust 1.100.0 msvc, debug. cargo test --workspace --no-fail-fast -- --test-threads=4 on the head a60db9f: 656 passed, 0 failed, 40 ignored (main 9ab7d76: 651 / 0 / 40). SKIPPED: only the usual two no wave64 (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware).

Run and written with Claude Code (Claude Opus 5.5).

@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Regression run wanted. We have no title on our machine. If you can run scripts/smoke.ps1 -Game <your title folder> twice, once built from main (9ab7d76) and once from this PR's head (a60db9f), please paste both xcl-smoke blocks here. I'll copy them into the description with your name and hardware.

🤖 Claude Opus 5.5

@JGonzalezRodriguez

Copy link
Copy Markdown

Tested PR #247 head a60db9f against base 9ab7d76 on both NVIDIA and AMD RDNA2 (native wave64).

Tested

  • Host / stack: CachyOS Linux, NVIDIA RTX 4090 (NVIDIA 610.57.4, wave32) and AMD RDNA2 iGPU (RADV RAPHAEL_MENDOCINO, radv 26.2.4, native wave64 + wave32) via Proton Experimental wine + relaxed vkd3d-proton; DXC 1.9.2609.5; cross-built x86_64-pc-windows-msvc debug (rustc 1.98.1, clang-cl 23.1.1 + lld-link, 0 errors, 0 warnings).
  • image_sample_offset tests (a60db9f vs 9ab7d76 emit.rs with a60db9f tests.rs):
Test Base 9ab7d76 (RTX 4090 / RADV) PR a60db9f (RTX 4090 / RADV)
gpu_image_sample_offset pass / pass pass / pass
gpu_ps_image_sample_offset_implicit_lod_between_mips pass / pass pass / pass
gpu_ps_image_sample_offset_point_mip pass / pass pass / pass
gpu_ps_image_sample_offset_bias_lod_magnified pass / pass pass / pass
gpu_ps_image_sample_offset_bias_lod FAIL (100, want 101) / FAIL (100, want 101) pass / pass
gpu_ps_image_sample_offset_gradient_lod FAIL (100, want 101) / FAIL (100, want 101) pass / pass
gpu_ps_image_sample_offset_compare_lod FAIL (0, want 1) / FAIL (0, want 1) pass / pass
  • Confirmed a60db9f fixes the symmetric b_o minification + negative bias case (LOD +2 + bias -1 → 101), b_o with MaxLOD = 0 (MIP_FILTER = point → 1), and d_o with MinLOD = 1 (101) on both GPUs.

Findings (synthetic probes reproduced identically on both RTX 4090 and AMD RDNA2)

  1. MIP_FILTER == 0 (NONE, S# w[2][27:26]) is ignored (emit.rs:2190-2212) — regresses vs 9ab7d76:

    • desc::sampler_d3d12 (desc.rs:290,322) forces MaxLOD = MinLOD when MIP_FILTER == 0, while a60db9f reads only S# w[1] (MAX_LOD). With MIP_FILTER = NONE and MAX_LOD = 0xFFF:
      • d_o (grad 1): pass (1) on 9ab7d76 → FAIL (2, want 1) on a60db9f
      • b_o (LOD 0, bias +1): pass (1) on 9ab7d76 → FAIL (2, want 1) on a60db9f
      • c_o (implicit LOD 1): pass (1) on 9ab7d76 → FAIL (0, want 1) on a60db9f
    • Reading S# w[2] (as emit.rs:2257 already does) and setting lod_max = lod_min when ((w2 >> 26) & 3u) == 0u matches desc::sampler_d3d12.
  2. T# ResourceMinLODClamp (tw1[19:8] u4.8, desc.rs:73,251) is dropped on b_o (emit.rs:2203-2212) — new regression in a60db9f:

    • CalculateLevelOfDetail included SRV.ResourceMinLODClamp, whereas CalculateLevelOfDetailUnclamped omits it, and a60db9f clamps only against S# w[1] MIN_LOD:
      • b_o (LOD 0, bias 0) with ResourceMinLODClamp = 1.0: pass (101) on 9ab7d76 → FAIL (100, want 101) on a60db9f
    • tw1 is already bound at emit.rs:2088, so lod_min = max(s_min, (float)((tw1 >> 8) & 0xFFFu) / 256.0f) fixes this for b_o, d_o, cd_o, and c_o.
  3. S# MipLODBias (w[2][13:0] s5.8) is omitted on grad_lod paths (d_o, cd_o, c_o) (emit.rs:2201-2202):

    • SampleGrad and SampleCmp both apply sampler.MipLODBias, whereas raw log2(...) does not:
      • d_o (grad 0) + MipLODBias = +1.0: FAIL (100, want 101)
      • c_o (implicit LOD 0) + MipLODBias = +1.0: FAIL (0, want 1)
    • Adding (float)(((int)(w2 << 18)) >> 18) / 256.0f to the grad_lod branches aligns them with CalculateLevelOfDetailUnclamped (which already includes sampler.MipLODBias).
  4. Comparison forms with explicit gradients/bias (c_d_o, c_cd_o, c_b_o) regress against SampleCmp / SampleCmpLevelZero (emit.rs:2200-2209 vs 2233-2234):

    • emit.rs:2233-2234 emits SampleCmp (implicit LOD, ignoring grads/bias) in PS and SampleCmpLevelZero (mip 0) outside PS, while the offset-level path now uses grad_lod(dx, dy) / + bias:
      • c_d_o in PS (implicit LOD 0, grad 1, GREATER_EQUAL z=1.5): pass (1) on 9ab7d76 → FAIL (0, want 1) on a60db9f
      • c_b_o in PS (implicit LOD 0, bias +1, GREATER_EQUAL z=1.5): pass (1) on 9ab7d76 → FAIL (0, want 1) on a60db9f
    • Until SM 6.7 SampleCmpGrad/SampleCmpBias/SampleCmpLevel are used, has_c should match the emitted instruction (0u when !ps || has_lz, pure screen-derivative LOD + sampler bias/clamps when ps).
  5. Minor: emit.rs:2188 calls self.texel_offset(&t, dim, o, "0u", "0") just to obtain {t}_w0/{t}_h0/{t}_d0/{t}_n0, leaving an unused float3 {t}_o0.

Not tested

  • Native Windows, Windows SDK DXC 1.7, full workspace test run on a60db9f (ran targeted image_sample_offset + probes on a60db9f; full gpu::recomp::tests:: ran on fd45f20), retail titles.

AI use

Antigravity (Gemini frontier model) assisted with code review, dual-GPU synthetic probe execution, and drafting this report; every line cited and repro result was directly verified on this host.

@ghost

ghost commented Nov 23, 2026

Copy link
Copy Markdown

Tested a60db9f merged onto main 4017f8f (clean merge) on AMD RDNA4: pass, and three of the five new tests fail without the fix.

Tested

  • AMD Radeon RX 9060 XT (RDNA4), driver 32.0.32029.2010; Ryzen 7 5800X3D; Windows 11 Pro 26200; Rust 1.100.0; DXC 1.9.2602.17 (SDK 10.0.26100); debug build.
  • .\scripts\test.ps1: 657 passed, 0 failed, 40 ignored; no SKIPPED GPU tests on this adapter.
  • XCL_REQUIRE_GPU=wave64,mesh cargo test -p xcl --lib image_sample_offset: 7 passed, 0 failed (the five new gpu_ps_image_sample_offset_* tests, ..._implicit_lod_between_mips and gpu_image_sample_offset).
  • Negative control: only this PR's tests.rs on main 4017f8f (the emit.rs change left out): ..._bias_lod, ..._gradient_lod and ..._compare_lod fail (tests.rs:2005). ..._point_mip and ..._bias_lod_magnified pass with or without the fix, so on this adapter they guard against regressions rather than show this change.

Not tested

  • No XCL_SAMPLE_* set and no retail title, so no smoke.ps1 regression run; vertex/compute stages with a bias or gradients (the new tests are PS only); NVIDIA.

AI use

  • Claude Code (Claude Opus 5.5) ran the commands and wrote this report from the logs; I checked it before posting.

@srcamarda

Copy link
Copy Markdown
Contributor

@Kalmarv the regression run you asked for, plus the first RDNA3 run.

Tested

  • AMD Radeon RX 7800 XT (RDNA3, native 64-lane waves), driver 32.0.32029.2010; Ryzen 5 5600G, 32 GB; Windows 11 Pro 26300; Rust 1.100.0 MSVC; DXC 1.8.2502.11 (SDK 10.0.26100)
  • Built from the head a60db9f itself (on 9ab7d76), no uncommitted changes
  • XCL_REQUIRE_GPU=wave64,mesh cargo test -p xcl --lib image_sample_offset: 7 passed, 0 failed (the five new tests, …_implicit_lod_between_mips, gpu_image_sample_offset)
  • cargo test --workspace -- --test-threads=4 (debug): 656 passed, 0 failed, 40 ignored, no SKIPPED

Regression run (retail title, scripts/smoke.ps1, 90 s, release). Three runs of each binary, the first with a cold translation cache: main 901 / 1 180 / 1 184 frames, this PR 1 168 / 1 167 / 1 357. No crash or device removal in any, and the same peak commit. gpu: names a virtual display adapter on this machine; XCL ran on the RX 7800 XT. The second run of each:

main 9ab7d76:

xcl-smoke v1
commit: 9ab7d763197c7f420bff10cd9bf1310f07e2a9aa
gpu: SudoMaker Virtual Display Adapter
title: RetailGame_Dump
seconds: 90
exit: 0x0
frames shown: 1180 (PresentX 1180)
presents per 2 s (last 3): 27 28 26
device removals: 0
crashes: 0
peak commit: 17197 MB

this PR's head a60db9f:

xcl-smoke v1
commit: a60db9f3e5f279e66b7e1a73ba66a8c13a98d14c
gpu: SudoMaker Virtual Display Adapter
title: RetailGame_Dump
seconds: 90
exit: 0x0
frames shown: 1167 (PresentX 1167)
presents per 2 s (last 3): 25 26 25
device removals: 0
crashes: 0
peak commit: 17201 MB

Not tested

  • The changed forms in a title. In these 90 s (the title's first menus) the shaders it loads use image_sample, _l, _lz, _c_lz, _d and _b (report.json → shaders.rdna2_mnemonics), but no _o form, so this run is a regression check only. The negative control was also not run here; nullmarsh did that on RDNA4.

AI use

  • Claude Code with Claude Opus 5.5: built both commits, ran the tests and the smoke runs, wrote this report.

@PHeitor1

Copy link
Copy Markdown

Re-tested a60db9f merged onto main 2b4bb43 (clean merge) on RTX 5060 Ti 8 GB (Blackwell, 32-lane waves), NVIDIA 621.24, Ryzen 5 5600X, Windows 11 Pro 26300 (native, Graphics Tools + XGameRuntime installed, so the debug-layer tests run), rustc 1.100.0 MSVC, debug, cargo test --workspace --no-fail-fast -- --test-threads=4, no XCL_SAMPLE_*.

Pass: 675 passed, 0 failed, 41 ignored. SKIPPED: only the 2 no wave64 tests.

Run and written with Claude Code (Claude Opus 5.5).

@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@srcamarda thank you, both blocks are in the description under Regression run, with your three-run spread and the note that the title's first menus don't reach an _o form.

🤖 Claude Opus 5.5

xcl-dev#229 picks the offset's mip for the plain form only; the bias, gradient
and (in a PS) comparison forms still divided by mip 0's size. The level
is now the given LOD, else that of the given gradients or the pixel's
own (screen derivatives for comparison samplers, which
CalculateLevelOfDetail does not take), plus the bias. That LOD is the
unclamped one, so a bias on a magnified pixel starts below 0 (found by
ryotdev); the sampler's MIN_LOD / MAX_LOD and the view's last mip are
applied after the bias.

The level follows what the view and the sampler are made of and the
sample that is emitted (found by JGonzalezRodriguez): the sampler's
LOD_BIAS is added to a LOD from gradients, as SampleGrad and SampleCmp
add it; the lower clamp includes the T#'s MIN_LOD (the SRV's
ResourceMinLODClamp); without a mip filter MAX_LOD is MIN_LOD, as
desc::sampler_d3d12 sets the sampler up. A comparison sample is
SampleCmpLevelZero outside a PS and SampleCmp, which takes neither
gradients nor a bias, in a PS, so its offset moves by mip 0 there and by
the pixel's own LOD here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Kalmarv
Kalmarv force-pushed the fix/sample-o-lod-variants branch from 287ca93 to 227a60a Compare November 24, 2026 17:36
@Kalmarv

Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@JGonzalezRodriguez thank you, and sorry this took a day. I checked all five points against the code and on the GPU, and they all hold. They're fixed in 227a60a, squashed into the PR's commit and rebased onto main 9e3831e. A whole-suite run on the old base stops in the #344 deadlock, which #443 fixed later. Each fix has a GPU test, and each test fails on 287ca93:

  1. No mip filter. When S# word 2 [27:26] is 0, the offset's level now takes MAX_LOD = MIN_LOD, as desc::sampler_d3d12 sets up the sampler. Test gpu_ps_image_sample_offset_without_a_mip_filter: your three cases, d_o (gradient LOD 1), b_o (LOD 0 + bias 1) and c_o (implicit LOD 1), read mip 0 and move by one of its texels.
  2. T# MIN_LOD. The lower clamp is now max(S# MIN_LOD, T# word 1 [19:8]); the T# field is the SRV's ResourceMinLODClamp. Test gpu_ps_image_sample_offset_resource_min_lod: b_o and d_o at LOD 0 with a clamp of 1.0 move by mip 1's texels.
  3. S# LOD_BIAS. It is now added to a LOD taken from gradients: the given ones (d_o, cd_o) and the screen derivatives of c_o. That matches SampleGrad and SampleCmp, which add it. b_o in a PS uses CalculateLevelOfDetailUnclamped, which already includes it. Test gpu_ps_image_sample_offset_sampler_bias: d_o at gradient LOD 0 and c_o at LOD 0 with LOD_BIAS +1 move by mip 1's texels. b_o is a control and passed before too.
  4. Comparison forms. You're right that the level has to follow the sample that is actually emitted. A comparison offset now moves by mip 0 outside a PS (SampleCmpLevelZero) and by the pixel's own LOD in a PS (SampleCmp, which takes neither gradients nor a bias in SM 6.6). Test gpu_image_sample_c_b_d_offset_moves_by_the_mip_read covers c_b_o and c_d_o in a PS and in a VS. It samples a checkerboard (one in each mip's own texels) at offsets 0 and +1. Moving by one texel of the mip that was read flips every pixel; moving by the other mip's texels flips half of them or none. So the test doesn't assume which mip is read.
    Recompiler: pixel comparison samples apply their LOD bias #349 and Recompiler: comparison samples use their supplied pixel gradients #350 make the PS SampleCmp take the bias and the gradients. In a tree with either of them and this PR, the matching line here has to take them too: lod_bias for Recompiler: pixel comparison samples apply their LOD bias #349, lod_grads for Recompiler: comparison samples use their supplied pixel gradients #350. The two lines are separate, so the two follow-ups don't conflict. I'll check this on a tree with all three, and push the one-line change to whichever of the three lands last.
  5. {t}_o0 is gone. The level-0 size now comes from mip_size, which texel_offset also calls.

Tested (RTX 5070 Ti, NVIDIA 610.74, Ryzen 9 9950X, Windows 11 Pro 26200, debug, SDK DXC 1.7)

  • gpu_ps_image_sample_offset*, gpu_image_sample_offset and the new comparison test on c14bd12 (the same patch before the rebase): 11 passed, 0 failed.
  • The same 11 with emit.rs from 287ca93: the four new tests fail and the other seven pass. Each case on its own (a scratch test, not in the PR): 11 of the 12 cases fail on 287ca93, and all 12 pass on c14bd12; the 12th is the b_o control.
  • cargo test --workspace -- --test-threads=4 on 227a60a: 785 passed, 0 failed, 41 ignored (the xcl library: 736 passed, 21 ignored). SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64), and heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows; main's own test).

Not tested

  • AMD, and a title using these forms with an offset (none is known).
  • A T# with MIN_LOD whose base level isn't 0. The offset applies MIN_LOD in the view's levels; I didn't check whether D3D12 applies ResourceMinLODClamp in the view's levels or the resource's.
  • c_l_o in a PS still moves by the given LOD while SampleCmp reads the pixel's own, as on main.

AI use: Claude Code (Claude Opus 5.5)

@PHeitor1

Copy link
Copy Markdown

Retest of the new head 227a60a, merged onto main 4178e88 (clean): passes on Blackwell, and five of its tests fail here without the fix.

Tested

  • RTX 5060 Ti 8 GB (32-lane waves), NVIDIA 621.24, Ryzen 5 5600X, Windows 11 Pro 26300, rustc 1.100.0 MSVC, DXC 1.9.2602.17, debug, no XCL_SAMPLE_*.
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 900 passed, 0 failed, 42 ignored. SKIPPED: the 2 no wave64 tests, heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows, and pso_measurement_compiles_an_exact_synthetic_record (Developer Mode is off here).
  • The 11 offset tests (image_sample_offset, image_sample_c_b_d_offset), --test-threads=1, no SKIPPED: 11 passed. The same tree with only emit.rs from main: 6 passed, 5 failed.
test emit.rs from main 227a60a
…_bias_lod FAIL: (0,0) = 100, expected 101 pass
…_gradient_lod FAIL: d_o (0,0) = 100, expected 101 pass
…_compare_lod FAIL: (0,0) = 0, expected 1 pass
…_resource_min_lod FAIL: d_o (0,0) = 100, expected 101 pass
…_sampler_bias FAIL: d_o (0,0) = 100, expected 101 pass
…_without_a_mip_filter, gpu_image_sample_c_b_d_offset_moves_by_the_mip_read pass pass
the other four pass pass

The two review tests that pass with main's emit.rs read mip 0 in the cases they check, which is the mip main already uses, so they guard the new code rather than show a bug on main.

Not tested: 287ca93's emit.rs, AMD / Intel, release, a title.

Run and written with Claude Code (Claude Opus 5.5).

@raylitebull

Copy link
Copy Markdown
Member

CI checks (Build and test and PR description) are green on 227a60a.

Remaining before merge: an independent AMD GPU pass on the current revised head 227a60a.

@Kalmarv

Kalmarv commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, @raylitebull. An AMD pass on the current head 227a60a is the one missing piece. We have no AMD card here, so this needs someone who does. @srcamarda and @DarkPanda69, you've run AMD passes on related heads before. If either of you has time:

git fetch https://github.com/xcl-dev/xcl.git pull/247/head && git checkout FETCH_HEAD
cargo test --release -p xcl --lib -- --test-threads=4

Please post the passed, failed and ignored counts, any SKIPPED lines, and your GPU, driver and DXC version.

AI use: Claude Code (Claude Opus 5.5) wrote this.

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.

8 participants