[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>
This commit is contained in:
Behdad Esfahbod committed 2026-04-13 15:10:09 -06:00
1 parent f3fcd46ba9
commit 34a9f22f25
7 files changed
+160 -83

No files matched your search

+5 -19
View File
@@ -12,25 +12,11 @@ CURRENT_SOURCE_DIR = sys.argv[2]
INPUT = sys.argv[3]
hh = os.path.basename(OUTPUT)
decl_map = {
'hb-gpu-fragment-glsl.hh': 'hb_gpu_fragment_glsl',
'hb-gpu-vertex-glsl.hh': 'hb_gpu_vertex_glsl',
'hb-gpu-fragment-msl.hh': 'hb_gpu_fragment_msl',
'hb-gpu-vertex-msl.hh': 'hb_gpu_vertex_msl',
'hb-gpu-fragment-wgsl.hh': 'hb_gpu_fragment_wgsl',
'hb-gpu-vertex-wgsl.hh': 'hb_gpu_vertex_wgsl',
'hb-gpu-fragment-hlsl.hh': 'hb_gpu_fragment_hlsl',
'hb-gpu-vertex-hlsl.hh': 'hb_gpu_vertex_hlsl',
'hb-gpu-draw-fragment-glsl.hh': 'hb_gpu_draw_fragment_glsl',
'hb-gpu-draw-fragment-msl.hh': 'hb_gpu_draw_fragment_msl',
'hb-gpu-draw-fragment-wgsl.hh': 'hb_gpu_draw_fragment_wgsl',
'hb-gpu-draw-fragment-hlsl.hh': 'hb_gpu_draw_fragment_hlsl',
'hb-gpu-paint-fragment-glsl.hh': 'hb_gpu_paint_fragment_glsl',
}
decl = decl_map.get(hh)
if not decl:
sys.exit(f'Unknown shader output: {hh}')
# 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: