"""scripts/validate_spirv.py finds a program cache record's stages and tells why a stage would fail. A cache file is made here with a mesh-as-compute record of two compute stages: a valid module whose workgroup memory (80000 bytes) is over RDNA1's 64 KB, and the same module with its array's element type left undefined. The stages are found by their magic words between the record's other fields, the local size and workgroup memory are read from the module, and (when the Vulkan SDK's spirv-val is there) the run flags both stages and writes them out. python -I -B tests/test_validate_spirv.py """ import importlib.util import os import struct import tempfile from pathlib import Path ROOT = Path(__file__).resolve().parents[1] spec = importlib.util.spec_from_file_location("validate_spirv", ROOT / "scripts" / "validate_spirv.py") vs = importlib.util.module_from_spec(spec) spec.loader.exec_module(vs) def op(code, *args): return [(len(args) + 1) << 16 | code, *args] def module(element=3): """OpCapability Shader; GLCompute main, LocalSize 64 1 1; a Workgroup uint[20000]""" w = [0x07230203, 0x00010000, 0, 10, 0] w += op(17, 1) + op(14, 0, 1) w += op(15, 5, 8, int.from_bytes(b"main", "little"), 0) w += op(16, 8, 17, 64, 1, 1) w += op(19, 1) + op(33, 2, 1) + op(21, 3, 32, 0) + op(43, 3, 4, 20000) w += op(28, 5, element, 4) + op(32, 6, 4, 5) + op(59, 6, 7, 4) w += op(54, 1, 8, 0, 2) + op(248, 9) + op(253) + op(56) return struct.pack("<%dI" % len(w), *w) def record(*spirvs): data = struct.pack("