Skip to content

Recompiler: preserve explicit cubemap sampling gradients - #778

Open
AkshatPal2007 wants to merge 1 commit into
xcl-dev:mainfrom
AkshatPal2007:codex/cube-sample-gradients
Open

AkshatPal2007 wants to merge 1 commit into
xcl-dev:mainfrom
AkshatPal2007:codex/cube-sample-gradients

Conversation

@AkshatPal2007

Copy link
Copy Markdown

Fixes #767.

XCL reduced the two face-space gradients of a cubemap sample to one mip level. That lost the direction of the texture footprint. On a synthetic 32×32 texture with a single white column, an 8×1 texel footprint returned 1.0 through the old cube path and 0.125 through the equivalent 2D-array slice on the same GPU. The retail shader survey in HANDOFF.md records this instruction on cubemaps.

What is in it

  • Transform both gradients through the selected cube face’s coordinate basis and pass them to TextureCubeArray.SampleGrad. image_sample_d_cl passes its minimum LOD directly to the sampler. This removes the cube path’s texture-size query and manual LOD calculation.
  • Add GPU regressions for face orientation, anisotropic filtering, linear filtering across edges, and mip selection. This supersedes the scalar-LOD approximation described in HANDOFF.md.

Tested

  • Commit 527a2c9, debug build. Windows 11 build 26300.8376, i9-14900HX, RTX 4070 Laptop GPU, driver 32.0.16.1656, Rust 1.100.0 MSVC, DXC 1.8.2502.11.
  • cargo build --workspace succeeded.
  • cargo test -p xcl --lib gpu_cube -- --nocapture — 4 passed, 0 failed, 0 ignored, 0 skipped. Off-centre samples matched the equivalent 2D-array slices on all six faces of two cubes for horizontal, vertical, and both diagonal anisotropic footprints.
  • Isotropic linear filtering produced the expected blend on both sides of all 12 edges, at the boundary and a quarter texel inside it. A supplemental local test checked all eight corners from each incident face. All 24 cases matched the three-face mean within 0.02 on this GPU.
  • On a four-mip texture, the shader selected mip 0 for a one-texel footprint and mip 2 for a four-texel footprint. Minimum LOD 1 preserved the gradient-selected mip 2. Minimum LOD 2.5 blended mips 2 and 3. Temporarily halving the gradient scale made two tests fail.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 — 701 reported passed, 3 failed, 41 ignored. The three failures match Tests: placed_title_textures_share_vram_and_preserve_pixels fails now and then at its cubemap reuse check (main 9ce2070) #718 on unchanged main. Existing texture-sampling regressions and the bundled end-to-end title passed.
  • cargo test --workspace --no-fail-fast -- --test-threads=1 — 704 reported passed, 0 failed, 41 ignored. Both workspace runs counted two native-wave64 skips among passes.

Regression run

Pending. No unpacked retail title was available for the required main and PR-head smoke runs.

Not tested

Retail visual quality and performance, external sample files, AMD GPUs, and Intel GPUs.

AI use

Codex (gpt-6.2-astra) investigated the issue, implemented the change and regression tests, ran verification.

@mastrr9

mastrr9 commented Nov 24, 2026

Copy link
Copy Markdown

Independent native Windows NVIDIA RTX 5080 build/test run and code review at head 527a2c9cab49669e88d5d079ad63cd912f7a6216.

Code Review

  • Clean analytic differentiation of cube_dir via cube_face_vector(2.0f * dx, 2.0f * dy, 0.0f, face) across all 6 cube faces (+X/-X/+Y/-Y/+Z/-Z), matching cube_dir's (s - 1.5) * 2, (t - 1.5) * 2 parameterization with constant major axis.
  • Verified all three new GPU tests (anisotropic 16x cube vs 2D array footprint, all 12 cube edges, and IMAGE_SAMPLE_D_CL min-LOD clamp) pass directly on NVIDIA RTX 5080. No issues found.

