Skip to content

Translator: --native-rounding for AMD's own Floor/Ceil/Fract - #4064

Open
DaniSBR1 wants to merge 2 commits into
ItsNotRexed:mainfrom
DaniSBR1:pr-native-rounding
Open

DaniSBR1 wants to merge 2 commits into
ItsNotRexed:mainfrom
DaniSBR1:pr-native-rounding

Conversation

@DaniSBR1

@DaniSBR1 DaniSBR1 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

New SHADER item, claimed in #3918 (claim). Depends on: none. Related: #3299 (cs_round_f32_denorm, the GPU test for these ops on denormals).

What and why

v_floor_f32, v_ceil_f32 and v_fract_f32 go through Gen.round_f32_flushed, which gives RDNA2's results on any driver:

  • a denormal operand reads as a zero of its sign;
  • Fract's round-up to 1.0 becomes 0x3f7fffff;
  • NaNs pass through unchanged, signalling ones too;
  • fract(±inf) is 0xffc00000.

That is right everywhere, but on an RX 5700 XT it costs about six instructions per v_fract, and it keeps the driver from folding them. A pixel shader of 2,000 random fma/mul/add/min/max/fract ops takes 1.71 ms, against 0.33 ms for the same program written as native SPIR-V. Without fract the two are equal.

On AMD the driver's own Floor/Ceil/Fract compile to v_floor_f32/v_ceil_f32/v_fract_f32, so they already give those words. --native-rounding translates the three ops as the plain GLSL functions:

  • It is opt-in: make_game.py --native-rounding forwards it like the other translator flags and records it beside the translation.
  • LEONIDA_NATIVE_ROUNDING=1 turns it on for build.py/check.py and run_gpu_tests.py. The checks keep the same RDNA2 words, so a run says whether a driver's functions match the hardware.
  • f16 ops are unchanged.
  • docs/design.md gets a sentence in the min/max/med3/v_fract row, and docs/testing.md a short section.

Results

RX 5700 XT (RDNA1), RADV Mesa 26.0.8, main aa2988c:

default --native-rounding
Probe: 16 operands × the three ops in compute (denormals of both signs, -1e-10 and -1e-7 that round up, ±0, ±inf, quiet and signalling NaNs, 1e30, ordinary values) the RDNA2 words 48/48 the same words
The same 16 operands through v_fract_f32 in a pixel shader 16/16 the same
AMD's Windows driver (Adrenalin 26.11.2, same RX 5700 XT): the probe, and run_gpu_tests.py with and without LEONIDA_NATIVE_ROUNDING=1 48/48 and 16/16; both GPU runs 185/210, identical line for line, ps_fnan_fract passes
run_gpu_tests.py 184/210, 25 skipped the same results per test (ps_fnan_fract passes)
build.py + check.py 175/184 175/184, the same per test
#3299's cs_round_f32_denorm (gfx1036-measured words), its branch with this change pass pass
Pixel shader, 2000 ops with fract (native SPIR-V: 0.33 ms) 1.71 ms, 3947 instructions 0.53 ms, 1219 instructions; bit-identical image
fract-only pixel shader (native: 0.045 ms) 0.53 ms 0.045 ms
unittest discover -s tests/semantic 7458 run; the only failures are the 9 that fail on main aa2988c too (test_loop_ballot_barrier emulate cases, test_cmp_class_f64, test_mutations)

The one failure in both GPU runs is cs_signed_zero_nan, the known Mesa NIR issue from #166.

On llvmpipe, 10 of the 48 compute words differ under the flag: denormals through all three ops, Fract's round-up to 1.0, and signalling NaNs that get quieted. ps_fnan_fract and cs_round_f32_denorm fail there, while they pass without it. That is why the flag is opt-in. A later make_game.py "auto" could turn it on for AMD GPUs once AMD's Windows driver and other RADV generations are checked; the GPU tests with LEONIDA_NATIVE_ROUNDING=1 are the check.

New test: tests/semantic/test_native_rounding.py. With the flag the module holds only the GLSL function (no NaN, infinity or 0x3f7fffff constants in the body). On ordinary operands both translations give the same words in the interpreter.

