vk_device: Make use of designated initializers where applicable

Avoids redundant repetitions of variable names, and allows assignment
all in one statement.
This commit is contained in:
Lioncash 2020-07-13 17:27:05 -04:00
parent b2305dcee0
commit 0f8b977663

View file

@ -22,14 +22,21 @@ namespace {
namespace Alternatives { namespace Alternatives {
constexpr std::array Depth24UnormS8_UINT = {VK_FORMAT_D32_SFLOAT_S8_UINT, constexpr std::array Depth24UnormS8_UINT{
VK_FORMAT_D16_UNORM_S8_UINT, VkFormat{}}; VK_FORMAT_D32_SFLOAT_S8_UINT,
constexpr std::array Depth16UnormS8_UINT = {VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D16_UNORM_S8_UINT,
VK_FORMAT_D32_SFLOAT_S8_UINT, VkFormat{}}; VkFormat{},
};
constexpr std::array Depth16UnormS8_UINT{
VK_FORMAT_D24_UNORM_S8_UINT,
VK_FORMAT_D32_SFLOAT_S8_UINT,
VkFormat{},
};
} // namespace Alternatives } // namespace Alternatives
constexpr std::array REQUIRED_EXTENSIONS = { constexpr std::array REQUIRED_EXTENSIONS{
VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_SWAPCHAIN_EXTENSION_NAME,
VK_KHR_16BIT_STORAGE_EXTENSION_NAME, VK_KHR_16BIT_STORAGE_EXTENSION_NAME,
VK_KHR_8BIT_STORAGE_EXTENSION_NAME, VK_KHR_8BIT_STORAGE_EXTENSION_NAME,
@ -169,97 +176,104 @@ bool VKDevice::Create() {
const auto queue_cis = GetDeviceQueueCreateInfos(); const auto queue_cis = GetDeviceQueueCreateInfos();
const std::vector extensions = LoadExtensions(); const std::vector extensions = LoadExtensions();
VkPhysicalDeviceFeatures2 features2; VkPhysicalDeviceFeatures2 features2{
features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
features2.pNext = nullptr; .pNext = nullptr,
};
const void* first_next = &features2; const void* first_next = &features2;
void** next = &features2.pNext; void** next = &features2.pNext;
auto& features = features2.features; features2.features = {
features.robustBufferAccess = false; .robustBufferAccess = false,
features.fullDrawIndexUint32 = false; .fullDrawIndexUint32 = false,
features.imageCubeArray = false; .imageCubeArray = false,
features.independentBlend = true; .independentBlend = true,
features.geometryShader = true; .geometryShader = true,
features.tessellationShader = true; .tessellationShader = true,
features.sampleRateShading = false; .sampleRateShading = false,
features.dualSrcBlend = false; .dualSrcBlend = false,
features.logicOp = false; .logicOp = false,
features.multiDrawIndirect = false; .multiDrawIndirect = false,
features.drawIndirectFirstInstance = false; .drawIndirectFirstInstance = false,
features.depthClamp = true; .depthClamp = true,
features.depthBiasClamp = true; .depthBiasClamp = true,
features.fillModeNonSolid = false; .fillModeNonSolid = false,
features.depthBounds = false; .depthBounds = false,
features.wideLines = false; .wideLines = false,
features.largePoints = true; .largePoints = true,
features.alphaToOne = false; .alphaToOne = false,
features.multiViewport = true; .multiViewport = true,
features.samplerAnisotropy = true; .samplerAnisotropy = true,
features.textureCompressionETC2 = false; .textureCompressionETC2 = false,
features.textureCompressionASTC_LDR = is_optimal_astc_supported; .textureCompressionASTC_LDR = is_optimal_astc_supported,
features.textureCompressionBC = false; .textureCompressionBC = false,
features.occlusionQueryPrecise = true; .occlusionQueryPrecise = true,
features.pipelineStatisticsQuery = false; .pipelineStatisticsQuery = false,
features.vertexPipelineStoresAndAtomics = true; .vertexPipelineStoresAndAtomics = true,
features.fragmentStoresAndAtomics = true; .fragmentStoresAndAtomics = true,
features.shaderTessellationAndGeometryPointSize = false; .shaderTessellationAndGeometryPointSize = false,
features.shaderImageGatherExtended = true; .shaderImageGatherExtended = true,
features.shaderStorageImageExtendedFormats = false; .shaderStorageImageExtendedFormats = false,
features.shaderStorageImageMultisample = false; .shaderStorageImageMultisample = false,
features.shaderStorageImageReadWithoutFormat = is_formatless_image_load_supported; .shaderStorageImageReadWithoutFormat = is_formatless_image_load_supported,
features.shaderStorageImageWriteWithoutFormat = true; .shaderStorageImageWriteWithoutFormat = true,
features.shaderUniformBufferArrayDynamicIndexing = false; .shaderUniformBufferArrayDynamicIndexing = false,
features.shaderSampledImageArrayDynamicIndexing = false; .shaderSampledImageArrayDynamicIndexing = false,
features.shaderStorageBufferArrayDynamicIndexing = false; .shaderStorageBufferArrayDynamicIndexing = false,
features.shaderStorageImageArrayDynamicIndexing = false; .shaderStorageImageArrayDynamicIndexing = false,
features.shaderClipDistance = false; .shaderClipDistance = false,
features.shaderCullDistance = false; .shaderCullDistance = false,
features.shaderFloat64 = false; .shaderFloat64 = false,
features.shaderInt64 = false; .shaderInt64 = false,
features.shaderInt16 = false; .shaderInt16 = false,
features.shaderResourceResidency = false; .shaderResourceResidency = false,
features.shaderResourceMinLod = false; .shaderResourceMinLod = false,
features.sparseBinding = false; .sparseBinding = false,
features.sparseResidencyBuffer = false; .sparseResidencyBuffer = false,
features.sparseResidencyImage2D = false; .sparseResidencyImage2D = false,
features.sparseResidencyImage3D = false; .sparseResidencyImage3D = false,
features.sparseResidency2Samples = false; .sparseResidency2Samples = false,
features.sparseResidency4Samples = false; .sparseResidency4Samples = false,
features.sparseResidency8Samples = false; .sparseResidency8Samples = false,
features.sparseResidency16Samples = false; .sparseResidency16Samples = false,
features.sparseResidencyAliased = false; .sparseResidencyAliased = false,
features.variableMultisampleRate = false; .variableMultisampleRate = false,
features.inheritedQueries = false; .inheritedQueries = false,
};
VkPhysicalDevice16BitStorageFeaturesKHR bit16_storage; VkPhysicalDevice16BitStorageFeaturesKHR bit16_storage{
bit16_storage.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR; .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR,
bit16_storage.pNext = nullptr; .pNext = nullptr,
bit16_storage.storageBuffer16BitAccess = false; .storageBuffer16BitAccess = false,
bit16_storage.uniformAndStorageBuffer16BitAccess = true; .uniformAndStorageBuffer16BitAccess = true,
bit16_storage.storagePushConstant16 = false; .storagePushConstant16 = false,
bit16_storage.storageInputOutput16 = false; .storageInputOutput16 = false,
};
SetNext(next, bit16_storage); SetNext(next, bit16_storage);
VkPhysicalDevice8BitStorageFeaturesKHR bit8_storage; VkPhysicalDevice8BitStorageFeaturesKHR bit8_storage{
bit8_storage.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR; .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR,
bit8_storage.pNext = nullptr; .pNext = nullptr,
bit8_storage.storageBuffer8BitAccess = false; .storageBuffer8BitAccess = false,
bit8_storage.uniformAndStorageBuffer8BitAccess = true; .uniformAndStorageBuffer8BitAccess = true,
bit8_storage.storagePushConstant8 = false; .storagePushConstant8 = false,
};
SetNext(next, bit8_storage); SetNext(next, bit8_storage);
VkPhysicalDeviceHostQueryResetFeaturesEXT host_query_reset; VkPhysicalDeviceHostQueryResetFeaturesEXT host_query_reset{
host_query_reset.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT; .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT,
host_query_reset.hostQueryReset = true; .hostQueryReset = true,
};
SetNext(next, host_query_reset); SetNext(next, host_query_reset);
VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8; VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8;
if (is_float16_supported) { if (is_float16_supported) {
float16_int8.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR; float16_int8 = {
float16_int8.pNext = nullptr; .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR,
float16_int8.shaderFloat16 = true; .pNext = nullptr,
float16_int8.shaderInt8 = false; .shaderFloat16 = true,
.shaderInt8 = false,
};
SetNext(next, float16_int8); SetNext(next, float16_int8);
} else { } else {
LOG_INFO(Render_Vulkan, "Device doesn't support float16 natively"); LOG_INFO(Render_Vulkan, "Device doesn't support float16 natively");
@ -271,10 +285,11 @@ bool VKDevice::Create() {
VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR std430_layout; VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR std430_layout;
if (khr_uniform_buffer_standard_layout) { if (khr_uniform_buffer_standard_layout) {
std430_layout.sType = std430_layout = {
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR; .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR,
std430_layout.pNext = nullptr; .pNext = nullptr,
std430_layout.uniformBufferStandardLayout = true; .uniformBufferStandardLayout = true,
};
SetNext(next, std430_layout); SetNext(next, std430_layout);
} else { } else {
LOG_INFO(Render_Vulkan, "Device doesn't support packed UBOs"); LOG_INFO(Render_Vulkan, "Device doesn't support packed UBOs");
@ -282,9 +297,11 @@ bool VKDevice::Create() {
VkPhysicalDeviceIndexTypeUint8FeaturesEXT index_type_uint8; VkPhysicalDeviceIndexTypeUint8FeaturesEXT index_type_uint8;
if (ext_index_type_uint8) { if (ext_index_type_uint8) {
index_type_uint8.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT; index_type_uint8 = {
index_type_uint8.pNext = nullptr; .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT,
index_type_uint8.indexTypeUint8 = true; .pNext = nullptr,
.indexTypeUint8 = true,
};
SetNext(next, index_type_uint8); SetNext(next, index_type_uint8);
} else { } else {
LOG_INFO(Render_Vulkan, "Device doesn't support uint8 indexes"); LOG_INFO(Render_Vulkan, "Device doesn't support uint8 indexes");
@ -292,11 +309,12 @@ bool VKDevice::Create() {
VkPhysicalDeviceTransformFeedbackFeaturesEXT transform_feedback; VkPhysicalDeviceTransformFeedbackFeaturesEXT transform_feedback;
if (ext_transform_feedback) { if (ext_transform_feedback) {
transform_feedback.sType = transform_feedback = {
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT; .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT,
transform_feedback.pNext = nullptr; .pNext = nullptr,
transform_feedback.transformFeedback = true; .transformFeedback = true,
transform_feedback.geometryStreams = true; .geometryStreams = true,
};
SetNext(next, transform_feedback); SetNext(next, transform_feedback);
} else { } else {
LOG_INFO(Render_Vulkan, "Device doesn't support transform feedbacks"); LOG_INFO(Render_Vulkan, "Device doesn't support transform feedbacks");
@ -304,10 +322,12 @@ bool VKDevice::Create() {
VkPhysicalDeviceCustomBorderColorFeaturesEXT custom_border; VkPhysicalDeviceCustomBorderColorFeaturesEXT custom_border;
if (ext_custom_border_color) { if (ext_custom_border_color) {
custom_border.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT; custom_border = {
custom_border.pNext = nullptr; .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT,
custom_border.customBorderColors = VK_TRUE; .pNext = nullptr,
custom_border.customBorderColorWithoutFormat = VK_TRUE; .customBorderColors = VK_TRUE,
.customBorderColorWithoutFormat = VK_TRUE,
};
SetNext(next, custom_border); SetNext(next, custom_border);
} else { } else {
LOG_INFO(Render_Vulkan, "Device doesn't support custom border colors"); LOG_INFO(Render_Vulkan, "Device doesn't support custom border colors");
@ -315,9 +335,11 @@ bool VKDevice::Create() {
VkPhysicalDeviceExtendedDynamicStateFeaturesEXT dynamic_state; VkPhysicalDeviceExtendedDynamicStateFeaturesEXT dynamic_state;
if (ext_extended_dynamic_state) { if (ext_extended_dynamic_state) {
dynamic_state.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT; dynamic_state = {
dynamic_state.pNext = nullptr; .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT,
dynamic_state.extendedDynamicState = VK_TRUE; .pNext = nullptr,
.extendedDynamicState = VK_TRUE,
};
SetNext(next, dynamic_state); SetNext(next, dynamic_state);
} else { } else {
LOG_INFO(Render_Vulkan, "Device doesn't support extended dynamic state"); LOG_INFO(Render_Vulkan, "Device doesn't support extended dynamic state");
@ -331,11 +353,13 @@ bool VKDevice::Create() {
if (nv_device_diagnostics_config) { if (nv_device_diagnostics_config) {
nsight_aftermath_tracker.Initialize(); nsight_aftermath_tracker.Initialize();
diagnostics_nv.sType = VK_STRUCTURE_TYPE_DEVICE_DIAGNOSTICS_CONFIG_CREATE_INFO_NV; diagnostics_nv = {
diagnostics_nv.pNext = &features2; .sType = VK_STRUCTURE_TYPE_DEVICE_DIAGNOSTICS_CONFIG_CREATE_INFO_NV,
diagnostics_nv.flags = VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_DEBUG_INFO_BIT_NV | .pNext = &features2,
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_RESOURCE_TRACKING_BIT_NV | .flags = VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_DEBUG_INFO_BIT_NV |
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_AUTOMATIC_CHECKPOINTS_BIT_NV; VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_RESOURCE_TRACKING_BIT_NV |
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_AUTOMATIC_CHECKPOINTS_BIT_NV,
};
first_next = &diagnostics_nv; first_next = &diagnostics_nv;
} }
@ -704,13 +728,15 @@ void VKDevice::SetupFeatures() {
} }
void VKDevice::CollectTelemetryParameters() { void VKDevice::CollectTelemetryParameters() {
VkPhysicalDeviceDriverPropertiesKHR driver; VkPhysicalDeviceDriverPropertiesKHR driver{
driver.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR; .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR,
driver.pNext = nullptr; .pNext = nullptr,
};
VkPhysicalDeviceProperties2KHR properties; VkPhysicalDeviceProperties2KHR properties{
properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR; .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR,
properties.pNext = &driver; .pNext = &driver,
};
physical.GetProperties2KHR(properties); physical.GetProperties2KHR(properties);
driver_id = driver.driverID; driver_id = driver.driverID;
@ -719,24 +745,26 @@ void VKDevice::CollectTelemetryParameters() {
const std::vector extensions = physical.EnumerateDeviceExtensionProperties(); const std::vector extensions = physical.EnumerateDeviceExtensionProperties();
reported_extensions.reserve(std::size(extensions)); reported_extensions.reserve(std::size(extensions));
for (const auto& extension : extensions) { for (const auto& extension : extensions) {
reported_extensions.push_back(extension.extensionName); reported_extensions.emplace_back(extension.extensionName);
} }
} }
std::vector<VkDeviceQueueCreateInfo> VKDevice::GetDeviceQueueCreateInfos() const { std::vector<VkDeviceQueueCreateInfo> VKDevice::GetDeviceQueueCreateInfos() const {
static constexpr float QUEUE_PRIORITY = 1.0f; static constexpr float QUEUE_PRIORITY = 1.0f;
std::unordered_set<u32> unique_queue_families = {graphics_family, present_family}; std::unordered_set<u32> unique_queue_families{graphics_family, present_family};
std::vector<VkDeviceQueueCreateInfo> queue_cis; std::vector<VkDeviceQueueCreateInfo> queue_cis;
queue_cis.reserve(unique_queue_families.size());
for (const u32 queue_family : unique_queue_families) { for (const u32 queue_family : unique_queue_families) {
VkDeviceQueueCreateInfo& ci = queue_cis.emplace_back(); queue_cis.push_back({
ci.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
ci.pNext = nullptr; .pNext = nullptr,
ci.flags = 0; .flags = 0,
ci.queueFamilyIndex = queue_family; .queueFamilyIndex = queue_family,
ci.queueCount = 1; .queueCount = 1,
ci.pQueuePriorities = &QUEUE_PRIORITY; .pQueuePriorities = &QUEUE_PRIORITY,
});
} }
return queue_cis; return queue_cis;