From e325352364980fb1c3116b18146682b56f8ea263 Mon Sep 17 00:00:00 2001 From: Luuk Motz Date: Tue, 1 Dec 2026 12:48:59 +0100 Subject: [PATCH] shader: lower v_cmpx_lg_f32, v_cmpx_gt_f32 and per-lane v_cmpx_gt_u32 in the mesh frontend The mesh frontend narrowed EXEC only for v_cmpx_eq_u32, ne_u32 and lt_u32, and for v_cmpx_gt_u32 only in the lane-linear count form. Mesh86 programs also use v_cmpx_lg_f32, v_cmpx_gt_f32 and a per-lane v_cmpx_gt_u32. They now get the same EXEC-only narrowing through the shared compare: lg is an ordered fcmp one and gt_f32 an ordered ogt, so a NaN lane leaves EXEC, and gt_u32 is icmp ugt. The count form of v_cmpx_gt_u32 is still matched first. Float abs/neg, SDWA, DPP, clamp and omod stay refused. Part of #3703. Co-Authored-By: Claude Opus 5.5 --- src/gfx1013_direct_mesh.inl | 11 ++++++++++ tests/native_direct_mesh_check.py | 36 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/gfx1013_direct_mesh.inl b/src/gfx1013_direct_mesh.inl index abc97056b8..72792a9d8d 100644 --- a/src/gfx1013_direct_mesh.inl +++ b/src/gfx1013_direct_mesh.inl @@ -1355,6 +1355,17 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout lane_active=full_exec ? pred : ir.value("and i1 "+before+", "+pred); mask_parent[lane_active]=before; full_exec=false; wave_active.clear(); exec_value[0].clear();exec_value[1].clear(); + } else if ((i.name=="v_cmpx_lg_f32" || i.name=="v_cmpx_gt_f32" || i.name=="v_cmpx_gt_u32") && + !branch && !i.dpp_control && !i.subword && !i.abs && !i.neg && + !i.scale && !i.clamp && (full_exec || !lane_active.empty())) { + // The same EXEC-only narrowing as v_cmpx_lt_u32. The shared compare gives + // lg as an ordered fcmp one and gt as ogt, so a NaN lane leaves EXEC. + // The lane-linear v_cmpx_gt_u32 count form above is matched first. + const auto before=lane_active; + auto pred=alu.comparison(i); + lane_active=full_exec ? pred : ir.value("and i1 "+before+", "+pred); + mask_parent[lane_active]=before; + full_exec=false; wave_active.clear(); exec_value[0].clear();exec_value[1].clear(); } else if (i.name=="s_cbranch_execz" && !full_exec && !lane_active.empty() && !branch && i.target()>i.next && i.target(){value}) = {predicate}\n', text) @@ -345,6 +358,29 @@ def run(name, words, expected=None): signed = v_cmpx_lt_u32_words(program, 256, 2, (_v_mov_b32(2, _inline_u32(2)),)) signed[9] = _vopc(0x91, 256, 2) # v_cmpx_lt_i32 v0, v2 stays refused run('v-cmpx-lt-i32-refused', signed, 'unsupported mesh instruction or EXEC state: v_cmpx_lt_i32') + # v_cmpx_gt_u32 outside the lane-linear count form narrows EXEC per lane with icmp ugt. + assert_cmpx_ne(run('v-cmpx-gt-u32-lanes', v_cmpx_words( + program, [_vopc(0xD4, 256, 2)], (_v_mov_b32(2, _inline_u32(2)),))), rf'icmp ugt i32 {lane}, 2') + assert_cmpx_ne(run('v-cmpx-gt-u32-unsigned', v_cmpx_words( + program, [_vopc(0xD4, _inline_u32(0xFFFFFFFF), 2)], (_v_mov_b32(2, _inline_u32(0)),))), + rf'icmp ugt i32 {_ir_u32(0xFFFFFFFF)}, 0') + assert_cmpx_ne(run('v-cmpx-gt-u32-empty', v_cmpx_words(program, [_vopc(0xD4, 256, 0)])), + rf'icmp ugt i32 (?P{lane}), (?P=same)') + run('v-cmpx-gt-i32-refused', v_cmpx_words(program, [_vopc(0x94, 256, 0)]), + 'unsupported mesh instruction or EXEC state: v_cmpx_gt_i32') + # v_cmpx_gt_f32 1.0, v2 (VOPC 0x14) and v_cmpx_lg_f32 1.0, v2 (0x15) are ordered: + # a NaN in v2 fails both, so that lane leaves EXEC. + half = (_v_mov_b32(2, 240),) # v_mov_b32 v2, 0.5 + nan = (_v_mov_b32(2, 255), 0x7FC00000) # v_mov_b32 v2, quiet NaN + for name, opcode, predicate in (('gt', 0x14, 'ogt'), ('lg', 0x15, 'one')): + for case, prepare in (('half', half), ('nan', nan)): + text = run(f'v-cmpx-{name}-f32-{case}', v_cmpx_words(program, [_vopc(opcode, 242, 2)], prepare)) + assert_cmpx_ne(text, rf'fcmp {predicate} float {lane}, {lane}') + assert not re.search(r'fcmp u\w+ float', text), text + # |v2| on the VOP3 form stays refused: the shared compare ignores float modifiers. + abs_lg = [0xD415026A, 242 | (258 << 9)] # v_cmpx_lg_f32 vcc, 1.0, |v2| + run('v-cmpx-lg-f32-abs', v_cmpx_words(program, abs_lg, half), + 'unsupported mesh instruction or EXEC state: v_cmpx_lg_f32') # Two scalar tests select either EXEC or zero. Their OR still gives # every active lane the same bit for CNDMASK and READFIRSTLANE. wave = [0x9396ff03, 0x40018] # s_bfe_u32 s22, s3, 0x40018