Coverage Report

Created: 2023-06-07 06:30

/src/vulkan-loader/loader/terminator.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 *
3
 * Copyright (c) 2014-2021 The Khronos Group Inc.
4
 * Copyright (c) 2014-2021 Valve Corporation
5
 * Copyright (c) 2014-2021 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
 *
21
 * Author: Jon Ashburn <jon@lunarg.com>
22
 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
23
 * Author: Mark Young <marky@lunarg.com>
24
 * Author: Lenny Komow <lenny@lunarg.com>
25
 * Author: Charles Giessen <charles@lunarg.com>
26
 *
27
 */
28
29
// Terminators which have simple logic belong here, since they are mostly "pass through"
30
// Function declarations are in vk_loader_extensions.h, thus not needed here
31
32
#include "allocation.h"
33
#include "loader_common.h"
34
#include "loader.h"
35
#include "log.h"
36
37
// Terminators for 1.0 functions
38
39
VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
40
0
                                                                  VkPhysicalDeviceProperties *pProperties) {
41
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
42
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
43
0
    if (NULL != icd_term->dispatch.GetPhysicalDeviceProperties) {
44
0
        icd_term->dispatch.GetPhysicalDeviceProperties(phys_dev_term->phys_dev, pProperties);
45
0
    }
46
0
}
47
48
VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
49
                                                                             uint32_t *pQueueFamilyPropertyCount,
50
0
                                                                             VkQueueFamilyProperties *pProperties) {
51
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
52
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
53
0
    if (NULL != icd_term->dispatch.GetPhysicalDeviceQueueFamilyProperties) {
54
0
        icd_term->dispatch.GetPhysicalDeviceQueueFamilyProperties(phys_dev_term->phys_dev, pQueueFamilyPropertyCount, pProperties);
55
0
    }
56
0
}
57
58
VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice,
59
0
                                                                        VkPhysicalDeviceMemoryProperties *pProperties) {
60
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
61
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
62
0
    if (NULL != icd_term->dispatch.GetPhysicalDeviceMemoryProperties) {
63
0
        icd_term->dispatch.GetPhysicalDeviceMemoryProperties(phys_dev_term->phys_dev, pProperties);
64
0
    }
65
0
}
66
67
VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,
68
0
                                                                VkPhysicalDeviceFeatures *pFeatures) {
69
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
70
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
71
0
    if (NULL != icd_term->dispatch.GetPhysicalDeviceFeatures) {
72
0
        icd_term->dispatch.GetPhysicalDeviceFeatures(phys_dev_term->phys_dev, pFeatures);
73
0
    }
74
0
}
75
76
VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format,
77
0
                                                                        VkFormatProperties *pFormatInfo) {
78
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
79
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
80
0
    if (NULL != icd_term->dispatch.GetPhysicalDeviceFormatProperties) {
81
0
        icd_term->dispatch.GetPhysicalDeviceFormatProperties(phys_dev_term->phys_dev, format, pFormatInfo);
82
0
    }
83
0
}
84
85
VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format,
86
                                                                                 VkImageType type, VkImageTiling tiling,
87
                                                                                 VkImageUsageFlags usage, VkImageCreateFlags flags,
88
0
                                                                                 VkImageFormatProperties *pImageFormatProperties) {
89
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
90
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
91
0
    if (NULL == icd_term->dispatch.GetPhysicalDeviceImageFormatProperties) {
92
0
        loader_log(
93
0
            icd_term->this_instance, VULKAN_LOADER_ERROR_BIT, 0,
94
0
            "The icd's vkGetPhysicalDeviceImageFormatProperties was null, returning with VK_ERROR_INITIALIZATION_FAILED instead.");
95
0
        return VK_ERROR_INITIALIZATION_FAILED;
96
0
    }
97
0
    return icd_term->dispatch.GetPhysicalDeviceImageFormatProperties(phys_dev_term->phys_dev, format, type, tiling, usage, flags,
98
0
                                                                     pImageFormatProperties);
99
0
}
100
101
VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format,
102
                                                                                   VkImageType type, VkSampleCountFlagBits samples,
103
                                                                                   VkImageUsageFlags usage, VkImageTiling tiling,
104
                                                                                   uint32_t *pNumProperties,
