-
-
Save fire/51a25deb25881649dbad to your computer and use it in GitHub Desktop.
Run scripts with added vulkan layers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Run programs with added vulkan layers. | |
Author: Henri Tuhola <[email protected]> | |
License: MIT | |
Date: 2016-2-20 | |
""" | |
import argparse, json, os, sys | |
parser = argparse.ArgumentParser(description="Run programs with added vulkan layers") | |
parser.add_argument("names", metavar="NAME", nargs='*', | |
help="Appropos for the vulkan layer to add") | |
parser.add_argument("-c", dest="cmd", metavar="COMMAND", nargs='+', | |
help="Command to execute") | |
parser.add_argument("-l", "--list", dest="ls", action="store_true", | |
help="List available layers") | |
args = parser.parse_args() | |
instance_layers = os.environ.get("VK_INSTANCE_LAYERS", "").split(":") | |
device_layers = os.environ.get("VK_DEVICE_LAYERS", "").split(":") | |
instance_layers = filter(bool, instance_layers) | |
device_layers = filter(bool, device_layers) | |
paths = [ | |
"/usr/share/vulkan/implicit_layer.d", | |
"/usr/share/vulkan/explicit_layer.d", | |
"/etc/vulkan/implicit_layer.d", | |
"/etc/vulkan/explicit_layer.d", | |
] | |
manifests = [] | |
for path in paths: | |
try: | |
manifests.extend(os.path.join(path, name) | |
for name in os.listdir(path) | |
if name.endswith(".json")) | |
except OSError as _: | |
pass | |
layers = [] | |
for path in manifests: | |
with open(path) as fd: | |
manifest = json.load(fd) | |
layers.append( manifest["layer"]["name"] ) | |
# I did not find the alias layers defined anywhere. So here it is. | |
aliases = { | |
"VK_LAYER_LUNARG_standard_validation": [ | |
"VK_LAYER_LUNARG_threading", | |
"VK_LAYER_LUNARG_param_checker", | |
"VK_LAYER_LUNARG_device_limits", | |
"VK_LAYER_LUNARG_object_tracker", | |
"VK_LAYER_LUNARG_image", | |
"VK_LAYER_LUNARG_mem_tracker", | |
"VK_LAYER_LUNARG_draw_state", | |
"VK_LAYER_LUNARG_swapchain", | |
"VK_LAYER_GOOGLE_unique_objects", | |
] | |
} | |
layers.extend(aliases) | |
for arg in args.names: | |
for name in layers: | |
if name.find(arg) >= 0: | |
instance_layers.append(name) | |
device_layers.append(name) | |
if args.ls: | |
for name in sorted(layers): | |
active = "[ ]" | |
if name in instance_layers and name in device_layers: | |
active = "[*]" | |
elif name in instance_layers: | |
active = "[I]" | |
elif name in device_layers: | |
active = "[D]" | |
sys.stdout.write("{:<40}{}\n".format(name, active)) | |
elif not args.cmd: | |
sys.stdout.write("\n ".join(["VK_INSTANCE_LAYERS="] + instance_layers) + "\n") | |
sys.stdout.write("\n ".join(["VK_DEVICE_LAYERS="] + device_layers) + "\n") | |
if args.cmd: | |
os.environ["VK_INSTANCE_LAYERS"] = ":".join(instance_layers) | |
os.environ["VK_DEVICE_LAYERS"] = ":".join(device_layers) | |
os.execvp(args.cmd[0], args.cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment