Updated GLSL shader compile script
This commit is contained in:
parent
5418a75799
commit
ab10ce1693
1 changed files with 40 additions and 22 deletions
|
|
@ -1,31 +1,49 @@
|
||||||
import sys
|
import argparse
|
||||||
|
import fileinput
|
||||||
import os
|
import os
|
||||||
import glob
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
parser = argparse.ArgumentParser(description='Compile all GLSL shaders')
|
||||||
sys.exit("Please provide a target directory")
|
parser.add_argument('--glslang', type=str, help='path to glslangvalidator executable')
|
||||||
|
parser.add_argument('--g', action='store_true', help='compile with debug symbols')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
if not os.path.exists(sys.argv[1]):
|
def findGlslang():
|
||||||
sys.exit("%s is not a valid directory" % sys.argv[1])
|
def isExe(path):
|
||||||
|
return os.path.isfile(path) and os.access(path, os.X_OK)
|
||||||
|
|
||||||
path = sys.argv[1]
|
if args.glslang != None and isExe(args.glslang):
|
||||||
|
return args.glslang
|
||||||
|
|
||||||
shaderfiles = []
|
exe_name = "glslangvalidator"
|
||||||
for exts in ('*.vert', '*.frag', '*.comp', '*.geom', '*.tesc', '*.tese'):
|
if os.name == "nt":
|
||||||
shaderfiles.extend(glob.glob(os.path.join(path, exts)))
|
exe_name += ".exe"
|
||||||
|
|
||||||
failedshaders = []
|
for exe_dir in os.environ["PATH"].split(os.pathsep):
|
||||||
for shaderfile in shaderfiles:
|
full_path = os.path.join(exe_dir, exe_name)
|
||||||
print("\n-------- %s --------\n" % shaderfile)
|
if isExe(full_path):
|
||||||
if subprocess.call("glslangValidator -V %s -o %s.spv" % (shaderfile, shaderfile), shell=True) != 0:
|
return full_path
|
||||||
failedshaders.append(shaderfile)
|
|
||||||
|
|
||||||
print("\n-------- Compilation result --------\n")
|
sys.exit("Could not find DXC executable on PATH, and was not specified with --dxc")
|
||||||
|
|
||||||
if len(failedshaders) == 0:
|
glslang_path = findGlslang()
|
||||||
print("SUCCESS: All shaders compiled to SPIR-V")
|
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
else:
|
dir_path = dir_path.replace('\\', '/')
|
||||||
print("ERROR: %d shader(s) could not be compiled:\n" % len(failedshaders))
|
for root, dirs, files in os.walk(dir_path):
|
||||||
for failedshader in failedshaders:
|
for file in files:
|
||||||
print("\t" + failedshader)
|
if file.endswith(".vert") or file.endswith(".frag") or file.endswith(".comp") or file.endswith(".geom") or file.endswith(".tesc") or file.endswith(".tese") or file.endswith(".rgen") or file.endswith(".rchit") or file.endswith(".rmiss"):
|
||||||
|
input_file = os.path.join(root, file)
|
||||||
|
output_file = input_file + ".spv"
|
||||||
|
|
||||||
|
add_params = ""
|
||||||
|
if args.g:
|
||||||
|
add_params = "-g"
|
||||||
|
|
||||||
|
if file.endswith(".rgen") or file.endswith(".rchit") or file.endswith(".rmiss"):
|
||||||
|
add_params = add_params + " --target-env vulkan1.2"
|
||||||
|
|
||||||
|
res = subprocess.call("%s -V %s -o %s %s" % (glslang_path, input_file, output_file, add_params), shell=True)
|
||||||
|
# res = subprocess.call([glslang_path, '-V', input_file, '-o', output_file, add_params], shell=True)
|
||||||
|
if res != 0:
|
||||||
|
sys.exit()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue