Skip to content

cpp-migration: lower v_cvt_pk_u8_f32 in the direct C++ compute path #2997

Done

Description

Target branch cpp-migration. Part of #2935 (instruction coverage: f32 ALU). I am taking this; please say if you already have it locally and I will drop it.

Gap: the direct compute path refuses v_cvt_pk_u8_f32 with direct DXIL lowering for v_cvt_pk_u8_f32. I found this with the same per-opcode VOP3 probe as #2985, on cpp-migration 05438d65.

gfx2hlsl.py lowers it (op_v_cvt_pk_u8_f32): D = (S2 & ~(0xff << 8 * S1[1:0])) | (flt32_to_uint8(S0) << 8 * S1[1:0]). Its conversion is the one measured on RDNA 2 hardware (see docs/experiments.md): round to nearest even, saturate to [0, 255]; NaN, both zeros and negatives give 0, and +inf gives 255. The positive test is the integer comparison (bits - 1) < 0x7f800000, which avoids a float compare that fast-math could fold.

Plan:

  • Lower the same expression: the integer positive test, DXIL FMin with 255.0, Round_ne, then fptoui and the byte merge into S2.
  • Modifiers stay refused, as in gfx2hlsl.py.
  • Fixture: a source-built dispatch with ties (0.5, 1.5, 2.5, 254.5), the saturation bound (255.5, 1e30, +inf), -0.0, -1.0, a NaN, the smallest subnormal and all four byte selects, against a CPU reference. References that round half up, truncate, or let NaN or negatives through must differ.

AI-assisted.

Activity

  1. akimfomin commented on Nov 27, 2026

    @akimfomin

    PortBridge Radar independently surfaced a useful control for your direct DXIL probe: the AnyPS5 team already recorded the expected packed words for this opcode on gfx1035. The pinned fixture and expected rows cover all four byte positions and retention of the other bytes.

    I replayed the 32 recorded expectations with a small CPU model. Round-to-nearest-even with saturation matches 32/32, truncation fails two rows and half-up fails one. For example, input 1.5 with prior word 0xbf800000 and byte selector 2 yields 0xbf020000; input 2.5 with prior word 0x3f000002 and selector 3 yields 0x02000002.

    The smallest next check is to add those two expected words to your existing DXIL dispatch as independent controls. The reference values belong to AnyPS5; the CPU replay is from PortBridge and does not predict a pass for the DXIL implementation. Both sources are linked from the public Radar.

    Update after #2998 merged: the new implementation uses Xbox2Windows’s own reference. The merged controls cover the rounding distinctions already. The reported GPU readback was SKIP on the Quadro. PortBridge Lab #121 now links the exact merged revision and asks for one run of that existing fixture on a Wave32 adapter.

  2. MasterDomino commented on Nov 27, 2026

    @MasterDomino
    Collaborator

    Completed by #2998, merged into cpp-migration as af6d255. Merges into a non-default branch do not close issues automatically.

  3. Leyukaka commented on Nov 27, 2026

    @Leyukaka
    Collaborator

    Second hardware readback for the v_cvt_pk_u8_f32 lowering of #2998. It passed on the RX 9070 XT in the #2998 review; it fails here on NVIDIA.

    Setup:

    • cpp-migration 999e17cd, Release.
    • NVIDIA GeForce RTX 5080, driver 32.0.16.2101, Windows 11 build 26300.9974, DXC from the Windows SDK 10.0.26100.
    • The D3D12 debug layer is not installed on this machine, so it was off.
    • ctest --test-dir <build> -R '^native_cvt_pk_u8_hardware$' fails.

    Result:

    • 64 of the 2,064 words differ, and all of them are case 0, S0 = 0.5 with byte select 0. The first mismatch is word 8 (lane 0). Every lane of both groups writes 0xa5a5a501 where round to nearest even expects 0xa5a5a500.
    • The other 15 cases match on every lane:
      • the ties 1.5, 2.5 and 254.5;
      • 255.5, 1e30, both infinities, both zeros, NaN, -1.0, the smallest denormal, 127.4999, 3.0 and 255.0.
    • The guards and sentinels are intact.

    So on this driver 0.5 rounds to 1 while the other ties round to even.

    • The lowering is a positive test, FMin(x, 255.0), Round_ne, fptoui and the byte merge, with no other rounding step. So this looks like Round_ne(0.5) giving 1 here.
    • S0 comes from a v_mov literal, so the driver compiler may also have folded it as a constant.
    • I have not checked Round_ne(0.5) in isolation. The same fixture passed on AMD in the shader: lower v_cvt_pk_u8_f32 in the direct C++ compute path #2998 review, so this is specific to this adapter or driver.

    AI-assisted.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions