<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Apr 28, 2018 at 5:09 AM, Antia Puentes <span dir="ltr"><<a href="mailto:apuentes@igalia.com" target="_blank">apuentes@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The Vertex Elements are now:<br>
* VE 1: <BaseVertex/firstvertex, BaseInstance, VertexID, InstanceID><br>
* VE 2: <DrawID, is-indexed-draw, 0, 0><br>
<br>
VE1 is it kept as it was before, VE2 additionally contains the new<br>
system value.<br>
---<br>
 src/intel/compiler/brw_fs_<wbr>nir.cpp             |  2 ++<br>
 src/intel/compiler/brw_nir.c                  | 11 +++++--<br>
 src/intel/compiler/brw_vec4.c<wbr>pp               | 14 +++++----<br>
 src/mesa/drivers/dri/i965/<wbr>brw_context.h       | 31 +++++++++++++++-----<br>
 src/mesa/drivers/dri/i965/<wbr>brw_draw.c          | 21 +++++++++-----<br>
 src/mesa/drivers/dri/i965/<wbr>brw_draw_upload.c   |  8 ++---<br>
 src/mesa/drivers/dri/i965/gen<wbr>X_state_upload.c | 42 +++++++++++++--------------<br>
 7 files changed, 80 insertions(+), 49 deletions(-)<br>
<br>
diff --git a/src/intel/compiler/brw_fs_ni<wbr>r.cpp b/src/intel/compiler/brw_fs_ni<wbr>r.cpp<br>
index 9698a0111ef..22beb0e00d1 100644<br>
--- a/src/intel/compiler/brw_fs_ni<wbr>r.cpp<br>
+++ b/src/intel/compiler/brw_fs_ni<wbr>r.cpp<br>
@@ -116,6 +116,7 @@ emit_system_values_block(nir_b<wbr>lock *block, fs_visitor *v)<br>
<br>
       case nir_intrinsic_load_vertex_id_z<wbr>ero_base:<br>
       case nir_intrinsic_load_base_vertex<wbr>:<br>
+      case nir_intrinsic_load_is_indexed_<wbr>draw:<br>
       case nir_intrinsic_load_first_verte<wbr>x:<br>
       case nir_intrinsic_load_instance_id<wbr>:<br>
       case nir_intrinsic_load_base_instan<wbr>ce:<br>
@@ -2460,6 +2461,7 @@ fs_visitor::nir_emit_vs_intrin<wbr>sic(const fs_builder &bld,<br>
    }<br>
<br>
    case nir_intrinsic_load_first_verte<wbr>x:<br>
+   case nir_intrinsic_load_is_indexed_<wbr>draw:<br>
       unreachable("lowered by brw_nir_lower_vs_inputs");<br>
<br>
    default:<br>
diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c<br>
index 16b0d86814f..a624deb6d2a 100644<br>
--- a/src/intel/compiler/brw_nir.c<br>
+++ b/src/intel/compiler/brw_nir.c<br>
@@ -266,6 +266,7 @@ brw_nir_lower_vs_inputs(nir_sh<wbr>ader *nir,<br>
             case nir_intrinsic_load_base_instan<wbr>ce:<br>
             case nir_intrinsic_load_vertex_id_z<wbr>ero_base:<br>
             case nir_intrinsic_load_instance_id<wbr>:<br>
+            case nir_intrinsic_load_is_indexed_<wbr>draw:<br>
             case nir_intrinsic_load_draw_id: {<br>
                b.cursor = nir_after_instr(&intrin->instr<wbr>);<br>
<br>
@@ -293,11 +294,15 @@ brw_nir_lower_vs_inputs(nir_sh<wbr>ader *nir,<br>
                   nir_intrinsic_set_component(l<wbr>oad, 3);<br>
                   break;<br>
                case nir_intrinsic_load_draw_id:<br>
-                  /* gl_DrawID is stored right after gl_VertexID and friends<br>
-                   * if any of them exist.<br>
+               case nir_intrinsic_load_is_indexed_<wbr>draw:<br>
+                  /* gl_DrawID and IsIndexedDraw are stored right after<br>
+                   * gl_VertexID and friends if any of them exist.<br>
                    */<br>
                   nir_intrinsic_set_base(load, num_inputs + has_sgvs);<br>
-                  nir_intrinsic_set_component(lo<wbr>ad, 0);<br>
+                  if (intrin->intrinsic == nir_intrinsic_load_draw_id)<br>
+                     nir_intrinsic_set_component(l<wbr>oad, 0);<br>
+                  else<br>
+                     nir_intrinsic_set_component(l<wbr>oad, 1);<br>
                   break;<br>
                default:<br>
                   unreachable("Invalid system value intrinsic");<br>
diff --git a/src/intel/compiler/brw_vec4.<wbr>cpp b/src/intel/compiler/brw_vec4.<wbr>cpp<br>
index e583c549204..898df90225f 100644<br>
--- a/src/intel/compiler/brw_vec4.<wbr>cpp<br>
+++ b/src/intel/compiler/brw_vec4.<wbr>cpp<br>
@@ -2833,6 +2833,13 @@ brw_compile_vs(const struct brw_compiler *compiler, void *log_data,<br>
       nr_attribute_slots++;<br>
    }<br>
<br>
+   /* gl_DrawID and IsIndexedDraw share its very own vec4 */<br>
+   if (shader->info.system_values_re<wbr>ad &<br>
+       (BITFIELD64_BIT(SYSTEM_VALUE_<wbr>DRAW_ID) |<br>
+        BITFIELD64_BIT(SYSTEM_VALUE_IS<wbr>_INDEXED_DRAW))) {<br>
+      nr_attribute_slots++;<br>
+   }<br>
+<br>
    if (shader->info.system_values_re<wbr>ad &<br>
        BITFIELD64_BIT(SYSTEM_VALUE_BA<wbr>SE_VERTEX))<br>
       prog_data->uses_basevertex = true;<br>
@@ -2857,12 +2864,9 @@ brw_compile_vs(const struct brw_compiler *compiler, void *log_data,<br>
        BITFIELD64_BIT(SYSTEM_VALUE_IN<wbr>STANCE_ID))<br>
       prog_data->uses_instanceid = true;<br>
<br>
-   /* gl_DrawID has its very own vec4 */<br>
    if (shader->info.system_values_re<wbr>ad &<br>
-       BITFIELD64_BIT(SYSTEM_VALUE_D<wbr>RAW_ID)) {<br>
-      prog_data->uses_drawid = true;<br>
-      nr_attribute_slots++;<br>
-   }<br>
+       BITFIELD64_BIT(SYSTEM_VALUE_D<wbr>RAW_ID))<br>
+          prog_data->uses_drawid = true;<br>
<br>
    /* The 3DSTATE_VS documentation lists the lower bound on "Vertex URB Entry<br>
     * Read Length" as 1 in vec4 mode, and 0 in SIMD8 mode.  Empirically, in<br>
diff --git a/src/mesa/drivers/dri/i965/br<wbr>w_context.h b/src/mesa/drivers/dri/i965/br<wbr>w_context.h<br>
index 1e6a45eee1f..be43eab43cc 100644<br>
--- a/src/mesa/drivers/dri/i965/br<wbr>w_context.h<br>
+++ b/src/mesa/drivers/dri/i965/br<wbr>w_context.h<br>
@@ -900,20 +900,35 @@ struct brw_context<br>
       } params;<br>
<br>
       /**<br>
-       * Buffer and offset used for GL_ARB_shader_draw_parameters<br>
-       * (for now, only gl_BaseVertex).<br>
+       * Buffer and offset used for GL_ARB_shader_draw_parameters which will<br>
+       * point to the indirect buffer for indirect draw calls.<br>
        */<br>
       struct brw_bo *draw_params_bo;<br>
       uint32_t draw_params_offset;<br>
<br>
+      struct {<br>
+         /**<br>
+          * The value of gl_DrawID for the current _mesa_prim. This always comes<br>
+          * in from it's own vertex buffer since it's not part of the indirect<br>
+          * draw parameters.<br>
+          */<br>
+         int gl_drawid;<br>
+<br>
+         /**<br>
+          * Stores if the current _mesa_prim is an indexed or non-indexed draw<br>
+          * (~0/0). Useful to calculate gl_BaseVertex as an AND of firstvertex<br>
+          * and is_indexed_draw.<br>
+          */<br>
+         int is_indexed_draw;<br>
+      } derived_params;<br>
+<br>
       /**<br>
-       * The value of gl_DrawID for the current _mesa_prim. This always comes<br>
-       * in from it's own vertex buffer since it's not part of the indirect<br>
-       * draw parameters.<br>
+       * Buffer and offset used for GL_ARB_shader_draw_parameters which contains<br>
+       * parameters that are not present in the indirect buffer. They will go in<br>
+       * their own vertex element.<br>
        */<br>
-      int gl_drawid;<br>
-      struct brw_bo *draw_id_bo;<br>
-      uint32_t draw_id_offset;<br>
+      struct brw_bo *derived_draw_params_bo;<br>
+      uint32_t derived_draw_params_offset;<br>
<br>
       /**<br>
        * Pointer to the the buffer storing the indirect draw parameters. It<br>
diff --git a/src/mesa/drivers/dri/i965/br<wbr>w_draw.c b/src/mesa/drivers/dri/i965/br<wbr>w_draw.c<br>
index f51f083178e..09199c30453 100644<br>
--- a/src/mesa/drivers/dri/i965/br<wbr>w_draw.c<br>
+++ b/src/mesa/drivers/dri/i965/br<wbr>w_draw.c<br>
@@ -861,17 +861,22 @@ brw_draw_single_prim(struct gl_context *ctx,<br>
    }<br>
<br>
    /* gl_DrawID always needs its own vertex buffer since it's not part of<br>
-    * the indirect parameter buffer. If the program uses gl_DrawID we need<br>
-    * to flag BRW_NEW_VERTICES. For the first iteration, we don't have<br>
-    * valid vs_prog_data, but we always flag BRW_NEW_VERTICES before<br>
-    * the loop.<br>
+    * the indirect parameter buffer. Same for is_indexed_draw, which shares<br>
+    * the buffer with gl_DrawID. If the program uses gl_DrawID, we need to<br>
+    * flag BRW_NEW_VERTICES. For the first iteration, we don't have valid<br>
+    * vs_prog_data, but we always flag BRW_NEW_VERTICES before the loop.<br>
     */<br>
-   brw->draw.gl_drawid = prim->draw_id;<br>
-   brw_bo_unreference(brw->draw.<wbr>draw_id_bo);<br>
-   brw->draw.draw_id_bo = NULL;<br>
-   if (prim_id > 0 && vs_prog_data->uses_drawid)<br>
+   if (prim_id > 0 &&<br>
+       vs_prog_data->uses_drawid)<br></blockquote><div><br></div><div>This doesn't need to be line-wrapped anymore.<br><br></div><div>Series is<br><br></div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
       brw->ctx.NewDriverState |= BRW_NEW_VERTICES;<br>
<br>
+   brw->draw.derived_params.gl_d<wbr>rawid = prim->draw_id;<br>
+   brw->draw.derived_params.is_i<wbr>ndexed_draw = prim->indexed ? ~0 : 0;<br>
+<br>
+   brw_bo_unreference(brw->draw.<wbr>derived_draw_params_bo);<br>
+   brw->draw.derived_draw_<wbr>params_bo = NULL;<br>
+   brw->draw.derived_draw_<wbr>params_offset = 0;<br>
+<br>
    if (devinfo->gen < 6)<br>
       brw_set_prim(brw, prim);<br>
    else<br>
diff --git a/src/mesa/drivers/dri/i965/br<wbr>w_draw_upload.c b/src/mesa/drivers/dri/i965/br<wbr>w_draw_upload.c<br>
index 7573f780f23..55566a7de44 100644<br>
--- a/src/mesa/drivers/dri/i965/br<wbr>w_draw_upload.c<br>
+++ b/src/mesa/drivers/dri/i965/br<wbr>w_draw_upload.c<br>
@@ -716,11 +716,11 @@ brw_prepare_shader_draw_parame<wbr>ters(struct brw_context *brw)<br>
                       &brw->draw.draw_params_<wbr>offset);<br>
    }<br>
