Fix shader generator script Windows compatibility

Co-authored-by: Concedo <39025047+LostRuins@users.noreply.github.com>
This commit is contained in:
0cc4m 2023-10-14 10:31:20 +02:00
parent 1e6e13f32b
commit 7efac61c7a

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python
import argparse
import asyncio
import os
import sys
@ -769,6 +770,7 @@ void main() {
}
"""
GLSLC = "glslc"
VK_NUM_TYPES = 16
@ -809,11 +811,11 @@ K_QUANTS_PER_ITERATION = 1
async def string_to_spv_file(name, code, defines, fp16):
with NamedTemporaryFile(mode="w") as f:
f = NamedTemporaryFile(mode="w", delete=False)
f.write(code)
f.flush()
cmd = ["glslc", "-fshader-stage=compute", "--target-env=vulkan1.2", "-O", f.name, "-o", os.path.join("vk_shaders", f"{name}{'_fp32' if not fp16 else ''}.comp")]
cmd = [GLSLC, "-fshader-stage=compute", "--target-env=vulkan1.2", "-O", f.name, "-o", os.path.join("vk_shaders", f"{name}{'_fp32' if not fp16 else ''}.comp")]
cmd.extend([f"-D{key}={value}" for key, value in defines.items()])
@ -826,7 +828,7 @@ async def string_to_spv_file(name, code, defines, fp16):
if proc.returncode:
# Generate preprocessed code
cmd = ["glslc", "-E", f.name]
cmd = [GLSLC, "-E", f.name]
cmd.extend([f"-D{key}={value}" for key, value in defines.items()])
proc = await asyncio.create_subprocess_exec(*cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
@ -843,8 +845,11 @@ async def string_to_spv_file(name, code, defines, fp16):
cmd.extend([f"-D{key}={value}" for key, value in defines.items()])
code_with_lines = "\n".join([f"{i}: {line}" for i, line in enumerate(preprocessed_code.splitlines())])
print(f"ERROR compiling {name}\n\n{code_with_lines}\n\n{error=}")
os.remove(f.name)
sys.exit(proc.returncode)
os.remove(f.name)
async def main():
print("ggml_vulkan: Generating and compiling shaders to SPIR-V")
@ -963,4 +968,14 @@ async def main():
await asyncio.gather(*tasks)
asyncio.run(main())
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="GGML Vulkan Shader Generator")
parser.add_argument("--glslc", help="Path to glslc")
args = parser.parse_args()
if args.glslc:
GLSLC = args.glslc
asyncio.run(main())