Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
247 changes: 87 additions & 160 deletions loader/loader.c

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions loader/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ VkResult loader_validate_layers(const struct loader_instance *inst, const uint32

VkResult loader_validate_instance_extensions(struct loader_instance *inst, const struct loader_extension_list *icd_exts,
const struct loader_layer_list *instance_layer,
const struct loader_envvar_all_filters *layer_filters,
const struct loader_pointer_layer_list *expanded_layers,
const VkInstanceCreateInfo *pCreateInfo);

#if defined(_WIN32)
Expand Down Expand Up @@ -154,15 +154,12 @@ VkResult loader_append_layer_property(const struct loader_instance *inst, struct
VkResult loader_add_layer_properties(const struct loader_instance *inst, struct loader_layer_list *layer_instance_list, cJSON *json,
bool is_implicit, char *filename);
bool loader_find_layer_name_in_list(const char *name, const struct loader_pointer_layer_list *layer_list);
VkResult loader_add_layer_properties_to_list(const struct loader_instance *inst, struct loader_pointer_layer_list *list,
struct loader_layer_properties *props);
VkResult loader_add_layer_properties_to_list(struct loader_instance *inst, struct loader_layer_properties *props);
void loader_free_layer_properties(const struct loader_instance *inst, struct loader_layer_properties *layer_properties);
bool loader_implicit_layer_is_enabled(const struct loader_instance *inst, const struct loader_envvar_all_filters *filters,
const struct loader_layer_properties *prop);
VkResult loader_add_meta_layer(const struct loader_instance *inst, const struct loader_envvar_all_filters *filters,
struct loader_layer_properties *prop, struct loader_pointer_layer_list *target_list,
struct loader_pointer_layer_list *expanded_target_list, const struct loader_layer_list *source_list,
bool *out_found_all_component_layers);
VkResult loader_add_meta_layer(struct loader_instance *inst, const struct loader_envvar_all_filters *filters,
struct loader_layer_properties *prop, bool *out_found_all_component_layers);
VkResult loader_add_to_ext_list(const struct loader_instance *inst, struct loader_extension_list *ext_list,
uint32_t prop_list_count, const VkExtensionProperties *props);
VkResult loader_add_device_extensions(const struct loader_instance *inst,
Expand Down Expand Up @@ -200,7 +197,6 @@ void loader_remove_logical_device(struct loader_icd_term *icd_term, struct loade
void loader_destroy_logical_device(struct loader_device *dev, const VkAllocationCallbacks *pAllocator);

VkResult loader_enable_instance_layers(struct loader_instance *inst, const VkInstanceCreateInfo *pCreateInfo,
const struct loader_layer_list *instance_layers,
const struct loader_envvar_all_filters *layer_filters);

VkResult loader_create_instance_chain(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
Expand Down
11 changes: 4 additions & 7 deletions loader/loader_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ struct loader_layer_list {
};

// Stores a list of pointers to loader_layer_properties
// Used for app_activated_layer_list and expanded_activated_layer_list
// Used for expanded_activated_layer_list
struct loader_pointer_layer_list {
size_t capacity;
uint32_t count;
Expand Down Expand Up @@ -375,12 +375,9 @@ struct loader_instance {
struct loader_layer_list instance_layer_list;
bool override_layer_present;

// List of activated layers.
// app_ is the version based on exactly what the application asked for.
// This is what must be returned to the application on Enumerate calls.
// expanded_ is the version based on expanding meta-layers into their
// individual component layers. This is what is used internally.
struct loader_pointer_layer_list app_activated_layer_list;
// List of activated layers, including the layers enabled from expanding meta-layers into their individual component
// layers. This active list of layers can include layers that failed to actually be enabled, such as not being able to load the
// binary, failing version negotiation, and not being able to query vkGetInstanceProcAddr
struct loader_pointer_layer_list expanded_activated_layer_list;

VkInstance instance; // layers/ICD instance returned to trampoline
Expand Down
31 changes: 12 additions & 19 deletions loader/loader_environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,7 @@ bool check_name_matches_filter_environment_var(const char *name, const struct lo
// Get the layer name(s) from the env_name environment variable. If layer is found in
// search_list then add it to layer_list. But only add it to layer_list if type_flags matches.
VkResult loader_add_environment_layers(struct loader_instance *inst, const char *enabled_layers_env,
const struct loader_envvar_all_filters *filters,
struct loader_pointer_layer_list *target_list,
struct loader_pointer_layer_list *expanded_target_list,
const struct loader_layer_list *source_list) {
const struct loader_envvar_all_filters *filters) {
VkResult res = VK_SUCCESS;
const enum layer_type_flags type_flags = VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER;

Expand All @@ -478,22 +475,20 @@ VkResult loader_add_environment_layers(struct loader_instance *inst, const char

if (strlen(name) > 0) {
bool found = false;
for (uint32_t i = 0; i < source_list->count; i++) {
struct loader_layer_properties *source_prop = &source_list->list[i];
for (uint32_t i = 0; i < inst->instance_layer_list.count; i++) {
struct loader_layer_properties *source_prop = &inst->instance_layer_list.list[i];

if (0 == strcmp(name, source_prop->info.layerName)) {
found = true;
// Only add it if it doesn't already appear in the layer list
if (!loader_find_layer_name_in_list(source_prop->info.layerName, target_list)) {
if (!loader_find_layer_name_in_list(source_prop->info.layerName,
&inst->expanded_activated_layer_list)) {
if (0 == (source_prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER)) {
source_prop->enabled_by_what = ENABLED_BY_WHAT_VK_INSTANCE_LAYERS;
res = loader_add_layer_properties_to_list(inst, target_list, source_prop);
if (res == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
res = loader_add_layer_properties_to_list(inst, expanded_target_list, source_prop);
res = loader_add_layer_properties_to_list(inst, source_prop);
if (res == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
} else {
res = loader_add_meta_layer(inst, filters, source_prop, target_list, expanded_target_list,
source_list, NULL);
res = loader_add_meta_layer(inst, filters, source_prop, NULL);
if (res == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
}
break;
Expand All @@ -511,8 +506,8 @@ VkResult loader_add_environment_layers(struct loader_instance *inst, const char
}

// Loop through all the layers and check the enable/disable filters
for (uint32_t i = 0; i < source_list->count; i++) {
struct loader_layer_properties *source_prop = &source_list->list[i];
for (uint32_t i = 0; i < inst->instance_layer_list.count; i++) {
struct loader_layer_properties *source_prop = &inst->instance_layer_list.list[i];

// If it doesn't match the type, or the name isn't what we're looking for, just continue
if ((source_prop->type_flags & type_flags) != type_flags) {
Expand All @@ -523,7 +518,7 @@ VkResult loader_add_environment_layers(struct loader_instance *inst, const char
// VK_INSTANCE_LAYERS, which VK_LOADER_LAYERS_ENABLE is a generalization of, and which overrides disables.
// Also make sure the layer isn't already in the output_list, skip adding it if it is.
bool force_enabled = check_name_matches_filter_environment_var(source_prop->info.layerName, &filters->enable_filter) &&
!loader_find_layer_name_in_list(source_prop->info.layerName, target_list);
!loader_find_layer_name_in_list(source_prop->info.layerName, &inst->expanded_activated_layer_list);

bool is_implicit = (0 == (source_prop->type_flags & VK_LAYER_TYPE_FLAG_EXPLICIT_LAYER));
bool disabled_by_type =
Expand All @@ -549,12 +544,10 @@ VkResult loader_add_environment_layers(struct loader_instance *inst, const char
// If not a meta-layer, simply add it.
if (0 == (source_prop->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER)) {
source_prop->enabled_by_what = ENABLED_BY_WHAT_VK_LOADER_LAYERS_ENABLE;
res = loader_add_layer_properties_to_list(inst, target_list, source_prop);
if (res == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
res = loader_add_layer_properties_to_list(inst, expanded_target_list, source_prop);
res = loader_add_layer_properties_to_list(inst, source_prop);
if (res == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
} else {
res = loader_add_meta_layer(inst, filters, source_prop, target_list, expanded_target_list, source_list, NULL);
res = loader_add_meta_layer(inst, filters, source_prop, NULL);
if (res == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
}
}
Expand Down
5 changes: 1 addition & 4 deletions loader/loader_environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ VkResult parse_layers_disable_filter_environment_var(const struct loader_instanc
VkResult parse_layer_environment_var_filters(const struct loader_instance *inst, struct loader_envvar_all_filters *layer_filters);
bool check_name_matches_filter_environment_var(const char *name, const struct loader_envvar_filter *filter_struct);
VkResult loader_add_environment_layers(struct loader_instance *inst, const char *enabled_layers_env,
const struct loader_envvar_all_filters *filters,
struct loader_pointer_layer_list *target_list,
struct loader_pointer_layer_list *expanded_target_list,
const struct loader_layer_list *source_list);
const struct loader_envvar_all_filters *filters);

void parse_id_filter_environment_var(const struct loader_instance *inst, const char *env_var_name,
struct loader_envvar_id_filter *filter_struct);
Expand Down
19 changes: 6 additions & 13 deletions loader/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -1163,11 +1163,8 @@ VkResult combine_settings_layers_with_regular_layers(const struct loader_instanc
return res;
}

VkResult enable_correct_layers_from_settings(const struct loader_instance* inst, const struct loader_envvar_all_filters* filters,
uint32_t app_enabled_name_count, const char* const* app_enabled_names,
const struct loader_layer_list* instance_layers,
struct loader_pointer_layer_list* target_layer_list,
struct loader_pointer_layer_list* activated_layer_list) {
VkResult enable_correct_layers_from_settings(struct loader_instance* inst, const struct loader_envvar_all_filters* filters,
uint32_t app_enabled_name_count, const char* const* app_enabled_names) {
VkResult res = VK_SUCCESS;
char* vk_instance_layers_env = loader_getenv(ENABLED_LAYERS_ENV, inst);
size_t vk_instance_layers_env_len = 0;
Expand All @@ -1180,9 +1177,9 @@ VkResult enable_correct_layers_from_settings(const struct loader_instance* inst,
loader_log(inst, VULKAN_LOADER_WARN_BIT | VULKAN_LOADER_LAYER_BIT, 0, "env var \'%s\' defined and adding layers: %s",
ENABLED_LAYERS_ENV, vk_instance_layers_env);
}
for (uint32_t i = 0; i < instance_layers->count; i++) {
for (uint32_t i = 0; i < inst->instance_layer_list.count; i++) {
bool enable_layer = false;
struct loader_layer_properties* props = &instance_layers->list[i];
struct loader_layer_properties* props = &inst->instance_layer_list.list[i];

// Skip the sentinel unordered layer location
if (props->settings_control_value == LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION) {
Expand Down Expand Up @@ -1259,14 +1256,10 @@ VkResult enable_correct_layers_from_settings(const struct loader_instance* inst,
if (enable_layer) {
// Check if the layer is a meta layer reuse the existing function to add the meta layer
if (props->type_flags & VK_LAYER_TYPE_FLAG_META_LAYER) {
res = loader_add_meta_layer(inst, filters, props, target_layer_list, activated_layer_list, instance_layers, NULL);
res = loader_add_meta_layer(inst, filters, props, NULL);
if (res == VK_ERROR_OUT_OF_HOST_MEMORY) goto out;
} else {
res = loader_add_layer_properties_to_list(inst, target_layer_list, props);
if (res != VK_SUCCESS) {
goto out;
}
res = loader_add_layer_properties_to_list(inst, activated_layer_list, props);
res = loader_add_layer_properties_to_list(inst, props);
if (res != VK_SUCCESS) {
goto out;
}
Expand Down
7 changes: 2 additions & 5 deletions loader/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,8 @@ VkResult combine_settings_layers_with_regular_layers(const struct loader_instanc

// Fill out activated_layer_list with the layers that should be activated, based on environment variables, VkInstanceCreateInfo, and
// the settings
VkResult enable_correct_layers_from_settings(const struct loader_instance* inst, const struct loader_envvar_all_filters* filters,
uint32_t app_enabled_name_count, const char* const* app_enabled_names,
const struct loader_layer_list* instance_layers,
struct loader_pointer_layer_list* target_layer_list,
struct loader_pointer_layer_list* activated_layer_list);
VkResult enable_correct_layers_from_settings(struct loader_instance* inst, const struct loader_envvar_all_filters* filters,
uint32_t app_enabled_name_count, const char* const* app_enabled_names);

// Add any drivers that the loader settings file contains to the out_files list. If the additional_drivers_use_exclusively field is
// true, clear the out_files list before adding any additional drivers
Expand Down
30 changes: 15 additions & 15 deletions loader/trampoline.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,6 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCr
if (res != VK_SUCCESS) {
goto out;
}
res = loader_validate_instance_extensions(ptr_instance, &ptr_instance->ext_list, &ptr_instance->instance_layer_list,
&layer_filters, &ici);
if (res != VK_SUCCESS) {
goto out;
}

ptr_instance->disp = loader_instance_heap_alloc(ptr_instance, sizeof(struct loader_instance_dispatch_table),
VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
Expand All @@ -719,7 +714,13 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCr
loader.instances = ptr_instance;

// Activate any layers on instance chain
res = loader_enable_instance_layers(ptr_instance, &ici, &ptr_instance->instance_layer_list, &layer_filters);
res = loader_enable_instance_layers(ptr_instance, &ici, &layer_filters);
if (res != VK_SUCCESS) {
goto out;
}

res = loader_validate_instance_extensions(ptr_instance, &ptr_instance->ext_list, &ptr_instance->instance_layer_list,
&ptr_instance->expanded_activated_layer_list, &ici);
if (res != VK_SUCCESS) {
goto out;
}
Expand Down Expand Up @@ -770,7 +771,6 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCr
destroy_debug_callbacks_chain(ptr_instance, pAllocator);

loader_destroy_pointer_layer_list(ptr_instance, &ptr_instance->expanded_activated_layer_list);
loader_destroy_pointer_layer_list(ptr_instance, &ptr_instance->app_activated_layer_list);

loader_delete_layer_list_and_properties(ptr_instance, &ptr_instance->instance_layer_list);
loader_destroy_generic_list(ptr_instance, (struct loader_generic_list *)&ptr_instance->ext_list);
Expand Down Expand Up @@ -844,7 +844,6 @@ LOADER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance,
loader_destroy_generic_list(ptr_instance, (struct loader_generic_list *)&ptr_instance->debug_report_callbacks_list);

loader_destroy_pointer_layer_list(ptr_instance, &ptr_instance->expanded_activated_layer_list);
loader_destroy_pointer_layer_list(ptr_instance, &ptr_instance->app_activated_layer_list);

loader_delete_layer_list_and_properties(ptr_instance, &ptr_instance->instance_layer_list);

Expand Down Expand Up @@ -1113,9 +1112,9 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(Vk

// Only count layers that successfully loaded, or had nothing to load (like meta layers)
uint32_t count = 0;
for (uint32_t i = 0; i < inst->app_activated_layer_list.count; i++) {
if (inst->app_activated_layer_list.list[i]->lib_status == LOADER_LAYER_LIB_NOT_LOADED ||
inst->app_activated_layer_list.list[i]->lib_status == LOADER_LAYER_LIB_SUCCESS_LOADED) {
for (uint32_t i = 0; i < inst->expanded_activated_layer_list.count; i++) {
if (inst->expanded_activated_layer_list.list[i]->lib_status == LOADER_LAYER_LIB_NOT_LOADED ||
inst->expanded_activated_layer_list.list[i]->lib_status == LOADER_LAYER_LIB_SUCCESS_LOADED) {
count++;
}
}
Expand All @@ -1128,10 +1127,11 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(Vk

copy_size = (*pPropertyCount < count) ? *pPropertyCount : count;
uint32_t propertiesIter = 0;
for (uint32_t i = 0; i < inst->app_activated_layer_list.count; i++) {
if (propertiesIter < copy_size && (inst->app_activated_layer_list.list[i]->lib_status == LOADER_LAYER_LIB_NOT_LOADED ||
inst->app_activated_layer_list.list[i]->lib_status == LOADER_LAYER_LIB_SUCCESS_LOADED)) {
memcpy(&pProperties[propertiesIter], &(inst->app_activated_layer_list.list[i]->info), sizeof(VkLayerProperties));
for (uint32_t i = 0; i < inst->expanded_activated_layer_list.count; i++) {
if (propertiesIter < copy_size &&
(inst->expanded_activated_layer_list.list[i]->lib_status == LOADER_LAYER_LIB_NOT_LOADED ||
inst->expanded_activated_layer_list.list[i]->lib_status == LOADER_LAYER_LIB_SUCCESS_LOADED)) {
memcpy(&pProperties[propertiesIter], &(inst->expanded_activated_layer_list.list[i]->info), sizeof(VkLayerProperties));
propertiesIter++;
}
}
Expand Down
Loading