<div dir="ltr"><div>I don't really like the helper because it seems like there should be a simpler way to do this.  That said, I don't know of one. :-)<br><br></div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 11, 2018 at 1:42 PM, Nanley Chery <span dir="ltr"><<a href="mailto:nanleychery@gmail.com" target="_blank">nanleychery@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This getter allows CNL to sample from fast-cleared sRGB textures correctly.<br>
---<br>
 src/mesa/drivers/dri/i965/brw_<wbr>blorp.c            | 13 ++++-------<br>
 src/mesa/drivers/dri/i965/brw_<wbr>wm_surface_state.c |  7 +++---<br>
 src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c    | 29 ++++++++++++++++++++++++<br>
 src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.h    |  8 +++++++<br>
 4 files changed, 46 insertions(+), 11 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>brw_blorp.c b/src/mesa/drivers/dri/i965/<wbr>brw_blorp.c<br>
index a1882abb7cb..48022bb1c4f 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>brw_blorp.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>brw_blorp.c<br>
@@ -166,7 +166,11 @@ blorp_surf_for_miptree(struct brw_context *brw,<br>
<span class="">       /* We only really need a clear color if we also have an auxiliary<br>
        * surface.  Without one, it does nothing.<br>
        */<br>
-      surf->clear_color = mt->fast_clear_color;<br>
+      surf->clear_color =<br>
+         intel_miptree_get_clear_color(<wbr>devinfo, mt, mt->surf.format,<br>
</span>+                                       !is_render_target, (struct brw_bo **)<br>
+                                       &surf->clear_color_addr.<wbr>buffer,<br>
+                                       &surf->clear_color_addr.<wbr>offset);<br>
<br>
       struct intel_miptree_aux_buffer *aux_buf =<br>
          intel_miptree_get_aux_buffer(<wbr>mt);<br>
@@ -178,13 +182,6 @@ blorp_surf_for_miptree(struct brw_context *brw,<br>
<br>
       surf->aux_addr.buffer = aux_buf->bo;<br>
       surf->aux_addr.offset = aux_buf->offset;<br>
-<br>
-      if (devinfo->gen >= 10) {<br>
-         surf->clear_color_addr = (struct blorp_address) {<br>
-            .buffer = aux_buf->clear_color_bo,<br>
-            .offset = aux_buf->clear_color_offset,<br>
-         };<br>
-      }<br>
    } else {<br>
<span class="">       surf->aux_addr = (struct blorp_address) {<br>
</span>          .buffer = NULL,<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/<wbr>brw_wm_surface_state.c<br>
index 3c70dbcc110..fb8e5942a11 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>brw_wm_surface_state.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>brw_wm_surface_state.c<br>
@@ -167,9 +167,10 @@ brw_emit_surface_state(struct brw_context *brw,<br>
<span class="">       /* We only really need a clear color if we also have an auxiliary<br>
        * surface.  Without one, it does nothing.<br>
        */<br>
</span>-      clear_bo = aux_buf->clear_color_bo;<br>
-      clear_offset = aux_buf->clear_color_offset;<br>
<span class="">-      clear_color = mt->fast_clear_color;<br>
+      clear_color =<br>
+         intel_miptree_get_clear_color(<wbr>devinfo, mt, view.format,<br>
</span>+                                       view.usage & ISL_SURF_USAGE_TEXTURE_BIT,<br>
+                                       &clear_bo, &clear_offset);<br>
<span class="">    }<br>
<br>
    void *state = brw_state_batch(brw,<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c b/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c<br>
</span>index c5791835409..88468399e1b 100644<br>
<span class="">--- a/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c<br>
@@ -46,6 +46,9 @@<br>
 #include "main/texcompress_etc.h"<br>
 #include "main/teximage.h"<br>
 #include "main/streaming-load-memcpy.h"<br>
+<br>
+#include "util/format_srgb.h"<br>
+<br>
 #include "x86/common_x86_asm.h"<br>
<br>
 #define FILE_DEBUG_FLAG DEBUG_MIPTREE<br>
</span>@@ -3802,3 +3805,29 @@ intel_miptree_set_depth_clear_<wbr>value(struct brw_context *brw,<br>
<span class="">    }<br>
    return false;<br>
 }<br>
+<br>
+union isl_color_value<br>
+intel_miptree_get_clear_<wbr>color(const struct gen_device_info *devinfo,<br>
+                              const struct intel_mipmap_tree *mt,<br>
</span>+                              enum isl_format view_format, bool sampling,<br>
+                              struct brw_bo **clear_color_bo,<br>
+                              uint32_t *clear_color_offset)<br>
+{<br>
+   assert(mt->aux_buf);<br>
+<br>
+   /* The gen10 sampler doesn't gamma-correct the clear color. */<br>
+   if (devinfo->gen == 10 && isl_format_is_srgb(view_<wbr>format) && sampling) {<br>
+      union isl_color_value srgb_decoded_value = mt->fast_clear_color;<br>
<span class="">+      for (unsigned i = 0; i < 3; i++) {<br>
</span>+         srgb_decoded_value.f32[i] =<br>
<span class="">+            util_format_srgb_to_linear_<wbr>float(mt->fast_clear_color.<wbr>f32[i]);<br>
+      }<br>
</span>+      *clear_color_bo = 0;<br>
+      *clear_color_offset = 0;<br>
+      return srgb_decoded_value;<br>
+   } else {<br>
+      *clear_color_bo = mt->aux_buf->clear_color_bo;<br>
+      *clear_color_offset = mt->aux_buf->clear_color_<wbr>offset;<br>
<span class="">+      return mt->fast_clear_color;<br>
+   }<br>
+}<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.h b/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.h<br>
</span>index 643de962d31..bb059cf4e8f 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.h<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.h<br>
@@ -735,6 +735,14 @@ intel_miptree_set_clear_color(<wbr>struct brw_context *brw,<br>
<span class="">                               struct intel_mipmap_tree *mt,<br>
                               const union gl_color_union *color);<br>
<br>
+/* Get a clear color suitable for filling out an ISL surface state. */<br>
+union isl_color_value<br>
+intel_miptree_get_clear_<wbr>color(const struct gen_device_info *devinfo,<br>
+                              const struct intel_mipmap_tree *mt,<br>
</span>+                              enum isl_format view_format, bool sampling,<br>
+                              struct brw_bo **clear_color_bo,<br>
+                              uint32_t *clear_color_offset);<br>
<div class="HOEnZb"><div class="h5">+<br>
 bool<br>
 intel_miptree_set_depth_clear_<wbr>value(struct brw_context *brw,<br>
                                     struct intel_mipmap_tree *mt,<br>
-- <br>
2.16.2<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br></div>