Mesa (master): lavapipe: rewrite attachment clearing for conditional rendering.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jan 27 01:28:57 UTC 2021


Module: Mesa
Branch: master
Commit: a57361ae02807207948fc1e9b2734caf1747178e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a57361ae02807207948fc1e9b2734caf1747178e

Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Dec 21 14:54:58 2020 +1000

lavapipe: rewrite attachment clearing for conditional rendering.

Attachment clears have to respect cond rendering, so they can't
call clear texture directly, they have to create temporary
surfaces and clear via those.

Reviewed-by: Roland Scheidegger <sroland at vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8182>

---

 src/gallium/frontends/lavapipe/lvp_execute.c | 59 ++++++++++++++++++++--------
 1 file changed, 42 insertions(+), 17 deletions(-)

diff --git a/src/gallium/frontends/lavapipe/lvp_execute.c b/src/gallium/frontends/lavapipe/lvp_execute.c
index 3c85dcd86d0..5f6ac808d01 100644
--- a/src/gallium/frontends/lavapipe/lvp_execute.c
+++ b/src/gallium/frontends/lavapipe/lvp_execute.c
@@ -2265,25 +2265,50 @@ static void handle_clear_attachments(struct lvp_cmd_buffer_entry *cmd,
             continue;
          imgv = state->vk_framebuffer->attachments[ds_att->attachment];
       }
-      uint32_t col_val[4];
-      if (util_format_is_depth_or_stencil(imgv->pformat)) {
-         int64_t val = util_pack64_z_stencil(imgv->pformat, att->clearValue.depthStencil.depth, att->clearValue.depthStencil.stencil);
-         memcpy(col_val, &val, 8);
-      } else
-         pack_clear_color(imgv->pformat, &att->clearValue.color, col_val);
+      union pipe_color_union col_val;
+      double dclear_val = 0;
+      uint32_t sclear_val = 0;
+      uint32_t ds_clear_flags = 0;
+      if (att->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
+         ds_clear_flags |= PIPE_CLEAR_DEPTH;
+         dclear_val = att->clearValue.depthStencil.depth;
+      }
+      if (att->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) {
+         ds_clear_flags |= PIPE_CLEAR_STENCIL;
+         sclear_val = att->clearValue.depthStencil.stencil;
+      }
+      if (att->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) {
+         for (unsigned i = 0; i < 4; i++)
+            col_val.ui[i] = att->clearValue.color.uint32[i];
+      }
+
       for (uint32_t r = 0; r < cmd->u.clear_attachments.rect_count; r++) {
-         struct pipe_box box;
+
          VkClearRect *rect = &cmd->u.clear_attachments.rects[r];
-         box.x = rect->rect.offset.x;
-         box.y = rect->rect.offset.y;
-         box.z = imgv->subresourceRange.baseArrayLayer + rect->baseArrayLayer;
-         box.width = rect->rect.extent.width;
-         box.height = rect->rect.extent.height;
-         box.depth = rect->layerCount;
-
-         state->pctx->clear_texture(state->pctx, imgv->image->bo,
-                                    imgv->subresourceRange.baseMipLevel,
-                                    &box, col_val);
+         struct pipe_surface *clear_surf = create_img_surface(state,
+                                                              imgv,
+                                                              imgv->format,
+                                                              state->framebuffer.width,
+                                                              state->framebuffer.height,
+                                                              rect->baseArrayLayer,
+                                                              rect->baseArrayLayer + rect->layerCount - 1);
+
+         if (ds_clear_flags) {
+            state->pctx->clear_depth_stencil(state->pctx,
+                                             clear_surf,
+                                             ds_clear_flags,
+                                             dclear_val, sclear_val,
+                                             rect->rect.offset.x, rect->rect.offset.y,
+                                             rect->rect.extent.width, rect->rect.extent.height,
+                                             true);
+         } else {
+            state->pctx->clear_render_target(state->pctx, clear_surf,
+                                             &col_val,
+                                             rect->rect.offset.x, rect->rect.offset.y,
+                                             rect->rect.extent.width, rect->rect.extent.height,
+                                             true);
+         }
+         state->pctx->surface_destroy(state->pctx, clear_surf);
       }
    }
 }



More information about the mesa-commit mailing list