Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
precompile-script.py: add arguments for glslangValidator and spirv-as
Browse files Browse the repository at this point in the history
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 <siglesias@igalia.com>
  • Loading branch information
samuelig committed Oct 16, 2018
1 parent 626b679 commit d817f8b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
23 changes: 15 additions & 8 deletions precompile-script.py
Expand Up @@ -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)
Expand All @@ -60,15 +61,15 @@ 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",
"--target-env", TARGET_ENV,
"-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])
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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)

0 comments on commit d817f8b

Please sign in to comment.