1# Copyright 2019 The SwiftShader Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15import("//build/config/ozone.gni") 16import("//build_overrides/build.gni") 17import("//build_overrides/wayland.gni") 18import("../swiftshader.gni") 19import("vulkan.gni") 20 21# Need a separate config to ensure the warnings are added to the end. 22config("swiftshader_libvulkan_private_config") { 23 if (is_linux) { 24 defines = [ "VK_EXPORT=__attribute__((visibility(\"default\")))" ] 25 if (ozone_platform_x11) { 26 defines += [ "VK_USE_PLATFORM_XCB_KHR" ] 27 } 28 if (ozone_platform_wayland) { 29 defines += [ "VK_USE_PLATFORM_WAYLAND_KHR" ] 30 } 31 } else if (is_chromeos) { 32 defines = [ "VK_EXPORT=__attribute__((visibility(\"default\")))" ] 33 } else if (is_fuchsia) { 34 defines = [ 35 "VK_USE_PLATFORM_FUCHSIA=1", 36 "VK_EXPORT=__attribute__((visibility(\"default\")))", 37 ] 38 } else if (is_win) { 39 defines = [ 40 "VK_USE_PLATFORM_WIN32_KHR=1", 41 "VK_EXPORT=", 42 ] 43 } else if (is_mac) { 44 defines = [ 45 "VK_USE_PLATFORM_MACOS_MVK=1", 46 "VK_USE_PLATFORM_METAL_EXT=1", 47 "VK_EXPORT=__attribute__((visibility(\"default\")))", 48 ] 49 } else { 50 defines = [ "VK_EXPORT=" ] 51 } 52 53 if (is_clang) { 54 cflags = [ 55 "-Wno-unused-private-field", 56 "-Wno-switch", 57 ] 58 } 59 60 defines += [ 61 "SWIFTSHADER_ENABLE_ASTC", # TODO(b/150130101) 62 "SWIFTSHADER_LEGACY_PRECISION=true", # TODO(chromium:1299047) 63 "SWIFTSHADER_ZERO_INITIALIZE_DEVICE_MEMORY", 64 ] 65 66 if (build_with_chromium) { 67 # Chromium requires higher precision filtering to pass the layout tests with SwiftShader. 68 # http://crbug.com/726075 69 defines += [ "SWIFTSHADER_HIGH_PRECISION_FILTERING" ] 70 } 71} 72 73swiftshader_source_set("swiftshader_libvulkan_headers") { 74 sources = [ 75 "Version.hpp", 76 "VkBuffer.hpp", 77 "VkBufferView.hpp", 78 "VkCommandBuffer.hpp", 79 "VkCommandPool.hpp", 80 "VkConfig.hpp", 81 "VkDebugUtilsMessenger.hpp", 82 "VkDescriptorPool.hpp", 83 "VkDescriptorSet.hpp", 84 "VkDescriptorSetLayout.hpp", 85 "VkDescriptorUpdateTemplate.hpp", 86 "VkDestroy.hpp", 87 "VkDevice.hpp", 88 "VkDeviceMemory.hpp", 89 "VkDeviceMemoryExternalHost.hpp", 90 "VkEvent.hpp", 91 "VkFence.hpp", 92 "VkFormat.hpp", 93 "VkFramebuffer.hpp", 94 "VkGetProcAddress.hpp", 95 "VkImage.hpp", 96 "VkImageView.hpp", 97 "VkInstance.hpp", 98 "VkMemory.hpp", 99 "VkObject.hpp", 100 "VkPhysicalDevice.hpp", 101 "VkPipeline.hpp", 102 "VkPipelineCache.hpp", 103 "VkPipelineLayout.hpp", 104 "VkPrivateData.hpp", 105 "VkQueryPool.hpp", 106 "VkQueue.hpp", 107 "VkRenderPass.hpp", 108 "VkSampler.hpp", 109 "VkSemaphore.hpp", 110 "VkShaderModule.hpp", 111 "VkSpecializationInfo.hpp", 112 "VkStringify.hpp", 113 "VkStructConversion.hpp", 114 "VkTimelineSemaphore.hpp", 115 "VulkanPlatform.hpp", 116 ] 117 if (is_linux || is_chromeos || is_android) { 118 sources += [ 119 "VkDeviceMemoryExternalLinux.hpp", 120 "VkSemaphoreExternalLinux.hpp", 121 ] 122 } else if (is_mac) { 123 sources += [ "VkDeviceMemoryExternalMac.hpp" ] 124 } else if (is_fuchsia) { 125 sources += [ "VkSemaphoreExternalFuchsia.hpp" ] 126 } 127} 128 129swiftshader_source_set("_swiftshader_libvulkan") { 130 sources = [ 131 "VkBuffer.cpp", 132 "VkBufferView.cpp", 133 "VkCommandBuffer.cpp", 134 "VkCommandPool.cpp", 135 "VkDebugUtilsMessenger.cpp", 136 "VkDescriptorPool.cpp", 137 "VkDescriptorSet.cpp", 138 "VkDescriptorSetLayout.cpp", 139 "VkDescriptorUpdateTemplate.cpp", 140 "VkDevice.cpp", 141 "VkDeviceMemory.cpp", 142 "VkDeviceMemoryExternalHost.cpp", 143 "VkFormat.cpp", 144 "VkFramebuffer.cpp", 145 "VkGetProcAddress.cpp", 146 "VkImage.cpp", 147 "VkImageView.cpp", 148 "VkInstance.cpp", 149 "VkMemory.cpp", 150 "VkPhysicalDevice.cpp", 151 "VkPipeline.cpp", 152 "VkPipelineCache.cpp", 153 "VkPipelineLayout.cpp", 154 "VkPromotedExtensions.cpp", 155 "VkQueryPool.cpp", 156 "VkQueue.cpp", 157 "VkRenderPass.cpp", 158 "VkSampler.cpp", 159 "VkSemaphore.cpp", 160 "VkShaderModule.cpp", 161 "VkSpecializationInfo.cpp", 162 "VkStringify.cpp", 163 "VkTimelineSemaphore.cpp", 164 "libVulkan.cpp", 165 "main.cpp", 166 "resource.h", 167 ] 168 169 configs = [ ":swiftshader_libvulkan_private_config" ] 170 171 libs = [] 172 173 if (is_win) { 174 libs += [ 175 "gdi32.lib", 176 "user32.lib", 177 ] 178 } 179 180 public_deps = [ 181 ":swiftshader_libvulkan_headers", 182 "../../third_party/SPIRV-Tools:spvtools_headers", 183 "../../third_party/SPIRV-Tools:spvtools_opt", 184 "../../third_party/SPIRV-Tools:spvtools_val", 185 "../../third_party/marl:Marl", 186 "../Device", 187 "../Pipeline", 188 "../Reactor:swiftshader_reactor", 189 "../System", 190 "../WSI", 191 ] 192 193 include_dirs = [ 194 "..", 195 "../../include", 196 "../../third_party/SPIRV-Tools/include", 197 "../../third_party/SPIRV-Headers/include", 198 ] 199} 200 201swiftshader_shared_library("swiftshader_libvulkan") { 202 # TODO(capn): Use the same ICD name on both Windows and non-Windows. 203 if (is_win) { 204 output_name = "vk_swiftshader" 205 } else { 206 output_name = "libvk_swiftshader" 207 } 208 209 if (is_win) { 210 sources = [ 211 "Vulkan.rc", 212 "vk_swiftshader.def", 213 ] 214 } else if (is_mac) { 215 ldflags = [ 216 "-Wl,-install_name,@rpath/libvk_swiftshader.dylib", 217 "-Wl,-exported_symbols_list," + 218 rebase_path("vk_swiftshader.exports", root_build_dir), 219 ] 220 } else if (is_linux || is_chromeos || is_fuchsia) { 221 inputs = [ "vk_swiftshader.lds" ] 222 ldflags = [ 223 # -Bsymbolic binds symbol references to their global definitions within 224 # a shared object, thereby preventing symbol preemption. 225 "-Wl,-Bsymbolic", 226 "-Wl,--version-script=" + 227 rebase_path("vk_swiftshader.lds", root_build_dir), 228 ] 229 } 230 231 deps = [ ":_swiftshader_libvulkan" ] 232} 233 234swiftshader_static_library("swiftshader_libvulkan_static") { 235 complete_static_lib = true 236 deps = [ ":_swiftshader_libvulkan" ] 237} 238 239# Generates an ICD JSON file that can be used by all targets in this GN build 240# (ANGLE, Dawn, Chromium). 241action("icd_file") { 242 output_icd_file = "${root_out_dir}/${swiftshader_icd_file_name}" 243 input_file = swiftshader_icd_file_name 244 245 if (is_win) { 246 library_path = ".\\vk_swiftshader.dll" 247 } else if (is_mac) { 248 library_path = "./libvk_swiftshader.dylib" 249 } else if (is_fuchsia) { 250 library_path = "/pkg/lib/libvk_swiftshader.so" 251 } else { 252 library_path = "./libvk_swiftshader.so" 253 } 254 255 script = "write_icd_json.py" 256 args = [ 257 "--input", 258 rebase_path(input_file, root_build_dir), 259 "--output", 260 rebase_path(output_icd_file, root_build_dir), 261 "--library_path", 262 library_path, 263 ] 264 265 inputs = [ input_file ] 266 outputs = [ output_icd_file ] 267 268 deps = [ ":swiftshader_libvulkan" ] 269} 270