forked from ConfettiFX/The-Forge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPyBuildShaders.py
56 lines (45 loc) · 2.05 KB
/
PyBuildShaders.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
"""
script which generates and compiles all shaders
"""
def BuildShaders() -> int:
import os, sys
_filedir = os.path.abspath(os.path.dirname(__file__))
# directly import fsl as module, calling the tool directly is much faster that way than spawning a process for each invocation
sys.path.append(os.path.join(_filedir, 'Common_3', 'Tools', 'ForgeShadingLanguage'))
from fsl import main
from compilers import get_available_compilers
# set default compiler paths
os.environ['FSL_COMPILER_FXC'] = os.path.normpath('C:/Program Files (x86)/Windows Kits/8.1/bin/x64/fxc.exe')
os.environ['FSL_COMPILER_DXC'] = os.path.normpath(_filedir+'/Common_3/ThirdParty/OpenSource/DirectXShaderCompiler/bin/x64/dxc.exe')
os.environ['FSL_COMPILER_METAL'] = os.path.normpath('C:/Program Files/Metal Developer Tools/macos/bin/metal.exe')
available_compilers = get_available_compilers()
shader_dirs = [
'Examples_3/Visibility_Buffer/src/Shaders/FSL',
'Examples_3/Unit_Tests/src/01_Transformations/Shaders/FSL/',
'Examples_3/Unit_Tests/src/02_Compute/Shaders/FSL/',
'Examples_3/Unit_Tests/src/03_MultiThread/Shaders/FSL/',
'Examples_3/Unit_Tests/src/04_ExecuteIndirect/Shaders/FSL/',
]
output_dir = 'GeneratedShaders'
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# sys.argv += ['--verbose', 'true']
# sys.argv += ['--compile', 'true']
argv = sys.argv[:]
languages = ['D3D12', 'Metal', 'Vulkan']
for lang in languages:
for shader_dir in shader_dirs:
project = os.path.normpath(shader_dir).split(os.path.sep)[-3]
shader_dir = os.path.join(_filedir, shader_dir)
for fsl_file in [os.path.join(shader_dir, _file) for _file in os.listdir(shader_dir) if _file.endswith('.fsl')]:
if lang != 'Metal' and 'icb.comp' in fsl_file: continue
sys.argv = argv[:]
if lang in available_compilers: sys.argv += ['--compile', 'true']
sys.argv += ['-l', lang]
sys.argv += ['-d', os.path.join(output_dir, project, lang)]
sys.argv += [fsl_file]
status = main()
if status != 0: return status
return 0
if __name__ == '__main__':
BuildShaders()