• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 The Khronos Group Inc.
3  * Copyright (c) 2022 Valve Corporation
4  * Copyright (c) 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 /*
31  * Tests to see if drivers return vkCmdBeginRenderingKHR as an unknown device or physical device extension
32  * If it is returned as a physical device extension, this test should crash. Otherwise it should work just fine.
33  */
34 
main()35 int main() {
36     VulkanFunctions vk_funcs{};
37 
38     InstWrapper inst(vk_funcs);
39     inst.CheckCreate();
40     auto phys_devs = inst.GetPhysDevs();
41 
42     for (const auto& phys_dev : phys_devs) {
43         uint32_t count = 0;
44         VkResult res = vk_funcs.vkEnumerateDeviceExtensionProperties(phys_dev, nullptr, &count, nullptr);
45         if (res != VK_SUCCESS) {
46             std::cout << "Failed to query device extension count\n";
47         }
48         std::vector<VkExtensionProperties> extensions{count};
49         res = vk_funcs.vkEnumerateDeviceExtensionProperties(phys_dev, nullptr, &count, extensions.data());
50         if (res != VK_SUCCESS) {
51             std::cout << "Failed to query device extensions\n";
52         }
53 
54         bool has_dynamic_rendering = false;
55         for (const auto& ext : extensions) {
56             if (string_eq("VK_KHR_dynamic_rendering", ext.extensionName)) {
57                 has_dynamic_rendering = true;
58                 break;
59             }
60         }
61         if (has_dynamic_rendering) {
62             DeviceWrapper dev(inst);
63             dev.create_info.add_extension("VK_KHR_dynamic_rendering");
64             dev.CheckCreate(phys_dev);
65 
66             DeviceFunctions funcs{vk_funcs, dev};
67             VkCommandPool command_pool;
68             VkCommandPoolCreateInfo pool_create_info{};
69             pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
70             funcs.vkCreateCommandPool(dev, &pool_create_info, nullptr, &command_pool);
71             VkCommandBuffer command_buffer;
72             VkCommandBufferAllocateInfo alloc_info{};
73             alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
74             alloc_info.commandBufferCount = 1;
75             alloc_info.commandPool = command_pool;
76             funcs.vkAllocateCommandBuffers(dev, &alloc_info, &command_buffer);
77             PFN_vkBeginCommandBuffer vkBeginCommandBuffer =
78                 reinterpret_cast<PFN_vkBeginCommandBuffer>(vk_funcs.vkGetInstanceProcAddr(inst.inst, "vkBeginCommandBuffer"));
79             VkCommandBufferBeginInfo begin_info{};
80             begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
81             res = vkBeginCommandBuffer(command_buffer, &begin_info);
82             if (res != VK_SUCCESS) {
83                 std::cout << "Failed to begin command buffer\n";
84             }
85 
86             // call the dynamic rendering function -- should not go into the physical device function trampoline.
87             PFN_vkCmdBeginRenderingKHR vkCmdBeginRenderingKHR =
88                 reinterpret_cast<PFN_vkCmdBeginRenderingKHR>(vk_funcs.vkGetInstanceProcAddr(inst.inst, "vkCmdBeginRenderingKHR"));
89             VkRenderingInfoKHR rendering_info{};
90             rendering_info.sType = VK_STRUCTURE_TYPE_RENDERING_INFO_KHR;
91             vkCmdBeginRenderingKHR(command_buffer, &rendering_info);
92         }
93     }
94 }
95