70 lines
2.0 KiB
Python
70 lines
2.0 KiB
Python
#!/user/bin/env python3
|
|
# invokes shadercross
|
|
# and builds shaders for samples
|
|
|
|
import os
|
|
import subprocess
|
|
|
|
from sys import platform
|
|
|
|
origDir = os.path.abspath(os.path.dirname(__file__))
|
|
contentDir = os.path.join(origDir, 'content/')
|
|
shadercrossDir = os.path.join(origDir, 'shadercross/bin')
|
|
|
|
if platform == "linux" or platform == "linux2":
|
|
shadercrossDir = os.path.join(shadercrossDir, 'linux')
|
|
elif platform == "darwin":
|
|
shadercrossDir = os.path.join(shadercrossDir, 'osx')
|
|
elif platform == "win32":
|
|
shadercrossDir = os.path.join(shadercrossDir, 'win64')
|
|
|
|
shadercross = os.path.join(shadercrossDir, 'shadercross')
|
|
|
|
inputFiles = [os.path.abspath(os.path.join(contentDir, x)) for x in os.listdir(contentDir) if x.endswith('.hlsl')]
|
|
|
|
def cookAll():
|
|
# general cooking flow I think for shaders is
|
|
# they will go under
|
|
cookedRoot = os.path.join(contentDir, '_cooked')
|
|
|
|
# we cook into 3 formats
|
|
# spirv
|
|
# msl
|
|
# dxil
|
|
|
|
outputFormats = [
|
|
('dxil', []),
|
|
('spv', []),
|
|
('msl', []),
|
|
]
|
|
|
|
spvs = []
|
|
|
|
for fmt in outputFormats:
|
|
outdir = os.path.join(cookedRoot, fmt[0])
|
|
for f in inputFiles:
|
|
basefile = f[:-5]
|
|
outfile = os.path.abspath(os.path.join(outdir, os.path.basename(basefile) + '.' + fmt[0] ))
|
|
os.makedirs(os.path.dirname(outfile), exist_ok=True)
|
|
cmd = [shadercross, f] + fmt[1] + [ '-o', outfile ]
|
|
|
|
if 'spv' == fmt[0]:
|
|
spvs.append((outfile, os.path.dirname(f)))
|
|
|
|
print(cmd)
|
|
subprocess.run(cmd)
|
|
|
|
# run spirv-cross and generate .json files
|
|
for f in spvs:
|
|
basefile = f[0][:-4]
|
|
# outdir = os.path.join(cookedRoot, '_def')
|
|
outfile = os.path.join(f[1], os.path.basename(basefile) + '.json' )
|
|
os.makedirs(os.path.dirname(outfile), exist_ok=True)
|
|
|
|
cmd = ['spirv-cross', f[0], '--reflect', '--output', outfile ]
|
|
print(cmd)
|
|
subprocess.run(cmd)
|
|
|
|
if __name__ == '__main__':
|
|
cookAll()
|