105
0
                                                                                   VkSparseImageFormatProperties *pProperties) {
106
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
107
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
108
0
    if (NULL != icd_term->dispatch.GetPhysicalDeviceSparseImageFormatProperties) {
109
0
        icd_term->dispatch.GetPhysicalDeviceSparseImageFormatProperties(phys_dev_term->phys_dev, format, type, samples, usage,
110
0
                                                                        tiling, pNumProperties, pProperties);
111
0
    }
112
0
}
113
114
VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
115
0
                                                                         VkLayerProperties *pProperties) {
116
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
117
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
118
0
    loader_log(icd_term->this_instance, VULKAN_LOADER_ERROR_BIT, 0,
119
0
               "Encountered the vkEnumerateDeviceLayerProperties terminator.  This means a layer improperly continued.");
120
    // Should never get here this call isn't dispatched down the chain
121
0
    return VK_ERROR_INITIALIZATION_FAILED;
122
0
}
123
124
// Terminators for 1.1 functions
125
126
VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice,
127
0
                                                                 VkPhysicalDeviceFeatures2 *pFeatures) {
128
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
129
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
130
0
    const struct loader_instance *inst = icd_term->this_instance;
131
132
0
    assert(inst != NULL);
133
134
    // Get the function pointer to use to call into the ICD. This could be the core or KHR version
135
0
    PFN_vkGetPhysicalDeviceFeatures2 fpGetPhysicalDeviceFeatures2 = NULL;
136
0
    if (loader_check_version_meets_required(LOADER_VERSION_1_1_0, inst->app_api_version)) {
137
0
        fpGetPhysicalDeviceFeatures2 = icd_term->dispatch.GetPhysicalDeviceFeatures2;
138
0
    }
139
0
    if (fpGetPhysicalDeviceFeatures2 == NULL && inst->enabled_known_extensions.khr_get_physical_device_properties2) {
140
0
        fpGetPhysicalDeviceFeatures2 = icd_term->dispatch.GetPhysicalDeviceFeatures2KHR;
141
0
    }
142
143
0
    if (fpGetPhysicalDeviceFeatures2 != NULL) {
144
        // Pass the call to the driver
145
0
        fpGetPhysicalDeviceFeatures2(phys_dev_term->phys_dev, pFeatures);
146
0
    } else {
147
        // Emulate the call
148
0
        loader_log(icd_term->this_instance, VULKAN_LOADER_INFO_BIT, 0,
149
0
                   "vkGetPhysicalDeviceFeatures2: Emulating call in ICD \"%s\" using vkGetPhysicalDeviceFeatures",
150
0
                   icd_term->scanned_icd->lib_name);
151
152
        // Write to the VkPhysicalDeviceFeatures2 struct
153
0
        icd_term->dispatch.GetPhysicalDeviceFeatures(phys_dev_term->phys_dev, &pFeatures->features);
154
155
0
        const VkBaseInStructure *pNext = pFeatures->pNext;
156
0
        while (pNext != NULL) {
157
0
            switch (pNext->sType) {
158
0
                case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES: {
159
                    // Skip the check if VK_KHR_multiview is enabled because it's a device extension
160
                    // Write to the VkPhysicalDeviceMultiviewFeaturesKHR struct
161
0
                    VkPhysicalDeviceMultiviewFeaturesKHR *multiview_features = (VkPhysicalDeviceMultiviewFeaturesKHR *)pNext;
162
0
                    multiview_features->multiview = VK_FALSE;
163
0
                    multiview_features->multiviewGeometryShader = VK_FALSE;
164
0
                    multiview_features->multiviewTessellationShader = VK_FALSE;
165
166
0
                    pNext = multiview_features->pNext;
167
0
                    break;
168
0
                }
169
0
                default: {
170
0
                    loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
171
0
                               "vkGetPhysicalDeviceFeatures2: Emulation found unrecognized structure type in pFeatures->pNext - "
172
0
                               "this struct will be ignored");
173
174
0
                    pNext = pNext->pNext;
175
0
                    break;
176
0
                }
177
0
            }
178
0
        }
179
0
    }
