Skip to content

[ET-VK][ez] Retry with no optimization during shader compilation #9096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 34 additions & 22 deletions backends/vulkan/runtime/gen_vulkan_spv.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,12 @@ def __init__(

self.env = env
self.glslc_path = glslc_path
self.glslc_flags = glslc_flags
self.glslc_flags = glslc_flags.split()
self.glslc_flags_no_opt = self.glslc_flags.copy()
if "-O" in self.glslc_flags_no_opt:
self.glslc_flags_no_opt.remove("-O")
if "-Os" in self.glslc_flags_no_opt:
self.glslc_flags_no_opt.remove("-Os")
self.replace_u16vecn = replace_u16vecn

self.glsl_src_files: Dict[str, str] = {}
Expand Down Expand Up @@ -751,30 +756,37 @@ def process_shader(shader_paths_pair):
if self.glslc_path is not None:
spv_out_path = os.path.join(output_dir, f"{shader_name}.spv")

cmd = (
[
self.glslc_path,
"-fshader-stage=compute",
glsl_out_path,
"-o",
spv_out_path,
"--target-env=vulkan1.1",
"-Werror",
]
+ [
arg
for src_dir_path in self.src_dir_paths
for arg in ["-I", src_dir_path]
]
+ self.glslc_flags.split()
)
cmd_base = [
self.glslc_path,
"-fshader-stage=compute",
glsl_out_path,
"-o",
spv_out_path,
"--target-env=vulkan1.1",
"-Werror",
] + [
arg
for src_dir_path in self.src_dir_paths
for arg in ["-I", src_dir_path]
]
cmd = cmd_base + self.glslc_flags

try:
subprocess.check_call(cmd)
subprocess.run(cmd, check=True, capture_output=True, text=True)
except subprocess.CalledProcessError as e:
raise RuntimeError(
f"Failed to compile {os.getcwd()}/{glsl_out_path}"
) from e
opt_fail = "compilation succeeded but failed to optimize"
err_msg_base = f"Failed to compile {os.getcwd()}/{glsl_out_path}: "
if opt_fail in e.stderr or opt_fail in e.stdout:
cmd_no_opt = cmd_base + self.glslc_flags_no_opt
try:
subprocess.run(cmd_no_opt, check=True, capture_output=True)
except subprocess.CalledProcessError as e_no_opt:
raise RuntimeError(
f"{err_msg_base} {e_no_opt.stderr}"
) from e_no_opt

else:
raise RuntimeError(f"{err_msg_base} {e.stderr}") from e

return (spv_out_path, glsl_out_path)

Expand Down
Loading