1/*
2 *
3 * Copyright (c) 2014-2022 The Khronos Group Inc.
4 * Copyright (c) 2014-2022 Valve Corporation
5 * Copyright (c) 2014-2022 LunarG, Inc.
6 * Copyright (C) 2015 Google Inc.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 *     http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 * Author: Jon Ashburn <jon@lunarg.com>
21 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
22 * Author: Chia-I Wu <olvaffe@gmail.com>
23 * Author: Chia-I Wu <olv@lunarg.com>
24 * Author: Mark Lobodzinski <mark@LunarG.com>
25 * Author: Lenny Komow <lenny@lunarg.com>
26 * Author: Charles Giessen <charles@lunarg.com>
27 *
28 */
29
30#pragma once
31
32#if defined(_WIN32)
33
34#include "loader_common.h"
35
36#include <minwindef.h>
37#include <cfgmgr32.h>
38#include <sdkddkver.h>
39
40// Windows specific initialization functionality
41void windows_initialization(void);
42
43// Append the JSON path data to the list and allocate/grow the list if it's not large enough.
44// Function returns true if filename was appended to reg_data list.
45// Caller should free reg_data.
46bool windows_add_json_entry(const struct loader_instance *inst,
47                            char **reg_data,    // list of JSON files
48                            PDWORD total_size,  // size of reg_data
49                            LPCSTR key_name,    // key name - used for debug prints - i.e. VulkanDriverName
50                            DWORD key_type,     // key data type
51                            LPSTR json_path,    // JSON string to add to the list reg_data
52                            DWORD json_size,    // size in bytes of json_path
53                            VkResult *result);
54
55// Find the list of registry files (names VulkanDriverName/VulkanDriverNameWow) in hkr.
56//
57// This function looks for filename in given device handle, filename is then added to return list
58// function return true if filename was appended to reg_data list
59// If error occurs result is updated with failure reason
60bool windows_get_device_registry_entry(const struct loader_instance *inst, char **reg_data, PDWORD total_size, DEVINST dev_id,
61                                       LPCSTR value_name, VkResult *result);
62
63// Find the list of registry files (names VulkanDriverName/VulkanDriverNameWow) in hkr .
64//
65// This function looks for display devices and childish software components
66// for a list of files which are added to a returned list (function return
67// value).
68// Function return is a string with a ';'  separated list of filenames.
69// Function return is NULL if no valid name/value pairs  are found in the key,
70// or the key is not found.
71//
72// *reg_data contains a string list of filenames as pointer.
73// When done using the returned string list, the caller should free the pointer.
74VkResult windows_get_device_registry_files(const struct loader_instance *inst, uint32_t log_target_flag, char **reg_data,
75                                           PDWORD reg_data_size, LPCSTR value_name);
76
77// Find the list of registry files (names within a key) in key "location".
78//
79// This function looks in the registry (hive = DEFAULT_VK_REGISTRY_HIVE) key as
80// given in "location"
81// for a list or name/values which are added to a returned list (function return
82// value).
83// The DWORD values within the key must be 0 or they are skipped.
84// Function return is a string with a ';'  separated list of filenames.
85// Function return is NULL if no valid name/value pairs  are found in the key,
86// or the key is not found.
87//
88// *reg_data contains a string list of filenames as pointer.
89// When done using the returned string list, the caller should free the pointer.
90VkResult windows_get_registry_files(const struct loader_instance *inst, char *location, bool use_secondary_hive, char **reg_data,
91                                    PDWORD reg_data_size);
92
93// Read manifest JSON files using the Windows driver interface
94VkResult windows_read_manifest_from_d3d_adapters(const struct loader_instance *inst, char **reg_data, PDWORD reg_data_size,
95                                                 const wchar_t *value_name);
96
97// Look for data files in the registry.
98VkResult windows_read_data_files_in_registry(const struct loader_instance *inst, enum loader_data_files_type data_file_type,
99                                             bool warn_if_not_present, char *registry_location,
100                                             struct loader_string_list *out_files);
101
102// This function allocates an array in sorted_devices which must be freed by the caller if not null
103VkResult windows_read_sorted_physical_devices(struct loader_instance *inst, uint32_t *icd_phys_devs_array_count,
104                                              struct loader_icd_physical_devices **icd_phys_devs_array);
105
106// This function sorts an array in physical device groups based on the sorted physical device information
107VkResult windows_sort_physical_device_groups(struct loader_instance *inst, const uint32_t group_count,
108                                             struct loader_physical_device_group_term *sorted_group_term,
109                                             const uint32_t sorted_device_count,
110                                             struct loader_icd_physical_devices *sorted_phys_dev_array);
111
112// Creates a DXGI factory
113// Returns VkLoaderFeatureFlags containing VK_LOADER_FEATURE_PHYSICAL_DEVICE_SORTING if successful, otherwise 0
114VkLoaderFeatureFlags windows_initialize_dxgi(void);
115
116// Retrieve a path to an installed app package that contains Vulkan manifests.
117// When done using the returned string, the caller should free the pointer.
118char *windows_get_app_package_manifest_path(const struct loader_instance *inst);
119
120// Gets the path to the loader settings file, if it exists. If it doesn't exists, writes NULL to out_path.
121// The path is located through the registry as an entry in HKEY_CURRENT_USER/SOFTWARE/Khronos/Vulkan/LoaderSettings
122// and if nothing is there, will try to look in HKEY_LOCAL_MACHINE/SOFTWARE/Khronos/Vulkan/LoaderSettings.
123// If running with elevated privileges, this function only looks in HKEY_LOCAL_MACHINE.
124VkResult windows_get_loader_settings_file_path(const struct loader_instance *inst, char **out_path);
125#endif  // WIN32
126