180
0
}
181
182
VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
183
0
                                                                   VkPhysicalDeviceProperties2 *pProperties) {
184
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
185
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
186
0
    const struct loader_instance *inst = icd_term->this_instance;
187
188
0
    assert(inst != NULL);
189
190
    // Get the function pointer to use to call into the ICD. This could be the core or KHR version
191
0
    PFN_vkGetPhysicalDeviceProperties2 fpGetPhysicalDeviceProperties2 = NULL;
192
0
    if (loader_check_version_meets_required(LOADER_VERSION_1_1_0, inst->app_api_version)) {
193
0
        fpGetPhysicalDeviceProperties2 = icd_term->dispatch.GetPhysicalDeviceProperties2;
194
0
    }
195
0
    if (fpGetPhysicalDeviceProperties2 == NULL && inst->enabled_known_extensions.khr_get_physical_device_properties2) {
196
0
        fpGetPhysicalDeviceProperties2 = icd_term->dispatch.GetPhysicalDeviceProperties2KHR;
197
0
    }
198
199
0
    if (fpGetPhysicalDeviceProperties2 != NULL) {
200
        // Pass the call to the driver
201
0
        fpGetPhysicalDeviceProperties2(phys_dev_term->phys_dev, pProperties);
202
0
    } else {
203
        // Emulate the call
204
0
        loader_log(icd_term->this_instance, VULKAN_LOADER_INFO_BIT, 0,
205
0
                   "vkGetPhysicalDeviceProperties2: Emulating call in ICD \"%s\" using vkGetPhysicalDeviceProperties",
206
0
                   icd_term->scanned_icd->lib_name);
207
208
        // Write to the VkPhysicalDeviceProperties2 struct
209
0
        icd_term->dispatch.GetPhysicalDeviceProperties(phys_dev_term->phys_dev, &pProperties->properties);
210
211
0
        const VkBaseInStructure *pNext = pProperties->pNext;
212
0
        while (pNext != NULL) {
213
0
            switch (pNext->sType) {
214
0
                case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES: {
215
0
                    VkPhysicalDeviceIDPropertiesKHR *id_properties = (VkPhysicalDeviceIDPropertiesKHR *)pNext;
216
217
                    // Verify that "VK_KHR_external_memory_capabilities" is enabled
218
0
                    if (icd_term->this_instance->enabled_known_extensions.khr_external_memory_capabilities) {
219
0
                        loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
220
0
                                   "vkGetPhysicalDeviceProperties2: Emulation cannot generate unique IDs for struct "
221
0
                                   "VkPhysicalDeviceIDProperties - setting IDs to zero instead");
222
223
                        // Write to the VkPhysicalDeviceIDPropertiesKHR struct
224
0
                        memset(id_properties->deviceUUID, 0, VK_UUID_SIZE);
225
0
                        memset(id_properties->driverUUID, 0, VK_UUID_SIZE);
226
0
                        id_properties->deviceLUIDValid = VK_FALSE;
227
0
                    }
228
229
0
                    pNext = id_properties->pNext;
230
0
                    break;
231
0
                }
232
0
                default: {
233
0
                    loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
234
0
                               "vkGetPhysicalDeviceProperties2KHR: Emulation found unrecognized structure type in "
235
0
                               "pProperties->pNext - this struct will be ignored");
236
237
0
                    pNext = pNext->pNext;
238
0
                    break;
239
0
                }
240
0
            }
241
0
        }
242
0
    }
243
0
}
244
245
VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceFormatProperties2(VkPhysicalDevice physicalDevice, VkFormat format,
246
0
                                                                         VkFormatProperties2 *pFormatProperties) {
247
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
248
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
249
0
    const struct loader_instance *inst = icd_term->this_instance;
250
251
0
    assert(inst != NULL);
252
253
    // Get the function pointer to use to call into the ICD. This could be the core or KHR version
254
0
    PFN_vkGetPhysicalDeviceFormatProperties2 fpGetPhysicalDeviceFormatProperties2 = NULL;
255
0
    if (loader_check_version_meets_required(LOADER_VERSION_1_1_0, inst->app_api_version)) {
256
0
        fpGetPhysicalDeviceFormatProperties2 = icd_term->dispatch.GetPhysicalDeviceFormatProperties2;
257
0
    }
258
0
    if (fpGetPhysicalDeviceFormatProperties2 == NULL && inst->enabled_known_extensions.khr_get_physical_device_properties2) {
259
0
        fpGetPhysicalDeviceFormatProperties2 = icd_term->dispatch.GetPhysicalDeviceFormatProperties2KHR;
260
0
    }
261
262
0
    if (fpGetPhysicalDeviceFormatProperties2 != NULL) {
263
        // Pass the call to the driver
264
0
        fpGetPhysicalDeviceFormatProperties2(phys_dev_term->phys_dev, format, pFormatProperties);
265
0
    } else {
266
        // Emulate the call
267
0
        loader_log(icd_term->this_instance, VULKAN_LOADER_INFO_BIT, 0,
268
0
                   "vkGetPhysicalDeviceFormatProperties2: Emulating call in ICD \"%s\" using vkGetPhysicalDeviceFormatProperties",
269
0
                   icd_term->scanned_icd->lib_name);
270
271
        // Write to the VkFormatProperties2 struct
272
0
        icd_term->dispatch.GetPhysicalDeviceFormatProperties(phys_dev_term->phys_dev, format, &pFormatProperties->formatProperties);
273
274
0
        if (pFormatProperties->pNext != NULL) {
275
0
            loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
276
0
                       "vkGetPhysicalDeviceFormatProperties2: Emulation found unrecognized structure type in "
277
0
                       "pFormatProperties->pNext - this struct will be ignored");
278
0
        }
279
0
    }
280
0
}
281
282
VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceImageFormatProperties2(
283
    VkPhysicalDevice physicalDevice, const VkPhysicalDeviceImageFormatInfo2KHR *pImageFormatInfo,
284
0
    VkImageFormatProperties2KHR *pImageFormatProperties) {
285
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
286
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
287
0
    const struct loader_instance *inst = icd_term->this_instance;
288
289
0
    assert(inst != NULL);
290
291
    // Get the function pointer to use to call into the ICD. This could be the core or KHR version
292
0
    PFN_vkGetPhysicalDeviceImageFormatProperties2 fpGetPhysicalDeviceImageFormatProperties2 = NULL;
293
0
    if (loader_check_version_meets_required(LOADER_VERSION_1_1_0, inst->app_api_version)) {
294
0
        fpGetPhysicalDeviceImageFormatProperties2 = icd_term->dispatch.GetPhysicalDeviceImageFormatProperties2;
295
0
    }
296
0
    if (fpGetPhysicalDeviceImageFormatProperties2 == NULL && inst->enabled_known_extensions.khr_get_physical_device_properties2) {
297
0
        fpGetPhysicalDeviceImageFormatProperties2 = icd_term->dispatch.GetPhysicalDeviceImageFormatProperties2KHR;
298
0
    }
299
300
0
    if (fpGetPhysicalDeviceImageFormatProperties2 != NULL) {
301
        // Pass the call to the driver
302
0
        return fpGetPhysicalDeviceImageFormatProperties2(phys_dev_term->phys_dev, pImageFormatInfo, pImageFormatProperties);
303
0
    } else {
304
        // Emulate the call
305
0
        loader_log(icd_term->this_instance, VULKAN_LOADER_INFO_BIT, 0,
306
0
                   "vkGetPhysicalDeviceImageFormatProperties2: Emulating call in ICD \"%s\" using "
307
0
                   "vkGetPhysicalDeviceImageFormatProperties",
308
0
                   icd_term->scanned_icd->lib_name);
309
310
        // If there is more info in  either pNext, then this is unsupported
311
0
        if (pImageFormatInfo->pNext != NULL || pImageFormatProperties->pNext != NULL) {
312
0
            return VK_ERROR_FORMAT_NOT_SUPPORTED;
313
0
        }
314
315
        // Write to the VkImageFormatProperties2KHR struct
316
0
        return icd_term->dispatch.GetPhysicalDeviceImageFormatProperties(
317
0
            phys_dev_term->phys_dev, pImageFormatInfo->format, pImageFormatInfo->type, pImageFormatInfo->tiling,
318
0
            pImageFormatInfo->usage, pImageFormatInfo->flags, &pImageFormatProperties->imageFormatProperties);
319
0
    }
320
0
}
321
322
VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceQueueFamilyProperties2(VkPhysicalDevice physicalDevice,
323
                                                                              uint32_t *pQueueFamilyPropertyCount,
324
0
                                                                              VkQueueFamilyProperties2KHR *pQueueFamilyProperties) {
325
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
326
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
327
0
    const struct loader_instance *inst = icd_term->this_instance;
328
329
0
    assert(inst != NULL);
330
331
    // Get the function pointer to use to call into the ICD. This could be the core or KHR version
332
0
    PFN_vkGetPhysicalDeviceQueueFamilyProperties2 fpGetPhysicalDeviceQueueFamilyProperties2 = NULL;
333
0
    if (loader_check_version_meets_required(LOADER_VERSION_1_1_0, inst->app_api_version)) {
334
0
        fpGetPhysicalDeviceQueueFamilyProperties2 = icd_term->dispatch.GetPhysicalDeviceQueueFamilyProperties2;
335
0
    }
336
0
    if (fpGetPhysicalDeviceQueueFamilyProperties2 == NULL && inst->enabled_known_extensions.khr_get_physical_device_properties2) {
337
0
        fpGetPhysicalDeviceQueueFamilyProperties2 = icd_term->dispatch.GetPhysicalDeviceQueueFamilyProperties2KHR;
338
0
    }
339
340
0
    if (fpGetPhysicalDeviceQueueFamilyProperties2 != NULL) {
341
        // Pass the call to the driver
342
0
        fpGetPhysicalDeviceQueueFamilyProperties2(phys_dev_term->phys_dev, pQueueFamilyPropertyCount, pQueueFamilyProperties);
343
0
    } else {
344
        // Emulate the call
345
0
        loader_log(icd_term->this_instance, VULKAN_LOADER_INFO_BIT, 0,
346
0
                   "vkGetPhysicalDeviceQueueFamilyProperties2: Emulating call in ICD \"%s\" using "
347
0
                   "vkGetPhysicalDeviceQueueFamilyProperties",
348
0
                   icd_term->scanned_icd->lib_name);
349
350
0
        if (pQueueFamilyProperties == NULL || *pQueueFamilyPropertyCount == 0) {
351
            // Write to pQueueFamilyPropertyCount
352
0
            icd_term->dispatch.GetPhysicalDeviceQueueFamilyProperties(phys_dev_term->phys_dev, pQueueFamilyPropertyCount, NULL);
353
0
        } else {
354
            // Allocate a temporary array for the output of the old function
355
0
            VkQueueFamilyProperties *properties = loader_stack_alloc(*pQueueFamilyPropertyCount * sizeof(VkQueueFamilyProperties));
356
0
            if (properties == NULL) {
357
0
                *pQueueFamilyPropertyCount = 0;
358
0
                loader_log(icd_term->this_instance, VULKAN_LOADER_ERROR_BIT, 0,
359
0
                           "vkGetPhysicalDeviceQueueFamilyProperties2: Out of memory - Failed to allocate array for loader "
360
0
                           "emulation.");
361
0
                return;
362
0
            }
363
364
0
            icd_term->dispatch.GetPhysicalDeviceQueueFamilyProperties(phys_dev_term->phys_dev, pQueueFamilyPropertyCount,
365
0
                                                                      properties);
366
0
            for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; ++i) {
367
                // Write to the VkQueueFamilyProperties2KHR struct
368
0
                memcpy(&pQueueFamilyProperties[i].queueFamilyProperties, &properties[i], sizeof(VkQueueFamilyProperties));
369
370
0
                if (pQueueFamilyProperties[i].pNext != NULL) {
371
0
                    loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
372
0
                               "vkGetPhysicalDeviceQueueFamilyProperties2: Emulation found unrecognized structure type in "
373
0
                               "pQueueFamilyProperties[%d].pNext - this struct will be ignored",
374
0
                               i);
375
0
                }
376
0
            }
377
0
        }
