<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 27, 2018 at 1:30 AM,  <span dir="ltr"><<a href="mailto:kevin.rogovin@intel.com" target="_blank">kevin.rogovin@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Kevin Rogovin <<a href="mailto:kevin.rogovin@intel.com">kevin.rogovin@intel.com</a>><br>
<br>
Gen9 GPU's suffer from a HW bug where the GPU will hang if<br>
the GPU accesses a texture with a an auxilary buffer and<br>
an ASTC5x5 texture without having a pipeline cs stall (and<br>
texture cache flush) between such accesses. This patch<br>
creates the infrastucture to track such potential texture<br>
accesses and to issue the required pipeline stalls.<br>
<br>
Signed-off-by: Kevin Rogovin <<a href="mailto:kevin.rogovin@intel.com">kevin.rogovin@intel.com</a>><br>
---<br>
 src/mesa/drivers/dri/i965/<wbr>Makefile.sources    |  1 +<br>
 src/mesa/drivers/dri/i965/brw_<wbr>context.c       |  6 +++++<br>
 src/mesa/drivers/dri/i965/brw_<wbr>context.h       | 24 ++++++++++++++++++<br>
 src/mesa/drivers/dri/i965/<wbr>gen9_astc5x5_wa.c   | 36 +++++++++++++++++++++++++++<br>
 src/mesa/drivers/dri/i965/<wbr>intel_batchbuffer.c |  1 +<br>
 src/mesa/drivers/dri/i965/<wbr>meson.build         |  1 +<br>
 6 files changed, 69 insertions(+)<br>
 create mode 100644 src/mesa/drivers/dri/i965/<wbr>gen9_astc5x5_wa.c<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>Makefile.sources b/src/mesa/drivers/dri/i965/<wbr>Makefile.sources<br>
index 2f349aa..20f7dee 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>Makefile.sources<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>Makefile.sources<br>
@@ -78,6 +78,7 @@ i965_FILES = \<br>
        gen7_urb.c \<br>
        gen8_depth_state.c \<br>
        gen8_multisample_state.c \<br>
+        gen9_astc5x5_wa.c \<br>
        hsw_queryobj.c \<br>
        hsw_sol.c \<br>
        intel_batchbuffer.c \<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>brw_context.c b/src/mesa/drivers/dri/i965/<wbr>brw_context.c<br>
index ea1c78d..a6e95b2 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>brw_context.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>brw_context.c<br>
@@ -1058,6 +1058,12 @@ brwCreateContext(gl_api api,<br>
    if (ctx->Extensions.INTEL_<wbr>performance_query)<br>
       brw_init_performance_queries(<wbr>brw);<br>
<br>
+   brw->astc5x5_wa.required = (devinfo->gen == 9);<br>
+   brw->astc5x5_wa.mode = BRW_ASTC5x5_WA_MODE_NONE;<br>
+   brw->astc5x5_wa.texture_<wbr>astc5x5_present = false;<br>
+   brw->astc5x5_wa.texture_with_<wbr>auxilary_present = false;<br>
+   brw->astc5x5_wa.blorp_<wbr>sampling_from_astc5x5 = false;<br>
+<br>
    vbo_use_buffer_objects(ctx);<br>
    vbo_always_unmap_buffers(ctx);<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>brw_context.h b/src/mesa/drivers/dri/i965/<wbr>brw_context.h<br>
index 050b656..5fe0b29 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>brw_context.h<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>brw_context.h<br>
@@ -166,6 +166,12 @@ enum brw_cache_id {<br>
    BRW_MAX_CACHE<br>
 };<br>
<br>
+enum brw_astc5x5_wa_mode_t {<br>
+   BRW_ASTC5x5_WA_MODE_NONE,<br>
+   BRW_ASTC5x5_WA_MODE_HAS_<wbr>ASTC5x5,<br>
+   BRW_ASTC5x5_WA_MODE_HAS_AUX,<br>
+};<br>
+<br>
 enum brw_state_id {<br>
    /* brw_cache_ids must come first - see brw_program_cache.c */<br>
    BRW_STATE_URB_FENCE = BRW_MAX_CACHE,<br>
@@ -1296,6 +1302,19 @@ struct brw_context<br>
     */<br>
    enum isl_aux_usage draw_aux_usage[MAX_DRAW_<wbr>BUFFERS];<br>
<br>
+   /* Certain GEN's have a hardware bug where the sampler hangs if it attempts<br>
+    * to access auxilary buffers and an ASTC5x5 compressed buffer. The workaround<br>
+    * is to make sure that the texture cache is cleared between such accesses<br>
+    * and that such accesses have a command streamer stall between them.<br>
+    */<br>
+   struct {<br>
+      bool required;<br></blockquote><div><br></div><div>I would rather have a helper function in brw_draw near where we implement the workaround than having a boolean in brw_context.  That way the code to detect the need for the workaround is near the implementation of the workaround.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      enum brw_astc5x5_wa_mode_t mode;<br>
+      bool texture_astc5x5_present;<br>
+      bool texture_with_auxilary_present;<br>
+      bool blorp_sampling_from_astc5x5;<br></blockquote><div><br></div><div>This is quite a bit more infastructure than we really need in brw_context.  All we reall need is the enum.  The rest just enables us to spread the workaround throughout the entire driver which is a bad thing.  Most of my comments will focus on this theme.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   } astc5x5_wa;<br>
+<br>
    __DRIcontext *driContext;<br>
    struct intel_screen *screen;<br>
 };<br>
@@ -1729,6 +1748,11 @@ void brw_query_internal_format(<wbr>struct gl_context *ctx, GLenum target,<br>
                                GLenum internalFormat, GLenum pname,<br>
                                GLint *params);<br>
<br>
+/* gen9_astc5x5_wa.c */<br>
+void gen9_set_astc5x5_wa_mode(<wbr>struct brw_context *brw,<br>
+                             enum brw_astc5x5_wa_mode_t mode);<br>
+void gen9_astc5x5_perform_wa(struct brw_context *brw);<br>
+<br>
 #ifdef __cplusplus<br>
 }<br>
 #endif<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>gen9_astc5x5_wa.c b/src/mesa/drivers/dri/i965/<wbr>gen9_astc5x5_wa.c<br>
