Skip to content

Commit 90a3ab1

Browse files
Reuse library loading code in pre-instance functions
The functions vkEnumerateInstanceExtensionProperties, vkEnumerateInstanceVersion, and vkEnumerateInstanceLayerProperties have no strong reason for duplicating the the logic to load and unload libraries. This commit re-uses existing facilities to handle library loading, which has the side benefit of adding logging to the loading and unloading of layer libraries.
1 parent 9959ca3 commit 90a3ab1

File tree

2 files changed

+12
-58
lines changed

2 files changed

+12
-58
lines changed

loader/loader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ VkResult loader_get_icd_loader_instance_extensions(const struct loader_instance
172172
struct loader_extension_list *inst_exts);
173173
struct loader_icd_term *loader_get_icd_and_device(const void *device, struct loader_device **found_dev);
174174
struct loader_instance *loader_get_instance(const VkInstance instance);
175+
loader_platform_dl_handle loader_open_layer_file(const struct loader_instance *inst, struct loader_layer_properties *prop);
175176
struct loader_device *loader_create_logical_device(const struct loader_instance *inst, const VkAllocationCallbacks *pAllocator);
176177
void loader_add_logical_device(struct loader_icd_term *icd_term, struct loader_device *found_dev);
177178
void loader_remove_logical_device(struct loader_icd_term *icd_term, struct loader_device *found_dev,

loader/trampoline.c

Lines changed: 11 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionPropert
184184

185185
// Get the implicit layers
186186
struct loader_layer_list layers = {0};
187-
loader_platform_dl_handle *libs = NULL;
188-
size_t lib_count = 0;
189187
memset(&layers, 0, sizeof(layers));
190188
struct loader_envvar_all_filters layer_filters = {0};
191189

@@ -199,27 +197,19 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionPropert
199197
return res;
200198
}
201199

