vulkan/wsi: Move prime blitting into queue_present
This lets us save a QueueSubmit and it also makes prime a lot less X11-specific. Also, it means we can only wait on the semaphores once instead of on every blit. Reviewed-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
@@ -84,6 +84,7 @@ wsi_swapchain_init(const struct wsi_device *wsi,
|
|||||||
chain->wsi = wsi;
|
chain->wsi = wsi;
|
||||||
chain->device = device;
|
chain->device = device;
|
||||||
chain->alloc = *pAllocator;
|
chain->alloc = *pAllocator;
|
||||||
|
chain->use_prime_blit = false;
|
||||||
|
|
||||||
chain->cmd_pools =
|
chain->cmd_pools =
|
||||||
vk_zalloc(pAllocator, sizeof(VkCommandPool) * wsi->queue_family_count, 8,
|
vk_zalloc(pAllocator, sizeof(VkCommandPool) * wsi->queue_family_count, 8,
|
||||||
@@ -483,30 +484,6 @@ wsi_destroy_image(const struct wsi_swapchain *chain,
|
|||||||
wsi->DestroyBuffer(chain->device, image->prime.buffer, &chain->alloc);
|
wsi->DestroyBuffer(chain->device, image->prime.buffer, &chain->alloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
VkResult
|
|
||||||
wsi_prime_image_blit_to_linear(const struct wsi_swapchain *chain,
|
|
||||||
struct wsi_image *image,
|
|
||||||
VkQueue queue,
|
|
||||||
uint32_t waitSemaphoreCount,
|
|
||||||
const VkSemaphore *pWaitSemaphores)
|
|
||||||
{
|
|
||||||
uint32_t queue_family = chain->wsi->queue_get_family_index(queue);
|
|
||||||
|
|
||||||
VkPipelineStageFlags stage_flags = VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT;
|
|
||||||
const VkSubmitInfo submit_info = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
|
|
||||||
.pNext = NULL,
|
|
||||||
.waitSemaphoreCount = waitSemaphoreCount,
|
|
||||||
.pWaitSemaphores = pWaitSemaphores,
|
|
||||||
.pWaitDstStageMask = &stage_flags,
|
|
||||||
.commandBufferCount = 1,
|
|
||||||
.pCommandBuffers = &image->prime.blit_cmd_buffers[queue_family],
|
|
||||||
.signalSemaphoreCount = 0,
|
|
||||||
.pSignalSemaphores = NULL,
|
|
||||||
};
|
|
||||||
return chain->wsi->QueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
VkResult
|
VkResult
|
||||||
wsi_common_get_images(VkSwapchainKHR _swapchain,
|
wsi_common_get_images(VkSwapchainKHR _swapchain,
|
||||||
uint32_t *pSwapchainImageCount,
|
uint32_t *pSwapchainImageCount,
|
||||||
@@ -559,6 +536,7 @@ wsi_common_queue_present(const struct wsi_device *wsi,
|
|||||||
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
|
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
|
||||||
.pNext = NULL,
|
.pNext = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
VkPipelineStageFlags *stage_flags = NULL;
|
VkPipelineStageFlags *stage_flags = NULL;
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
/* We only need/want to wait on semaphores once. After that, we're
|
/* We only need/want to wait on semaphores once. After that, we're
|
||||||
@@ -582,6 +560,18 @@ wsi_common_queue_present(const struct wsi_device *wsi,
|
|||||||
|
|
||||||
submit_info.pWaitDstStageMask = stage_flags;
|
submit_info.pWaitDstStageMask = stage_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (swapchain->use_prime_blit) {
|
||||||
|
/* If we are using prime blits, we need to perform the blit now. The
|
||||||
|
* command buffer is attached to the image.
|
||||||
|
*/
|
||||||
|
struct wsi_image *image =
|
||||||
|
swapchain->get_wsi_image(swapchain, pPresentInfo->pImageIndices[i]);
|
||||||
|
submit_info.commandBufferCount = 1;
|
||||||
|
submit_info.pCommandBuffers =
|
||||||
|
&image->prime.blit_cmd_buffers[queue_family_index];
|
||||||
|
}
|
||||||
|
|
||||||
result = wsi->QueueSubmit(queue, 1, &submit_info, swapchain->fences[0]);
|
result = wsi->QueueSubmit(queue, 1, &submit_info, swapchain->fences[0]);
|
||||||
vk_free(&swapchain->alloc, stage_flags);
|
vk_free(&swapchain->alloc, stage_flags);
|
||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS)
|
||||||
@@ -592,9 +582,6 @@ wsi_common_queue_present(const struct wsi_device *wsi,
|
|||||||
region = ®ions->pRegions[i];
|
region = ®ions->pRegions[i];
|
||||||
|
|
||||||
result = swapchain->queue_present(swapchain,
|
result = swapchain->queue_present(swapchain,
|
||||||
queue,
|
|
||||||
pPresentInfo->waitSemaphoreCount,
|
|
||||||
pPresentInfo->pWaitSemaphores,
|
|
||||||
pPresentInfo->pImageIndices[i],
|
pPresentInfo->pImageIndices[i],
|
||||||
region);
|
region);
|
||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS)
|
||||||
|
@@ -59,6 +59,8 @@ struct wsi_swapchain {
|
|||||||
VkPresentModeKHR present_mode;
|
VkPresentModeKHR present_mode;
|
||||||
uint32_t image_count;
|
uint32_t image_count;
|
||||||
|
|
||||||
|
bool use_prime_blit;
|
||||||
|
|
||||||
/* Command pools, one per queue family */
|
/* Command pools, one per queue family */
|
||||||
VkCommandPool *cmd_pools;
|
VkCommandPool *cmd_pools;
|
||||||
|
|
||||||
@@ -70,9 +72,6 @@ struct wsi_swapchain {
|
|||||||
uint64_t timeout, VkSemaphore semaphore,
|
uint64_t timeout, VkSemaphore semaphore,
|
||||||
uint32_t *image_index);
|
uint32_t *image_index);
|
||||||
VkResult (*queue_present)(struct wsi_swapchain *swap_chain,
|
VkResult (*queue_present)(struct wsi_swapchain *swap_chain,
|
||||||
VkQueue queue,
|
|
||||||
uint32_t waitSemaphoreCount,
|
|
||||||
const VkSemaphore *pWaitSemaphores,
|
|
||||||
uint32_t image_index,
|
uint32_t image_index,
|
||||||
const VkPresentRegionKHR *damage);
|
const VkPresentRegionKHR *damage);
|
||||||
};
|
};
|
||||||
|
@@ -64,11 +64,4 @@ void
|
|||||||
wsi_destroy_image(const struct wsi_swapchain *chain,
|
wsi_destroy_image(const struct wsi_swapchain *chain,
|
||||||
struct wsi_image *image);
|
struct wsi_image *image);
|
||||||
|
|
||||||
VkResult
|
|
||||||
wsi_prime_image_blit_to_linear(const struct wsi_swapchain *chain,
|
|
||||||
struct wsi_image *image,
|
|
||||||
VkQueue queue,
|
|
||||||
uint32_t waitSemaphoreCount,
|
|
||||||
const VkSemaphore *pWaitSemaphores);
|
|
||||||
|
|
||||||
#endif /* WSI_COMMON_PRIVATE_H */
|
#endif /* WSI_COMMON_PRIVATE_H */
|
||||||
|
@@ -644,9 +644,6 @@ static const struct wl_callback_listener frame_listener = {
|
|||||||
|
|
||||||
static VkResult
|
static VkResult
|
||||||
wsi_wl_swapchain_queue_present(struct wsi_swapchain *wsi_chain,
|
wsi_wl_swapchain_queue_present(struct wsi_swapchain *wsi_chain,
|
||||||
VkQueue queue,
|
|
||||||
uint32_t waitSemaphoreCount,
|
|
||||||
const VkSemaphore *pWaitSemaphores,
|
|
||||||
uint32_t image_index,
|
uint32_t image_index,
|
||||||
const VkPresentRegionKHR *damage)
|
const VkPresentRegionKHR *damage)
|
||||||
{
|
{
|
||||||
|
@@ -625,8 +625,6 @@ struct x11_image {
|
|||||||
struct x11_swapchain {
|
struct x11_swapchain {
|
||||||
struct wsi_swapchain base;
|
struct wsi_swapchain base;
|
||||||
|
|
||||||
bool use_prime_blit;
|
|
||||||
|
|
||||||
xcb_connection_t * conn;
|
xcb_connection_t * conn;
|
||||||
xcb_window_t window;
|
xcb_window_t window;
|
||||||
xcb_gc_t gc;
|
xcb_gc_t gc;
|
||||||
@@ -862,24 +860,10 @@ x11_acquire_next_image(struct wsi_swapchain *anv_chain,
|
|||||||
|
|
||||||
static VkResult
|
static VkResult
|
||||||
x11_queue_present(struct wsi_swapchain *anv_chain,
|
x11_queue_present(struct wsi_swapchain *anv_chain,
|
||||||
VkQueue queue,
|
|
||||||
uint32_t waitSemaphoreCount,
|
|
||||||
const VkSemaphore *pWaitSemaphores,
|
|
||||||
uint32_t image_index,
|
uint32_t image_index,
|
||||||
const VkPresentRegionKHR *damage)
|
const VkPresentRegionKHR *damage)
|
||||||
{
|
{
|
||||||
struct x11_swapchain *chain = (struct x11_swapchain *)anv_chain;
|
struct x11_swapchain *chain = (struct x11_swapchain *)anv_chain;
|
||||||
VkResult result;
|
|
||||||
|
|
||||||
if (chain->use_prime_blit) {
|
|
||||||
result = wsi_prime_image_blit_to_linear(&chain->base,
|
|
||||||
&chain->images[image_index].base,
|
|
||||||
queue,
|
|
||||||
waitSemaphoreCount,
|
|
||||||
pWaitSemaphores);
|
|
||||||
if (result != VK_SUCCESS)
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chain->threaded) {
|
if (chain->threaded) {
|
||||||
wsi_queue_push(&chain->present_queue, image_index);
|
wsi_queue_push(&chain->present_queue, image_index);
|
||||||
@@ -947,7 +931,7 @@ x11_image_init(VkDevice device_h, struct x11_swapchain *chain,
|
|||||||
VkResult result;
|
VkResult result;
|
||||||
uint32_t bpp = 32;
|
uint32_t bpp = 32;
|
||||||
|
|
||||||
if (chain->use_prime_blit) {
|
if (chain->base.use_prime_blit) {
|
||||||
result = wsi_create_prime_image(&chain->base, pCreateInfo, &image->base);
|
result = wsi_create_prime_image(&chain->base, pCreateInfo, &image->base);
|
||||||
} else {
|
} else {
|
||||||
result = wsi_create_native_image(&chain->base, pCreateInfo, &image->base);
|
result = wsi_create_native_image(&chain->base, pCreateInfo, &image->base);
|
||||||
@@ -1104,11 +1088,8 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
|
|||||||
chain->threaded = false;
|
chain->threaded = false;
|
||||||
chain->status = VK_SUCCESS;
|
chain->status = VK_SUCCESS;
|
||||||
|
|
||||||
|
if (!wsi_x11_check_dri3_compatible(conn, local_fd))
|
||||||
chain->use_prime_blit = false;
|
chain->base.use_prime_blit = true;
|
||||||
if (!wsi_x11_check_dri3_compatible(conn, local_fd)) {
|
|
||||||
chain->use_prime_blit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
chain->event_id = xcb_generate_id(chain->conn);
|
chain->event_id = xcb_generate_id(chain->conn);
|
||||||
xcb_present_select_input(chain->conn, chain->event_id, chain->window,
|
xcb_present_select_input(chain->conn, chain->event_id, chain->window,
|
||||||
|
Reference in New Issue
Block a user