diff options
Diffstat (limited to 'scripts/run_gpu_tests.py')
| -rw-r--r-- | scripts/run_gpu_tests.py | 65 |
1 files changed, 60 insertions, 5 deletions
diff --git a/scripts/run_gpu_tests.py b/scripts/run_gpu_tests.py index 75bf851cc..ff52a3f9b 100644 --- a/scripts/run_gpu_tests.py +++ b/scripts/run_gpu_tests.py | |||
| @@ -129,7 +129,25 @@ def assemble_to_s(llvm_mc: str, asm_path: str, s_path: str, name: str) -> None: | |||
| 129 | f.write("\n".join(lines) + "\n") | 129 | f.write("\n".join(lines) + "\n") |
| 130 | 130 | ||
| 131 | 131 | ||
| 132 | def spirv_as(asm_text: str, out_spv: str) -> None: | 132 | def resolve_assembler(choice: str) -> str: |
| 133 | """Resolve --assembler choice ('auto', 'spirv-as', or 'python') to a concrete assembler name.""" | ||
| 134 | if choice in ("spirv-as", "python"): | ||
| 135 | return choice | ||
| 136 | if choice == "auto": | ||
| 137 | return "spirv-as" if shutil.which("spirv-as") else "python" | ||
| 138 | raise ValueError(f"unknown assembler: {choice!r}") | ||
| 139 | |||
| 140 | |||
| 141 | def spirv_as(asm_text: str, out_spv: str, assembler: str = "spirv-as") -> None: | ||
| 142 | if assembler == "python": | ||
| 143 | import spirv_asm | ||
| 144 | try: | ||
| 145 | spv_bytes = spirv_asm.assemble(asm_text, target_env="vulkan1.2") | ||
| 146 | except spirv_asm.SpirvAsmError as exc: | ||
| 147 | raise RuntimeError(f"spirv_asm failed for {out_spv}:\n{exc}") from None | ||
| 148 | with open(out_spv, "wb") as f: | ||
| 149 | f.write(spv_bytes) | ||
| 150 | return | ||
| 133 | p = subprocess.run(["spirv-as", "--target-env", "vulkan1.2", "-o", out_spv, "-"], | 151 | p = subprocess.run(["spirv-as", "--target-env", "vulkan1.2", "-o", out_spv, "-"], |
| 134 | input=asm_text, capture_output=True, text=True) | 152 | input=asm_text, capture_output=True, text=True) |
| 135 | if p.returncode != 0: | 153 | if p.returncode != 0: |
| @@ -699,12 +717,26 @@ def main() -> int: | |||
| 699 | ap.add_argument("--work", default=None) | 717 | ap.add_argument("--work", default=None) |
| 700 | ap.add_argument("--filter", default="") | 718 | ap.add_argument("--filter", default="") |
| 701 | ap.add_argument("--require-pass", action="store_true", help="exit 1 if no GPU test passes") | 719 | ap.add_argument("--require-pass", action="store_true", help="exit 1 if no GPU test passes") |
| 720 | ap.add_argument("--assembler", choices=("auto", "spirv-as", "python"), default="auto", | ||
| 721 | help="SPIR-V assembler: auto (use spirv-as if on PATH, else tools/spirv_asm.py), " | ||
| 722 | "spirv-as, or python") | ||
| 723 | ap.add_argument("--no-validate", action="store_true", | ||
| 724 | help="skip spirv-val during translation (automatic when --assembler resolves to python " | ||
| 725 | "and spirv-val is not on PATH)") | ||
| 726 | ap.add_argument("--disasm-dir", default=None, | ||
| 727 | help="folder of pre-disassembled <name>.s listings (e.g. tests/semantic/fixtures/disasm); " | ||
| 728 | "skips llvm-mc and runs only fixtures present there") | ||
| 702 | a = ap.parse_args() | 729 | a = ap.parse_args() |
| 703 | # Some test programs run with their working directory in <work>/spirv (vk_texture_test), so a relative path | 730 | # Some test programs run with their working directory in <work>/spirv (vk_texture_test), so a relative path |
| 704 | # given here would point somewhere else for them. | 731 | # given here would point somewhere else for them. |
| 705 | a.build = os.path.abspath(a.build) | 732 | a.build = os.path.abspath(a.build) |
| 706 | if a.work: | 733 | if a.work: |
| 707 | a.work = os.path.abspath(a.work) | 734 | a.work = os.path.abspath(a.work) |
| 735 | if a.disasm_dir is not None: | ||
| 736 | a.disasm_dir = os.path.abspath(a.disasm_dir) | ||
| 737 | if not os.path.isdir(a.disasm_dir): | ||
| 738 | print(f"error: --disasm-dir is not a directory: {a.disasm_dir}", file=sys.stderr) | ||
| 739 | return 2 | ||
| 708 | 740 | ||
| 709 | ext = ".exe" if os.name == "nt" else "" | 741 | ext = ".exe" if os.name == "nt" else "" |
| 710 | required = tuple(t + ext for t in TEST_PROGRAMS) | 742 | required = tuple(t + ext for t in TEST_PROGRAMS) |
| @@ -761,10 +793,24 @@ W64_GRAPHICS_ONLY = _w64_graphics_only() | |||
| 761 | 793 | ||
| 762 | 794 | ||
| 763 | def run_suite(a, work: str) -> int: | 795 | def run_suite(a, work: str) -> int: |
| 796 | assembler = resolve_assembler(getattr(a, "assembler", "auto")) | ||
| 797 | explicit_no_validate = bool(getattr(a, "no_validate", False)) | ||
| 798 | no_validate = explicit_no_validate or (assembler == "python" and shutil.which("spirv-val") is None) | ||
| 799 | disasm_src = getattr(a, "disasm_dir", None) | ||
| 800 | |||
| 764 | asm_files = sorted({f for f in os.listdir(SHADER_DIR) if f.endswith(".asm")} | {n + ".asm" for n in CLIP_CASES}) | 801 | asm_files = sorted({f for f in os.listdir(SHADER_DIR) if f.endswith(".asm")} | {n + ".asm" for n in CLIP_CASES}) |
| 765 | # The wave64 pixel fixtures of runtime/test/shaders/w64_graphics.py (tiers A-C, #1541) are checked by that | 802 | # The wave64 pixel fixtures of runtime/test/shaders/w64_graphics.py (tiers A-C, #1541) are checked by that |
| 766 | # runner, not here: they need a 64-wide fragment subgroup or the halves-aware lowering it drives. | 803 | # runner, not here: they need a 64-wide fragment subgroup or the halves-aware lowering it drives. |
| 767 | asm_files = [f for f in asm_files if f[:-4] not in W64_GRAPHICS_ONLY] | 804 | asm_files = [f for f in asm_files if f[:-4] not in W64_GRAPHICS_ONLY] |
| 805 | if disasm_src is not None: | ||
| 806 | available = {os.path.splitext(f)[0] for f in os.listdir(disasm_src) if f.endswith(".s")} | ||
| 807 | asm_files = [ | ||
| 808 | f for f in asm_files | ||
| 809 | if all(os.path.splitext(p)[0] in available for p in with_draw_shaders([f])) | ||
| 810 | ] | ||
| 811 | if not asm_files: | ||
| 812 | print(f"error: --disasm-dir {disasm_src!r} matched no GPU test cases", file=sys.stderr) | ||
| 813 | return 2 | ||
| 768 | if a.filter: | 814 | if a.filter: |
| 769 | asm_files = [f for f in asm_files if a.filter in f] | 815 | asm_files = [f for f in asm_files if a.filter in f] |
| 770 | if not asm_files: | 816 | if not asm_files: |
| @@ -813,7 +859,10 @@ def run_suite(a, work: str) -> int: | |||
| 813 | f.write(compute_header(os.path.join(SHADER_DIR, fname))) | 859 | f.write(compute_header(os.path.join(SHADER_DIR, fname))) |
| 814 | fname = shader_source(name) + ".asm" | 860 | fname = shader_source(name) + ".asm" |
| 815 | disasm_path = os.path.join(disasm_dir, f"{name}.s") | 861 | disasm_path = os.path.join(disasm_dir, f"{name}.s") |
| 816 | assemble_to_s(a.llvm_mc, os.path.join(SHADER_DIR, fname), disasm_path, name) | 862 | if disasm_src is not None: |
| 863 | shutil.copyfile(os.path.join(disasm_src, f"{name}.s"), disasm_path) | ||
| 864 | else: | ||
| 865 | assemble_to_s(a.llvm_mc, os.path.join(SHADER_DIR, fname), disasm_path, name) | ||
| 817 | disasm_files.append(disasm_path) | 866 | disasm_files.append(disasm_path) |
| 818 | # A failed translation must not run an old binary left in a reused --work directory. | 867 | # A failed translation must not run an old binary left in a reused --work directory. |
| 819 | Path(spirv_dir, f"{name}.spv").unlink(missing_ok=True) | 868 | Path(spirv_dir, f"{name}.spv").unlink(missing_ok=True) |
| @@ -823,6 +872,12 @@ def run_suite(a, work: str) -> int: | |||
| 823 | for path in disasm_files: | 872 | for path in disasm_files: |
| 824 | shutil.copyfile(path, os.path.join(selected_disasm, os.path.basename(path))) | 873 | shutil.copyfile(path, os.path.join(selected_disasm, os.path.basename(path))) |
| 825 | cmd = [sys.executable, "-I", TRANSLATOR, selected_disasm, "--out", spirv_dir] | 874 | cmd = [sys.executable, "-I", TRANSLATOR, selected_disasm, "--out", spirv_dir] |
| 875 | if assembler == "python": | ||
| 876 | cmd += ["--assembler", "python"] | ||
| 877 | if no_validate: | ||
| 878 | if not explicit_no_validate: | ||
| 879 | print("note: spirv-val not found on PATH; translating with --no-validate", flush=True) | ||
| 880 | cmd.append("--no-validate") | ||
| 826 | if w64_emulated(): # wave64 compute/mesh exact on any subgroup size | 881 | if w64_emulated(): # wave64 compute/mesh exact on any subgroup size |
| 827 | cmd.append("--wave64-emulate") | 882 | cmd.append("--wave64-emulate") |
| 828 | if bary_fallback(): # raw barycentrics from an interpolated input, fed by a pass-through GS | 883 | if bary_fallback(): # raw barycentrics from an interpolated input, fed by a pass-through GS |
| @@ -856,9 +911,9 @@ def run_suite(a, work: str) -> int: | |||
| 856 | vs_tri = os.path.join(spirv_dir, "vs_tri.spv") | 911 | vs_tri = os.path.join(spirv_dir, "vs_tri.spv") |
| 857 | fs_passthru = os.path.join(spirv_dir, "fs_passthru.spv") | 912 | fs_passthru = os.path.join(spirv_dir, "fs_passthru.spv") |
| 858 | fs_loc1 = os.path.join(spirv_dir, "fs_loc1.spv") | 913 | fs_loc1 = os.path.join(spirv_dir, "fs_loc1.spv") |
| 859 | spirv_as(VS_TRI_SPVASM, vs_tri) | 914 | spirv_as(VS_TRI_SPVASM, vs_tri, assembler=assembler) |
| 860 | spirv_as(make_fs_passthru(0), fs_passthru) | 915 | spirv_as(make_fs_passthru(0), fs_passthru, assembler=assembler) |
| 861 | spirv_as(make_fs_passthru(1), fs_loc1) | 916 | spirv_as(make_fs_passthru(1), fs_loc1, assembler=assembler) |
| 862 | 917 | ||
| 863 | index = {} | 918 | index = {} |
| 864 | idx_path = os.path.join(spirv_dir, "index.json") | 919 | idx_path = os.path.join(spirv_dir, "index.json") |