From e37a89136ff0534ec3694e1bf1246a17d70194be Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 19 May 2015 11:27:20 -0700 Subject: [PATCH] vk/glsl_scraper: Add a --glsl-only option --- src/vulkan/glsl_scraper.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/vulkan/glsl_scraper.py b/src/vulkan/glsl_scraper.py index 55885b4bdbf..c35337bace5 100644 --- a/src/vulkan/glsl_scraper.py +++ b/src/vulkan/glsl_scraper.py @@ -81,7 +81,7 @@ class Shader: os.remove(glsl_fname) os.remove(spirv_fname) - def dump_c_code(self, f): + def dump_c_code(self, f, glsl_only = False): f.write('\n\n') var_prefix = '_glsl_helpers_shader{0}'.format(self.line) @@ -94,6 +94,9 @@ class Shader: f.write('\n"{0}\\n"'.format(line)) f.write(';\n\n') + if glsl_only: + return + # Now dump the SPIR-V source f.write('static const uint32_t {0}_spir_v_src[] = {{'.format(var_prefix)) line_start = 0 @@ -192,6 +195,7 @@ def open_file(name, mode): infname = None outfname = '-' glslang = 'glslangValidator' +glsl_only = False arg_idx = 1 while arg_idx < len(sys.argv): @@ -202,6 +206,8 @@ while arg_idx < len(sys.argv): outfname = sys.argv[arg_idx] elif sys.argv[arg_idx].startswith('--with-glslang='): glslang = sys.argv[arg_idx][len('--with-glslang='):] + elif sys.argv[arg_idx] == '--glsl-only': + glsl_only = True; else: infname = sys.argv[arg_idx] break @@ -214,20 +220,21 @@ with open_file(infname, 'r') as infile: parser = Parser(infile) parser.run() -# glslangValidator has an absolutely *insane* interface. We pretty much -# have to run in a temporary directory. Sad day. -current_dir = os.getcwd() -tmpdir = tempfile.mkdtemp('glsl_scraper') +if not glsl_only: + # glslangValidator has an absolutely *insane* interface. We pretty much + # have to run in a temporary directory. Sad day. + current_dir = os.getcwd() + tmpdir = tempfile.mkdtemp('glsl_scraper') -try: - os.chdir(tmpdir) + try: + os.chdir(tmpdir) - for shader in parser.shaders: - shader.compile() + for shader in parser.shaders: + shader.compile() - os.chdir(current_dir) -finally: - shutil.rmtree(tmpdir) + os.chdir(current_dir) + finally: + shutil.rmtree(tmpdir) with open_file(outfname, 'w') as outfile: outfile.write("""\ @@ -238,4 +245,4 @@ with open_file(outfname, 'w') as outfile: #include """) for shader in parser.shaders: - shader.dump_c_code(outfile) + shader.dump_c_code(outfile, glsl_only) -- 2.30.2