new file mode 100644<br>
index 0000000..d3efd05<br>
--- /dev/null<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>gen9_astc5x5_wa.c<br>
@@ -0,0 +1,36 @@<br>
+#include "brw_context.h"<br>
+#include "brw_defines.h"<br>
+#include "intel_mipmap_tree.h"<br>
+<br>
+void<br>
+gen9_set_astc5x5_wa_mode(<wbr>struct brw_context *brw,<br>
+                         enum brw_astc5x5_wa_mode_t mode)<br>
+{<br>
+   if (!brw->astc5x5_wa.required ||<br>
+       mode == BRW_ASTC5x5_WA_MODE_NONE ||<br>
+       brw->astc5x5_wa.mode == mode) {<br>
+      return;<br>
+   }<br>
+<br>
+   if (brw->astc5x5_wa.mode != BRW_ASTC5x5_WA_MODE_NONE) {<br>
+      const uint32_t flags = PIPE_CONTROL_CS_STALL |<br>
+         PIPE_CONTROL_TEXTURE_CACHE_<wbr>INVALIDATE;<br>
+      brw_emit_pipe_control_flush(<wbr>brw, flags);<br>
+   }<br>
+<br>
+   brw->astc5x5_wa.mode = mode;<br>
+}<br>
+<br>
+void<br>
+gen9_astc5x5_perform_wa(<wbr>struct brw_context *brw)<br>
+{<br>
+   if (!brw->astc5x5_wa.required) {<br>
+      return;<br>
+   }<br>
+<br>
+   if (brw->astc5x5_wa.texture_<wbr>astc5x5_present) {<br>
+      gen9_set_astc5x5_wa_mode(brw, BRW_ASTC5x5_WA_MODE_HAS_<wbr>ASTC5x5);<br>
+   } else if (brw->astc5x5_wa.texture_with_<wbr>auxilary_present) {<br>
+      gen9_set_astc5x5_wa_mode(brw, BRW_ASTC5x5_WA_MODE_HAS_AUX);<br>
+   }<br>
+}<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>intel_batchbuffer.c b/src/mesa/drivers/dri/i965/<wbr>intel_batchbuffer.c<br>
index d0999bb..4e56fa9 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>intel_batchbuffer.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>intel_batchbuffer.c<br>
@@ -692,6 +692,7 @@ brw_new_batch(struct brw_context *brw)<br>
<br>
    /* Create a new batchbuffer and reset the associated state: */<br>
    intel_batchbuffer_reset_and_<wbr>clear_render_cache(brw);<br>
+   brw->astc5x5_wa.mode = BRW_ASTC5x5_WA_MODE_NONE;<br>
<br>
    /* If the kernel supports hardware contexts, then most hardware state is<br>
     * preserved between batches; we only need to re-emit state that is required<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>meson.build b/src/mesa/drivers/dri/i965/<wbr>meson.build<br>
index e686614..55a5f15 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>meson.build<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>meson.build<br>
@@ -97,6 +97,7 @@ files_i965 = files(<br>
   'gen7_urb.c',<br>
   'gen8_depth_state.c',<br>
   'gen8_multisample_state.c',<br>
+  'gen9_astc5x5_wa.c',<br>
   'hsw_queryobj.c',<br>
   'hsw_sol.c',<br>
   'intel_batchbuffer.c',<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.7.4<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>
</font></span></blockquote></div><br></div></div>