Shaders: max, min and med3 as the host's own FMax and FMin on NVIDIA #635
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!635
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-635"
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?
@liandraraiane on GitHub · 2026-11-28 02:10 UTC · original
liandraraiane:perf/nvidia-native-minmax→main· +762 −28 · 10 files · 1 commits · openThe problem
The console's
v_max_f32andv_min_f32order -0 below +0, which DXIL's FMax and FMin do not promise. So on every host but AMD RDNA the translator adds a bitcast, integer compare and select after each of them, and spellsv_med3_f32between two constants out with NaN tests. The same goes for the min3/max3 and the 16-bit forms.On an RTX 3060 the card's own FMax and FMin already give the console's results, so that code does nothing there but cost time.
The change
On NVIDIA (vendor 0x10DE) the
MAX_MINandMED3forms, until now only for AMD RDNA, are written.VICTORY_NVIDIA_FLOAT=0turns them off.min(max(x, -0), 1)and ofmed3(x, -0, 1), which gives +0 where the console gives -0.Module::negative_zerofinds the constant given as bits, as a negated +0, moved to a register or behind a select. It does not follow joins of blocks, so a -0 arriving only through a phi is not seen (the difference would be the sign of a zero).fractand the legacy multiply are unchanged: the host's results differ there (Frcgives 1.0 for a tiny negative number; a zero's sign differs).host_rdna()is renamednative_float(), since it now answers for two vendors.victory translateandvictory replay --retranslatetakeVICTORY_HOST_NVIDIA=1.The shader cache key includes these bits and the translator's source, so shaders are translated again on the first run.
Measurements
RTX 3060 12 GB, driver 610.88, Windows 11.
native_float_costs: synthetic compute kernels, 131,072 threads of 4,096 rounds, GPU timestamps, the two forms turn by turn, medians of 61 runs. Three runs agreed within 0.1 percentage points.These are arithmetic-bound kernels, not the title. I have not run the title, so I have no frame time to report. Real shaders also wait on memory and textures, and a CPU-bound frame will not change; I expect a much smaller gain in a game.
Tests
nvidia_forms_give_what_the_spelled_out_ones_give(runs on NVIDIA cards, skipped elsewhere): 42 instruction patterns, about 6,000 inputs each (zeros of both signs, NaNs, infinities, denormals, pseudo-random bit patterns), the two forms compared bit for bit, NaN payloads aside. Passes. With the -0 guard removed it fails on 6 patterns.a_constant_negative_zero_keeps_the_spelled_out_form: needs no particular card.cargo test --workspace --release --locked:victory-shader292 passed, 5 ignored.victory-gpu441 passed and 2 failed (host_list_budget_starts_empty_at_each_submission,warp_batch_charges_every_execution), the same two as onmainwithout this change (see #67).victory-shadersuite with the NVIDIA forms forced on (a local hack, not committed): 290 passed, 2 failed, both on WARP, after the same cases had passed on the card. WARP does not order the zeros and is never given these forms.cargo clippy --workspace --all-targets --all-features: no warning on a changed line.Help wanted
Tested on Ampere only. A run on an RTX 20, 40 or 50 card would settle the others:
No game files, dumps or extracted data are included. This change and its testing were done with an AI assistant.
🤖 Generated with Claude Code
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.