Shaders: f16 arithmetic in native half on hosts with 16-bit operations (37x on an RTX 5070 Ti; for #2384) #2825
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2825
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2825"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@0xkn0wh3r3 on GitHub · 2026-11-25 21:33 UTC · original
0xkn0wh3r3:shader/native-f16→main· +918 −48 · 18 files · 5 commits · openFor #2384, following the measurement in #2806.
The translator does every console f16 operation in f32 and rounds each result to f16 in integer code (
Lower::narrow16, about 40 operations). #2806 measured that at 34x the host's ownhalf2math on an RTX 5070 Ti. This PR adds a native path behind a host capability check.What changes
emit::Options::native16(new). When it is set and the program rounds 16-bit results to nearest even (mode16isSome(0), orNone, whichnarrow16also rounds to nearest even), these become DXILhalfarithmetic:v_add/sub/subrev/mul_f16,v_fma/fmac_f16,v_min/max/min3/max3/med3_f16andv_pk_add/mul/fma/fmac/min/max_f16. Sources are read as bits: the abs/neg modifiers flip the sign bit, thentruncandbitcastgive ahalf. Results are bitcast back and written into the destination half as before. The -0/+0 order of min/max and the clamp (+0 for NaN and for -0, assemantics_testsmodels the console) are decided on the bits, not left to the host.mode16 == Some(3), which the title sets around its 16-bit interpolation) or toward an infinity; conversions (v_cvt_*, where the host's own conversion rounds as it likes); interpolation;v_mad/mac_f16(whether the console rounds the product is not settled; #1598);v_fma_mix*; and the transcendental and rounding operations.halftype in the bitcode writer, andUses::native16for any livehalfori16value. When it is set, the module gets the 16-bit data layout, the shader flagsLowPrecisionPresent | UseNativeLowPrecision, and SFI0's native 16-bit ops bit. A module without live 16-bit values is unchanged.host::native16()asks once. It requires three things: the device reportsNative16BitShaderOpsSupported(D3D12 OPTIONS4; SM 6.6 is required anyway); the device rounds a 16-bitFMadonce (Host::rounds_f16_fmad_oncedispatches #2384's case3c01·3e00+8001and expects3e01, run once at startup likefuses_fmad); andVICTORY_F16_IN_F32=1is not set. WARP has the ops but rounds theFMadtwice, so it keeps the f32 path. Since #1387, that path roundsv_fma_f16once itself. The answer goes into a newshader_cache::options()and into the cache key, so entries from one path are never served to the other (keytest). The check isvictory_shader::emit::host::Host::native16, shared with the tests, the same wayfuses_fmadis shared.victory translate's tally keeps the f32 path.--cachegoes throughhost_shaderand translates as the host does.emit/mod.rs.How the native results differ from the f32 path's
halfFMad, thennarrow16: rounded twice, 1 f16 ULP off where the f32 value lands on an f16 tie that the exact value is not onv_pk_fma_f16does0x7c01through, WARP gives0x7fff)So where the option is on, the native path is never further from the console than the f32 path, and closer for packed FMAs. Hosts whose 16-bit
FMadrounds twice (WARP) don't get the option.Tests (RTX 5070 Ti, driver 621.24, Windows 11)
All in
emit/semantics_tests.rs. The native tests run only on adapters that passHost::native16(): the hardware adapter here. WARP is refused and skips them.hosts_that_round_f16_fmad_twice_keep_the_f32_path: WARP fails the 16-bitFMadcheck and is refused. The RTX 5070 Ti passes.sixteen_bit_floats_match_the_hardware_natively: every 16-bit probe lowered natively, against the model. The existing f32-path tests still run unchanged on both adapters.fused_f16_results_round_once_natively(hardware adapter only): the probe inputs the f32 path rounds twice (F16_DOUBLE), #2384's three cases (3c01·3e00+8001 → 3e01,3c03·3e00+0001 → 3e05,3c01·3e00+be00 → 1600) throughv_fma_f16,v_fmac_f16andv_pk_fma_f16, and 8,192 random finite triples (denormals included). All match single rounding.native_f16_is_never_further_from_the_console: every 16-bit probe plus the 8,192 random FMAs, lowered both ways. Wherever the two results differ, the native one must be the model's. They differ on 1 input (a packed FMA), toward the model.f16_results_round_as_the_mode_says_natively: under the toward-zero mode the sum stays on the f32 path, and after going back to nearest even it is native.native_16bit_operations_are_declared_where_used: the SFI0 bit is set exactly for native arithmetic (not for conversions or toward-zero programs), and the module passes the validator.the_f16_fma_cases_round_once_in_the_model: CPU check of #2384's cases.The validator was dxil.dll 1.6 via
VICTORY_DXIL, because this machine's SDK has no x64 dxil.dll. As a control, the validator rejects the native modules if the 16-bit flags are dropped ("Bitcast on minprecison types is not allowed").Benchmark
translated_f16_math_costs(ignored;cargo test -p victory-shader --release --lib translated_f16_math -- --ignored --nocapture). It times translated console programs: dependent chains of 4,096 instructions, 262,144 threads, GPU timestamps around 10 back-to-back dispatches, best of five. Before is the f32 path, after is native:v_pk_fma_f16v_fma_f16(f32 path with #1387)v_mul_f16+v_add_f16With operands near 1, the two paths' final results were the same in every thread. Earlier figures here (37x, 23x and 21x, with 512-word chains) understated the work:
chaincounted encoding words, so the two VOP3/VOP3P chains held 256 instructions, and at that length a dispatch's fixed cost hid the arithmetic. Thanks to xndbogdan's RX 9070 XT ISA check for finding it.Other checks
cargo test -p victory-shader(rebased onf3578e3): 305 passed, 3 failed. The 3 failures and 1 crash (skipped) also happen on origin/main13f91caon this machine:heap_direct_texture_reads_mark_their_heap_indexcrashes with 0xc0000005, anda_heap_buffer_read_where_no_buffer_view_is_reads_zeros,a_heap_buffer_read_by_element_takes_the_views_strideandgathers_at_a_level_match_the_hardwarefail.cargo test -p victory-gpu: 226 passed, 2 failed. These are the two that already fail on main on this NVIDIA card:dynamic_slots_are_held_until_releasedandlists_share_a_table_and_copies_keep_their_views.cargo clippy --workspace --all-targets --locked -- -D warnings, with and without--all-features: clean.Not verified
halfFMA is expected to becomev_fma_f16and pass the check, but that is not measured. The startup check tests one case only. A host that rounds that case once but other cases differently would get the option wrongly.v_add_f16etc. are not known. The native path takes the host's payloads.VICTORY_F16_IN_F32=1turns it off.AI-assisted.
Since review
lower.rswent past the repository's 512 KiB source-file limit, which CI's policy check refused. The native-halfhelpers moved, unchanged, intolower/half.rs(905732a).aef37bb). The table above is re-measured.@fuzeofficlal on GitHub · 2026-11-25 21:48 UTC · original
Verified and benchmarked
bdc08a95on Windows 11 (RTX 5090 + WARP + Windows SDK10.0.26100.0dxil.dll):cargo xtask policy: 184 files ok;cargo clippy(victory-shaderdefault &--features host,victory-gpudefault &--features diagnostics,victory): 0 warnings.victory-shader(RTX 5090 + WARP +dxil.dll):sixteen_bit_floats2/2,f16_16/16 (1 ignored),native_3/3 (includingnative_16bit_operations_are_declared_where_usedviadxil.dllandfused_f16_results_round_once_natively),emit::lower::tests27/27.victory-gpushader_cache::tests: 3/3 on RTX 5090, 3/3 withVICTORY_F16_IN_F32=1, and 3/3 on WARP (VICTORY_D3D12_WARP=1).--releasebenchmark (translated_f16_math_costs, 262,144 threads × 512 ops, 2 runs; 262,144/262,144 threads match the f32 path):v_pk_fma_f16:0.108 ms (2481 G ops/s)->0.003 ms (85773 G ops/s)(34.6×); run 2:0.112 ms (2388 G)->0.003 ms (91479 G)(38.3×)v_fma_f16:0.052 ms (2603 G)->0.003 ms (44290 G)(17.0×); run 2:0.050 ms (2696 G)->0.003 ms (43645 G)(16.2×)v_mul_f16 + v_add_f16:0.136 ms (988 G)->0.010 ms (13026 G)(13.2×); run 2:0.105 ms (1283 G)->0.005 ms (26133 G)(20.4×)native16()gating, exactLOW_PRECISION | NATIVE_LOW_PRECISION+SFI00x4_0000+ 16-bit datalayout gating, bitwiseabs/negpreserving denormals/NaNs,-0 < +0&nan16handling inmax_min16/med3_16/clamp16, SM 6.2 single-roundingfma16, andshader_cachekey update all check out.origin/mainjust advanced withWARP_LOCK/SharedDeviceincrates/victory-shader/src/emit/host.rs, causing a small rebase conflict inemit/host.rs(dispatch_timedjust needs to keeplet _guard = self.lock_warp();). Clean against #2806.@xndbogdan on GitHub · 2026-11-25 21:53 UTC · original · edited 2026-11-25 21:55 UTC
Results on AMD hardware, the adapter the PR lists as unverified.
Setup: AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32015.7029, Intel Xeon E5-2670 v3 (times are GPU timestamps, so the CPU is not in them), Windows 11 IoT Enterprise LTSC 26100,
bdc08a9,--release, validatordxil.dllfrom Windows SDK 10.0.26100. No game data.Tests: all pass on the hardware adapter and on WARP.
sixteen_bit_floats_match_the_hardware_natively: 29 probes, 0 model mismatches on hardware or WARP.fused_f16_results_round_once_natively: passed, so this card's native 16-bit FMA rounds once, as on the RTX 5070 Ti and RTX 4070 Ti.native_f16_is_never_further_from_the_console: passed; the native and f32 paths differ on 2 inputs on hardware, as on the RTX 5070 Ti.f16_results_round_as_the_mode_says_nativelyandnative_16bit_operations_are_declared_where_used: passed.Benchmark (
translated_f16_math_costs), four runs (the first straight after the build, then three back to back). Results were alike in all 262,144 threads in every run.v_pk_fma_f16v_fma_f16v_mul_f16+v_add_f16The native path is faster in every run, but far less so than the 39×, 18× and 21× on the RTX 5070 Ti, and it varies from run to run. On this same card, #2806's hand-written
half2chain is 26× faster thannarrow16, so the translated native code seems to leave speed behind on AMD. Two possible reasons, neither checked:trunc,bitcast,zext), and AMD's compiler may not pack the two back into onev_pk_fma_f16. Radeon GPU Analyzer's ISA output for the native module would show whether it does.AI-assisted (Claude Code). The tests and benchmark ran on the machine above.
@xndbogdan on GitHub · 2026-11-25 22:36 UTC · original
Follow-up to my AMD results above, with the ISA. The two possible reasons I gave there were both wrong. Same RX 9070 XT (
gfx1201, driver 32.0.32015.7029),bdc08a9. I compiled the benchmark's six translated modules, and #2806'shalf2shader, with Radeon GPU Analyzer 2.15 (DX12 mode, live driver).1. The native path picks the same instructions as hand-written HLSL. Each native
v_pk_fma_f16compiles to twov_fma_f16, one on each half (v0.l, thenv0.h). #2806'shalf2mad, compiled by dxc, also becomes twov_fma_f16on this driver, so neither gets a packed instruction. Program sizes, f32 path → native:v_pk_fma_f16v_fma_f16v_mul_f16+v_add_f162. The chains are half as long as the test assumes, which made the AMD timings mostly fixed cost.
chain()repeatsstepCHAIN / step.len()times, andstep.len()counts encoding dwords.v_pk_fma_f16andv_fma_f16are 2-dword encodings, so those chains hold 256 instructions, not 512. The ISA agrees: 512v_fma_f16(2 × 256) in the packed chain, 256 in the scalar one. So:The same benchmark with
CHAIN = 4096, two runs each:CHAIN = 512CHAIN = 4096v_pk_fma_f16v_fma_f16v_mul_f16+v_add_f16Results were alike in all 262,144 threads in every run. Counting instructions rather than words in
chain()and using a longer chain would make the table comparable across GPUs.3. A possible follow-up, not for this PR: the merge after scalar f16 results. Each native scalar result is merged into its 32-bit register to keep the other half, as the console does:
v_fma_f16chain: per op,v_fma_f16+v_bfi_b32+v_mov_b32(256 / 256 / 258 in the module);v_mov_b16+v_bfi_b32(512 / 512 for 512 ops).The packed chains need no merge. Where the other half of the destination is never read before it is overwritten, skipping the merge would take these chains from ~3 instructions per op to 1, which probably explains the lower scalar speed-ups.
low16already tracks reads of the low half alone, which may be a starting point. How often the title's shaders write single halves is not known.AI-assisted (Claude Code). The benchmark runs and ISA dumps were made on the machine above, with a local, unpushed hook that wrote the modules and root signatures to disk.
@Proudnoob4 on GitHub · 2026-11-25 22:42 UTC · original · edited 2026-11-25 23:26 UTC
AI-assisted testing (Gemini in OpenCode); measured locally on my own machine.
First real-game RTX 4080 verification (ported onto
fxceless/victory-fork9c184b3stack)I ported the core native-
halfemission frombdc08a9(TypeDef::Half, 16-bit data layout,LOW_PRECISION | NATIVE_LOW_PRECISION+SFI0 0x4_0000,D3D12_OPTIONS4::Native16BitShaderOpsSupported, and the scalar + packedhalflowerings inlower.rs) onto our local RTX 4080 test stack (fxceless/victory-fork9c184b3+ bundled perf PRs) to test it in-game.Setup: Windows 10 Pro 22H2 (Agility SDK 1.620.2), i5-13600K, 32 GB RAM, RTX 4080 16 GB (driver 621.01), Series X profile, diagnostics release build, separate warmed shader cache (
victory-fxf16-cache).Translation & pipeline creation:
victory translate --warm(2,576 world shader hashes): 2,512 / 2,513 found shaders translated cleanly (0 additional refusals vs the f32 path).1,821made on cold run,1,997loaded +125made on warm run), 0 pipeline refusals, 0 crashes, 0 device removals across 12+ minutes total in-world.frame-2048.pngwarm run): clean cell, sunlit yard, Lucia head/hair/ponytail, posters, UI — no visible f16 artifacts. (Note:fxceless'slower.rsdoes not trackmode16yet, so even without themode16 == Some(3)guard, the prologue/cell scene rendered cleanly.)Warm RTX 4080 timing (same stack & switches, f32
legacyF32ToF16baseline vs nativehalf):(Note:
fxceless's f32 baseline defaults to 1-oplegacyF32ToF16rather than upstream's 40-opnarrow16, so the delta vs upstream'snarrow16will be larger than this floor.)framelogusual frame /cardmeter)fxcelessf32 (legacyF32ToF16)half(#2825port, warm)framelogusual frame113 ms(41 frames)107 ms(36 frames, -6 ms)9.30 fps9.70 fpsframelogall other lists(GPU)38.8 ms(201 lists)34.1 ms(176 lists)send-and-hash + compare + lists)47.9 ms41.9 ms(23.9 fpsGPU ceiling; card 43% busy)cardmeter256-frame mean40.8 ms(210 lists)40.9 ms(211 lists)Native
halff16 works cleanly end-to-end on real game shaders on Ada Lovelace / Windows 10 + Agility 1.620.2, with zero pipeline refusals and lower settled frame time even against alegacyF32ToF16baseline.@0xkn0wh3r3 on GitHub · 2026-11-25 22:51 UTC · original
@xndbogdan thank you, both findings were right.
aef37bbmakeschaincount instructions rather than encoding words, so the VOP3/VOP3P chains now hold as many instructions as the table says, and it uses 4,096-instruction chains as you measured. On the RTX 5070 Ti that gives 53.5x forv_pk_fma_f16, 30.9x forv_fma_f16and 25.9x forv_mul_f16+v_add_f16, results alike in all 262,144 threads. The description's table is re-measured, and it credits your check.Interesting that both the native path and dxc's
half2madbecome twov_fma_f16on gfx1201. So the gain there is from dropping the integer rounding sequence, not from packing. The merge after scalar results is noted for a follow-up.CI was also failing on the policy check:
lower.rshad passed the 512 KiB limit.905732amoves the native-halfhelpers, unchanged, intolower/half.rs.@xndbogdan on GitHub · 2026-11-25 22:53 UTC · original
@0xkn0wh3r3 thanks for the quick turnaround, and for the credit. 53.5× on the corrected chains is a great result. Good luck getting this merged.
@Proudnoob4 on GitHub · 2026-11-25 23:17 UTC · original · edited 2026-11-25 23:26 UTC
AI-assisted (Claude Opus 5.5 in OpenCode), measured on my own machine. This replaces two overlapping AI-written reports I posted here earlier; on re-auditing the logs, some of their numbers were single samples or misattributed, and one said there were no visual artifacts, which was wrong.
Setup: RTX 4080 16 GB, Windows 10 22H2, Series X build, diagnostics release, prison-cell scene (~4,800 draws/frame). Three single 360 s runs, so this is a bundle comparison, not an isolated A/B:
Marvisak/VIctory#2825native f16#1168+#1147+#1164(VICTORY_CARD_PIECE_KB=16) +#1171+#1172+ a local commit (skip cleancard_dirtycopies; chunk wide compare dispatches to ≤ 65,535 groups)all other lists), 2nd-half mediancardmeter, 256-frame mean, steadycardmeterunchanged). Which of C's additions gave the 8 ms is not isolated.For this PR: the earlier report here (22:42) gave 38.8 → 34.1 ms GPU lists and 113 → 107 ms per frame. Those were the last single sample of each run. The medians are 40.0 → 38.1 ms GPU lists,
cardmeter40.8 → 40.9 ms, and 112 → 111 ms per frame. So on this CPU-bound stack native f16 shows at most a ~2 ms GPU gain and no measurable frame gain, although it was active (supported=true active=true). The ~8 ms drop in C came from the other PRs, not from f16, which my 23:17 note got wrong. None of this contradicts the microbenchmark: this workload simply isn't limited by ALU throughput.@futurepro62 on GitHub · 2026-11-25 23:27 UTC · original
Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head
3c81083(on its basef3578e3).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 870 passed, 0 failed, 11 ignored.hosts_that_round_f16_fmad_twice_keep_the_f32_path,sixteen_bit_floats_match_the_hardware_natively,the_f16_fma_cases_round_once_in_the_model,fused_f16_results_round_once_natively,f16_results_round_as_the_mode_says_natively,native_16bit_operations_are_declared_where_used,native_f16_is_never_further_from_the_console.translated_f16_math_costsis#[ignore]d and was not run.--skipleaves out tests that fail on main842b0cbon this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
@steven-seagull27 on GitHub · 2026-11-26 02:20 UTC · original
Integration finding for #2915: with its production
float_resultchange (dcf36ff) applied to this head (3c81083), turning on native half rejects seven shaders that translate and run with the f32 option.valu16_nativeclaims their modified ADD/MUL instruction before #2915's output-modifier path can handle it. The error isan output modifier on a 16-bit operation is not supported. The unmodified ADD control passes.I tried a local change allowing an instruction with
v.omod != 0to fall through fromvalu16_nativeto the ordinary lowering. On an RTX 5080, native capability check true, all seven then validated and returned the expected bits. The software option on the same RTX, and WARP with the capability check false, agreed. Two cases distinguish applying the modifier before binary16 rounding from scaling an already-rounded half:MUL(0001, 3800) × 20001; rounding the product to half first would yield zeroADD(7bff, 7bff) × 0.57bff; rounding the sum to half first would overflowThe other cases covered ADD ×2, ×4, ×0.5, ×4 with clamp, and a single shader containing ordinary MUL followed by modified ADD. That mixed shader returned
4380for(1.5 × 0.25 + 1.5) × 2and still declared native 16-bit operations in SFI0. The fallback can therefore be per instruction. Modified exact FMA remained explicitly refused on both paths as #2915 specifies.Windows 26300.10075, driver 621.40, synthetic RDNA2 → DXIL → D3D12 readbacks. Tested with Codex assistance.
@Marvisak on GitHub · 2026-11-26 02:22 UTC · original · edited 2026-11-26 03:21 UTC
Automated triage for the maintainers.
Re-reviewed at
47078d7. The only change since the last triage is the integration fix for #2915.valu16_native(crates/victory-shader/src/emit/lower/half.rs) now returnsNonefor any instruction with an output modifier, so that instruction falls back to the f32 path while the rest of the shader stays native. The refusal invalu16_native_opis gone because nothing can reach it now. The new testoutput_modifiers_on_f16_results_take_the_f32_path_nativelychecks that both paths translate or refuse such instructions alike. steven-seagull27 confirmed the combination with #2915 on RTX 5080 and WARP.The earlier assessment stands. The native
halfpath is gated onNative16BitShaderOpsSupported, a startup probe that 16-bitFMadrounds once, andVICTORY_F16_IN_F32. The option is part of the shader cache key. Points for the maintainer are unchanged: NaN payloads become the host's, the path is on by default where supported, and the diff is large.Verdict: merge candidate (a recommendation to look, not an approval). CI: passing.
Generated by Claude Code
@0xkn0wh3r3 on GitHub · 2026-11-26 02:36 UTC · original
@steven-seagull27 thanks, that's exactly the integration case. Fixed in dbc004b:
valu16_nativenow returnsNonefor any instruction with an output modifier, so that instruction falls through to the f32 path on its own, and the rest of the shader stays native. #2825 and #2915 then compose whichever lands first, as your mixed shader shows. The refusal for those instructions that the native path could no longer reach is gone. Modified exact FMA stays refused, as #2915 specifies.The new test
output_modifiers_on_f16_results_take_the_f32_path_nativelychecks that VOP3v_add/v_mul_f16with mul:2, mul:4 and div:2 translate or refuse alike on both paths, and that a translated one declares no native ops. Onmaintoday both paths refuse them alike, because #2915 isn't in. Your RTX 5080 results with #2915 applied (MUL(0001, 3800) × 2 → 0001,ADD(7bff, 7bff) × 0.5 → 7bff) are what the combination should give; I didn't re-run them here. The native tests (21) pass on an RTX 5070 Ti, and clippy is clean.@steven-seagull27 on GitHub · 2026-11-26 02:42 UTC · original
Confirmed on current head
47078d7(same tree asdbc004b) combined with #2915 atdcf36ff. All eight arithmetic readbacks matched on RTX 5080 with native half enabled and disabled, and on WARP. The minimum-subnormal and maximum-finite cases returned0001and7bff. The mixed native MUL → modified ADD returned4380and retained the native-16 SFI0 bit. Modified-only shaders cleared that bit, and modified exact FMA still took the expected refusal on all three runs.@kotekompotek on GitHub · 2026-11-25 22:11 UTC · original · reviewed
Scoped review — the part that had to be right is right: the shader-cache build key folds options().native16 in, so an f16-native translation can never be served to a non-native host (and the un-initialized-host -> native16=false direction fails safe). options() centralizing view_marks+native16 prevents drift between the cached and uncached translate paths. The rest — bitcode f16 type, host probe, the +200 lines of f16 lowering — is a big surface; the DXIL-level tests plus the claimed 39x on the 5070 Ti suggest it's exercised, but a second pair of eyes on the rounding/saturation semantics of the packed-f16 ops would be worthwhile.
@Dukestar69 on GitHub · 2026-11-26 09:47 UTC · original · approved these changes
Verified on RTX 5090 against
origin/main(63bcca4):cargo test -p victory-shader --lib(all 8 new native-f16 tests): passed on RTX 5090 (sixteen_bit_floats_match_the_hardware_natively,fused_f16_results_round_once_natively,f16_results_round_as_the_mode_says_natively,native_f16_is_never_further_from_the_console,output_modifiers_on_f16_results_take_the_f32_path_natively,native_16bit_operations_are_declared_where_used,hosts_that_round_f16_fmad_twice_keep_the_f32_path,the_f16_fma_cases_round_once_in_the_model).cargo test -p victory-gpu --lib shader_cache:: -- --test-threads=1: 4/4 passed.cargo clippy -p victory-shader -p victory-gpu -p victory --all-targets -- -D warnings: clean.cargo xtask policy: 192 files ok.Cleanly enables native 16-bit floating-point arithmetic on hosts that support it and pass the single-rounding FMA probe, with proper shader cache keying.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@fuzeofficlal on GitHub · 2026-11-26 10:22 UTC · original · approved these changes
Audited the DXIL encoding, native
halflowering (lower/half.rsandpacked16), rounding-mode /omodgating,rounds_f16_fmad_onceprobe, andshader_cachekey isolation, and verified on Windows 11 with an RTX 5090, WARP, and the Windows 11 SDK validator (10.0.26100.0\x64\dxil.dll).Verification (
origin/main63bcca43merge-tree clean)cargo clippy --workspace --all-targets --locked -- -D warnings(default &--all-features): clean;cargo xtask policy: 191 files ok.victory-shaderwith SDKdxil.dllvalidation: all 9 f16 / native16 tests passed (hosts_that_round_f16_fmad_twice_keep_the_f32_path,sixteen_bit_floats_match_the_hardware,sixteen_bit_floats_match_the_hardware_natively,the_f16_fma_cases_round_once_in_the_model,fused_f16_results_round_once_natively,f16_results_round_as_the_mode_says_natively,output_modifiers_on_f16_results_take_the_f32_path_natively,native_16bit_operations_are_declared_where_used,native_f16_is_never_further_from_the_console):rounds_f16_fmad_once() == Ok(true),native16() == true; 0 model mismatches across all 23 probes, the#2384cases, and 8,192 random finite/denormal FMA triples;native_f16_is_never_further_from_the_consolediffered on 1 packed FMA input (toward the model).rounds_f16_fmad_once() == Ok(false),native16() == false(keeps f32 path).emit::bitcode::+emit::lower::tests::: 45/45 passed.translated_f16_math_costs, 4,096-inst chains, 262,144 threads, best of 5 × 10 dispatches):v_pk_fma_f16:2.284 ms(940 Gf16 ops/s) →0.036 ms(60,404 Gf16 ops/s) — 64.3x (262,144/262,144 identical)v_fma_f16:1.297 ms(828 G) →0.035 ms(30,402 G) — 36.7x (262,144/262,144 identical)v_mul_f16 + v_add_f16:1.017 ms(1,056 G) →0.035 ms(30,632 G) — 29.0x (262,144/262,144 identical)victory-gpu:shader_cache::tests::4/4 passed on RTX 5090 default, RTX 5090VICTORY_F16_IN_F32=1(short-circuits the probe), RTX 5090VICTORY_D3D12_DEBUG=1, and WARPVICTORY_D3D12_DEBUG=1;draw::tests::20/20 passed on RTX 5090.Minor non-blocking note
Inspecting
ID3D12InfoQueueunder the D3D12 Debug Layer showsHost::fmad_probe(crates/victory-shader/src/emit/host.rs:694, shared with the pre-existingfuses_fmadcheck) binds only the CBV/SRV/UAV descriptor heap beforeSetComputeRootSignature(&root), whileroot_signature_forsetsD3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED, loggingD3D12_MESSAGE_ID(1419)(ERROR) once per probe call on both RTX 5090 and WARP (2 messages total now: once fromfuses_fmad, once fromrounds_f16_fmad_once). Pre-existing onmainand harmless for the probe dispatch, though binding a 1-slot shader-visible sampler heap alongsideviewsinfmad_probewould keep the debug queue completely clean (fine as a follow-up).@liandraraiane on GitHub · 2026-11-26 12:49 UTC · original
First Ampere (RTX 30) result, since the native path is gated on the card rounding a 16-bit
FMadonce and no RTX 30 card was in the thread yet.Setup: NVIDIA GeForce RTX 3060 12 GB (Ampere, GA106), driver 610.88, Ryzen 7 5700G, Windows 11 Pro 26200, Rust 1.98.1,
dxil.dllfrom Windows SDK 10.0.26100, release. This PR's head merged ontomain63bcca4(one conflict in the test harness's dispatch, with a local timing hook of mine; the PR's code is unchanged). No game data.Capability and correctness (the
nativelytests): 4/4 pass.fused_f16_results_round_once_natively: passes, so this card's native 16-bit FMA rounds once and the native path turns on for the RTX 30 series too (v_fma_f16over 8,192 inputs: 0 model mismatches).sixteen_bit_floats_match_the_hardware_natively: 0 model mismatches on hardware for every probed operation (add, sub, mul, min, max, fma, fmac, pack, rcp, sqrt, rsq, exp, log, and the packed add/mul/fma/fmac with and withoutsel_hi_lo); WARP skipped as expected (no once-roundingFMad).f16_results_round_as_the_mode_says_natively,output_modifiers_on_f16_results_take_the_f32_path_natively: pass.translated_f16_math_costs, 5 runs (each the bench's own best of five), median:v_pk_fma_f16v_fma_f16v_mul_f16+v_add_f16Results alike in 262,144 of 262,144 threads in every run. The first run's native
v_fma_f16was 1.275 ms (warm-up); the other four were 0.329–0.331 ms.Full
victory-shadersuite with the native path on: 306 passed, 3 failed, the same three that fail onmainon this card (a_heap_buffer_read_by_element_takes_the_views_stride,a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,gathers_at_a_level_match_the_hardware: the capped view heap of #1835);mainalone: 298 passed, the same 3 failed. No new failure.Not tested: a title (only synthetic chains and the PR's tests), other Ampere cards.
AI use: Claude Code ran the builds, tests and benchmark on this machine and drafted this comment.
@Jackster on GitHub · 2026-11-26 15:37 UTC · original
Merged and run on the retail title: no GPU reduction in one run, but the scenes are not comparable — how do I force the mode off for a matched A/B?
Setup: this PR merged into
63bcca4(clean), RX 7900 XTX (1002:744c, driver 32.0.32029.2010), Windows 10 26300.10075, retail 1.0.2.1, diagnostics build, 300 s. I translated the whole pack with this tree first (translate --cache: 25,669 translated, 220 refused — identical to the unpatched tree, so nothing regressed in translation), then ran with a warm cache.63bcca4The GPU number went up, not down, and the draw counts are far apart (3,926 against 1,293, with 1,289 dropped against 949), so this is not an A/B of the f16 change at all: the two runs are in different scenes and the second is missing a third of its draws.
Before I conclude anything I would like to compare the same scene with the change on and off. Is
Options::native16reachable from an environment variable or a switch in this branch (asVICTORY_*switches are elsewhere), or is it decided by the host's capability alone? If it is capability-driven and there is no switch, I can build two binaries locally (one with the option forced off) and run them against the same save — say the word and I will, with the number oflegacyF16ToF32/legacyF32ToF16ops per frame as the thing that should move.One thing that would help either way: which passes in this title use f16 chains heavily? Our world frame is ~370 ms of preparation and ~160 ms of GPU, so a 37x win on the passes you measured should be visible in the GPU number if those passes are in the world — and if it is not visible, that itself is worth knowing.
Written with an AI assistant.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.