diff --git a/docs/experiments/native-lane-access-compute.md b/docs/experiments/native-lane-access-compute.md index d6767e2ca0..4e94a56507 100644 --- a/docs/experiments/native-lane-access-compute.md +++ b/docs/experiments/native-lane-access-compute.md @@ -10,6 +10,8 @@ wave32 scalar pair read of VCC reads s106 and s107, as the hardware does. In wave64, `vcc_hi` holds the high half of the VCC mask. Refills carry numeric values and clear the destination's symbolic provenance. +Direct compute `s_mov_b32 exec_hi` stores a readable high word in wave32 and updates the upper-half EXEC mask in split wave64. + The source-built hardware fixture compares two 32-thread workgroups with a CPU reference and checks the untouched buffer words. It covers constant and SGPR selectors, writes to an EXEC-disabled lane, and lane reads feeding diff --git a/src/gfx1013_direct_compute.inl b/src/gfx1013_direct_compute.inl index fb6e462aea..9d1eef17e3 100644 --- a/src/gfx1013_direct_compute.inl +++ b/src/gfx1013_direct_compute.inl @@ -2002,7 +2002,8 @@ struct DirectCompute { return i.subword && j < 2 ? subword(value, i.src_select[j], i.src_sext[j]) : value; }; if (n == "s_mov_b32" || n == "s_mov_b64") { - if (i.dst > 106 && i.dst != 126 && !(compute && i.dst == 107) && !(wave64 && i.dst == 127)) + const bool exec_hi = i.dst == 127 && (wave64 || (compute && n == "s_mov_b32")); + if (i.dst > 106 && i.dst != 126 && !(compute && i.dst == 107) && !exec_hi) refuse(i.pc, "direct scalar move destination"); if (i.src[0] <= 105 && !state[i.src[0]].numeric()) { if (i.dst > 105) diff --git a/tests/cmake/native_smov_exec_hi.cmake b/tests/cmake/native_smov_exec_hi.cmake new file mode 100644 index 0000000000..dea0fb06ca --- /dev/null +++ b/tests/cmake/native_smov_exec_hi.cmake @@ -0,0 +1,10 @@ +if(X2W_HAVE_DXCAPI AND EXISTS "${INTAKE_PYTHON}") + add_test(NAME native_smov_exec_hi_wave64 + COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/native_smov_exec_hi_check.py" + wave64 "$" "${DXC_BIN_DIR}") + set_tests_properties(native_smov_exec_hi_wave64 PROPERTIES TIMEOUT 60) + add_test(NAME native_smov_exec_hi_hardware + COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/native_smov_exec_hi_check.py" + hardware "$" "${DXC_BIN_DIR}") + set_tests_properties(native_smov_exec_hi_hardware PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 60) +endif() diff --git a/tests/native_smov_exec_hi_check.py b/tests/native_smov_exec_hi_check.py new file mode 100644 index 0000000000..9d449d41fd --- /dev/null +++ b/tests/native_smov_exec_hi_check.py @@ -0,0 +1,89 @@ +"""Exercise EXEC_HI scalar moves in the direct compute frontend.""" +from pathlib import Path +import struct +import subprocess +import sys +import tempfile + +from native_compute_clear_check import write_request +from native_direct_container_check import compute, words +from native_dpp_mirror_check import vop2 +from native_scalar_lds_check import scalar, sop1, vmove + + +EXEC_LO, EXEC_HI = 126, 127 +END = 0xBF810000 +THREADS = 32 +LANES = 2 * THREADS +LOW_MASK = 0x9 +VALUES = (0x550055, 5, 0x80000002) +GUARD = 0x69696969 +OUTPUT_WORDS = 2064 + + +def mov(dst, src): + return sop1(3, dst, src) + + +def program(): + # Load the output UAV from the table in s4. v8 addresses one dword per lane. + code = [ + mov(20, 4), mov(21, 128), 0xF408080A, 0xFA000020, + scalar(0x1E, 7, 5, 135), # group.x * 128 + vop2(0x1A, 8, 130, 0), vop2(0x25, 8, 7, 8), + mov(EXEC_LO, 128 + LOW_MASK), + mov(EXEC_HI, 255), VALUES[0], mov(12, EXEC_HI), + 0xE0701000, 0x80080008, # store local.x under the narrowed EXEC + mov(EXEC_HI, 128 + VALUES[1]), mov(13, EXEC_HI), + mov(14, 255), VALUES[2], mov(EXEC_HI, 14), mov(15, EXEC_HI), + mov(EXEC_LO, 193), # restore all wave32 lanes for the readbacks + ] + for plane, reg in enumerate((12, 13, 15), start=1): + code.extend((vmove(4, reg), 0xE0701000 | (4 * LANES * plane), 0x80080408)) + return code + [END] + + +def reference(): + masked = tuple(lane if LOW_MASK & (1 << lane) else GUARD for lane in range(THREADS)) + readbacks = tuple(value for value in VALUES for _ in range(LANES)) + return (GUARD,) * 8 + masked * 2 + readbacks + (GUARD,) * (OUTPUT_WORDS - 8 - 4 * LANES) + + +def hardware(replay, sdk, work): + source = work / "root.hlsl" + root = work / "root.bin" + source.write_text('#define SIG "DescriptorTable(UAV(u0,numDescriptors=8))"') + subprocess.run([Path(sdk) / "dxc.exe", "-T", "rootsig_1_1", "-E", "SIG", + "-Fo", root, source], check=True) + sa = struct.pack("<7I", 0, 0, 0, THREADS | (1 << 16), 1 | (1 << 20), 0, 0x8A) + marker = write_request(work, program(), root.read_bytes(), sa) + output = work / "readback.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, reference())): + assert got == want, f"word {index}: got {got:#010x}, expected {want:#010x}" + return 0 + + +def wave64(cli, sdk, work): + source = work / "wave64" + output = work / "wave64.cso" + code = words(mov(EXEC_LO, 129), mov(EXEC_HI, 255), VALUES[0], mov(12, EXEC_HI), + mov(EXEC_HI, 128 + VALUES[1]), mov(13, EXEC_HI), + mov(14, 255), VALUES[2], mov(EXEC_HI, 14), mov(15, EXEC_HI), vmove(4, 15), END) + source.write_bytes(compute(code, threads=64, wave32=False)) + subprocess.run([cli, sdk, work / "cache", "gfx1013-container-cs", source, output], check=True) + assert output.read_bytes().startswith(b"DXBC") + return 0 + + +def main(mode, tool, sdk): + with tempfile.TemporaryDirectory() as temp: + return {"hardware": hardware, "wave64": wave64}[mode](tool, sdk, Path(temp)) + + +if __name__ == "__main__": + sys.exit(main(*sys.argv[1:]))