Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/gfx1013_direct_mesh.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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()<code.size()) {
if (exec_skip) {
Expand Down
36 changes: 36 additions & 0 deletions tests/native_direct_mesh_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ def v_cmpx_lt_u32_words(program, src0, vsrc1, prepare=()):
return program[:7] + body + program[7:]


def v_cmpx_words(program, compare, prepare=()):
# Like v_cmpx_lt_u32_words, for any VOPC (or VOP3) CMPX encoding.
body = [
0xBE96047E, # s_mov_b64 s[22:23], exec
*prepare,
*compare,
0xBF880001, # s_cbranch_execz +1
0x7E020282, # v_mov_b32 v1, 2
0xBEFE0416, # s_mov_b64 exec, s[22:23]
]
return program[:7] + body + program[7:]


def assert_cmpx_ne(text, predicate):
value = r'%[\w.]+'
pred = re.search(rf'(?P<pred>{value}) = {predicate}\n', text)
Expand Down Expand Up @@ -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<same>{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
Expand Down
Loading