Skip to content

M post: the history encode relies on a driver conversion fold without a start-up check #232

Open

Description

@phantoslayer21

Model M's D3D12 post kernels (clean/dx12/kernels/post.hlsl, around lines 1127-1132) write the history texel as
mad(log2(..), kEncK, 0.0f) fed into the driver's round-to-nearest-even matrix conversion (cvt3_f16). The gfx1201
D3D12 compiler folds that into v_fma_mixlo_f16 .., kEncK, 0, which is HIP's own instruction, so today's bytes match HIP.

The exactness depends on that fold. A driver that does not fold would round the FP32 product first and then convert
it: two roundings, one FP16 ulp off wherever the FP32 product lands exactly on an FP16 midpoint. The frame checks would
likely not see it, because synthetic data rarely hits such midpoints.

Model L's post is getting the same guard in #231. M's post should get it too:

  • a needs=fold / needs=nofold pair of post ports, with the previous round-to-odd form as the no-fold fallback;
  • a start-up self-test that runs the REAL fold and no-fold post shaders on one small crafted frame whose history-encode
    inputs sit on FP16 midpoints from both sides, ties, +-0, subnormals and the floor, and compares their raw bytes
    (equal: fold port; different or any error: no-fold port). A separate probe shader is not enough, because the driver
    can compile the real post shader differently;
  • an isa= rule in build_dx12.py on each port that relies on the fold, tied to the actual sites.

Activity

  1. added this to the 0.6.5 milestone on Nov 15, 2026
  2. j0nsh1n commented on Nov 15, 2026

    @j0nsh1n
    Contributor

    Not sure how helpful this will be: a data point for the Proton path, in case it helps with the guard. There the history encode does fold.

    Checked on origin/main, all 14 post ports, with vkd3d-proton 5b1089c8 + dxil-spirv #362 (with and without the FMad NoContraction change) and an older vkd3d-proton build:

    • DXIL: FMad (dx.op.tertiary.f32 46, !dx.precise) of log2(..) x kEncK + 0, then the AGS conversion; 6 sites per port (18 in the direct ports).
    • dxil-spirv emits OpExtInst Fma x kEncK 0 decorated NoContraction, then OpFConvert to half. Both dxil-spirv builds give identical SPIR-V here, since the DXIL is already precise.
    • Mesa RADV / ACO folds it into one v_fma_mixlo_f16 / v_fma_mixhi_f16 .., s(kEncK), .., neg(0) at every site: RX 7900 XT (gfx1100), Mesa 27.0-devel. No v_mul_f32 + v_cvt_f16_f32 pair. NoContraction does not stop it.
    • gfx1201 without the card (Mesa 25.2.8 null device, vkd3d-proton's SPIR-V compiled directly): the same single v_fma_mixlo_f16 in the 7 ports tried.
    • On the 7900 XT, 37,632 inputs around FP16 midpoints match single rounding on all of them; double rounding would differ on 2,719.
    • If a stack did round twice: about 1 in 18,000 float32 inputs come out one FP16 ulp off, for example x = 3.36234355 gives 0x35d5 instead of 0x35d4.

    So the bytes match under Proton today. ACO folding it is compiler behaviour, not a promise, so the start-up self-test you describe would still be what keeps it safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions