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
2 changes: 2 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ local second operand. A sparse EXEC mask distinguishes fetching an inactive
source, supplying zero and retaining the destination. The test checks both
workgroups and the surrounding buffer guards.

Wave32 direct compute lowers `s_or_saveexec_b32`. As with `s_mov_b32 exec_lo`, EXEC keeps bits past the group; a lane runs only if its own bit is set.

The pixel fixture opens EXEC to all lanes, seeds a guest register with scalar
lane writes and reads back lanes in each half of a guest wave64. The compiler
can track those words independently of the desktop rasterizer's choice of
Expand Down
4 changes: 4 additions & 0 deletions src/gfx1013_compute_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,10 @@ State transfer(const Inst &i, State s, bool wave64, bool graphics, bool heap_win
set(i.dst, v);
if (i.name == "s_mov_b64")
set(i.dst + 1, high);
} else if (!graphics && !wave64 && (i.name == "s_and_saveexec_b32" || i.name == "s_or_saveexec_b32")) {
// Both the saved EXEC and the updated EXEC are numeric mask words.
set(i.dst, {});
set(126, {});
} else if (i.name == "s_and_b32" || i.name == "s_lshl_b32") {
const auto a = source(i, i.src[0], s), b = source(i, i.src[1], s);
Symbol out{};
Expand Down
13 changes: 9 additions & 4 deletions src/gfx1013_direct_compute.inl
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,7 @@ struct DirectCompute {
inst.enc == Encoding::Sopc || n == "s_bfe_u32" || n == "s_and_b32" ||
n == "s_or_b32" || n == "s_max_u32" || n == "s_add_u32" || n == "s_sub_u32" ||
n == "s_add_i32" || n == "s_sub_i32" || n == "s_and_saveexec_b32" ||
n == "s_andn2_wrexec_b32" || n == "s_andn2_b32" || n == "s_orn2_b32" ||
n == "s_or_saveexec_b32" || n == "s_andn2_wrexec_b32" || n == "s_andn2_b32" || n == "s_orn2_b32" ||
n == "s_nor_b32" || n == "s_nand_b32" || n == "s_xnor_b32" || n == "s_not_b32" ||
n == "s_lshr_b32" || n == "s_lshl_b32" || n == "s_ashr_i32" ||
n == "s_lshl_b64" || n == "s_lshr_b64" || n == "s_ashr_i64" || n == "s_xor_b32" ||
Expand Down Expand Up @@ -2980,10 +2980,15 @@ struct DirectCompute {
write(128, ir.value("zext i1 " + cmp("ne", ir.binary("or", lo, hi), "0") + " to i32"));
return;
}
if (n == "s_and_saveexec_b32" || n == "s_andn2_wrexec_b32") {
const bool or_saveexec = n == "s_or_saveexec_b32" && compute && !wave64;
if (or_saveexec || n == "s_and_saveexec_b32" || n == "s_andn2_wrexec_b32") {
const bool save = n != "s_andn2_wrexec_b32";
if (or_saveexec && i.dst > 107)
refuse(i.pc, "unsupported wave32 SAVEEXEC destination");
auto old = read(126);
auto mask = ir.binary("and", a, n == "s_and_saveexec_b32" ? old : ir.binary("xor", old, "4294967295"));
write(i.dst, n == "s_and_saveexec_b32" ? old : mask);
// Like s_mov_b32 exec_lo, EXEC keeps every bit; a lane runs only if its own bit is set.
auto mask = ir.binary(or_saveexec ? "or" : "and", a, save ? old : ir.binary("xor", old, "4294967295"));
write(i.dst, save ? old : mask);
write(126, mask);
write(128, ir.value("zext i1 " + cmp("ne", mask, "0") + " to i32"));
return;
Expand Down
6 changes: 6 additions & 0 deletions tests/cmake/native_or_saveexec.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if(TARGET native_store_replay AND EXISTS "${INTAKE_PYTHON}" AND
EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll")
add_test(NAME native_or_saveexec_hardware COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/native_or_saveexec_check.py" "$<TARGET_FILE:native_store_replay>" "${DXC_BIN_DIR}")
set_tests_properties(native_or_saveexec_hardware PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 120)
endif()
4 changes: 4 additions & 0 deletions tests/native_direct_container_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ def check(name, profile, data, expected=""):
check("descriptor-sop1-before-scc-read", cs,
compute(words(*address_field, *pair_zero, ff1_pair, select_scc, end), table=True),
"numeric SCC from a symbolic descriptor field")
or_saveexec = 0xbe983dc1 # s_or_saveexec_b32 s24, -1
check("descriptor-or-saveexec-kill", cs, compute(words(*address_field, or_saveexec, read_scc, end), table=True))
check("or-saveexec-exec-destination", cs, compute(words(0xbefe3dc1, end)),
"unsupported wave32 SAVEEXEC destination")
# The previous symbolic SCC is dead at WQM. Reading it before WQM
# must still refuse. The nonzero high word supplies the new SCC.
numeric_wqm = [0xbe9a0380, 0xbe9b0381, 0xbe980a1a] # s[24:25] = WQM(s[26:27])
Expand Down
79 changes: 79 additions & 0 deletions tests/native_or_saveexec_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"""Direct wave32 s_or_saveexec_b32: saved EXEC, the OR result, SCC and a restore, in full and partial waves."""
from pathlib import Path
import struct
import subprocess
import sys
import tempfile

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


def or_saveexec_readback(work, gpu, sdk):
full = 0xffffffff
root = (work / "root.bin").read_bytes()
for width in (8, 32):
entry = (1 << width) - 1
sa = struct.pack("<7I", 0, 0, 0, width | 1 << 16, 1, 0, 0x80 | 5 << 1)
for name, old, src, mask in (
("all", 0x25, 193, full),
("sgpr", 0x25, 10, 0x80000092), # Source aliases the saved EXEC destination.
("literal", 0x25, 255, 0x80000018),
("vcc", 0x25, 106, 0x80000042),
("empty", 0, 128, 0),
("past-end", 0, 255, 0x80000000),
):
updated = old | mask # EXEC is stored as computed, including bits past the group
words = [sop1(3, 20, 4), sop1(3, 21, 128), 0xf408080a, 0xfa000020,
scalar(0x1e, 7, 5, 137), 0x34000000 | 8 << 17 | 132,
0x4a000000 | 8 << 17 | 8 << 9 | 7,
sop1(0x3c, 24, 255), old]
if src in (10, 106):
words += [sop1(3, src, 255), mask]
if name == "all":
words.append(sop1(3, 10, 32)) # Replace symbolic descriptor provenance with numeric EXEC.
if name == "vcc":
# Derive the same partial EXEC through S_ANDN2_WREXEC_B32.
words += [sop1(3, 126, 255), entry ^ old, sop1(0x47, 25, 24)]
# Set the incoming SCC opposite to the expected new SCC.
words += [0xbf068180 if updated else 0xbf068080, sop1(0x3d, 10, src)]
if src == 255:
words.append(mask)
words += [scalar(0xa, 11, 129, 128), vmove(9, 10), vmove(10, 126),
0xe0701000, 0x80080908, 0xe0701004, 0x80080a08,
sop1(3, 126, 10), vmove(9, 177), 0xe0701008, 0x80080908,
sop1(3, 126, 24), vmove(9, 11), 0xe070100c, 0x80080908,
0xbf810000]
expected = [0x69696969] * 2064
for group in range(2):
for lane in range(width):
pos = 8 + group * 128 + lane * 4
if updated & (1 << lane):
expected[pos:pos + 2] = [old, updated]
if old & (1 << lane):
expected[pos + 2] = 49
expected[pos + 3] = int(bool(updated))
marker = write_request(work, words, root, sa)
dest = work / "or-saveexec.bin"
result = subprocess.run([gpu, sdk, marker, work / "cache", "0", dest, "--direct"])
if result.returncode == 77:
sys.exit(77)
result.check_returncode()
actual = struct.unpack("<2064I", dest.read_bytes())
assert list(actual) == expected, (width, name, [
(i, a, b) for i, (a, b) in enumerate(zip(actual, expected)) if a != b
][:10])


def main(gpu, sdk):
with tempfile.TemporaryDirectory() as temp:
work = Path(temp)
src, root = work / "root.hlsl", work / "root.bin"
src.write_text('#define SIG "DescriptorTable(UAV(u0,numDescriptors=8))"')
subprocess.run([Path(sdk) / "dxc.exe", "-T", "rootsig_1_1", "-E", "SIG", "-Fo", root, src], check=True)
or_saveexec_readback(work, gpu, sdk)
print("s_or_saveexec_b32 matched six sources in 8- and 32-thread groups, with SCC, restore and guards.")


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