Skip to content

Commit b5ed865

Browse files
committed
loader: Support latest Fuchsia build
This change merges the Fuchsia-forked Vulkan-Loader branch into the upstream. Since last update (#478), there has been significant changes to the way for Vulkan Loader to get manifests and the way for Vulkan ICDs to get I/O access to GPU devices. Also, Fuchsia has completely dropped C bindings for the FIDL API which `dlopen_fuchsia.c` uses. This change makes the following changes: * Add `loader_extensions_fuchsia.{cc,h}`. This allows the Vulkan Loader to provide a way to allow I/O to GPU devices to the ICDs it opens. The extended ICD API is defined in https://fuchsia.dev/fuchsia-src/ contribute/governance/rfcs/0205_vulkan_loader and it's implemented on ICDs like Fuchsia's Intel Mesa ICD: https://fuchsia.googlesource.com/third_party/mesa/+/main/src/intel/ vulkan/anv_magma.c * Access data and manifest files from manifest file system FD: The Fuchsia Vulkan loader service provides manifests using a service-provided virtual file system. It creates these filesystems based on the contents of multiple ICD packages and services it receives through devfs. As a result, they must be constructed using a filesystem serving library and don't reflect anything on-disk (see https://fuchsia.dev/fuchsia-src/contribute/governance/ rfcs/0205_vulkan_loader#filesystem_serving for details). The service-provided file system can be only opened as an FD using Fuchsia's FDIO (https://fuchsia.googlesource.com/fuchsia/+/main/sdk/ lib/fdio) library. Thus, in order to read manifest files located in a directory opened as an FD, we need to add a `parent_dir_fd` param to the functions that read files, including `loader_get_json` and `add_data_files`. * Migrated to the C++ FIDL bindings. The old C bindings are not supported anymore and have been deleted from the Fuchsia tree. This change migrates `dlopen_fuchsia` to use the C++ wire bindings (https://fuchsia.dev/fuchsia-src/reference/ fidl/bindings/cpp-bindings) which is part of the Fuchsia SDK. Test: libvulkan builds on Fuchsia with the changes above. Bug: https://fxbug.dev/378964821 Change-Id: I2af9f677d706d07193aecd2dcc4640ec602b138f
1 parent 24e6717 commit b5ed865

21 files changed

Lines changed: 998 additions & 151 deletions

BUILD.gn

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ config("vulkan_internal_config") {
4949
}
5050
if (is_fuchsia) {
5151
defines += [
52-
"SYSCONFDIR=\"/config\"",
52+
"SYSCONFDIR=\"/vulkan-loader-configuration\"",
5353
"EXTRASYSCONFDIR=\"/pkg/data\"",
5454
]
5555
}
@@ -73,9 +73,7 @@ config("vulkan_loader_config") {
7373
"loader/generated",
7474
"loader",
7575
]
76-
defines = [
77-
"LOADER_USE_UNSAFE_FILE_SEARCH=1",
78-
]
76+
defines = [ "LOADER_USE_UNSAFE_FILE_SEARCH=1" ]
7977

8078
if (is_win) {
8179
cflags = [ "/wd4201" ]
@@ -87,6 +85,9 @@ config("vulkan_loader_config") {
8785
"LOADER_ENABLE_LINUX_SORT",
8886
]
8987
}
88+
if (is_fuchsia || is_linux || is_chromeos) {
89+
defines += [ "HAVE_ALLOCA_H" ]
90+
}
9091
}
9192

