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
6 changes: 4 additions & 2 deletions docs/experiments/native-salu64-ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ offset, writes both words of an aligned SGPR pair, and preserves SCC.
`s_not_b64` complements both words and sets SCC when either result word
is nonzero. Both take aligned SGPR pairs or constants, with sign extension
for inline negatives and zero extension for other integers. They can
write VCC as a pair. `s_bfm_b64` may also write EXEC, as both words, in wave32
and wave64. `s_cselect_b64` and `s_not_b64` still refuse EXEC destinations.
write VCC as a pair. `s_bfm_b64` and `s_not_b64` may also write EXEC, as both
words, in wave32 and wave64. `s_cselect_b64` still refuses EXEC destinations.
`s_not_b64` and `s_cselect_b64` also take VCC and EXEC as 64-bit sources
(`tests/native_s_not_b64_exec_check.py`, `ctest --preset dev --no-tests=error -R '^native_s_not_b64_exec_'`).

Direct compute also accepts `s_bitreplicate_b64_b32 exec, imm`, writing both EXEC words and preserving SCC. Wave32 lane activity uses only `exec_lo`.

Expand Down
22 changes: 13 additions & 9 deletions src/gfx1013_direct_compute.inl
Original file line number Diff line number Diff line change
Expand Up @@ -2912,25 +2912,29 @@ struct DirectCompute {
return;
}
if (compute && (n == "s_cselect_b64" || n == "s_not_b64")) {
if ((i.dst & 1) || (i.dst > 104 && i.dst != 106))
const bool invert = n == "s_not_b64";
if ((i.dst & 1) || (i.dst > 104 && i.dst != 106 && !(invert && i.dst == 126)))
refuse(i.pc, "invalid " + string(n) + " destination");
auto high = [&](unsigned src) {
if (src == 106 || src == 126)
auto scalar64 = [&](unsigned src) -> std::pair<string, string> {
if (!((src <= 104 && !(src & 1)) || src == 106 || src == 126 ||
(src >= 128 && src <= 208) || src == 255))
refuse(i.pc, "invalid " + string(n) + " source");
return pair_high(i, src);
return {operand32(i, src), pair_high(i, src)};
};
auto lo = val(0), hi = high(i.src[0]);
if (n == "s_cselect_b64") {
auto [lo, hi] = scalar64(i.src[0]);
if (!invert) {
auto [other_lo, other_hi] = scalar64(i.src[1]);
auto condition = cmp("ne", read(128), "0");
lo = select(condition, lo, val(1));
hi = select(condition, hi, high(i.src[1]));
lo = select(condition, lo, other_lo);
hi = select(condition, hi, other_hi);
} else {
lo = ir.binary("xor", lo, "4294967295");
hi = ir.binary("xor", hi, "4294967295");
write(128, ir.value("zext i1 " + cmp("ne", ir.binary("or", lo, hi), "0") + " to i32"));
}
write(i.dst, lo);
write(i.dst + 1, hi);
if (invert)
write(128, ir.value("zext i1 " + cmp("ne", ir.binary("or", lo, hi), "0") + " to i32"));
return;
}
if (compute && (n == "s_lshl_b64" || n == "s_lshr_b64" || n == "s_ashr_i64")) {
Expand Down
12 changes: 12 additions & 0 deletions tests/cmake/native_s_not_b64_exec.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if(TARGET compile_dxil AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll")
add_test(NAME native_s_not_b64_exec_controls COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/native_s_not_b64_exec_check.py" controls
"$<TARGET_FILE:compile_dxil>" "${DXC_BIN_DIR}")
set_tests_properties(native_s_not_b64_exec_controls PROPERTIES TIMEOUT 60)
if(TARGET native_store_replay)
add_test(NAME native_s_not_b64_exec_hardware COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/native_s_not_b64_exec_check.py" hardware
"$<TARGET_FILE:native_store_replay>" "${DXC_BIN_DIR}")
set_tests_properties(native_s_not_b64_exec_hardware PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60)
endif()
endif()
143 changes: 143 additions & 0 deletions tests/native_s_not_b64_exec_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
"""Compile and replay 64-bit NOT and CSELECT with the compute mask registers."""
from pathlib import Path
import struct
import subprocess
import sys
import tempfile

from native_scalar_lds_check import scalar, sop1, vmove
from native_wave64_exec_salu_check import (
END, EXEC, GROUP_STRIDE_WORDS, GUARD_WORDS, NEG_ONE, OUTPUT_WORDS,
SENTINEL, VCC, ZERO, compile_request, request,
)


NOT_B64, CSELECT_B64 = 0x08, 0x0B
MOV_B32, MOV_B64, LITERAL = 3, 4, 255
M0, RESULT = 124, 24
MASK32, MASK64 = (1 << 32) - 1, (1 << 64) - 1
EXEC_MASK = 0xA5600FF00F0FF00F
VCC_MASK = 0x3150C4D2FFFFFFFF
PLANE_WORDS = 2 * GROUP_STRIDE_WORDS
CASES = ("not_exec", "not_vcc", "not_vcc_all_ones", "select_scc0", "select_scc1", "not_into_exec")


def move_pair(dst, bits):
return [sop1(MOV_B32, dst, LITERAL), bits & MASK32,
sop1(MOV_B32, dst + 1, LITERAL), bits >> 32]


def set_scc(value):
# s_cmp_eq_u32 0, 0 (SCC = 1) or s_cmp_eq_u32 0, 1 (SCC = 0).
return 0xBF060000 | (ZERO + (1 - value)) << 8 | ZERO


def store(vgpr, plane):
return [0xE0701000 | (4 * PLANE_WORDS * plane), 0x80080008 | vgpr << 8]


def program(case):
# Prepare every lane's address before narrowing EXEC. The shader uses
# the same two-group UAV layout as the wave64 EXEC SALU fixture.
words = [
sop1(MOV_B64, EXEC, NEG_ONE),
sop1(MOV_B32, 20, 4), sop1(MOV_B32, 21, ZERO),
0xF408080A, 0xFA000020, # s_load_dwordx4 s[32:35], s[20:21], 0x20
scalar(0x1E, 7, 5, ZERO + 9), # s_lshl_b32 s7, s5, 9
0x34100082, # v_lshlrev_b32 v8, 2, v0
0x4A101007, # v_add_nc_u32 v8, s7, v8
]
words += move_pair(EXEC, EXEC_MASK)
words += move_pair(VCC, MASK64 if case == "not_vcc_all_ones" else VCC_MASK)
if case.startswith("select"):
words += [set_scc(int(case[-1])), scalar(CSELECT_B64, RESULT, EXEC, VCC)]
elif case == "not_into_exec":
words += [set_scc(0), sop1(NOT_B64, EXEC, EXEC), *store(0, 0)]
# Save both new EXEC words before restoring all lanes for readback.
words.append(sop1(MOV_B64, RESULT, EXEC))
else:
source = EXEC if case == "not_exec" else VCC
words += [set_scc(int(case == "not_vcc_all_ones")), sop1(NOT_B64, RESULT, source)]

words += [sop1(MOV_B64, EXEC, NEG_ONE), scalar(0x0A, RESULT + 2, ZERO + 1, ZERO)]
for plane, src in enumerate((RESULT, RESULT + 1, RESULT + 2), start=1):
words += [vmove(1, src), *store(1, plane)]
return words + [END]


def expected_words(wave_size, case):
if case.startswith("select"):
scc = int(case[-1])
result = EXEC_MASK if scc else VCC_MASK
else:
source = {"not_exec": EXEC_MASK, "not_vcc": VCC_MASK,
"not_vcc_all_ones": MASK64, "not_into_exec": EXEC_MASK}[case]
result = source ^ MASK64
scc = int(result != 0)
expected = [SENTINEL] * OUTPUT_WORDS
for group in range(2):
for lane in range(wave_size):
index = GUARD_WORDS + group * GROUP_STRIDE_WORDS + lane
if case == "not_into_exec" and result & (1 << lane):
expected[index] = lane
for plane, value in enumerate((result & MASK32, result >> 32, scc), start=1):
expected[index + plane * PLANE_WORDS] = value
return expected


def controls(cli, sdk, work, root):
cache = work / "cache"
failures = []
for wave_size in (32, 64):
for case in CASES:
marker = request(work, root, wave_size, wave_size, program(case))
output, result = compile_request(cli, sdk, cache, marker)
if result.returncode or not output.is_file():
failures.append((wave_size, case, result.stdout, result.stderr))
assert not failures, failures

prefix = [sop1(MOV_B32, 23, ZERO), sop1(MOV_B32, M0, ZERO), set_scc(1)]
refusals = [
(sop1(NOT_B64, RESULT, src), "invalid s_not_b64 source")
for src in (23, M0)
] + [
(scalar(CSELECT_B64, RESULT, a, b), "invalid s_cselect_b64 source")
for src in (23, M0) for a, b in ((src, ZERO), (ZERO, src))
] + [(scalar(CSELECT_B64, EXEC, ZERO, ZERO), "invalid s_cselect_b64 destination")]
for instruction, error in refusals:
marker = request(work, root, 64, 64, prefix + [instruction, END])
output, result = compile_request(cli, sdk, cache, marker)
assert result.returncode and error in result.stderr, (error, result.stdout, result.stderr)
assert not output.exists(), output
print("Wave32 and wave64 compile controls and invalid operand refusals passed")
return 0


def hardware(replay, sdk, work, root):
for wave_size in (32, 64):
for case in CASES:
marker = request(work, root, wave_size, wave_size, program(case))
output = work / f"wave{wave_size}_{case}.bin"
result = subprocess.run([replay, sdk, marker, work / "cache", "0", output, "--direct"])
if result.returncode == 77:
return 77
result.check_returncode()
actual = struct.unpack(f"<{OUTPUT_WORDS}I", output.read_bytes())
for index, (got, want) in enumerate(zip(actual, expected_words(wave_size, case))):
assert got == want, (wave_size, case, index, hex(got), hex(want))
print(f"wave{wave_size} {case}: both groups and guards matched")
return 0


def main(mode, tool, 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)
return {"controls": controls, "hardware": hardware}[mode](tool, sdk, work, root_file.read_bytes())


if __name__ == "__main__":
sys.exit(main(*sys.argv[1:]))
2 changes: 1 addition & 1 deletion tests/native_salu64_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def compute_program(instructions, dst):

def controls(cli, sdk, work, root):
for words, error in (([scalar(CSELECT, 126, NEG_ONE, ZERO), 0xBF810000], "invalid s_cselect_b64 destination"),
([sop1(NOT, 24, 106), 0xBF810000], "invalid s_not_b64 source")):
([sop1(NOT, 24, 127), 0xBF810000], "invalid s_not_b64 source")):
marker = request(work, root, words)
output = marker.with_suffix(".cso")
result = subprocess.run([cli, sdk, work / "cache", "gfx1013-direct-cs@0", marker, output],
Expand Down
Loading