Skip to content

rdna2spirv: --bias-minlod-grad samples _b_cl / _c_b_cl as Grad|MinLod on Intel's Windows driver (#7030) - #7719

Open
Tinto57 wants to merge 1 commit into
ItsNotRexed:mainfrom
Tinto57:intel-bias-minlod-grad
Open

Tinto57 wants to merge 1 commit into
ItsNotRexed:mainfrom
Tinto57:intel-bias-minlod-grad

Conversation

@Tinto57

@Tinto57 Tinto57 commented Nov 23, 2026

Copy link
Copy Markdown

Fixes #7030. Claim: #7694 (comment)

@ItsNotRexed

The bug

Intel's Windows Vulkan driver (101.9175, Arc 140V) drops the MinLod operand of an implicit-LOD sample that also carries a Bias: ps_texture_b_cl reads mip 0 on the right half where the clamp asks for mip 1. On the same driver MinLod alone (ps_texture_cl), Bias alone (ps_texture_bias_a16) and Grad|MinLod (ps_texture_grad_cl_a16) are right.

The fix

A translator fallback, --bias-minlod-grad. A pixel-shader image_sample_b_cl / image_sample_c_b_cl becomes OpImageSample(Dref)ExplicitLod with Grad|MinLod (Grad|Offset|MinLod for _o). The gradients are OpDPdx / OpDPdy of the spatial coordinates (not the array layer), times exp2(bias). Scaling the footprint by 2^bias adds bias to log2 of it, so the LOD and the anisotropy are those of the implicit sample. The sampler's own bias and LOD clamps apply to both forms alike. The one difference is the maxSamplerLodBias clamp on the shader bias, which Grad does not apply. texel_offset_fold already scales the derivatives the same way for --texel-offset-fallback.

A Grad sample is slower than an implicit one on some GPUs, so the translator does not use this form by default. It follows the --bary-fallback pattern from #6828:

  • tools/vk_subgroup_info.py reports bias_minlod_grad for driver ID 5 (VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS).
  • make_game.py, scripts/run_gpu_tests.py and runtime/test/shaders/build.py turn the flag on there. LEONIDA_BIAS_MINLOD_GRAD=1/0 overrides it.
  • make_game.py records it with the other fallback flags, so a change retranslates. It also keeps it when the probe can't answer, the same as the other flags.
  • The docs/design.md min-LOD row and the docs/testing.md troubleshooting table describe it.

Tested

Windows 11, CPU only. No Intel GPU here, so ps_texture_b_cl on an Arc is not tested. A run on an Arc under Intel's Windows driver with this branch would confirm it: python -I scripts/run_gpu_tests.py --build <build> --filter ps_texture_b_cl.

  • tests/semantic/test_sample_cl.py: new BiasMinLodGrad cases check the Grad|MinLod shape, that exp2 reads the bias VGPR and scales OpDPdx/OpDPdy of the sampled coordinate, the array layer having no derivative, Offset coming between Grad and MinLod, _c_b_cl, the other forms staying unchanged, and the flag being off by default. A spirv-val case runs where SPIRV-Tools are installed, as in CI. I had no SPIRV-Tools locally, so CI runs it.
  • tests/test_vk_subgroup_info.py, tests/test_make_game_translator_flags.py, tests/test_run_gpu_tests.py: the probe, the CLI and environment precedence, and the recorded flag order. The existing tests that mock the barycentric probe now mock this one too.
  • Translator suite (scripts/run_semantic_tests.py tests/semantic): 446 files and 5,958 tests. test_image_atomics_guard and test_image_store_d16 fail the same way on unmodified main.

No game data. AI-assisted (Claude Code).

🤖 Generated with Claude Code

… on Intel's Windows driver (ItsNotRexed#7030)

Intel's Windows Vulkan driver (101.9175, Arc 140V) drops the MinLod operand of an
implicit-LOD sample that also carries a Bias, so ps_texture_b_cl reads mip 0 on the
half where the clamp asks for mip 1. MinLod alone, Bias alone and Grad|MinLod are right
on the same driver.

With --bias-minlod-grad, a pixel-shader image_sample_b_cl / image_sample_c_b_cl becomes
OpImageSample(Dref)ExplicitLod Grad|MinLod (Grad|Offset|MinLod for _o), with the quad
derivatives of the spatial coordinates scaled by exp2(bias): the same LOD and anisotropy.
Grad samples are slower on some GPUs, so it is a fallback:

