blob: e20282ce2c68cc4bc61fb5d71c58495864424592 [file] [log] [blame]
Saman Samif4d2a442019-05-21 15:04:41 -04001# 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")
Corentin Walleze7ce4e52019-11-22 16:13:50 +010017import("vulkan.gni")
Saman Samif4d2a442019-05-21 15:04:41 -040018
19# Need a separate config to ensure the warnings are added to the end.
20config("swiftshader_libvulkan_private_config") {
Hidehiko Abefe878de2020-09-11 16:12:25 +090021 if (is_linux || is_chromeos) {
Alexis Hetu110f60e2019-06-04 10:02:09 -040022 defines = [
23 "VK_USE_PLATFORM_XLIB_KHR",
Jamie Madillcebb9632019-09-09 11:28:19 -040024 "VK_USE_PLATFORM_XCB_KHR",
Alexis Hetu110f60e2019-06-04 10:02:09 -040025 "VK_EXPORT=__attribute__((visibility(\"default\")))",
26 ]
David 'Digit' Turner58c34f52019-08-12 14:11:58 +020027 } else if (is_fuchsia) {
28 defines = [
29 "VK_USE_PLATFORM_FUCHSIA=1",
30 "VK_EXPORT=__attribute__((visibility(\"default\")))",
31 ]
Jamie Madillbbd8c422019-08-28 17:08:17 -040032 } else if (is_win) {
33 defines = [
34 "VK_USE_PLATFORM_WIN32_KHR=1",
35 "VK_EXPORT=",
36 ]
Jonah Ryan-Davis6623ca12019-10-25 10:44:05 -060037 } else if (is_mac) {
38 defines = [
39 "VK_USE_PLATFORM_MACOS_MVK=1",
Jonah Ryan-Davis215bc792019-10-31 17:23:49 -040040 "VK_USE_PLATFORM_METAL_EXT=1",
Jonah Ryan-Davis6623ca12019-10-25 10:44:05 -060041 "VK_EXPORT=__attribute__((visibility(\"default\")))",
42 ]
Alexis Hetu110f60e2019-06-04 10:02:09 -040043 } else {
44 defines = [ "VK_EXPORT=" ]
45 }
Saman Samif4d2a442019-05-21 15:04:41 -040046
Jamie Madill9746f8b2019-09-05 13:17:09 -040047 if (is_clang) {
48 cflags = [
49 "-Wno-unused-private-field",
50 "-Wno-switch",
51 ]
52 }
Nicolas Capensa4347a92020-03-01 08:29:25 -050053
54 defines += [
55 "SWIFTSHADER_ENABLE_ASTC", # TODO(b/150130101)
56 ]
Saman Samif4d2a442019-05-21 15:04:41 -040057}
58
Jamie Madillfe23c662019-08-30 17:38:24 -040059swiftshader_source_set("swiftshader_libvulkan_headers") {
Saman Samif4d2a442019-05-21 15:04:41 -040060 sources = [
Antonio Maiorano42fd1592020-04-27 11:30:40 -040061 "Version.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040062 "VkBuffer.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040063 "VkBufferView.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040064 "VkCommandBuffer.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040065 "VkCommandPool.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -040066 "VkConfig.hpp",
Alexis Hetu74f6c652020-07-22 21:57:05 -040067 "VkDebugUtilsMessenger.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040068 "VkDescriptorPool.hpp",
69 "VkDescriptorSet.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040070 "VkDescriptorSetLayout.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040071 "VkDescriptorUpdateTemplate.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -040072 "VkDestroy.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040073 "VkDevice.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040074 "VkDeviceMemory.hpp",
Alexis Hetua1594b92021-10-07 15:48:06 -040075 "VkDeviceMemoryExternalHost.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040076 "VkEvent.hpp",
77 "VkFence.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -040078 "VkFormat.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040079 "VkFramebuffer.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -040080 "VkGetProcAddress.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040081 "VkImage.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040082 "VkImageView.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040083 "VkInstance.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -040084 "VkMemory.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040085 "VkObject.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040086 "VkPhysicalDevice.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040087 "VkPipeline.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040088 "VkPipelineCache.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040089 "VkPipelineLayout.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040090 "VkQueryPool.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040091 "VkQueue.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040092 "VkRenderPass.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040093 "VkSampler.hpp",
94 "VkSemaphore.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040095 "VkShaderModule.hpp",
Ben Clayton4d23aa32020-04-14 20:33:52 +010096 "VkSpecializationInfo.hpp",
Ben Clayton597db182019-11-24 22:40:40 +000097 "VkStringify.hpp",
Sean Risser68463892020-12-14 16:35:57 -050098 "VkTimelineSemaphore.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -040099 "VulkanPlatform.hpp",
Jamie Madillfe23c662019-08-30 17:38:24 -0400100 ]
Hidehiko Abefe878de2020-09-11 16:12:25 +0900101 if (is_linux || is_chromeos || is_android) {
David 'Digit' Turner7c4d0a02019-09-03 17:00:02 +0200102 sources += [
David 'Digit' Turner359bc802019-08-14 17:46:07 +0200103 "VkDeviceMemoryExternalLinux.hpp",
David 'Digit' Turner7c4d0a02019-09-03 17:00:02 +0200104 "VkSemaphoreExternalLinux.hpp",
105 ]
David 'Digit' Turner89fd1482020-02-20 13:12:08 +0100106 } else if (is_mac) {
107 sources += [
108 "VkDeviceMemoryExternalMac.hpp",
109 ]
David 'Digit' Turnerfda994c2019-09-04 16:36:36 +0200110 } else if (is_fuchsia) {
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100111 sources += [ "VkSemaphoreExternalFuchsia.hpp" ]
David 'Digit' Turner7c4d0a02019-09-03 17:00:02 +0200112 }
Jamie Madillfe23c662019-08-30 17:38:24 -0400113}
114
115swiftshader_shared_library("swiftshader_libvulkan") {
116 sources = [
117 "VkBuffer.cpp",
118 "VkBufferView.cpp",
119 "VkCommandBuffer.cpp",
120 "VkCommandPool.cpp",
Alexis Hetu74f6c652020-07-22 21:57:05 -0400121 "VkDebugUtilsMessenger.cpp",
Jamie Madillfe23c662019-08-30 17:38:24 -0400122 "VkDescriptorPool.cpp",
Alexis Hetu4f438a52020-06-15 16:13:51 -0400123 "VkDescriptorSet.cpp",
Jamie Madillfe23c662019-08-30 17:38:24 -0400124 "VkDescriptorSetLayout.cpp",
125 "VkDescriptorUpdateTemplate.cpp",
126 "VkDevice.cpp",
127 "VkDeviceMemory.cpp",
Alexis Hetua1594b92021-10-07 15:48:06 -0400128 "VkDeviceMemoryExternalHost.cpp",
Jamie Madillfe23c662019-08-30 17:38:24 -0400129 "VkFormat.cpp",
130 "VkFramebuffer.cpp",
131 "VkGetProcAddress.cpp",
132 "VkImage.cpp",
133 "VkImageView.cpp",
134 "VkInstance.cpp",
135 "VkMemory.cpp",
136 "VkPhysicalDevice.cpp",
137 "VkPipeline.cpp",
138 "VkPipelineCache.cpp",
139 "VkPipelineLayout.cpp",
140 "VkPromotedExtensions.cpp",
141 "VkQueryPool.cpp",
142 "VkQueue.cpp",
143 "VkRenderPass.cpp",
144 "VkSampler.cpp",
David 'Digit' Turner99938ea2019-09-03 15:11:17 +0200145 "VkSemaphore.cpp",
Jamie Madillfe23c662019-08-30 17:38:24 -0400146 "VkShaderModule.cpp",
Ben Clayton4d23aa32020-04-14 20:33:52 +0100147 "VkSpecializationInfo.cpp",
Ben Claytond44d6152019-11-24 22:40:40 +0000148 "VkStringify.cpp",
Sean Risser68463892020-12-14 16:35:57 -0500149 "VkTimelineSemaphore.cpp",
Saman Samif4d2a442019-05-21 15:04:41 -0400150 "libVulkan.cpp",
Saman Samif4d2a442019-05-21 15:04:41 -0400151 "main.cpp",
152 "resource.h",
153 ]
154
155 configs = [ ":swiftshader_libvulkan_private_config" ]
156
Jamie Madill9746f8b2019-09-05 13:17:09 -0400157 # TODO(capn): Use the same ICD name on both Windows and non-Windows.
158 if (is_win) {
159 output_name = "vk_swiftshader"
160 } else {
161 output_name = "libvk_swiftshader"
162 }
Saman Samif4d2a442019-05-21 15:04:41 -0400163
Sylvain Defresneb94db862020-09-24 11:47:25 +0200164 if (is_win) {
165 sources += [
166 "Vulkan.rc",
167 "vk_swiftshader.def",
168 ]
169 }
170
Alexis Hetuec63fbe2019-07-15 14:33:11 -0400171 if (is_mac) {
172 ldflags = [
173 "-Wl,-install_name,@rpath/libvk_swiftshader.dylib",
174 "-Wl,-exported_symbols_list," +
Nicolas Capensf0033322019-08-30 12:51:12 -0400175 rebase_path("vk_swiftshader.exports", root_build_dir),
Alexis Hetuec63fbe2019-07-15 14:33:11 -0400176 ]
Hidehiko Abefe878de2020-09-11 16:12:25 +0900177 } else if (is_linux || is_chromeos || is_fuchsia) {
Tom Anderson42d64612019-06-12 11:05:21 -0700178 inputs = [
Nicolas Capensf0033322019-08-30 12:51:12 -0400179 "vk_swiftshader.lds",
Tom Anderson42d64612019-06-12 11:05:21 -0700180 ]
Nicolas Capense3621dc2020-02-25 22:45:42 -0500181 ldflags = [
182 # -Bsymbolic binds symbol references to their global definitions within
183 # a shared object, thereby preventing symbol preemption.
184 "-Wl,-Bsymbolic",
185 "-Wl,--version-script=" +
186 rebase_path("vk_swiftshader.lds", root_build_dir) ]
Alexis Hetuf9e9cf62019-06-05 17:18:40 -0400187 }
Saman Samif4d2a442019-05-21 15:04:41 -0400188
189 deps = [
Jamie Madillfe23c662019-08-30 17:38:24 -0400190 "${swiftshader_spirv_tools_dir}:SPIRV-Tools",
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100191 "../../third_party/marl:Marl",
Saman Samif4d2a442019-05-21 15:04:41 -0400192 "../Device",
193 "../Pipeline",
Alexis Hetuf6e439f2020-03-10 16:44:26 -0400194 "../Reactor:swiftshader_reactor",
Saman Samif4d2a442019-05-21 15:04:41 -0400195 "../System",
196 "../WSI",
Saman Samif4d2a442019-05-21 15:04:41 -0400197 ]
198
199 include_dirs = [
200 "..",
201 "../../include",
Jamie Madillbbd8c422019-08-28 17:08:17 -0400202 "$swiftshader_spirv_tools_dir/include",
203 "$spirv_tools_spirv_headers_dir/include",
Saman Samif4d2a442019-05-21 15:04:41 -0400204 ]
Jamie Madillfe23c662019-08-30 17:38:24 -0400205
206 public_deps = [
207 ":swiftshader_libvulkan_headers",
208 ]
Saman Samif4d2a442019-05-21 15:04:41 -0400209}
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100210
211# Generates an ICD JSON file that can be used by all targets in this GN build
212# (ANGLE, Dawn, Chromium).
213action("icd_file") {
Jamie Madill2613cb52019-11-27 08:34:49 -0500214 output_icd_file = "${root_out_dir}/${swiftshader_icd_file_name}"
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100215 input_file = swiftshader_icd_file_name
216
217 if (is_win) {
218 library_path = ".\\vk_swiftshader.dll"
219 } else if (is_mac) {
220 library_path = "./libvk_swiftshader.dylib"
221 } else {
222 library_path = "./libvk_swiftshader.so"
223 }
224
225 script = "write_icd_json.py"
226 args = [
227 "--input",
Jamie Madill389749a2019-11-28 10:35:58 -0500228 rebase_path(input_file, root_build_dir),
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100229 "--output",
Jamie Madill389749a2019-11-28 10:35:58 -0500230 rebase_path(output_icd_file, root_build_dir),
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100231 "--library_path",
232 library_path,
233 ]
234
235 inputs = [
236 input_file,
237 ]
238 outputs = [
239 output_icd_file,
240 ]
241
242 deps = [
243 ":swiftshader_libvulkan",
244 ]
245}