Skip to content

Top 10 GTA VI Betrayals (#11 will shock you): 11 RDNA2 ops the translator refused - #1976

Open
IAmNotSiob wants to merge 22 commits into
ItsNotRexed:mainfrom
IAmNotSiob:top-10-gta-vi-betrayals
Open

IAmNotSiob wants to merge 22 commits into
ItsNotRexed:mainfrom
IAmNotSiob:top-10-gta-vi-betrayals

Conversation

@IAmNotSiob

@IAmNotSiob IAmNotSiob commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

claimed in #1745. tools/isa_coverage.py lists 246 RDNA2 instructions with no translator rule. these 11 are the ones that are plain ALU, still Unsupported on main (checked by translating each), and not in an open PR (the v_dot* ones are #1808's).

the list

# instruction what it does now
10 v_add_nc_i16 mine main now has it (#2029), so this PR uses main's and keeps only the test
9 v_sub_nc_i16 same, main's now
8 v_sat_pk_u8_i16 each signed 16-bit half clamped to [0, 255], packed into the low 16 bits
7 v_cvt_norm_i16_f16 f16 -> snorm16, same rule as main's v_cvt_pknorm_i16_f32 (clamp, ×32767, round to nearest even, NaN -> 0), low half, op_sel kept
6 v_cvt_norm_u16_f16 f16 -> unorm16, ×65535
5 v_cvt_pknorm_i16_f16 two f16 -> packed snorm16
4 v_cvt_pknorm_u16_f16 two f16 -> packed unorm16
3 v_fma_legacy_f32 fused multiply-add where 0 × anything (inf/NaN too) is 0, like the existing v_mad_legacy_f32 but with no flush and one rounding
2 v_fmac_legacy_f32 its VOP2 form, D as the addend
1 v_fmaak_f16 S0*S1 + K, through the existing single-rounded v_fma_f16 path
11 (shocking) v_fmamk_f16 S0*K + S1, same. print order matches v_fma_f32's fmaak/fmamk handling

clamp/omod on the norm conversions and op_sel destination on the clamped i16 add/sub are refused, not guessed, as the neighbouring ops do.

tested

  • tests/semantic/test_top10_betrayals.py (new): every op against a plain-Python reference over edge values (±0, ±1, ±inf, NaN, 0x7fff/0x8000 overflow, an f16 denormal, fma cancellations). all OK, and each fails on main with Unsupported
  • tests/semantic full suite: OK
  • isa_coverage.py with AMD's RDNA2 XML: handled-exact 476 -> 487, unknown 246 -> 235

no GPU run (none of these touch the runtime). no game files.


TL;DR: 11 RDNA2 instructions the shader translator used to refuse now translate, each checked against a reference, so ISA coverage goes up 11. the title is clickbait, the code isn't. AI-assisted (Claude Code).


also in here (draft: collecting more wins before review)

d3d12_subgroup_test never built without the Vulkan SDK on PATH. its shader-generation step was the only one not given LEONIDA_SPIRV_TOOLS, so build.py's spirv-as call failed and stopped ninja. it now gets the tools path like the M1.5–M5 blocks, and is gated on spirv-as/spirv-val like them. Windows 10 VM + RTX 6000 Ada: d3d12_subgroup builds and passes, full ctest 116/116.

DXGI GetFullscreenState now reports what SetFullscreenState set (M7, alt-tab). measured on host DXGI (Win10 22H2, flip-discard): SetFullscreenState(TRUE) -> GetFullscreenState TRUE, FALSE -> FALSE; the layer always said FALSE. same probe: a minimised flip-model window still gets S_OK from Present (not DXGI_STATUS_OCCLUDED), so that part already matched and is left alone. dxgi_swapchain_test gets the round-trip and passes in a desktop session.

15 f64 instructions (more of the isa_coverage unknown list; v_mul_f64/v_fma_f64 are the ones #503's review noted were missing): v_mul_f64, v_fma_f64, v_min_f64, v_max_f64, v_ldexp_f64, v_floor_f64, v_ceil_f64, v_trunc_f64, v_rndne_f64, v_fract_f64, v_cvt_f64_f32, v_cvt_f64_i32, v_cvt_f64_u32, v_cvt_i32_f64, v_cvt_u32_f64. same conventions as their f32 siblings and v_add_f64: f64 -> int truncates and saturates with NaN -> 0, fract keeps results below 1.0, clamp/omod through clamp_mods_f64; refused (not guessed) under a non-default MODE rounding.

  • the semantic interpreter has no doubles, so these are checked on a GPU: 17 generated compute shaders over edge inputs (±0, denormals, 1e308 overflow, NaN, fused-vs-unfused cancellations, ldexp into a denormal) on NVIDIA RTX 6000 Ada (615.71, Linux), all bit-exact against an exact-arithmetic Python reference (integral results keep the operand's sign: ceil(-0.75) is -0)
  • new GPU fixture cs_w32_f64_ops (8 words: fma, ldexp to the smallest denormal, both saturating conversions, ceil's -0, fract's below-one clamp), registered in check.py and run_gpu_tests.py: PASS
  • run_gpu_tests.py full run: the same 12 failures as on main with the same (older) harness build, none new; pytest tests/test_shader_checks.py tests/test_run_gpu_tests.py 92 passed

isa_coverage on this branch (merged with current main): handled-exact 510, unknown 212 (476 and 246 on the main this PR started from).

self-review before undrafting

TL;DR: 26 RDNA2 instructions the translator refused now translate (11 integer/f16 checked on the CPU, 15 f64 checked bit-exact on a GPU, with a new GPU fixture). also a build fix that makes d3d12_subgroup_test actually build without the SDK on PATH, and GetFullscreenState now matching host DXGI. ISA coverage 476 -> 510. AI-assisted (Claude Code).

…, f16 norm conversions, fma_legacy, f16 fmaak/fmamk)
@Youssefrah16

Copy link
Copy Markdown

Tested 1c448ad7 on AMD Radeon 680M (gfx1035, RDNA2, Windows 11 10.0.26300, driver 26.5.1 / amdhip64_6.dll): pass (AI-assisted).

  • python -I tests/semantic/test_top10_betrayals.py -v: 5/5 OK
  • Native RDNA2 gfx1035 silicon spot-check via tools/hw_oracle (destination preloaded 0x5a5a5a5a): 7/7 bit-exact match between translator and gfx1035 hardware on v_add_nc_i16 (wrap & clamp), v_sub_nc_i16 (clamp), v_sat_pk_u8_i16 (clamped 0xff00 & in-range 0x4210), v_cvt_norm_i16_f16, and v_cvt_norm_u16_f16 (untouched high half 0x5a5a preserved).

@Impre-visible

Copy link
Copy Markdown

Tested 99c2651 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_top10_betrayals.py): distinct modules: 934, pass spirv-val: 934, rejected: 0
  • tests/semantic: 1676 OK
  • build.py: 199 shaders, 199 translated, 199 pass spirv-val; check.py: 125 of 160 pass, 35 skipped (wave64 without emulation, mesh fixtures)
  • run_gpu_tests.py: 185 shaders: 185 translated, 185 pass spirv-val; 136/180 passed, 44 skipped, 0 failed
  • LEONIDA_W64_EMULATE=1 run_gpu_tests.py: 167/180 passed, 13 skipped (12 fixtures run by the d3d12 tests, 1 needs a 64-wide fragment subgroup), 0 failed

The PR adds no GPU fixture, so the 11 ops are covered only by the semantic tests here.

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

@IAmNotSiob

Copy link
Copy Markdown
Contributor Author

thx @Youssefrah16 @Impre-visible :D

fyi pushed 916f904: packed v_cvt_pknorm_*_f16 now honours the op_sel dst bit (result << 16, as Vonsek measured on gfx1036), test added.

@IAmNotSiob

Copy link
Copy Markdown
Contributor Author

merged main again; main now has its own hw-verified v_cvt_norm_*_f16 (6958558), so i dropped those two from this pr and kept only the packed pknorm f16 forms. tests green ^^

@kapitche

Copy link
Copy Markdown
Contributor

Tested 3caf7a6 merged with main 98fa503 (merged tree 2a0b88dc1d) on Windows 11, RTX 4080 SUPER + Intel UHD 770 (MSVC 14.51), Python 3.13.1: pass. Rebuilt the runtime from the merged tree (C++ changed).

  • scripts/run_gpu_tests.py, per-case diff against main's run: NVIDIA 171/218 passed, 47 skipped, 0 failed (main 170/217, 47, 0); the only difference is the new cs_w32_f64_ops PASS. Intel 150/218 passed, 68 skipped, 0 failed (main 150/217, 67, 0); the only difference is the new cs_w32_f64_ops, a SKIP ("no shaderFloat64 on this device").
  • Full ctest on NVIDIA: 173 run, 0 failed (the rest are skips on this machine). dxgi_swapchain and dxgi_swapchain_count pass on both GPUs.
  • tests/semantic/test_top10_betrayals.py 7 OK, test_alu_f64_hw.py 2 OK, tests/test_run_gpu_tests.py 41 OK.
  • Control: main's tools/rdna2spirv.py with the PR's suite: cs_w32_f64_ops fails with "missing .spv (translation failed)". Main's dxgi_com.cpp with the PR's dxgi_swapchain_test: fails on both GPUs with "GetFullscreenState should report SetFullscreenState(TRUE)".
  • The new GPU case does not discriminate on Intel UHD 770 (no shaderFloat64, so it skips); the f64 results were checked on NVIDIA only.

@Ayinaki

Ayinaki commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 68d225a on RTX 5070, driver 616.86, Windows 10.0.26200: pass.

Built runtime with MSVC 14.52 (Visual Studio 18 2026, x64, RelWithDebInfo) and ran dxgi_swapchain_test with LEONIDA_VK_DEVICE="RTX 5070"; it exits 0 and reports PASS over CreateSwapChain, CreateSwapChainForHwnd, CreateSwapChainForCoreWindow and the rest of its scenarios, with the device line naming the RTX 5070.

The translator side (tests/semantic/test_top10_betrayals.py, the new cs_w32_f64_ops.asm fixture and run_gpu_tests.py) was not exercised by this run — only the C++ target this PR changes.

@lines9686-rgb

Copy link
Copy Markdown
Contributor

Tested 68d225a on NVIDIA GeForce RTX 3060 Ti (Ampere), driver 610.88, Vulkan 1.4.341, Windows 11 (26200): pass.

Test programs built from this commit (MSVC from VS 2026 + Ninja, including its runtime changes); llvm-mc 23.1.6 (conda-forge llvm-tools); SPIRV-Tools from Vulkan SDK 1.4.357.0.

run_gpu_tests.py native LEONIDA_W64_EMULATE=1
--filter f64 4 translated, 4 pass spirv-val, 4/4 PASS 4/4 PASS
--filter cs_w32 14 translated, 14 pass spirv-val, 14/14 PASS 14/14 PASS
  • cs_w32_f64_ops: PASS, 1202590843 1070889697 1 0 2147483647 0 2147483648 1072693247; cs_f64_add, ps_f64_mods, ps_f64_round (4096/4096 exact) also pass.
  • tests/semantic test_*f64*.py: 817 tests OK.

This adds Ampere to the RTX 5070 run on this head. No game files. AI-assisted (Claude Code).

@abilliontokens

Copy link
Copy Markdown
Contributor

Tested 68d225ad963a8c66ccd3ec4f701f40225dd7479f on NVIDIA GeForce RTX 5060 Ti (621.24, Windows 11): pass.

Worktree at the PR head, runtime built with scripts/build_runtime.ps1 (MSVC 14.44, RelWithDebInfo), Vulkan pinned to the RTX 5060 Ti (driver 621.24.0.0, Vulkan 1.4.357), LLVM_MC=C:/Users/james/AppData/Local/Leonida/llvm-mc/llvm-mc.exe.

Commands and results:

python -I tests/semantic/test_top10_betrayals.py     -> Ran 7 tests, OK
python -I -m compileall -q make_game.py tools tests  -> exit 0
python -I scripts/run_gpu_tests.py --filter f64_ops
  -> 1 shaders: 1 translated, 1 pass spirv-val
  -> PASS cs_w32_f64_ops (8 words exact)
python -I scripts/run_gpu_tests.py                   -> full synthetic GPU suite
  -> 171/218 passed, 47 skipped, 0 failed

The 47 skips are the usual device-dependent ones on a 32-lane-subgroup RTX 50 part (64-wide wave64/fragment-subgroup cases and the package/SDL-gated entries). Synthetic fixtures only, no game files.

@illusionart453-max illusionart453-max left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Independent review of the subgroup CMake fix only, commit 99c26513 carried by current head 68d225ad. Applied that unchanged commit to my local main 3faac557 + open-PR integration tree; I am not claiming a review of the other translator/DXGI changes in this PR.

Windows 11 build 26200, MSVC 19.44, Visual Studio generator, RelWithDebInfo; native AMDGPU llvm-mc 23.1.6 and SDK 1.4.363.0 tools configured by absolute CMake paths, spirv-as/spirv-val absent from PATH:

  • Without the fix: d3d12_subgroup_test fails in rdna2spirv.assemble_spirv with FileNotFoundError for spirv-as. The sibling M1.5/M2/M3/M4/buffer-UAV targets build in the same setup.
  • With your unchanged CMake hunk: forced regeneration of all four subgroup shader variants succeeds; each translates and passes spirv-val without adding the SDK to the caller's PATH.
  • With SPIR-V tools unavailable at configure time: the subgroup target is omitted with the documented dependency message. Restoring the configured tool paths registers it again. This verifies the added tool guard as well as the environment forwarding.
  • ctest -R '^d3d12_subgroup$' passes on RTX 5060 / NVIDIA 610.88 with Khronos validation and synchronization validation enabled. The seven other newly available translated-shader checks also pass in this local tree.

No new competing PR from me: this exact fix is already yours. For integration with #3279, retain both this LEONIDA_SPIRV_TOOLS environment entry and its LEONIDA_PC_TAIL_UBO entry in the shader-generation command.

AI-assisted (Codex). Synthetic inputs only; no game files.

@DenRakEiw

Copy link
Copy Markdown
Contributor

Independent hardware review of 68d225ad963a8c66ccd3ec4f701f40225dd7479f merged cleanly onto main (3faac557) on Windows 11 x64 (Python 3.12.10, SPIRV-Tools v2026.4 / Vulkan SDK 1.4.363.0, llvm-mc 21 via WSL Ubuntu-24.04): pass.

  • Merge & diff: git merge --no-commit --no-ff onto 3faac557 succeeded cleanly; git diff --check clean.
  • Semantic & unit tests:
    • python -I -m unittest discover -s tests/semantic -p test_top10_betrayals.py -v: 7/7 OK
    • python -I -m unittest discover -s tests/semantic -p test_alu_f64_hw.py -v: 2/2 OK
    • python -I -m unittest discover -s tests/semantic -p "test_*f64*.py": 817/817 OK
    • python -I tests/test_run_gpu_tests.py -v: 41/41 OK
  • Dual-GPU shader test (scripts/run_gpu_tests.py --filter f64_ops): 1 shaders: 1 translated, 1 pass spirv-val
    • NVIDIA GeForce RTX 5090 (driver 32.0.16.1088, LEONIDA_W64_EMULATE=1): PASS cs_w32_f64_ops (1202590843 1070889697 1 0 2147483647 0 2147483648 1072693247) — 1/1 passed
    • AMD Radeon(TM) Graphics RDNA2 iGPU (driver 31.0.22044.1, LEONIDA_VK_DEVICE=AMD): PASS cs_w32_f64_ops (1202590843 1070889697 1 0 2147483647 0 2147483648 1072693247) — 1/1 passed

Synthetic fixtures only; C++ runtime changes (dxgi_com.cpp, dxgi_swapchain_test.cpp, CMakeLists.txt) were not rebuilt in this pass.

AI-assisted (Gemini 4 Neon).

@IAmNotSiob

Copy link
Copy Markdown
Contributor Author

merged main again: main now has its own hw-verified v_ldexp_f64 (bit-exact, integer-only) and v_cvt_f64_i32/u32, so i dropped those from this pr; the -floor(-x) ceil fix still applies on main's rounding block. f64 tests green ^^

@iurysf

iurysf commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Found with a local f64 differential fuzzer (tools/f64_diff.py from #4536 plus extra references on a local branch, not published): a 32-bit literal operand of v_min_f64 / v_max_f64 (and v_mul_f64 / v_fma_f64 in directed probes) is read as the low half of the f64 instead of the high half. Example: v_min_f64 v[8:9], 0xe8c2d219, 1.5 gives e8c2d219 00000000 instead of 00000000 e8c2d219. Same on the CPU interpreter and on an RTX 4070 (driver 621.01, Windows 11); the v_add_f64 control matches.

Tested at 68d225a (head alone): 19/27 mismatches on CPU seeds 1/2 and 19 on GPU seed 1 (--ops v_mul_f64,v_min_f64,v_max_f64,v_fma_f64,v_cvt_f64_f32 --programs 300), all min/max with a literal; without literals the same programs are 166/0 (CPU) and 229/0 (GPU).

Cause: tools/shader_ir.py:195-202 only sets f64_literal for v_add_f64, v_cvt_f32_f64, rcp/rsq/sqrt, frexp and trunc/ceil/rndne/floor, so rd64 zero-extends the literal for the new ops. Adding v_mul_f64, v_fma_f64, v_min_f64 and v_max_f64 to that tuple (in memory only) gives 171/0 on the CPU and 228/0 on the GPU. The current head ccdec63 (merge of main) does not change that list; I checked the code there but did not re-run.

AI-assisted (OpenBot team).

…2_f64 is the high half (found by @iurysf); test_valu_cvt_int_f64 runs the conversions instead of pinning them Unsupported
@speed-y

speed-y commented Nov 23, 2026

Copy link
Copy Markdown

Tested on NVIDIA GeForce RTX 5080, driver 621.24, Windows 11 (10.0.26200), Vulkan device API 1.4.357: pass

Checked out PR head 2404f9d65eec6b60ec54c6adfd14ae6b1073f1c9. VS 2022 / Ninja RelWithDebInfo. AI-assisted.

Check Result
unittest discover -s tests/semantic -p test_top10_betrayals.py 8/8 OK
est_alu_f64_hw.py 2/2 OK
est_valu_cvt_int_f64.py 3/3 OK

|
un_gpu_tests.py --filter cs_w32_f64_ops | PASS (1/1) |
| ctest dxgi_swapchain | PASS |
| ctest d3d12_subgroup | PASS |

@itaskaev2

Copy link
Copy Markdown

Tested 2404f9d6 (contains main 561b65a8) on Windows 11, NVIDIA GeForce RTX 4080 SUPER (Ada), driver 616.92, MSVC 14.51, Vulkan SDK 1.4.363, llvm-mc 23.1.4, RelWithDebInfo: pass. This is a native Windows run of the new f64 fixture, next to the RTX 6000 Ada / Linux one. AI-assisted (Claude Code), no game files.

  • The runtime builds.
  • pytest tests/semantic/test_top10_betrayals.py tests/semantic/test_valu_cvt_int_f64.py tests/semantic/test_alu_f64_hw.py tests/test_run_gpu_tests.py: 61 passed, 580 subtests passed.
  • scripts/run_gpu_tests.py: 184/233 passed, 48 skipped, 1 failed. The f64 rows: cs_w32_f64_ops PASS (1202590843 1070889697 1 0 2147483647 0 2147483648 1072693247), cs_f64_add PASS, ps_f64_mods and ps_f64_round both 4096/4096 exact.
    • The one failure is ms_wave_info_s3 (got (-1,-1,-1,-1), want (0.0078,0.0078,0.5,1.0)). It fails the same way on plain main 561b65a8 on this GPU, so it does not come from this PR.
  • dxgi_swapchain_test in a desktop session: PASS, 0 validation errors. This includes the GetFullscreenState round-trip.

@DeSunShine

Copy link
Copy Markdown

Two bits from my closed duplicate #6229 (commit DeSunShine/Leonida@4afd70682) that this PR doesn't have, in case they're useful here:

  • tests/spirv_interp.py: OpConvertSToF / OpConvertUToF to a 64-bit float currently round through f32, and OpFConvert isn't executed. The fix is 6 lines (int and f32 → double exact, f64 → f32 round-to-nearest-even).
  • A v_fma_f64 cancellation probe that tells a fused Fma from a split one: fma(a, a, c) with a = 1 + 2^-30, c = -(1 + 2^-29) is exactly 2^-60 (high word 0x3c300000) with one rounding and 0 with two (runtime/test/shaders/ps_f64_alu.asm, word 0). 0.1 * 0.2 + 0.3 in cs_w32_f64_ops gives the same result either way.

Happy to send either as a follow-up PR on top of this one once it lands. AI-assisted (Claude Code).

@sh1shu1

sh1shu1 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 2404f9d on NVIDIA RTX 4070 SUPER (driver 616.92), Windows 11 26200, MSVC 14.44, Vulkan SDK 1.4.363, RelWithDebInfo: pass, no regression against main 561b65a.

  • ctest: 243/247 passed; d3d12_indirect_dispatch_count, d3d12_indirect_rt, dxgi_device, dxgi_swapchain fails on main 561b65a too (not from this PR), same 11 skips as main 561b65a
  • dxgi_swapchain: 0/1
  • run_gpu_tests (LEONIDA_VK_VALIDATION=1): 184/233 native, 215/233 with LEONIDA_W64_EMULATE=1, 2 failed; ms_wave_info_s3 fails on main 561b65a too
  • window-based tests skip in this session (no interactive desktop)
    AI-assisted (Claude Code, Claude Fable 5.1).

# Conflicts:
#	runtime/test/shaders/check.py
#	scripts/run_gpu_tests.py
@DeSunShine

Copy link
Copy Markdown

Measured since my note above: on an RTX 4090 (NVIDIA 621.24, Windows) a binary64 GLSL.std.450 Fma rounds twice. The fma(a, a, c) probe (a = 1 + 2^-30, c = -(1 + 2^-29)) gives 0 instead of 2^-60, while OpFmaKHR %double gives the fused result. So v_fma_f64 as GLSL Fma here will be single-rounded only on drivers that fuse. #6635 adds Gen.emit_fma64 (OpFmaKHR %double under --fma khr, feature shaderFmaFloat64) for v_div_fmas_f64; once either PR lands, v_fma_f64 can go through it with a one-line change. AI-assisted (Claude Code).

@DeSunShine

Copy link
Copy Markdown

Tested be1dd3b1a merged into main 1cc6e3c12 on NVIDIA GeForce RTX 4090 (driver 621.24), Windows 11 Pro 26200, MSVC (VS Build Tools 18) + Ninja, Vulkan SDK 1.4.363, llvm-mc 23.1.6, Python 3.15: pass.

  • python -I scripts/run_gpu_tests.py (native): 187/236 passed, 48 skipped, only FAIL is ms_wave_info_s3 (known on main, ms_wave_info_s3 intermittently fails on RX 7900 XT / RADV NAVI31 (pass rate 100% -> 2.5%, same binaries) #6172).
  • LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py: 218/236 passed, 17 skipped, only FAIL is ms_wave_info_s3 (same as main).
  • --filter f64_ops (cs_w32_f64_ops): PASS, 8 words 1202590843 1070889697 1 0 2147483647 0 2147483648 1072693247.
  • python -m pytest -q tests/semantic/test_top10_betrayals.py tests/semantic/test_alu_f64_hw.py tests/semantic/test_valu_cvt_int_f64.py tests/test_run_gpu_tests.py: 63 passed, 580 subtests passed.
  • ctest -R "dxgi_swapchain|subgroup": 4/4 passed.

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.