378
0
    }
379
0
}
380
381
VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceMemoryProperties2(VkPhysicalDevice physicalDevice,
382
0
                                                                         VkPhysicalDeviceMemoryProperties2 *pMemoryProperties) {
383
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
384
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
385
0
    const struct loader_instance *inst = icd_term->this_instance;
386
387
0
    assert(inst != NULL);
388
389
    // Get the function pointer to use to call into the ICD. This could be the core or KHR version
390
0
    PFN_vkGetPhysicalDeviceMemoryProperties2 fpGetPhysicalDeviceMemoryProperties2 = NULL;
391
0
    if (loader_check_version_meets_required(LOADER_VERSION_1_1_0, inst->app_api_version)) {
392
0
        fpGetPhysicalDeviceMemoryProperties2 = icd_term->dispatch.GetPhysicalDeviceMemoryProperties2;
393
0
    }
394
0
    if (fpGetPhysicalDeviceMemoryProperties2 == NULL && inst->enabled_known_extensions.khr_get_physical_device_properties2) {
395
0
        fpGetPhysicalDeviceMemoryProperties2 = icd_term->dispatch.GetPhysicalDeviceMemoryProperties2KHR;
396
0
    }
397
398
0
    if (fpGetPhysicalDeviceMemoryProperties2 != NULL) {
399
        // Pass the call to the driver
400
0
        fpGetPhysicalDeviceMemoryProperties2(phys_dev_term->phys_dev, pMemoryProperties);
401
0
    } else {
402
        // Emulate the call
403
0
        loader_log(icd_term->this_instance, VULKAN_LOADER_INFO_BIT, 0,
404
0
                   "vkGetPhysicalDeviceMemoryProperties2: Emulating call in ICD \"%s\" using vkGetPhysicalDeviceMemoryProperties",
405
0
                   icd_term->scanned_icd->lib_name);
406
407
        // Write to the VkPhysicalDeviceMemoryProperties2 struct
408
0
        icd_term->dispatch.GetPhysicalDeviceMemoryProperties(phys_dev_term->phys_dev, &pMemoryProperties->memoryProperties);
409
410
0
        if (pMemoryProperties->pNext != NULL) {
411
0
            loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
412
0
                       "vkGetPhysicalDeviceMemoryProperties2: Emulation found unrecognized structure type in "
413
0
                       "pMemoryProperties->pNext - this struct will be ignored");
414
0
        }
415
0
    }
