From d817f8b186cccebed89471580a685dc80a330946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Iglesias=20Gons=C3=A1lvez?= Date: Thu, 11 Oct 2018 11:59:40 +0200 Subject: [PATCH] precompile-script.py: add arguments for glslangValidator and spirv-as MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add two new arguments to precompile-script.py, they specify where the glslangValidator and spirv-as binaries are in the system, so the user doesn't need to add them to the current path nor install them into the system. Signed-off-by: Samuel Iglesias Gonsálvez --- README.md | 5 +++++ precompile-script.py | 23 +++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cb0637a..17cf35c 100644 --- a/README.md +++ b/README.md @@ -312,6 +312,11 @@ test scripts to binary. It can be run for example as below: ./precompile-script.py -o compiled-examples examples/*.shader_test ./src/vkrunner compiled-examples/*.shader_test +If glslangValidator and spirv-as are not in the path, you can indicate +where the binaries are with the following command line arguments: + + ./precompile-script.py -o compiled-examples examples/*.shader_test -g PATH_GLSLANG/glslangValidator -s PATH_SPIRV_AS/spirv-as + ## Library VkRunner can alternatively be used as a library to integrate it into diff --git a/precompile-script.py b/precompile-script.py index 3850e33..d1903f4 100755 --- a/precompile-script.py +++ b/precompile-script.py @@ -46,11 +46,12 @@ } class Converter: - def __init__(self, type, stage, fout): + def __init__(self, type, stage, fout, binary): self._type = type self._stage = stage self._fout = fout self._tempfile = tempfile.NamedTemporaryFile('w+') + self._binary = binary def add_line(self, line): self._tempfile.write(line) @@ -60,7 +61,7 @@ def finish(self): with tempfile.NamedTemporaryFile() as temp_outfile: if self._type == 'glsl': - subprocess.check_call(["glslangValidator", + subprocess.check_call([self._binary, "-S", self._stage, "-G", "-V", @@ -68,7 +69,7 @@ def finish(self): "-o", temp_outfile.name, self._tempfile.name]) else: - subprocess.check_call(["spirv-as", + subprocess.check_call([self._binary, "--target-env", TARGET_ENV, "-o", temp_outfile.name, self._tempfile.name]) @@ -111,7 +112,7 @@ def finish(self): print(file=self._fout) -def convert_stream(fin, fout): +def convert_stream(fin, fout, glslang, spirv_as): converter = None for line in fin: @@ -127,12 +128,13 @@ def convert_stream(fin, fout): stage_name = section_name[:-6] converter = Converter('spirv', STAGE_MAP[stage_name], - fout) + fout, + spirv_as) print("[{} binary]".format(stage_name), file=fout) elif section_name in STAGE_MAP: converter = Converter('glsl', STAGE_MAP[section_name], - fout) + fout, glslang) print("[{} binary]".format(section_name), file=fout) else: fout.write(line) @@ -145,13 +147,18 @@ def convert_stream(fin, fout): converter.finish() - parser = argparse.ArgumentParser(description='Precompile VkRunner scripts.') parser.add_argument('inputs', metavar='INPUT', type=str, nargs='+', help='an input file process') parser.add_argument('-o', dest='output', metavar='OUTPUT', help='an output file or directory', required=True) +parser.add_argument('-g', dest='glslang', metavar='GLSLANG', + help='glslangValidator binary path', required=False, default="glslangValidator") + +parser.add_argument('-s', dest='spirv_as', metavar='SPIRV_AS', + help='spirv-as binary path', required=False, default="spirv-as") + args = parser.parse_args() output_is_directory = len(args.inputs) >= 2 or os.path.isdir(args.output) @@ -169,4 +176,4 @@ def convert_stream(fin, fout): with open(input, 'r') as fin: with open(output, 'w') as fout: - convert_stream(fin, fout) + convert_stream(fin, fout, args.glslang, args.spirv_as)