Files
harfbuzz/src/gen-gpu-shader-artifacts.py
T
Behdad Esfahbod 34a9f22f25 [util/gpu] Extract demo shaders into .glsl files
demo_vertex_glsl and demo_fragment_glsl were inline R"glsl(...)"
string literals in util/gpu/demo-shader.cc.  Pull them into
dedicated util/gpu/demo-{vertex,fragment}.glsl source files with
their own copyright headers, and wire the existing
gen-gpu-shader-artifacts.py generator to stringize them into
demo-*-glsl.hh at build time.

Also simplifies gen-gpu-shader-artifacts.py: the decl_map had
grown to cover every shader and its entries were all trivial
filename-to-symbol derivations.  Replace the map with direct
derivation (hyphens -> underscores, strip .hh), so adding more
shaders anywhere -- library or demo -- needs no generator edit.

Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 15:10:09 -06:00

44 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
"This tool is intended to be used from meson"
import os, sys, shutil
if len(sys.argv) < 4:
sys.exit(__doc__)
OUTPUT = sys.argv[1]
CURRENT_SOURCE_DIR = sys.argv[2]
INPUT = sys.argv[3]
hh = os.path.basename(OUTPUT)
# Decl name derives from the .hh filename: hyphens -> underscores,
# strip the .hh suffix. Example: hb-gpu-fragment-glsl.hh -> hb_gpu_fragment_glsl.
if not hh.endswith('.hh'):
sys.exit(f'Output must end with .hh: {hh}')
decl = hh[:-len('.hh')].replace('-', '_')
# Stringize the GLSL source into a C string literal
with open(INPUT, 'r') as f:
lines = f.read().splitlines()
parts = [f'static const char *{decl} =\n']
for line in lines:
line = line.replace('\\', '\\\\').replace('"', '\\"')
parts.append(f'"{line}\\n"\n')
parts.append(';\n')
content = ''.join(parts)
with open(OUTPUT, 'w') as f:
f.write(content)
# Copy back to source tree; if read-only, verify committed copy matches.
src_copy = os.path.join(CURRENT_SOURCE_DIR, hh)
try:
shutil.copyfile(OUTPUT, src_copy)
except OSError:
import filecmp
if not filecmp.cmp(OUTPUT, src_copy, shallow=False):
sys.exit(f'{src_copy} is out of date; regenerate with a writable source tree')