1 /*
2 * Copyright (c) 2021-2022 The Khronos Group Inc.
3 * Copyright (c) 2021-2022 Valve Corporation
4 * Copyright (c) 2021-2022 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and/or associated documentation files (the "Materials"), to
8 * deal in the Materials without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Materials, and to permit persons to whom the Materials are
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice(s) and this permission notice shall be included in
14 * all copies or substantial portions of the Materials.
15 *
16 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 *
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
23 * USE OR OTHER DEALINGS IN THE MATERIALS.
24 *
25 * Author: Charles Giessen <charles@lunarg.com>
26 */
27
28 #include "test_environment.h"
29
30 // Verify that the various ways to get vkGetInstanceProcAddr return the same value
TEST(GetProcAddr,VerifyGetInstanceProcAddr)31 TEST(GetProcAddr, VerifyGetInstanceProcAddr) {
32 FrameworkEnvironment env{};
33 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).add_physical_device("physical_device_0");
34 {
35 InstWrapper inst{env.vulkan_functions};
36 inst.create_info.set_api_version(VK_API_VERSION_1_1);
37 inst.CheckCreate();
38
39 // NOTE: The vulkan_functions are queried using the platform get proc addr from the loader. So we'll compare
40 // that to what is returned by asking it what the various Vulkan get proc addr functions are.
41 PFN_vkGetInstanceProcAddr gipa_loader = env.vulkan_functions.vkGetInstanceProcAddr;
42 PFN_vkGetInstanceProcAddr gipa_queried = reinterpret_cast<PFN_vkGetInstanceProcAddr>(
43 env.vulkan_functions.vkGetInstanceProcAddr(inst.inst, "vkGetInstanceProcAddr"));
44 ASSERT_EQ(gipa_loader, gipa_queried);
45 }
46
47 {
48 InstWrapper inst{env.vulkan_functions};
49 inst.create_info.set_api_version(VK_API_VERSION_1_3);
50 inst.CheckCreate();
51
52 // NOTE: The vulkan_functions are queried using the platform get proc addr from the loader. So we'll compare
53 // that to what is returned by asking it what the various Vulkan get proc addr functions are.
54 PFN_vkGetInstanceProcAddr gipa_loader = env.vulkan_functions.vkGetInstanceProcAddr;
55 PFN_vkGetInstanceProcAddr gipa_queried = reinterpret_cast<PFN_vkGetInstanceProcAddr>(
56 env.vulkan_functions.vkGetInstanceProcAddr(inst.inst, "vkGetInstanceProcAddr"));
57 ASSERT_EQ(gipa_loader, gipa_queried);
58 }
59 }
60
61 // Verify that the various ways to get vkGetDeviceProcAddr return the same value
TEST(GetProcAddr,VerifyGetDeviceProcAddr)62 TEST(GetProcAddr, VerifyGetDeviceProcAddr) {
63 FrameworkEnvironment env{};
64 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).add_physical_device("physical_device_0");
65
66 InstWrapper inst{env.vulkan_functions};
67 inst.create_info.set_api_version(VK_API_VERSION_1_1);
68 inst.CheckCreate();
69 VkPhysicalDevice phys_dev = inst.GetPhysDev();
70
71 // NOTE: The vulkan_functions are queried using the platform get proc addr from the loader. So we'll compare
72 // that to what is returned by asking it what the various Vulkan get proc addr functions are.
73 PFN_vkGetDeviceProcAddr gdpa_loader = env.vulkan_functions.vkGetDeviceProcAddr;
74 PFN_vkGetDeviceProcAddr gdpa_inst_queried = inst.load("vkGetDeviceProcAddr");
75 ASSERT_EQ(gdpa_loader, gdpa_inst_queried);
76
77 DeviceWrapper dev{inst};
78 dev.CheckCreate(phys_dev);
79
80 PFN_vkGetDeviceProcAddr gdpa_dev_queried = dev.load("vkGetDeviceProcAddr");
81 ASSERT_EQ(gdpa_loader, gdpa_dev_queried);
82 }
83
84 // Load the global function pointers with and without a NULL vkInstance handle.
85 // Call the function to make sure it is callable, don't care about what is returned.
TEST(GetProcAddr,GlobalFunctions)86 TEST(GetProcAddr, GlobalFunctions) {
87 FrameworkEnvironment env{};
88 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).add_physical_device("physical_device_0");
89
90 auto& gipa = env.vulkan_functions.vkGetInstanceProcAddr;
91 // global entry points with NULL instance handle
92 {
93 auto EnumerateInstanceExtensionProperties =
94 reinterpret_cast<PFN_vkEnumerateInstanceExtensionProperties>(gipa(NULL, "vkEnumerateInstanceExtensionProperties"));
95 handle_assert_has_value(EnumerateInstanceExtensionProperties);
96 uint32_t ext_count = 0;
97 ASSERT_EQ(VK_SUCCESS, EnumerateInstanceExtensionProperties("", &ext_count, nullptr));
98
99 auto EnumerateInstanceLayerProperties =
100 reinterpret_cast<PFN_vkEnumerateInstanceLayerProperties>(gipa(NULL, "vkEnumerateInstanceLayerProperties"));
101 handle_assert_has_value(EnumerateInstanceLayerProperties);
102 uint32_t layer_count = 0;
103 ASSERT_EQ(VK_SUCCESS, EnumerateInstanceLayerProperties(&layer_count, nullptr));
104
105 auto EnumerateInstanceVersion = reinterpret_cast<PFN_vkEnumerateInstanceVersion>(gipa(NULL, "vkEnumerateInstanceVersion"));
106 handle_assert_has_value(EnumerateInstanceVersion);
107 uint32_t api_version = 0;
108 EnumerateInstanceVersion(&api_version);
109
110 auto GetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(gipa(NULL, "vkGetInstanceProcAddr"));
111 ASSERT_EQ(GetInstanceProcAddr,
112 reinterpret_cast<PFN_vkGetInstanceProcAddr>(GetInstanceProcAddr(NULL, "vkGetInstanceProcAddr")));
113
114 auto CreateInstance = reinterpret_cast<PFN_vkCreateInstance>(gipa(NULL, "vkCreateInstance"));
115 handle_assert_has_value(CreateInstance);
116 }
117 // Now create an instance and query the functions again - should work because the instance version is less than 1.2
118 for (int i = 0; i <= 2; i++) {
119 InstWrapper inst{env.vulkan_functions};
120 inst.create_info.api_version = VK_MAKE_API_VERSION(0, 1, i, 0);
121 inst.CheckCreate();
122
123 PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties =
124 inst.load("vkEnumerateInstanceExtensionProperties");
125 handle_assert_has_value(EnumerateInstanceExtensionProperties);
126 uint32_t ext_count = 0;
127 ASSERT_EQ(VK_SUCCESS, EnumerateInstanceExtensionProperties("", &ext_count, nullptr));
128
129 PFN_vkEnumerateInstanceLayerProperties EnumerateInstanceLayerProperties = inst.load("vkEnumerateInstanceLayerProperties");
130 handle_assert_has_value(EnumerateInstanceLayerProperties);
131 uint32_t layer_count = 0;
132 ASSERT_EQ(VK_SUCCESS, EnumerateInstanceLayerProperties(&layer_count, nullptr));
133
134 PFN_vkEnumerateInstanceVersion EnumerateInstanceVersion = inst.load("vkEnumerateInstanceVersion");
135 handle_assert_has_value(EnumerateInstanceVersion);
136 uint32_t api_version = 0;
137 EnumerateInstanceVersion(&api_version);
138
139 PFN_vkGetInstanceProcAddr GetInstanceProcAddr = inst.load("vkGetInstanceProcAddr");
140 handle_assert_has_value(GetInstanceProcAddr);
141 ASSERT_EQ(GetInstanceProcAddr,
142 reinterpret_cast<PFN_vkGetInstanceProcAddr>(GetInstanceProcAddr(inst, "vkGetInstanceProcAddr")));
143
144 PFN_vkCreateInstance CreateInstance = inst.load("vkCreateInstance");
145 handle_assert_has_value(CreateInstance);
146 }
147 {
148 // Create a 1.3 instance - now everything should return NULL
149 InstWrapper inst{env.vulkan_functions};
150 inst.create_info.api_version = VK_MAKE_API_VERSION(0, 1, 3, 0);
151 inst.CheckCreate();
152
153 PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties =
154 inst.load("vkEnumerateInstanceExtensionProperties");
155 handle_assert_null(EnumerateInstanceExtensionProperties);
156
157 PFN_vkEnumerateInstanceLayerProperties EnumerateInstanceLayerProperties = inst.load("vkEnumerateInstanceLayerProperties");
158 handle_assert_null(EnumerateInstanceLayerProperties);
159
160 PFN_vkEnumerateInstanceVersion EnumerateInstanceVersion = inst.load("vkEnumerateInstanceVersion");
161 handle_assert_null(EnumerateInstanceVersion);
162
163 PFN_vkCreateInstance CreateInstance = inst.load("vkCreateInstance");
164 handle_assert_null(CreateInstance);
165
166 PFN_vkGetInstanceProcAddr GetInstanceProcAddr = inst.load("vkGetInstanceProcAddr");
167 handle_assert_equal(env.vulkan_functions.vkGetInstanceProcAddr, GetInstanceProcAddr);
168 ASSERT_EQ(GetInstanceProcAddr,
169 reinterpret_cast<PFN_vkGetInstanceProcAddr>(GetInstanceProcAddr(inst, "vkGetInstanceProcAddr")));
170 ASSERT_EQ(GetInstanceProcAddr,
171 reinterpret_cast<PFN_vkGetInstanceProcAddr>(GetInstanceProcAddr(NULL, "vkGetInstanceProcAddr")));
172 // get a non pre-instance function pointer
173 PFN_vkEnumeratePhysicalDevices EnumeratePhysicalDevices = inst.load("vkEnumeratePhysicalDevices");
174 handle_assert_has_value(EnumeratePhysicalDevices);
175
176 EnumeratePhysicalDevices = reinterpret_cast<PFN_vkEnumeratePhysicalDevices>(gipa(NULL, "vkEnumeratePhysicalDevices"));
177 handle_assert_null(EnumeratePhysicalDevices);
178 }
179 }
180
TEST(GetProcAddr,Verify10FunctionsFailToLoadWithSingleDriver)181 TEST(GetProcAddr, Verify10FunctionsFailToLoadWithSingleDriver) {
182 FrameworkEnvironment env{};
183 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)).add_physical_device({}).set_can_query_GetPhysicalDeviceFuncs(false);
184
185 InstWrapper inst{env.vulkan_functions};
186 inst.CheckCreate(VK_ERROR_INCOMPATIBLE_DRIVER);
187 }
188
TEST(GetProcAddr,Verify10FunctionsLoadWithMultipleDrivers)189 TEST(GetProcAddr, Verify10FunctionsLoadWithMultipleDrivers) {
190 FrameworkEnvironment env{};
191 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)).add_physical_device({});
192 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2)).add_physical_device({}).set_can_query_GetPhysicalDeviceFuncs(false);
193
194 InstWrapper inst{env.vulkan_functions};
195 inst.CheckCreate();
196
197 inst.GetPhysDevs(1);
198 }
199
200 // Swapchain functions which require a terminator in all cases have situations where the driver may have a
201 // NULL function pointer but the loader shouldn't abort() if that is the case. Rather, it should log a message
202 // and return VK_SUCCESS to maintain previous behavior.
TEST(GetDeviceProcAddr,SwapchainFuncsWithTerminator)203 TEST(GetDeviceProcAddr, SwapchainFuncsWithTerminator) {
204 FrameworkEnvironment env{};
205 auto& driver =
206 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).setup_WSI().add_physical_device("physical_device_0");
207
208 InstWrapper inst(env.vulkan_functions);
209 inst.create_info.add_extension("VK_EXT_debug_utils");
210 inst.create_info.setup_WSI();
211 ASSERT_NO_FATAL_FAILURE(inst.CheckCreate());
212
213 VkSurfaceKHR surface{};
214 ASSERT_EQ(VK_SUCCESS, create_surface(inst, surface));
215
216 VkSurfaceKHR surface2{};
217 ASSERT_EQ(VK_SUCCESS, create_surface(inst, surface2));
218
219 DebugUtilsWrapper log{inst};
220 ASSERT_EQ(VK_SUCCESS, CreateDebugUtilsMessenger(log));
221 auto phys_dev = inst.GetPhysDev();
222 {
223 DeviceWrapper dev{inst};
224 ASSERT_NO_FATAL_FAILURE(dev.CheckCreate(phys_dev));
225 DeviceFunctions dev_funcs{env.vulkan_functions, dev};
226
227 PFN_vkCreateSwapchainKHR CreateSwapchainKHR = dev.load("vkCreateSwapchainKHR");
228 PFN_vkCreateSwapchainKHR inst_CreateSwapchainKHR = inst.load("vkCreateSwapchainKHR");
229 PFN_vkGetDeviceGroupSurfacePresentModesKHR GetDeviceGroupSurfacePresentModesKHR =
230 dev.load("vkGetDeviceGroupSurfacePresentModesKHR");
231 PFN_vkCreateSharedSwapchainsKHR CreateSharedSwapchainsKHR = dev.load("vkCreateSharedSwapchainsKHR");
232 ASSERT_FALSE(CreateSwapchainKHR);
233 ASSERT_TRUE(inst_CreateSwapchainKHR);
234 ASSERT_FALSE(GetDeviceGroupSurfacePresentModesKHR);
235 ASSERT_FALSE(CreateSharedSwapchainsKHR);
236
237 VkSwapchainCreateInfoKHR info{};
238 info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
239 info.surface = surface;
240
241 VkSwapchainKHR swapchain{};
242 log.logger.clear();
243 ASSERT_FALSE(dev_funcs.vkDestroySwapchainKHR);
244
245 // try to call the vkCreateSwapchainKHR acquired from the instance - this *should* abort due to not enabling the extension
246 ASSERT_DEATH(inst_CreateSwapchainKHR(dev.dev, &info, nullptr, &swapchain),
247 "vkCreateSwapchainKHR: Driver's function pointer was NULL, returning VK_SUCCESS. Was the VK_KHR_swapchain "
248 "extension enabled?");
249
250 log.logger.clear();
251 ASSERT_FALSE(dev_funcs.vkDestroySwapchainKHR);
252 }
253 driver.physical_devices.at(0).add_extensions({"VK_KHR_swapchain", "VK_KHR_display_swapchain", "VK_EXT_debug_marker"});
254 {
255 DeviceWrapper dev{inst};
256 dev.create_info.add_extensions({"VK_KHR_swapchain", "VK_KHR_display_swapchain", "VK_EXT_debug_marker"});
257 ASSERT_NO_FATAL_FAILURE(dev.CheckCreate(phys_dev));
258 DeviceFunctions dev_funcs{env.vulkan_functions, dev};
259
260 PFN_vkCreateSwapchainKHR CreateSwapchainKHR = dev.load("vkCreateSwapchainKHR");
261 PFN_vkCreateSwapchainKHR inst_CreateSwapchainKHR = inst.load("vkCreateSwapchainKHR");
262 PFN_vkGetDeviceGroupSurfacePresentModesKHR GetDeviceGroupSurfacePresentModesKHR =
263 dev.load("vkGetDeviceGroupSurfacePresentModesKHR");
264 PFN_vkCreateSharedSwapchainsKHR CreateSharedSwapchainsKHR = dev.load("vkCreateSharedSwapchainsKHR");
265 ASSERT_TRUE(CreateSwapchainKHR);
266 ASSERT_TRUE(inst_CreateSwapchainKHR);
267 ASSERT_TRUE(GetDeviceGroupSurfacePresentModesKHR);
268 ASSERT_TRUE(CreateSharedSwapchainsKHR);
269 ASSERT_TRUE(dev_funcs.vkDestroySwapchainKHR);
270
271 VkSwapchainCreateInfoKHR info{};
272 info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
273 info.surface = surface;
274
275 VkSwapchainKHR swapchain{};
276 CreateSwapchainKHR(dev.dev, &info, nullptr, &swapchain);
277 ASSERT_FALSE(
278 log.find("vkCreateSwapchainKHR: Driver's function pointer was NULL, returning VK_SUCCESS. Was the VK_KHR_swapchain "
279 "extension enabled?"));
280 log.logger.clear();
281 dev_funcs.vkDestroySwapchainKHR(dev.dev, swapchain, nullptr);
282 inst_CreateSwapchainKHR(dev.dev, &info, nullptr, &swapchain);
283 ASSERT_FALSE(
284 log.find("vkCreateSwapchainKHR: Driver's function pointer was NULL, returning VK_SUCCESS. Was the VK_KHR_swapchain "
285 "extension enabled?"));
286 log.logger.clear();
287 dev_funcs.vkDestroySwapchainKHR(dev.dev, swapchain, nullptr);
288
289 VkDeviceGroupPresentModeFlagsKHR modes{};
290 GetDeviceGroupSurfacePresentModesKHR(dev.dev, surface, &modes);
291
292 std::array<VkSwapchainCreateInfoKHR, 2> infos{};
293 infos[0] = info;
294 infos[1].sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
295 infos[1].surface = surface2;
296
297 ASSERT_EQ(VK_SUCCESS, CreateSharedSwapchainsKHR(dev.dev, 2, infos.data(), nullptr, &swapchain));
298 }
299 env.vulkan_functions.vkDestroySurfaceKHR(inst.inst, surface, nullptr);
300 env.vulkan_functions.vkDestroySurfaceKHR(inst.inst, surface2, nullptr);
301 }
302
303 // Verify that the various ways to get vkGetDeviceProcAddr return the same value
TEST(GetProcAddr,PreserveLayerGettingVkCreateDeviceWithNullInstance)304 TEST(GetProcAddr, PreserveLayerGettingVkCreateDeviceWithNullInstance) {
305 FrameworkEnvironment env{};
306 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).add_physical_device("physical_device_0");
307
308 env.add_implicit_layer(TestLayerDetails(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{}
309 .set_name("VK_LAYER_technically_buggy_layer")
310 .set_description("actually_layer_1")
311 .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)
312 .set_disable_environment("if_you_can")),
313 "buggy_layer_1.json"));
314 env.get_test_layer().set_buggy_query_of_vkCreateDevice(true);
315 InstWrapper inst{env.vulkan_functions};
316 inst.create_info.set_api_version(VK_API_VERSION_1_1);
317 inst.CheckCreate();
318 VkPhysicalDevice phys_dev = inst.GetPhysDev();
319
320 DeviceWrapper dev{inst};
321 dev.CheckCreate(phys_dev);
322 }
323
324 // The following tests - AppQueries11FunctionsWhileOnlyEnabling10, AppQueries12FunctionsWhileOnlyEnabling11, and
325 // AppQueries13FunctionsWhileOnlyEnabling12 - check that vkGetDeviceProcAddr only returning functions from core versions up to
326 // the apiVersion declared in VkApplicationInfo. Function querying should succeed if VK_KHR_maintenance_5 is not enabled, and they
327 // should return zero when that extension is enabled.
328
TEST(GetDeviceProcAddr,AppQueries11FunctionsWhileOnlyEnabling10)329 TEST(GetDeviceProcAddr, AppQueries11FunctionsWhileOnlyEnabling10) {
330 FrameworkEnvironment env{};
331 auto& driver =
332 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2, VK_API_VERSION_1_1))
333 .set_icd_api_version(VK_API_VERSION_1_1)
334 .add_physical_device(
335 PhysicalDevice{}.set_api_version(VK_API_VERSION_1_1).add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME).finish());
336
337 std::vector<const char*> functions = {"vkGetDeviceQueue2", "vkCmdDispatchBase", "vkCreateDescriptorUpdateTemplate"};
338 for (const auto& f : functions) {
339 driver.physical_devices.back().add_device_function(VulkanFunction{f, [] {}});
340 }
341 { // doesn't enable the feature or extension
342 InstWrapper inst{env.vulkan_functions};
343 inst.create_info.set_api_version(1, 0, 0);
344 inst.CheckCreate();
345
346 DeviceWrapper dev{inst};
347 dev.CheckCreate(inst.GetPhysDev());
348 for (const auto& f : functions) {
349 ASSERT_NE(nullptr, dev->vkGetDeviceProcAddr(dev.dev, f));
350 }
351 }
352 { // doesn't enable the feature
353 InstWrapper inst{env.vulkan_functions};
354 inst.create_info.set_api_version(1, 0, 0);
355 inst.CheckCreate();
356
357 DeviceWrapper dev{inst};
358 dev.create_info.add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME);
359 dev.CheckCreate(inst.GetPhysDev());
360 for (const auto& f : functions) {
361 ASSERT_NE(nullptr, dev->vkGetDeviceProcAddr(dev.dev, f));
362 }
363 }
364 { // enables the feature and extension
365 InstWrapper inst{env.vulkan_functions};
366 inst.create_info.set_api_version(1, 0, 0);
367 inst.CheckCreate();
368
369 VkPhysicalDeviceMaintenance5FeaturesKHR features{};
370 features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_5_FEATURES_KHR;
371 features.maintenance5 = VK_TRUE;
372
373 DeviceWrapper dev{inst};
374 dev.create_info.add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME);
375 dev.create_info.dev.pNext = &features;
376 dev.CheckCreate(inst.GetPhysDev());
377 for (const auto& f : functions) {
378 ASSERT_EQ(nullptr, dev->vkGetDeviceProcAddr(dev.dev, f));
379 }
380 }
381 }
382
TEST(GetDeviceProcAddr,AppQueries12FunctionsWhileOnlyEnabling11)383 TEST(GetDeviceProcAddr, AppQueries12FunctionsWhileOnlyEnabling11) {
384 FrameworkEnvironment env{};
385 auto& driver =
386 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2, VK_API_VERSION_1_2))
387 .set_icd_api_version(VK_API_VERSION_1_2)
388 .add_physical_device(
389 PhysicalDevice{}.set_api_version(VK_API_VERSION_1_2).add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME).finish());
390 std::vector<const char*> functions = {"vkCmdDrawIndirectCount", "vkCmdNextSubpass2", "vkGetBufferDeviceAddress",
391 "vkGetDeviceMemoryOpaqueCaptureAddress"};
392 for (const auto& f : functions) {
393 driver.physical_devices.back().add_device_function(VulkanFunction{f, [] {}});
394 }
395 { // doesn't enable the feature or extension
396 InstWrapper inst{env.vulkan_functions};
397 inst.create_info.set_api_version(1, 1, 0);
398 inst.CheckCreate();
399
400 DeviceWrapper dev{inst};
401 dev.CheckCreate(inst.GetPhysDev());
402
403 for (const auto& f : functions) {
404 ASSERT_NE(nullptr, dev->vkGetDeviceProcAddr(dev.dev, f));
405 }
406 }
407 { // doesn't enable the feature
408 InstWrapper inst{env.vulkan_functions};
409 inst.create_info.set_api_version(1, 1, 0);
410 inst.CheckCreate();
411
412 DeviceWrapper dev{inst};
413 dev.create_info.add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME);
414 dev.CheckCreate(inst.GetPhysDev());
415
416 for (const auto& f : functions) {
417 ASSERT_NE(nullptr, dev->vkGetDeviceProcAddr(dev.dev, f));
418 }
419 }
420 { // enables the feature and extension
421 InstWrapper inst{env.vulkan_functions};
422 inst.create_info.set_api_version(1, 1, 0);
423 inst.CheckCreate();
424
425 VkPhysicalDeviceMaintenance5FeaturesKHR features{};
426 features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_5_FEATURES_KHR;
427 features.maintenance5 = VK_TRUE;
428
429 DeviceWrapper dev{inst};
430 dev.create_info.add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME);
431 dev.create_info.dev.pNext = &features;
432 dev.CheckCreate(inst.GetPhysDev());
433
434 for (const auto& f : functions) {
435 ASSERT_EQ(nullptr, dev->vkGetDeviceProcAddr(dev.dev, f));
436 }
437 }
438 }
439
TEST(GetDeviceProcAddr,AppQueries13FunctionsWhileOnlyEnabling12)440 TEST(GetDeviceProcAddr, AppQueries13FunctionsWhileOnlyEnabling12) {
441 FrameworkEnvironment env{};
442 auto& driver =
443 env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2, VK_API_VERSION_1_3))
444 .set_icd_api_version(VK_API_VERSION_1_3)
445 .add_physical_device(
446 PhysicalDevice{}.set_api_version(VK_API_VERSION_1_3).add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME).finish());
447 std::vector<const char*> functions = {"vkCreatePrivateDataSlot", "vkGetDeviceBufferMemoryRequirements", "vkCmdWaitEvents2",
448 "vkGetDeviceImageSparseMemoryRequirements"};
449
450 for (const auto& f : functions) {
451 driver.physical_devices.back().add_device_function(VulkanFunction{f, [] {}});
452 }
453 { // doesn't enable the feature or extension
454 InstWrapper inst{env.vulkan_functions};
455 inst.create_info.set_api_version(1, 2, 0);
456 inst.CheckCreate();
457
458 DeviceWrapper dev{inst};
459 dev.CheckCreate(inst.GetPhysDev());
460
461 for (const auto& f : functions) {
462 ASSERT_NE(nullptr, dev->vkGetDeviceProcAddr(dev.dev, f));
463 }
464 }
465 { // doesn't enable the feature
466 InstWrapper inst{env.vulkan_functions};
467 inst.create_info.set_api_version(1, 2, 0);
468 inst.CheckCreate();
469
470 DeviceWrapper dev{inst};
471 dev.create_info.add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME);
472 dev.CheckCreate(inst.GetPhysDev());
473
474 for (const auto& f : functions) {
475 ASSERT_NE(nullptr, dev->vkGetDeviceProcAddr(dev.dev, f));
476 }
477 }
478 { // enables the feature and extension
479 InstWrapper inst{env.vulkan_functions};
480 inst.create_info.set_api_version(1, 2, 0);
481 inst.CheckCreate();
482
483 VkPhysicalDeviceMaintenance5FeaturesKHR features{};
484 features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_5_FEATURES_KHR;
485 features.maintenance5 = VK_TRUE;
486
487 DeviceWrapper dev{inst};
488 dev.create_info.add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME);
489 dev.create_info.dev.pNext = &features;
490 dev.CheckCreate(inst.GetPhysDev());
491
492 for (const auto& f : functions) {
493 ASSERT_EQ(nullptr, dev->vkGetDeviceProcAddr(dev.dev, f));
494 }
495 }
496 }
497