diff options
author | Dave Airlie <airlied@redhat.com> | 2020-06-19 16:37:51 +1000 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2020-07-27 13:14:09 +1000 |
commit | 5611c40fc01040caf9127e5034eefba213260f07 (patch) | |
tree | ddc59c101787c6116d580354285d7330446a96ce | |
parent | a6cd471cad1c03729b9c5af0ce7c15d9f8731e3a (diff) |
vulkan/wsi: add sw support.
This allows using put image to display images for sw vk drivers
-rw-r--r-- | src/vulkan/wsi/wsi_common.c | 55 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common.h | 12 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common_x11.c | 71 |
3 files changed, 108 insertions, 30 deletions
diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c index 2108f7f703f..8825b60396f 100644 --- a/src/vulkan/wsi/wsi_common.c +++ b/src/vulkan/wsi/wsi_common.c @@ -35,12 +35,12 @@ #include <stdio.h> VkResult -wsi_device_init(struct wsi_device *wsi, - VkPhysicalDevice pdevice, - WSI_FN_GetPhysicalDeviceProcAddr proc_addr, - const VkAllocationCallbacks *alloc, - int display_fd, - const struct driOptionCache *dri_options) +wsi_device_sw_init(struct wsi_device *wsi, + VkPhysicalDevice pdevice, + WSI_FN_GetPhysicalDeviceProcAddr proc_addr, + const VkAllocationCallbacks *alloc, + int display_fd, + const struct driOptionCache *dri_options, bool sw) { const char *present_mode; UNUSED VkResult result; @@ -49,7 +49,7 @@ wsi_device_init(struct wsi_device *wsi, wsi->instance_alloc = *alloc; wsi->pdevice = pdevice; - + wsi->sw = sw; #define WSI_GET_CB(func) \ PFN_vk##func func = (PFN_vk##func)proc_addr(pdevice, "vk" #func) WSI_GET_CB(GetPhysicalDeviceProperties2); @@ -94,13 +94,16 @@ wsi_device_init(struct wsi_device *wsi, WSI_GET_CB(GetImageDrmFormatModifierPropertiesEXT); WSI_GET_CB(GetImageMemoryRequirements); WSI_GET_CB(GetImageSubresourceLayout); - WSI_GET_CB(GetMemoryFdKHR); + if (!wsi->sw) + WSI_GET_CB(GetMemoryFdKHR); WSI_GET_CB(GetPhysicalDeviceFormatProperties); WSI_GET_CB(GetPhysicalDeviceFormatProperties2KHR); WSI_GET_CB(GetPhysicalDeviceImageFormatProperties2); WSI_GET_CB(ResetFences); WSI_GET_CB(QueueSubmit); WSI_GET_CB(WaitForFences); + WSI_GET_CB(MapMemory); + WSI_GET_CB(UnmapMemory); #undef WSI_GET_CB #ifdef VK_USE_PLATFORM_XCB_KHR @@ -170,6 +173,17 @@ wsi_device_finish(struct wsi_device *wsi, #endif } +VkResult +wsi_device_init(struct wsi_device *wsi, + VkPhysicalDevice pdevice, + WSI_FN_GetPhysicalDeviceProcAddr proc_addr, + const VkAllocationCallbacks *alloc, + int display_fd, + const struct driOptionCache *dri_options) +{ + return wsi_device_sw_init(wsi, pdevice, proc_addr, alloc, display_fd, dri_options, false); +} + bool wsi_device_matches_drm_fd(const struct wsi_device *wsi, int drm_fd) { @@ -575,18 +589,21 @@ wsi_create_native_image(const struct wsi_swapchain *chain, if (result != VK_SUCCESS) goto fail; - const VkMemoryGetFdInfoKHR memory_get_fd_info = { - .sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR, - .pNext = NULL, - .memory = image->memory, - .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, - }; - int fd; - result = wsi->GetMemoryFdKHR(chain->device, &memory_get_fd_info, &fd); - if (result != VK_SUCCESS) - goto fail; + int fd = -1; + if (!wsi->sw) { + const VkMemoryGetFdInfoKHR memory_get_fd_info = { + .sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR, + .pNext = NULL, + .memory = image->memory, + .handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, + }; + + result = wsi->GetMemoryFdKHR(chain->device, &memory_get_fd_info, &fd); + if (result != VK_SUCCESS) + goto fail; + } - if (num_modifier_lists > 0) { + if (!wsi->sw && num_modifier_lists > 0) { VkImageDrmFormatModifierPropertiesEXT image_mod_props = { .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT, }; diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h index cbf7e1be14e..685ef0719d7 100644 --- a/src/vulkan/wsi/wsi_common.h +++ b/src/vulkan/wsi/wsi_common.h @@ -116,6 +116,8 @@ struct wsi_device { bool ensure_minImageCount; } x11; + bool sw; + /* Signals the semaphore such that any wait on the semaphore will wait on * any reads or writes on the give memory object. This is used to * implement the semaphore signal operation in vkAcquireNextImage. @@ -177,6 +179,8 @@ struct wsi_device { WSI_CB(ResetFences); WSI_CB(QueueSubmit); WSI_CB(WaitForFences); + WSI_CB(MapMemory); + WSI_CB(UnmapMemory); #undef WSI_CB struct wsi_interface * wsi[VK_ICD_WSI_PLATFORM_MAX]; @@ -192,6 +196,14 @@ wsi_device_init(struct wsi_device *wsi, int display_fd, const struct driOptionCache *dri_options); +VkResult +wsi_device_sw_init(struct wsi_device *wsi, + VkPhysicalDevice pdevice, + WSI_FN_GetPhysicalDeviceProcAddr proc_addr, + const VkAllocationCallbacks *alloc, + int display_fd, + const struct driOptionCache *dri_options, bool sw); + void wsi_device_finish(struct wsi_device *wsi, const VkAllocationCallbacks *alloc); diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c index 979dca0784c..24201d79136 100644 --- a/src/vulkan/wsi/wsi_common_x11.c +++ b/src/vulkan/wsi/wsi_common_x11.c @@ -663,6 +663,9 @@ x11_surface_is_local_to_gpu(struct wsi_device *wsi_dev, if (!wsi_conn) return false; + if (wsi_dev->sw) + return true; + if (!wsi_x11_check_for_dri3(wsi_conn)) return false; @@ -1014,8 +1017,8 @@ x11_acquire_next_image_from_queue(struct x11_swapchain *chain, } static VkResult -x11_present_to_x11(struct x11_swapchain *chain, uint32_t image_index, - uint32_t target_msc) +x11_present_to_x11_dri3(struct x11_swapchain *chain, uint32_t image_index, + uint32_t target_msc) { struct x11_image *image = &chain->images[image_index]; @@ -1074,6 +1077,41 @@ x11_present_to_x11(struct x11_swapchain *chain, uint32_t image_index, } static VkResult +x11_present_to_x11_sw(struct x11_swapchain *chain, uint32_t image_index, + uint32_t target_msc) +{ + struct x11_image *image = &chain->images[image_index]; + + xcb_void_cookie_t cookie; + void *myptr; + chain->base.wsi->MapMemory(chain->base.device, + image->base.memory, + 0, 0, 0, &myptr); + + cookie = xcb_put_image(chain->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, + chain->window, + chain->gc, + image->base.row_pitches[0] / 4, + chain->extent.height, + 0,0,0,24, + image->base.row_pitches[0] * chain->extent.height, + myptr); + + chain->base.wsi->UnmapMemory(chain->base.device, image->base.memory); + xcb_discard_reply(chain->conn, cookie.sequence); + xcb_flush(chain->conn); + return x11_swapchain_result(chain, VK_SUCCESS); +} +static VkResult +x11_present_to_x11(struct x11_swapchain *chain, uint32_t image_index, + uint32_t target_msc) +{ + if (chain->base.wsi->sw) + return x11_present_to_x11_sw(chain, image_index, target_msc); + return x11_present_to_x11_dri3(chain, image_index, target_msc); +} + +static VkResult x11_acquire_next_image(struct wsi_swapchain *anv_chain, const VkAcquireNextImageInfoKHR *info, uint32_t *image_index) @@ -1085,6 +1123,10 @@ x11_acquire_next_image(struct wsi_swapchain *anv_chain, if (chain->status < 0) return chain->status; + if (chain->base.wsi->sw) { + *image_index = 0; + return VK_SUCCESS; + } if (chain->has_acquire_queue) { return x11_acquire_next_image_from_queue(chain, image_index, timeout); } else { @@ -1204,6 +1246,10 @@ x11_image_init(VkDevice device_h, struct x11_swapchain *chain, if (result < 0) return result; + if (chain->base.wsi->sw) { + image->busy = false; + return VK_SUCCESS; + } image->pixmap = xcb_generate_id(chain->conn); #ifdef HAVE_DRI3_MODIFIERS @@ -1292,12 +1338,14 @@ x11_image_finish(struct x11_swapchain *chain, { xcb_void_cookie_t cookie; - cookie = xcb_sync_destroy_fence(chain->conn, image->sync_fence); - xcb_discard_reply(chain->conn, cookie.sequence); - xshmfence_unmap_shm(image->shm_fence); + if (!chain->base.wsi->sw) { + cookie = xcb_sync_destroy_fence(chain->conn, image->sync_fence); + xcb_discard_reply(chain->conn, cookie.sequence); + xshmfence_unmap_shm(image->shm_fence); - cookie = xcb_free_pixmap(chain->conn, image->pixmap); - xcb_discard_reply(chain->conn, cookie.sequence); + cookie = xcb_free_pixmap(chain->conn, image->pixmap); + xcb_discard_reply(chain->conn, cookie.sequence); + } wsi_destroy_image(&chain->base, &image->base); } @@ -1518,8 +1566,9 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, else chain->last_present_mode = XCB_PRESENT_COMPLETE_MODE_COPY; - if (!wsi_x11_check_dri3_compatible(wsi_device, conn)) - chain->base.use_prime_blit = true; + if (!wsi_device->sw) + if (!wsi_x11_check_dri3_compatible(wsi_device, conn)) + chain->base.use_prime_blit = true; chain->event_id = xcb_generate_id(chain->conn); xcb_present_select_input(chain->conn, chain->event_id, chain->window, @@ -1567,8 +1616,8 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, goto fail_init_images; } - if (chain->base.present_mode == VK_PRESENT_MODE_FIFO_KHR || - chain->base.present_mode == VK_PRESENT_MODE_MAILBOX_KHR) { + if ((chain->base.present_mode == VK_PRESENT_MODE_FIFO_KHR || + chain->base.present_mode == VK_PRESENT_MODE_MAILBOX_KHR) && !chain->base.wsi->sw) { chain->has_present_queue = true; /* Initialize our queues. We make them base.image_count + 1 because we will |