blob: 5556abdf097f203f858226718f4600106014f590 [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")
Nicolas Capens74c71132022-06-20 09:34:47 -040016import("//build_overrides/wayland.gni")
Yaroslav Isakove0d50dd2022-07-20 19:41:18 +020017import("//build/config/ozone.gni")
Saman Samif4d2a442019-05-21 15:04:41 -040018import("../swiftshader.gni")
Corentin Walleze7ce4e52019-11-22 16:13:50 +010019import("vulkan.gni")
Saman Samif4d2a442019-05-21 15:04:41 -040020
21# Need a separate config to ensure the warnings are added to the end.
22config("swiftshader_libvulkan_private_config") {
Ben Claytonbe3a0de2022-01-20 15:34:07 +000023 if (is_linux) {
Alexis Hetu110f60e2019-06-04 10:02:09 -040024 defines = [
Alexis Hetu110f60e2019-06-04 10:02:09 -040025 "VK_EXPORT=__attribute__((visibility(\"default\")))",
26 ]
Yaroslav Isakove0d50dd2022-07-20 19:41:18 +020027 if (ozone_platform_x11) {
28 defines += [ "VK_USE_PLATFORM_XCB_KHR" ]
29 }
Nicolas Capens74c71132022-06-20 09:34:47 -040030 if (ozone_platform_wayland) {
31 defines += [ "VK_USE_PLATFORM_WAYLAND_KHR" ]
32 }
Ben Claytonbe3a0de2022-01-20 15:34:07 +000033 } else if (is_chromeos) {
34 defines = [
35 "VK_EXPORT=__attribute__((visibility(\"default\")))",
36 ]
David 'Digit' Turner58c34f52019-08-12 14:11:58 +020037 } else if (is_fuchsia) {
38 defines = [
39 "VK_USE_PLATFORM_FUCHSIA=1",
40 "VK_EXPORT=__attribute__((visibility(\"default\")))",
41 ]
Jamie Madillbbd8c422019-08-28 17:08:17 -040042 } else if (is_win) {
43 defines = [
44 "VK_USE_PLATFORM_WIN32_KHR=1",
45 "VK_EXPORT=",
46 ]
Jonah Ryan-Davis6623ca12019-10-25 10:44:05 -060047 } else if (is_mac) {
48 defines = [
49 "VK_USE_PLATFORM_MACOS_MVK=1",
Jonah Ryan-Davis215bc792019-10-31 17:23:49 -040050 "VK_USE_PLATFORM_METAL_EXT=1",
Jonah Ryan-Davis6623ca12019-10-25 10:44:05 -060051 "VK_EXPORT=__attribute__((visibility(\"default\")))",
52 ]
Alexis Hetu110f60e2019-06-04 10:02:09 -040053 } else {
54 defines = [ "VK_EXPORT=" ]
55 }
Saman Samif4d2a442019-05-21 15:04:41 -040056
Jamie Madill9746f8b2019-09-05 13:17:09 -040057 if (is_clang) {
58 cflags = [
59 "-Wno-unused-private-field",
60 "-Wno-switch",
61 ]
62 }
Nicolas Capensa4347a92020-03-01 08:29:25 -050063
64 defines += [
65 "SWIFTSHADER_ENABLE_ASTC", # TODO(b/150130101)
Alexis Hétu22d5e1e2022-12-13 04:11:10 +000066 "SWIFTSHADER_LEGACY_PRECISION=true", # TODO(chromium:1299047)
Nicolas Capens5ca5b0a2022-05-25 17:04:06 -040067 "SWIFTSHADER_ZERO_INITIALIZE_DEVICE_MEMORY",
Nicolas Capensa4347a92020-03-01 08:29:25 -050068 ]
Saman Samif4d2a442019-05-21 15:04:41 -040069}
70
Jamie Madillfe23c662019-08-30 17:38:24 -040071swiftshader_source_set("swiftshader_libvulkan_headers") {
Saman Samif4d2a442019-05-21 15:04:41 -040072 sources = [
Antonio Maiorano42fd1592020-04-27 11:30:40 -040073 "Version.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040074 "VkBuffer.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040075 "VkBufferView.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040076 "VkCommandBuffer.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040077 "VkCommandPool.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -040078 "VkConfig.hpp",
Alexis Hetu74f6c652020-07-22 21:57:05 -040079 "VkDebugUtilsMessenger.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040080 "VkDescriptorPool.hpp",
81 "VkDescriptorSet.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040082 "VkDescriptorSetLayout.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040083 "VkDescriptorUpdateTemplate.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -040084 "VkDestroy.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040085 "VkDevice.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040086 "VkDeviceMemory.hpp",
Alexis Hetua1594b92021-10-07 15:48:06 -040087 "VkDeviceMemoryExternalHost.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040088 "VkEvent.hpp",
89 "VkFence.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -040090 "VkFormat.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040091 "VkFramebuffer.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -040092 "VkGetProcAddress.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040093 "VkImage.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040094 "VkImageView.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040095 "VkInstance.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -040096 "VkMemory.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040097 "VkObject.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040098 "VkPhysicalDevice.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040099 "VkPipeline.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -0400100 "VkPipelineCache.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -0400101 "VkPipelineLayout.hpp",
Alexis Hetuea980602021-10-29 09:27:51 -0400102 "VkPrivateData.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -0400103 "VkQueryPool.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -0400104 "VkQueue.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -0400105 "VkRenderPass.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -0400106 "VkSampler.hpp",
107 "VkSemaphore.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -0400108 "VkShaderModule.hpp",
Ben Clayton4d23aa32020-04-14 20:33:52 +0100109 "VkSpecializationInfo.hpp",
Ben Clayton597db182019-11-24 22:40:40 +0000110 "VkStringify.hpp",
Alexis Hetu62c5ce32021-11-11 16:30:00 -0500111 "VkStructConversion.hpp",
Sean Risser68463892020-12-14 16:35:57 -0500112 "VkTimelineSemaphore.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -0400113 "VulkanPlatform.hpp",
Jamie Madillfe23c662019-08-30 17:38:24 -0400114 ]
Hidehiko Abefe878de2020-09-11 16:12:25 +0900115 if (is_linux || is_chromeos || is_android) {
David 'Digit' Turner7c4d0a02019-09-03 17:00:02 +0200116 sources += [
David 'Digit' Turner359bc802019-08-14 17:46:07 +0200117 "VkDeviceMemoryExternalLinux.hpp",
David 'Digit' Turner7c4d0a02019-09-03 17:00:02 +0200118 "VkSemaphoreExternalLinux.hpp",
119 ]
David 'Digit' Turner89fd1482020-02-20 13:12:08 +0100120 } else if (is_mac) {
121 sources += [
122 "VkDeviceMemoryExternalMac.hpp",
123 ]
David 'Digit' Turnerfda994c2019-09-04 16:36:36 +0200124 } else if (is_fuchsia) {
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100125 sources += [ "VkSemaphoreExternalFuchsia.hpp" ]
David 'Digit' Turner7c4d0a02019-09-03 17:00:02 +0200126 }
Jamie Madillfe23c662019-08-30 17:38:24 -0400127}
128
129swiftshader_shared_library("swiftshader_libvulkan") {
130 sources = [
131 "VkBuffer.cpp",
132 "VkBufferView.cpp",
133 "VkCommandBuffer.cpp",
134 "VkCommandPool.cpp",
Alexis Hetu74f6c652020-07-22 21:57:05 -0400135 "VkDebugUtilsMessenger.cpp",
Jamie Madillfe23c662019-08-30 17:38:24 -0400136 "VkDescriptorPool.cpp",
Alexis Hetu4f438a52020-06-15 16:13:51 -0400137 "VkDescriptorSet.cpp",
Jamie Madillfe23c662019-08-30 17:38:24 -0400138 "VkDescriptorSetLayout.cpp",
139 "VkDescriptorUpdateTemplate.cpp",
140 "VkDevice.cpp",
141 "VkDeviceMemory.cpp",
Alexis Hetua1594b92021-10-07 15:48:06 -0400142 "VkDeviceMemoryExternalHost.cpp",
Jamie Madillfe23c662019-08-30 17:38:24 -0400143 "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",
David 'Digit' Turner99938ea2019-09-03 15:11:17 +0200159 "VkSemaphore.cpp",
Jamie Madillfe23c662019-08-30 17:38:24 -0400160 "VkShaderModule.cpp",
Ben Clayton4d23aa32020-04-14 20:33:52 +0100161 "VkSpecializationInfo.cpp",
Ben Claytond44d6152019-11-24 22:40:40 +0000162 "VkStringify.cpp",
Sean Risser68463892020-12-14 16:35:57 -0500163 "VkTimelineSemaphore.cpp",
Saman Samif4d2a442019-05-21 15:04:41 -0400164 "libVulkan.cpp",
Saman Samif4d2a442019-05-21 15:04:41 -0400165 "main.cpp",
166 "resource.h",
167 ]
168
169 configs = [ ":swiftshader_libvulkan_private_config" ]
170
Dan Fieldbea8d242022-06-13 12:55:52 -0700171 libs = []
172
Jamie Madill9746f8b2019-09-05 13:17:09 -0400173 # TODO(capn): Use the same ICD name on both Windows and non-Windows.
174 if (is_win) {
175 output_name = "vk_swiftshader"
176 } else {
177 output_name = "libvk_swiftshader"
178 }
Saman Samif4d2a442019-05-21 15:04:41 -0400179
Sylvain Defresneb94db862020-09-24 11:47:25 +0200180 if (is_win) {
181 sources += [
182 "Vulkan.rc",
183 "vk_swiftshader.def",
184 ]
Dan Fieldbea8d242022-06-13 12:55:52 -0700185 libs += [
186 "gdi32.lib",
187 "user32.lib",
188 ]
Sylvain Defresneb94db862020-09-24 11:47:25 +0200189 }
190
Alexis Hetuec63fbe2019-07-15 14:33:11 -0400191 if (is_mac) {
192 ldflags = [
193 "-Wl,-install_name,@rpath/libvk_swiftshader.dylib",
194 "-Wl,-exported_symbols_list," +
Nicolas Capensf0033322019-08-30 12:51:12 -0400195 rebase_path("vk_swiftshader.exports", root_build_dir),
Alexis Hetuec63fbe2019-07-15 14:33:11 -0400196 ]
Hidehiko Abefe878de2020-09-11 16:12:25 +0900197 } else if (is_linux || is_chromeos || is_fuchsia) {
Tom Anderson42d64612019-06-12 11:05:21 -0700198 inputs = [
Nicolas Capensf0033322019-08-30 12:51:12 -0400199 "vk_swiftshader.lds",
Tom Anderson42d64612019-06-12 11:05:21 -0700200 ]
Nicolas Capense3621dc2020-02-25 22:45:42 -0500201 ldflags = [
202 # -Bsymbolic binds symbol references to their global definitions within
203 # a shared object, thereby preventing symbol preemption.
204 "-Wl,-Bsymbolic",
205 "-Wl,--version-script=" +
206 rebase_path("vk_swiftshader.lds", root_build_dir) ]
Alexis Hetuf9e9cf62019-06-05 17:18:40 -0400207 }
Saman Samif4d2a442019-05-21 15:04:41 -0400208
209 deps = [
Nicolas Capensdde31452022-03-18 16:09:22 -0400210 "../../third_party/SPIRV-Tools:spvtools_opt",
211 "../../third_party/SPIRV-Tools:spvtools_val",
212 "../../third_party/SPIRV-Tools:spvtools_headers",
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100213 "../../third_party/marl:Marl",
Saman Samif4d2a442019-05-21 15:04:41 -0400214 "../Device",
215 "../Pipeline",
Alexis Hetuf6e439f2020-03-10 16:44:26 -0400216 "../Reactor:swiftshader_reactor",
Saman Samif4d2a442019-05-21 15:04:41 -0400217 "../System",
218 "../WSI",
Saman Samif4d2a442019-05-21 15:04:41 -0400219 ]
220
221 include_dirs = [
222 "..",
223 "../../include",
Nicolas Capensdde31452022-03-18 16:09:22 -0400224 "../../third_party/SPIRV-Tools/include",
225 "../../third_party/SPIRV-Headers/include",
Saman Samif4d2a442019-05-21 15:04:41 -0400226 ]
Jamie Madillfe23c662019-08-30 17:38:24 -0400227
228 public_deps = [
229 ":swiftshader_libvulkan_headers",
230 ]
Saman Samif4d2a442019-05-21 15:04:41 -0400231}
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100232
233# Generates an ICD JSON file that can be used by all targets in this GN build
234# (ANGLE, Dawn, Chromium).
235action("icd_file") {
Jamie Madill2613cb52019-11-27 08:34:49 -0500236 output_icd_file = "${root_out_dir}/${swiftshader_icd_file_name}"
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100237 input_file = swiftshader_icd_file_name
238
239 if (is_win) {
240 library_path = ".\\vk_swiftshader.dll"
241 } else if (is_mac) {
242 library_path = "./libvk_swiftshader.dylib"
Sergey Ulanov61f6c382021-11-12 02:02:57 +0000243 } else if (is_fuchsia) {
244 library_path = "/pkg/lib/libvk_swiftshader.so"
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100245 } else {
246 library_path = "./libvk_swiftshader.so"
247 }
248
249 script = "write_icd_json.py"
250 args = [
251 "--input",
Jamie Madill389749a2019-11-28 10:35:58 -0500252 rebase_path(input_file, root_build_dir),
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100253 "--output",
Jamie Madill389749a2019-11-28 10:35:58 -0500254 rebase_path(output_icd_file, root_build_dir),
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100255 "--library_path",
256 library_path,
257 ]
258
259 inputs = [
260 input_file,
261 ]
262 outputs = [
263 output_icd_file,
264 ]
265
266 deps = [
267 ":swiftshader_libvulkan",
268 ]
269}