-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile_shaders.py
55 lines (41 loc) · 1.48 KB
/
compile_shaders.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import io
import os
import glob
import platform
import subprocess
# shader source file extensions
rt_extensions = ["rchit", "rgen", "rmiss"]
sh_extensions = ["vert", "frag", "geom", "comp"]
# configuration
debug_print = False
src_dirs = ["Resources/Shaders", "Resources/Raytracing"]
bin_dir = "cmake-build-debug"
target_vk = "vulkan1.3"
slash = "\\"
# List of shaders to compile
_to_compile = []
def sort_shaders():
for src_dir in src_dirs:
all_shaders = glob.glob(f"{src_dir}/*")
for shader in all_shaders:
ext = shader.rsplit('.')[-1]
file = shader.rsplit(slash)[-1]
if ext in sh_extensions:
_to_compile.append(f"{src_dir}/{file}")
if platform.system() != "Darwin" and ext in rt_extensions:
_to_compile.append(f"{src_dir}/{file}")
if debug_print:
print(_to_compile)
def compile_shaders():
print(f"Compiling ({len(_to_compile)}) shaders...\nTarget environment: {target_vk}")
counter = 0
for shader in _to_compile:
command = f"glslangValidator -g -o {bin_dir}/{shader.rsplit('/')[-1]}.spv -V {shader} --target-env {target_vk}"
with subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) as proc:
for line in io.TextIOWrapper(proc.stdout, encoding="utf-8"):
counter += 1
print(f"({ counter }) {line.rstrip()}")
if not os.path.exists(f"{bin_dir}"):
os.makedirs(f"{bin_dir}")
sort_shaders()
compile_shaders()