27 lines
1.5 KiB
Python
27 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Compile the Turnip smoke shaders (drivers/AdrenoMetal/shaders, GLSL) to SPIR-V with glslc, validate them with spirv-val and write
|
|
build/turnip-smoke/NativeTurnipShaders.h (word arrays). Build product only; the GLSL is the source."""
|
|
from pathlib import Path
|
|
import struct
|
|
import subprocess
|
|
import tempfile
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
OUT = ROOT / 'build/turnip-smoke'
|
|
OUT.mkdir(parents=True, exist_ok=True)
|
|
lines = ['// Generated by scripts/gen-turnip-smoke-shaders.py from drivers/AdrenoMetal/shaders; do not edit.', '#pragma once', '#include <stdint.h>']
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
for source in sorted((ROOT / 'drivers/AdrenoMetal/shaders').glob('smoke_*')):
|
|
spv = Path(tmp) / (source.name + '.spv')
|
|
subprocess.run(['glslc', '--target-env=vulkan1.1', '-O', str(source), '-o', str(spv)], check=True)
|
|
subprocess.run(['spirv-val', '--target-env', 'vulkan1.1', str(spv)], check=True)
|
|
data = spv.read_bytes()
|
|
words = struct.unpack('<%dI' % (len(data) // 4), data)
|
|
name = 'kSpv_' + source.name.replace('.', '_')
|
|
lines.append('static const uint32_t %s[] = {' % name)
|
|
for i in range(0, len(words), 8):
|
|
lines.append(' ' + ', '.join('0x%08x' % w for w in words[i:i + 8]) + ',')
|
|
lines.append('};')
|
|
(OUT / 'NativeTurnipShaders.h').write_text('\n'.join(lines) + '\n')
|
|
print('PASS: smoke shaders compiled and validated ->', OUT / 'NativeTurnipShaders.h')
|