Skip to content

Commit ac94112

Browse files
Cleanup BUILDER_VALUE macros in tests
Changes BUILDER_VALUE & BUILDER_VECTOR to deduce the return type, so the class name doesn't need to be given. Changes BUILDER_VALUE to default everything with {}, and adds BUILDER_VALUE_WITH_DEFAULT for the places that want a specific default value instead.
1 parent 322d634 commit ac94112

File tree

5 files changed

+203
-204
lines changed

5 files changed

+203
-204
lines changed

tests/framework/icd/test_icd.h

+52-52
Original file line numberDiff line numberDiff line change
@@ -79,39 +79,39 @@ struct PhysicalDevice {
7979
PhysicalDevice(const char* name) : deviceName(name) {}
8080

8181
DispatchableHandle<VkPhysicalDevice> vk_physical_device;
82-
BUILDER_VALUE(PhysicalDevice, std::string, deviceName, "")
83-
BUILDER_VALUE(PhysicalDevice, VkPhysicalDeviceProperties, properties, {})
84-
BUILDER_VALUE(PhysicalDevice, VkPhysicalDeviceFeatures, features, {})
85-
BUILDER_VALUE(PhysicalDevice, VkPhysicalDeviceMemoryProperties, memory_properties, {})
86-
BUILDER_VALUE(PhysicalDevice, VkImageFormatProperties, image_format_properties, {})
87-
BUILDER_VALUE(PhysicalDevice, VkExternalMemoryProperties, external_memory_properties, {})
88-
BUILDER_VALUE(PhysicalDevice, VkExternalSemaphoreProperties, external_semaphore_properties, {})
89-
BUILDER_VALUE(PhysicalDevice, VkExternalFenceProperties, external_fence_properties, {})
90-
BUILDER_VALUE(PhysicalDevice, uint32_t, pci_bus, {})
91-
92-
BUILDER_VECTOR(PhysicalDevice, MockQueueFamilyProperties, queue_family_properties, queue_family_properties)
93-
BUILDER_VECTOR(PhysicalDevice, VkFormatProperties, format_properties, format_properties)
94-
BUILDER_VECTOR(PhysicalDevice, VkSparseImageFormatProperties, sparse_image_format_properties, sparse_image_format_properties)
95-
96-
BUILDER_VECTOR(PhysicalDevice, Extension, extensions, extension)
97-
98-
BUILDER_VALUE(PhysicalDevice, VkSurfaceCapabilitiesKHR, surface_capabilities, {})
99-
BUILDER_VECTOR(PhysicalDevice, VkSurfaceFormatKHR, surface_formats, surface_format)
100-
BUILDER_VECTOR(PhysicalDevice, VkPresentModeKHR, surface_present_modes, surface_present_mode)
101-
BUILDER_VALUE(PhysicalDevice, VkSurfacePresentScalingCapabilitiesEXT, surface_present_scaling_capabilities, {})
82+
BUILDER_VALUE(std::string, deviceName)
83+
BUILDER_VALUE(VkPhysicalDeviceProperties, properties)
84+
BUILDER_VALUE(VkPhysicalDeviceFeatures, features)
85+
BUILDER_VALUE(VkPhysicalDeviceMemoryProperties, memory_properties)
86+
BUILDER_VALUE(VkImageFormatProperties, image_format_properties)
87+
BUILDER_VALUE(VkExternalMemoryProperties, external_memory_properties)
88+
BUILDER_VALUE(VkExternalSemaphoreProperties, external_semaphore_properties)
89+
BUILDER_VALUE(VkExternalFenceProperties, external_fence_properties)
90+
BUILDER_VALUE(uint32_t, pci_bus)
91+
92+
BUILDER_VECTOR(MockQueueFamilyProperties, queue_family_properties, queue_family_properties)
93+
BUILDER_VECTOR(VkFormatProperties, format_properties, format_properties)
94+
BUILDER_VECTOR(VkSparseImageFormatProperties, sparse_image_format_properties, sparse_image_format_properties)
95+
96+
BUILDER_VECTOR(Extension, extensions, extension)
97+
98+
BUILDER_VALUE(VkSurfaceCapabilitiesKHR, surface_capabilities)
99+
BUILDER_VECTOR(VkSurfaceFormatKHR, surface_formats, surface_format)
100+
BUILDER_VECTOR(VkPresentModeKHR, surface_present_modes, surface_present_mode)
101+
BUILDER_VALUE(VkSurfacePresentScalingCapabilitiesEXT, surface_present_scaling_capabilities)
102102
// No good way to make this a builder value. Each std::vector<VkPresentModeKHR> corresponds to each surface_present_modes
103103
// element
104104
std::vector<std::vector<VkPresentModeKHR>> surface_present_mode_compatibility{};
105105

106-
BUILDER_VECTOR(PhysicalDevice, VkDisplayPropertiesKHR, display_properties, display_properties)
107-
BUILDER_VECTOR(PhysicalDevice, VkDisplayPlanePropertiesKHR, display_plane_properties, display_plane_properties)
108-
BUILDER_VECTOR(PhysicalDevice, VkDisplayKHR, displays, displays)
109-
BUILDER_VECTOR(PhysicalDevice, VkDisplayModePropertiesKHR, display_mode_properties, display_mode_properties)
110-
BUILDER_VALUE(PhysicalDevice, VkDisplayModeKHR, display_mode, {})
111-
BUILDER_VALUE(PhysicalDevice, VkDisplayPlaneCapabilitiesKHR, display_plane_capabilities, {})
106+
BUILDER_VECTOR(VkDisplayPropertiesKHR, display_properties, display_properties)
107+
BUILDER_VECTOR(VkDisplayPlanePropertiesKHR, display_plane_properties, display_plane_properties)
108+
BUILDER_VECTOR(VkDisplayKHR, displays, displays)
109+
BUILDER_VECTOR(VkDisplayModePropertiesKHR, display_mode_properties, display_mode_properties)
110+
BUILDER_VALUE(VkDisplayModeKHR, display_mode)
111+
BUILDER_VALUE(VkDisplayPlaneCapabilitiesKHR, display_plane_capabilities)
112112

113-
BUILDER_VALUE(PhysicalDevice, VkLayeredDriverUnderlyingApiMSFT, layered_driver_underlying_api,
114-
VK_LAYERED_DRIVER_UNDERLYING_API_NONE_MSFT)
113+
BUILDER_VALUE_WITH_DEFAULT(VkLayeredDriverUnderlyingApiMSFT, layered_driver_underlying_api,
114+
VK_LAYERED_DRIVER_UNDERLYING_API_NONE_MSFT)
115115

116116
PhysicalDevice& set_api_version(uint32_t version) {
117117
properties.apiVersion = version;
@@ -128,12 +128,12 @@ struct PhysicalDevice {
128128
// Unknown physical device functions. Add a `VulkanFunction` to this list which will be searched in
129129
// vkGetInstanceProcAddr for custom_instance_functions and vk_icdGetPhysicalDeviceProcAddr for custom_physical_device_functions.
130130
// To add unknown device functions, add it to the PhysicalDevice directly (in the known_device_functions member)
131-
BUILDER_VECTOR(PhysicalDevice, VulkanFunction, custom_physical_device_functions, custom_physical_device_function)
131+
BUILDER_VECTOR(VulkanFunction, custom_physical_device_functions, custom_physical_device_function)
132132

133133
// List of function names which are 'known' to the physical device but have test defined implementations
134134
// The purpose of this list is so that vkGetDeviceProcAddr returns 'a real function pointer' in tests
135135
// without actually implementing any of the logic inside of it.
136-
BUILDER_VECTOR(PhysicalDevice, VulkanFunction, known_device_functions, device_function)
136+
BUILDER_VECTOR(VulkanFunction, known_device_functions, device_function)
137137
};
138138

139139
struct PhysicalDeviceGroup {
@@ -154,25 +154,25 @@ struct PhysicalDeviceGroup {
154154
struct TestICD {
155155
std::filesystem::path manifest_file_path;
156156

157-
BUILDER_VALUE(TestICD, bool, exposes_vk_icdNegotiateLoaderICDInterfaceVersion, true)
158-
BUILDER_VALUE(TestICD, bool, exposes_vkEnumerateInstanceExtensionProperties, true)
159-
BUILDER_VALUE(TestICD, bool, exposes_vkCreateInstance, true)
160-
BUILDER_VALUE(TestICD, bool, exposes_vk_icdGetPhysicalDeviceProcAddr, true)
157+
BUILDER_VALUE_WITH_DEFAULT(bool, exposes_vk_icdNegotiateLoaderICDInterfaceVersion, true)
158+
BUILDER_VALUE_WITH_DEFAULT(bool, exposes_vkEnumerateInstanceExtensionProperties, true)
159+
BUILDER_VALUE_WITH_DEFAULT(bool, exposes_vkCreateInstance, true)
160+
BUILDER_VALUE_WITH_DEFAULT(bool, exposes_vk_icdGetPhysicalDeviceProcAddr, true)
161161
#if defined(WIN32)
162-
BUILDER_VALUE(TestICD, bool, exposes_vk_icdEnumerateAdapterPhysicalDevices, true)
162+
BUILDER_VALUE_WITH_DEFAULT(bool, exposes_vk_icdEnumerateAdapterPhysicalDevices, true)
163163
#endif
164164

165165
CalledICDGIPA called_vk_icd_gipa = CalledICDGIPA::not_called;
166166
CalledNegotiateInterface called_negotiate_interface = CalledNegotiateInterface::not_called;
167167

168168
InterfaceVersionCheck interface_version_check = InterfaceVersionCheck::not_called;
169-
BUILDER_VALUE(TestICD, uint32_t, min_icd_interface_version, 0)
170-
BUILDER_VALUE(TestICD, uint32_t, max_icd_interface_version, 7)
169+
BUILDER_VALUE_WITH_DEFAULT(uint32_t, min_icd_interface_version, 0)
170+
BUILDER_VALUE_WITH_DEFAULT(uint32_t, max_icd_interface_version, 7)
171171
uint32_t icd_interface_version_received = 0;
172172

173173
bool called_enumerate_adapter_physical_devices = false;
174174

175-
BUILDER_VALUE(TestICD, bool, enable_icd_wsi, false);
175+
BUILDER_VALUE(bool, enable_icd_wsi);
176176
bool is_using_icd_wsi = false;
177177

178178
TestICD& setup_WSI(const char* api_selection = nullptr) {
@@ -182,14 +182,14 @@ struct TestICD {
182182
return *this;
183183
}
184184

185-
BUILDER_VALUE(TestICD, uint32_t, icd_api_version, VK_API_VERSION_1_0)
186-
BUILDER_VECTOR(TestICD, LayerDefinition, instance_layers, instance_layer)
187-
BUILDER_VECTOR(TestICD, Extension, instance_extensions, instance_extension)
185+
BUILDER_VALUE_WITH_DEFAULT(uint32_t, icd_api_version, VK_API_VERSION_1_0)
186+
BUILDER_VECTOR(LayerDefinition, instance_layers, instance_layer)
187+
BUILDER_VECTOR(Extension, instance_extensions, instance_extension)
188188
std::vector<Extension> enabled_instance_extensions;
189189

190-
BUILDER_VECTOR_MOVE_ONLY(TestICD, PhysicalDevice, physical_devices, physical_device);
190+
BUILDER_VECTOR_MOVE_ONLY(PhysicalDevice, physical_devices, physical_device);
191191

192-
BUILDER_VECTOR(TestICD, PhysicalDeviceGroup, physical_device_groups, physical_device_group);
192+
BUILDER_VECTOR(PhysicalDeviceGroup, physical_device_groups, physical_device_group);
193193

194194
DispatchableHandle<VkInstance> instance_handle;
195195
std::vector<DispatchableHandle<VkDevice>> device_handles;
@@ -198,27 +198,27 @@ struct TestICD {
198198
std::vector<uint64_t> callback_handles;
199199
std::vector<uint64_t> swapchain_handles;
200200

201-
BUILDER_VALUE(TestICD, bool, can_query_vkEnumerateInstanceVersion, true);
202-
BUILDER_VALUE(TestICD, bool, can_query_GetPhysicalDeviceFuncs, true);
201+
BUILDER_VALUE_WITH_DEFAULT(bool, can_query_vkEnumerateInstanceVersion, true);
202+
BUILDER_VALUE_WITH_DEFAULT(bool, can_query_GetPhysicalDeviceFuncs, true);
203203

204204
// Unknown instance functions Add a `VulkanFunction` to this list which will be searched in
205205
// vkGetInstanceProcAddr for custom_instance_functions and vk_icdGetPhysicalDeviceProcAddr for
206206
// custom_physical_device_functions. To add unknown device functions, add it to the PhysicalDevice directly (in the
207207
// known_device_functions member)
208-
BUILDER_VECTOR(TestICD, VulkanFunction, custom_instance_functions, custom_instance_function)
208+
BUILDER_VECTOR(VulkanFunction, custom_instance_functions, custom_instance_function)
209209

210210
// Must explicitely state support for the tooling info extension, that way we can control if vkGetInstanceProcAddr returns a
211211
// function pointer for vkGetPhysicalDeviceToolPropertiesEXT or vkGetPhysicalDeviceToolProperties (core version)
212-
BUILDER_VALUE(TestICD, bool, supports_tooling_info_ext, false);
213-
BUILDER_VALUE(TestICD, bool, supports_tooling_info_core, false);
212+
BUILDER_VALUE(bool, supports_tooling_info_ext);
213+
BUILDER_VALUE(bool, supports_tooling_info_core);
214214
// List of tooling properties that this driver 'supports'
215-
BUILDER_VECTOR(TestICD, VkPhysicalDeviceToolPropertiesEXT, tooling_properties, tooling_property)
215+
BUILDER_VECTOR(VkPhysicalDeviceToolPropertiesEXT, tooling_properties, tooling_property)
216216
std::vector<DispatchableHandle<VkCommandBuffer>> allocated_command_buffers;
217217

218218
VkInstanceCreateFlags passed_in_instance_create_flags{};
219219

220-
BUILDER_VALUE(TestICD, VkResult, enum_physical_devices_return_code, VK_SUCCESS);
221-
BUILDER_VALUE(TestICD, VkResult, enum_adapter_physical_devices_return_code, VK_SUCCESS);
220+
BUILDER_VALUE_WITH_DEFAULT(VkResult, enum_physical_devices_return_code, VK_SUCCESS);
221+
BUILDER_VALUE_WITH_DEFAULT(VkResult, enum_adapter_physical_devices_return_code, VK_SUCCESS);
222222

223223
PhysicalDevice& GetPhysDevice(VkPhysicalDevice physicalDevice) {
224224
for (auto& phys_dev : physical_devices) {
@@ -258,7 +258,7 @@ struct TestICD {
258258
}
259259

260260
#if defined(WIN32)
261-
BUILDER_VALUE(TestICD, LUID, adapterLUID, {})
261+
BUILDER_VALUE(LUID, adapterLUID)
262262
#endif // defined(WIN32)
263263
};
264264

tests/framework/layer/layer_util.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
#include "test_util.h"
3131

3232
struct LayerDefinition {
33-
BUILDER_VALUE(LayerDefinition, std::string, layerName, {})
34-
BUILDER_VALUE(LayerDefinition, uint32_t, specVersion, VK_API_VERSION_1_0)
35-
BUILDER_VALUE(LayerDefinition, uint32_t, implementationVersion, VK_API_VERSION_1_0)
36-
BUILDER_VALUE(LayerDefinition, std::string, description, {})
37-
BUILDER_VECTOR(LayerDefinition, Extension, extensions, extension)
33+
BUILDER_VALUE(std::string, layerName)
34+
BUILDER_VALUE_WITH_DEFAULT(uint32_t, specVersion, VK_API_VERSION_1_0)
35+
BUILDER_VALUE_WITH_DEFAULT(uint32_t, implementationVersion, VK_API_VERSION_1_0)
36+
BUILDER_VALUE(std::string, description)
37+
BUILDER_VECTOR(Extension, extensions, extension)
3838

3939
VkLayerProperties get() const noexcept {
4040
VkLayerProperties props{};

0 commit comments

Comments
 (0)