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

Open
opened 2026-11-29 07:51:23 +00:00 by Leyukaka · 1 comment
Leyukaka commented 2026-11-29 07:51:23 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T07:51:23Z.


On main (eab7180c), 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 79410a80 (#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 40365770. The descriptor-stride branch of s_max_u32 against 1 in arithmetic (cmp("ugt",stride->second,"1") / cmp("ult",stride->second,"1"), from 350785e8, #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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6676324937 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3434). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T07:51:23Z. --- On `main` (eab7180c), 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`): ```python cast = 'int' if base.endswith('_i32') else '' return '(%s(%s) %s %s(%s))' % (cast, a, '<=' if base.startswith('s_min') else '>=', cast, b) ``` From 79410a80 (#2778). **Direct compute: S0 == S1 clears SCC.** `src/gfx1013_direct_compute.inl`, `arithmetic`: ```cpp 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: ```cpp body << "{uint lhs=" << a << ",rhs=" << b << ";scc=lhs" << (n == "s_min_u32" ? "<" : ">") << "rhs;" << d << "=scc?lhs:rhs;}\n"; ``` Both from 40365770. The descriptor-stride branch of `s_max_u32` against 1 in `arithmetic` (`cmp("ugt",stride->second,"1")` / `cmp("ult",stride->second,"1")`, from 350785e8, #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.
Leyukaka commented 2026-11-29 09:09:11 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T09:09:11Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7253571254 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3434#issuecomment-7253571254). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T09:09:11Z. --- 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 in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#3434
No description provided.