Tested

  • Environment: NVIDIA GeForce RTX 5080 (16 GB, wave32, driver 617.42 / 32.0.16.1742), Windows 11 Pro 25H2 (26200.9974), rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC from Windows SDK 10.0.26100.0, debug build.
  • Command: cargo build --workspace && cargo test --workspace -- --test-threads=4
  • Result: 704 passed, 0 failed, 41 ignored (0 new warnings).
  • PR-specific GPU tests (3/3 ok, executed on RTX 5080, not skipped):
    • gpu::recomp::tests::gpu_cube_sample_grad_matches_face_texture
    • gpu::recomp::tests::gpu_cube_sample_grad_edges
    • gpu::recomp::tests::gpu_cube_sample_grad_min_lod
  • SKIPPED (2):
    • gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64)
    • gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)

Not tested

  • D3D12 debug layer, AMD/wave64 hardware, release build, and retail titles.

AI use: Antigravity (Gemini 4 Neon) performed the code review, ran the RTX 5080 workspace tests, and drafted this comment.

@eizispark

Copy link
Copy Markdown

Hardware check of 527a2c9cab49669e88d5d079ad63cd912f7a6216 (verified clean merge with main d208e14): regression noted.

Tested

  • Hardware: AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32015.16001), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profile
  • cargo test --workspace -- --test-threads=4: -p xcl --lib exited abnormally (0xc0000005, STATUS_ACCESS_VIOLATION) in gpu::recomp::tests::gpu_cube_sample_grad_min_lod after gpu::recomp::tests::gpu_cube_sample_grad_matches_face_texture failed; all other workspace targets passed (41 passed, 0 failed, 20 ignored). Rerunning cargo test -p xcl --lib -- --test-threads=4 --skip gpu::recomp::tests::gpu_cube_sample_grad_min_lod gave 661 passed, 1 failed, 21 ignored (702 passed, 2 failed, 41 ignored across the workspace; GPU tests skipped on this adapter: none; baseline main f4ce27c: 701 passed, 0 failed, 41 ignored)
  • cargo test -p xcl --lib gpu_cube: 2 passed, 2 failed when run individually (gpu_cube_array_slices: ok; gpu_cube_sample_grad_edges: ok; gpu_cube_sample_grad_matches_face_texture: panicked at crates/xcl/src/gpu/recomp/tests.rs:2355:5 with the reference must resolve the two footprint directions; gpu_cube_sample_grad_min_lod: process exited with 0xc0000005, STATUS_ACCESS_VIOLATION)

Regression run
main (f4ce27c):

xcl-smoke v1
commit: f4ce27ceb6d1b0576d0c659b713b674778bf1968
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1667 (PresentX 1667)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14847 MB

PR (527a2c9):

xcl-smoke v1
commit: 527a2c9cab49669e88d5d079ad63cd912f7a6216
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1659 (PresentX 1659)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14863 MB

Not tested

  • wave32-only GPUs (NVIDIA / Intel); gameplay past the menus

AI use

  • Antigravity (Gemini 4 Carbon) ran the build, test suite, and scripts/smoke.ps1 harness on this machine and formatted this report.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

AMD RDNA4 run of 527a2c9cab49669e88d5d079ad63cd912f7a6216: the new test fails here, every time. I merged it onto current main d208e14 locally (clean merge) and tested that tree.

Tested

What that shows: it is the test's own precondition that fails, not the comparison with the cube path. 2.09375 is slice 2 + 3/32 of the synthetic texture, i.e. the same texel for every lane, whatever the gradients, and not at v = 19.5/32. So on this driver the 2D-array reference with D3D12_FILTER_ANISOTROPIC does not show the footprint direction at all (and the cube path returns the same value), which makes the test depend on how a driver implements anisotropic filtering on a one-mip R32_FLOAT texture. A texture with mips, or comparing against a CPU reference instead of the GPU's own 2D-array sample, would make it hold on AMD too. I have not looked into why the texel is the one at y = 3.

