blob: ec6cd2b85d7eb9b3c7439ea861879a7eabbb5f61 [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") {
Alexis Hetu110f60e2019-06-04 10:02:09 -040021 if (is_linux) {
22 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",
Saman Samif4d2a442019-05-21 15:04:41 -040067 "VkDescriptorPool.hpp",
68 "VkDescriptorSet.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040069 "VkDescriptorSetLayout.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040070 "VkDescriptorUpdateTemplate.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -040071 "VkDestroy.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040072 "VkDevice.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040073 "VkDeviceMemory.hpp",
74 "VkEvent.hpp",
75 "VkFence.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -040076 "VkFormat.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040077 "VkFramebuffer.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -040078 "VkGetProcAddress.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040079 "VkImage.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040080 "VkImageView.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040081 "VkInstance.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -040082 "VkMemory.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040083 "VkObject.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040084 "VkPhysicalDevice.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040085 "VkPipeline.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040086 "VkPipelineCache.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040087 "VkPipelineLayout.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040088 "VkQueryPool.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040089 "VkQueue.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040090 "VkRenderPass.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040091 "VkSampler.hpp",
92 "VkSemaphore.hpp",
Saman Samif4d2a442019-05-21 15:04:41 -040093 "VkShaderModule.hpp",
Ben Clayton4d23aa32020-04-14 20:33:52 +010094 "VkSpecializationInfo.hpp",
Ben Clayton597db182019-11-24 22:40:40 +000095 "VkStringify.hpp",
Antonio Maiorano42fd1592020-04-27 11:30:40 -040096 "VulkanPlatform.hpp",
Jamie Madillfe23c662019-08-30 17:38:24 -040097 ]
David 'Digit' Turner7c4d0a02019-09-03 17:00:02 +020098 if (is_linux || is_android) {
99 sources += [
David 'Digit' Turner359bc802019-08-14 17:46:07 +0200100 "VkDeviceMemoryExternalLinux.hpp",
David 'Digit' Turner7c4d0a02019-09-03 17:00:02 +0200101 "VkSemaphoreExternalLinux.hpp",
102 ]
David 'Digit' Turnerfda994c2019-09-04 16:36:36 +0200103 } else if (is_fuchsia) {
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100104 sources += [ "VkSemaphoreExternalFuchsia.hpp" ]
David 'Digit' Turner7c4d0a02019-09-03 17:00:02 +0200105 }
Jamie Madillfe23c662019-08-30 17:38:24 -0400106}
107
108swiftshader_shared_library("swiftshader_libvulkan") {
109 sources = [
110 "VkBuffer.cpp",
111 "VkBufferView.cpp",
112 "VkCommandBuffer.cpp",
113 "VkCommandPool.cpp",
Jamie Madillfe23c662019-08-30 17:38:24 -0400114 "VkDescriptorPool.cpp",
Alexis Hetu4f438a52020-06-15 16:13:51 -0400115 "VkDescriptorSet.cpp",
Jamie Madillfe23c662019-08-30 17:38:24 -0400116 "VkDescriptorSetLayout.cpp",
117 "VkDescriptorUpdateTemplate.cpp",
118 "VkDevice.cpp",
119 "VkDeviceMemory.cpp",
120 "VkFormat.cpp",
121 "VkFramebuffer.cpp",
122 "VkGetProcAddress.cpp",
123 "VkImage.cpp",
124 "VkImageView.cpp",
125 "VkInstance.cpp",
126 "VkMemory.cpp",
127 "VkPhysicalDevice.cpp",
128 "VkPipeline.cpp",
129 "VkPipelineCache.cpp",
130 "VkPipelineLayout.cpp",
131 "VkPromotedExtensions.cpp",
132 "VkQueryPool.cpp",
133 "VkQueue.cpp",
134 "VkRenderPass.cpp",
135 "VkSampler.cpp",
David 'Digit' Turner99938ea2019-09-03 15:11:17 +0200136 "VkSemaphore.cpp",
Jamie Madillfe23c662019-08-30 17:38:24 -0400137 "VkShaderModule.cpp",
Ben Clayton4d23aa32020-04-14 20:33:52 +0100138 "VkSpecializationInfo.cpp",
Ben Claytond44d6152019-11-24 22:40:40 +0000139 "VkStringify.cpp",
Jamie Madillfe23c662019-08-30 17:38:24 -0400140 "Vulkan.rc",
Saman Samif4d2a442019-05-21 15:04:41 -0400141 "libVulkan.cpp",
Saman Samif4d2a442019-05-21 15:04:41 -0400142 "main.cpp",
143 "resource.h",
Jamie Madillfe23c662019-08-30 17:38:24 -0400144 "vk_swiftshader.def",
Saman Samif4d2a442019-05-21 15:04:41 -0400145 ]
146
147 configs = [ ":swiftshader_libvulkan_private_config" ]
148
Jamie Madill9746f8b2019-09-05 13:17:09 -0400149 # TODO(capn): Use the same ICD name on both Windows and non-Windows.
150 if (is_win) {
151 output_name = "vk_swiftshader"
152 } else {
153 output_name = "libvk_swiftshader"
154 }
Saman Samif4d2a442019-05-21 15:04:41 -0400155
Alexis Hetuec63fbe2019-07-15 14:33:11 -0400156 if (is_mac) {
157 ldflags = [
158 "-Wl,-install_name,@rpath/libvk_swiftshader.dylib",
159 "-Wl,-exported_symbols_list," +
Nicolas Capensf0033322019-08-30 12:51:12 -0400160 rebase_path("vk_swiftshader.exports", root_build_dir),
Alexis Hetuec63fbe2019-07-15 14:33:11 -0400161 ]
David 'Digit' Turner58c34f52019-08-12 14:11:58 +0200162 } else if (is_linux || is_fuchsia) {
Tom Anderson42d64612019-06-12 11:05:21 -0700163 inputs = [
Nicolas Capensf0033322019-08-30 12:51:12 -0400164 "vk_swiftshader.lds",
Tom Anderson42d64612019-06-12 11:05:21 -0700165 ]
Nicolas Capense3621dc2020-02-25 22:45:42 -0500166 ldflags = [
167 # -Bsymbolic binds symbol references to their global definitions within
168 # a shared object, thereby preventing symbol preemption.
169 "-Wl,-Bsymbolic",
170 "-Wl,--version-script=" +
171 rebase_path("vk_swiftshader.lds", root_build_dir) ]
Alexis Hetuf9e9cf62019-06-05 17:18:40 -0400172 }
Saman Samif4d2a442019-05-21 15:04:41 -0400173
174 deps = [
Jamie Madillfe23c662019-08-30 17:38:24 -0400175 "${swiftshader_spirv_tools_dir}:SPIRV-Tools",
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100176 "../../third_party/marl:Marl",
Saman Samif4d2a442019-05-21 15:04:41 -0400177 "../Device",
178 "../Pipeline",
Alexis Hetuf6e439f2020-03-10 16:44:26 -0400179 "../Reactor:swiftshader_reactor",
Saman Samif4d2a442019-05-21 15:04:41 -0400180 "../System",
181 "../WSI",
Saman Samif4d2a442019-05-21 15:04:41 -0400182 ]
183
184 include_dirs = [
185 "..",
186 "../../include",
Jamie Madillbbd8c422019-08-28 17:08:17 -0400187 "$swiftshader_spirv_tools_dir/include",
188 "$spirv_tools_spirv_headers_dir/include",
Saman Samif4d2a442019-05-21 15:04:41 -0400189 ]
Jamie Madillfe23c662019-08-30 17:38:24 -0400190
191 public_deps = [
192 ":swiftshader_libvulkan_headers",
193 ]
Saman Samif4d2a442019-05-21 15:04:41 -0400194}
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100195
196# Generates an ICD JSON file that can be used by all targets in this GN build
197# (ANGLE, Dawn, Chromium).
198action("icd_file") {
Jamie Madill2613cb52019-11-27 08:34:49 -0500199 output_icd_file = "${root_out_dir}/${swiftshader_icd_file_name}"
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100200 input_file = swiftshader_icd_file_name
201
202 if (is_win) {
203 library_path = ".\\vk_swiftshader.dll"
204 } else if (is_mac) {
205 library_path = "./libvk_swiftshader.dylib"
206 } else {
207 library_path = "./libvk_swiftshader.so"
208 }
209
210 script = "write_icd_json.py"
211 args = [
212 "--input",
Jamie Madill389749a2019-11-28 10:35:58 -0500213 rebase_path(input_file, root_build_dir),
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100214 "--output",
Jamie Madill389749a2019-11-28 10:35:58 -0500215 rebase_path(output_icd_file, root_build_dir),
Corentin Walleze7ce4e52019-11-22 16:13:50 +0100216 "--library_path",
217 library_path,
218 ]
219
220 inputs = [
221 input_file,
222 ]
223 outputs = [
224 output_icd_file,
225 ]
226
227 deps = [
228 ":swiftshader_libvulkan",
229 ]
230}