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
4 changes: 3 additions & 1 deletion src/gfx1013_direct_mesh.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,9 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout
const auto sum=ir.binary("add",lo,hi);
alu.write(i.dst,sum);
alu.write(128,ir.value("zext i1 "+alu.cmp("ne",sum,"0")+" to i32"));
} else if (i.name=="s_bfe_u32" || i.name=="s_min_u32") {
} else if (i.name=="s_bfe_u32" || i.name=="s_min_u32" || i.name=="s_bfe_i32" ||
i.name=="s_not_b32" || i.name=="s_brev_b32") {
// The shared scalar ALU lowers each one, SCC included (s_brev_b32 leaves it unchanged).
if (i.dst==126 || i.dst==127) refuse(pc,"mesh scalar write to EXEC");
if (i.dst==106 || i.dst==107) refuse(pc,"mesh scalar write to VCC");
alu.arithmetic(i,state);
Expand Down
38 changes: 38 additions & 0 deletions tests/native_direct_mesh_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,45 @@ def run(name, words, expected=None):
xor = re.search(r'(%[\w.]+) = xor i32 -2, -1\n', text)
assert xor, text
assert_position_x(text, r'and i32 ' + re.escape(xor[1]) + ',')
# s_not_b32, s_brev_b32 and s_bfe_i32 on the same s20 = -2 go through the shared scalar ALU.
movk = 0xb014fffe # s_movk_i32 s20, 0xfffe
use = 0x36020015 # v_and_b32 v1, s21, v0
text = run('scalar-not', program[:5] + [movk, 0xbe950714, use] + program[6:]) # s_not_b32 s21, s20
inverted = re.search(r'(%[\w.]+) = xor i32 -2, -1\n', text)
assert inverted, text
assert_position_x(text, r'and i32 ' + re.escape(inverted[1]) + ',')
text = run('scalar-brev', program[:5] + [movk, 0xbe950b14, use] + program[6:]) # s_brev_b32 s21, s20
reversed_bits = re.search(r'(%[\w.]+) = call i32 @dx\.op\.unary\.i32\(i32 30, i32 -2\)', text)
assert reversed_bits, text
assert_position_x(text, r'and i32 ' + re.escape(reversed_bits[1]) + ',')
# s_bfe_i32 s21, s20, 0x80004: 8 bits from bit 4, sign-extended (an arithmetic shift, not a logical one).
text = run('scalar-bfe-i32', program[:5] + [movk, 0x9415ff14, 0x00080004, use] + program[6:])
signed = re.search(r'(?P<shifted>%[\w.]+) = ashr i32 -2, %[\w.]+\n.*?'
r'(?P<up>%[\w.]+) = shl i32 (?P=shifted), (?P<pad>%[\w.]+)\n'
r'\s*%[\w.]+ = ashr i32 (?P=up), (?P=pad)\n', text, re.S)
assert signed and not re.search(r'= lshr i32 -2,', text), text
# SCC: s_cmp_eq_u32 s20, 0 sets it, then s_cselect_b32 s21, 1, 0 reads it after the op.
# s_brev_b32 leaves the compare's SCC; s_not_b32 replaces it with (result != 0).
compare, cselect = 0xbf068014, 0x85158081
text = run('scalar-brev-keeps-scc', program[:5] + [movk, compare, 0xbe960b14, # s_brev_b32 s22, s20
cselect, use] + program[6:])
kept_scc = re.search(r'(?P<cmp>%[\w.]+) = icmp eq i32 -2, 0\n\s*(?P<scc>%[\w.]+) = zext i1 (?P=cmp) to i32\n.*?'
r'(?P<test>%[\w.]+) = icmp ne i32 (?P=scc), 0\n\s*'
r'(?P<pick>%[\w.]+) = select i1 (?P=test), i32 1, i32 0\n', text, re.S)
assert kept_scc, text
assert_position_x(text, r'and i32 ' + re.escape(kept_scc['pick']) + ',')
text = run('scalar-not-sets-scc', program[:5] + [movk, compare, 0xbe960714, # s_not_b32 s22, s20
cselect, use] + program[6:])
not_scc = re.search(r'(?P<not>%[\w.]+) = xor i32 -2, -1\n.*?'
r'(?P<nz>%[\w.]+) = icmp ne i32 (?P=not), 0\n\s*(?P<scc>%[\w.]+) = zext i1 (?P=nz) to i32\n.*?'
r'(?P<test>%[\w.]+) = icmp ne i32 (?P=scc), 0\n\s*'
r'(?P<pick>%[\w.]+) = select i1 (?P=test), i32 1, i32 0\n', text, re.S)
assert not_scc, text
assert_position_x(text, r'and i32 ' + re.escape(not_scc['pick']) + ',')
for scalar_k_case, scalar_k_word, scalar_k_reason in (
('scalar-not-exec', 0xbefe0714, 'mesh scalar write to EXEC'), # s_not_b32 exec_lo, s20
('scalar-brev-vcc', 0xbeea0b14, 'mesh scalar write to VCC'), # s_brev_b32 vcc_lo, s20
('scalar-not-vcc-hi', 0xbeeb0714, 'mesh scalar write to VCC'), # s_not_b32 vcc_hi, s20
('scalar-movk-vcc', 0xb06afffe, 'unsupported mesh instruction or EXEC state: s_movk_i32'),
('scalar-movk-exec', 0xb07efffe, 'unsupported mesh instruction or EXEC state: s_movk_i32'),
('scalar-movk-m0', 0xb07cfffe, 'unsupported mesh instruction or EXEC state: s_movk_i32'),
Expand Down
Loading