Skip to content

Recompiler: pixel comparison samples apply their LOD bias - #349

Open
Kalmarv wants to merge 1 commit into
ivall:mainfrom
Kalmarv:fix/ps-compare-bias
Open

Kalmarv wants to merge 1 commit into
ivall:mainfrom
Kalmarv:fix/ps-compare-bias

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Pixel-shader image_sample_c_b* now applies the instruction’s LOD bias to depth comparisons. With point mip filtering, +1 selects the coarser mip and −1 the finer mip. This overlaps #247 in emit.rs and builds directly on main.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs — Scales ddx(coord) and ddy(coord) by exp2(bias). At ps_6_6, QuadReadAcrossX and QuadReadAcrossY on SV_Position identify the pixel in the quad. An unrolled four-iteration loop uses QuadReadLaneAt for the coordinate and both derivatives, then issues one native SampleCmp per iteration. Each pixel selects its own result.
  • crates/xcl/src/gpu/recomp/tests.rs — six 16×16 raster draws check positive, negative and per-pixel bias, the zero-offset form, zero bias and a minimum-LOD clamp against two opposite depth checkerboards with point mip filtering.

Tested

  • Ryzen 9 9950X, RTX 5070 Ti (610.74), Windows 11 25H2 build 26200.9711, Rust 1.99.0 (MSVC x64), debug, SDK DXC 1.7.2308.16.
  • Head d25aea141589 on 9ab7d763197c. cargo build --workspace passed. cargo test --workspace -- --test-threads=4 returned 652 passed, 0 failed, 40 ignored. GPU tests reporting SKIPPED (included in Cargo’s pass count): gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64).
  • Base 9ab7d763197c with only the tests added failed four of six draw cases. The two controls passed on base, and all six passed on this head.
  • Integration with the companion fix and Recompiler: image_sample_b/d/cd/c_o offsets move by the mip they read #247 at a60db9f3e5f2: two checks passed. Both offset forms read the expected texel at mip 1 with a nonzero offset. SDK DXC compiled 20 opcode and view combinations.
  • Serial debug-layer suite on clean main: 593 passed, 18 failed, 20 ignored. On both main and the gradient run (594 passed, 18 failed, 20 ignored), CreateReservedResource returned E_OUTOFMEMORY in gpu_sparse_vram_descriptors_buffers_and_xmem. Three sparse windows had zero GPU addresses, then pipeline creation returned DXGI_ERROR_DEVICE_REMOVED.

Regression run

main: Pending: no title on our machine yet; our own run follows when we have one.

PR: Pending: no title on our machine yet; our own run follows when we have one.

Not tested

  • AMD. The pixel-shader quad operations emitted by this change have never been compiled by an AMD driver in our testing.
  • Regression run on a real title. The workspace used synthetic inputs only.
  • Cube and array sampling on hardware, and the throughput cost of issuing four comparison samples.

AI use

  • Codex (GPT-6.2 Astra): code, tests and this description

🤖 Generated with Claude Code

@nullmarsh

Copy link
Copy Markdown

AMD run, since Not tested says no AMD driver has compiled these quad operations yet: d25aea1 merged onto main a6f5f7a (clean merge): pass on RDNA4, and the new test fails without the emit.rs change.

Tested

  • AMD Radeon RX 9060 XT (RDNA4, wave64 + mesh shaders), 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: 677 passed, 0 failed, 41 ignored; no SKIPPED GPU tests.
  • XCL_REQUIRE_GPU=wave64,mesh cargo test -p xcl --lib gpu_ps_compare_mip: gpu_ps_compare_mip_bias passes.
  • Negative control: the merged tree with only emit.rs back on main. The test fails with IMAGE_SAMPLE_C_B, scale 0.125, slope 0: pixel (0,0): 0 instead of 1 from mip 1, plus the _C_B_CL, _C_B_O and slope 0.5 cases.
  • With Recompiler: comparison samples use their supplied pixel gradients #350 also merged (the shared sample_cmp_grad is identical, so git merges it cleanly): both compare-mip tests pass.

Not tested

  • A retail title (smoke.ps1); cube and array sampling on hardware; NVIDIA.

AI use

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

@Kalmarv

Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for testing on the RX 9060 XT and checking the negative control where reverting just the emitter change brought back all four mip-selection failures.

🤖 GPT-6.2 Astra

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.

2 participants