shader: double support — the conversion pair and the four arithmetic forms #142
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/142"
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 Zettrox/ztrx. Originally posted by xiaotu030202 on 2026-11-25T14:10:17Z.
What this adds
Six double instructions in
gfx10/opcodes.rswere unreachable together, because nothing inemithad adouble:TypeDefhad aFloatand noDouble,Typeshad anf32and nof64, andCastwent fromSiToFp = 6straight toBitcast = 11, skipping LLVM'sfptrunc = 7andfpext = 8.All three exist now, plus six instructions:
v_cvt_f32_f64Double,f64,FPTrunc— narrow to one dwordv_cvt_f64_f32FPExt— widen into two VGPRsv_add_f64,v_mul_f64v_min_f64,v_max_f64f64_max_min, because DXIL has noFMin/FMaxforf64Two shaders in #132's log stop at the first of these —
5dc3b25986622949and6f225b641c5b0708. The rest are the other half of what that unlocked; no title has been seen failing on them.Three refusals worth recording
A "did it lower" test would have hidden all of them behind the last one.
Flags must match usage. declared=…4, actual=…0— and0x4is not the answer.The delta the validator prints is the difference between two values, not the bit to set.
d3dcommon.hhas the real one:Every other flag in this file already matches that enum exactly (
STENCIL_REF 0x200,WAVE_OPS 0x4000,INT64_OPS 0x8000,BARYCENTRICS 0x20000), which is what made the header the right authority rather than the diff. Setting0x4passed the first check and failed the next:Container part 'Feature Info' does not match expected for module.FPExt only operates on FP—%10 = fpext i32 %9 to double.A VALU source register holds an
i32, so widening needs a bitcast tof32first. This is exactly whyv_cvt_f32_f16goes throughlegacyF16ToF32(integer in, float out) instead of casting the raw register.I briefly "learned" the opposite — that widening did not need the
DOUBLESbit — from a green run that was green only because thefpextwas still malformed and the module therefore contained no realdouble. A false green that teaches the wrong lesson is worse than a red.'dx.op.binary.f32' is not a DXILOpFuncition for DXILOpcode 'FMin'.The
f32min/max helper callsbinary.f32withi32bitcasts.FMin/FMaxhave nof64overload at all, sof64_max_minis a compare and a select, keeping the hardware's−0rule — of two zeros the maximum is+0unless both are−0, the minimum is−0unless neither is — withi64masks (0x7FFF_FFFF_FFFF_FFFF) rather thani32ones.Two bugs in my own tests, both caught by checking values
Register clobbering. The first arithmetic test failed with
v_add_f64(1.0, 2.0) -> 1.0. The lowering was fine:build_cshands its four input dwords tov1..v4, and I widened the first input intov2— clobbering the second before it was read. The sum really wasa + garbage. Temporaries start atv8now.A test that measured nothing. My first
v_cvt_f64_f32test asserted only!shader.dxil.is_empty()— and it passed with a lowering that wrote only the low half of the pair. I found that by mutating the code, not by reading it. It is replaced by one that compares the high dword againstf64::from(f).to_bits() >> 32.Tests — values, on hardware and WARP
v_cvt_f32_f64_narrows_a_double_to_one_dword,…_takes_a_scalar_pair_too— VGPR pair and SGPR pairv_cvt_f64_f32_widens_one_dword_into_two— high dword against Rust'sf64for 1.0, 2.0, −1.0, 0.0the_double_arithmetic_forms_compute_in_double— all four forms over four input pairs, widened and narrowed through the conversion pair, so one test exercises everything hereChecked by mutation, each time by breaking the code and re-running:
Verification
Windows 11, RTX 5070 Ti, Rust 1.98.1 (pinned), MSVC 14.44.35207, Windows SDK 10.0.26100.0,
VICTORY_DXILset. No game files.What is not claimed
I have not seen the two shaders from #132 translate. That needs
shaders.rpfand game files. Whether they now go through, or stop at the next thing they contain, is whatvictory translate --listwould say.Seven double instructions still do not lower:
v_fma_f64,v_rcp_f64,v_rsq_f64,v_sqrt_f64,v_frexp_*_f64,v_div_scale/fmas/fixup_f64, the wholev_cmp_*_f64family, and everyds_*_f64LDS form. Each needs its own reading of the ISA —v_sqrt_f64is a two-instruction sequence on some hardware — and none are here.Why one PR instead of three
I first opened this as #138, #140 and #141, judging each worth reviewing alone. That was wrong for a feature stack: two of them cannot apply to
mainwithout the first, so reviewing them apart means reviewing a branch that does not build. This replaces all three — same content, one description, one diff. I will close those once this is up.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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.