diff --git a/src/gfx1013_compute_native.cpp b/src/gfx1013_compute_native.cpp index 18721c14c..0e8b4a7af 100644 --- a/src/gfx1013_compute_native.cpp +++ b/src/gfx1013_compute_native.cpp @@ -716,6 +716,14 @@ State transfer(const Inst &i, State s, bool wave64, bool graphics, bool heap_win // Both the saved/written destination and the updated EXEC are numeric mask words. set(i.dst, {}); set(126, {}); + } else if (!graphics && i.enc == Encoding::Sop1 && i.name.size() >= 13 && + (i.name.substr(i.name.size() - 13) == "_saveexec_b64" || + i.name.substr(i.name.size() - 11) == "_wrexec_b64")) { + // These instructions also overwrite both EXEC words implicitly. + set(i.dst, {}); + set(i.dst + 1, {}); + set(126, {}); + set(127, {}); } 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{}; diff --git a/tests/cmake/native_exec_symbol_b64.cmake b/tests/cmake/native_exec_symbol_b64.cmake new file mode 100644 index 000000000..c39593c99 --- /dev/null +++ b/tests/cmake/native_exec_symbol_b64.cmake @@ -0,0 +1,7 @@ +if(TARGET compile_dxil AND EXISTS "${INTAKE_PYTHON}" AND + EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll") + add_test(NAME native_exec_symbol_b64_controls COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/native_exec_symbol_b64_check.py" + controls "$" "${DXC_BIN_DIR}") + set_tests_properties(native_exec_symbol_b64_controls PROPERTIES TIMEOUT 60) +endif() diff --git a/tests/native_exec_symbol_b64_check.py b/tests/native_exec_symbol_b64_check.py new file mode 100644 index 000000000..a6349abda --- /dev/null +++ b/tests/native_exec_symbol_b64_check.py @@ -0,0 +1,47 @@ +"""Reject a sampler word copied from EXEC after a 64-bit implicit write.""" +from pathlib import Path +import subprocess +import sys +import tempfile + +from native_direct_container_check import comparison_program, compute, words + + +def program(exec_op=None): + code = comparison_program(dim=5) + sampler_address = code[4] + code[3:5] = [ + 0x7e2c0500, # v_readfirstlane_b32 s22, v0 + 0xbe970380, # s_mov_b32 s23, 0 + 0xbefe04ff, sampler_address, # s_mov_b64 exec, comparison sampler word + *(() if exec_op is None else (exec_op,)), + 0xbe84037e, # s_mov_b32 s4, exec_lo + ] + return compute(words(*code, 0xbf810000), threads=64, table=True, wave32=False) + + +def controls(cli, sdk): + with tempfile.TemporaryDirectory() as temp: + work = Path(temp) + for name, exec_op in ( + ("constant-exec", None), + ("saveexec", 0xbe982416), # s_and_saveexec_b64 s[24:25], s[22:23] + ("wrexec", 0xbe983a16), # s_andn2_wrexec_b64 s[24:25], s[22:23] + ): + source = work / (name + ".cdx") + output = source.with_suffix(".cso") + source.write_bytes(program(exec_op)) + result = subprocess.run( + [cli, sdk, work / "cache", "gfx1013-container-cs", source, output], + capture_output=True, text=True, + ) + if exec_op is None: + assert result.returncode == 0 and output.read_bytes().startswith(b"DXBC"), (name, result.stderr) + else: + assert result.returncode != 0 and "nonconstant sampler" in result.stderr, (name, result.stderr) + assert not output.exists(), output + + +if __name__ == "__main__": + mode, cli, sdk = sys.argv[1:] + {"controls": controls}[mode](cli, sdk)