AI-assisted (Claude Code): code, tests and this description. The tests ran on my own RX 5700 XT.

Tested f01af63 (on main aa2988c) on AMD Radeon RX 5700 XT (RDNA1, Navi 10), RADV Mesa 26.0.8-1ubuntu0.3, Vulkan 1.4.335, Ubuntu 26.04.1 (kernel 7.0.0-42), LLVM 21: pass

🤖 Generated with Claude Code

@Kam471 Kam471 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.

Ran this at 192ab970 on Windows 11: python tests/semantic/test_native_rounding.py -> 2 tests, OK; compileall and git diff --check clean.

The tests pin both halves: with the flag, the module contains exactly the GLSL Floor/Ceil/Fract per value and no 0x3f7fffff/NaN/infinity constants; without it, the exact round_f32_flushed path remains, and ordinary operands produce the same interpreted words. The flag is opt-in through --native-rounding, make_game.py and the GPU runner, and the help/docs say it is exact only where the driver lowers to the hardware instructions (AMD/RADV), not generally. No blocking issue.

@TheMrBeez

Copy link
Copy Markdown

The check the description asks for before an "auto" mode: AMD's Windows driver on RDNA2. Tested 192ab970 against the native instructions on gfx1036 (the Ryzen 9 9950X3D iGPU, AMD driver 32.0.21030.2001), and through the translator on that iGPU and on an RTX 5080 (driver 621.01).

Inputs. 65,536 f32 operands:

  • both signs × all 256 exponents × 128 mantissas;
  • the mantissas are pseudo-random, plus 0, 0x7fffff and 0x400000;
  • so the sweep covers every denormal and NaN class, ±inf, ±0, and the tiny negatives whose fract rounds up.

Each operand goes through v_floor_f32, v_ceil_f32 and v_fract_f32, giving 196,608 result words.

Native reference (raw tools/hw_oracle kernels):

  • With the game's MODE (ieee = 0, denorm32 = 0), every NaN passes through unchanged, signalling ones included, as the description says.
  • With the oracle's default MODE (IEEE on), the hardware quiets the 126 signalling-NaN operands (0x7fbc6ef3 → 0x7ffc6ef3).
  • Those 126 are the only differences between the two modes.
  • Everything below is compared with the game-MODE words.
translation RTX 5080 Radeon gfx1036, AMD Windows driver
default 196,608 / 196,608 196,608 / 196,608
--native-rounding floor 65,156, ceil 65,156, fract 52,098 (of 65,536 each) 196,608 / 196,608

So on AMD's Windows driver for RDNA2, the driver's own Floor/Ceil/Fract give the RDNA2 word for every operand in this sweep:

  • denormals read as zero of their sign;
  • fract's round-up stays at 0x3f7fffff;
  • signalling NaNs pass through unchanged;
  • fract(±inf) = 0xffc00000.

That is one more driver beside your RADV result.

The 5080 differences are the cases the flag exists for, the same kinds you list for llvmpipe:

  • fract returns 1.0 for all 13,056 negative operands in the sweep with |x| ≤ 2⁻²⁵, the 127 negative denormals included (0x80800000 → 0x3f800000 where RDNA2 gives 0x3f7fffff);
  • positive denormals aren't flushed either (ceil(0x007fffff) = 1.0, fract keeps the denormal);
  • NaNs come back as 0x7fffffff, and so does fract(±inf).

Keeping it opt-in, or AMD-only for an "auto" mode, fits this.

run_gpu_tests.py on the gfx1036 (AMD Windows driver), without and with LEONIDA_NATIVE_ROUNDING=1:

Also: tests/semantic/test_native_rounding.py 2 OK, and spirv-val is clean for both translations.

Windows 11, Vulkan SDK 1.4.363, llvm-mc AMD LLVM 23.0.0git. Synthetic operands only, no game files. The sweep script is local. AI-assisted (Claude Code).

@Flyander Flyander 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.

