Commit c4faeb79 by Jamie Madill Committed by Commit Bot

Use SwiftShader-based ICD generation.

We moved this into the SwiftShader repo proper in: https://swiftshader-review.googlesource.com/c/SwiftShader/+/38491 We can remove ANGLE's custom rules. Also removes the layer generation script which was now unused. Also cleans up the Vulkan back-end BUILD.gn a bit. Bug: dawn:283 Change-Id: I490e8e8fc6fcadec58aca53a157ce7c4a47def3c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1932340Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 38e5a8de
#!/usr/bin/env python
#
# Copyright 2016 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Generate copies of the Vulkan layers JSON files, with no paths, forcing
Vulkan to use the default search path to look for layers."""
from __future__ import print_function
import argparse
import glob
import json
import os
import platform
import sys
def glob_slash(dirname):
"""Like regular glob but replaces \ with / in returned paths."""
return [s.replace('\\', '/') for s in glob.glob(dirname)]
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--icd', action='store_true')
parser.add_argument('source_dir')
parser.add_argument('target_dir')
parser.add_argument('version_header', help='path to vulkan_core.h')
parser.add_argument('json_files', nargs='*')
parser.add_argument('--replacement', help='replacement for the library', default=None)
args = parser.parse_args()
source_dir = args.source_dir
target_dir = args.target_dir
json_files = [j for j in args.json_files if j.endswith('.json')]
json_in_files = [j for j in args.json_files if j.endswith('.json.in')]
data_key = 'ICD' if args.icd else 'layer'
if not os.path.isdir(source_dir):
print(source_dir + ' is not a directory.', file=sys.stderr)
return 1
if not os.path.exists(target_dir):
os.makedirs(target_dir)
# Copy the *.json files from source dir to target dir
if (set(glob_slash(os.path.join(source_dir, '*.json'))) !=
set(json_files)) and data_key != 'ICD':
print(glob.glob(os.path.join(source_dir, '*.json')))
print('.json list in gn file is out-of-date', file=sys.stderr)
return 1
for json_fname in json_files:
if not json_fname.endswith('.json'):
continue
with open(json_fname) as infile:
data = json.load(infile)
# Update the path.
if not data_key in data:
raise Exception("Could not find '%s' key in %s" % (data_key, json_fname))
# The standard validation layer has no library path.
if 'library_path' in data[data_key]:
prev_name = os.path.basename(data[data_key]['library_path'])
if args.replacement:
data[data_key]['library_path'] = args.replacement
else:
data[data_key]['library_path'] = prev_name
target_fname = os.path.join(target_dir, os.path.basename(json_fname))
with open(target_fname, 'wb') as outfile:
json.dump(data, outfile)
# Get the Vulkan version from the vulkan_core.h file
vk_header_filename = args.version_header
vk_version = None
if data_key != 'ICD':
with open(vk_header_filename) as vk_header_file:
for line in vk_header_file:
if line.startswith('#define VK_HEADER_VERSION'):
vk_version = line.split()[-1]
break
if not vk_version:
print('failed to extract vk_version', file=sys.stderr)
return 1
# Set json file prefix and suffix for generating files, default to Linux.
relative_path_prefix = '../lib'
file_type_suffix = '.so'
if platform.system() == 'Windows':
relative_path_prefix = r'..\\' # json-escaped, hence two backslashes.
file_type_suffix = '.dll'
# For each *.json.in template files in source dir generate actual json file
# in target dir
if (set(glob_slash(os.path.join(source_dir, '*.json.in'))) != set(json_in_files)):
print('.json.in list in gn file is out-of-date', file=sys.stderr)
return 1
for json_in_name in json_in_files:
if not json_in_name.endswith('.json.in'):
continue
json_in_fname = os.path.basename(json_in_name)
layer_name = json_in_fname[:-len('.json.in')]
layer_lib_name = layer_name + file_type_suffix
json_out_fname = os.path.join(target_dir, json_in_fname[:-len('.in')])
with open(json_out_fname,'w') as json_out_file, \
open(json_in_name) as infile:
for line in infile:
line = line.replace('@RELATIVE_LAYER_BINARY@',
relative_path_prefix + layer_lib_name)
line = line.replace('@VK_VERSION@', '1.1.' + vk_version)
json_out_file.write(line)
if __name__ == '__main__':
sys.exit(main())
......@@ -151,76 +151,6 @@ if (is_mac) {
]
}
config("vulkan_config") {
_sws_icd = "./libvk_swiftshader_icd.json"
if (is_win) {
_sws_icd = ".\\\\libvk_swiftshader_icd.json"
}
defines = [
"ANGLE_VK_LAYERS_DIR=\"$angle_data_dir\"",
"ANGLE_VK_MOCK_ICD_JSON=\"$angle_data_dir/VkICD_mock_icd.json\"",
"ANGLE_VK_SWIFTSHADER_ICD_JSON=\"${_sws_icd}\"",
]
if (is_android) {
libs = [ "vulkan" ]
}
if (angle_enable_vulkan_validation_layers) {
defines += [ "ANGLE_ENABLE_VULKAN_VALIDATION_LAYERS_BY_DEFAULT" ]
}
}
if (angle_enable_swiftshader) {
copy("angle_swiftshader_icd_rename") {
sources = [
"$swiftshader_dir/src/Vulkan/vk_swiftshader_icd.json",
]
outputs = [
"$root_gen_dir/angle/libvk_swiftshader_icd.json",
]
}
action("angle_swiftshader_icd") {
deps = [
":angle_swiftshader_icd_rename",
"$angle_root/third_party/vulkan-headers/src:vulkan_headers",
]
script = "$angle_root/scripts/generate_vulkan_layers_json.py"
sources = [
"$angle_root/third_party/vulkan-headers/src/include/vulkan/vulkan_core.h",
]
# Must be listed after vulkan_core.h. git cl format sorts them if they
# are in one list. So split up the sources manually.
sources += [ "$root_gen_dir/angle/libvk_swiftshader_icd.json" ]
outputs = [
"$root_out_dir/libvk_swiftshader_icd.json",
]
data = outputs
_raw_sws_in = rebase_path("$root_gen_dir/angle", root_build_dir)
_raw_sws_out = rebase_path("$root_out_dir", root_build_dir)
_sws_output = ""
if (is_win) {
_sws_output += ".\\vk_swiftshader.dll"
} else if (is_mac) {
_sws_output += "./libvk_swiftshader.dylib"
} else {
_sws_output += "./libvk_swiftshader.so"
}
args = [
"--icd",
"--replacement",
_sws_output,
_raw_sws_in,
_raw_sws_out,
] + rebase_path(sources, root_build_dir)
}
}
config("angle_vulkan_lib_android") {
if (is_android) {
libs = [ "vulkan" ]
......@@ -272,9 +202,17 @@ angle_source_set("angle_vulkan_backend") {
]
public_configs = [ ":angle_vulkan_backend_config" ]
configs += [ ":vulkan_config" ]
data_deps = []
defines = [
"ANGLE_VK_LAYERS_DIR=\"$angle_data_dir\"",
"ANGLE_VK_MOCK_ICD_JSON=\"$angle_data_dir/VkICD_mock_icd.json\"",
]
if (is_android) {
libs += [ "vulkan" ]
}
# Include generated shaders.
import("vk_internal_shaders_autogen.gni")
sources += angle_vulkan_internal_shaders
......@@ -285,6 +223,7 @@ angle_source_set("angle_vulkan_backend") {
}
if (angle_enable_vulkan_validation_layers) {
defines += [ "ANGLE_ENABLE_VULKAN_VALIDATION_LAYERS_BY_DEFAULT" ]
if (is_fuchsia) {
data_deps += [ "//third_party/fuchsia-sdk:vulkan_validation" ]
} else {
......@@ -296,8 +235,16 @@ angle_source_set("angle_vulkan_backend") {
}
if (angle_enable_swiftshader) {
import("$swiftshader_dir/src/Vulkan/vulkan.gni")
_sws_icd = "./$swiftshader_icd_file_name"
if (is_win) {
_sws_icd = ".\\\\$swiftshader_icd_file_name"
}
defines += [ "ANGLE_VK_SWIFTSHADER_ICD_JSON=\"${_sws_icd}\"" ]
data_deps += [
":angle_swiftshader_icd",
"$swiftshader_dir/src/Vulkan:icd_file",
"$swiftshader_dir/src/Vulkan:swiftshader_libvulkan",
]
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment