dymokomi/luce-render
Source of release 0.1.3
0.1.3 / tools / build_kernels.py
#!/usr/bin/env python3
"""Embed luce-render's GLSL kernels into src/render/kernels.lucb.
Every kernel in KERNELS is compiled through luce-gpu's tools/embed_shaders.py
(SPIR-V for Vulkan, Metal through spirv-cross); tracing kernels are embedded
twice, spectral (SPECTRAL=1) and RGB (SPECTRAL=0). Run it after changing
anything under shaders/; builds use the checked-in module.
python3 tools/build_kernels.py
"""
from pathlib import Path
import subprocess
import sys
ROOT = Path(__file__).resolve().parent.parent
EMBED = ROOT.parent / 'luce-gpu' / 'tools' / 'embed_shaders.py'
SHADERS = ROOT / 'shaders'
OUTPUT = ROOT / 'src' / 'render' / 'kernels.lucb'
# (source, stem, defines): kernels as the host creates them.
KERNELS = [('probe.comp', 'probe', ''), ('tables.comp', 'tables', ''), ('guide_fit.comp', 'guide_fit', '')]
# The integrator, spectral and RGB.
for name in ['camera', 'shade_surface', 'shade_miss', 'finish', 'film_convert', 'adaptive', 'light_emit']:
KERNELS.append((f'{name}.comp', f'{name}', 'SPECTRAL=1'))
KERNELS.append((f'{name}.comp', f'{name}_rgb', 'SPECTRAL=0'))
# Intersection on the software BVH, or by hardware ray queries where the
# device has them. Closest hits add the splats' emission, spectral or RGB;
# shadow rays read no spectra, so both builds share them.
for defines, stem in [('SPECTRAL=1', ''), ('SPECTRAL=0', '_rgb')]:
KERNELS.append(('intersect_closest.comp', f'intersect_closest{stem}', f'{defines},RAY_QUERY=0'))
KERNELS.append(('intersect_closest.comp', f'intersect_closest{stem}_rq', f'{defines},RAY_QUERY=1'))
KERNELS.append(('intersect_shadow.comp', 'intersect_shadow', 'RAY_QUERY=0'))
KERNELS.append(('intersect_shadow.comp', 'intersect_shadow_rq', 'RAY_QUERY=1'))
def main() -> int:
specs = []
for source, stem, defines in KERNELS:
spec = f'{SHADERS / source}:{stem}'
if defines:
spec += ':' + defines
specs.append(spec)
# Vulkan 1.2 SPIR-V: ray queries need it, and every device we run has it.
command = [sys.executable, str(EMBED), str(OUTPUT), '--public', '--shared', '--target-env', 'vulkan1.2', '-I', str(SHADERS)] + specs
return subprocess.call(command)
if __name__ == '__main__':
sys.exit(main())