From 21d39dd1deb03366f54c4d7bfa09835cab0f1ca9 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 26 Sep 2022 09:13:37 +1000 Subject: [PATCH] lavapipe: take layers into account around render surface creation. This makes the code more consistent with handling layers, but also makes sure a new surface is created when the w/h/layers changes. Fixes: 8a6160a354282 ("lavapipe: VK_KHR_dynamic_rendering") Reviewed-By: Mike Blumenkrantz Part-of: --- src/gallium/frontends/lavapipe/lvp_execute.c | 24 ++++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/gallium/frontends/lavapipe/lvp_execute.c b/src/gallium/frontends/lavapipe/lvp_execute.c index 2e795c697c6..01cb188175b 100644 --- a/src/gallium/frontends/lavapipe/lvp_execute.c +++ b/src/gallium/frontends/lavapipe/lvp_execute.c @@ -1327,7 +1327,7 @@ static struct pipe_surface *create_img_surface_bo(struct rendering_state *state, template.width = width; template.height = height; template.u.tex.first_layer = range->baseArrayLayer + base_layer; - template.u.tex.last_layer = range->baseArrayLayer + layer_count; + template.u.tex.last_layer = range->baseArrayLayer + base_layer + layer_count - 1; template.u.tex.level = range->baseMipLevel + level; if (template.format == PIPE_FORMAT_NONE) @@ -1351,12 +1351,20 @@ static struct pipe_surface *create_img_surface(struct rendering_state *state, } static void add_img_view_surface(struct rendering_state *state, - struct lvp_image_view *imgv, int width, int height) + struct lvp_image_view *imgv, int width, int height, + int layer_count) { + if (imgv->surface) { + if (imgv->surface->width != width || + imgv->surface->height != height || + (imgv->surface->u.tex.last_layer - imgv->surface->u.tex.first_layer) != (layer_count - 1)) + pipe_surface_reference(&imgv->surface, NULL); + } + if (!imgv->surface) { imgv->surface = create_img_surface(state, imgv, imgv->vk.format, width, height, - 0, imgv->vk.layer_count - 1); + 0, layer_count); } } @@ -1388,7 +1396,7 @@ static void clear_attachment_layers(struct rendering_state *state, state->framebuffer.width, state->framebuffer.height, base_layer, - base_layer + layer_count - 1); + layer_count); if (ds_clear_flags) { state->pctx->clear_depth_stencil(state->pctx, @@ -1780,7 +1788,8 @@ static void handle_begin_rendering(struct vk_cmd_queue_entry *cmd, if (state->color_att[i].imgv) { struct lvp_image_view *imgv = state->color_att[i].imgv; add_img_view_surface(state, imgv, - state->framebuffer.width, state->framebuffer.height); + state->framebuffer.width, state->framebuffer.height, + state->framebuffer.layers); if (state->forced_sample_count && imgv->image->vk.samples == 1) state->color_att[i].imgv = create_multisample_surface(state, imgv, state->forced_sample_count, att_needs_replicate(state, imgv, state->color_att[i].load_op)); @@ -1800,7 +1809,8 @@ static void handle_begin_rendering(struct vk_cmd_queue_entry *cmd, state->stencil_att.imgv; struct lvp_image_view *imgv = state->ds_imgv; add_img_view_surface(state, imgv, - state->framebuffer.width, state->framebuffer.height); + state->framebuffer.width, state->framebuffer.height, + state->framebuffer.layers); if (state->forced_sample_count && imgv->image->vk.samples == 1) { VkAttachmentLoadOp load_op; if (state->depth_att.load_op == VK_ATTACHMENT_LOAD_OP_CLEAR || @@ -2911,7 +2921,7 @@ static void handle_clear_ds_image(struct vk_cmd_queue_entry *cmd, surf = create_img_surface_bo(state, range, image->bo, image->bo->format, width, height, - 0, depth - 1, j); + 0, depth, j); state->pctx->clear_depth_stencil(state->pctx, surf,