Skip to content

Commit

Permalink
scripts: Add back 'outfilename' arg to generate_spirv.py
Browse files Browse the repository at this point in the history
Useful for CIs with strict sandboxing rules (i.e. @google).
  • Loading branch information
amaiorano authored and ncesario-lunarg committed Aug 11, 2022
1 parent 1a9a1e9 commit 5dc0e67
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions scripts/generate_spirv.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def compile(filename, glslang_validator):
args = [glslang_validator, "-V", "-H", "-o", tmpfile, filename]
output = subprocess.check_output(args, universal_newlines=True)
except subprocess.CalledProcessError as e:
raise(e.output)
raise Exception(e.output)

# read the temp file into a list of SPIR-V words
words = []
Expand All @@ -70,7 +70,7 @@ def compile(filename, glslang_validator):
# Because this might be absolute on the system, remove it
return (words, output.rstrip()[output.index('\n') + 1:])

def write(words, disassembled, filename):
def write(words, disassembled, filename, outfilename = None):
name = identifierize(os.path.basename(filename))

literals = []
Expand Down Expand Up @@ -117,14 +117,19 @@ def write(words, disassembled, filename):
};
""" % (disassembled, name, len(words), "\n".join(literals))

out_file = os.path.join(common_codegen.repo_relative('layers/generated'), name + '.h')
if outfilename:
out_file = outfilename
else:
out_file = os.path.join(common_codegen.repo_relative('layers/generated'), name + '.h')
os.makedirs(os.path.dirname(out_file), exist_ok=True)
with open(out_file, "w") as f:
print(header, end="", file=f)

def main():
parser = argparse.ArgumentParser(description='Generate spirv code for this repository, see layers/gpu_shaders/README.md for more deatils')
parser.add_argument('--shader', action='store', type=str, help='Input Filename')
parser.add_argument('--glslang', action='store', type=str, help='Path to glslangvalidator to use')
parser.add_argument('--outfilename', action='store', type=str, help='Optional path to output file')
args = parser.parse_args()

generate_shaders = []
Expand All @@ -149,7 +154,7 @@ def main():

for shader in generate_shaders:
words, disassembled = compile(shader, glslang_validator)
write(words, disassembled, shader)
write(words, disassembled, shader, args.outfilename)

if __name__ == '__main__':
main()

0 comments on commit 5dc0e67

Please sign in to comment.