vk_swapchain: Make use of designated initializers where applicable
This commit is contained in:
parent
3c060503bc
commit
08d36afd40
|
@ -95,15 +95,16 @@ bool VKSwapchain::Present(VkSemaphore render_semaphore, VKFence& fence) {
|
||||||
const auto present_queue{device.GetPresentQueue()};
|
const auto present_queue{device.GetPresentQueue()};
|
||||||
bool recreated = false;
|
bool recreated = false;
|
||||||
|
|
||||||
VkPresentInfoKHR present_info;
|
const VkPresentInfoKHR present_info{
|
||||||
present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
|
||||||
present_info.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
present_info.waitSemaphoreCount = render_semaphore ? 2U : 1U;
|
.waitSemaphoreCount = render_semaphore ? 2U : 1U,
|
||||||
present_info.pWaitSemaphores = semaphores.data();
|
.pWaitSemaphores = semaphores.data(),
|
||||||
present_info.swapchainCount = 1;
|
.swapchainCount = 1,
|
||||||
present_info.pSwapchains = swapchain.address();
|
.pSwapchains = swapchain.address(),
|
||||||
present_info.pImageIndices = &image_index;
|
.pImageIndices = &image_index,
|
||||||
present_info.pResults = nullptr;
|
.pResults = nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
switch (const VkResult result = present_queue.Present(present_info)) {
|
switch (const VkResult result = present_queue.Present(present_info)) {
|
||||||
case VK_SUCCESS:
|
case VK_SUCCESS:
|
||||||
|
@ -147,24 +148,25 @@ void VKSwapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities,
|
||||||
requested_image_count = capabilities.maxImageCount;
|
requested_image_count = capabilities.maxImageCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkSwapchainCreateInfoKHR swapchain_ci;
|
VkSwapchainCreateInfoKHR swapchain_ci{
|
||||||
swapchain_ci.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
|
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
|
||||||
swapchain_ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
swapchain_ci.flags = 0;
|
.flags = 0,
|
||||||
swapchain_ci.surface = surface;
|
.surface = surface,
|
||||||
swapchain_ci.minImageCount = requested_image_count;
|
.minImageCount = requested_image_count,
|
||||||
swapchain_ci.imageFormat = surface_format.format;
|
.imageFormat = surface_format.format,
|
||||||
swapchain_ci.imageColorSpace = surface_format.colorSpace;
|
.imageColorSpace = surface_format.colorSpace,
|
||||||
swapchain_ci.imageArrayLayers = 1;
|
.imageArrayLayers = 1,
|
||||||
swapchain_ci.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
|
||||||
swapchain_ci.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||||
swapchain_ci.queueFamilyIndexCount = 0;
|
.queueFamilyIndexCount = 0,
|
||||||
swapchain_ci.pQueueFamilyIndices = nullptr;
|
.pQueueFamilyIndices = nullptr,
|
||||||
swapchain_ci.preTransform = capabilities.currentTransform;
|
.preTransform = capabilities.currentTransform,
|
||||||
swapchain_ci.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
|
||||||
swapchain_ci.presentMode = present_mode;
|
.presentMode = present_mode,
|
||||||
swapchain_ci.clipped = VK_FALSE;
|
.clipped = VK_FALSE,
|
||||||
swapchain_ci.oldSwapchain = nullptr;
|
.oldSwapchain = nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
const u32 graphics_family{device.GetGraphicsFamily()};
|
const u32 graphics_family{device.GetGraphicsFamily()};
|
||||||
const u32 present_family{device.GetPresentFamily()};
|
const u32 present_family{device.GetPresentFamily()};
|
||||||
|
@ -173,8 +175,6 @@ void VKSwapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities,
|
||||||
swapchain_ci.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
|
swapchain_ci.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
|
||||||
swapchain_ci.queueFamilyIndexCount = static_cast<u32>(queue_indices.size());
|
swapchain_ci.queueFamilyIndexCount = static_cast<u32>(queue_indices.size());
|
||||||
swapchain_ci.pQueueFamilyIndices = queue_indices.data();
|
swapchain_ci.pQueueFamilyIndices = queue_indices.data();
|
||||||
} else {
|
|
||||||
swapchain_ci.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request the size again to reduce the possibility of a TOCTOU race condition.
|
// Request the size again to reduce the possibility of a TOCTOU race condition.
|
||||||
|
@ -200,20 +200,28 @@ void VKSwapchain::CreateSemaphores() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void VKSwapchain::CreateImageViews() {
|
void VKSwapchain::CreateImageViews() {
|
||||||
VkImageViewCreateInfo ci;
|
VkImageViewCreateInfo ci{
|
||||||
ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
||||||
ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
ci.flags = 0;
|
.flags = 0,
|
||||||
// ci.image
|
.viewType = VK_IMAGE_VIEW_TYPE_2D,
|
||||||
ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
.format = image_format,
|
||||||
ci.format = image_format;
|
.components =
|
||||||
ci.components = {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
|
{
|
||||||
VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY};
|
.r = VK_COMPONENT_SWIZZLE_IDENTITY,
|
||||||
ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
.g = VK_COMPONENT_SWIZZLE_IDENTITY,
|
||||||
ci.subresourceRange.baseMipLevel = 0;
|
.b = VK_COMPONENT_SWIZZLE_IDENTITY,
|
||||||
ci.subresourceRange.levelCount = 1;
|
.a = VK_COMPONENT_SWIZZLE_IDENTITY,
|
||||||
ci.subresourceRange.baseArrayLayer = 0;
|
},
|
||||||
ci.subresourceRange.layerCount = 1;
|
.subresourceRange =
|
||||||
|
{
|
||||||
|
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
|
.baseMipLevel = 0,
|
||||||
|
.levelCount = 1,
|
||||||
|
.baseArrayLayer = 0,
|
||||||
|
.layerCount = 1,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
image_views.resize(image_count);
|
image_views.resize(image_count);
|
||||||
for (std::size_t i = 0; i < image_count; i++) {
|
for (std::size_t i = 0; i < image_count; i++) {
|
||||||
|
|
Loading…
Reference in New Issue