"""Compile the FSR RR conversion shaders with the pinned glslang into tools/windows/fsr_rr/fsr_rr_shaders_spv.h.""" import hashlib import struct import subprocess import sys import tempfile from pathlib import Path repo = Path(__file__).resolve().parents[2] glslang = repo / '.tools/glslang-16.6.0/bin/glslangValidator.exe' if hashlib.sha256(glslang.read_bytes()).hexdigest() != '9643709c02c83e26773f96b6a87f197ab2e84f78be0879ad8fb3619418b5d9ad': sys.exit('requires the pinned glslang 16.6.0') source = repo / 'tools/windows/fsr_rr' lines = ['#pragma once', '#include ', '// Generated by scripts/windows/compile-fsr-rr-shaders.py; do not edit.'] with tempfile.TemporaryDirectory() as tmp: for name in ('fsr_rr_prepare', 'fsr_rr_compose'): out = Path(tmp) / (name + '.spv') subprocess.run([str(glslang), '-V', '--target-env', 'vulkan1.0', '-o', str(out), str(source / (name + '.comp'))], check=True, stdout=subprocess.DEVNULL) data = out.read_bytes() words = struct.unpack('<' + 'I' * (len(data) // 4), data) lines.append(f'static const uint32_t d4r_vk_{name}[] = {{') lines.extend(','.join(f'0x{w:08x}' for w in words[i:i + 8]) + ',' for i in range(0, len(words), 8)) lines.append('};') (source / 'fsr_rr_shaders_spv.h').write_text('\n'.join(lines) + '\n') print('wrote', source / 'fsr_rr_shaders_spv.h')