From bf67eb342bccce285053b0080a1c63ab31800438 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Wed, 26 Jun 2024 21:52:30 +0200 Subject: [PATCH] render/vulkan: vkMapMemory stage spans up front We always need these mapped for CPU access, so map it up front instead of duplicating lazy mapping at each site of use. --- render/vulkan/pass.c | 7 ------- render/vulkan/renderer.c | 6 ++++++ render/vulkan/texture.c | 11 ----------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/render/vulkan/pass.c b/render/vulkan/pass.c index 852bb64f..c879b71c 100644 --- a/render/vulkan/pass.c +++ b/render/vulkan/pass.c @@ -822,13 +822,6 @@ static bool create_3d_lut_image(struct wlr_vk_renderer *renderer, goto fail_imageview; } - if (!span.buffer->cpu_mapping) { - res = vkMapMemory(dev, span.buffer->memory, 0, VK_WHOLE_SIZE, 0, &span.buffer->cpu_mapping); - if (res != VK_SUCCESS) { - wlr_vk_error("vkMapMemory", res); - goto fail_imageview; - } - } char *map = (char*)span.buffer->cpu_mapping + span.alloc.start; float *dst = (float*)map; size_t dim_len = lut_3d->dim_len; diff --git a/render/vulkan/renderer.c b/render/vulkan/renderer.c index 5535cc4f..32effb5a 100644 --- a/render/vulkan/renderer.c +++ b/render/vulkan/renderer.c @@ -309,6 +309,12 @@ struct wlr_vk_buffer_span vulkan_get_stage_span(struct wlr_vk_renderer *r, goto error; } + res = vkMapMemory(r->dev->dev, buf->memory, 0, VK_WHOLE_SIZE, 0, &buf->cpu_mapping); + if (res != VK_SUCCESS) { + wlr_vk_error("vkMapMemory", res); + goto error; + } + struct wlr_vk_allocation *a = wl_array_add(&buf->allocs, sizeof(*a)); if (a == NULL) { wlr_log_errno(WLR_ERROR, "Allocation failed"); diff --git a/render/vulkan/texture.c b/render/vulkan/texture.c index 086f59f8..c4053313 100644 --- a/render/vulkan/texture.c +++ b/render/vulkan/texture.c @@ -41,9 +41,7 @@ static bool write_pixels(struct wlr_vk_texture *texture, uint32_t stride, const pixman_region32_t *region, const void *vdata, VkImageLayout old_layout, VkPipelineStageFlags src_stage, VkAccessFlags src_access) { - VkResult res; struct wlr_vk_renderer *renderer = texture->renderer; - VkDevice dev = texture->renderer->dev->dev; const struct wlr_pixel_format_info *format_info = drm_get_pixel_format_info(texture->format->drm); assert(format_info); @@ -79,15 +77,6 @@ static bool write_pixels(struct wlr_vk_texture *texture, free(copies); return false; } - - if (!span.buffer->cpu_mapping) { - res = vkMapMemory(dev, span.buffer->memory, 0, VK_WHOLE_SIZE, 0, &span.buffer->cpu_mapping); - if (res != VK_SUCCESS) { - wlr_vk_error("vkMapMemory", res); - free(copies); - return false; - } - } char *map = (char*)span.buffer->cpu_mapping + span.alloc.start; // upload data