- tools/vk_subgroup_info.py reports bias_minlod_grad for driver ID 5 (Intel proprietary
  Windows);
- make_game.py, scripts/run_gpu_tests.py and runtime/test/shaders/build.py turn the flag
  on there, LEONIDA_BIAS_MINLOD_GRAD=1/0 overrides, and make_game records it with the
  other fallback flags.

Tests: tests/semantic/test_sample_cl.py (shape, bias source, array layer, offset order,
other forms unchanged), tests/test_vk_subgroup_info.py, tests/test_make_game_translator_flags.py,
tests/test_run_gpu_tests.py. Not run on Intel hardware.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@boesbo

boesbo commented Nov 23, 2026

Copy link
Copy Markdown

Independent Linux GPU comparison at ad05b5b. On Bazzite 44 I pinned each 64-bit Vulkan ICD in turn and verified the physical device in vk_texture_test’s output.

GPU Driver Fallback off Fallback on
NVIDIA RTX 4070 SUPER NVIDIA 615.78.08 4/4 pass 4/4 pass
AMD Ryzen 7 7700X integrated graphics (Raphael) RADV, Mesa 26.2.4 4/4 pass 4/4 pass

The target was ps_texture_b_cl, with ps_texture_cl, ps_texture_grad_cl_a16 and ps_texture_bias_a16 as controls. On each GPU, check.py’s per-pixel oracle passed all 4,096 pixels for each case. The separate raw readbacks matched byte for byte with the fallback on and off and across the two GPUs. On the target shader I confirmed the generated instruction changed from implicit LOD with Bias|MinLod to explicit LOD with Grad|MinLod.

I used build.py twice with LEONIDA_BIAS_MINLOD_GRAD=0/1. All five synthetic shaders in each build (including the shared vertex shader) passed spirv-val. The 17 test_sample_cl tests passed. Built in Fedora 44 with GCC 16.2.1, LLVM MC 22.1.8 and SPIRV-Tools v2026.1, then ran the native binary against the host drivers.

This establishes equivalent output for these fixtures on NVIDIA and RADV. The original Intel Arc 140V / Windows driver case in #7030 still needs a hardware run. No game data. AI-assisted with Codex.

@Inkotake

Copy link
Copy Markdown

Tested ad05b5b4c2272daab031769fe7e8722c9866ed54 on Intel Arc B390, Windows 11 Pro (26200), Intel 32.0.101.8860, Vulkan 1.4.348, subgroup 16..32, with binaries and tests from the same revision.

