<p dir="ltr">As much as memset clears amuse me, I have to nak this patch as is.  The memset you are using doesn't properly account for the Y-tiled format of the MCs buffer for certain surface sizes.  I can explain more later but the short version is that the total_height parameter we have in intel_mipmap_tree may not be the full height of the tiled buffer.  The total_height is only 4-aligned while the buffer is going to be 32-aligned (I think). The result is a partially-cleared surface.  Incidentally, I think the memset we use when we create the MCs is wrong too.<br>
--Jason</p>
<div class="gmail_quote">On Sep 25, 2014 11:28 AM, "Kenneth Graunke" <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Fast color clears simply fill the MCS buffer with 0xff.  If the MCS BO<br>
is not busy, we can map it without stalling and simply use memset to do<br>
that, without having to reprogram the entire GPU, draw rectangles, and<br>
invoke pixel shaders.  This is presumably cheaper.<br>
<br>
This code was swiped from intel_miptree_alloc_mcs, which clears the<br>
buffer using memset when allocating the MCS.<br>
<br>
Improves performance in GpuTest Triangle by 5.09439% +/- 1.27536%.<br>
Xonotic, EgyptHD, and many others also hit this path, but I was not<br>
able to measure any performance increase in other applications.<br>
<br>
Signed-off-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
<br>
Concerns I have which hopefully reviewers can address:<br>
- Do we need to worry about clipping/scissoring/etc?  I think our<br>
fast color clear implementation only handles full surface clears, so we<br>
should be OK.<br>
- Do we need to check if the miptree BO is referenced/busy?  Or is<br>
  checking the MCS really sufficient?<br>
---<br>
 src/mesa/drivers/dri/i965/brw_meta_fast_clear.c | 13 +++++++++++++<br>
 1 file changed, 13 insertions(+)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_meta_fast_clear.c b/src/mesa/drivers/dri/i965/brw_meta_fast_clear.c<br>
index b4e75a7..43df2d0 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_meta_fast_clear.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_meta_fast_clear.c<br>
@@ -503,6 +503,19 @@ brw_meta_fast_clear(struct brw_context *brw, struct gl_framebuffer *fb,<br>
          if (irb->mt->fast_clear_state == INTEL_FAST_CLEAR_STATE_CLEAR)<br>
             continue;<br>
<br>
+         /* If the MCS isn't busy, just do a CPU-side memset rather than<br>
+          * reprogramming the whole GPU.<br>
+          */<br>
+         if (!drm_intel_bo_references(brw-><a href="http://batch.bo" target="_blank">batch.bo</a>, irb->mt->mcs_mt->bo) &&<br>
+             !drm_intel_bo_busy(irb->mt->mcs_mt->bo)) {<br>
+            void *data = intel_miptree_map_raw(brw, irb->mt->mcs_mt);<br>
+            memset(data, 0xff,<br>
+                   irb->mt->mcs_mt->total_height * irb->mt->mcs_mt->pitch);<br>
+            intel_miptree_unmap_raw(brw, irb->mt->mcs_mt);<br>
+            irb->mt->fast_clear_state = INTEL_FAST_CLEAR_STATE_CLEAR;<br>
+            continue;<br>
+         }<br>
+<br>
          /* Set fast_clear_state to RESOLVED so we don't try resolve them when<br>
           * we draw, in case the mt is also bound as a texture.<br>
           */<br>
--<br>
2.1.0<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</blockquote></div>