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
18 changes: 12 additions & 6 deletions src/gfx1013_direct_compute.inl
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,8 @@ struct DirectCompute {
n == "s_quadmask_b32" || n == "s_quadmask_b64" ||
n == "s_and_saveexec_b64" || n == "s_or_saveexec_b64" || n == "s_xor_saveexec_b64" ||
n == "s_andn2_saveexec_b64" || n == "s_orn2_saveexec_b64" ||
n == "s_nand_saveexec_b64" || n == "s_nor_saveexec_b64" || n == "s_xnor_saveexec_b64";
n == "s_nand_saveexec_b64" || n == "s_nor_saveexec_b64" || n == "s_xnor_saveexec_b64" ||
n == "s_andn2_wrexec_b64";
const bool overwrites = mask_scc || n == "s_abs_i32" ||
n == "s_bcnt0_i32_b32" || n == "s_bcnt1_i32_b32" ||
n == "s_bcnt0_i32_b64" || n == "s_bcnt1_i32_b64" ||
Expand Down Expand Up @@ -3139,12 +3140,16 @@ struct DirectCompute {
}
if ((i.enc == Encoding::Sop1 || i.enc == Encoding::Sop2) && n.size() > 6 && n.substr(n.size() - 4) == "_b64") {
bool save = n.find("_saveexec_") != Name::npos;
const bool wrexec = compute && wave64 && n == "s_andn2_wrexec_b64";
auto op = n.substr(2, n.find('_', 2) - 2);
if ((i.dst & 1) || (i.dst > 104 && i.dst != 106 && i.dst != 126) ||
(save && i.enc != Encoding::Sop1) || (!save && i.enc != Encoding::Sop2))
if (wrexec ? ((i.dst | i.src[0]) & 1) || i.dst > 104 || i.src[0] > 104
: (i.dst & 1) || (i.dst > 104 && i.dst != 106 && i.dst != 126) ||
(save ? i.enc != Encoding::Sop1 : i.enc != Encoding::Sop2))
refuse(i.pc, "unsupported wave64 scalar operation");
auto ah = pair_high(i, i.src[0]);
auto bl = save ? read(126) : b, bh = save ? read(127) : pair_high(i, i.src[1]);
const bool updates_exec = save || wrexec;
auto bl = updates_exec ? read(126) : b;
auto bh = updates_exec ? read(127) : pair_high(i, i.src[1]);
auto combine = [&](const string &left, const string &right) -> string {
if (op == "and" || op == "or" || op == "xor") return ir.binary(string(op), left, right);
if (op == "andn2" || op == "orn2")
Expand All @@ -3153,11 +3158,12 @@ struct DirectCompute {
return ir.binary("xor", ir.binary(op == "nand" ? "and" : op == "nor" ? "or" : "xor", left, right), "4294967295");
refuse(i.pc, "unsupported wave64 scalar mask operation");
};
// SAVEEXEC combines its source operand with the old EXEC in ISA operand order.
// SAVEEXEC and WREXEC combine the source with old EXEC in ISA operand order.
// WREXEC stores the new mask in the destination pair.
auto lo = combine(a, bl), hi = combine(ah, bh);
write(i.dst, save ? bl : lo);
write(i.dst + 1, save ? bh : hi);
if (save) { write(126, lo); write(127, hi); }
if (updates_exec) { write(126, lo); write(127, hi); }
write(128, ir.value("zext i1 " + cmp("ne", ir.binary("or", lo, hi), "0") + " to i32"));
return;
}
Expand Down
7 changes: 7 additions & 0 deletions tests/cmake/native_wrexec64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if(TARGET compile_dxil AND TARGET native_store_replay AND
EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll")
add_test(NAME native_wrexec64_hardware COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/native_wrexec64_check.py"
"$<TARGET_FILE:compile_dxil>" "$<TARGET_FILE:native_store_replay>" "${DXC_BIN_DIR}")
set_tests_properties(native_wrexec64_hardware PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
endif()
112 changes: 112 additions & 0 deletions tests/native_wrexec64_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
"""Check slot 67 wave64 WREXEC lane stores, destination words and SCC."""
from pathlib import Path
import struct
import subprocess
import sys
import tempfile

from native_compute_clear_check import write_request
from native_dpp_mirror_check import vop2
from native_scalar_lds_check import scalar, sop1, vmove


MOV_B32, ANDN2_WREXEC_B64 = 3, 0x3A
ZERO, ONE, NEG_ONE, LITERAL = 128, 129, 193, 255
EXEC_LO, EXEC_HI = 126, 127
OLD_EXEC = (0x80000012, 0x40000009)
GUARD_WORDS, OUTPUT_WORDS = 8, 2064
GROUP_WORDS, PLANE_WORDS = 128, 256
SENTINEL = 0x69696969
CASES = (
# X, source words, destination, incoming SCC, expected result, expected SCC
(64, (0x80000084, 0xC0000021), 24, 0, (0x84, 0x80000020), 1),
(128, (0x80000084, 0xC0000021), 24, 0, (0x84, 0x80000020), 1),
(128, (0x80000002, 0xC0000021), 22, 0, (0, 0x80000020), 1),
(64, OLD_EXEC, 24, 1, (0, 0), 0),
)


def program(source, dst, incoming_scc, src=22):
# s4 holds the table, s5 holds group.x and v0 holds local.x.
# v8 = 512 * group.x + 4 * local.x, calculated before narrowing EXEC.
words = [
sop1(MOV_B32, 20, 4), sop1(MOV_B32, 21, ZERO),
0xF408080A, 0xFA000020,
scalar(0x1E, 7, 5, ZERO + 9),
vop2(0x1A, 8, ZERO + 2, 0), vop2(0x25, 8, 7, 8),
0xBF8CC07F,
sop1(MOV_B32, EXEC_LO, LITERAL), OLD_EXEC[0],
sop1(MOV_B32, EXEC_HI, LITERAL), OLD_EXEC[1],
sop1(MOV_B32, 22, LITERAL), source[0],
sop1(MOV_B32, 23, LITERAL), source[1],
0xBF060080 | (ZERO if incoming_scc else ONE) << 8, # s_cmp_eq_u32
sop1(ANDN2_WREXEC_B64, dst, src),
0xE0701000, 0x80080008, # store v0 under the new EXEC
scalar(0x0A, 26, ONE, ZERO), # s_cselect_b32 captures SCC
sop1(MOV_B32, EXEC_LO, NEG_ONE), sop1(MOV_B32, EXEC_HI, NEG_ONE),
]
for plane, reg in enumerate((dst, dst + 1, 26), start=1):
words += [vmove(4, reg), 0xE0701000 | (plane * PLANE_WORDS * 4), 0x80080408]
return words + [0xBF810000]


def request(work, root, threads, words):
# .sa dword 4 bit 20 is clear, selecting the wave64 model.
sa = struct.pack("<7I", 0, 0, 0, threads | (1 << 16), 1, 0, 0x8A)
return write_request(work, words, root, sa)


def expected_output(threads, result, scc):
expected = [SENTINEL] * OUTPUT_WORDS
for group in range(2):
for local in range(threads):
index = GUARD_WORDS + group * GROUP_WORDS + local
lane = local % 64
if result[lane // 32] & (1 << (lane % 32)):
expected[index] = local
for plane, value in enumerate((*result, scc), start=1):
expected[index + plane * PLANE_WORDS] = value
return expected


def main(cli, replay, sdk):
with tempfile.TemporaryDirectory() as temp:
work = Path(temp)
shader, root_file = work / "root.hlsl", work / "root.bin"
shader.write_text('#define SIG "DescriptorTable(UAV(u0,numDescriptors=8))"')
subprocess.run([Path(sdk) / "dxc.exe", "-T", "rootsig_1_1", "-E", "SIG",
"-Fo", root_file, shader], check=True)
root = root_file.read_bytes()
cache = work / "cache"
compile_cmd = [cli, sdk, cache, "gfx1013-direct-cs@0"]
replay_cases = []
for threads, source, dst, incoming_scc, result, scc in CASES:
marker = request(work, root, threads, program(source, dst, incoming_scc))
output = marker.with_suffix(".cso")
compiled = subprocess.run([*compile_cmd, marker, output], capture_output=True, text=True)
assert compiled.returncode == 0 and output.is_file(), (compiled.stdout, compiled.stderr)
replay_cases.append((threads, result, scc, marker))

for src, dst in ((106, 24), (23, 24), (22, 25)):
marker = request(work, root, 64, program(CASES[0][1], dst, 0, src))
output = marker.with_suffix(".cso")
compiled = subprocess.run([*compile_cmd, marker, output], capture_output=True, text=True)
assert compiled.returncode != 0 and "unsupported wave64 scalar operation" in compiled.stderr, (
src, dst, compiled.stdout, compiled.stderr)
assert not output.exists(), output

for threads, result, scc, marker in replay_cases:
output = marker.with_suffix(".bin")
replayed = subprocess.run([replay, sdk, marker, cache, "0", output, "--direct"])
if replayed.returncode == 77:
return 77
replayed.check_returncode()
actual = struct.unpack(f"<{OUTPUT_WORDS}I", output.read_bytes())
for index, (got, want) in enumerate(zip(actual, expected_output(threads, result, scc))):
assert got == want, (threads, result, index, hex(got), hex(want))
print(f"wave64 X={threads}, EXEC={result[1]:08x}:{result[0]:08x}, SCC={scc} matched")
return 0


if __name__ == "__main__":
sys.exit(main(*sys.argv[1:]))
Loading