@ -105,23 +105,23 @@ VkCompositeAlphaFlagBitsKHR ChooseAlphaFlags(const VkSurfaceCapabilitiesKHR& cap
} // Anonymous namespace
} // Anonymous namespace
Swapchain : : Swapchain ( VkSurfaceKHR surface_ , const Device & device_ , Scheduler & scheduler_ ,
Swapchain : : Swapchain ( VkSurfaceKHR_T * surface_handl e_ , const Device & device_ , Scheduler & scheduler_ ,
u32 width_ , u32 height_ )
u32 width_ , u32 height_ )
: surface { surface_ } , device { device_ } , scheduler { scheduler_ } {
Create ( surface_ , width_ , height_ ) ;
: surface_handle { surface_handl e_ } , device { device_ } , scheduler { scheduler_ } {
Create ( surface_handle , width_ , height_ ) ;
}
}
Swapchain : : ~ Swapchain ( ) = default ;
Swapchain : : ~ Swapchain ( ) = default ;
void Swapchain : : Create ( VkSurfaceKHR surface_ , u32 width_ , u32 height_ ) {
void Swapchain : : Create ( VkSurfaceKHR_T * surface_handl e_ , u32 width_ , u32 height_ ) {
is_outdated = false ;
is_outdated = false ;
is_suboptimal = false ;
is_suboptimal = false ;
width = width_ ;
width = width_ ;
height = height_ ;
height = height_ ;
surface = surface_ ;
surface_handle = surface_handl e_ ;
const auto physical_device = device . GetPhysical ( ) ;
const auto physical_device = device . GetPhysical ( ) ;
const auto capabilities { physical_device . GetSurfaceCapabilitiesKHR ( surface ) } ;
const auto capabilities { physical_device . GetSurfaceCapabilitiesKHR ( surface_handle ) } ;
if ( capabilities . maxImageExtent . width = = 0 | | capabilities . maxImageExtent . height = = 0 ) {
if ( capabilities . maxImageExtent . width = = 0 | | capabilities . maxImageExtent . height = = 0 ) {
return ;
return ;
}
}
@ -199,8 +199,8 @@ void Swapchain::Present(VkSemaphore render_semaphore) {
void Swapchain : : CreateSwapchain ( const VkSurfaceCapabilitiesKHR & capabilities ) {
void Swapchain : : CreateSwapchain ( const VkSurfaceCapabilitiesKHR & capabilities ) {
const auto physical_device { device . GetPhysical ( ) } ;
const auto physical_device { device . GetPhysical ( ) } ;
const auto formats { physical_device . GetSurfaceFormatsKHR ( surface ) } ;
const auto present_modes = physical_device . GetSurfacePresentModesKHR ( surface ) ;
const auto formats { physical_device . GetSurfaceFormatsKHR ( surface_handle ) } ;
const auto present_modes = physical_device . GetSurfacePresentModesKHR ( surface_handle ) ;
has_mailbox = std : : find ( present_modes . begin ( ) , present_modes . end ( ) ,
has_mailbox = std : : find ( present_modes . begin ( ) , present_modes . end ( ) ,
VK_PRESENT_MODE_MAILBOX_KHR ) ! = present_modes . end ( ) ;
VK_PRESENT_MODE_MAILBOX_KHR ) ! = present_modes . end ( ) ;
has_imm = std : : find ( present_modes . begin ( ) , present_modes . end ( ) ,
has_imm = std : : find ( present_modes . begin ( ) , present_modes . end ( ) ,
@ -228,7 +228,7 @@ void Swapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities) {
. sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR ,
. sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR ,
. pNext = nullptr ,
. pNext = nullptr ,
. flags = 0 ,
. flags = 0 ,
. surface = surface ,
. surface = surface_handle ,
. minImageCount = requested_image_count ,
. minImageCount = requested_image_count ,
. imageFormat = surface_format . format ,
. imageFormat = surface_format . format ,
. imageColorSpace = surface_format . colorSpace ,
. imageColorSpace = surface_format . colorSpace ,
@ -269,7 +269,7 @@ void Swapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities) {
swapchain_ci . flags | = VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR ;
swapchain_ci . flags | = VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR ;
}
}
// 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.
const auto updated_capabilities = physical_device . GetSurfaceCapabilitiesKHR ( surface ) ;
const auto updated_capabilities = physical_device . GetSurfaceCapabilitiesKHR ( surface_handle ) ;
swapchain_ci . imageExtent = ChooseSwapExtent ( updated_capabilities , width , height ) ;
swapchain_ci . imageExtent = ChooseSwapExtent ( updated_capabilities , width , height ) ;
// Don't add code within this and the swapchain creation.
// Don't add code within this and the swapchain creation.
swapchain = device . GetLogical ( ) . CreateSwapchainKHR ( swapchain_ci ) ;
swapchain = device . GetLogical ( ) . CreateSwapchainKHR ( swapchain_ci ) ;