416
0
}
417
418
VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceSparseImageFormatProperties2(
419
    VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSparseImageFormatInfo2KHR *pFormatInfo, uint32_t *pPropertyCount,
420
0
    VkSparseImageFormatProperties2KHR *pProperties) {
421
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
422
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
423
0
    const struct loader_instance *inst = icd_term->this_instance;
424
425
0
    assert(inst != NULL);
426
427
    // Get the function pointer to use to call into the ICD. This could be the core or KHR version
428
0
    PFN_vkGetPhysicalDeviceSparseImageFormatProperties2 fpGetPhysicalDeviceSparseImageFormatProperties2 = NULL;
429
0
    if (loader_check_version_meets_required(LOADER_VERSION_1_1_0, inst->app_api_version)) {
430
0
        fpGetPhysicalDeviceSparseImageFormatProperties2 = icd_term->dispatch.GetPhysicalDeviceSparseImageFormatProperties2;
431
0
    }
432
0
    if (fpGetPhysicalDeviceSparseImageFormatProperties2 == NULL &&
433
0
        inst->enabled_known_extensions.khr_get_physical_device_properties2) {
434
0
        fpGetPhysicalDeviceSparseImageFormatProperties2 = icd_term->dispatch.GetPhysicalDeviceSparseImageFormatProperties2KHR;
435
0
    }
436
437
0
    if (fpGetPhysicalDeviceSparseImageFormatProperties2 != NULL) {
438
        // Pass the call to the driver
439
0
        fpGetPhysicalDeviceSparseImageFormatProperties2(phys_dev_term->phys_dev, pFormatInfo, pPropertyCount, pProperties);
440
0
    } else {
441
        // Emulate the call
442
0
        loader_log(icd_term->this_instance, VULKAN_LOADER_INFO_BIT, 0,
443
0
                   "vkGetPhysicalDeviceSparseImageFormatProperties2: Emulating call in ICD \"%s\" using "
444
0
                   "vkGetPhysicalDeviceSparseImageFormatProperties",
445
0
                   icd_term->scanned_icd->lib_name);
446
447
0
        if (pFormatInfo->pNext != NULL) {
448
0
            loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
449
0
                       "vkGetPhysicalDeviceSparseImageFormatProperties2: Emulation found unrecognized structure type in "
450
0
                       "pFormatInfo->pNext - this struct will be ignored");
451
0
        }
452
453
0
        if (pProperties == NULL || *pPropertyCount == 0) {
454
            // Write to pPropertyCount
455
0
            icd_term->dispatch.GetPhysicalDeviceSparseImageFormatProperties(
456
0
                phys_dev_term->phys_dev, pFormatInfo->format, pFormatInfo->type, pFormatInfo->samples, pFormatInfo->usage,
457
0
                pFormatInfo->tiling, pPropertyCount, NULL);
458
0
        } else {
459
            // Allocate a temporary array for the output of the old function
460
0
            VkSparseImageFormatProperties *properties =
461
0
                loader_stack_alloc(*pPropertyCount * sizeof(VkSparseImageMemoryRequirements));
462
0
            if (properties == NULL) {
463
0
                *pPropertyCount = 0;
464
0
                loader_log(icd_term->this_instance, VULKAN_LOADER_ERROR_BIT, 0,
465
0
                           "vkGetPhysicalDeviceSparseImageFormatProperties2: Out of memory - Failed to allocate array for "
466
0
                           "loader emulation.");
467
0
                return;
468
0
            }
469
470
0
            icd_term->dispatch.GetPhysicalDeviceSparseImageFormatProperties(
471
0
                phys_dev_term->phys_dev, pFormatInfo->format, pFormatInfo->type, pFormatInfo->samples, pFormatInfo->usage,
472
0
                pFormatInfo->tiling, pPropertyCount, properties);
473
0
            for (uint32_t i = 0; i < *pPropertyCount; ++i) {
474
                // Write to the VkSparseImageFormatProperties2KHR struct
475
0
                memcpy(&pProperties[i].properties, &properties[i], sizeof(VkSparseImageFormatProperties));
476
477
0
                if (pProperties[i].pNext != NULL) {
478
0
                    loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
479
0
                               "vkGetPhysicalDeviceSparseImageFormatProperties2: Emulation found unrecognized structure type in "
480
0
                               "pProperties[%d].pNext - this struct will be ignored",
481
0
                               i);
482
0
                }
483
0
            }
484
0
        }
485
0
    }
