Skip to content

Recompiler: comparison samples use their supplied pixel gradients - #350

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

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

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Pixel-shader image_sample_c_d* and image_sample_c_cd* now use the instruction’s gradients for depth comparisons. Main selected the mip from screen derivatives even when the instruction requested a finer or coarser footprint. This overlaps #247 in emit.rs and builds directly on main.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs — Uses the instruction’s X and Y gradients, keeping array layers discrete and projecting cube-face coordinates back to a direction. 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 coarser, finer and per-pixel gradients, the coarse-derivative zero-offset form, matching gradients 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 13d8a1f5e592 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: 13d8a1f 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 (the two wave64 skips on your 5070 Ti run here).
  • XCL_REQUIRE_GPU=wave64,mesh cargo test -p xcl --lib gpu_ps_compare_mip: gpu_ps_compare_mip_gradients passes.
  • Negative control: the merged tree with only emit.rs back on main. The test fails with IMAGE_SAMPLE_C_D, scale 0.125, slope 0: pixel (0,0): 0 instead of 1 from mip 1, plus the _C_D_CL, _C_CD_O and slope 0.0625 cases.
  • With Recompiler: pixel comparison samples apply their LOD bias #349 also merged (the shared sample_cmp_grad is identical, so git merges it cleanly): both gpu_ps_compare_mip_gradients and gpu_ps_compare_mip_bias 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.

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