SwapchainBuilder: Remove use_default_min_image_count(), introduce BufferMode enum

This commit is contained in:
Yoan Lecoq 2022-05-19 20:01:13 +02:00 committed by Charles Giessen
parent f528fe33d6
commit 78ee4e67cd
2 changed files with 10 additions and 12 deletions

View File

@ -1776,7 +1776,7 @@ detail::Result<Swapchain> SwapchainBuilder::build() const {
uint32_t image_count;
if (info.min_image_count == 0) {
image_count = surface_support.capabilities.minImageCount + info.add_to_min_image_count;
image_count = surface_support.capabilities.minImageCount + 1; // This has been the default behavior so far.
} else {
image_count = info.min_image_count;
if (image_count < surface_support.capabilities.minImageCount)
@ -1982,12 +1982,6 @@ SwapchainBuilder& SwapchainBuilder::set_image_array_layer_count(uint32_t array_l
}
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) {
info.min_image_count = 0;
info.add_to_min_image_count = add_to_min_image_count;
return *this;
}
SwapchainBuilder& SwapchainBuilder::set_clipped(bool clipped) {

View File

@ -846,12 +846,17 @@ class SwapchainBuilder {
// Set the number of views in for multiview/stereo surface
SwapchainBuilder& set_image_array_layer_count(uint32_t array_layer_count);
// Convenient named constants for passing to set_desired_min_image_count().
// Note that it is not an `enum class`, so its constants can be passed as an integer value without casting (in other words, these might as well be `static const int`, but they benefit from being grouped together this way).
enum BufferMode {
SINGLE_BUFFERING = 1,
DOUBLE_BUFFERING = 2,
TRIPLE_BUFFERING = 3,
};
// Sets the desired minimum image count for the swapchain. Note that the presentation engine is always free to create more images than requested.
// You may pass one of the values specified in the BufferMode enum, or any integer value.
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.
@ -892,7 +897,6 @@ class SwapchainBuilder {
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;