vulkan/wsi: Persistently map CPU images

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17388>
This commit is contained in:
Jason Ekstrand 2022-07-06 18:52:32 -05:00
parent 1d0290fbfe
commit cf37837d36
4 changed files with 13 additions and 18 deletions

View file

@ -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;

View file

@ -85,6 +85,7 @@ struct wsi_image {
#ifndef _WIN32
int dma_buf_fd;
#endif
void *cpu_map;
};
struct wsi_swapchain {

View file

@ -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) {

View file

@ -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);
}