<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Ah, didn’t notice that they were all shifted by arrayIndex.  Fine to leave the changes as they are, then.
<div class=""><br class="">
</div>
<div class="">This series of four patches (or rather, the rebased versions in your repo) are Reviewed-by: Tim Rowley <<a href="mailto:timothy.o.rowley@intel.com" class="">timothy.o.rowley@intel.com</a>></div>
<div class=""><br class="">
</div>
<div class=""><br class="">
<div class="">
<div>
<blockquote type="cite" class="">
<div class="">On Nov 23, 2016, at 2:11 PM, Ilia Mirkin <<a href="mailto:imirkin@alum.mit.edu" class="">imirkin@alum.mit.edu</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">On Wed, Nov 23, 2016 at 3:02 PM, Rowley, Timothy O<br class="">
<<a href="mailto:timothy.o.rowley@intel.com" class="">timothy.o.rowley@intel.com</a>> wrote:<br class="">
<blockquote type="cite" class="">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?<br class="">
</blockquote>
<br class="">
They have a logical start layer which is the same (0), since the real<br class="">
start layer is in the SWR_SURFACE_STATE's arrayIndex. The arrayIndex<br class="">
is added to the renderTargetArrayIndex to compute a final layer to<br class="">
operate on.<br class="">
<br class="">
If you'd like to simplify this code, I could just clear every<br class="">
attachment/layer one at a time rather than trying to do it in fewer<br class="">
steps. I suspect that the end effect on the swr backend will be<br class="">
largely identical.<br class="">
<br class="">
 -ilia<br class="">
<br class="">
<blockquote type="cite" class=""><br class="">
-Tim<br class="">
<br class="">
<blockquote type="cite" class="">On Nov 17, 2016, at 6:51 PM, Ilia Mirkin <<a href="mailto:imirkin@alum.mit.edu" class="">imirkin@alum.mit.edu</a>> wrote:<br class="">
<br class="">
Signed-off-by: Ilia Mirkin <<a href="mailto:imirkin@alum.mit.edu" class="">imirkin@alum.mit.edu</a>><br class="">
---<br class="">
<br class="">
With this patch, the layered-rendering clear tests pass, both with fast clear<br class="">
enabled and disabled.<br class="">
<br class="">
src/gallium/drivers/swr/swr_clear.cpp | 35 +++++++++++++++++++++++++++++------<br class="">
1 file changed, 29 insertions(+), 6 deletions(-)<br class="">
<br class="">
diff --git a/src/gallium/drivers/swr/swr_clear.cpp b/src/gallium/drivers/swr/swr_clear.cpp<br class="">
index 25f066e..7ac308e 100644<br class="">
--- a/src/gallium/drivers/swr/swr_clear.cpp<br class="">
+++ b/src/gallium/drivers/swr/swr_clear.cpp<br class="">
@@ -35,6 +35,7 @@ swr_clear(struct pipe_context *pipe,<br class="">
  struct pipe_framebuffer_state *fb = &ctx->framebuffer;<br class="">
<br class="">
  UINT clearMask = 0;<br class="">
+   int layers = 0;<br class="">
<br class="">
  if (!swr_check_render_cond(pipe))<br class="">
     return;<br class="">
@@ -44,24 +45,46 @@ swr_clear(struct pipe_context *pipe,<br class="">
<br class="">
  if (buffers & PIPE_CLEAR_COLOR && fb->nr_cbufs) {<br class="">
     for (unsigned i = 0; i < fb->nr_cbufs; ++i)<br class="">
-         if (fb->cbufs[i])<br class="">
+         if (fb->cbufs[i] && (buffers & (PIPE_CLEAR_COLOR0 << i))) {<br class="">
           clearMask |= (SWR_ATTACHMENT_COLOR0_BIT << i);<br class="">
+            layers = std::max(layers, fb->cbufs[i]->u.tex.last_layer -<br class="">
+                                      fb->cbufs[i]->u.tex.first_layer + 1);<br class="">
+         }<br class="">
  }<br class="">
<br class="">
-   if (buffers & PIPE_CLEAR_DEPTH && fb->zsbuf)<br class="">
+   if (buffers & PIPE_CLEAR_DEPTH && fb->zsbuf) {<br class="">
     clearMask |= SWR_ATTACHMENT_DEPTH_BIT;<br class="">
+      layers = std::max(layers, fb->zsbuf->u.tex.last_layer -<br class="">
+                                fb->zsbuf->u.tex.first_layer + 1);<br class="">
+   }<br class="">
<br class="">
-   if (buffers & PIPE_CLEAR_STENCIL && fb->zsbuf)<br class="">
+   if (buffers & PIPE_CLEAR_STENCIL && fb->zsbuf) {<br class="">
     clearMask |= SWR_ATTACHMENT_STENCIL_BIT;<br class="">
+      layers = std::max(layers, fb->zsbuf->u.tex.last_layer -<br class="">
+                                fb->zsbuf->u.tex.first_layer + 1);<br class="">
+   }<br class="">
<br class="">
#if 0 // XXX HACK, override clear color alpha. On ubuntu, clears are<br class="">
     // transparent.<br class="">
  ((union pipe_color_union *)color)->f[3] = 1.0; /* cast off your const'd-ness */<br class="">
#endif<br class="">
<br class="">
-   swr_update_draw_context(ctx);<br class="">
-   SwrClearRenderTarget(ctx->swrContext, clearMask, 0, color->f, depth, stencil,<br class="">
-                        ctx->swr_scissor);<br class="">
+   for (int i = 0; i < layers; ++i) {<br class="">
+      swr_update_draw_context(ctx);<br class="">
+      SwrClearRenderTarget(ctx->swrContext, clearMask, i,<br class="">
+                           color->f, depth, stencil,<br class="">
+                           ctx->swr_scissor);<br class="">
+<br class="">
+      // Mask out the attachments that are out of layers.<br class="">
+      if (fb->zsbuf &&<br class="">
+          fb->zsbuf->u.tex.last_layer - fb->zsbuf->u.tex.first_layer <= i)<br class="">
+         clearMask &= ~(SWR_ATTACHMENT_DEPTH_BIT | SWR_ATTACHMENT_STENCIL_BIT);<br class="">
+      for (unsigned c = 0; c < fb->nr_cbufs; ++c) {<br class="">
+         const struct pipe_surface *sf = fb->cbufs[c];<br class="">
+         if (sf && sf->u.tex.last_layer - sf->u.tex.first_layer <= i)<br class="">
+            clearMask &= ~(SWR_ATTACHMENT_COLOR0_BIT << c);<br class="">
+      }<br class="">
+   }<br class="">
}<br class="">
<br class="">
<br class="">
--<br class="">
2.7.3<br class="">
<br class="">
</blockquote>
<br class="">
</blockquote>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</body>
</html>