|
6 | 6 | # LICENSE file in the root directory of this source tree. |
7 | 7 |
|
8 | 8 | import functools |
| 9 | +import os |
9 | 10 | import platform |
10 | 11 | import re |
11 | 12 | import subprocess |
@@ -55,6 +56,45 @@ def is_cuda_available() -> bool: |
55 | 56 | return False |
56 | 57 |
|
57 | 58 |
|
| 59 | +def is_vulkan_available() -> bool: |
| 60 | + """ |
| 61 | + Check if the Vulkan shader compiler (glslc) is available on the system. |
| 62 | +
|
| 63 | + glslc is the only build-time dependency for the Vulkan backend; the Vulkan |
| 64 | + loader itself is dlopen()ed at runtime via volk. Restricted to Linux and |
| 65 | + Windows, the desktop GPU platforms the backend supports (macOS would require |
| 66 | + MoltenVK). |
| 67 | +
|
| 68 | + glslc is looked up on PATH and, failing that, under $VULKAN_SDK/{bin,Bin} to |
| 69 | + match the find_program() HINTS the build uses (see pybind.cmake and |
| 70 | + ShaderLibrary.cmake): the Windows Vulkan SDK sets VULKAN_SDK but does not add |
| 71 | + its bin directory to PATH, so a PATH-only probe would miss it there. |
| 72 | +
|
| 73 | + Returns: |
| 74 | + True if glslc is available on a supported platform, False otherwise. |
| 75 | + """ |
| 76 | + if sys.platform not in ("linux", "win32"): |
| 77 | + return False |
| 78 | + candidates = ["glslc"] |
| 79 | + vulkan_sdk = os.environ.get("VULKAN_SDK") |
| 80 | + if vulkan_sdk: |
| 81 | + glslc_name = "glslc.exe" if sys.platform == "win32" else "glslc" |
| 82 | + candidates += [ |
| 83 | + os.path.join(vulkan_sdk, "bin", glslc_name), |
| 84 | + os.path.join(vulkan_sdk, "Bin", glslc_name), |
| 85 | + ] |
| 86 | + for glslc in candidates: |
| 87 | + try: |
| 88 | + # Only the exit status matters, so skip text=True; keep the except |
| 89 | + # tight to avoid masking things like UnicodeDecodeError. |
| 90 | + subprocess.run([glslc, "--version"], capture_output=True, check=True) |
| 91 | + return True |
| 92 | + except (OSError, subprocess.SubprocessError): |
| 93 | + # glslc missing or not runnable -> unavailable; try the next candidate. |
| 94 | + continue |
| 95 | + return False |
| 96 | + |
| 97 | + |
58 | 98 | @functools.lru_cache(maxsize=1) |
59 | 99 | def _get_cuda_version(): |
60 | 100 | """ |
|
0 commit comments