-
Notifications
You must be signed in to change notification settings - Fork 0
/
shaders.py
68 lines (57 loc) · 2 KB
/
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
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import sys
import subprocess as sb
from contextlib import contextmanager
this_dir = os.path.dirname(__file__)
@contextmanager
def cwd(path):
oldpwd=os.getcwd()
if not os.path.exists(path): os.mkdir(path)
os.chdir(path)
try:
yield
finally:
os.chdir(oldpwd)
def FindVulkanSDK():
default_vulkan_path = 'C:\\VUlkanSDK\\'
current_dir = None
current_max = 0
for d in os.listdir(default_vulkan_path):
try:
v = d.split('.')
m = ((1 << 16) << int(v[0]))
m = m + ((1 << 8) << int(v[1]))
m = m + int(v[2])
m = m + int(v[3])
if max(m,current_max) == m:
current_max = m
current_dir = d
except Exception as e:
print(e)
if (current_dir):
p = os.path.join(default_vulkan_path,current_dir)
print("Using vulkan %s" % (p))
return p
else:
raise Exception( "Invalid VulkanSDK configuration. Expecting path in %s".format(default_vulkan_path) )
def GenerateShaders(output_mode='release'):
folder_shader = os.path.join(this_dir,'src','shaders')
folder_output = os.path.join(this_dir,'src',output_mode,'shaders')
print("Output shader files to ... %s" % (folder_output))
exec_glslc = os.path.join(FindVulkanSDK(), 'Bin','glslc.exe')
with cwd(folder_output):
for file in os.listdir(folder_shader):
print("Working on file %s" % (file))
if file[-2:] != '.h':
abs_path_file = os.path.abspath(os.path.join(folder_shader,file))
#abs_path_output = os.path.abspath(os.path.join(folder_output,file[0:file.index('.')] + '.spv'))
abs_path_output = folder_output
args = [exec_glslc,'-c',abs_path_file]#,'-o',abs_path_output]
sb.call(args)
if __name__ == '__main__':
args = sys.argv
output_mode = 'release'
if len(args) > 1:
if (args[1] == 'd'):
output_mode = 'debug'
GenerateShaders(output_mode)