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 #pragma once
29 
30 #include "test_util.h"
31 
32 // Move only type because it holds a DispatchableHandle<VkPhysicalDevice>
33 struct PhysicalDevice {
PhysicalDevicePhysicalDevice34     PhysicalDevice() {}
PhysicalDevicePhysicalDevice35     PhysicalDevice(std::string name) : deviceName(name) {}
PhysicalDevicePhysicalDevice36     PhysicalDevice(const char* name) : deviceName(name) {}
37 
38     DispatchableHandle<VkPhysicalDevice> vk_physical_device;
39     BUILDER_VALUE(PhysicalDevice, std::string, deviceName, "")
40     BUILDER_VALUE(PhysicalDevice, VkPhysicalDeviceProperties, properties, {})
41     BUILDER_VALUE(PhysicalDevice, VkPhysicalDeviceFeatures, features, {})
42     BUILDER_VALUE(PhysicalDevice, VkPhysicalDeviceMemoryProperties, memory_properties, {})
43     BUILDER_VALUE(PhysicalDevice, VkImageFormatProperties, image_format_properties, {})
44     BUILDER_VALUE(PhysicalDevice, VkExternalMemoryProperties, external_memory_properties, {})
45     BUILDER_VALUE(PhysicalDevice, VkExternalSemaphoreProperties, external_semaphore_properties, {})
46     BUILDER_VALUE(PhysicalDevice, VkExternalFenceProperties, external_fence_properties, {})
47     BUILDER_VALUE(PhysicalDevice, uint32_t, pci_bus, {})
48 
49     BUILDER_VECTOR(PhysicalDevice, MockQueueFamilyProperties, queue_family_properties, queue_family_properties)
50     BUILDER_VECTOR(PhysicalDevice, VkFormatProperties, format_properties, format_properties)
51     BUILDER_VECTOR(PhysicalDevice, VkSparseImageFormatProperties, sparse_image_format_properties, sparse_image_format_properties)
52 
53     BUILDER_VECTOR(PhysicalDevice, Extension, extensions, extension)
54 
55     BUILDER_VALUE(PhysicalDevice, VkSurfaceCapabilitiesKHR, surface_capabilities, {})
56     BUILDER_VECTOR(PhysicalDevice, VkSurfaceFormatKHR, surface_formats, surface_format)
57     BUILDER_VECTOR(PhysicalDevice, VkPresentModeKHR, surface_present_modes, surface_present_mode)
58 
59     BUILDER_VECTOR(PhysicalDevice, VkDisplayPropertiesKHR, display_properties, display_properties)
60     BUILDER_VECTOR(PhysicalDevice, VkDisplayPlanePropertiesKHR, display_plane_properties, display_plane_properties)
61     BUILDER_VECTOR(PhysicalDevice, VkDisplayKHR, displays, displays)
62     BUILDER_VECTOR(PhysicalDevice, VkDisplayModePropertiesKHR, display_mode_properties, display_mode_properties)
63     BUILDER_VALUE(PhysicalDevice, VkDisplayModeKHR, display_mode, {})
64     BUILDER_VALUE(PhysicalDevice, VkDisplayPlaneCapabilitiesKHR, display_plane_capabilities, {})
65 
66     BUILDER_VALUE(PhysicalDevice, VkLayeredDriverUnderlyingApiMSFT, layered_driver_underlying_api,
67                   VK_LAYERED_DRIVER_UNDERLYING_API_NONE_MSFT)
68 
set_api_versionPhysicalDevice69     PhysicalDevice& set_api_version(uint32_t version) {
70         properties.apiVersion = version;
71         return *this;
72     }
73 
finishPhysicalDevice74     PhysicalDevice&& finish() { return std::move(*this); }
75 
76     // Objects created from this physical device
77     std::vector<VkDevice> device_handles;
78     std::vector<DeviceCreateInfo> device_create_infos;
79     std::vector<DispatchableHandle<VkQueue>> queue_handles;
80 
81     // Unknown physical device functions. Add a `VulkanFunction` to this list which will be searched in
82     // vkGetInstanceProcAddr for custom_instance_functions and vk_icdGetPhysicalDeviceProcAddr for custom_physical_device_functions.
83     // To add unknown device functions, add it to the PhysicalDevice directly (in the known_device_functions member)
84     BUILDER_VECTOR(PhysicalDevice, VulkanFunction, custom_physical_device_functions, custom_physical_device_function)
85 
86     // List of function names which are 'known' to the physical device but have test defined implementations
87     // The purpose of this list is so that vkGetDeviceProcAddr returns 'a real function pointer' in tests
88     // without actually implementing any of the logic inside of it.
89     BUILDER_VECTOR(PhysicalDevice, VulkanFunction, known_device_functions, device_function)
90 };
91 
92 struct PhysicalDeviceGroup {
PhysicalDeviceGroupPhysicalDeviceGroup93     PhysicalDeviceGroup() {}
PhysicalDeviceGroupPhysicalDeviceGroup94     PhysicalDeviceGroup(PhysicalDevice const& physical_device) { physical_device_handles.push_back(&physical_device); }
PhysicalDeviceGroupPhysicalDeviceGroup95     PhysicalDeviceGroup(std::vector<PhysicalDevice*> const& physical_devices) {
96         physical_device_handles.insert(physical_device_handles.end(), physical_devices.begin(), physical_devices.end());
97     }
use_physical_devicePhysicalDeviceGroup98     PhysicalDeviceGroup& use_physical_device(PhysicalDevice const& physical_device) {
99         physical_device_handles.push_back(&physical_device);
100         return *this;
101     }
102 
103     std::vector<PhysicalDevice const*> physical_device_handles;
104     VkBool32 subset_allocation = false;
105 };
106