Reviewed at 192ab97 and independently ran the focused test file on Windows: 2/2 passed. The option is explicit and opt-in; the exact RDNA2 path remains the default, while the help and docs identify the native driver behavior as AMD-specific.

@ricardotanaka

Copy link
Copy Markdown

Tested 192ab970 (merged onto main aa2988cc) on AMD Radeon RX 7600 (RDNA3, Navi 33), AMD Windows driver 26.11.2 (LLPC, Vulkan 1.4.359), Windows 11 26200.9457, MSVC 19.44 RelWithDebInfo, llvm-mc 23.1.6: pass, and the flag changes no result here. One more AMD generation on AMD's own Windows driver, next to @TheMrBeez's RDNA2 and the RDNA1/RADV in the description.

default LEONIDA_NATIVE_ROUNDING=1
build.py 234 translated, 234 pass spirv-val the same
check.py 181 of 184 pass, 3 skipped the same, line for line (184 of 184 identical)
run_gpu_tests.py 196/210 passed, 14 skipped the same, test for test (209 result lines identical)
ps_fnan_fract 4096/4096 pixels exact 4096/4096 pixels exact

tests/semantic/test_native_rounding.py (through unittest discover): 2 OK.

Not covered: the denormal and round-up-to-1.0 cases. On main the suite only reaches them through #3299's cs_round_f32_denorm, and #3299 conflicts with main now, so I couldn't run it beside this branch. What this run shows for RDNA3 is the NaN path (ps_fnan_fract) and that no other fixture moves under the flag; it isn't the 65,536-operand sweep TheMrBeez ran on RDNA2.

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

@iurysf

iurysf commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Code read of 192ab970 (GPU results from @TheMrBeez and the reviews above not repeated). Ran on Windows 11, Python 3.14, llvm-mc 23.1.6: test_native_rounding.py 2 OK, make_game.py --help lists the flag; with main's tools/rdna2spirv.py the new tests error (6). Mutation check: forcing if NATIVE_ROUNDING: to False or True is caught, but changing NATIVE_ROUNDING = a.native_rounding to False in main() is not, because the tests set the module global directly; nothing checks that the command-line option reaches the generator. build.py with LEONIDA_NATIVE_ROUNDING=1 does change the output (ps_fnan_fract: 489 lines instead of 506, both pass spirv-val), so the environment path works. A small test that runs the CLI with --native-rounding and compares with the default output would pin the plumbing.
AI-assisted code read (Claude).

