15db71995Sopenharmony_ci/* 25db71995Sopenharmony_ci * 35db71995Sopenharmony_ci * Copyright (c) 2023 The Khronos Group Inc. 45db71995Sopenharmony_ci * Copyright (c) 2023 Valve Corporation 55db71995Sopenharmony_ci * Copyright (c) 2023 LunarG, Inc. 65db71995Sopenharmony_ci * 75db71995Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 85db71995Sopenharmony_ci * you may not use this file except in compliance with the License. 95db71995Sopenharmony_ci * You may obtain a copy of the License at 105db71995Sopenharmony_ci * 115db71995Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 125db71995Sopenharmony_ci * 135db71995Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 145db71995Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 155db71995Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 165db71995Sopenharmony_ci * See the License for the specific language governing permissions and 175db71995Sopenharmony_ci * limitations under the License. 185db71995Sopenharmony_ci * 195db71995Sopenharmony_ci * 205db71995Sopenharmony_ci * Author: Charles Giessen <charles@lunarg.com> 215db71995Sopenharmony_ci * 225db71995Sopenharmony_ci */ 235db71995Sopenharmony_ci 245db71995Sopenharmony_ci#pragma once 255db71995Sopenharmony_ci 265db71995Sopenharmony_ci#include <stdio.h> 275db71995Sopenharmony_ci#include <stddef.h> 285db71995Sopenharmony_ci#include <stdbool.h> 295db71995Sopenharmony_ci#include <stdint.h> 305db71995Sopenharmony_ci 315db71995Sopenharmony_ci#include "vulkan/vulkan_core.h" 325db71995Sopenharmony_ci 335db71995Sopenharmony_ci#include "log.h" 345db71995Sopenharmony_ci 355db71995Sopenharmony_cistruct loader_instance; 365db71995Sopenharmony_cistruct loader_layer_list; 375db71995Sopenharmony_cistruct loader_pointer_layer_list; 385db71995Sopenharmony_cistruct loader_envvar_all_filters; 395db71995Sopenharmony_citypedef struct log_configuration log_configuration; 405db71995Sopenharmony_ci 415db71995Sopenharmony_citypedef enum loader_settings_layer_control { 425db71995Sopenharmony_ci LOADER_SETTINGS_LAYER_CONTROL_DEFAULT, // layer is not enabled by settings file but can be enabled through other means 435db71995Sopenharmony_ci LOADER_SETTINGS_LAYER_CONTROL_ON, // layer is enabled by settings file 445db71995Sopenharmony_ci LOADER_SETTINGS_LAYER_CONTROL_OFF, // layer is prevented from being enabled 455db71995Sopenharmony_ci LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION // special control indicating unspecified layers should go here. If this is not 465db71995Sopenharmony_ci // in the settings file, then the loader assume no other layers should be 475db71995Sopenharmony_ci // searched & loaded. 485db71995Sopenharmony_ci} loader_settings_layer_control; 495db71995Sopenharmony_ci 505db71995Sopenharmony_ci// If a loader_settings_layer_configuration has a name of loader_settings_unknown_layers_location, then it specifies that the 515db71995Sopenharmony_ci// layer configuration it was found in shall be the location all layers not listed in the settings file that are enabled. 525db71995Sopenharmony_ci#define LOADER_SETTINGS_UNKNOWN_LAYERS_LOCATION "loader_settings_unknown_layers_location" 535db71995Sopenharmony_ci 545db71995Sopenharmony_ci#define LOADER_SETTINGS_MAX_NAME_SIZE 256U; 555db71995Sopenharmony_ci 565db71995Sopenharmony_citypedef struct loader_settings_layer_configuration { 575db71995Sopenharmony_ci char* name; 585db71995Sopenharmony_ci char* path; 595db71995Sopenharmony_ci loader_settings_layer_control control; 605db71995Sopenharmony_ci bool treat_as_implicit_manifest; // whether or not the layer should be parsed as if it is implicit 615db71995Sopenharmony_ci 625db71995Sopenharmony_ci} loader_settings_layer_configuration; 635db71995Sopenharmony_ci 645db71995Sopenharmony_citypedef struct loader_settings { 655db71995Sopenharmony_ci bool settings_active; 665db71995Sopenharmony_ci bool has_unordered_layer_location; 675db71995Sopenharmony_ci enum vulkan_loader_debug_flags debug_level; 685db71995Sopenharmony_ci 695db71995Sopenharmony_ci uint32_t layer_configuration_count; 705db71995Sopenharmony_ci loader_settings_layer_configuration* layer_configurations; 715db71995Sopenharmony_ci 725db71995Sopenharmony_ci char* settings_file_path; 735db71995Sopenharmony_ci} loader_settings; 745db71995Sopenharmony_ci 755db71995Sopenharmony_ci// Call this function to get the current settings that the loader should use. 765db71995Sopenharmony_ci// It will open up the current loader settings file and return a loader_settings in out_loader_settings if it. 775db71995Sopenharmony_ci// It should be called on every call to the global functions excluding vkGetInstanceProcAddr 785db71995Sopenharmony_ci// Caller is responsible for cleaning up by calling free_loader_settings() 795db71995Sopenharmony_ciVkResult get_loader_settings(const struct loader_instance* inst, loader_settings* out_loader_settings); 805db71995Sopenharmony_ci 815db71995Sopenharmony_civoid free_loader_settings(const struct loader_instance* inst, loader_settings* loader_settings); 825db71995Sopenharmony_ci 835db71995Sopenharmony_ci// Log the settings to the console 845db71995Sopenharmony_civoid log_settings(const struct loader_instance* inst, loader_settings* settings); 855db71995Sopenharmony_ci 865db71995Sopenharmony_ci// Every global function needs to call this at startup to insure that 875db71995Sopenharmony_ciVkResult update_global_loader_settings(void); 885db71995Sopenharmony_ci 895db71995Sopenharmony_ci// Needs to be called during startup - 905db71995Sopenharmony_civoid init_global_loader_settings(void); 915db71995Sopenharmony_civoid teardown_global_loader_settings(void); 925db71995Sopenharmony_ci 935db71995Sopenharmony_ci// Check the global settings and return true if msg_type does not correspond to the active global loader settings 945db71995Sopenharmony_cibool should_skip_logging_global_messages(VkFlags msg_type); 955db71995Sopenharmony_ci 965db71995Sopenharmony_ci// Query the current settings (either global or per-instance) and return the list of layers contained within. 975db71995Sopenharmony_ci// should_search_for_other_layers tells the caller if the settings file should be used exclusively for layer searching or not 985db71995Sopenharmony_ciVkResult get_settings_layers(const struct loader_instance* inst, struct loader_layer_list* settings_layers, 995db71995Sopenharmony_ci bool* should_search_for_other_layers); 1005db71995Sopenharmony_ci 1015db71995Sopenharmony_ci// Take the provided list of settings_layers and add in the layers from regular search paths 1025db71995Sopenharmony_ci// Only adds layers that aren't already present in the settings_layers and in the location of the 1035db71995Sopenharmony_ci// layer configuration with LOADER_SETTINGS_LAYER_UNORDERED_LAYER_LOCATION set 1045db71995Sopenharmony_ciVkResult combine_settings_layers_with_regular_layers(const struct loader_instance* inst, struct loader_layer_list* settings_layers, 1055db71995Sopenharmony_ci struct loader_layer_list* regular_layers, 1065db71995Sopenharmony_ci struct loader_layer_list* output_layers); 1075db71995Sopenharmony_ci 1085db71995Sopenharmony_ci// Fill out activated_layer_list with the layers that should be activated, based on environment variables, VkInstanceCreateInfo, and 1095db71995Sopenharmony_ci// the settings 1105db71995Sopenharmony_ciVkResult enable_correct_layers_from_settings(const struct loader_instance* inst, const struct loader_envvar_all_filters* filters, 1115db71995Sopenharmony_ci uint32_t app_enabled_name_count, const char* const* app_enabled_names, 1125db71995Sopenharmony_ci const struct loader_layer_list* instance_layers, 1135db71995Sopenharmony_ci struct loader_pointer_layer_list* target_layer_list, 1145db71995Sopenharmony_ci struct loader_pointer_layer_list* activated_layer_list); 115