• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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("${skia_root_dir}/build_overrides/build.gni")
16import("../swiftshader.gni")
17import("vulkan.gni")
18
19# Need a separate config to ensure the warnings are added to the end.
20config("swiftshader_libvulkan_private_config") {
21  if (is_linux || is_chromeos) {
22    defines = [
23      "VK_USE_PLATFORM_XLIB_KHR",
24      "VK_USE_PLATFORM_XCB_KHR",
25      "VK_EXPORT=__attribute__((visibility(\"default\")))",
26    ]
27  } else if (is_fuchsia) {
28    defines = [
29      "VK_USE_PLATFORM_FUCHSIA=1",
30      "VK_EXPORT=__attribute__((visibility(\"default\")))",
31    ]
32  } else if (is_win) {
33    defines = [
34      "VK_USE_PLATFORM_WIN32_KHR=1",
35      "VK_EXPORT=",
36    ]
37  } else if (is_mac) {
38    defines = [
39      "VK_USE_PLATFORM_MACOS_MVK=1",
40      "VK_USE_PLATFORM_METAL_EXT=1",
41      "VK_EXPORT=__attribute__((visibility(\"default\")))",
42    ]
43  } else {
44    defines = [ "VK_EXPORT=" ]
45  }
46
47  if (is_clang) {
48    cflags = [
49      "-Wno-unused-private-field",
50      "-Wno-switch",
51    ]
52  }
53
54  defines += [
55     "SWIFTSHADER_ENABLE_ASTC",  # TODO(b/150130101)
56  ]
57}
58
59swiftshader_source_set("swiftshader_libvulkan_headers") {
60  sources = [
61    "Version.hpp",
62    "VkBuffer.hpp",
63    "VkBufferView.hpp",
64    "VkCommandBuffer.hpp",
65    "VkCommandPool.hpp",
66    "VkConfig.hpp",
67    "VkDebugUtilsMessenger.hpp",
68    "VkDescriptorPool.hpp",
69    "VkDescriptorSet.hpp",
70    "VkDescriptorSetLayout.hpp",
71    "VkDescriptorUpdateTemplate.hpp",
72    "VkDestroy.hpp",
73    "VkDevice.hpp",
74    "VkDeviceMemory.hpp",
75    "VkDeviceMemoryExternalHost.hpp",
76    "VkEvent.hpp",
77    "VkFence.hpp",
78    "VkFormat.hpp",
79    "VkFramebuffer.hpp",
80    "VkGetProcAddress.hpp",
81    "VkImage.hpp",
82    "VkImageView.hpp",
83    "VkInstance.hpp",
84    "VkMemory.hpp",
85    "VkObject.hpp",
86    "VkPhysicalDevice.hpp",
87    "VkPipeline.hpp",
88    "VkPipelineCache.hpp",
89    "VkPipelineLayout.hpp",
90    "VkQueryPool.hpp",
91    "VkQueue.hpp",
92    "VkRenderPass.hpp",
93    "VkSampler.hpp",
94    "VkSemaphore.hpp",
95    "VkShaderModule.hpp",
96    "VkSpecializationInfo.hpp",
97    "VkStringify.hpp",
98    "VkStructConversion.hpp",
99    "VkTimelineSemaphore.hpp",
100    "VulkanPlatform.hpp",
101  ]
102  if (is_linux || is_chromeos || is_android) {
103    sources += [
104      "VkDeviceMemoryExternalLinux.hpp",
105      "VkSemaphoreExternalLinux.hpp",
106    ]
107  } else if (is_mac) {
108    sources += [
109      "VkDeviceMemoryExternalMac.hpp",
110    ]
111  } else if (is_fuchsia) {
112    sources += [ "VkSemaphoreExternalFuchsia.hpp" ]
113  }
114}
115
116swiftshader_shared_library("swiftshader_libvulkan") {
117  sources = [
118    "VkBuffer.cpp",
119    "VkBufferView.cpp",
120    "VkCommandBuffer.cpp",
121    "VkCommandPool.cpp",
122    "VkDebugUtilsMessenger.cpp",
123    "VkDescriptorPool.cpp",
124    "VkDescriptorSet.cpp",
125    "VkDescriptorSetLayout.cpp",
126    "VkDescriptorUpdateTemplate.cpp",
127    "VkDevice.cpp",
128    "VkDeviceMemory.cpp",
129    "VkDeviceMemoryExternalHost.cpp",
130    "VkFormat.cpp",
131    "VkFramebuffer.cpp",
132    "VkGetProcAddress.cpp",
133    "VkImage.cpp",
134    "VkImageView.cpp",
135    "VkInstance.cpp",
136    "VkMemory.cpp",
137    "VkPhysicalDevice.cpp",
138    "VkPipeline.cpp",
139    "VkPipelineCache.cpp",
140    "VkPipelineLayout.cpp",
141    "VkPromotedExtensions.cpp",
142    "VkQueryPool.cpp",
143    "VkQueue.cpp",
144    "VkRenderPass.cpp",
145    "VkSampler.cpp",
146    "VkSemaphore.cpp",
147    "VkShaderModule.cpp",
148    "VkSpecializationInfo.cpp",
149    "VkStringify.cpp",
150    "VkTimelineSemaphore.cpp",
151    "libVulkan.cpp",
152    "main.cpp",
153    "resource.h",
154  ]
155
156  configs = [ ":swiftshader_libvulkan_private_config" ]
157
158  # TODO(capn): Use the same ICD name on both Windows and non-Windows.
159  if (is_win) {
160    output_name = "vk_swiftshader"
161  } else {
162    output_name = "libvk_swiftshader"
163  }
164
165  if (is_win) {
166    sources += [
167      "Vulkan.rc",
168      "vk_swiftshader.def",
169    ]
170  }
171
172  if (is_mac) {
173    ldflags = [
174      "-Wl,-install_name,@rpath/libvk_swiftshader.dylib",
175      "-Wl,-exported_symbols_list," +
176          rebase_path("vk_swiftshader.exports", root_build_dir),
177    ]
178  } else if (is_linux || is_chromeos || is_fuchsia) {
179    inputs = [
180      "vk_swiftshader.lds",
181    ]
182    ldflags = [
183      # -Bsymbolic binds symbol references to their global definitions within
184      # a shared object, thereby preventing symbol preemption.
185      "-Wl,-Bsymbolic",
186      "-Wl,--version-script=" +
187          rebase_path("vk_swiftshader.lds", root_build_dir) ]
188  }
189
190  deps = [
191    "${swiftshader_spirv_tools_dir}:SPIRV-Tools",
192    "../../third_party/marl:Marl",
193    "../Device",
194    "../Pipeline",
195    "../Reactor:swiftshader_reactor",
196    "../System",
197    "../WSI",
198  ]
199
200  include_dirs = [
201    "..",
202    "../../include",
203    "$swiftshader_spirv_tools_dir/include",
204    "$spirv_tools_spirv_headers_dir/include",
205  ]
206
207  public_deps = [
208    ":swiftshader_libvulkan_headers",
209  ]
210}
211
212# Generates an ICD JSON file that can be used by all targets in this GN build
213# (ANGLE, Dawn, Chromium).
214action("icd_file") {
215  output_icd_file = "${root_out_dir}/${swiftshader_icd_file_name}"
216  input_file = swiftshader_icd_file_name
217
218  if (is_win) {
219    library_path = ".\\vk_swiftshader.dll"
220  } else if (is_mac) {
221    library_path = "./libvk_swiftshader.dylib"
222  } else {
223    library_path = "./libvk_swiftshader.so"
224  }
225
226  script = "write_icd_json.py"
227  args = [
228    "--input",
229    rebase_path(input_file, root_build_dir),
230    "--output",
231    rebase_path(output_icd_file, root_build_dir),
232    "--library_path",
233    library_path,
234  ]
235
236  inputs = [
237    input_file,
238  ]
239  outputs = [
240    output_icd_file,
241  ]
242
243  deps = [
244    ":swiftshader_libvulkan",
245  ]
246}
247