render/vulkan: keep wlr_vk_shared_buffer mapped

This commit is contained in:
Simon Ser 2023-11-24 20:13:31 +01:00
parent 50b471e035
commit 79cbbfb366
3 changed files with 12 additions and 13 deletions

View file

@ -436,6 +436,7 @@ struct wlr_vk_shared_buffer {
VkBuffer buffer;
VkDeviceMemory memory;
VkDeviceSize buf_size;
void *map;
struct wl_array allocs; // struct wlr_vk_allocation
};

View file

@ -178,6 +178,9 @@ static void shared_buffer_destroy(struct wlr_vk_renderer *r,
}
wl_array_release(&buffer->allocs);
if (buffer->map) {
vkUnmapMemory(r->dev->dev, buffer->memory);
}
if (buffer->buffer) {
vkDestroyBuffer(r->dev->dev, buffer->buffer, NULL);
}
@ -302,6 +305,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->map);
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");

View file

@ -78,7 +78,6 @@ static bool write_pixels(struct wlr_vk_texture *texture,
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);
@ -145,20 +144,10 @@ static bool write_pixels(struct wlr_vk_texture *texture,
buf_off += height * packed_stride;
}
void *vmap;
res = vkMapMemory(dev, span.buffer->memory, span.alloc.start,
bsize, 0, &vmap);
if (res != VK_SUCCESS) {
wlr_vk_error("vkMapMemory", res);
free(copies);
return false;
}
copy_pixels(vmap, vdata, texture->wlr_texture.width,
char *dst = (char *)span.buffer->map + span.alloc.start;
copy_pixels(dst, vdata, texture->wlr_texture.width,
stride, bsize, region, format_info);
vkUnmapMemory(dev, span.buffer->memory);
VkSemaphoreSignalInfoKHR signal_info = {
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SIGNAL_INFO_KHR,
.semaphore = renderer->upload_timeline_semaphore,