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_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    "VkEvent.hpp",
76    "VkFence.hpp",
77    "VkFormat.hpp",
78    "VkFramebuffer.hpp",
79    "VkGetProcAddress.hpp",
80    "VkImage.hpp",
81    "VkImageView.hpp",
82    "VkInstance.hpp",
83    "VkMemory.hpp",
84    "VkObject.hpp",
85    "VkPhysicalDevice.hpp",
86    "VkPipeline.hpp",
87    "VkPipelineCache.hpp",
88    "VkPipelineLayout.hpp",
89    "VkQueryPool.hpp",
90    "VkQueue.hpp",
91    "VkRenderPass.hpp",
92    "VkSampler.hpp",
93    "VkSemaphore.hpp",
94    "VkShaderModule.hpp",
95    "VkSpecializationInfo.hpp",
96    "VkStringify.hpp",
97    "VkTimelineSemaphore.hpp",
98    "VulkanPlatform.hpp",
99  ]
100  if (is_linux || is_chromeos || is_android) {
101    sources += [
102      "VkDeviceMemoryExternalLinux.hpp",
103      "VkSemaphoreExternalLinux.hpp",
104    ]
105  } else if (is_mac) {
106    sources += [
107      "VkDeviceMemoryExternalMac.hpp",
108    ]
109  } else if (is_fuchsia) {
110    sources += [ "VkSemaphoreExternalFuchsia.hpp" ]
111  }
112}
113
114swiftshader_shared_library("swiftshader_libvulkan") {
115  sources = [
116    "VkBuffer.cpp",
117    "VkBufferView.cpp",
118    "VkCommandBuffer.cpp",
119    "VkCommandPool.cpp",
120    "VkDebugUtilsMessenger.cpp",
121    "VkDescriptorPool.cpp",
122    "VkDescriptorSet.cpp",
123    "VkDescriptorSetLayout.cpp",
124    "VkDescriptorUpdateTemplate.cpp",
125    "VkDevice.cpp",
126    "VkDeviceMemory.cpp",
127    "VkFormat.cpp",
128    "VkFramebuffer.cpp",
129    "VkGetProcAddress.cpp",
130    "VkImage.cpp",
131    "VkImageView.cpp",
132    "VkInstance.cpp",
133    "VkMemory.cpp",
134    "VkPhysicalDevice.cpp",
135    "VkPipeline.cpp",
136    "VkPipelineCache.cpp",
137    "VkPipelineLayout.cpp",
138    "VkPromotedExtensions.cpp",
139    "VkQueryPool.cpp",
140    "VkQueue.cpp",
141    "VkRenderPass.cpp",
142    "VkSampler.cpp",
143    "VkSemaphore.cpp",
144    "VkShaderModule.cpp",
145    "VkSpecializationInfo.cpp",
146    "VkStringify.cpp",
147    "VkTimelineSemaphore.cpp",
148    "libVulkan.cpp",
149    "main.cpp",
150    "resource.h",
151  ]
152
153  configs = [ ":swiftshader_libvulkan_private_config" ]
154
155  # TODO(capn): Use the same ICD name on both Windows and non-Windows.
156  if (is_win) {
157    output_name = "vk_swiftshader"
158  } else {
159    output_name = "libvk_swiftshader"
160  }
161
162  if (is_win) {
163    sources += [
164      "Vulkan.rc",
165      "vk_swiftshader.def",
166    ]
167  }
168
169  if (is_mac) {
170    ldflags = [
171      "-Wl,-install_name,@rpath/libvk_swiftshader.dylib",
172      "-Wl,-exported_symbols_list," +
173          rebase_path("vk_swiftshader.exports", root_build_dir),
174    ]
175  } else if (is_linux || is_chromeos || is_fuchsia) {
176    inputs = [
177      "vk_swiftshader.lds",
178    ]
179    ldflags = [
180      # -Bsymbolic binds symbol references to their global definitions within
181      # a shared object, thereby preventing symbol preemption.
182      "-Wl,-Bsymbolic",
183      "-Wl,--version-script=" +
184          rebase_path("vk_swiftshader.lds", root_build_dir) ]
185  }
186
187  deps = [
188    "${swiftshader_spirv_tools_dir}:SPIRV-Tools",
189    "../../third_party/marl:Marl",
190    "../Device",
191    "../Pipeline",
192    "../Reactor:swiftshader_reactor",
193    "../System",
194    "../WSI",
195  ]
196
197  include_dirs = [
198    "..",
199    "../../include",
200    "$swiftshader_spirv_tools_dir/include",
201    "$spirv_tools_spirv_headers_dir/include",
202  ]
203
204  public_deps = [
205    ":swiftshader_libvulkan_headers",
206  ]
207}
208
209# Generates an ICD JSON file that can be used by all targets in this GN build
210# (ANGLE, Dawn, Chromium).
211action("icd_file") {
212  output_icd_file = "${root_out_dir}/${swiftshader_icd_file_name}"
213  input_file = swiftshader_icd_file_name
214
215  if (is_win) {
216    library_path = ".\\vk_swiftshader.dll"
217  } else if (is_mac) {
218    library_path = "./libvk_swiftshader.dylib"
219  } else {
220    library_path = "./libvk_swiftshader.so"
221  }
222
223  script = "write_icd_json.py"
224  args = [
225    "--input",
226    rebase_path(input_file, root_build_dir),
227    "--output",
228    rebase_path(output_icd_file, root_build_dir),
229    "--library_path",
230    library_path,
231  ]
232
233  inputs = [
234    input_file,
235  ]
236  outputs = [
237    output_icd_file,
238  ]
239
240  deps = [
241    ":swiftshader_libvulkan",
242  ]
243}
244