Not tested: the retail shaders the description mentions (no game data), release build.

Run and report by Claude Code (Claude Opus 5.5) on this machine; the values come from the runs above.

@milas6669

Copy link
Copy Markdown
Contributor

Test report and regression run for 527a2c9 (PR head, based on main 64b3f35; main is now d208e14, no conflict).

Tested

Regression run (the one this PR lists as pending; the same retail title, 60 s, release builds; the PR's run is on its own head, based on 64b3f35)

main (d208e14):

xcl-smoke v1
commit: d208e14b765f469f4b56301b78afa8dac5378339
gpu: NVIDIA GeForce RTX 3070
title: dumped
seconds: 60
exit: 0x0
frames shown: 359 (PresentX 359)
presents per 2 s (last 3): 13 13 13
device removals: 0
crashes: 0
peak commit: 15865 MB

this PR (527a2c9):

xcl-smoke v1
commit: 527a2c9cab49669e88d5d079ad63cd912f7a6216
gpu: NVIDIA GeForce RTX 3070
title: dumped
seconds: 60
exit: 0x0
frames shown: 331 (PresentX 331)
presents per 2 s (last 3): 13 13 12
device removals: 0
crashes: 0
peak commit: 15868 MB

That is 92 % of main's frames and the same peak commit, with no crash and no device removal. Both runs are on an NVIDIA card, so they say nothing about AMD.

Not tested

  • AMD / wave64 hardware, retail visual quality of cubemap sampling (the title was only run for a regression check; I did not look at the picture)
  • the cold DXIL cache: the translated HLSL changes with this PR, and I did not measure the first run separately

AI use

  • Claude Code, Claude Sonnet 5.5, ran the commands and wrote this report. I did not review the diff beyond reading it.

@luckyteagirl

Copy link
Copy Markdown
Contributor

RDNA2 test results for the cubemap gradient changes

Tested clean PR head 527a2c9cab49669e88d5d079ad63cd912f7a6216, debug build, Windows 11 Home build 26200, Ryzen 9 5980HX, Radeon RX 6800M driver 30.0.13002.13003, Rust 1.99.0 MSVC and DXC 1.8.2502.11. Set XCL_ADAPTER=6800M.

I ran each test separately with cargo test --locked -p xcl --lib gpu::recomp::tests::<name> -- --exact --test-threads=1 --nocapture.

Test Result
gpu_cube_array_slices Passed
gpu_cube_sample_grad_edges Passed
gpu_cube_sample_grad_matches_face_texture Failed at the reference must resolve the two footprint directions
gpu_cube_sample_grad_min_lod Process access violation 0xc0000005 in amdxc64.dll 30.0.13002.13003, fault offset 0x80B300

On a separate diagnostic run with only a print added, both the cube and 2D reference were 2.09375 for lanes 0, 12, 24 and 36. The first assertion compared two 2D reference values and failed before the cube-versus-2D comparisons. I removed the diagnostic print afterwards.

Not tested

The full workspace suite at this PR head, release mode, other drivers, and retail titles.

AI use

OpenAI Codex (GPT-6 family, exact model variant unavailable) ran the tests, checked the Windows crash event, and drafted this report.

@Abuudiii

Copy link
Copy Markdown

Independent exact-head synthetic checks at 527a2c9cab49669e88d5d079ad63cd912f7a6216: RX 9070 (RADV / Mesa 26.2.5), Arch Linux, GE-Proton 11-7 + vkd3d-proton 3.1, DXC/DXIL 1.9.2609.5, Rust 1.99.1 Windows GNU debug build.

Tested: Each gpu::recomp::tests:: case below ran in a fresh process with --exact --test-threads=1 --nocapture. The cube-array slice and seam controls (gpu_cube_array_slices, gpu_cube_sample_grad_edges) passed. gpu_cube_sample_grad_matches_face_texture failed at the 2D precondition, “the reference must resolve the two footprint directions.” Exact head: 2 passed, 1 failed, no skips.

A separate scratch run changed only logging, not the assertions: lanes 0, 12, 24 and 36 all returned 2.09375 for both cube and 2D reference. The reference did not distinguish the inputs, so this run cannot validate or refute cube-gradient preservation. No runtime change is proposed from that result.

Not tested: Minimum-LOD pixel test, native Windows, or retail. No game data was used.

AI use: omp (GPT-6.2 Sol) ran the checks and drafted this report.

@Xeltax

Xeltax commented Nov 24, 2026 •

Copy link
Copy Markdown

Same result as luckyteagirl (RX 6800M) and Abuudiii (RX 9070, RADV) above, on a third AMD setup: the Ryzen 9 9900X's RDNA2 iGPU, driver 32.0.21042.62, native Windows 11, PR head 527a2c9 merged onto main 077ce40.

  • gpu_cube_sample_grad_matches_face_texture fails at the 2D precondition (2 of 2).
  • Lanes 0/12/24/36 all read 2.09375 for both the cube and the 2D reference.

For comparison, the RTX 4080 on the same machine passes all three tests, with the 2D reference at 0.78125 / 1.65625 / 1.0761719 / 0.80566406 and the cube equal to it on those lanes. So the precondition holds there and not on any AMD driver tried so far.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.

@upipibi upipibi mentioned this pull request Nov 24, 2026
@AkshatPal2007
AkshatPal2007 force-pushed the codex/cube-sample-gradients branch from 527a2c9 to 1ec845b Compare November 24, 2026 10:45
AkshatPal2007 added a commit to AkshatPal2007/xcl that referenced this pull request Nov 24, 2026
Project both explicit face-space gradients into direction space and use native anisotropic sampling for unclamped cube operations. Keep the scalar LOD path for clamped cube operations after reports of AMD driver access violations in PR xcl-dev#778.

Exercise four anisotropic footprints with point-sampled texel and slice controls, filter all twelve cube edges, and check clamp behavior on a fully initialized four-mip cubemap.

Assisted-by: Codex (gpt-6.2-astra and gpt-6.2-sol)
AkshatPal2007 added a commit to AkshatPal2007/xcl that referenced this pull request Nov 24, 2026
Project both explicit face-space gradients into direction space for native anisotropic filtering. Keep the upstream scalar LOD path for clamped cube samples after AMD driver access violations reported on PR xcl-dev#778.

Check cube and 2D gradient samples against point-sampled controls. Cover all twelve cube edges and verify the scalar clamp on a four-mip texture.

Assisted-by: Codex (gpt-6.2-astra and gpt-6.2-sol)
@AkshatPal2007
AkshatPal2007 force-pushed the codex/cube-sample-gradients branch from 1ec845b to 1921924 Compare November 24, 2026 10:52
@AkshatPal2007

Copy link
Copy Markdown
Author

Thanks everyone for the feedback! Updated PR head to 1921924 with changes addressing the AMD test failures and driver crash.

Local tests: 738 passed, 0 failed, 41 ignored (2 wave64 skips counted as passes).

Could someone with AMD hardware retest the latest revision? Retail smoke tests are still pending.

@Toons29

Toons29 commented Nov 24, 2026 •

Copy link
Copy Markdown

Retest of 1921924 on AMD, as asked: the crash is gone, and gpu_cube_sample_grad_matches_face_texture still fails, now at a later check.

Tested

  • 1921924 merged into main 47efa2e (clean merge), debug
  • AMD Radeon RX 9070 (RDNA4, native wave64, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0 (stable MSVC)
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 743 passed, 1 failed, 41 ignored, 0 GPU tests SKIPPED
new test 527a2c9 on main 077ce40 1921924 on main 47efa2e
whole suite lib test process crashed (0xC0000005) in gpu_cube_sample_grad_min_lod, 2 of 2 reruns at --test-threads=1 no crash
gpu_cube_sample_grad_matches_face_texture, alone (--exact) failed 8 of 8: the reference must resolve the two footprint directions (tests.rs:2355) failed 8 of 8: lane 0: cube 0.6480392, 2D face 0.18431373 (tests.rs:2378)
gpu_cube_sample_grad_edges, alone passed 5 of 5 passed 5 of 5
gpu_cube_sample_grad_min_lod, alone not reached (crash) passed 5 of 5

The lane 0 values were the same in all 9 runs of 1921924 (the suite run and the 8 alone).

Not tested

  • No regression run (scripts/smoke.ps1): I have no retail title.
  • NVIDIA / wave32-only GPUs.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds and tests and drafted this report on the machine above; I checked each point against the logs before posting.

Game run

Regression run of 556300f4 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: 556300f4ecfa4bf507d9ec9e5f8df6e03b085d85
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1628 (PresentX 1628)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14692 MB

Against the limits in CONTRIBUTING.md: 101 % of main's frames, 99 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

Project face-space gradients into direction space for native anisotropic filtering. Keep the upstream scalar LOD path for clamped samples after AMD driver access violations in PR xcl-dev#778.

Compare translated samples to independently projected native cubemap samples rather than assuming that cube and 2D array filtering footprints agree on every driver. Keep the seam, point sampling, and minimum-LOD checks.

Assisted-by: Codex (gpt-6.2-astra and gpt-6.2-sol)
@AkshatPal2007

Copy link
Copy Markdown
Author

Could someone with AMD hardware retest the latest revision?

@JJAutoCompare

Copy link
Copy Markdown

Independent Intel Arc A770 test of #778 (fixes #767)

Tested

  • Clean, detached PR head 556300f4ecfa4bf507d9ec9e5f8df6e03b085d85, verified against the open PR. Intel Arc A770 driver 32.0.101.9175, Ryzen 7 3800X, Windows 11 Enterprise Evaluation 26200.9974, Rust 1.100.0 (x86_64-pc-windows-msvc), DXC/DXIL 1.9.2609.5 (DXC 01b62ad4). Set XCL_ADAPTER=A770 and pointed XCL_DXC_DIR at that DXC installation. Used the unoptimized test profile with debug info and incremental compilation disabled and two Cargo build jobs.
  • Prebuilt with cargo test --locked -p xcl --lib gpu_cube --no-run. Ran L:/XclTooling/pr1844-71f2ceb-t3-737e5ee5/target/debug/build/xcl/77aca8ccb20e299f/out/xcl-77aca8ccb20e299f.exe gpu::recomp::tests::gpu_cube --test-threads=1 --nocapture under the Arc GPU lock.
  • 4 passed, 0 failed, 0 ignored, 0 GPU skips (742 filtered out). gpu_cube_array_slices checked face and slice selection and resource info. gpu_cube_sample_grad_matches_native_cube matched the native D3D12 cube reference for horizontal, vertical and diagonal anisotropic footprints across all six faces in two cubes, with off-center point samples checking orientation. gpu_cube_sample_grad_edges checked linear filtering from both incident faces of all 12 edges. gpu_cube_sample_grad_min_lod checked gradient-selected mip levels and minimum LOD in a draw with pixel readback.
  • These fixtures used HLSL → DXIL via DXC on D3D12. The translated compute kernels used split wave64 and the anisotropy reference used a 32-lane HLSL wave. The mip test ran through the graphics path.

Not tested

  • AMD retest, NVIDIA, native wave64, direct DXIL emission, retail rendering or smoke, and the workspace suite. This run adds Intel coverage for the checked-in synthetic cases.

AI use

  • Codex (gpt-6.2-sol) in T3 Code ran the tests and wrote this report from the logs.

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.

Recompiler: preserve the texture footprint for cubemap samples with explicit gradients

10 participants