[Mesa-dev] [PATCH 4/4] swr: clear every layer of the attached surfaces

Rowley, Timothy O timothy.o.rowley at intel.com
Wed Nov 23 20:32:00 UTC 2016


Ah, didn’t notice that they were all shifted by arrayIndex.  Fine to leave the changes as they are, then.

This series of four patches (or rather, the rebased versions in your repo) are Reviewed-by: Tim Rowley <timothy.o.rowley at intel.com<mailto:timothy.o.rowley at intel.com>>


On Nov 23, 2016, at 2:11 PM, Ilia Mirkin <imirkin at alum.mit.edu<mailto:imirkin at alum.mit.edu>> wrote:

On Wed, Nov 23, 2016 at 3:02 PM, Rowley, Timothy O
<timothy.o.rowley at intel.com<mailto:timothy.o.rowley at intel.com>> wrote:
This code seems to assume that all attached buffers have the same start layer, and that start will be zero.  Maybe it should construct the clearMask inside the layer loop, which would also be a bit clearer than the code you added to drop bits out of the mask?

They have a logical start layer which is the same (0), since the real
start layer is in the SWR_SURFACE_STATE's arrayIndex. The arrayIndex
is added to the renderTargetArrayIndex to compute a final layer to
operate on.

If you'd like to simplify this code, I could just clear every
attachment/layer one at a time rather than trying to do it in fewer
steps. I suspect that the end effect on the swr backend will be
largely identical.

 -ilia


-Tim

On Nov 17, 2016, at 6:51 PM, Ilia Mirkin <imirkin at alum.mit.edu<mailto:imirkin at alum.mit.edu>> wrote:

Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu<mailto:imirkin at alum.mit.edu>>
---

With this patch, the layered-rendering clear tests pass, both with fast clear
enabled and disabled.

src/gallium/drivers/swr/swr_clear.cpp | 35 +++++++++++++++++++++++++++++------
1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/swr/swr_clear.cpp b/src/gallium/drivers/swr/swr_clear.cpp
index 25f066e..7ac308e 100644
--- a/src/gallium/drivers/swr/swr_clear.cpp
+++ b/src/gallium/drivers/swr/swr_clear.cpp
@@ -35,6 +35,7 @@ swr_clear(struct pipe_context *pipe,
  struct pipe_framebuffer_state *fb = &ctx->framebuffer;

  UINT clearMask = 0;
+   int layers = 0;

  if (!swr_check_render_cond(pipe))
     return;
@@ -44,24 +45,46 @@ swr_clear(struct pipe_context *pipe,

  if (buffers & PIPE_CLEAR_COLOR && fb->nr_cbufs) {
     for (unsigned i = 0; i < fb->nr_cbufs; ++i)
-         if (fb->cbufs[i])
+         if (fb->cbufs[i] && (buffers & (PIPE_CLEAR_COLOR0 << i))) {
           clearMask |= (SWR_ATTACHMENT_COLOR0_BIT << i);
+            layers = std::max(layers, fb->cbufs[i]->u.tex.last_layer -
+                                      fb->cbufs[i]->u.tex.first_layer + 1);
+         }
  }

-   if (buffers & PIPE_CLEAR_DEPTH && fb->zsbuf)
+   if (buffers & PIPE_CLEAR_DEPTH && fb->zsbuf) {
     clearMask |= SWR_ATTACHMENT_DEPTH_BIT;
+      layers = std::max(layers, fb->zsbuf->u.tex.last_layer -
+                                fb->zsbuf->u.tex.first_layer + 1);
+   }

-   if (buffers & PIPE_CLEAR_STENCIL && fb->zsbuf)
+   if (buffers & PIPE_CLEAR_STENCIL && fb->zsbuf) {
     clearMask |= SWR_ATTACHMENT_STENCIL_BIT;
+      layers = std::max(layers, fb->zsbuf->u.tex.last_layer -
+                                fb->zsbuf->u.tex.first_layer + 1);
+   }

#if 0 // XXX HACK, override clear color alpha. On ubuntu, clears are
     // transparent.
  ((union pipe_color_union *)color)->f[3] = 1.0; /* cast off your const'd-ness */
#endif

-   swr_update_draw_context(ctx);
-   SwrClearRenderTarget(ctx->swrContext, clearMask, 0, color->f, depth, stencil,
-                        ctx->swr_scissor);
+   for (int i = 0; i < layers; ++i) {
+      swr_update_draw_context(ctx);
+      SwrClearRenderTarget(ctx->swrContext, clearMask, i,
+                           color->f, depth, stencil,
+                           ctx->swr_scissor);
+
+      // Mask out the attachments that are out of layers.
+      if (fb->zsbuf &&
+          fb->zsbuf->u.tex.last_layer - fb->zsbuf->u.tex.first_layer <= i)
+         clearMask &= ~(SWR_ATTACHMENT_DEPTH_BIT | SWR_ATTACHMENT_STENCIL_BIT);
+      for (unsigned c = 0; c < fb->nr_cbufs; ++c) {
+         const struct pipe_surface *sf = fb->cbufs[c];
+         if (sf && sf->u.tex.last_layer - sf->u.tex.first_layer <= i)
+            clearMask &= ~(SWR_ATTACHMENT_COLOR0_BIT << c);
+      }
+   }
}


--
2.7.3



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20161123/b9eb4fd6/attachment-0001.html>


More information about the mesa-dev mailing list