2 * Copyright © 2017 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include "wsi_common_private.h"
25 #include "util/macros.h"
29 wsi_device_init(struct wsi_device
*wsi
,
30 VkPhysicalDevice pdevice
,
31 WSI_FN_GetPhysicalDeviceProcAddr proc_addr
)
33 memset(wsi
, 0, sizeof(*wsi
));
35 #define WSI_GET_CB(func) \
36 PFN_vk##func func = (PFN_vk##func)proc_addr(pdevice, "vk" #func)
37 WSI_GET_CB(GetPhysicalDeviceMemoryProperties
);
38 WSI_GET_CB(GetPhysicalDeviceQueueFamilyProperties
);
41 GetPhysicalDeviceMemoryProperties(pdevice
, &wsi
->memory_props
);
42 GetPhysicalDeviceQueueFamilyProperties(pdevice
, &wsi
->queue_family_count
, NULL
);
44 #define WSI_GET_CB(func) \
45 wsi->func = (PFN_vk##func)proc_addr(pdevice, "vk" #func)
46 WSI_GET_CB(AllocateMemory
);
47 WSI_GET_CB(AllocateCommandBuffers
);
48 WSI_GET_CB(BindBufferMemory
);
49 WSI_GET_CB(BindImageMemory
);
50 WSI_GET_CB(BeginCommandBuffer
);
51 WSI_GET_CB(CmdCopyImageToBuffer
);
52 WSI_GET_CB(CreateBuffer
);
53 WSI_GET_CB(CreateCommandPool
);
54 WSI_GET_CB(CreateFence
);
55 WSI_GET_CB(CreateImage
);
56 WSI_GET_CB(DestroyBuffer
);
57 WSI_GET_CB(DestroyCommandPool
);
58 WSI_GET_CB(DestroyFence
);
59 WSI_GET_CB(DestroyImage
);
60 WSI_GET_CB(EndCommandBuffer
);
61 WSI_GET_CB(FreeMemory
);
62 WSI_GET_CB(FreeCommandBuffers
);
63 WSI_GET_CB(GetBufferMemoryRequirements
);
64 WSI_GET_CB(GetImageMemoryRequirements
);
65 WSI_GET_CB(GetImageSubresourceLayout
);
66 WSI_GET_CB(GetMemoryFdKHR
);
67 WSI_GET_CB(ResetFences
);
68 WSI_GET_CB(QueueSubmit
);
69 WSI_GET_CB(WaitForFences
);
74 wsi_swapchain_init(const struct wsi_device
*wsi
,
75 struct wsi_swapchain
*chain
,
77 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
78 const VkAllocationCallbacks
*pAllocator
)
82 memset(chain
, 0, sizeof(*chain
));
85 chain
->device
= device
;
86 chain
->alloc
= *pAllocator
;
87 chain
->use_prime_blit
= false;
90 vk_zalloc(pAllocator
, sizeof(VkCommandPool
) * wsi
->queue_family_count
, 8,
91 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
92 if (!chain
->cmd_pools
)
93 return VK_ERROR_OUT_OF_HOST_MEMORY
;
95 for (uint32_t i
= 0; i
< wsi
->queue_family_count
; i
++) {
96 const VkCommandPoolCreateInfo cmd_pool_info
= {
97 .sType
= VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO
,
100 .queueFamilyIndex
= i
,
102 result
= wsi
->CreateCommandPool(device
, &cmd_pool_info
, &chain
->alloc
,
103 &chain
->cmd_pools
[i
]);
104 if (result
!= VK_SUCCESS
)
111 wsi_swapchain_finish(chain
);
116 wsi_swapchain_finish(struct wsi_swapchain
*chain
)
118 for (unsigned i
= 0; i
< ARRAY_SIZE(chain
->fences
); i
++)
119 chain
->wsi
->DestroyFence(chain
->device
, chain
->fences
[i
], &chain
->alloc
);
121 for (uint32_t i
= 0; i
< chain
->wsi
->queue_family_count
; i
++) {
122 chain
->wsi
->DestroyCommandPool(chain
->device
, chain
->cmd_pools
[i
],
128 select_memory_type(const struct wsi_device
*wsi
,
129 VkMemoryPropertyFlags props
,
132 for (uint32_t i
= 0; i
< wsi
->memory_props
.memoryTypeCount
; i
++) {
133 const VkMemoryType type
= wsi
->memory_props
.memoryTypes
[i
];
134 if ((type_bits
& (1 << i
)) && (type
.propertyFlags
& props
) == props
)
138 unreachable("No memory type found");
142 vk_format_size(VkFormat format
)
145 case VK_FORMAT_B8G8R8A8_UNORM
:
146 case VK_FORMAT_B8G8R8A8_SRGB
:
149 unreachable("Unknown WSI Format");
153 static inline uint32_t
154 align_u32(uint32_t v
, uint32_t a
)
156 assert(a
!= 0 && a
== (a
& -a
));
157 return (v
+ a
- 1) & ~(a
- 1);
161 wsi_create_native_image(const struct wsi_swapchain
*chain
,
162 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
163 struct wsi_image
*image
)
165 const struct wsi_device
*wsi
= chain
->wsi
;
168 memset(image
, 0, sizeof(*image
));
170 const struct wsi_image_create_info image_wsi_info
= {
171 .sType
= VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA
,
175 const VkImageCreateInfo image_info
= {
176 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
177 .pNext
= &image_wsi_info
,
179 .imageType
= VK_IMAGE_TYPE_2D
,
180 .format
= pCreateInfo
->imageFormat
,
182 .width
= pCreateInfo
->imageExtent
.width
,
183 .height
= pCreateInfo
->imageExtent
.height
,
188 .samples
= VK_SAMPLE_COUNT_1_BIT
,
189 .tiling
= VK_IMAGE_TILING_OPTIMAL
,
190 .usage
= pCreateInfo
->imageUsage
,
191 .sharingMode
= pCreateInfo
->imageSharingMode
,
192 .queueFamilyIndexCount
= pCreateInfo
->queueFamilyIndexCount
,
193 .pQueueFamilyIndices
= pCreateInfo
->pQueueFamilyIndices
,
194 .initialLayout
= VK_IMAGE_LAYOUT_UNDEFINED
,
196 result
= wsi
->CreateImage(chain
->device
, &image_info
,
197 &chain
->alloc
, &image
->image
);
198 if (result
!= VK_SUCCESS
)
201 VkMemoryRequirements reqs
;
202 wsi
->GetImageMemoryRequirements(chain
->device
, image
->image
, &reqs
);
204 VkSubresourceLayout image_layout
;
205 const VkImageSubresource image_subresource
= {
206 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
210 wsi
->GetImageSubresourceLayout(chain
->device
, image
->image
,
211 &image_subresource
, &image_layout
);
213 const struct wsi_memory_allocate_info memory_wsi_info
= {
214 .sType
= VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA
,
216 .implicit_sync
= true,
218 const VkExportMemoryAllocateInfoKHR memory_export_info
= {
219 .sType
= VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR
,
220 .pNext
= &memory_wsi_info
,
221 .handleTypes
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
,
223 const VkMemoryDedicatedAllocateInfoKHR memory_dedicated_info
= {
224 .sType
= VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR
,
225 .pNext
= &memory_export_info
,
226 .image
= image
->image
,
227 .buffer
= VK_NULL_HANDLE
,
229 const VkMemoryAllocateInfo memory_info
= {
230 .sType
= VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
,
231 .pNext
= &memory_dedicated_info
,
232 .allocationSize
= reqs
.size
,
233 .memoryTypeIndex
= select_memory_type(wsi
, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
234 reqs
.memoryTypeBits
),
236 result
= wsi
->AllocateMemory(chain
->device
, &memory_info
,
237 &chain
->alloc
, &image
->memory
);
238 if (result
!= VK_SUCCESS
)
241 result
= wsi
->BindImageMemory(chain
->device
, image
->image
,
243 if (result
!= VK_SUCCESS
)
246 const VkMemoryGetFdInfoKHR memory_get_fd_info
= {
247 .sType
= VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
,
249 .memory
= image
->memory
,
250 .handleType
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
,
253 result
= wsi
->GetMemoryFdKHR(chain
->device
, &memory_get_fd_info
, &fd
);
254 if (result
!= VK_SUCCESS
)
257 image
->size
= reqs
.size
;
258 image
->row_pitch
= image_layout
.rowPitch
;
265 wsi_destroy_image(chain
, image
);
270 #define WSI_PRIME_LINEAR_STRIDE_ALIGN 256
273 wsi_create_prime_image(const struct wsi_swapchain
*chain
,
274 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
275 struct wsi_image
*image
)
277 const struct wsi_device
*wsi
= chain
->wsi
;
280 memset(image
, 0, sizeof(*image
));
282 const uint32_t cpp
= vk_format_size(pCreateInfo
->imageFormat
);
283 const uint32_t linear_stride
= align_u32(pCreateInfo
->imageExtent
.width
* cpp
,
284 WSI_PRIME_LINEAR_STRIDE_ALIGN
);
286 uint32_t linear_size
= linear_stride
* pCreateInfo
->imageExtent
.height
;
287 linear_size
= align_u32(linear_size
, 4096);
289 const VkExternalMemoryBufferCreateInfoKHR prime_buffer_external_info
= {
290 .sType
= VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
,
292 .handleTypes
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
,
294 const VkBufferCreateInfo prime_buffer_info
= {
295 .sType
= VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
,
296 .pNext
= &prime_buffer_external_info
,
298 .usage
= VK_BUFFER_USAGE_TRANSFER_DST_BIT
,
299 .sharingMode
= VK_SHARING_MODE_EXCLUSIVE
,
301 result
= wsi
->CreateBuffer(chain
->device
, &prime_buffer_info
,
302 &chain
->alloc
, &image
->prime
.buffer
);
303 if (result
!= VK_SUCCESS
)
306 VkMemoryRequirements reqs
;
307 wsi
->GetBufferMemoryRequirements(chain
->device
, image
->prime
.buffer
, &reqs
);
308 assert(reqs
.size
<= linear_size
);
310 const struct wsi_memory_allocate_info memory_wsi_info
= {
311 .sType
= VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA
,
313 .implicit_sync
= true,
315 const VkExportMemoryAllocateInfoKHR prime_memory_export_info
= {
316 .sType
= VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR
,
317 .pNext
= &memory_wsi_info
,
318 .handleTypes
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
,
320 const VkMemoryDedicatedAllocateInfoKHR prime_memory_dedicated_info
= {
321 .sType
= VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR
,
322 .pNext
= &prime_memory_export_info
,
323 .image
= VK_NULL_HANDLE
,
324 .buffer
= image
->prime
.buffer
,
326 const VkMemoryAllocateInfo prime_memory_info
= {
327 .sType
= VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
,
328 .pNext
= &prime_memory_dedicated_info
,
329 .allocationSize
= linear_size
,
330 .memoryTypeIndex
= select_memory_type(wsi
, 0, reqs
.memoryTypeBits
),
332 result
= wsi
->AllocateMemory(chain
->device
, &prime_memory_info
,
333 &chain
->alloc
, &image
->prime
.memory
);
334 if (result
!= VK_SUCCESS
)
337 result
= wsi
->BindBufferMemory(chain
->device
, image
->prime
.buffer
,
338 image
->prime
.memory
, 0);
339 if (result
!= VK_SUCCESS
)
342 const VkImageCreateInfo image_info
= {
343 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
346 .imageType
= VK_IMAGE_TYPE_2D
,
347 .format
= pCreateInfo
->imageFormat
,
349 .width
= pCreateInfo
->imageExtent
.width
,
350 .height
= pCreateInfo
->imageExtent
.height
,
355 .samples
= VK_SAMPLE_COUNT_1_BIT
,
356 .tiling
= VK_IMAGE_TILING_OPTIMAL
,
357 .usage
= pCreateInfo
->imageUsage
| VK_IMAGE_USAGE_TRANSFER_SRC_BIT
,
358 .sharingMode
= pCreateInfo
->imageSharingMode
,
359 .queueFamilyIndexCount
= pCreateInfo
->queueFamilyIndexCount
,
360 .pQueueFamilyIndices
= pCreateInfo
->pQueueFamilyIndices
,
361 .initialLayout
= VK_IMAGE_LAYOUT_UNDEFINED
,
363 result
= wsi
->CreateImage(chain
->device
, &image_info
,
364 &chain
->alloc
, &image
->image
);
365 if (result
!= VK_SUCCESS
)
368 wsi
->GetImageMemoryRequirements(chain
->device
, image
->image
, &reqs
);
370 const VkMemoryDedicatedAllocateInfoKHR memory_dedicated_info
= {
371 .sType
= VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR
,
373 .image
= image
->image
,
374 .buffer
= VK_NULL_HANDLE
,
376 const VkMemoryAllocateInfo memory_info
= {
377 .sType
= VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
,
378 .pNext
= &memory_dedicated_info
,
379 .allocationSize
= reqs
.size
,
380 .memoryTypeIndex
= select_memory_type(wsi
, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
381 reqs
.memoryTypeBits
),
383 result
= wsi
->AllocateMemory(chain
->device
, &memory_info
,
384 &chain
->alloc
, &image
->memory
);
385 if (result
!= VK_SUCCESS
)
388 result
= wsi
->BindImageMemory(chain
->device
, image
->image
,
390 if (result
!= VK_SUCCESS
)
393 image
->prime
.blit_cmd_buffers
=
394 vk_zalloc(&chain
->alloc
,
395 sizeof(VkCommandBuffer
) * wsi
->queue_family_count
, 8,
396 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
397 if (!image
->prime
.blit_cmd_buffers
)
400 for (uint32_t i
= 0; i
< wsi
->queue_family_count
; i
++) {
401 const VkCommandBufferAllocateInfo cmd_buffer_info
= {
402 .sType
= VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO
,
404 .commandPool
= chain
->cmd_pools
[i
],
405 .level
= VK_COMMAND_BUFFER_LEVEL_PRIMARY
,
406 .commandBufferCount
= 1,
408 result
= wsi
->AllocateCommandBuffers(chain
->device
, &cmd_buffer_info
,
409 &image
->prime
.blit_cmd_buffers
[i
]);
410 if (result
!= VK_SUCCESS
)
413 const VkCommandBufferBeginInfo begin_info
= {
414 .sType
= VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO
,
416 wsi
->BeginCommandBuffer(image
->prime
.blit_cmd_buffers
[i
], &begin_info
);
418 struct VkBufferImageCopy buffer_image_copy
= {
420 .bufferRowLength
= linear_stride
/ cpp
,
421 .bufferImageHeight
= 0,
422 .imageSubresource
= {
423 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
428 .imageOffset
= { .x
= 0, .y
= 0, .z
= 0 },
430 .width
= pCreateInfo
->imageExtent
.width
,
431 .height
= pCreateInfo
->imageExtent
.height
,
435 wsi
->CmdCopyImageToBuffer(image
->prime
.blit_cmd_buffers
[i
],
437 VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
,
439 1, &buffer_image_copy
);
441 result
= wsi
->EndCommandBuffer(image
->prime
.blit_cmd_buffers
[i
]);
442 if (result
!= VK_SUCCESS
)
446 const VkMemoryGetFdInfoKHR linear_memory_get_fd_info
= {
447 .sType
= VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
,
449 .memory
= image
->prime
.memory
,
450 .handleType
= VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
,
453 result
= wsi
->GetMemoryFdKHR(chain
->device
, &linear_memory_get_fd_info
, &fd
);
454 if (result
!= VK_SUCCESS
)
457 image
->size
= linear_size
;
458 image
->row_pitch
= linear_stride
;
465 wsi_destroy_image(chain
, image
);
471 wsi_destroy_image(const struct wsi_swapchain
*chain
,
472 struct wsi_image
*image
)
474 const struct wsi_device
*wsi
= chain
->wsi
;
476 if (image
->prime
.blit_cmd_buffers
) {
477 for (uint32_t i
= 0; i
< wsi
->queue_family_count
; i
++) {
478 wsi
->FreeCommandBuffers(chain
->device
, chain
->cmd_pools
[i
],
479 1, &image
->prime
.blit_cmd_buffers
[i
]);
481 vk_free(&chain
->alloc
, image
->prime
.blit_cmd_buffers
);
484 wsi
->FreeMemory(chain
->device
, image
->memory
, &chain
->alloc
);
485 wsi
->DestroyImage(chain
->device
, image
->image
, &chain
->alloc
);
486 wsi
->FreeMemory(chain
->device
, image
->prime
.memory
, &chain
->alloc
);
487 wsi
->DestroyBuffer(chain
->device
, image
->prime
.buffer
, &chain
->alloc
);
491 wsi_common_create_swapchain(struct wsi_device
*wsi
,
494 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
495 const VkAllocationCallbacks
*pAllocator
,
496 VkSwapchainKHR
*pSwapchain
)
498 ICD_FROM_HANDLE(VkIcdSurfaceBase
, surface
, pCreateInfo
->surface
);
499 struct wsi_interface
*iface
= wsi
->wsi
[surface
->platform
];
500 struct wsi_swapchain
*swapchain
;
502 VkResult result
= iface
->create_swapchain(surface
, device
, wsi
, fd
,
503 pCreateInfo
, pAllocator
,
505 if (result
!= VK_SUCCESS
)
508 *pSwapchain
= wsi_swapchain_to_handle(swapchain
);
514 wsi_common_destroy_swapchain(VkDevice device
,
515 VkSwapchainKHR _swapchain
,
516 const VkAllocationCallbacks
*pAllocator
)
518 WSI_FROM_HANDLE(wsi_swapchain
, swapchain
, _swapchain
);
522 swapchain
->destroy(swapchain
, pAllocator
);
526 wsi_common_get_images(VkSwapchainKHR _swapchain
,
527 uint32_t *pSwapchainImageCount
,
528 VkImage
*pSwapchainImages
)
530 WSI_FROM_HANDLE(wsi_swapchain
, swapchain
, _swapchain
);
531 VK_OUTARRAY_MAKE(images
, pSwapchainImages
, pSwapchainImageCount
);
533 for (uint32_t i
= 0; i
< swapchain
->image_count
; i
++) {
534 vk_outarray_append(&images
, image
) {
535 *image
= swapchain
->get_wsi_image(swapchain
, i
)->image
;
539 return vk_outarray_status(&images
);
543 wsi_common_queue_present(const struct wsi_device
*wsi
,
546 int queue_family_index
,
547 const VkPresentInfoKHR
*pPresentInfo
)
549 VkResult final_result
= VK_SUCCESS
;
551 const VkPresentRegionsKHR
*regions
=
552 vk_find_struct_const(pPresentInfo
->pNext
, PRESENT_REGIONS_KHR
);
554 for (uint32_t i
= 0; i
< pPresentInfo
->swapchainCount
; i
++) {
555 WSI_FROM_HANDLE(wsi_swapchain
, swapchain
, pPresentInfo
->pSwapchains
[i
]);
558 if (swapchain
->fences
[0] == VK_NULL_HANDLE
) {
559 const VkFenceCreateInfo fence_info
= {
560 .sType
= VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
,
564 result
= wsi
->CreateFence(device
, &fence_info
,
566 &swapchain
->fences
[0]);
567 if (result
!= VK_SUCCESS
)
570 wsi
->ResetFences(device
, 1, &swapchain
->fences
[0]);
573 VkSubmitInfo submit_info
= {
574 .sType
= VK_STRUCTURE_TYPE_SUBMIT_INFO
,
578 VkPipelineStageFlags
*stage_flags
= NULL
;
580 /* We only need/want to wait on semaphores once. After that, we're
581 * guaranteed ordering since it all happens on the same queue.
583 submit_info
.waitSemaphoreCount
= pPresentInfo
->waitSemaphoreCount
,
584 submit_info
.pWaitSemaphores
= pPresentInfo
->pWaitSemaphores
,
586 /* Set up the pWaitDstStageMasks */
587 stage_flags
= vk_alloc(&swapchain
->alloc
,
588 sizeof(VkPipelineStageFlags
) *
589 pPresentInfo
->waitSemaphoreCount
,
591 VK_SYSTEM_ALLOCATION_SCOPE_COMMAND
);
593 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
596 for (uint32_t s
= 0; s
< pPresentInfo
->waitSemaphoreCount
; s
++)
597 stage_flags
[s
] = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT
;
599 submit_info
.pWaitDstStageMask
= stage_flags
;
602 if (swapchain
->use_prime_blit
) {
603 /* If we are using prime blits, we need to perform the blit now. The
604 * command buffer is attached to the image.
606 struct wsi_image
*image
=
607 swapchain
->get_wsi_image(swapchain
, pPresentInfo
->pImageIndices
[i
]);
608 submit_info
.commandBufferCount
= 1;
609 submit_info
.pCommandBuffers
=
610 &image
->prime
.blit_cmd_buffers
[queue_family_index
];
613 result
= wsi
->QueueSubmit(queue
, 1, &submit_info
, swapchain
->fences
[0]);
614 vk_free(&swapchain
->alloc
, stage_flags
);
615 if (result
!= VK_SUCCESS
)
618 const VkPresentRegionKHR
*region
= NULL
;
619 if (regions
&& regions
->pRegions
)
620 region
= ®ions
->pRegions
[i
];
622 result
= swapchain
->queue_present(swapchain
,
623 pPresentInfo
->pImageIndices
[i
],
625 if (result
!= VK_SUCCESS
)
628 VkFence last
= swapchain
->fences
[2];
629 swapchain
->fences
[2] = swapchain
->fences
[1];
630 swapchain
->fences
[1] = swapchain
->fences
[0];
631 swapchain
->fences
[0] = last
;
633 if (last
!= VK_NULL_HANDLE
) {
634 wsi
->WaitForFences(device
, 1, &last
, true, 1);
638 if (pPresentInfo
->pResults
!= NULL
)
639 pPresentInfo
->pResults
[i
] = result
;
641 /* Let the final result be our first unsuccessful result */
642 if (final_result
== VK_SUCCESS
)
643 final_result
= result
;