python -X utf8 -I scripts/run_gpu_tests.py --build <build> --filter ps_texture_ --assembler spirv-as --require-pass: 8/8 passed with auto-selection, including 4,096/4,096 pixels for ps_texture_b_cl. With LEONIDA_BIAS_MINLOD_GRAD=0 on the same PR head and harness, 7/8 passed; ps_texture_b_cl was again the sole failure (2,048/4,096 pixels differed). All 9 modules passed spirv-val both ways. Unpatched main dde82f27 showed the same wrong mip in default-native and wave64-emulated runs (#7030).

Synthetic project fixtures only. AI-assisted: yes (Codex).

@vicennpacheco

Copy link
Copy Markdown
Contributor

Tested ad05b5b4c on AMD Radeon Vega 8 iGPU (GCN 5 / gfx90c, PCI 1002:15E7, maxPushConstantsSize = 128, AMD Windows driver 31.0.21921.13001, Vulkan 1.3.260), Windows 11, llvm-mingw Clang 23.1.6 + Vulkan SDK 1.4.363.0 (spirv-val), llvm-mc 23.1.6, Python 3.14.3: pass (no Intel Arc GPU here, so this checks Windows AMD probe behaviour, spirv-val, and the tail-UBO path).

  • python -I tools/vk_subgroup_info.py: reports "barycentric_fallback": true, "bias_minlod_grad": false, "max_push_constants_size": 128, "driver_id": 1 (Intel-only flag stays off on AMD Windows).
  • Unit & semantic tests: test_vk_subgroup_info.py 54/54, test_make_game_argparse.py 36/36, test_make_game_translator_flags.py 35/35, test_run_gpu_tests.py 64/64, tests/semantic/test_sample_cl.py 17/17 OK (including test_bias_minlod_grad_modules_validate with spirv-val).
  • GPU (LEONIDA_PC_TAIL_UBO=1, harnesses rebuilt from ad05b5b4c): ps_texture_b_cl, ps_texture_cl, ps_texture_grad_cl_a16, ps_texture_bias_a16 all pass 4/4 (4096/4096 RGBA pixels matched) in run_gpu_tests.py and build.py/check.py both with LEONIDA_BIAS_MINLOD_GRAD unset/0 and forced =1.
  • spirv-dis on ps_texture_b_cl.spv confirms OpImageSampleImplicitLod ... Bias|MinLod when off and OpDPdx/OpDPdy/Exp2 + OpImageSampleExplicitLod ... Grad|MinLod when forced on.

Synthetic fixtures only, no game data. AI-assisted.

@Henergyque

Copy link
Copy Markdown

Tested ad05b5b (merged locally onto main dde82f2, no conflicts) on RTX 5060 Ti, NVIDIA 621.24, Windows 11 (26300): pass. No game files involved.

Runtime built from main with scripts/build_runtime.ps1 (MSVC, VS 2022); the PR doesn't touch runtime/ C++. Vulkan SDK 1.4.363.1, LLVM 21+ llvm-mc.

scripts/run_gpu_tests.py, full suite

run translated / spirv-val result
main dde82f2 (baseline) 247 / 247 192/241 passed, 48 skipped
this PR, default (probe says off on NVIDIA) 247 / 247 192/241 passed, 48 skipped
this PR, LEONIDA_BIAS_MINLOD_GRAD=1 (forced) 247 / 247 192/241 passed, 48 skipped

Per-test PASS/FAIL/SKIP status is identical across the three runs. The one failure, ms_wave_info_s3 (got -1.0 ×4, want 0.0078, 0.0078, 0.5, 1.0), is already there on main, so it's unrelated to this PR.

ps_texture_b_cl, ps_texture_cl, ps_texture_bias_a16, ps_texture_grad_a16 and ps_texture_grad_cl_a16 pass in all three runs.

Checked that the fallback really kicks in (--filter ps_texture_b_cl --work <dir>, then read the .spvasm):

  • flag 0: OpImageSampleImplicitLod ... Bias|MinLod, PASS (4096 RGBA pixels matched)
  • flag 1: OpImageSampleExplicitLod ... Grad|MinLod, PASS (4096 RGBA pixels matched)

So on NVIDIA the exp2(bias)-scaled Grad|MinLod form gives the same result as the implicit Bias|MinLod sample. An Arc on Intel's Windows driver is still needed to confirm the actual fix.

The PR's CPU tests pass too: tests/semantic/test_sample_cl.py (17), test_make_game_argparse (36), test_make_game_translator_flags (35), test_run_gpu_tests (64), test_vk_subgroup_info (54).

Run with an AI assistant (Claude Code).

@Impre-visible

Copy link
Copy Markdown

Tested ad05b5b on NVIDIA GeForce GTX 1660 (Turing, TU116, subgroup 32..32), driver 620.73.04 (proprietary, Vulkan 1.4.357), Arch Linux (kernel 6.18): pass, no regression.

Native build of runtime/ from this head (Ninja, RelWithDebInfo, clang 23.1.5), llvm-mc 23.1.5, SPIRV-Tools v2026.4.

  • spirv-val on the modules the PR's semantic tests translate (test_sample_cl.py): distinct modules: 19, pass spirv-val: 19, rejected: 0
  • tests/semantic: 5958 OK
  • build.py: 269 shaders, 269 translated, 269 pass spirv-val; check.py: 176 of 211 pass, 35 skipped (wave64 without emulation, mesh fixtures)
  • run_gpu_tests.py: 191/240 passed, 48 skipped, 0 failed
  • LEONIDA_W64_EMULATE=1 run_gpu_tests.py: 222/240 passed, 17 skipped, 0 failed

AI-assisted run (Claude). Synthetic programs only, no game files involved.

@airp1ane

Copy link
Copy Markdown
Contributor

Tested ad05b5b on Windows 11, Python 3.15.2, NVIDIA RTX 4060 Ti (driver 621.24; CPU-only checks, no game files, no GPU/llvm-mc/MSVC used): pass.

Ran the test files this PR adds or changes, from a clean checkout of the PR head: test_make_game_argparse.py, test_make_game_translator_flags.py, test_run_gpu_tests.py, test_vk_subgroup_info.py - all exit 0. The translator semantic suite was not run for this PR.

AI-assisted (Claude Code).

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.

ps_texture_b_cl fails on Intel Arc 140V (Windows 101.9175): OpImageSampleImplicitLod Bias|MinLod drops MinLod clamp

7 participants