<br>
-   if (vs_prog_data->uses_drawid) {<br>
+   if (vs_prog_data->uses_drawid || vs_prog_data->uses_is_indexed_<wbr>draw) {<br>
       brw_upload_data(&brw->upload,<br>
-                      &brw->draw.gl_drawid, sizeof(brw->draw.gl_drawid), 4,<br>
-                      &brw->draw.draw_id_bo,<br>
-                      &brw->draw.draw_id_offset);<br>
+                      &brw->draw.derived_params, sizeof(brw->draw.derived_param<wbr>s), 4,<br>
+                      &brw->draw.derived_draw_params<wbr>_bo,<br>
+                      &brw->draw.derived_draw_params<wbr>_offset);<br>
    }<br>
 }<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/ge<wbr>nX_state_upload.c b/src/mesa/drivers/dri/i965/ge<wbr>nX_state_upload.c<br>
index 1a32c60ae34..093954054fc 100644<br>
--- a/src/mesa/drivers/dri/i965/ge<wbr>nX_state_upload.c<br>
+++ b/src/mesa/drivers/dri/i965/ge<wbr>nX_state_upload.c<br>
@@ -539,16 +539,21 @@ genX(emit_vertices)(struct brw_context *brw)<br>
    }<br>
 #endif<br>
<br>
-   const bool uses_firstvertex =<br>
-      vs_prog_data->uses_basevertex || vs_prog_data->uses_firstvertex<wbr>;<br>
+   const bool uses_draw_params =<br>
+      vs_prog_data->uses_firstvertex ||<br>
+      vs_prog_data->uses_basevertex ||<br>
+      vs_prog_data->uses_baseinstanc<wbr>e;<br>
+<br>
+   const bool uses_derived_draw_params =<br>
+      vs_prog_data->uses_drawid ||<br>
+      vs_prog_data->uses_is_indexed_<wbr>draw;<br>
<br>
-   const bool needs_sgvs_element = (uses_firstvertex ||<br>
-                                    vs_prog_data->uses_baseinstanc<wbr>e ||<br>
+   const bool needs_sgvs_element = (uses_draw_params ||<br>
                                     vs_prog_data->uses_instanceid ||<br>
                                     vs_prog_data->uses_vertexid);<br>
<br>
    unsigned nr_elements =<br>
-      brw->vb.nr_enabled + needs_sgvs_element + vs_prog_data->uses_drawid;<br>
+      brw->vb.nr_enabled + needs_sgvs_element + uses_derived_draw_params;<br>
<br>
 #if GEN_GEN < 8<br>
    /* If any of the formats of vb.enabled needs more that one upload, we need<br>
@@ -588,11 +593,8 @@ genX(emit_vertices)(struct brw_context *brw)<br>
    }<br>
<br>
    /* Now emit 3DSTATE_VERTEX_BUFFERS and 3DSTATE_VERTEX_ELEMENTS packets. */<br>
-   const bool uses_draw_params =<br>
-      uses_firstvertex ||<br>
-      vs_prog_data->uses_baseinstanc<wbr>e;<br>
    const unsigned nr_buffers = brw->vb.nr_buffers +<br>
-      uses_draw_params + vs_prog_data->uses_drawid;<br>
+      uses_draw_params + uses_derived_draw_params;<br>
<br>
    if (nr_buffers) {<br>
       assert(nr_buffers <= (GEN_GEN >= 6 ? 33 : 17));<br>
@@ -626,11 +628,11 @@ genX(emit_vertices)(struct brw_context *brw)<br>
                                              0 /* step rate */);<br>
       }<br>
