From 4be0e92db10584bc3526884b92aa483458aa93af Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 21 Dec 2020 14:49:50 +1000 Subject: [PATCH] lavapipe: refactor image surface creation There is a need to create arbitrary surfaces for clearing, so split out the templating from the storing to img->vk_surface so temporary surfaces can be created for clearing. Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/frontends/lavapipe/lvp_execute.c | 41 +++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/gallium/frontends/lavapipe/lvp_execute.c b/src/gallium/frontends/lavapipe/lvp_execute.c index cfc77ae38a9..3c85dcd86d0 100644 --- a/src/gallium/frontends/lavapipe/lvp_execute.c +++ b/src/gallium/frontends/lavapipe/lvp_execute.c @@ -1096,25 +1096,36 @@ static void handle_descriptor_sets(struct lvp_cmd_buffer_entry *cmd, } } +static struct pipe_surface *create_img_surface(struct rendering_state *state, + struct lvp_image_view *imgv, + VkFormat format, int width, + int height, + int base_layer, int layer_count) +{ + struct pipe_surface template; + + memset(&template, 0, sizeof(struct pipe_surface)); + + template.format = vk_format_to_pipe(format); + template.width = width; + template.height = height; + template.u.tex.first_layer = imgv->subresourceRange.baseArrayLayer + base_layer; + template.u.tex.last_layer = imgv->subresourceRange.baseArrayLayer + layer_count; + template.u.tex.level = imgv->subresourceRange.baseMipLevel; + + if (template.format == PIPE_FORMAT_NONE) + return NULL; + return state->pctx->create_surface(state->pctx, + imgv->image->bo, &template); + +} static void add_img_view_surface(struct rendering_state *state, struct lvp_image_view *imgv, VkFormat format, int width, int height) { if (!imgv->surface) { - struct pipe_surface template; - - memset(&template, 0, sizeof(struct pipe_surface)); - - template.format = vk_format_to_pipe(format); - template.width = width; - template.height = height; - template.u.tex.first_layer = imgv->subresourceRange.baseArrayLayer; - template.u.tex.last_layer = imgv->subresourceRange.baseArrayLayer + lvp_get_layerCount(imgv->image, &imgv->subresourceRange) - 1; - template.u.tex.level = imgv->subresourceRange.baseMipLevel; - - if (template.format == PIPE_FORMAT_NONE) - return; - imgv->surface = state->pctx->create_surface(state->pctx, - imgv->image->bo, &template); + imgv->surface = create_img_surface(state, imgv, format, + width, height, + 0, lvp_get_layerCount(imgv->image, &imgv->subresourceRange) - 1); } }