"""The per-basic-block descriptor lookup cache of tools/rdna2spirv.py (standard library only: no GPU, LLVM or SPIRV-Tools). python -I tests/test_desc_cache.py Every image instruction needs the bindless index of its T# (8 SGPRs) and S# (4 SGPRs): a call of %desc_lookup_fn. A second instruction on the same descriptors in the same basic block reuses the first one's result as long as no SGPR of the descriptor was written in between. These tests translate small pixel shaders (the .s text is made here, with encodings of the right length so that branch targets work out) and count the calls in the SPIR-V. """ import gc import os import shutil import struct import subprocess import sys import tempfile import warnings ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.dont_write_bytecode = True sys.path.insert(0, os.path.join(ROOT, "tools")) import rdna2spirv # noqa: E402 CALL = "OpFunctionCall %uint %desc_lookup_fn" STUB_DXBC = b"DXBC" + bytes(24) + struct.pack("