9293
if (!is_android) {
@@ -98,18 +99,15 @@ if (!is_android) {
9899
library_type = "static_library"
99100
}
100101
support_unknown_function_handling = false
101-
if (defined(ar_path) && ar_path != "" && !is_win && (current_cpu == "arm64" || current_cpu == "x86_64")) {
102+
if (defined(ar_path) && ar_path != "" && !is_win &&
103+
(current_cpu == "arm64" || current_cpu == "x86_64")) {
102104
support_unknown_function_handling = true
103105
static_library("asm_offset") {
104106
sources = [ "loader/asm_offset.c" ]
105-
deps = [
106-
"$vulkan_headers_dir:vulkan_headers",
107-
]
107+
deps = [ "$vulkan_headers_dir:vulkan_headers" ]
108108

109109
if (is_fuchsia) {
110-
deps += [
111-
":dlopen_fuchsia",
112-
]
110+
deps += [ ":dlopen_fuchsia" ]
113111
}
114112

115113
# Output raw assembly instead of compiled object file. The assembly will be included as a member of the output ar file.
@@ -147,9 +145,7 @@ if (!is_android) {
147145
if (is_win) {
148146
action("gen_loader_rc") {
149147
script = "scripts/generate_loader_rc.py"
150-
inputs = [
151-
"loader/loader.rc",
152-
]
148+
inputs = [ "loader/loader.rc" ]
153149
args = [
154150
rebase_path("loader/loader.rc", root_build_dir),
155151
rebase_path("$target_gen_dir/loader.rc", root_build_dir),
@@ -170,33 +166,35 @@ if (!is_android) {
170166
"loader/cJSON.h",
171167
"loader/debug_utils.c",
172168
"loader/debug_utils.h",
169+
173170
# Should only be linked when assembler is used
174171
# "loader/dev_ext_trampoline.c",
175172
"loader/extension_manual.c",
176173
"loader/extension_manual.h",
177174
"loader/generated/vk_layer_dispatch_table.h",
178175
"loader/generated/vk_loader_extensions.h",
179176
"loader/generated/vk_object_types.h",
180-
"loader/gpa_helper.h",
181177
"loader/gpa_helper.c",
178+
"loader/gpa_helper.h",
179+
"loader/loader.c",
180+
"loader/loader.h",
182181
"loader/loader_common.h",
183182
"loader/loader_environment.c",
184183
"loader/loader_environment.h",
185-
"loader/loader.c",
186-
"loader/loader.h",
187184
"loader/loader_json.c",
188185
"loader/loader_json.h",
189186
"loader/log.c",
190187
"loader/log.h",
188+
191189
# Should only be linked when assembler is used
192190
# "loader/phys_dev_ext.c",
193191
"loader/settings.c",
194192
"loader/settings.h",
195193
"loader/stack_allocation.h",
196194
"loader/terminator.c",
197195
"loader/trampoline.c",
198-
"loader/unknown_function_handling.h",
199196
"loader/unknown_function_handling.c",
197+
"loader/unknown_function_handling.h",
200198
"loader/vk_loader_layer.h",
201199
"loader/vk_loader_platform.h",
202200
"loader/wsi.c",
@@ -221,11 +219,11 @@ if (!is_android) {
221219
deps = []
222220
if (is_win) {
223221
sources += [
222+
"$target_gen_dir/loader.rc",
224223
"loader/dirent_on_windows.c",
225224
"loader/dirent_on_windows.h",
226225
"loader/loader_windows.c",
227226
"loader/loader_windows.h",
228-
"$target_gen_dir/loader.rc",
229227
"loader/vulkan-1.def",
230228
]
231229
if (!is_clang) {
@@ -270,18 +268,41 @@ if (!is_android) {
270268

271269
if (is_fuchsia) {
272270
category = "partner"
271+
sdk_name = "vulkan"
272+
273+
symbols_api = "vulkan.ifs"
273274

274275
# The Vulkan loader's interface is defined by standard Khronos vulkan headers
275276
# which can be obtained separately from the loader implementation itself.
276277
no_headers = true
277278

279+
sources += [
280+
"loader/dlopen_fuchsia.cc",
281+
"loader/dlopen_fuchsia.h",
282+
"loader/loader_extensions_fuchsia.cc",
283+
"loader/loader_extensions_fuchsia.h",
284+
"loader/loader_fuchsia.h",
285+
"loader/loader_fuchsia_service.cc",
286+
"loader/loader_fuchsia_service.h",
287+
]
288+
278289
deps += [
279290
":dlopen_fuchsia",
291+
"//sdk/fidl/fuchsia.io:fuchsia.io_cpp",
292+
"//sdk/fidl/fuchsia.vulkan.loader:fuchsia.vulkan.loader_cpp",
293+
"//sdk/lib/component/incoming/cpp",
280294
"//sdk/lib/fdio",
281295
]
296+
include_dirs = [ "$target_gen_dir" ]
297+
298+
runtime_deps = [
299+
"//sdk/lib/fdio:fdio_sdk",
300+
"//zircon/system/ulib/trace-engine:trace-engine_sdk",
301+
]
282302

283-
runtime_deps = [ "//sdk/lib/fdio:fdio_sdk" ]
303+
libcxx_linkage = "static"
284304
}
305+
285306
if (support_unknown_function_handling) {
286307
if (current_cpu == "arm64") {
287308
sources += [ "loader/unknown_ext_chain_gas_aarch.S" ]
@@ -291,29 +312,17 @@ if (!is_android) {
291312
assert(false, "Unexpected CPU $current_cpu")
292313
}
293314

294-
defines += ["UNKNOWN_FUNCTIONS_SUPPORTED=1"]
315+
defines += [ "UNKNOWN_FUNCTIONS_SUPPORTED=1" ]
295316
deps += [ ":gen_defines" ]
296317
include_dirs = [ "$target_gen_dir" ]
297318
}
298319
}
299320
}
300321

301322
if (is_fuchsia) {
302-
source_set("dlopen_fuchsia") {
303-
sources = [
304-
"loader/dlopen_fuchsia.c",
305-
"loader/dlopen_fuchsia.h",
306-
]
307-
308-
deps = [
309-
"//sdk/fidl/fuchsia.vulkan.loader:fuchsia.vulkan.loader_c_client",
310-
"//sdk/lib/fdio",
311-
]
312-
}
313-
314323
sdk_documentation("vulkan_license") {
315324
name = "vulkan_license"
316-
category = "public"
325+
category = "partner"
317326

318327
files = [
319328
{

BUILD.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ Fuchsia uses the project's GN build system to integrate with the Fuchsia platfor
604604
### SDK Symbols
605605

606606
The Vulkan Loader is a component of the Fuchsia SDK, so it must explicitly declare its exported symbols in
607-
the file vulkan.symbols.api; see [SDK](https://fuchsia.dev/fuchsia-src/development/sdk).
607+
the file vulkan.ifs; see [SDK](https://fuchsia.dev/fuchsia-src/development/sdk).
608608

609609
## Building on QNX
610610

loader/README_fuchsia.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Fuchsia extensions to the loader
2+
3+
## Shared library opening
4+
5+
The loader doesn't have direct access to the filesystem containing an ICD. Instead, it must connect
6+
to the [Vulkan loader service][loader-service] at `/svc/fuchsia.vulkan.loader.Loader`. That service
7+
can provide an executable VMO for an ICD, which can be loaded using `dlopen_vmo`.
8+
9+
## Open in namespace callback
10+
11+
According to the [Fuchsia system ABI][abi], Vulkan ICDs cannot directly use the filesystem to read
12+
files or connect to services. Instead loader will call the `vk_icdInitializeOpenInNamespaceCallback`
13+
function in the ICD immediately after the ICD is dlopened. The callback may be used by the ICD to
14+
connect to services, or the driver device node or to read from files.
15+
16+
## Exporting device nodes
17+
18+
If an ICD tries to open a path under `/loader-gpu-devices` using
19+
`vk_icdInitializeOpenInNamespaceCallback`, the loader will redirect that request to a directory
20+
returned by [fuchsia.vulkan.loader/Loader.ConnectToDeviceFs][connect-device-fs]. This allows the
21+
loader service to ensure all devnodes the ICD needs are accessible to it, without the application or
22+
application runtime needing to special-case device nodes in the application's component manifest.
23+
24+
## Getting ICD manifests
25+
26+
[ICD manifests][manifests] are retrieved using [ConnectToManifestFs][connect-manifest-fs] on the
27+
loader service instead of being read directly from the filesystem. This allows ICD manifests to be
28+
packaged alongside the ICD shared library. Layer manifests are read from the filesystem like normal.
29+
30+
[loader-service]: https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/src/graphics/bin/vulkan_loader/README.md
31+
[abi]: https://fuchsia.dev/fuchsia-src/concepts/system/abi/system?hl=en
32+
[connect-device-fs]: https://fuchsia.dev/reference/fidl/fuchsia.vulkan.loader?hl=en#fuchsia.vulkan.loader/Loader.ConnectToDeviceFs
33+
[connect-manifest-fs]: https://fuchsia.dev/reference/fidl/fuchsia.vulkan.loader?hl=en#fuchsia.vulkan.loader/Loader.ConnectToManifestFs
34+
[manifests]: LoaderAndLayerInterface.md

loader/dlopen_fuchsia.c

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)