Skip to content

BUILD-1447: root-cause --bary-fallback PS deltas and fix %bary half-slot collision - #8987

Open
FelipeGFA wants to merge 1 commit into
ItsNotRexed:mainfrom
FelipeGFA:fix/build-1447-bary-f16-root-cause
Open

FelipeGFA wants to merge 1 commit into
ItsNotRexed:mainfrom
FelipeGFA:fix/build-1447-bary-f16-root-cause

Conversation

@FelipeGFA

Copy link
Copy Markdown

Claimed in the coordination issue as: BUILD-1447 (#8047 (comment))

What and why

  • Root-causes the #4847 ps_sweep differences between the default and fallback translations on all 480 sampled PS (--seed 20261122, variant z, main dde82f27e) and across all 12,101 PS on an AMD Radeon RX 6650 XT:
    • 29 of 12,101 PS declare MinLod (image_sample_d_cl, 273 occurrences), and 0 of the 480 sampled PS use MinLod, so the MinLod fallback plays no part in this 480-shader difference.
    • Across the 480 sampled PS, 272 modules are byte-identical across default, --bary-fallback, and --bary-fallback --f16-interp-fallback, 10 are refused (computed I/J pair under --bary-fallback), and 198 differ (186 v_interp_*_f16 all using high, 12 raw barycentrics needing .bary_gs.spv, 0 combining both in the sample).
    • Under --bary-fallback alone, all 63 differing/NaN/zero draws (54 beyond tolerance: 53 gross >0.1, 1 moderate >1e-2; 8 NaN on default only; 1 zero on default only) are v_interp_*_f16 shaders: the default sweep VS without f16_halves writes [0, 1] smooth f32 outputs that default unpacks per vertex via PerVertexKHR UnpackHalf2x16 into negative or large f16 values (feeding sqrt/log/pow), whereas --bary-fallback alone reads the positive smooth f32 values directly.
    • Re-running the same 198 shaders with --bary-fallback --f16-interp-fallback gives 153/153 completing draws (141 v_interp_*_f16 + 12 raw-bary GS, 573/573 targets) bit-for-bit identical against default (ps_sweep.py compare --exact), with 0 differences and 0 NaN/zero mismatches (12 driver crashes on both 0xC0000005 unchanged with an 8 MiB stack, 33 timeouts). All 3/5 translatable whole-corpus PS combining raw barycentrics and v_interp_*_f16 also match default bit-for-bit (3/3 draws, 11/11 targets) on the RX 6650 XT.
  • Fixes %bary input location allocation in tools/rdna2spirv.py (assemble()) to skip occupied = used | reserved instead of used alone, preventing %bary from colliding with an unread reserved f16_halves producer slot when combining --bary-fallback and --f16-interp-fallback.
  • Adds synthetic regression tests in tests/semantic/test_bary_fallback.py (BaryAndF16FallbackInteraction) covering --bary-fallback divergence vs --bary-fallback --f16-interp-fallback equivalence, %bary slot avoidance past unread reserved f16_halves slots (29 -> 30), and combined raw-barycentric + f16 interpolation with .bary_gs.spv validation.
  • Documents the RX 6650 XT measurements and combined fallback support in docs/shader_validation.md and docs/design.md.

Tested

  • GPU & driver: AMD Radeon RX 6650 XT (RDNA2), Windows 11, driver 32.0.21045.29003, Vulkan SDK 1.4.363.1 (SPIRV-Tools v2026.4).
  • ps_sweep on the RX 6650 XT (480 sampled PS, 198 differing modules, variant z, --timeout 30):
    • default vs --bary-fallback alone: 90 OK on both (12 GS + 78 f16), 54 differ (53 gross, 1 moderate), 9 NaN/zero on default only (8 NaN, 1 zero), 12 fail on both (0xC0000005), 33 timeout.
    • default vs --bary-fallback --f16-interp-fallback: 153 OK on both (141 f16 + 12 GS), 0 differ, 0 NaN/zero mismatch, 12 fail on both, 33 timeout; 153/153 completing draws (89 non-clear exact + 64 clear-only exact across 573/573 targets) bit-exact under ps_sweep.py compare --exact.
    • Whole-corpus combined raw barycentrics + v_interp_*_f16: 3/3 draws (11/11 targets) bit-exact on the RX 6650 XT (2/5 refused for computed I/J pair under --bary-fallback).
  • Translator + spirv-val counts before vs after (SPIRV-Tools v2026.4):
    • --limit 200 slice (default): before 200 translated / 200 spirv-val-valid; after 200 translated / 200 spirv-val-valid (0 regressions).
    • --limit 200 slice (--bary-fallback --f16-interp-fallback): after 200 translated / 200 spirv-val-valid (0 regressions).
    • Whole-corpus combined raw-bary + v_interp_*_f16 subset (5 shaders): before 3 translated / 3 spirv-val-valid (2 refused); after 3 translated / 3 spirv-val-valid (2 refused), 0 regressions.
  • Automated tests & checks:
    • Negative control: temporarily reverting occupied to used in tools/rdna2spirv.py caused test_bary_location_avoids_unread_reserved_f16_half_slot to fail with AssertionError: {'location': 29} != {'location': 30}.
    • Post-final-edit checks:
      • python -m compileall -q make_game.py tools tests (exit 0)
      • python -m unittest discover -s tests/semantic -p test_bary_fallback.py -v (15 tests, OK, spirv-as/spirv-val active, 0 skipped)
      • python -m unittest discover -s tests/semantic -p test_f16_interp_fallback.py -v (15 tests, OK)
      • python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_bary_fallback.py docs/shader_validation.md docs/design.md (exit 0)
    • Pre-helper-extraction checks (after all translator and doc edits):
      • test_interp_p1lv_f16.py (36/36), test_interp_f16_high.py (5/5), tests/test_ps_sweep.py (23, 3 skipped).
      • tests/test_docs_cli_flags.py & tests/test_docs_design_rows.py: 8 passed, edited files clean (the 2 remaining failures are pre-existing on main in docs/embedded_shaders.md and docs/README.md).
      • python -I scripts/run_semantic_tests.py tests/semantic: 447 files, 5960 tests (444 passed; 3 pre-existing unrelated main failures: test_image_atomics_guard, test_image_cube_store_glc, test_image_store_d16).

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

@catminou4

Copy link
Copy Markdown

Tested on Apple M1 Max, macOS 27.2.1 arm64, MoltenVK 1.4.2: pass (with a platform caveat).

  • python -m unittest test_bary_fallback → 15/15 OK on ARM64.
  • GPU run_gpu_tests.py --filter bary → ps_bary PASS (4096/4096), ps_persp_bary PASS (perspective-correct) — native PerVertexKHR path unaffected.
  • Caveat: the fixed collision needs both --bary-fallback and --f16-interp-fallback active. MoltenVK has native barycentrics (barycentric_fallback: false) and no geometryShader, so the GS-fed fallback path cannot run here — ps_ij_computed skips. The occupied = used | reserved fix is verified by the semantic file; on-GPU confirmation of the dual-fallback path remains for RADV/NVIDIA.

No game files. AI-assisted (Devin).

@abnalstlll-byte abnalstlll-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Windows review (commit \e3edd59a185fcec8f652db23f67c8f5e00739e2a)

What changed:

  • \ ools/rdna2spirv.py:
    • Resolves location collision where \gen.bary_location\ assigned slot numbers already reserved by \ 16_half_locs.
    • Fixes the allocation check to compute \occupied = used | reserved, preventing collisions between %bary\ and reserved 16-bit half slots.
  • \docs/shader_validation.md:
    • Documents the barycentric coordinate allocation contract and root-cause analysis for BUILD-1447.
  • \ ests/semantic/test_bary_fallback.py:
    • Adds regression test suite for half-slot barycentric location assignment.

Verification:

  • Ran \python -I -m unittest discover -s tests/semantic -p test_bary_fallback.py: 15/15 OK.
  • Pure standard library / Python, clean git diff, zero game files.

Ready for merge.

@WALID1618Y

Copy link
Copy Markdown
Contributor

Tested e3edd59a1 on NVIDIA GeForce RTX 3050 (driver 621.24 / 32.0.16.2124, Vulkan 1.4.357, Windows x64, Python 3.13.14): pass

Environment notes: pre-built runtime-windows CI binaries from e68c5c9c9 (tools/rdna2spirv.py unchanged between e68c5c9c9 and 867d922f0), --assembler python (tools/spirv_asm.py), --disasm-dir tests/semantic/fixtures/disasm (no llvm-mc), spirv-val skipped (--no-validate). Synthetic/fixture shaders only, no game files. AI-assisted.

Semantic tests:

  • Red-before (LEONIDA_TOOLS_DIR -> base tools/): python -m unittest discover -s tests/semantic -p test_bary_fallback.py -v -> Ran 15 tests, FAILED (failures=1, skipped=1) (test_bary_location_avoids_unread_reserved_f16_half_slot: AssertionError: {'location': 29} != {'location': 30})
  • Green-after (e3edd59a1): python -m unittest discover -s tests/semantic -p test_bary_fallback.py -v -> Ran 15 tests, OK (skipped=1) (spirv-val not on PATH)

RTX 3050 GPU runs (e3edd59a1):

  • Native scripts/run_gpu_tests.py --build runtime-windows --disasm-dir tests/semantic/fixtures/disasm --assembler python --filter bary --require-pass: 1/1 passed (ps_bary: 4096/4096 pixels match)
  • Direct --bary-fallback --f16-interp-fallback RTX 3050 draw: translated ps_bary.s with rdna2spirv.py --bary-fallback --f16-interp-fallback --assembler python --no-validate, generated its helper GS via bary_fallback_gs._helpers_for_index and assembled with tools/spirv_asm.py (note bary_fallback_gs.build_for_index currently invokes spirv-as directly), and drew via vk_harness.exe (VKH_GS_HELPER=1) -> bary_loc=1, 4096/4096 pixels match (run_gpu_tests.check_bary).

@comtek21516

Copy link
Copy Markdown

Tested e3edd59a1 merged onto main at 867d922f0 on Quadro RTX 4000 (Turing, subgroup 32..32), NVIDIA 615.71.09, Ubuntu 22.04.5 (kernel 5.15), g++ 13.4, llvm-mc 21.1.8, Vulkan SDK 1.4.363.1, Python 3.12.16: pass, on the native path and with the fallback forced.

  • tests/semantic/test_bary_fallback.py: 15 tests, OK.
  • scripts/run_gpu_tests.py, default (this GPU has VK_KHR_fragment_shader_barycentric, so pixel shaders take the native path): 192/241 passed, 48 skipped, 1 failed. With LEONIDA_W64_EMULATE=1: 223/241 passed, 17 skipped, 1 failed.
  • The same suite with LEONIDA_BARY_FALLBACK=1, so the runner translates with --bary-fallback and draws through tools/bary_fallback_gs.py: 189/241 passed, 51 skipped, 1 failed, on main and with this PR alike. The three extra skips are ms_f16_pack, ps_ij_computed and ps_interp_f16_high.

All three runs are test by test the same as main; the one failure is ms_wave_info_s3, which fails on main here as well (#8306; #8608 fixes it on this GPU).

What this does not show: none of the hand-written fixtures changed its result under the fallback, so the %bary half-slot collision the PR fixes is not something these fixtures hit on this GPU, before or after. The run confirms that nothing regresses; the fix itself rests on the PR's CPU test. No game files. 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.

5 participants