486
0
}
487
488
VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceExternalBufferProperties(
489
    VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalBufferInfo *pExternalBufferInfo,
490
0
    VkExternalBufferProperties *pExternalBufferProperties) {
491
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
492
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
493
0
    const struct loader_instance *inst = icd_term->this_instance;
494
495
0
    assert(inst != NULL);
496
497
    // Get the function pointer to use to call into the ICD. This could be the core or KHR version
498
0
    PFN_vkGetPhysicalDeviceExternalBufferProperties fpGetPhysicalDeviceExternalBufferProperties = NULL;
499
0
    if (loader_check_version_meets_required(LOADER_VERSION_1_1_0, inst->app_api_version)) {
500
0
        fpGetPhysicalDeviceExternalBufferProperties = icd_term->dispatch.GetPhysicalDeviceExternalBufferProperties;
501
0
    }
502
0
    if (fpGetPhysicalDeviceExternalBufferProperties == NULL && inst->enabled_known_extensions.khr_external_memory_capabilities) {
503
0
        fpGetPhysicalDeviceExternalBufferProperties = icd_term->dispatch.GetPhysicalDeviceExternalBufferPropertiesKHR;
504
0
    }
505
506
0
    if (fpGetPhysicalDeviceExternalBufferProperties != NULL) {
507
        // Pass the call to the driver
508
0
        fpGetPhysicalDeviceExternalBufferProperties(phys_dev_term->phys_dev, pExternalBufferInfo, pExternalBufferProperties);
509
0
    } else {
510
        // Emulate the call
511
0
        loader_log(icd_term->this_instance, VULKAN_LOADER_INFO_BIT, 0,
512
0
                   "vkGetPhysicalDeviceExternalBufferProperties: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name);
513
514
0
        if (pExternalBufferInfo->pNext != NULL) {
515
0
            loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
516
0
                       "vkGetPhysicalDeviceExternalBufferProperties: Emulation found unrecognized structure type in "
517
0
                       "pExternalBufferInfo->pNext - this struct will be ignored");
518
0
        }
519
520
        // Fill in everything being unsupported
521
0
        memset(&pExternalBufferProperties->externalMemoryProperties, 0, sizeof(VkExternalMemoryPropertiesKHR));
522
523
0
        if (pExternalBufferProperties->pNext != NULL) {
524
0
            loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
525
0
                       "vkGetPhysicalDeviceExternalBufferProperties: Emulation found unrecognized structure type in "
526
0
                       "pExternalBufferProperties->pNext - this struct will be ignored");
527
0
        }
528
0
    }
529
0
}
530
531
VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceExternalSemaphoreProperties(
532
    VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalSemaphoreInfo *pExternalSemaphoreInfo,
533
0
    VkExternalSemaphoreProperties *pExternalSemaphoreProperties) {
534
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
535
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
536
0
    const struct loader_instance *inst = icd_term->this_instance;
537
538
0
    assert(inst != NULL);
539
540
    // Get the function pointer to use to call into the ICD. This could be the core or KHR version
541
0
    PFN_vkGetPhysicalDeviceExternalSemaphoreProperties fpGetPhysicalDeviceExternalSemaphoreProperties = NULL;
542
0
    if (loader_check_version_meets_required(LOADER_VERSION_1_1_0, inst->app_api_version)) {
543
0
        fpGetPhysicalDeviceExternalSemaphoreProperties = icd_term->dispatch.GetPhysicalDeviceExternalSemaphoreProperties;
544
0
    }
545
0
    if (fpGetPhysicalDeviceExternalSemaphoreProperties == NULL &&
546
0
        inst->enabled_known_extensions.khr_external_semaphore_capabilities) {
547
0
        fpGetPhysicalDeviceExternalSemaphoreProperties = icd_term->dispatch.GetPhysicalDeviceExternalSemaphorePropertiesKHR;
548
0
    }
549
550
0
    if (fpGetPhysicalDeviceExternalSemaphoreProperties != NULL) {
551
        // Pass the call to the driver
552
0
        fpGetPhysicalDeviceExternalSemaphoreProperties(phys_dev_term->phys_dev, pExternalSemaphoreInfo,
553
0
                                                       pExternalSemaphoreProperties);
554
0
    } else {
555
        // Emulate the call
556
0
        loader_log(icd_term->this_instance, VULKAN_LOADER_INFO_BIT, 0,
557
0
                   "vkGetPhysicalDeviceExternalSemaphoreProperties: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name);
558
559
0
        if (pExternalSemaphoreInfo->pNext != NULL) {
560
0
            loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
561
0
                       "vkGetPhysicalDeviceExternalSemaphoreProperties: Emulation found unrecognized structure type in "
562
0
                       "pExternalSemaphoreInfo->pNext - this struct will be ignored");
563
0
        }
564
565
        // Fill in everything being unsupported
566
0
        pExternalSemaphoreProperties->exportFromImportedHandleTypes = 0;
567
0
        pExternalSemaphoreProperties->compatibleHandleTypes = 0;
568
0
        pExternalSemaphoreProperties->externalSemaphoreFeatures = 0;
569
570
0
        if (pExternalSemaphoreProperties->pNext != NULL) {
571
0
            loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
572
0
                       "vkGetPhysicalDeviceExternalSemaphoreProperties: Emulation found unrecognized structure type in "
573
0
                       "pExternalSemaphoreProperties->pNext - this struct will be ignored");
574
0
        }
575
0
    }
