Repository navigation
Conversation
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>
Kam471
left a comment
There was a problem hiding this comment.
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.
|
The check the description asks for before an "auto" mode: AMD's Windows driver on RDNA2. Tested Inputs. 65,536 f32 operands:
Each operand goes through Native reference (raw
So on AMD's Windows driver for RDNA2, the driver's own
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:
Keeping it opt-in, or AMD-only for an "auto" mode, fits this.
Also: 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
left a comment
There was a problem hiding this comment.
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.
|
Tested
Not covered: the denormal and round-up-to-1.0 cases. On No game files. AI-assisted (Claude Code). |
|
Code read of |
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>
|
Two updates.
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. |
|
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:
AI-assisted (Claude Code). |
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_f32andv_fract_f32go throughGen.round_f32_flushed, which gives RDNA2's results on any driver: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/Fractcompile tov_floor_f32/v_ceil_f32/v_fract_f32, so they already give those words.--native-roundingtranslates the three ops as the plain GLSL functions:make_game.py --native-roundingforwards it like the other translator flags and records it beside the translation.LEONIDA_NATIVE_ROUNDING=1turns it on forbuild.py/check.pyandrun_gpu_tests.py. The checks keep the same RDNA2 words, so a run says whether a driver's functions match the hardware.docs/design.mdgets a sentence in the min/max/med3/v_fractrow, anddocs/testing.mda short section.Results
RX 5700 XT (RDNA1), RADV Mesa 26.0.8, main aa2988c:
--native-roundingv_fract_f32in a pixel shaderrun_gpu_tests.pywith and withoutLEONIDA_NATIVE_ROUNDING=1ps_fnan_fractpassesrun_gpu_tests.pyps_fnan_fractpasses)build.py+check.pycs_round_f32_denorm(gfx1036-measured words), its branch with this changeunittest discover -s tests/semantictest_loop_ballot_barrieremulate 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_fractandcs_round_f32_denormfail there, while they pass without it. That is why the flag is opt-in. A latermake_game.py"auto" could turn it on for AMD GPUs once AMD's Windows driver and other RADV generations are checked; the GPU tests withLEONIDA_NATIVE_ROUNDING=1are 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