1bf215546Sopenharmony_ci# Copyright © 2019 Raspberry Pi Ltd
2bf215546Sopenharmony_ci#
3bf215546Sopenharmony_ci# Permission is hereby granted, free of charge, to any person obtaining a copy
4bf215546Sopenharmony_ci# of this software and associated documentation files (the "Software"), to deal
5bf215546Sopenharmony_ci# in the Software without restriction, including without limitation the rights
6bf215546Sopenharmony_ci# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7bf215546Sopenharmony_ci# copies of the Software, and to permit persons to whom the Software is
8bf215546Sopenharmony_ci# furnished to do so, subject to the following conditions:
9bf215546Sopenharmony_ci#
10bf215546Sopenharmony_ci# The above copyright notice and this permission notice shall be included in
11bf215546Sopenharmony_ci# all copies or substantial portions of the Software.
12bf215546Sopenharmony_ci#
13bf215546Sopenharmony_ci# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14bf215546Sopenharmony_ci# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15bf215546Sopenharmony_ci# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16bf215546Sopenharmony_ci# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17bf215546Sopenharmony_ci# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18bf215546Sopenharmony_ci# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19bf215546Sopenharmony_ci# SOFTWARE.
20bf215546Sopenharmony_ci
21bf215546Sopenharmony_civ3dv_entrypoints = custom_target(
22bf215546Sopenharmony_ci  'v3dv_entrypoints',
23bf215546Sopenharmony_ci  input : [vk_entrypoints_gen, vk_api_xml],
24bf215546Sopenharmony_ci  output : ['v3dv_entrypoints.h', 'v3dv_entrypoints.c'],
25bf215546Sopenharmony_ci  command : [
26bf215546Sopenharmony_ci    prog_python, '@INPUT0@', '--xml', '@INPUT1@', '--proto', '--weak',
27bf215546Sopenharmony_ci    '--out-h', '@OUTPUT0@', '--out-c', '@OUTPUT1@', '--prefix', 'v3dv',
28bf215546Sopenharmony_ci    '--device-prefix', 'ver42',
29bf215546Sopenharmony_ci  ],
30bf215546Sopenharmony_ci  depend_files : vk_entrypoints_gen_depend_files,
31bf215546Sopenharmony_ci)
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_cilibv3dv_files = files(
34bf215546Sopenharmony_ci  'v3dv_bo.c',
35bf215546Sopenharmony_ci  'v3dv_cl.c',
36bf215546Sopenharmony_ci  'v3dv_cmd_buffer.c',
37bf215546Sopenharmony_ci  'v3dv_debug.c',
38bf215546Sopenharmony_ci  'v3dv_debug.h',
39bf215546Sopenharmony_ci  'v3dv_descriptor_set.c',
40bf215546Sopenharmony_ci  'v3dv_device.c',
41bf215546Sopenharmony_ci  'v3dv_formats.c',
42bf215546Sopenharmony_ci  'v3dv_image.c',
43bf215546Sopenharmony_ci  'v3dv_limits.h',
44bf215546Sopenharmony_ci  'v3dv_meta_clear.c',
45bf215546Sopenharmony_ci  'v3dv_meta_copy.c',
46bf215546Sopenharmony_ci  'v3dv_pass.c',
47bf215546Sopenharmony_ci  'v3dv_pipeline.c',
48bf215546Sopenharmony_ci  'v3dv_pipeline_cache.c',
49bf215546Sopenharmony_ci  'v3dv_private.h',
50bf215546Sopenharmony_ci  'v3dv_query.c',
51bf215546Sopenharmony_ci  'v3dv_queue.c',
52bf215546Sopenharmony_ci  'v3dv_uniforms.c',
53bf215546Sopenharmony_ci  'v3dv_wsi.c',
54bf215546Sopenharmony_ci) + [v3d_xml_pack, vk_common_entrypoints[0], wsi_entrypoints[0]]
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_cifiles_per_version = files(
57bf215546Sopenharmony_ci  'v3dvx_cmd_buffer.c',
58bf215546Sopenharmony_ci  'v3dvx_descriptor_set.c',
59bf215546Sopenharmony_ci  'v3dvx_device.c',
60bf215546Sopenharmony_ci  'v3dvx_formats.c',
61bf215546Sopenharmony_ci  'v3dvx_image.c',
62bf215546Sopenharmony_ci  'v3dvx_pipeline.c',
63bf215546Sopenharmony_ci  'v3dvx_meta_common.c',
64bf215546Sopenharmony_ci  'v3dvx_pipeline.c',
65bf215546Sopenharmony_ci  'v3dvx_queue.c',
66bf215546Sopenharmony_ci)
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci# The vulkan driver only supports version >= 42, which is the version present in
69bf215546Sopenharmony_ci# Rpi4. We need to explicitly set it as we are reusing pieces from the GL v3d
70bf215546Sopenharmony_ci# driver.
71bf215546Sopenharmony_civ3d_versions = ['42']
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_civ3dv_flags = []
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_cidep_v3dv3 = dependency('v3dv3', required : false)
76bf215546Sopenharmony_ciif dep_v3dv3.found()
77bf215546Sopenharmony_ci  v3dv_flags += '-DUSE_V3D_SIMULATOR'
78bf215546Sopenharmony_ciendif
79bf215546Sopenharmony_ci
80bf215546Sopenharmony_civ3dv_deps = [
81bf215546Sopenharmony_ci  dep_dl,
82bf215546Sopenharmony_ci  dep_libdrm,
83bf215546Sopenharmony_ci  dep_valgrind,
84bf215546Sopenharmony_ci  dep_v3dv3,
85bf215546Sopenharmony_ci  idep_nir,
86bf215546Sopenharmony_ci  idep_nir_headers,
87bf215546Sopenharmony_ci  idep_vulkan_util,
88bf215546Sopenharmony_ci  idep_vulkan_runtime,
89bf215546Sopenharmony_ci  idep_vulkan_wsi,
90bf215546Sopenharmony_ci]
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ciif with_platform_x11
93bf215546Sopenharmony_ci  v3dv_deps += dep_xcb_dri3
94bf215546Sopenharmony_ciendif
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ciif with_platform_wayland
97bf215546Sopenharmony_ci  v3dv_deps += [dep_wayland_client, dep_wl_protocols]
98bf215546Sopenharmony_ci  libv3dv_files += [wayland_drm_client_protocol_h, wayland_drm_protocol_c]
99bf215546Sopenharmony_ciendif
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ciif with_platform_android
102bf215546Sopenharmony_ci  v3dv_deps += dep_android
103bf215546Sopenharmony_ci  v3dv_flags += '-DVK_USE_PLATFORM_ANDROID_KHR'
104bf215546Sopenharmony_ci  libv3dv_files += files('v3dv_android.c')
105bf215546Sopenharmony_ciendif
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ciper_version_libs = []
108bf215546Sopenharmony_ciforeach ver : v3d_versions
109bf215546Sopenharmony_ci  per_version_libs += static_library(
110bf215546Sopenharmony_ci    'v3dv-v' + ver,
111bf215546Sopenharmony_ci    [files_per_version, v3d_xml_pack, v3dv_entrypoints[0]],
112bf215546Sopenharmony_ci    include_directories : [
113bf215546Sopenharmony_ci      inc_src, inc_include, inc_gallium, inc_gallium_aux, inc_broadcom,
114bf215546Sopenharmony_ci      inc_compiler, inc_util,
115bf215546Sopenharmony_ci    ],
116bf215546Sopenharmony_ci    c_args : [v3dv_flags, '-DV3D_VERSION=' + ver],
117bf215546Sopenharmony_ci    gnu_symbol_visibility : 'hidden',
118bf215546Sopenharmony_ci    dependencies : [v3dv_deps],
119bf215546Sopenharmony_ci)
120bf215546Sopenharmony_ciendforeach
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_cilibvulkan_broadcom = shared_library(
123bf215546Sopenharmony_ci  'vulkan_broadcom',
124bf215546Sopenharmony_ci  [libv3dv_files, v3dv_entrypoints, sha1_h],
125bf215546Sopenharmony_ci  include_directories : [
126bf215546Sopenharmony_ci    inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_broadcom, inc_compiler, inc_util,
127bf215546Sopenharmony_ci  ],
128bf215546Sopenharmony_ci  link_with : [
129bf215546Sopenharmony_ci    libbroadcom_cle,
130bf215546Sopenharmony_ci    libbroadcom_v3d,
131bf215546Sopenharmony_ci    per_version_libs,
132bf215546Sopenharmony_ci  ],
133bf215546Sopenharmony_ci  dependencies : v3dv_deps,
134bf215546Sopenharmony_ci  c_args : v3dv_flags,
135bf215546Sopenharmony_ci  link_args : ['-Wl,--build-id=sha1', ld_args_bsymbolic, ld_args_gc_sections],
136bf215546Sopenharmony_ci  gnu_symbol_visibility : 'hidden',
137bf215546Sopenharmony_ci  install : true,
138bf215546Sopenharmony_ci)
139bf215546Sopenharmony_ci
140bf215546Sopenharmony_ciif with_symbols_check
141bf215546Sopenharmony_ci  test(
142bf215546Sopenharmony_ci    'v3dv symbols check',
143bf215546Sopenharmony_ci    symbols_check,
144bf215546Sopenharmony_ci    args : [
145bf215546Sopenharmony_ci      '--lib', libvulkan_broadcom,
146bf215546Sopenharmony_ci      '--symbols-file', vulkan_icd_symbols,
147bf215546Sopenharmony_ci      symbols_check_args,
148bf215546Sopenharmony_ci    ],
149bf215546Sopenharmony_ci    suite : ['broadcom'],
150bf215546Sopenharmony_ci  )
151bf215546Sopenharmony_ciendif
152bf215546Sopenharmony_ci
153bf215546Sopenharmony_cibroadcom_icd = custom_target(
154bf215546Sopenharmony_ci  'broadcom_icd',
155bf215546Sopenharmony_ci  input : [vk_icd_gen, vk_api_xml],
156bf215546Sopenharmony_ci  output : 'broadcom_icd.@0@.json'.format(host_machine.cpu()),
157bf215546Sopenharmony_ci  command : [
158bf215546Sopenharmony_ci    prog_python, '@INPUT0@',
159bf215546Sopenharmony_ci    '--api-version', '1.2', '--xml', '@INPUT1@',
160bf215546Sopenharmony_ci    '--lib-path', join_paths(get_option('prefix'), get_option('libdir'),
161bf215546Sopenharmony_ci    		  	     'libvulkan_broadcom.so'),
162bf215546Sopenharmony_ci    '--out', '@OUTPUT@',
163bf215546Sopenharmony_ci  ],
164bf215546Sopenharmony_ci  build_by_default : true,
165bf215546Sopenharmony_ci  install_dir : with_vulkan_icd_dir,
166bf215546Sopenharmony_ci  install : true,
167bf215546Sopenharmony_ci)
168bf215546Sopenharmony_ci
169bf215546Sopenharmony_ciif meson.version().version_compare('>= 0.58')
170bf215546Sopenharmony_ci  _dev_icdname = 'broadcom_devenv_icd.@0@.json'.format(host_machine.cpu())
171bf215546Sopenharmony_ci  custom_target(
172bf215546Sopenharmony_ci    'broadcom_devenv_icd',
173bf215546Sopenharmony_ci    input : [vk_icd_gen, vk_api_xml],
174bf215546Sopenharmony_ci    output : _dev_icdname,
175bf215546Sopenharmony_ci    command : [
176bf215546Sopenharmony_ci      prog_python, '@INPUT0@',
177bf215546Sopenharmony_ci      '--api-version', '1.3', '--xml', '@INPUT1@',
178bf215546Sopenharmony_ci      '--lib-path', meson.current_build_dir() / 'libvulkan_broadcom.so',
179bf215546Sopenharmony_ci      '--out', '@OUTPUT@',
180bf215546Sopenharmony_ci    ],
181bf215546Sopenharmony_ci    build_by_default : true,
182bf215546Sopenharmony_ci  )
183bf215546Sopenharmony_ci
184bf215546Sopenharmony_ci  devenv.append('VK_ICD_FILENAMES', meson.current_build_dir() / _dev_icdname)
185bf215546Sopenharmony_ciendif
186