<br>
-      if (vs_prog_data->uses_drawid) {<br>
+      if (uses_derived_draw_params) {<br>
          dw = genX(emit_vertex_buffer_state)<wbr>(brw, dw, brw->vb.nr_buffers + 1,<br>
-                                             brw->draw.draw_id_bo,<br>
-                                             brw->draw.draw_id_offset,<br>
-                                             brw->draw.draw_id_bo->size,<br>
+                                             brw->draw.derived_draw_<wbr>params_bo,<br>
+                                             brw->draw.derived_draw_<wbr>params_offset,<br>
+                                             brw->draw.derived_draw_<wbr>params_bo->size,<br>
                                              0 /* stride */,<br>
                                              0 /* step rate */);<br>
       }<br>
@@ -772,8 +774,7 @@ genX(emit_vertices)(struct brw_context *brw)<br>
       };<br>
<br>
 #if GEN_GEN >= 8<br>
-      if (uses_firstvertex ||<br>
-          vs_prog_data->uses_baseinstanc<wbr>e) {<br>
+      if (uses_draw_params) {<br>
          elem_state.VertexBufferIndex = brw->vb.nr_buffers;<br>
          elem_state.SourceElementFormat = ISL_FORMAT_R32G32_UINT;<br>
          elem_state.Component0Control = VFCOMP_STORE_SRC;<br>
@@ -782,11 +783,10 @@ genX(emit_vertices)(struct brw_context *brw)<br>
 #else<br>
       elem_state.VertexBufferIndex = brw->vb.nr_buffers;<br>
       elem_state.<wbr>SourceElementFormat = ISL_FORMAT_R32G32_UINT;<br>
-      if (uses_firstvertex)<br>
+      if (uses_draw_params) {<br>
          elem_state.Component0Control = VFCOMP_STORE_SRC;<br>
-<br>
-      if (vs_prog_data->uses_baseinstan<wbr>ce)<br>
          elem_state.Component1Control = VFCOMP_STORE_SRC;<br>
+      }<br>
<br>
       if (vs_prog_data->uses_vertexid)<br>
          elem_state.Component2Control = VFCOMP_STORE_VID;<br>
@@ -799,13 +799,13 @@ genX(emit_vertices)(struct brw_context *brw)<br>
       dw += GENX(VERTEX_ELEMENT_STATE_leng<wbr>th);<br>
    }<br>
<br>
-   if (vs_prog_data->uses_drawid) {<br>
+   if (uses_derived_draw_params) {<br>
       struct GENX(VERTEX_ELEMENT_STATE) elem_state = {<br>
          .Valid = true,<br>
          .VertexBufferIndex = brw->vb.nr_buffers + 1,<br>
-         .SourceElementFormat = ISL_FORMAT_R32_UINT,<br>
+         .SourceElementFormat = ISL_FORMAT_R32G32_UINT,<br>
          .Component0Control = VFCOMP_STORE_SRC,<br>
-         .Component1Control = VFCOMP_STORE_0,<br>
+         .Component1Control = VFCOMP_STORE_SRC,<br>
          .Component2Control = VFCOMP_STORE_0,<br>
          .Component3Control = VFCOMP_STORE_0,<br>
 #if GEN_GEN < 5<br>
<span class="m_-7628320610120514061HOEnZb"><font color="#888888">-- <br>
2.14.1<br>
<br>
</font></span></blockquote></div><br></div></div>