diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c index d621d35edc9..5b2b005a308 100644 --- a/src/vulkan/wsi/wsi_common.c +++ b/src/vulkan/wsi/wsi_common.c @@ -547,6 +547,9 @@ wsi_destroy_image(const struct wsi_swapchain *chain, close(image->dma_buf_fd); #endif + if (image->cpu_map != NULL) + wsi->UnmapMemory(chain->device, image->memory); + if (image->buffer.blit_cmd_buffers) { int cmd_buffer_count = chain->buffer_blit_queue != VK_NULL_HANDLE ? 1 : wsi->queue_family_count; @@ -1567,6 +1570,11 @@ wsi_create_cpu_image_mem(const struct wsi_swapchain *chain, if (result != VK_SUCCESS) return result; + result = wsi->MapMemory(chain->device, image->memory, + 0, VK_WHOLE_SIZE, 0, &image->cpu_map); + if (result != VK_SUCCESS) + return result; + image->num_planes = 1; image->sizes[0] = reqs.size; image->row_pitches[0] = layout.rowPitch; diff --git a/src/vulkan/wsi/wsi_common_private.h b/src/vulkan/wsi/wsi_common_private.h index 992ebf448b4..8db8014a178 100644 --- a/src/vulkan/wsi/wsi_common_private.h +++ b/src/vulkan/wsi/wsi_common_private.h @@ -85,6 +85,7 @@ struct wsi_image { #ifndef _WIN32 int dma_buf_fd; #endif + void *cpu_map; }; struct wsi_swapchain { diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index e6d0e28b82b..097c732c669 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -1045,17 +1045,8 @@ wsi_wl_swapchain_queue_present(struct wsi_swapchain *wsi_chain, if (chain->display->sw) { struct wsi_wl_image *image = &chain->images[image_index]; - void *dptr = image->data_ptr; - void *sptr; - chain->base.wsi->MapMemory(chain->base.device, - image->base.memory, - 0, VK_WHOLE_SIZE, 0, &sptr); - - memcpy(dptr, sptr, image->base.row_pitches[0] * chain->extent.height); - - chain->base.wsi->UnmapMemory(chain->base.device, - image->base.memory); - + memcpy(image->data_ptr, image->base.cpu_map, + image->base.row_pitches[0] * chain->extent.height); } if (chain->base.present_mode == VK_PRESENT_MODE_FIFO_KHR) { while (!chain->fifo_ready) { diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c index 5221b430947..eaabaceafb7 100644 --- a/src/vulkan/wsi/wsi_common_x11.c +++ b/src/vulkan/wsi/wsi_common_x11.c @@ -1290,16 +1290,12 @@ x11_present_to_x11_sw(struct x11_swapchain *chain, uint32_t image_index, struct x11_image *image = &chain->images[image_index]; xcb_void_cookie_t cookie; - void *myptr; + void *myptr = image->base.cpu_map; size_t hdr_len = sizeof(xcb_put_image_request_t); int stride_b = image->base.row_pitches[0]; size_t size = (hdr_len + stride_b * chain->extent.height) >> 2; uint64_t max_req_len = xcb_get_maximum_request_length(chain->conn); - chain->base.wsi->MapMemory(chain->base.device, - image->base.memory, - 0, VK_WHOLE_SIZE, 0, &myptr); - if (size < max_req_len) { cookie = xcb_put_image(chain->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, chain->window, @@ -1308,7 +1304,7 @@ x11_present_to_x11_sw(struct x11_swapchain *chain, uint32_t image_index, chain->extent.height, 0,0,0,24, image->base.row_pitches[0] * chain->extent.height, - myptr); + image->base.cpu_map); xcb_discard_reply(chain->conn, cookie.sequence); } else { int num_lines = ((max_req_len << 2) - hdr_len) / stride_b; @@ -1330,7 +1326,6 @@ x11_present_to_x11_sw(struct x11_swapchain *chain, uint32_t image_index, } } - chain->base.wsi->UnmapMemory(chain->base.device, image->base.memory); xcb_flush(chain->conn); return x11_swapchain_result(chain, VK_SUCCESS); }