"""The root-layout and used-resource tables of an FSSM program record: tools/fssm_root_layout.py (root_tables() and its command line) and tools/root_layout_census.py. python -I tests/test_fssm_root_layout.py Zero game data: every blob here is built by hand from the layout in tools/fssm_root_layout.py's docstring, with placeholder words for code. The numbers in the tables are made up to cover the entry kinds (constants, a root descriptor, tables, an immediate sampler, the heaps, a spilled parameter), not copied from a shader. """ import json import os import random import struct import subprocess import sys import tempfile import unittest ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, os.path.join(ROOT, "tools")) sys.path.insert(0, os.path.join(ROOT, "tests")) import fssm_root_layout # noqa: E402 import fssm_unpack # noqa: E402 import root_layout_census as census # noqa: E402 from test_fssm_unpack import make_dxbc, make_xbch, make_xdat_list # noqa: E402 DUMP = os.path.join(ROOT, "tools", "fssm_root_layout.py") CENSUS = os.path.join(ROOT, "tools", "root_layout_census.py") PAYLOAD = 0x10 RECORD = 0x54 FIRST_RECORD = 0xB0 # in the payload; any offset past the slot table would do ABSENT = 0xDEADBEEFDEADBEEF SLOTS = dict(fssm_root_layout.FSSM_STAGE_SLOTS) CODE = struct.pack("<4I", 0xBF810000, 0xBF9F0000, 0xBF9F0000, 0xBF9F0000) # s_endpgm and s_code_end padding CONSTANTS, DESCRIPTOR, TABLE, IMMEDIATE_SAMPLER, RESOURCE_HEAP, SAMPLER_HEAP = 0, 1, 3, 4, 5, 6 SRV, SAMPLER, CBV, UAV = 0, 1, 2, 3 def param(root_type, user_data, sgprs, slot, register=0, table_offset=0, reserved=0): """A 20-byte root-layout entry.""" return struct.pack(" (bytearray, {stage: blob offset of its record}). programs: {stage: (root-layout entries, used-resource entries)}. The records follow the slot table, then for each program its code, its root-layout table and its used-resource table. An empty table gets a count of 0 and the 0xDEADBEEFDEADBEEF offset.""" stages = [stage for stage, _ in fssm_root_layout.FSSM_STAGE_SLOTS if stage in programs] payload = bytearray(FIRST_RECORD + 0x88 * len(stages)) struct.pack_into("= 16: struct.pack_into("