Shaders: f16 math in native half on cards with 16-bit operations, and its count in victory translate #2833
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!2833
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2833"
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?
@xndbogdan on GitHub · 2026-11-29 17:53 UTC · original
shaders/native-f16→main· +859 −24 · 11 files · 2 commits · closed without mergingTwo changes, both on 16-bit float math in translated shaders: a count of how much of it there is, and native
halfarithmetic for it on cards that run 16-bit operations.1.
victory translatecounts the instructions on 16-bit floatsFrom my Marvisak/VIctory#2866. One more line after the program count:
An instruction counts when its name has an
_f16operand or result. It is counted once where it appears in the code, not by how often it runs. Nobody has posted this number for the title's shaders yet; it says how much of the shader code the second change can reach.2. f16 arithmetic in native
halfPorted from Marvisak/VIctory#2825 by @0xkn0wh3r3 (that PR and its account are gone; the commit credits them as co-author). Their translator was different enough that this is a port onto this one, not a cherry-pick.
Today each console f16 operation is done in f32 and converted back with the host's
f32tof16. On NVIDIA that rounds toward zero, unlessVICTORY_F16_NEAREST=1. Where the card reportsNative16BitShaderOpsSupported, these now become DXILhalfarithmetic:v_add/sub/subrev/mul_f16,v_fma/fmac_f16,v_min/max/min3/max3/med3_f16v_pk_add/mul/fma/fmac/min/max_f16That happens only where the program rounds 16-bit results to nearest even: no
MODEwrite, or round-to-nearest set. Toward zero or toward an infinity, a mode that isn't known at that point, output modifiers, conversions,v_mad/mac_f16,v_fma_mix*, and the transcendental and rounding operations keep the f32 path.VICTORY_F16_IN_F32=1restores the old behaviour exactly.What changes in the results:
FMadis fused (RTX 4070 Ti, 5070 Ti and 5080, measured in Marvisak/VIctory#2384), as the console'sv_fma_f16. The f32 path rounds them twice.v_med3_f16uses the host's own min/max, as this fork's f32med3does, so signed-zero behaviour does not change.Cost: #2825 measured, on an RTX 5070 Ti with GPU timestamps, dependent chains of 512 instructions:
v_pk_fma_f1639x,v_fma_f1618x,v_mul_f16+v_add_f1621x faster. How much of that shows in a frame depends on the share from change 1.How it's wired:
victory-gpuasks the device once, next to the existing wave-lane query, and tells the translator throughset_host_native16, likeset_host_rdna.host_settings()andtranslation_fingerprint(), so a cached translation of one path is never served to the other.halftype, the 16-bit data layout, the low-precision shader flags and SFI0's native 16-bit bit are set only when a program useshalf. The optimiser's usage scan clears them again if a pass removes every use.Tests
On an RTX 5080 (driver 621.24) and WARP, Windows 11 build 26300, Ryzen 7 9800X3D:
native_f16_arithmetic_rounds_once_to_nearest_evencompares against an exact model: integers in units of 2^-48, rounded once.v_add/sub/subrev/mul_f16,v_pk_add/mul_f16, 192 random finite operand sets each, denormals included.FMadin f32 first:v_fma_f16,v_fmac_f16andv_pk_fma_f16, the same random sets plus #2384's five single-rounding cases.native_f16_min_max_med3_and_clamp_match_the_f32_pathruns min, max, min3, max3, med3, pk_min and pk_max both ways over zeros of both signs, denormals, infinities, NaNs and ordinary values, and checks the clamp's +0 for NaN and negatives.native_16bit_operations_are_declared_where_used_and_toward_zero_stays_in_f32: SFI0's bit is set forv_add_f16andv_pk_fma_f16, and not for a conversion, a toward-zero program, or anything with the switch off. The toward-zero program's results stay those of the f32 path.dxil.dllvalidation.cargo test --locked -p victory-shader -p victory-gpu -p victory, rebased onmainate1251c31:victorypasses,victory-shader536 passed and 4 failed,victory-gpu1131 passed and 2 failed. All six fail the same way onmainate1251c31:victory-shader:barycentric_tests::first_half_values_render_on_hardware_and_warp,rect::tests::rectangles_are_drawn_whole,rect::tests::the_rectangle_stage_is_a_geometry_shader("Pipeline State Validation does not match"), andbitcode::opt::tests::hw_tests::split_lds_wave32_read_after_read_barrier_coalescing_and_parity(neg_uav_load_between_reads mask=ALL pattern).victory-gpu:list::thin::tests::bindings_record_no_work("a call is in no list") andshader_cache::tests::every_switch_of_the_translator_is_in_the_key(VICTORY_ORACLE_RUNSis listed but not read).cargo clippyadds no warnings.Not done
VICTORY_F16_IN_F32=1for an A/B.victory translate <game dir>\shaders.rpfwould give it.AI-assisted (Claude Code).
🤖 Generated with Claude Code
05ca77bd60toce8d2f26bdPull request closed