mirror of
https://github.com/charles-lunarg/vk-bootstrap.git
synced 2024-11-22 15:24:34 +00:00
SwapchainBuilder: provide some control over minImageCount
This commit is contained in:
parent
f847ab8566
commit
5ac2b21dfe
@ -1774,10 +1774,18 @@ detail::Result<Swapchain> SwapchainBuilder::build() const {
|
||||
return detail::Error{ SwapchainError::failed_query_surface_support_details, surface_support_ret.vk_result() };
|
||||
auto surface_support = surface_support_ret.value();
|
||||
|
||||
uint32_t image_count = surface_support.capabilities.minImageCount + 1;
|
||||
uint32_t image_count;
|
||||
if (info.min_image_count == 0) {
|
||||
image_count = surface_support.capabilities.minImageCount + info.add_to_min_image_count;
|
||||
} else {
|
||||
image_count = info.min_image_count;
|
||||
if (image_count < surface_support.capabilities.minImageCount)
|
||||
image_count = surface_support.capabilities.minImageCount;
|
||||
}
|
||||
if (surface_support.capabilities.maxImageCount > 0 && image_count > surface_support.capabilities.maxImageCount) {
|
||||
image_count = surface_support.capabilities.maxImageCount;
|
||||
}
|
||||
|
||||
VkSurfaceFormatKHR surface_format =
|
||||
detail::find_surface_format(info.physical_device, surface_support.formats, desired_formats, info.format_feature_flags);
|
||||
|
||||
@ -1972,6 +1980,16 @@ SwapchainBuilder& SwapchainBuilder::set_image_array_layer_count(uint32_t array_l
|
||||
info.array_layer_count = array_layer_count;
|
||||
return *this;
|
||||
}
|
||||
SwapchainBuilder& SwapchainBuilder::set_desired_min_image_count(uint32_t min_image_count) {
|
||||
info.min_image_count = min_image_count;
|
||||
info.add_to_min_image_count = 0; // Unnecessary, but let's do it for clarity
|
||||
return *this;
|
||||
}
|
||||
SwapchainBuilder& SwapchainBuilder::use_default_min_image_count(uint32_t add_to_min_image_count = 1) {
|
||||
info.min_image_count = 0;
|
||||
info.add_to_min_image_count = add_to_min_image_count;
|
||||
return *this;
|
||||
}
|
||||
SwapchainBuilder& SwapchainBuilder::set_clipped(bool clipped) {
|
||||
info.clipped = clipped;
|
||||
return *this;
|
||||
|
@ -846,6 +846,13 @@ class SwapchainBuilder {
|
||||
// Set the number of views in for multiview/stereo surface
|
||||
SwapchainBuilder& set_image_array_layer_count(uint32_t array_layer_count);
|
||||
|
||||
// Sets the desired minimum image count for the swapchain. Note that the presentation engine is always free to create more images than requested.
|
||||
SwapchainBuilder& set_desired_min_image_count(uint32_t min_image_count);
|
||||
// Use the default desired minimum image count for the swapchain. The chosen value is calculated as `capabilitites.minImageCount + add_to_min_image_count`.
|
||||
// The default behavior so far was equivalent to setting `add_to_min_image_count` to 1, and generally led to a triple buffering setup.
|
||||
// A discussion of the trade-offs involved between double buffering and triple buffering is available as https://en.wikipedia.org/wiki/Multiple_buffering
|
||||
SwapchainBuilder& use_default_min_image_count(uint32_t add_to_min_image_count = 1);
|
||||
|
||||
// Set whether the Vulkan implementation is allowed to discard rendering operations that
|
||||
// affect regions of the surface that are not visible. Default is true.
|
||||
// Note: Applications should use the default of true if they do not expect to read back the content
|
||||
@ -884,6 +891,8 @@ class SwapchainBuilder {
|
||||
uint32_t desired_width = 256;
|
||||
uint32_t desired_height = 256;
|
||||
uint32_t array_layer_count = 1;
|
||||
uint32_t min_image_count = 0;
|
||||
uint32_t add_to_min_image_count = 1; // Keep in sync with default parameter value in use_default_min_image_count()
|
||||
VkImageUsageFlags image_usage_flags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
VkFormatFeatureFlags format_feature_flags = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
|
||||
uint32_t graphics_queue_index = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user