diff options
Diffstat (limited to 'scripts/vs_layout_census.py')
| -rw-r--r-- | scripts/vs_layout_census.py | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/scripts/vs_layout_census.py b/scripts/vs_layout_census.py index 249a9c74e..1d7174e77 100644 --- a/scripts/vs_layout_census.py +++ b/scripts/vs_layout_census.py | |||
| @@ -31,6 +31,7 @@ sys.path.insert(0, os.path.join(ROOT, "scripts")) | |||
| 31 | import fssm_unpack # noqa: E402 | 31 | import fssm_unpack # noqa: E402 |
| 32 | import pal_stages # noqa: E402 | 32 | import pal_stages # noqa: E402 |
| 33 | import shader_disasm # noqa: E402 | 33 | import shader_disasm # noqa: E402 |
| 34 | from report_paths import same_report_path # noqa: E402 | ||
| 34 | import shader_ir # noqa: E402 | 35 | import shader_ir # noqa: E402 |
| 35 | from vs_input_survey import (FETCH_CALL, MBCNT, PARAM_EXPORT, POS0_EXPORT, PRIM_EXPORT, SENDMSG, # noqa: E402 | 36 | from vs_input_survey import (FETCH_CALL, MBCNT, PARAM_EXPORT, POS0_EXPORT, PRIM_EXPORT, SENDMSG, # noqa: E402 |
| 36 | read_before_write) | 37 | read_before_write) |
| @@ -87,10 +88,9 @@ def payloads_of(dxbc_path): | |||
| 87 | for i, blob in enumerate(blobs)] | 88 | for i, blob in enumerate(blobs)] |
| 88 | 89 | ||
| 89 | 90 | ||
| 90 | def survey(dxbc_dir, disasm_fn=None, limit=None): | 91 | def load_index(dxbc_dir): |
| 91 | """The census over <dxbc>: counts by stage, hardware id, markers and VS entry VGPRs.""" | 92 | """(stage by stem, stems in index order) from <dxbc>/index.json.""" |
| 92 | index_path = os.path.join(dxbc_dir, "index.json") | 93 | with open(os.path.join(dxbc_dir, "index.json"), encoding="utf-8") as f: |
| 93 | with open(index_path, encoding="utf-8") as f: | ||
| 94 | index = json.load(f) | 94 | index = json.load(f) |
| 95 | if not isinstance(index, list) or not all(isinstance(e, dict) for e in index): | 95 | if not isinstance(index, list) or not all(isinstance(e, dict) for e in index): |
| 96 | raise ValueError("index.json is not a list of shader entries") | 96 | raise ValueError("index.json is not a list of shader entries") |
| @@ -102,6 +102,26 @@ def survey(dxbc_dir, disasm_fn=None, limit=None): | |||
| 102 | if stem not in stages: | 102 | if stem not in stages: |
| 103 | names.append(stem) | 103 | names.append(stem) |
| 104 | stages[stem] = e.get("stage") | 104 | stages[stem] = e.get("stage") |
| 105 | return stages, names | ||
| 106 | |||
| 107 | |||
| 108 | def input_paths(dxbc_dir): | ||
| 109 | """Every file the census may read: index.json, then each indexed container and its disasm/<stem>.s listing. | ||
| 110 | An index that cannot be read names no more; survey() reports it.""" | ||
| 111 | paths = [os.path.join(dxbc_dir, "index.json")] | ||
| 112 | try: | ||
| 113 | _stages, names = load_index(dxbc_dir) | ||
| 114 | except (OSError, ValueError): | ||
| 115 | return paths | ||
| 116 | for name in names: | ||
| 117 | paths.append(os.path.join(dxbc_dir, name + ".dxbc")) | ||
| 118 | paths.append(os.path.join(dxbc_dir, "disasm", name + ".s")) | ||
| 119 | return paths | ||
| 120 | |||
| 121 | |||
| 122 | def survey(dxbc_dir, disasm_fn=None, limit=None): | ||
| 123 | """The census over <dxbc>: counts by stage, hardware id, markers and VS entry VGPRs.""" | ||
| 124 | stages, names = load_index(dxbc_dir) | ||
| 105 | if limit is not None: | 125 | if limit is not None: |
| 106 | names = names[:limit] | 126 | names = names[:limit] |
| 107 | 127 | ||
| @@ -186,9 +206,15 @@ def main(argv=None): | |||
| 186 | ap.add_argument("--limit", type=int, help="stop after this many containers (index order)") | 206 | ap.add_argument("--limit", type=int, help="stop after this many containers (index order)") |
| 187 | a = ap.parse_args(argv) | 207 | a = ap.parse_args(argv) |
| 188 | index_path = os.path.join(a.dxbc, "index.json") | 208 | index_path = os.path.join(a.dxbc, "index.json") |
| 189 | if a.json and os.path.exists(a.json) and os.path.exists(index_path) and os.path.samefile(a.json, index_path): | 209 | if a.json: |
| 190 | print(f"vs_layout_census: error: --json would overwrite the input {index_path}", file=sys.stderr) | 210 | # Refuse before survey(): it reads the whole corpus and runs llvm-mc for every unlisted payload. |
| 191 | return 2 | 211 | if os.path.isdir(a.json): |
| 212 | print(f"vs_layout_census: error: --json {a.json} is a directory, not a JSON file", file=sys.stderr) | ||
| 213 | return 2 | ||
| 214 | for path in input_paths(a.dxbc): | ||
| 215 | if same_report_path(a.json, path): | ||
| 216 | print(f"vs_layout_census: error: --json would overwrite the input {path}", file=sys.stderr) | ||
| 217 | return 2 | ||
| 192 | try: | 218 | try: |
| 193 | r = survey(a.dxbc, disasm_fn=default_disasm, limit=a.limit) | 219 | r = survey(a.dxbc, disasm_fn=default_disasm, limit=a.limit) |
| 194 | except (OSError, ValueError) as e: | 220 | except (OSError, ValueError) as e: |