DaniSBR1 added a commit to DaniSBR1/Leonida that referenced this pull request Nov 22, 2026
The other tests set rdna2spirv.NATIVE_ROUNDING directly, so dropping the assignment from the command line in
main() went unnoticed (@iurysf's mutation check in ItsNotRexed#4064). This one runs rdna2spirv.py as a process with and
without the option and checks that only the default keeps the 0x3f7fffff clamp.

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

Copy link
Copy Markdown
Contributor Author

Two updates.

  1. A correction to the probe behind the first table rows. Its plain mode replaced only Fract, so Floor and Ceil went through the exact code in both runs, and their 32 words matched by construction. The Windows run below caught it. With all three ops plain, the RX 5700 XT on RADV still gives 48/48 in compute and 16/16 in the pixel shader. llvmpipe now differs on 10 of 48: Floor and Ceil of denormals and signalling NaNs too. I've corrected that row of the description. The GPU checks were never affected: ps_fnan_fract and Tests: GPU check for v_floor/ceil/fract_f32 and v_cvt_flr_i32_f32 of a denormal (TEST-515) #3299's cs_round_f32_denorm ran with the real --native-rounding, which covers all three ops.

  2. AMD's Windows driver, same RX 5700 XT (Adrenalin 26.11.2, Vulkan 1.4.315, main aa2988c): the corrected probe gives 48/48 and 16/16. run_gpu_tests.py on this branch, with and without LEONIDA_NATIVE_ROUNDING=1, gives 185/210, 25 skipped, 0 failed both times, identical line for line, and ps_fnan_fract passes (4096/4096 pixels). So both AMD drivers I can test give the hardware's words through plain Floor/Ceil/Fract. A make_game.py auto mode for AMD could follow once an RDNA2/3 card on RADV is checked too.

  3. @iurysf, good catch on the plumbing. The new commit adds test_the_command_line_option_reaches_the_translator, which runs rdna2spirv.py as a process with and without --native-rounding. With NATIVE_ROUNDING = a.native_rounding changed to False in main(), it now fails.

Thanks @TheMrBeez for the 65,536-operand sweep on RDNA2 with AMD's Windows driver, and @ricardotanaka for RDNA3.

AI-assisted (Claude Code); the runs are on my own RX 5700 XT.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested f01af63 merged onto main 03b09a0 on an RTX 5090 (driver 616.92), Windows 11, Vulkan SDK 1.4.363. The GPU test programs were built from the same tree:

  • scripts/run_gpu_tests.py: 164/210 passed, 46 skipped, 0 failed. main 03b09a0 gives 164/210, 46 skipped, 0 failed. All 214 test shaders translate and pass spirv-val.
  • tests/semantic/test_native_rounding.py: ran 3 tests in 0.958s; OK.

AI-assisted (Claude Code).

DaniSBR1 and others added 2 commits November 23, 2026 00:02
v_floor_f32, v_ceil_f32 and v_fract_f32 go through Gen.round_f32_flushed, which gives RDNA2's results for denormal
operands, Fract's round-up to 1.0, NaNs and infinities on any driver. That costs about six instructions per
v_fract on an RX 5700 XT and keeps the driver from folding them: a pixel shader of 2000 ops with v_fract among them
takes 1.71 ms against 0.33 ms for the same program in native SPIR-V.

On AMD the driver's own Floor/Ceil/Fract are the hardware instructions, so they already give those words. With
--native-rounding (opt-in; make_game.py --native-rounding, LEONIDA_NATIVE_ROUNDING=1 for the GPU test runners) the
three ops are plain GLSL Floor/Ceil/Fract. On an RX 5700 XT (RADV, Mesa 26.0.8):
- 48 of 48 edge-case words in compute (16 operands: denormals of both signs, -1e-10 and -1e-7 that round up,
  +-0, +-inf, quiet and signalling NaNs, large and ordinary values, through each op) and 16 of 16 v_fract words in
  a pixel shader equal the default translation;
- run_gpu_tests.py and check.py match the default per test (ps_fnan_fract passes), and so does ItsNotRexed#3299's
  cs_round_f32_denorm (gfx1036-measured words);
- the 2000-op shader goes from 1.71 ms to 0.53 ms, a v_fract-only one from 0.53 ms to 0.045 ms (= native).
On llvmpipe 5 of the 16 compute words differ, and ps_fnan_fract and cs_round_f32_denorm fail under the flag, which is
why it stays opt-in.

tests/semantic/test_native_rounding.py checks that the flag leaves only the GLSL function in the module and the
same words on ordinary operands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The other tests set rdna2spirv.NATIVE_ROUNDING directly, so dropping the assignment from the command line in
main() went unnoticed (@iurysf's mutation check in ItsNotRexed#4064). This one runs rdna2spirv.py as a process with and
without the option and checks that only the default keeps the 0x3f7fffff clamp.

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

Copy link
Copy Markdown
Contributor Author

Rebased onto main d974c88. The conflicts were in tools/rdna2spirv.py, scripts/run_gpu_tests.py and runtime/test/shaders/build.py, all next to the new --fma exact. Both options are kept side by side. round_f32_flushed still has the one caller (v_floor_f32/v_ceil_f32/v_fract_f32), so the change covers the same three ops.

Re-tested on the RX 5700 XT (AMD Adrenalin 26.11.2, Windows 11):

  • Probe: the 16 operands through the three ops in compute give 48/48 RDNA2 words, and 16/16 through v_fract_f32 in a pixel shader.
  • run_gpu_tests.py with and without LEONIDA_NATIVE_ROUNDING=1: both 191/217 with 26 skipped and no failures. The two runs are identical line for line, and ps_fnan_fract passes (4096/4096 pixels).
  • tests/semantic/test_native_rounding.py, the docs tests and tests/test_make_game_translator_flags.py pass.
  • unittest discover -s tests/semantic: 6248 run. The only failures are 5 emulate cases in test_loop_ballot_barrier, which fail the same way on main d974c88 without this change.

AI-assisted (Claude Code).

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 4e1a550b02d3833f5e529f00df9c96356a716dea on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

At 4e1a550b on Linux RTX 5090, the synthetic ps_fnan_fract fixture passed with default rounding (4,096/4,096 pixels exact). With LEONIDA_NATIVE_ROUNDING=1, all 4,096 pixels mismatched and the runner exited 1. At (0,0) the first word was 0x3f800000 (1.0), where the fixture expects 0x3f7fffff (the preceding float32 value). The other three words at that pixel matched. Both modes passed SPIR-V validation.

This verifies the default path for this fixture and shows why the native flag needs device-specific validation.

AI-assisted verification.

@tunczzz

tunczzz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 4e1a550b (merge base d974c88a) on an NVIDIA GeForce RTX 5070 Ti (Blackwell, subgroup 32..32), driver 616.56, Windows 11 10.0.26300. Runtime test programs were built from main 3faac557 (MSVC 19.44); llvm-mc 21 came from WSL Ubuntu. Result: pass, with the documented NVIDIA difference under the flag.

  • Default scripts/run_gpu_tests.py: 170/217 passed, 47 skipped, 0 failed. Test by test it is identical to main 3faac557 on the same build, so the default path is unchanged.
  • LEONIDA_NATIVE_ROUNDING=1: 169/217 passed, 47 skipped, 1 failed. Only ps_fnan_fract fails, on all 4096 pixels: the first word is 0x3f800000 (1.0) where 0x3f7fffff is wanted, so NVIDIA's Fract of a tiny negative value rounds up to 1.0 where RDNA2 doesn't. docs/testing.md in this PR says this is expected off AMD, and @tylerstraub saw the same on an RTX 5090 under Linux. main with the same variable set passes all 170, because it ignores the flag. Every other test matches.

Not run: LEONIDA_W64_EMULATE=1, an AMD GPU (the case the flag is for). No game files.

AI-assisted (Claude Code).

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 4e1a550 on Intel UHD 630 (CFL GT2, subgroup 8..32), Mesa 25.2.8 ANV, Ubuntu 24.04, LEONIDA_VK_DEVICE=Intel: no change with or without the flag.

  • Full build, then scripts/run_gpu_tests.py: 154/217 passed, 61 skipped, both by default and with LEONIDA_NATIVE_ROUNDING=1; the per-test lines are identical apart from temp paths. Both fail cs_fmt_int_narrow and cs_signed_zero_nan, which main 3faac55 also fails on this machine with the same 154/217.
  • ps_fnan_fract: PASS, 4096/4096 pixels exact, in both modes.
  • runtime/test/shaders/build.py with and without the flag: of 253 outputs, only spirv/ps_fnan_fract.spv and its .spvasm differ.
  • check.py: 141 of 188 pass, 45 skipped, in both modes.
  • tests/semantic test_native_rounding: Ran 3 tests, OK.

AI-assisted.

@ricardotanaka

Copy link
Copy Markdown

Re-tested the rebased head 4e1a550b (my earlier check above was on 192ab970) merged onto main 3faac557, on the same AMD Radeon RX 7600 (RDNA3), AMD 26.11.2, Windows 11 26200, MSVC 19.44: pass, and the flag still changes no result here. The other checks on this head are NVIDIA and Intel; this is AMD's own driver, where the flag is meant to be used.

default LEONIDA_NATIVE_ROUNDING=1
build.py 242 translated, 242 pass spirv-val the same
check.py 185 of 188 pass, 3 skipped the same, line for line
run_gpu_tests.py 202/217 passed, 15 skipped the same, test for test (217 result lines identical)
ps_fnan_fract 4096/4096 pixels exact 4096/4096 pixels exact

The flag did reach the translation: of the 242 .spv files build.py wrote in each mode, only ps_fnan_fract's differs. test_native_rounding.py: OK.

Still not covered here: the denormal and round-up-to-1.0 cases (#3299's cs_round_f32_denorm is not on main and #3299 conflicts with main).

AI-assisted (Claude Code).

@KkelebekK

Copy link
Copy Markdown

Tested 4e1a550b (merge base d974c88a; merges cleanly into main 3faac557) on AMD Radeon 780M (RADV PHOENIX, gfx1103 / RDNA3, Mesa 26.2.6) and NVIDIA GeForce RTX 4070 Laptop (620.70.06), CachyOS Linux 7.3.4, Python 3.14.10, llvm-mc 23.1.4: pass for the default path; concern for the claim that the flag is exact on AMD (RDNA3 RADV differs on denormals and signalling NaNs).

  • Default path, full run_gpu_tests.py: 780M 202/217 passed, 15 skipped; 4070 170/217, 47 skipped; 4070 with LEONIDA_W64_EMULATE=1 201/217, 16 skipped. 0 failed, the same counts as main 3faac557 here.
  • LEONIDA_NATIVE_ROUNDING=1, full suite: 780M 202/217, 15 skipped, identical per test to the default run (ps_fnan_fract passes, 4096/4096 pixels). 4070 169/217 with one failure, ps_fnan_fract on 4096/4096 pixels (first pixel 0x3f800000 where 0x3f7fffff is wanted, i.e. Fract rounds up to 1.0); 4070 with W64 emulation 200/217, the same single failure. That is the NVIDIA difference docs/testing.md says to expect. No other result differs from the default run.
  • Independent probe (synthetic compute shader, thread 0, run through vk_compute_test): 16 operands (both-sign denormals incl. 0x007fffff, -1e-10, -1e-7, ±0, ±inf, quiet and signalling NaN, 1e30, ±1.25, 3.75) through v_floor_f32, v_ceil_f32, v_fract_f32 = 48 words, compared with a numpy model of the rules in docs/design.md (a denormal operand reads as a zero of its sign; fract rounds once and gives 0x3f7fffff where that is 1.0; fract(±inf) = 0xffc00000; NaNs pass unchanged, fract(±0) = +0). The model is mine, not hardware.
    • Default translation: 0 of 48 words differ, on both GPUs.
    • --native-rounding on the 780M: 7 of 48 differ: floor(-denormal) gives -1.0 for 0x80000001 and 0x807fffff; ceil(+denormal) 0x00000001 gives 0x1 (not +0); fract(-denormal) gives 1.0 for 0x80000001 and 0x807fffff; floor and fract of the signalling NaN 0x7fa00000 come back quieted (0x7fe00000).
    • --native-rounding on the 4070: 17 of 48 differ (denormals, NaNs, fract(±inf) = 0x7fffffff, fract(-1e-10) = 1.0).
      So on an RDNA3 iGPU under Mesa 26.2.6 the native functions are not the RDNA2 words for denormal operands or signalling NaNs, while the PR text and the docs/design.md row say they are exact on AMD (measured on RX 5700 XT, RADV 26.0.8, and a Windows RDNA2 and RDNA3 card for the fixtures). ps_fnan_fract does not exercise those operands (it passes here), so the fixture run alone would not show it. Suggest naming the generations and drivers that were measured, and keeping the flag opt-in. I did not run a pixel-shader version of the probe.
  • Python: tests/semantic/test_native_rounding.py, tests/test_make_game_translator_flags.py, tests/test_run_gpu_tests.py, tests/test_shader_build_fallbacks.py, tests/test_docs_*.py: 104 passed, 70 subtests passed; the same 104 on the merged tree. The new test file on the merge base's translator: 7 failed, 2 passed (the flag does not exist there).
  • No runtime C++ changes; I reused the runtime/build/linux build of af70fc78 (its vk_* test programs are unchanged between af70fc78 and main 3faac557).

Not run: RDNA1/RDNA2 hardware, AMD's Windows driver, the speed claim (1.71 ms to 0.53 ms), W64 emulation on the 780M.

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

@kapitche

Copy link
Copy Markdown
Contributor

Tested 4e1a550 merged with main 3faac55 on Linux (WSL2), Python 3.12.16: pass (with one test not runnable here).
tests/semantic/test_native_rounding.py: 3 run; 2 pass. test_the_command_line_option_reaches_the_translator errors here only because spirv-as is not installed on this machine (the translator exits 2 with 'spirv-as not found'); with that subprocess output inspected, the setup is otherwise as expected. That test does not skip when spirv-as is missing, which may be worth a skipUnless. 10 test_docs_.py, 22 test_make_game_.py, test_run_gpu_tests*.py, test_shader_build_fallbacks.py pass.
Negative control: with rdna2spirv.py, make_game.py, build.py and run_gpu_tests.py from main, all 3 tests fail/error (7 errors across subtests).
GPU claims (exact on RADV) not checked.

@bunbeans2-arch

Copy link
Copy Markdown

RDNA4 on AMD's Windows driver, the case an "auto on AMD" mode would need: AMD Radeon RX 9070 XT (gfx1201), AMD 26.10.1 (32.0.32015.7029, driverVersion 2.0.416), Windows 11, PR head 4e1a550b.

The 65,536-operand layout @TheMrBeez used (both signs x 256 exponents x 128 mantissas, incl. 0, 0x7fffff, 0x400000), each operand through v_floor_f32, v_ceil_f32 and v_fract_f32, translated by this head with and without --native-rounding:

op same words differ
floor 65,410 / 65,536 126
ceil 65,410 / 65,536 126
fract 65,410 / 65,536 126

All 378 differences are the 126 signalling-NaN operands. Under the flag, this driver's Floor/Ceil/Fract quiet them (0x7fbc6ef3 -> 0x7ffc6ef3, 0x7fa00000 -> 0x7fe00000); the default translation keeps them unchanged, as the RDNA2 Windows run above does.

Everything else gives the RDNA2 words under the flag: denormals of both signs, fract's round-up (-1e-10 -> 0x3f7fffff), ±0, ±inf (fract -> 0xffc00000) and quiet NaNs. Against the rules in round_f32_flushed (16 operands, 48 words): default 48/48, native 45/48 (the three sNaN words).

So on RDNA4 with this driver the flag is exact except for signalling NaNs, unlike the RDNA2 run on AMD's Windows driver. An AMD "auto" would need to exclude gfx12 or accept quieted sNaNs. Not tested:

  • whether gfx1201 hardware itself passes sNaNs with IEEE mode off (no hw_oracle kernel run);
  • the 26.11.x drivers;
  • the speed claim.

Synthetic operands only. AI-assisted (Claude Code). No game files.

@bunbeans2-arch

Copy link
Copy Markdown

Follow-up on the RDNA4 signalling-NaN difference above: it comes from the hardware, not the driver.

Native tools/hw_oracle kernels on the same RX 9070 XT (gfx1201), f32 denormals flushed: v_floor_f32, v_ceil_f32 and v_fract_f32 quiet every signalling NaN (0x7fa00000 -> 0x7fe00000, 0x7fbc6ef3 -> 0x7ffc6ef3, 0xffa00000 -> 0xffe00000). These are the same words the driver's Floor/Ceil/Fract give under --native-rounding.

Unlike gfx1036 (which passes sNaNs with the game's ieee=0), I found no MODE setting on gfx1201 that keeps them:

  • .amdhsa_ieee_mode is rejected for gfx1201 (see tools/hw_oracle/asm.py).
  • MODE reads back 0x000000c0, and s_setreg of bit 9 (the IEEE bit on gfx10/11) to 0 changes no word.

I did not check gfx12's MODE layout against a spec.

So on RDNA4, --native-rounding matches RDNA4's own hardware; only the default translation keeps RDNA2's sNaN pass-through.

Synthetic operands only. AI-assisted (Claude Code). No game files.

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.