202-
res = loader_init_library_list(&layers, &libs);
203-
if (VK_SUCCESS != res) {
204-
return res;
205-
}
206-
207200
// Prepend layers onto the chain if they implement this entry point
208201
for (uint32_t i = 0; i < layers.count; ++i) {
209202
// Skip this layer if it doesn't expose the entry-point
210203
if (NULL == layers.list[i].pre_instance_functions.enumerate_instance_extension_properties) {
211204
continue;
212205
}
213206

214-
loader_platform_dl_handle layer_lib = loader_platform_open_library(layers.list[i].lib_name);
215-
if (layer_lib == NULL) {
216-
loader_log(NULL, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
217-
"%s: Unable to load implicit layer library \"%s\"", __FUNCTION__, layers.list[i].lib_name);
207+
loader_open_layer_file(NULL, &layers.list[i]);
208+
if (layers.list[i].lib_handle == NULL) {
218209
continue;
219210
}
220211

221-
libs[lib_count++] = layer_lib;
222-
void *pfn = loader_platform_get_proc_address(layer_lib,
212+
void *pfn = loader_platform_get_proc_address(layers.list[i].lib_handle,
223213
layers.list[i].pre_instance_functions.enumerate_instance_extension_properties);
224214
if (pfn == NULL) {
225215
loader_log(NULL, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0,
@@ -259,12 +249,6 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionPropert
259249
loader_free(NULL, holder);
260250
}
261251

262-
// Close the dl handles
263-
for (size_t i = 0; i < lib_count; ++i) {
264-
loader_platform_close_library(libs[i]);
265-
}
266-
loader_free(NULL, libs);
267-
268252
return res;
269253
}
270254

@@ -290,8 +274,6 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
290274

291275
// Get the implicit layers
292276
struct loader_layer_list layers;
293-
loader_platform_dl_handle *libs = NULL;
294-
size_t lib_count = 0;
295277
memset(&layers, 0, sizeof(layers));
296278
struct loader_envvar_all_filters layer_filters = {0};
297279

@@ -305,28 +287,20 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
305287
return res;
306288
}
307289

308-
res = loader_init_library_list(&layers, &libs);
309-
if (VK_SUCCESS != res) {
310-
return res;
311-
}
312-
313290
// Prepend layers onto the chain if they implement this entry point
314291
for (uint32_t i = 0; i < layers.count; ++i) {
315292
// Skip this layer if it doesn't expose the entry-point
316293
if (NULL == layers.list[i].pre_instance_functions.enumerate_instance_layer_properties) {
317294
continue;
318295
}
319296

320-
loader_platform_dl_handle layer_lib = loader_platform_open_library(layers.list[i].lib_name);
321-
if (layer_lib == NULL) {
322-
loader_log(NULL, VULKAN_LOADER_WARN_BIT, 0, "%s: Unable to load implicit layer library \"%s\"", __FUNCTION__,
323-
layers.list[i].lib_name);
297+
loader_open_layer_file(NULL, &layers.list[i]);
298+
if (layers.list[i].lib_handle == NULL) {
324299
continue;
325300
}
326301

327-
libs[lib_count++] = layer_lib;
328-
void *pfn =
329-
loader_platform_get_proc_address(layer_lib, layers.list[i].pre_instance_functions.enumerate_instance_layer_properties);
302+
void *pfn = loader_platform_get_proc_address(layers.list[i].lib_handle,
303+
layers.list[i].pre_instance_functions.enumerate_instance_layer_properties);
330304
if (pfn == NULL) {
331305
loader_log(NULL, VULKAN_LOADER_WARN_BIT, 0, "%s: Unable to resolve symbol \"%s\" in implicit layer library \"%s\"",
332306
__FUNCTION__, layers.list[i].pre_instance_functions.enumerate_instance_layer_properties,
@@ -365,12 +339,6 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
365339
loader_free(NULL, holder);
366340
}
367341

368-
// Close the dl handles
369-
for (size_t i = 0; i < lib_count; ++i) {
370-
loader_platform_close_library(libs[i]);
371-
}
372-
loader_free(NULL, libs);
373-
374342
return res;
375343
}
376344

@@ -403,8 +371,6 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceVersion(uint32_t
403371

404372
// Get the implicit layers
405373
struct loader_layer_list layers;
406-
loader_platform_dl_handle *libs = NULL;
407-
size_t lib_count = 0;
408374
memset(&layers, 0, sizeof(layers));
409375
struct loader_envvar_all_filters layer_filters = {0};
410376

@@ -418,27 +384,20 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceVersion(uint32_t
418384
return res;
419385
}
420386

421-
res = loader_init_library_list(&layers, &libs);
422-
if (VK_SUCCESS != res) {
423-
return res;
424-
}
425-
426387
// Prepend layers onto the chain if they implement this entry point
427388
for (uint32_t i = 0; i < layers.count; ++i) {
428389
// Skip this layer if it doesn't expose the entry-point
429390
if (NULL == layers.list[i].pre_instance_functions.enumerate_instance_version) {
430391
continue;
431392
}
432393

433-
loader_platform_dl_handle layer_lib = loader_platform_open_library(layers.list[i].lib_name);
434-
if (layer_lib == NULL) {
435-
loader_log(NULL, VULKAN_LOADER_WARN_BIT, 0, "%s: Unable to load implicit layer library \"%s\"", __FUNCTION__,
436-
layers.list[i].lib_name);
394+
loader_open_layer_file(NULL, &layers.list[i]);
395+
if (layers.list[i].lib_handle == NULL) {
437396
continue;
438397
}
439398

440-
libs[lib_count++] = layer_lib;
441-
void *pfn = loader_platform_get_proc_address(layer_lib, layers.list[i].pre_instance_functions.enumerate_instance_version);
399+
void *pfn = loader_platform_get_proc_address(layers.list[i].lib_handle,
400+
layers.list[i].pre_instance_functions.enumerate_instance_version);
442401
if (pfn == NULL) {
443402
loader_log(NULL, VULKAN_LOADER_WARN_BIT, 0, "%s: Unable to resolve symbol \"%s\" in implicit layer library \"%s\"",
444403
__FUNCTION__, layers.list[i].pre_instance_functions.enumerate_instance_version, layers.list[i].lib_name);
@@ -476,12 +435,6 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceVersion(uint32_t
476435
loader_free(NULL, holder);
477436
}
478437

479-
// Close the dl handles
480-
for (size_t i = 0; i < lib_count; ++i) {
481-
loader_platform_close_library(libs[i]);
482-
}
483-
loader_free(NULL, libs);
484-
485438
return res;
486439
}
487440

0 commit comments

Comments
 (0)