diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/run_gpu_tests.py | 16 | ||||
| -rw-r--r-- | scripts/vs_input_survey.py | 134 |
2 files changed, 149 insertions, 1 deletions
diff --git a/scripts/run_gpu_tests.py b/scripts/run_gpu_tests.py index b63617b6e..d5fb01b64 100644 --- a/scripts/run_gpu_tests.py +++ b/scripts/run_gpu_tests.py | |||
| @@ -493,7 +493,8 @@ DRAWN_WITH = {GATHER_LOD_TEST: "vs_ids.asm", "ps_flat": "vs_ids.asm", "ps_textur | |||
| 493 | "ps_gather_wrap": "vs_ids.asm", | 493 | "ps_gather_wrap": "vs_ids.asm", |
| 494 | **{name: "vs_ids.asm" for name in GRADIENT_TESTS}, "vs_clip": "ps_ops.asm", | 494 | **{name: "vs_ids.asm" for name in GRADIENT_TESTS}, "vs_clip": "ps_ops.asm", |
| 495 | "ps_interp_f16_high": "vs_f16_pack.asm", "ms_f16_pack": "ps_interp_f16_high.asm", | 495 | "ps_interp_f16_high": "vs_f16_pack.asm", "ms_f16_pack": "ps_interp_f16_high.asm", |
| 496 | "ps_interp_f32_mods": "vs_interp_consts.asm", "ps_interp_mov_mods": "vs_interp_consts.asm"} | 496 | "ps_interp_f32_mods": "vs_interp_consts.asm", "ps_interp_mov_mods": "vs_interp_consts.asm", |
| 497 | "vs_base_ids": "ps_flat.asm"} | ||
| 497 | 498 | ||
| 498 | 499 | ||
| 499 | def with_draw_shaders(asm_files: list[str]) -> list[str]: | 500 | def with_draw_shaders(asm_files: list[str]) -> list[str]: |
| @@ -1087,6 +1088,19 @@ def run_suite(a, work: str) -> int: | |||
| 1087 | else: | 1088 | else: |
| 1088 | ok, detail = check_clip_half(raw, 0.5, 1.0) | 1089 | ok, detail = check_clip_half(raw, 0.5, 1.0) |
| 1089 | results.append((name, ok, detail)) | 1090 | results.append((name, ok, detail)) |
| 1091 | elif name == "vs_base_ids": | ||
| 1092 | # Zero-based v0 / v3 (the hardware's VS input VGPRs): drawn with firstVertex 16 and firstInstance 7, | ||
| 1093 | # ps_flat must still see vertex 0 of instance 0 (0x101), as check.py checks. | ||
| 1094 | raw = os.path.join(raw_dir, f"{name}.raw") | ||
| 1095 | env = dict(gfx_env or os.environ, VKH_DRAW="16,7") | ||
| 1096 | rc, msg = run_cmd([vk_harness, spv, os.path.join(spirv_dir, "ps_flat.spv"), raw], env=env) | ||
| 1097 | if rc == UNSUPPORTED: | ||
| 1098 | results.append((name, None, unsupported_skip(msg))) | ||
| 1099 | elif rc != 0: | ||
| 1100 | results.append((name, False, msg)) | ||
| 1101 | else: | ||
| 1102 | ok, detail = check_flat(raw) | ||
| 1103 | results.append((name, ok, detail)) | ||
| 1090 | 1104 | ||
| 1091 | if a.filter and not results: # the filter matched only inputs/partners: say so rather than "0/0 passed" | 1105 | if a.filter and not results: # the filter matched only inputs/partners: say so rather than "0/0 passed" |
| 1092 | names = [os.path.splitext(f)[0] for f in asm_files] | 1106 | names = [os.path.splitext(f)[0] for f in asm_files] |
diff --git a/scripts/vs_input_survey.py b/scripts/vs_input_survey.py new file mode 100644 index 000000000..e1da657ff --- /dev/null +++ b/scripts/vs_input_survey.py | |||
| @@ -0,0 +1,134 @@ | |||
| 1 | """SHADER-33: which hardware vertex-shader layout the corpus uses (legacy VS or NGG), and which input VGPRs it reads. | ||
| 2 | |||
| 3 | python -I scripts/vs_input_survey.py <work>/shaders/dxbc [--json OUT] | ||
| 4 | |||
| 5 | Reads <dxbc>/index.json (stage per shader) and <dxbc>/disasm/<name>.s (shader_disasm.py) for every vertex shader and | ||
| 6 | prints counts only: | ||
| 7 | |||
| 8 | - NGG markers: `exp prim` (primitive export), `s_sendmsg` (NGG needs GS_ALLOC_REQ) and `v_mbcnt` (NGG thread ids). | ||
| 9 | A legacy (non-NGG) hardware VS has none of them and exports `pos0` / `param` only. | ||
| 10 | - Registers read before written, straight-line, from the start of the program: the same rule as #240's | ||
| 11 | scripts/audit_shader4_regs.py (by @eIBart0) uses for CS/MS/GS. In the legacy GFX10 VS layout (Mesa | ||
| 12 | radv_shader_args.c, declare_vs_input_vgprs, not is_ngg) v0 = vertex id, v1 unused, v2 = primitive id, | ||
| 13 | v3 = instance id; in an NGG VS merged with GS the VS inputs start at v5 (vertex id) / v8 (instance id). | ||
| 14 | - The fetch call: `s_swappc_b64 s[4:5], s[4:5]` at the start of a VS calls the driver's fetch program, which reads | ||
| 15 | v0 itself and leaves the attributes in v4 and up. | ||
| 16 | |||
| 17 | Standard library only. Nothing from the game is printed or written beyond counts. | ||
| 18 | """ | ||
| 19 | import argparse | ||
| 20 | import json | ||
| 21 | import os | ||
| 22 | import re | ||
| 23 | import sys | ||
| 24 | from collections import Counter | ||
| 25 | |||
| 26 | ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
| 27 | sys.path.insert(0, os.path.join(ROOT, "tools")) | ||
| 28 | import shader_ir # noqa: E402 | ||
| 29 | |||
| 30 | NO_DEST_OPS = ("s_cmp", "s_bitcmp", "v_cmpx", "s_set", "s_rfe", "s_branch", "s_cbranch", "s_waitcnt", "s_barrier", | ||
| 31 | "s_nop", "s_endpgm", "s_sendmsg", "s_sleep", "exp", "buffer_store", "global_store", "flat_store", | ||
| 32 | "scratch_store", "image_store", "ds_write") | ||
| 33 | PRIM_EXPORT = re.compile(r"^\s*exp\s+prim\b", re.M) | ||
| 34 | POS0_EXPORT = re.compile(r"^\s*exp\s+pos0\b", re.M) | ||
| 35 | PARAM_EXPORT = re.compile(r"^\s*exp\s+param\d+\b", re.M) | ||
| 36 | SENDMSG = re.compile(r"^\s*s_sendmsg\b", re.M) | ||
| 37 | MBCNT = re.compile(r"\bv_mbcnt_(lo|hi)_u32_b32\b") | ||
| 38 | FETCH_CALL = re.compile(r"^\s*s_swappc_b64\s+s\[4:5\],\s*s\[4:5\]", re.M) | ||
| 39 | |||
| 40 | |||
| 41 | def base_op(op): | ||
| 42 | for sfx in ("_e32", "_e64", "_sdwa", "_dpp"): | ||
| 43 | if op.endswith(sfx): | ||
| 44 | return op[:-len(sfx)] | ||
| 45 | return op | ||
| 46 | |||
| 47 | |||
| 48 | def read_before_write(insns): | ||
| 49 | """(SGPRs, VGPRs) read before any write, straight-line from the first instruction.""" | ||
| 50 | written_s, written_v, read_s, read_v = set(), set(), set(), set() | ||
| 51 | for ins in insns: | ||
| 52 | op, args = base_op(ins["op"]), ins["args"] | ||
| 53 | if not args: | ||
| 54 | continue | ||
| 55 | no_dest = op.startswith(NO_DEST_OPS) | ||
| 56 | dst_read = "fmac" in op or "mac_" in op or op in ("v_writelane_b32", "v_swap_b32") or "_atomic_" in op | ||
| 57 | if not no_dest and op.startswith("v_") and "_co_" in op and "_ci_" not in op and len(args) >= 2: | ||
| 58 | dsts, srcs = args[:2], args[2:] # v_add_co_u32 writes a VGPR and a carry | ||
| 59 | elif no_dest: | ||
| 60 | dsts, srcs = [], args | ||
| 61 | else: | ||
| 62 | dsts, srcs = args[:1], (args[:1] if dst_read else []) + args[1:] | ||
| 63 | for a in srcs: | ||
| 64 | regs = range(a["r"], a["r"] + a.get("n", 1)) if a["k"] in ("sgpr", "vgpr") else () | ||
| 65 | for r in regs: | ||
| 66 | if a["k"] == "sgpr" and r not in written_s: | ||
| 67 | read_s.add(r) | ||
| 68 | elif a["k"] == "vgpr" and r not in written_v: | ||
| 69 | read_v.add(r) | ||
| 70 | for a in dsts: | ||
| 71 | if a["k"] == "sgpr": | ||
| 72 | written_s.update(range(a["r"], a["r"] + a.get("n", 1))) | ||
| 73 | elif a["k"] == "vgpr": | ||
| 74 | written_v.update(range(a["r"], a["r"] + a.get("n", 1))) | ||
| 75 | return read_s, read_v | ||
| 76 | |||
| 77 | |||
| 78 | def survey(dxbc_dir): | ||
| 79 | with open(os.path.join(dxbc_dir, "index.json"), encoding="utf-8") as f: | ||
| 80 | index = json.load(f) | ||
| 81 | names = [os.path.splitext(e["file"])[0] for e in index if e.get("stage") == "vs"] | ||
| 82 | markers, vgprs, families = Counter(), Counter(), Counter() | ||
| 83 | missing = 0 | ||
| 84 | for n in names: | ||
| 85 | path = os.path.join(dxbc_dir, "disasm", n + ".s") | ||
| 86 | if not os.path.isfile(path): | ||
| 87 | missing += 1 | ||
| 88 | continue | ||
| 89 | with open(path, encoding="utf-8", errors="replace") as f: | ||
| 90 | text = f.read() | ||
| 91 | _, read_v = read_before_write(shader_ir.parse_file(path)["insns"]) | ||
| 92 | for r in read_v: | ||
| 93 | if r < 16: | ||
| 94 | vgprs[f"v{r}"] += 1 | ||
| 95 | fetch = bool(FETCH_CALL.search(text)) | ||
| 96 | markers["exp prim"] += bool(PRIM_EXPORT.search(text)) | ||
| 97 | markers["s_sendmsg"] += bool(SENDMSG.search(text)) | ||
| 98 | markers["v_mbcnt"] += bool(MBCNT.search(text)) | ||
| 99 | markers["exp pos0"] += bool(POS0_EXPORT.search(text)) | ||
| 100 | markers["exp param"] += bool(PARAM_EXPORT.search(text)) | ||
| 101 | markers["fetch call"] += fetch | ||
| 102 | if fetch: | ||
| 103 | families["fetch call, attributes from v4 up"] += 1 | ||
| 104 | elif 0 in read_v: | ||
| 105 | families["reads v0 (vertex id)" + (" and v3 (instance id)" if 3 in read_v else "")] += 1 | ||
| 106 | else: | ||
| 107 | families["reads neither v0 nor a fetch call"] += 1 | ||
| 108 | return {"vertex_shaders": len(names), "missing_listings": missing, "markers": dict(markers), | ||
| 109 | "input_vgprs_read": dict(sorted(vgprs.items(), key=lambda kv: int(kv[0][1:]))), | ||
| 110 | "families": dict(families)} | ||
| 111 | |||
| 112 | |||
| 113 | def main(): | ||
| 114 | ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) | ||
| 115 | ap.add_argument("dxbc", help="<work>/shaders/dxbc from make_game.py") | ||
| 116 | ap.add_argument("--json", help="also write the counts as JSON") | ||
| 117 | a = ap.parse_args() | ||
| 118 | r = survey(a.dxbc) | ||
| 119 | m = r["markers"] | ||
| 120 | print(f"{r['vertex_shaders']} vertex shaders ({r['missing_listings']} without a listing)") | ||
| 121 | print(f"NGG markers: exp prim {m.get('exp prim', 0)}, s_sendmsg {m.get('s_sendmsg', 0)}, v_mbcnt {m.get('v_mbcnt', 0)}") | ||
| 122 | print(f"exports: pos0 {m.get('exp pos0', 0)}, param {m.get('exp param', 0)}; fetch call {m.get('fetch call', 0)}") | ||
| 123 | print("input VGPRs read before written (v0..v15):", r["input_vgprs_read"]) | ||
| 124 | print("families:", r["families"]) | ||
| 125 | legacy = not (m.get("exp prim") or m.get("s_sendmsg") or m.get("v_mbcnt")) | ||
| 126 | print("layout:", "legacy (non-NGG) VS" if legacy else "NGG markers present: check the VS input layout") | ||
| 127 | if a.json: | ||
| 128 | with open(a.json, "w", encoding="utf-8") as f: | ||
| 129 | json.dump(r, f, indent=1) | ||
| 130 | return 0 | ||
| 131 | |||
| 132 | |||
| 133 | if __name__ == "__main__": | ||
| 134 | sys.exit(main()) | ||