diff options
| author | Tony Barbour <tony@LunarG.com> | 2015-10-08 14:26:24 -0600 |
|---|---|---|
| committer | Tony Barbour <tony@LunarG.com> | 2015-10-08 16:08:47 -0600 |
| commit | d8e504fe37e83cb0e6127e302d4cdf2d20388d11 (patch) | |
| tree | de1513ec177bc7a18d26bcf4d214eee507f4097b | |
| parent | cc69f4573abed2cb8246d888c450ebca3c686e09 (diff) | |
| download | usermoji-d8e504fe37e83cb0e6127e302d4cdf2d20388d11.tar.xz | |
demos: Remove swapchain workaround code and don't assume 2 buffers
Addresses Lunar Exchange issue 153
| -rw-r--r-- | demos/cube.c | 30 | ||||
| -rw-r--r-- | demos/tri.c | 11 |
2 files changed, 14 insertions, 27 deletions
diff --git a/demos/cube.c b/demos/cube.c index cc8e3359..6437a71e 100644 --- a/demos/cube.c +++ b/demos/cube.c @@ -46,7 +46,6 @@ #include "vk_sdk_platform.h" #include "linmath.h" -#define DEMO_BUFFER_COUNT 2 #define DEMO_TEXTURE_COUNT 1 #define APP_SHORT_NAME "cube" #define APP_LONG_NAME "The Vulkan Cube Demo Program" @@ -329,7 +328,6 @@ struct demo { VkQueueFamilyProperties *queue_props; VkPhysicalDeviceMemoryProperties memory_properties; - VkFramebuffer framebuffer; int width, height; VkFormat format; VkColorSpaceKHR color_space; @@ -389,7 +387,7 @@ struct demo { VkDescriptorPool desc_pool; VkDescriptorSet desc_set; - VkFramebuffer framebuffers[DEMO_BUFFER_COUNT]; + VkFramebuffer *framebuffers; bool quit; int32_t curFrame; @@ -702,15 +700,6 @@ static void demo_prepare_buffers(struct demo *demo) } } -#define WORK_AROUND_CODE -#ifdef WORK_AROUND_CODE - // After the proper code was created, other parts of this demo were - // modified to only support DEMO_BUFFER_COUNT number of command buffers, - // images, etc. Live with that for now. - // TODO: Rework this demo code to live with the number of buffers returned - // by vkCreateSwapchainKHR(). - uint32_t desiredNumberOfSwapchainImages = DEMO_BUFFER_COUNT; -#else // WORK_AROUND_CODE // 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): @@ -721,7 +710,6 @@ static void demo_prepare_buffers(struct demo *demo) // Application must settle for fewer images than desired: desiredNumberOfSwapchainImages = surfProperties.maxImageCount; } -#endif // WORK_AROUND_CODE VkSurfaceTransformFlagsKHR preTransform; if (surfProperties.supportedTransforms & VK_SURFACE_TRANSFORM_NONE_BIT_KHR) { @@ -767,14 +755,6 @@ static void demo_prepare_buffers(struct demo *demo) &demo->swapchainImageCount, swapchainImages); assert(!err); -#ifdef WORK_AROUND_CODE - // After the proper code was created, other parts of this demo were - // modified to only support DEMO_BUFFER_COUNT number of command buffers, - // images, etc. Live with that for now. - // TODO: Rework this demo code to live with the number of buffers returned - // by vkCreateSwapchainKHR(). - demo->swapchainImageCount = DEMO_BUFFER_COUNT; -#endif // WORK_AROUND_CODE demo->buffers = (SwapchainBuffers*)malloc(sizeof(SwapchainBuffers)*demo->swapchainImageCount); assert(demo->buffers); @@ -1669,7 +1649,10 @@ static void demo_prepare_framebuffers(struct demo *demo) VkResult U_ASSERT_ONLY err; uint32_t i; - for (i = 0; i < DEMO_BUFFER_COUNT; i++) { + demo->framebuffers = (VkFramebuffer *)malloc(demo->swapchainImageCount * sizeof(VkFramebuffer)); + assert(demo->framebuffers); + + for (i = 0; i < demo->swapchainImageCount; i++) { attachments[0] = demo->buffers[i].view; err = vkCreateFramebuffer(demo->device, &fb_info, &demo->framebuffers[i]); assert(!err); @@ -1737,9 +1720,10 @@ static void demo_cleanup(struct demo *demo) demo->prepared = false; - for (i = 0; i < DEMO_BUFFER_COUNT; i++) { + for (i = 0; i < demo->swapchainImageCount; i++) { vkDestroyFramebuffer(demo->device, demo->framebuffers[i]); } + free(demo->framebuffers); vkDestroyDescriptorPool(demo->device, demo->desc_pool); vkDestroyPipeline(demo->device, demo->pipeline); diff --git a/demos/tri.c b/demos/tri.c index 652c48df..ad5c5a05 100644 --- a/demos/tri.c +++ b/demos/tri.c @@ -48,7 +48,6 @@ #include "icd-spv.h" -#define DEMO_BUFFER_COUNT 2 #define DEMO_TEXTURE_COUNT 1 #define VERTEX_BUFFER_BIND_ID 0 #define APP_SHORT_NAME "tri" @@ -231,7 +230,7 @@ struct demo { VkDescriptorPool desc_pool; VkDescriptorSet desc_set; - VkFramebuffer framebuffers[DEMO_BUFFER_COUNT]; + VkFramebuffer *framebuffers; VkPhysicalDeviceMemoryProperties memory_properties; @@ -1403,7 +1402,10 @@ static void demo_prepare_framebuffers(struct demo *demo) VkResult U_ASSERT_ONLY err; uint32_t i; - for (i = 0; i < DEMO_BUFFER_COUNT; i++) { + demo->framebuffers = (VkFramebuffer *) malloc(demo->swapchainImageCount * sizeof(VkFramebuffer)); + assert(demo->framebuffers); + + for (i = 0; i < demo->swapchainImageCount; i++) { attachments[0]= demo->buffers[i].view; err = vkCreateFramebuffer(demo->device, &fb_info, &demo->framebuffers[i]); assert(!err); @@ -2111,9 +2113,10 @@ static void demo_cleanup(struct demo *demo) demo->prepared = false; - for (i = 0; i < DEMO_BUFFER_COUNT; i++) { + for (i = 0; i < demo->swapchainImageCount; i++) { vkDestroyFramebuffer(demo->device, demo->framebuffers[i]); } + free(demo->framebuffers); vkDestroyDescriptorPool(demo->device, demo->desc_pool); if (demo->setup_cmd) { |
