Skip to content

shader: gfx2hlsl and the direct compute path give different SCC for s_min/s_max when S0 == S1 #3434

Backlog

Description

@Leyukaka

On main (eab7180), gfx2hlsl and the direct compute path give different SCC for s_min_u32, s_max_u32, s_min_i32 and s_max_i32 when both sources are equal.

gfx2hlsl: S0 == S1 sets SCC. tools/startup/gfx2hlsl.py, add_sub_min_max_scc (docstring: s_min / s_max: SCC = (D == S0), the first source was chosen):

    cast = 'int' if base.endswith('_i32') else ''
    return '(%s(%s) %s %s(%s))' % (cast, a, '<=' if base.startswith('s_min') else '>=', cast, b)

From 79410a8 (#2778).

Direct compute: S0 == S1 clears SCC. src/gfx1013_direct_compute.inl, arithmetic:

            auto pred = cmp(sign + (n.substr(2, 3) == "min" ? "lt" : "gt"), a, b);
            auto result = select(pred, a, b);
            if (scalar) {
                write(i.dst, result);
                write(128, ir.value("zext i1 " + pred + " to i32"));

The predicate is ult/slt/ugt/sgt. src/gfx1013_compute_native.cpp (unsigned forms only) is strict too:

            body << "{uint lhs=" << a << ",rhs=" << b << ";scc=lhs" << (n == "s_min_u32" ? "<" : ">") << "rhs;" << d
                 << "=scc?lhs:rhs;}\n";

Both from 4036577. The descriptor-stride branch of s_max_u32 against 1 in arithmetic (cmp("ugt",stride->second,"1") / cmp("ult",stride->second,"1"), from 350785e, #3227) is strict as well.

Tests.

  • gfx2hlsl: case S of tests/startup_gfx2hlsl_compute_check.py runs the four ops on a 4x4 grid of edge values; its diagonal has S0 == S1. The reference is scc = result == x, and the s-min-strict control requires a strict s_min_u32 compare to fail.
  • Direct path: I found no test that reads SCC after one of these ops with S0 == S1 on the general block above. tests/native_descriptor_scc_check.py covers only the stride branch (stride 1 against 1, expected 0).

The repository does not include the ISA text for these opcodes, so it does not settle which result is correct.

Suggested test: run the four ops with S0 == S1 (for example 0, 0xffffffff, 0x7fffffff, 0x80000000), each followed by an SCC read, through both gfx2hlsl and gfx1013-direct-cs, and compare the SCC bits.

Activity

  1. Leyukaka commented on Nov 29, 2026

    @Leyukaka
    CollaboratorAuthor

    Taking the direct-path test: branch tests-direct-scc-equal adds to tests/native_descriptor_scc_check.py an SCC read after s_min_u32, s_min_i32, s_max_u32 and s_max_i32 with equal operands (expected 0) and unequal operands (3 vs -1, expected 1), on the gfx1013-direct-cs path. It pins the current strict behaviour, not what the ISA specifies. It does not compare against gfx2hlsl, and it does not change either lowering. #3435 changes the gfx2hlsl side.

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