Performance ideas from two other Rust game ports: native 16-bit shader math, and an LTO build profile #2382
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Imported from Marvisak/VIctory. Originally posted by xndbogdan on 2026-11-25T12:25:02Z.
I read VIctory and had my agent check OpenInfestation and OpenV2K, two recomps of mine that were recently finished, for anything in their renderers that would help shaders here. Most of it doesn't carry over: those ports compile their own GLSL to SPIR-V for Vulkan, while VIctory translates console code to DXIL. VIctory also already has what I would have suggested first: per-command GPU timing (
VICTORY_GPU_TIMING), a wave size declared only where a program needs one, and non-uniform indexing only where it is needed. Two things do carry over. Nothing below was run or measured on VIctory.1. Every f16 result is rounded in software
emit/lower.rsdoes 16-bit float math in f32 and narrows each result withnarrow16, because the host'slegacyF32ToF16rounds toward zero on the RX 6700 XT and WARP. Its round-to-nearest path is about 44 integer operations: bit tests, shifts and selects for normal, denormal, infinite and NaN halves. Each source is also widened withlegacyF16ToF32. So one console instruction such asv_pk_fma_f16(two halves, three sources each,packed16) becomes roughly 100 host operations, where the console runs one.#400 measured 180–320 ms of a ~800 ms world frame on the GPU, so translated ALU work is not free. Nobody has measured how much of it is f16 math.
A possible direction: where the device reports
Native16BitShaderOpsSupported, emit DXILhalfarithmetic (SM 6.2 native 16-bit types, with the matching shader flag), so the host GPU does the f16 operation itself and rounds as RDNA2 does. Keep the current path for:mode16 == Some(3), around the title's 16-bit interpolation);To check before writing it:
VICTORY_GPU_TIMING's slowest commands, and a count of f16 opcodes over the translated corpus;2. The release build has no LTO and no target CPU
Both ports ship a build like this:
What they measured (OpenInfestation docs/PERFORMANCE.md, OpenV2K docs/PERFORMANCE.md): fat LTO took 5–10% off the CPU frame, and x86-64-v2 took 2–4% (v3 was no better than v2 for their code). Event logs and snapshots stayed byte-identical, because Rust never contracts or reassociates floating point unless asked. VIctory's
[profile.release]has neither setting. The README already requires AVX2, so x86-64-v3 drops no supported CPU.Where it could help here: shader translation at first use (draws wait on it),
translate --cache, page comparisons, detiling and BCPack. It would not speed up GPU work or the driver's pipeline compiles. Much of the copy time in #400 is spent in kernel calls (write-watch), which no compiler flag shortens. It needs an A/B on the diag build before anyone trusts a number. A fat-LTO build is several times slower to compile (about 5 minutes against 1 there), so it belongs in its own profile, not inrelease.Imported from Marvisak/VIctory. Originally posted by Ingenioeren on 2026-11-25T12:34:27Z.
I tested the native f16 arithmetic idea on
940d32fusing the existing D3D12 dispatch/readback helper and half-precision CPU reference. The RX 6750 XT (driver32.0.21045.29003) and WARP on Windows 11 build 26200 both reportedNative16BitShaderOpsSupported. The synthetic SM 6.6 shader used raw binary16 inputs and outputs. DXC disassembly confirmedfadd halfandfmul half. CPU referenceAcross 132,096 input pairs per backend, every non-NaN result matched the round-to-nearest-even reference bit for bit, including signed zeros and subnormals. NaN classification also matched. NaN bits differed between the backends in 4,380 additions and 4,386 multiplications. For example, input bits
0x7c01and0x0001returned0x7c01on the Radeon and0x7fffon WARP for both operations. VIctory's current software narrowing explicitly sets the quiet bit. Current narrowingThat gives concrete coverage for native add and multiply in the default rounding mode. A native path that needs bit-identical NaNs still needs an explicit policy for them. FMA, other rounding modes and performance were outside this probe.
AI-assisted. One synthetic test passed on both backends. No game files used.
Imported from Marvisak/VIctory. Originally posted by xndbogdan on 2026-11-25T12:53:04Z.
Thanks for testing this, that's more than I had. Good to see add and multiply match bit for bit outside NaNs. One question on those: the Radeon passed
0x7c01through unquieted. Does the console'sv_add_f16do the same in the title's shader mode? If it does, native ops might match the console's NaNs more closely than the current narrowing, and only WARP would need the software path. Fused multiply-add and a timing on a real shader seem like the next things to check.That's all I had to add here. Good luck getting the port running better!
Imported from Marvisak/VIctory. Originally posted by DrDarkDK on 2026-11-25T14:00:55Z.
I tested native f16
FMadon an RTX 4070 Ti (driver 621.01) and WARP. For the cancellation case(0x3c01, 0x3e00, 0xbe00), both returned0x1600. Separate half multiply and add returned0x1800.Two inputs distinguished the backends. All values below are binary16 bits.
(a, b, c)3c01, 3e00, 80013e013e013e023e023c03, 3e00, 00013e053e053e043e04These two inputs could serve as regression cases for a native f16 path. The probe used synthetic D3D12 shaders and covered rounding only.
AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T16:01:14Z.
Automated triage for the maintainers.
Both suggestions still describe main (
63bcca4). 16-bit float results are computed in f32 and rounded in software byLower::narrow16incrates/victory-shader/src/emit/lower.rs, and nothing emits native DXILhalfarithmetic.[profile.release]inCargo.tomlsets onlydebug = "line-tables-only". There is no LTO profile, and.cargo/config.tomlhas notarget-cpu. Both fit the project's scope.The probes in the thread are useful input for a native-f16 path:
narrow16. The latest comment gives two all-normal regression vectors for this.Whether to pursue either suggestion is left to the maintainers.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T01:51:13Z.
The native half-FMA difference also occurs when every operand and the result are normal binary16 values. I used the three shaders from #2806 at
5dfeaf69and scaled the earlier discriminating cases by 1024 (multiply bothaandcby 1024, keepbfixed). Two regression vectors from D3D12 readback, in binary16 bits:a, b, chalf2half2narrow16, both adapters6401, 3e00, 840066016601660266026403, 3e00, 04006605660566046604I swept 16,384 finite triples:
a = ±(1 + m/1024) × Sfor everym = 0..1023,b = 1.5,c = ±k × 2^-24 × S, with independent signs,S ∈ {1, 1024}, andk ∈ {1, 4}. For each scale, rounding once and rounding through binary32 disagreed in 684 of 4,096 cases atk=1; atk=4both references agreed for all 4,096. I cross-checked the references using exact integer arithmetic in units of 2^-24.half2matched single rounding in all 16,384 cases. WARP nativehalf2matched binary32-then-binary16 nearest-even in all 16,384. Both devices reported native 16-bit shader ops support.narrow16matched the two-stage nearest-even reference on both devices. Thef32tof16variant matched binary32 nearest-even followed by binary16 truncation toward zero on both devices.These are deliberately selected midpoint cases, so the counts do not estimate how often a game shader encounters the difference. Windows build 26300.10075, NVIDIA driver 621.40, SDK 10.0.26100.0. The shader compiled to two DXIL
FMad.f16calls for the packed operation. I used a local readback fixture and Codex assistance. No console measurement.