"""CPU test for tools/psocache_usersig.py on a synthetic cache built by this test. The cache has two graphics PSOs. Their stage records name three chunk records: one with SRV/UAV/CBV/sampler entries and constants (fits), one with extra slots (fits), and one with 40 constant dwords (does not fit). """ import contextlib import importlib.util import io import json import os import struct import subprocess import sys import tempfile import unittest from unittest import mock ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TOOL = os.path.join(ROOT, "tools", "psocache_usersig.py") HEADER = 0x80 GRAPHICS = 2 COMPUTE = 0 META_INDEX = 6 SHADER_INDEX = 1 CODE_SIZE = 0x100 END_PGM = b"\x00\x00\x81\xbf" CODE_END = b"\x00\x00\x9f\xbf" CHUNK = 32 STAGE0 = 0x30 CHUNK_A = 0x18 + 9 * CHUNK CHUNK_B = 0x18 + 3 * CHUNK CHUNK_C = 0x18 + 5 * CHUNK LAYOUT = 0x20 STAGE1 = 0x30 META_SIZE = STAGE0 + CHUNK_A + CHUNK_B + CHUNK_C + LAYOUT + STAGE1 FILE_SIZE = ( HEADER + GRAPHICS * 0x70 + COMPUTE * 0x18 + META_INDEX * 8 + SHADER_INDEX * 8 + META_SIZE + CODE_SIZE ) def chunk(data, off, *words): struct.pack_into("<8I", data, off, *(list(words) + [0] * (8 - len(words)))) def build(): data = bytearray(FILE_SIZE) data[0:4] = b"PS\x00\x09" struct.pack_into("<4I", data, 0x50, GRAPHICS, COMPUTE, META_INDEX, SHADER_INDEX) struct.pack_into("<2I", data, 0x60, META_SIZE, CODE_SIZE) off = HEADER for stage in (0, 5): struct.pack_into("