576
0
}
577
578
VKAPI_ATTR void VKAPI_CALL terminator_GetPhysicalDeviceExternalFenceProperties(
579
    VkPhysicalDevice physicalDevice, const VkPhysicalDeviceExternalFenceInfo *pExternalFenceInfo,
580
0
    VkExternalFenceProperties *pExternalFenceProperties) {
581
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
582
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
583
0
    const struct loader_instance *inst = icd_term->this_instance;
584
585
0
    assert(inst != NULL);
586
587
    // Get the function pointer to use to call into the ICD. This could be the core or KHR version
588
0
    PFN_vkGetPhysicalDeviceExternalFenceProperties fpGetPhysicalDeviceExternalFenceProperties = NULL;
589
0
    if (loader_check_version_meets_required(LOADER_VERSION_1_1_0, inst->app_api_version)) {
590
0
        fpGetPhysicalDeviceExternalFenceProperties = icd_term->dispatch.GetPhysicalDeviceExternalFenceProperties;
591
0
    }
592
0
    if (fpGetPhysicalDeviceExternalFenceProperties == NULL && inst->enabled_known_extensions.khr_external_fence_capabilities) {
593
0
        fpGetPhysicalDeviceExternalFenceProperties = icd_term->dispatch.GetPhysicalDeviceExternalFencePropertiesKHR;
594
0
    }
595
596
0
    if (fpGetPhysicalDeviceExternalFenceProperties != NULL) {
597
        // Pass the call to the driver
598
0
        fpGetPhysicalDeviceExternalFenceProperties(phys_dev_term->phys_dev, pExternalFenceInfo, pExternalFenceProperties);
599
0
    } else {
600
        // Emulate the call
601
0
        loader_log(icd_term->this_instance, VULKAN_LOADER_INFO_BIT, 0,
602
0
                   "vkGetPhysicalDeviceExternalFenceProperties: Emulating call in ICD \"%s\"", icd_term->scanned_icd->lib_name);
603
604
0
        if (pExternalFenceInfo->pNext != NULL) {
605
0
            loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
606
0
                       "vkGetPhysicalDeviceExternalFenceProperties: Emulation found unrecognized structure type in "
607
0
                       "pExternalFenceInfo->pNext - this struct will be ignored");
608
0
        }
609
610
        // Fill in everything being unsupported
611
0
        pExternalFenceProperties->exportFromImportedHandleTypes = 0;
612
0
        pExternalFenceProperties->compatibleHandleTypes = 0;
613
0
        pExternalFenceProperties->externalFenceFeatures = 0;
614
615
0
        if (pExternalFenceProperties->pNext != NULL) {
616
0
            loader_log(icd_term->this_instance, VULKAN_LOADER_WARN_BIT, 0,
617
0
                       "vkGetPhysicalDeviceExternalFenceProperties: Emulation found unrecognized structure type in "
618
0
                       "pExternalFenceProperties->pNext - this struct will be ignored");
619
0
        }
620
0
    }
621
0
}
622
623
// 1.3 Core terminators
624
625
VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceToolProperties(VkPhysicalDevice physicalDevice, uint32_t *pToolCount,
626
0
                                                                          VkPhysicalDeviceToolProperties *pToolProperties) {
627
0
    struct loader_physical_device_term *phys_dev_term = (struct loader_physical_device_term *)physicalDevice;
628
0
    struct loader_icd_term *icd_term = phys_dev_term->this_icd_term;
629
630
0
    if (NULL == icd_term->dispatch.GetPhysicalDeviceToolProperties) {
631
0
        loader_log(icd_term->this_instance, VULKAN_LOADER_ERROR_BIT, 0,
632
0
                   "terminator_GetPhysicalDeviceToolProperties: The ICD's vkGetPhysicalDeviceToolProperties was NULL yet "
633
0
                   "the physical device supports Vulkan API Version 1.3.");
634
0
    } else {
635
0
        VkPhysicalDeviceProperties properties;
636
0
        if (icd_term->dispatch.GetPhysicalDeviceProperties) {
637
0
            icd_term->dispatch.GetPhysicalDeviceProperties(phys_dev_term->phys_dev, &properties);
638
639
0
            if (VK_API_VERSION_MINOR(properties.apiVersion) >= 3) {
640
0
                return icd_term->dispatch.GetPhysicalDeviceToolProperties(phys_dev_term->phys_dev, pToolCount, pToolProperties);
641
0
            }
642
0
        }
643
0
    }
644
645
    // In the case the driver didn't support 1.3, make sure that the first layer doesn't find the count uninitialized
646
0
    *pToolCount = 0;
647
0
    return VK_SUCCESS;
648
0
}