aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Elliott <ianelliott@google.com>2016-08-19 03:46:58 -0600
committerIan Elliott <ianelliott@google.com>2016-08-29 11:09:13 -0600
commitcf7f7485f065c3f434082bfdb5804242e2683b47 (patch)
tree4567de6d77b5e15736ad748418d2b3facf6be151
parentd297c407d67a5c7f00f26278bd48abd688396527 (diff)
downloadusermoji-cf7f7485f065c3f434082bfdb5804242e2683b47.tar.xz
demos: Update some of the WSI code to match the spec example code
A pending Vulkan spec change contains updates to the WSI example code. This is a coordinated, cosmetic change, that allows the example code and demo code to more-closely match.
-rw-r--r--demos/cube.c45
-rw-r--r--demos/tri.c43
2 files changed, 56 insertions, 32 deletions
diff --git a/demos/cube.c b/demos/cube.c
index a7c5d868..6017444f 100644
--- a/demos/cube.c
+++ b/demos/cube.c
@@ -725,14 +725,13 @@ static void demo_draw(struct demo *demo) {
VkPresentInfoKHR present = {
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
.pNext = NULL,
+ .waitSemaphoreCount = 1,
+ .pWaitSemaphores = &demo->draw_complete_semaphore,
.swapchainCount = 1,
.pSwapchains = &demo->swapchain,
.pImageIndices = &demo->current_buffer,
- .waitSemaphoreCount = 1,
- .pWaitSemaphores = &demo->draw_complete_semaphore,
};
- // TBD/TODO: SHOULD THE "present" PARAMETER BE "const" IN THE HEADER?
err = demo->fpQueuePresentKHR(demo->present_queue, &present);
if (err == VK_ERROR_OUT_OF_DATE_KHR) {
// demo->swapchain is out of date (e.g. the window was resized) and
@@ -768,12 +767,25 @@ static void demo_prepare_buffers(struct demo *demo) {
assert(!err);
VkExtent2D swapchainExtent;
- // width and height are either both -1, or both not -1.
- if (surfCapabilities.currentExtent.width == (uint32_t)-1) {
- // If the surface size is undefined, the size is set to
- // the size of the images requested.
+ // width and height are either both 0xFFFFFFFF, or both not 0xFFFFFFFF.
+ if (surfCapabilities.currentExtent.width == 0xFFFFFFFF) {
+ // If the surface size is undefined, the size is set to the size
+ // of the images requested, which must fit within the minimum and
+ // maximum values.
swapchainExtent.width = demo->width;
swapchainExtent.height = demo->height;
+
+ if (swapchainExtent.width < surfCapabilities.minImageExtent.width) {
+ swapchainExtent.width = surfCapabilities.minImageExtent.width;
+ } else if (swapchainExtent.width > surfCapabilities.maxImageExtent.width) {
+ swapchainExtent.width = surfCapabilities.maxImageExtent.width;
+ }
+
+ if (swapchainExtent.height < surfCapabilities.minImageExtent.height) {
+ swapchainExtent.height = surfCapabilities.minImageExtent.height;
+ } else if (swapchainExtent.height > surfCapabilities.maxImageExtent.height) {
+ swapchainExtent.height = surfCapabilities.maxImageExtent.height;
+ }
} else {
// If the surface size is defined, the swap chain size must match
swapchainExtent = surfCapabilities.currentExtent;
@@ -797,17 +809,16 @@ static void demo_prepare_buffers(struct demo *demo) {
}
}
- // Determine the number of VkImage's to use in the swap chain (we desire to
- // own only 1 image at a time, besides the images being displayed and
- // queued for display):
- uint32_t desiredNumberOfSwapchainImages =
- surfCapabilities.minImageCount + 1;
- // If maxImageCount is 0, we can ask for as many images as we want, otherwise
- // we're limited to maxImageCount
+ // Determine the number of VkImage's to use in the swap chain.
+ // Application desires to only acquire 1 image at a time (which is
+ // "surfCapabilities.minImageCount").
+ uint32_t desiredNumOfSwapchainImages = surfCapabilities.minImageCount;
+ // If maxImageCount is 0, we can ask for as many images as we want;
+ // otherwise we're limited to maxImageCount
if ((surfCapabilities.maxImageCount > 0) &&
- (desiredNumberOfSwapchainImages > surfCapabilities.maxImageCount)) {
+ (desiredNumOfSwapchainImages > surfCapabilities.maxImageCount)) {
// Application must settle for fewer images than desired:
- desiredNumberOfSwapchainImages = surfCapabilities.maxImageCount;
+ desiredNumOfSwapchainImages = surfCapabilities.maxImageCount;
}
VkSurfaceTransformFlagsKHR preTransform;
@@ -822,7 +833,7 @@ static void demo_prepare_buffers(struct demo *demo) {
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
.pNext = NULL,
.surface = demo->surface,
- .minImageCount = desiredNumberOfSwapchainImages,
+ .minImageCount = desiredNumOfSwapchainImages,
.imageFormat = demo->format,
.imageColorSpace = demo->color_space,
.imageExtent =
diff --git a/demos/tri.c b/demos/tri.c
index 9baa23a5..adfef501 100644
--- a/demos/tri.c
+++ b/demos/tri.c
@@ -587,14 +587,13 @@ static void demo_draw(struct demo *demo) {
VkPresentInfoKHR present = {
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
.pNext = NULL,
+ .waitSemaphoreCount = 1,
+ .pWaitSemaphores = &drawCompleteSemaphore,
.swapchainCount = 1,
.pSwapchains = &demo->swapchain,
.pImageIndices = &demo->current_buffer,
- .waitSemaphoreCount = 1,
- .pWaitSemaphores = &drawCompleteSemaphore,
};
- // TBD/TODO: SHOULD THE "present" PARAMETER BE "const" IN THE HEADER?
err = demo->fpQueuePresentKHR(demo->queue, &present);
if (err == VK_ERROR_OUT_OF_DATE_KHR) {
// demo->swapchain is out of date (e.g. the window was resized) and
@@ -636,12 +635,25 @@ static void demo_prepare_buffers(struct demo *demo) {
assert(!err);
VkExtent2D swapchainExtent;
- // width and height are either both -1, or both not -1.
- if (surfCapabilities.currentExtent.width == (uint32_t)-1) {
- // If the surface size is undefined, the size is set to
- // the size of the images requested.
+ // width and height are either both 0xFFFFFFFF, or both not 0xFFFFFFFF.
+ if (surfCapabilities.currentExtent.width == 0xFFFFFFFF) {
+ // If the surface size is undefined, the size is set to the size
+ // of the images requested, which must fit within the minimum and
+ // maximum values.
swapchainExtent.width = demo->width;
swapchainExtent.height = demo->height;
+
+ if (swapchainExtent.width < surfCapabilities.minImageExtent.width) {
+ swapchainExtent.width = surfCapabilities.minImageExtent.width;
+ } else if (swapchainExtent.width > surfCapabilities.maxImageExtent.width) {
+ swapchainExtent.width = surfCapabilities.maxImageExtent.width;
+ }
+
+ if (swapchainExtent.height < surfCapabilities.minImageExtent.height) {
+ swapchainExtent.height = surfCapabilities.minImageExtent.height;
+ } else if (swapchainExtent.height > surfCapabilities.maxImageExtent.height) {
+ swapchainExtent.height = surfCapabilities.maxImageExtent.height;
+ }
} else {
// If the surface size is defined, the swap chain size must match
swapchainExtent = surfCapabilities.currentExtent;
@@ -651,15 +663,16 @@ static void demo_prepare_buffers(struct demo *demo) {
VkPresentModeKHR swapchainPresentMode = VK_PRESENT_MODE_FIFO_KHR;
- // Determine the number of VkImage's to use in the swap chain (we desire to
- // own only 1 image at a time, besides the images being displayed and
- // queued for display):
- uint32_t desiredNumberOfSwapchainImages =
- surfCapabilities.minImageCount + 1;
+ // Determine the number of VkImage's to use in the swap chain.
+ // Application desires to only acquire 1 image at a time (which is
+ // "surfCapabilities.minImageCount").
+ uint32_t desiredNumOfSwapchainImages = surfCapabilities.minImageCount;
+ // If maxImageCount is 0, we can ask for as many images as we want;
+ // otherwise we're limited to maxImageCount
if ((surfCapabilities.maxImageCount > 0) &&
- (desiredNumberOfSwapchainImages > surfCapabilities.maxImageCount)) {
+ (desiredNumOfSwapchainImages > surfCapabilities.maxImageCount)) {
// Application must settle for fewer images than desired:
- desiredNumberOfSwapchainImages = surfCapabilities.maxImageCount;
+ desiredNumOfSwapchainImages = surfCapabilities.maxImageCount;
}
VkSurfaceTransformFlagsKHR preTransform;
@@ -674,7 +687,7 @@ static void demo_prepare_buffers(struct demo *demo) {
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
.pNext = NULL,
.surface = demo->surface,
- .minImageCount = desiredNumberOfSwapchainImages,
+ .minImageCount = desiredNumOfSwapchainImages,
.imageFormat = demo->format,
.imageColorSpace = demo->color_space,
.imageExtent =