1# Copyright (C) 2018-2019 The ANGLE Project Authors. 2# Copyright (C) 2019 LunarG, Inc. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# https://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import("//build_overrides/vulkan_validation_layers.gni") 17 18# Fuchsia has non-upstream changes to the vulkan layers, so we don't want 19# to build it from upstream sources. 20assert(!is_fuchsia) 21 22vulkan_undefine_configs = [] 23if (is_win) { 24 vulkan_undefine_configs += [ 25 "//build/config/win:nominmax", 26 "//build/config/win:unicode", 27 ] 28} 29 30vulkan_gen_dir = "$target_gen_dir/$vulkan_gen_subdir" 31raw_vulkan_gen_dir = rebase_path(vulkan_gen_dir, root_build_dir) 32 33vulkan_data_dir = "$root_out_dir/$vulkan_data_subdir" 34raw_vulkan_data_dir = rebase_path(vulkan_data_dir, root_build_dir) 35 36raw_root_out_dir = rebase_path(root_out_dir, root_build_dir) 37 38# This special action is needed to remove old VVL objects that are now renamed. 39action("vulkan_clean_old_validation_layer_objects") { 40 script = "build-gn/remove_files.py" 41 42 # inputs is a (random) new file since the vvl roll, used to ensure the cleanup is done only once 43 inputs = [ 44 "layers/gpu_validation.cpp", 45 ] 46 outputs = [ 47 "$vulkan_gen_dir/old_vvl_files_are_removed", 48 ] 49 args = [ 50 "$raw_vulkan_gen_dir/old_vvl_files_are_removed", 51 "$raw_root_out_dir/libVkLayer*", 52 "$raw_root_out_dir/VkLayer*", 53 "$raw_vulkan_data_dir/VkLayer*.json", 54 ] 55} 56 57config("vulkan_internal_config") { 58 defines = [ 59 "VULKAN_NON_CMAKE_BUILD", 60 "API_NAME=\"Vulkan\"", 61 ] 62 if (is_clang || !is_win) { 63 cflags = [ "-Wno-unused-function" ] 64 } 65 if (is_linux) { 66 defines += [ 67 "SYSCONFDIR=\"/etc\"", 68 "FALLBACK_CONFIG_DIRS=\"/etc/xdg\"", 69 "FALLBACK_DATA_DIRS=\"/usr/local/share:/usr/share\"", 70 ] 71 } 72} 73 74# The validation layers 75# --------------------- 76 77config("vulkan_layer_config") { 78 include_dirs = [ 79 "layers", 80 "layers/generated", 81 ] 82} 83 84core_validation_sources = [ 85 # This file is manually included in the layer 86 # "layers/generated/vk_safe_struct.cpp", 87 "layers/buffer_validation.cpp", 88 "layers/buffer_validation.h", 89 "layers/core_validation.cpp", 90 "layers/core_validation.h", 91 "layers/convert_to_renderpass2.cpp", 92 "layers/descriptor_sets.cpp", 93 "layers/descriptor_sets.h", 94 "layers/drawdispatch.cpp", 95 "layers/gpu_validation.cpp", 96 "layers/gpu_validation.h", 97 "layers/shader_validation.cpp", 98 "layers/shader_validation.h", 99 "layers/xxhash.c", 100 "layers/xxhash.h", 101] 102 103object_lifetimes_sources = [ 104 "layers/generated/object_tracker.cpp", 105 "layers/generated/object_tracker.h", 106 "layers/object_tracker_utils.cpp", 107] 108 109stateless_validation_sources = [ 110 "layers/generated/parameter_validation.cpp", 111 "layers/generated/parameter_validation.h", 112 "layers/parameter_validation_utils.cpp", 113] 114 115thread_safety_sources = [ 116 "layers/generated/thread_safety.cpp", 117 "layers/generated/thread_safety.h", 118] 119 120unique_objects_sources = [] 121 122chassis_sources = [ 123 "layers/core_validation.h", 124 "layers/generated/vk_safe_struct.h", 125 "layers/generated/thread_safety.h", 126 "layers/generated/chassis.cpp", 127 "layers/generated/chassis.h", 128 "layers/generated/layer_chassis_dispatch.cpp", 129 "layers/generated/layer_chassis_dispatch.h", 130 "$vulkan_headers_dir/include/vulkan/vk_layer.h", 131 "$vulkan_headers_dir/include/vulkan/vulkan.h", 132] 133 134layers = [ 135 [ 136 "core_validation", 137 core_validation_sources + chassis_sources + thread_safety_sources, 138 [ ":vulkan_core_validation_glslang" ], 139 [ "BUILD_CORE_VALIDATION" ], 140 ], 141 [ 142 "object_lifetimes", 143 object_lifetimes_sources + chassis_sources + thread_safety_sources + core_validation_sources, 144 [ ":vulkan_core_validation_glslang" ], 145 [ "BUILD_OBJECT_TRACKER" ], 146 ], 147 [ 148 "stateless_validation", 149 stateless_validation_sources + chassis_sources + core_validation_sources, 150 [ ":vulkan_core_validation_glslang" ], 151 [ "BUILD_PARAMETER_VALIDATION" ], 152 ], 153 [ 154 "thread_safety", 155 thread_safety_sources + chassis_sources + core_validation_sources, 156 [ ":vulkan_core_validation_glslang" ], 157 [ "BUILD_THREAD_SAFETY" ], 158 ], 159 [ 160 "unique_objects", 161 unique_objects_sources + chassis_sources + core_validation_sources, 162 [ ":vulkan_core_validation_glslang" ], 163 [ "LAYER_CHASSIS_CAN_WRAP_HANDLES" ], 164 ], 165 [ 166 "khronos_validation", 167 core_validation_sources + object_lifetimes_sources + 168 stateless_validation_sources + thread_safety_sources + 169 unique_objects_sources + chassis_sources, 170 [ ":vulkan_core_validation_glslang" ], 171 [ 172 "BUILD_KHRONOS_VALIDATION", 173 "BUILD_CORE_VALIDATION", 174 "BUILD_OBJECT_TRACKER", 175 "BUILD_THREAD_SAFETY", 176 "BUILD_PARAMETER_VALIDATION", 177 "LAYER_CHASSIS_CAN_WRAP_HANDLES", 178 ], 179 ], 180] 181 182if (!is_android) { 183 action("vulkan_gen_json_files") { 184 script = "build-gn/generate_vulkan_layers_json.py" 185 public_deps = [ 186 ":vulkan_clean_old_validation_layer_objects", 187 ] 188 json_names = [ 189 "VkLayer_core_validation.json", 190 "VkLayer_object_lifetimes.json", 191 "VkLayer_stateless_validation.json", 192 "VkLayer_standard_validation.json", 193 "VkLayer_thread_safety.json", 194 "VkLayer_unique_objects.json", 195 "VkLayer_khronos_validation.json", 196 ] 197 sources = [ 198 "$vulkan_headers_dir/include/vulkan/vulkan_core.h", 199 "$vulkan_headers_dir/include/vulkan/vk_layer.h", 200 ] 201 outputs = [] 202 foreach(json_name, json_names) { 203 sources += [ "layers/json/$json_name.in" ] 204 outputs += [ "$vulkan_data_dir/$json_name" ] 205 } 206 args = [ 207 rebase_path("layers/json", root_build_dir), 208 rebase_path(vulkan_data_dir, root_build_dir), 209 ] + rebase_path(sources, root_build_dir) 210 211 # The layer JSON files are part of the necessary data deps. 212 data = outputs 213 } 214} 215 216source_set("vulkan_layer_utils") { 217 include_dirs = [ 218 "layers", 219 "layers/generated", 220 ] 221 sources = [ 222 "layers/vk_format_utils.cpp", 223 "layers/vk_format_utils.h", 224 "layers/vk_layer_config.cpp", 225 "layers/vk_layer_config.h", 226 "layers/vk_layer_extension_utils.cpp", 227 "layers/vk_layer_extension_utils.h", 228 "layers/vk_layer_utils.cpp", 229 "layers/vk_layer_utils.h", 230 "$vulkan_headers_dir/include/vulkan/vk_layer.h", 231 "$vulkan_headers_dir/include/vulkan/vulkan.h", 232 "$vulkan_headers_dir/include/vulkan/vk_sdk_platform.h", 233 ] 234 public_configs = [ 235 "$vulkan_headers_dir:vulkan_headers_config", 236 ":vulkan_internal_config", 237 ] 238 configs -= [ "//build/config/compiler:chromium_code" ] 239 configs += [ "//build/config/compiler:no_chromium_code" ] 240 public_deps = [] 241 configs -= vulkan_undefine_configs 242} 243 244config("vulkan_core_validation_config") { 245 include_dirs = [ "$vvl_glslang_dir" ] 246} 247 248source_set("vulkan_core_validation_glslang") { 249 public_deps = [ 250 "${vvl_spirv_tools_dir}:spvtools", 251 "${vvl_spirv_tools_dir}:spvtools_opt", 252 "${vvl_spirv_tools_dir}:spvtools_val", 253 ] 254 public_configs = [ 255 "$vulkan_headers_dir:vulkan_headers_config", 256 ":vulkan_core_validation_config", 257 ] 258} 259 260config("vulkan_stateless_validation_config") { 261 if (is_clang) { 262 cflags_cc = [ "-Wno-unused-const-variable" ] 263 } 264} 265 266foreach(layer_info, layers) { 267 name = layer_info[0] 268 shared_library("VkLayer_$name") { 269 configs -= [ "//build/config/compiler:chromium_code" ] 270 configs += [ "//build/config/compiler:no_chromium_code" ] 271 configs -= vulkan_undefine_configs 272 public_configs = [ ":vulkan_layer_config" ] 273 deps = [ 274 ":vulkan_layer_utils", 275 ] 276 if (layer_info[2] != "") { 277 deps += layer_info[2] 278 } 279 sources = layer_info[1] 280 if (is_win) { 281 sources += [ "layers/VkLayer_$name.def" ] 282 } 283 if (is_linux || is_android) { 284 ldflags = [ "-Wl,-Bsymbolic,--exclude-libs,ALL" ] 285 } 286 if (is_android) { 287 libs = [ 288 "log", 289 "nativewindow", 290 ] 291 configs -= [ "//build/config/android:hide_all_but_jni_onload" ] 292 } 293 defines = layer_info[3] 294 } 295} 296 297group("vulkan_validation_layers") { 298 data_deps = [] 299 foreach(layer_info, layers) { 300 name = layer_info[0] 301 data_deps += [ ":VkLayer_$name" ] 302 } 303} 304