Skip to content

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

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

Kalmarv wants to merge 1 commit into
xcl-dev: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

  • Head 7d1c008 is fe3011d's two commits squashed into one, with the same tree (git diff fe3011d 7d1c008 is empty). cargo test --workspace -- --test-threads=4 on 7d1c008 merged onto main 9e3831e (a clean merge, 389c343): 777 passed, 0 failed, 41 ignored (the xcl library: 728 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).
  • Rebased head fe3011d1b16d on 18c105af8692. The bias and flat integer selector raster tests both passed (2 passed, 0 failed). cargo build --workspace passed. cargo test --workspace -- --test-threads=4 returned 690 passed, 0 failed, 41 ignored. GPU tests reporting SKIPPED within the pass count: gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64).
  • Previous head cccc2c3890ef on an RTX 5070 Ti (610.74), SDK DXC 1.7, ps_6_6: the targeted raster test passed. The full workspace returned 652 passed, 0 failed, 40 ignored; two native-wave64 tests reported SKIPPED within the pass count. All six bias cases passed on the full-screen triangle and the partial quads along the diagonal.
  • 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.
  • Independent run by @throny (Recompiler: pixel comparison samples apply their LOD bias #349 (comment)): RTX 4080 (NVIDIA 610.88), i9-12900K, Windows 11 26300, Rust 1.100.0, debug, d25aea1 merged onto main 7ebf1b8. The new test passes, and with emit.rs from main fails in four of its six cases. Their whole suite stopped in the D3D12.X: replacing the sparse state deadlocks when the old state still holds placed buffers #344 hang in 4 of 4 runs; with D3D12.X: the sparse state is replaced outside its lock #443 merged too: 679 passed, 0 failed, 41 ignored.
  • Earlier smoke runs by @CuteBooty, RTX 3070 (NVIDIA 617.14), release, on main 9ab7d76 and the head tested in that report: 918 and 913 frames, no crash or device removal (Recompiler: pixel comparison samples apply their LOD bias #349 (comment)).

Regression run

Our own runs, one after the other on the machine under Tested (RTX 5070 Ti), release builds, no uncommitted changes: main at 18c105a (this PR's base), then this PR's head 7d1c008. 1276 / 1246 frames (102 %), peak commit 26598 / 27160 MB (98 %); no device removal and no crash on either run.

main:

xcl-smoke v1
commit: 18c105af86929d6ae26c44096c85b66f1644e743
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1246 (PresentX 1246)
presents per 2 s (last 3): 18 15 7
device removals: 0
crashes: 0
peak commit: 27160 MB

PR:

xcl-smoke v1
commit: 7d1c008da9127bde6076023cd3856a92dbb04c40
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1276 (PresentX 1276)
presents per 2 s (last 3): 23 37 20
device removals: 0
crashes: 0
peak commit: 26598 MB

Not tested

  • AMD. The pixel-shader quad operations emitted by this change have never been compiled by an AMD driver in our testing.
  • Whether the title's frames reach these sample forms: the smoke run is a regression check 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, the rebase onto 18c105a and its runs, and this description
  • Claude Code (Claude Opus 5.5): the smoke runs under Regression run, the squash into one commit and the suite run on 7d1c008

🤖 Generated with Claude Code

@ghost

ghost commented Nov 24, 2026

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

@throny

throny commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

NVIDIA RTX 40 run of d25aea1 on main 7ebf1b8 (clean merge): the new test passes and fails without the emit.rs change. The whole suite did not finish on this tree here, for a reason that is not this PR (below).

Tested

Reviewed (read the whole diff)

  • In iteration q every pixel of the quad computes coord[q] + (its position − q's position) · gradient[q], so the implicit derivatives SampleCmp sees are pixel q's scaled ones, and each pixel keeps the result of its own iteration (delta 0, its own coordinate). xi.xcl_pos is always a member of XclIn.

Not tested

  • No regression run (scripts/smoke.ps1) on a title, no shader-pack run (XCL_SAMPLE_RPF), wave64 hardware, cube and array forms (the test draws 2D only).

AI use

  • Claude Code (Claude Fable 5.2) ran the builds, the tests and the controls, read the diff and wrote this report. The runs above are real, on the hardware named.

@QemmHD

QemmHD commented Nov 24, 2026

Copy link
Copy Markdown

Review: scaling ddx/ddy by exp2(bias) adds the bias to log2 of the footprint, and the quad construction reproduces those derivatives exactly. Two points (same as on #350):

  1. emit.rs:2191-2196: offsets for comparison samples still use level 0u, so _c_b_o / _c_b_cl_o with a non-zero offset move by mip-0 texels while the bias selects mip ≥ 1. The test's _O rows use offset 0; a note on the Recompiler: image_sample_b/d/cd/c_o offsets move by the mip they read #247 dependency, or a non-zero-offset row after Recompiler: image_sample_b/d/cd/c_o offsets move by the mip they read #247, would cover it.
  2. The full-screen triangle never creates a partial quad, so helper lanes (which QuadReadLaneAt and SampleCmp depend on here) aren't exercised; an edge through quads would cover that.

AI-assisted review (Claude Code, Claude Opus 5.5).
Discord: bigpeppa.

@CuteBooty

Copy link
Copy Markdown

Regression run on a retail title for d25aea1, which the description lists as pending: pass (no device removal, no crash, frames and peak commit level with main).

Tested

  • RTX 3070 8 GB (32-lane waves), NVIDIA 617.14; Ryzen 5 3600, 32 GB; Windows 11 Pro 26200; rustc 1.100.0 MSVC; release build.
  • scripts\smoke.ps1 -Game <folder> -Seconds 60 on the PR's head as it is and on main 9ab7d76, the commit it is based on, each built from a clean checkout of its commit.
  • Each build ran twice back to back and the blocks are the second runs. The first runs: 912 frames (main) and 911 frames (PR), also with no device removal or crash. The main block is one run, shared with my reports on Memory: a freed sparse block is decommitted before its address is reused #348 and Recompiler: comparison samples use their supplied pixel gradients #350.
  • Video memory at 60 s, from XCL's memory: line: 6311 MB local / 4619 MB non-local (main), 6311 MB local / 4619 MB non-local (PR).

main:

xcl-smoke v1
commit: 9ab7d763197c7f420bff10cd9bf1310f07e2a9aa
gpu: NVIDIA GeForce RTX 3070
title: game
seconds: 60
exit: 0x0
frames shown: 918 (PresentX 918)
presents per 2 s (last 3): 40 41 40
device removals: 0
crashes: 0
peak commit: 14793 MB

PR:

xcl-smoke v1
commit: d25aea1415895c250f82ec3b36023761c146a3ad
gpu: NVIDIA GeForce RTX 3070
title: game
seconds: 60
exit: 0x0
frames shown: 913 (PresentX 914)
presents per 2 s (last 3): 41 40 40
device removals: 0
crashes: 0
peak commit: 14796 MB

Not tested

  • The test suite on this head (others have posted it), anything past the first 60 s, and whether a shader the title draws with in these 60 s has a comparison sample with a bias (the case this changes).

AI use: Claude Code with Claude Fable 5.2 made the runs with me present and wrote this comment.

@Kalmarv

Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for checking the mip calculation and the triangle coverage.

The standalone head uses mip-0 texel units for both offset forms, and its two offset rows pass zero. I added that dependency to the PR body draft. With #247 at a60db9f, a synthetic IMAGE_SAMPLE_C_B_O draw with a +1 X offset read the expected neighbor at mip 1.

The full-screen triangle left the helper-lane case uncovered. The test now keeps that draw and adds a diagonal that leaves one or three covered pixels in each edge quad. The bias fixture now enters whole-quad mode (S_WQM_B64 EXEC, EXEC) before computing texture coordinates so helper pixels supply the screen derivatives. It checks the depth comparison for all 96 covered pixels and the clear value for the other 160.

Tested

PR head cccc2c3890ef on an RTX 5070 Ti (610.74), SDK DXC 1.7, ps_6_6: the targeted raster test passed. The full workspace returned 652 passed, 0 failed, 40 ignored; two native-wave64 tests reported SKIPPED within the pass count.

Not tested

AMD on this follow-up. Our title smoke pair on this head is in the description; the title doesn't show whether it reaches these sampling forms.

🤖 GPT-6.2 Astra

@thehollowedone

Copy link
Copy Markdown

Independent native D3D12 check of fe3011d on RTX 3080 Ti / 621.35, Windows 11 build 26300, DXC 1.8.2502.11 and Rust 1.99.1 MSVC, release.

All six bias cases matched the expected pixel values on both the full-screen and partial-quad triangles. The flat integer selector control passed too. The offset variants in this fixture use zero offsets. Two stock tests passed, with zero failures, ignores or skips.

Commands used XCL_ADAPTER=3080 Ti and cargo test --locked --offline --release -p xcl --lib <filter> -- --test-threads=1 --nocapture, with gpu_ps_compare_mip_bias and gpu_ps_p0_reads_flat_integer_selectors.

AI use: Codex (GPT-6, exact variant unavailable) ran the tests and drafted this report.

SM 6.6 has no comparison sample that takes a bias, so a pixel shader's
image_sample_c_b* selected its mip from the unbiased screen derivatives.
The derivatives are now scaled by 2^bias, and SampleCmp runs once for each
pixel of the quad (QuadReadLaneAt) with that pixel's footprint; each pixel
keeps its own result. A lane's own coordinate is used unchanged on an axis
it does not move along, so a non-finite derivative cannot turn it into NaN.
The test draws a full-screen triangle and one whose edge leaves partial
quads.

Assisted-by: Codex (GPT-6.2 Astra)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Kalmarv

Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Squashed into one commit (7d1c008, the same tree as before) as CONTRIBUTING asks; the smoke pair for it is queued.

A note for the merge order with #247: this PR makes the PS SampleCmp take the bias, and #247 moves a comparison offset by the mip that sample reads. With both in a tree, one line in #247's offset code has to take the bias too, or gpu_image_sample_c_b_d_offset_moves_by_the_mip_read fails (sample_c_b_o, PS: pixel (0,0) = 0). We have that line ready and tested (62f93a3; with it the test passes, and main + all eleven of our open PRs + both follow-ups pass the whole suite, 815 passed, 0 failed). Whichever of the two lands second, we push it there.

AI use: Claude Code (Claude Opus 5.5)

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.

5 participants