Fix shader generator script Windows compatibility
Co-authored-by: Concedo <39025047+LostRuins@users.noreply.github.com>
This commit is contained in:
parent
1e6e13f32b
commit
7efac61c7a
1 changed files with 38 additions and 23 deletions
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -769,6 +770,7 @@ void main() {
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
GLSLC = "glslc"
|
||||||
|
|
||||||
VK_NUM_TYPES = 16
|
VK_NUM_TYPES = 16
|
||||||
|
|
||||||
|
@ -809,11 +811,11 @@ K_QUANTS_PER_ITERATION = 1
|
||||||
|
|
||||||
|
|
||||||
async def string_to_spv_file(name, code, defines, fp16):
|
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.write(code)
|
||||||
f.flush()
|
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()])
|
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:
|
if proc.returncode:
|
||||||
# Generate preprocessed code
|
# 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()])
|
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)
|
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()])
|
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())])
|
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=}")
|
print(f"ERROR compiling {name}\n\n{code_with_lines}\n\n{error=}")
|
||||||
|
os.remove(f.name)
|
||||||
sys.exit(proc.returncode)
|
sys.exit(proc.returncode)
|
||||||
|
|
||||||
|
os.remove(f.name)
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
print("ggml_vulkan: Generating and compiling shaders to SPIR-V")
|
print("ggml_vulkan: Generating and compiling shaders to SPIR-V")
|
||||||
|
@ -963,4 +968,14 @@ async def main():
|
||||||
await asyncio.gather(*tasks)
|
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())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue