i965: Combine 3DSTATE_STREAMOUT emitters and genX_sol_state atoms.
authorKenneth Graunke <kenneth@whitecape.org>
Wed, 22 Jun 2016 07:33:46 +0000 (00:33 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 23 Jun 2016 18:58:50 +0000 (11:58 -0700)
They're basically the same.  Let's avoid the code duplication.

v2: Fix SO_BUFFER_ENABLE stuff to only happen on Gen < 8 (caught
    by Jason Ekstrand).

Cc: mesa-stable@lists.freedesktop.org
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/mesa/drivers/dri/i965/brw_state.h
src/mesa/drivers/dri/i965/brw_state_upload.c
src/mesa/drivers/dri/i965/gen7_sol_state.c
src/mesa/drivers/dri/i965/gen8_sol_state.c

index b29412e37f7d5db95030b262fed16047682d0e65..a16e8768066f2caa9f32fad5dd4ce5070ed73bc8 100644 (file)
@@ -166,7 +166,6 @@ extern const struct brw_tracked_state gen8_wm_state;
 extern const struct brw_tracked_state gen8_raster_state;
 extern const struct brw_tracked_state gen8_sbe_state;
 extern const struct brw_tracked_state gen8_sf_state;
-extern const struct brw_tracked_state gen8_sol_state;
 extern const struct brw_tracked_state gen8_sf_clip_viewport;
 extern const struct brw_tracked_state gen8_vertices;
 extern const struct brw_tracked_state gen8_vf_topology;
@@ -303,6 +302,7 @@ void gen8_upload_ps_extra(struct brw_context *brw,
 /* gen7_sol_state.c */
 void gen7_upload_3dstate_so_decl_list(struct brw_context *brw,
                                       const struct brw_vue_map *vue_map);
+void gen8_upload_3dstate_so_buffers(struct brw_context *brw);
 
 /* gen8_surface_state.c */
 
index 0b47ebe3a145b272709bb01d881a0eac15429e6c..4a208210c7048f121cd98e3708525299077c31d1 100644 (file)
@@ -337,7 +337,7 @@ static const struct brw_tracked_state *gen8_render_atoms[] =
    &gen7_te_state,
    &gen8_ds_state,
    &gen8_gs_state,
-   &gen8_sol_state,
+   &gen7_sol_state,
    &gen6_clip_state,
    &gen8_raster_state,
    &gen8_sbe_state,
index 4749cc89ebaf4baac1cf1cdab77eb18b9c30ccc9..6f51040078098d60eec00f544fdd3f8d6ab29b05 100644 (file)
@@ -222,7 +222,9 @@ upload_3dstate_streamout(struct brw_context *brw, bool active,
    /* BRW_NEW_TRANSFORM_FEEDBACK */
    struct gl_transform_feedback_object *xfb_obj =
       ctx->TransformFeedback.CurrentObject;
-   uint32_t dw1 = 0, dw2 = 0;
+   const struct gl_transform_feedback_info *linked_xfb_info =
+      &xfb_obj->shader_program->LinkedTransformFeedback;
+   uint32_t dw1 = 0, dw2 = 0, dw3 = 0, dw4 = 0;
    int i;
 
    if (active) {
@@ -237,10 +239,12 @@ upload_3dstate_streamout(struct brw_context *brw, bool active,
       if (ctx->Light.ProvokingVertex != GL_FIRST_VERTEX_CONVENTION)
         dw1 |= SO_REORDER_TRAILING;
 
-      for (i = 0; i < 4; i++) {
-        if (xfb_obj->Buffers[i]) {
-           dw1 |= SO_BUFFER_ENABLE(i);
-        }
+      if (brw->gen < 8) {
+         for (i = 0; i < 4; i++) {
+            if (xfb_obj->Buffers[i]) {
+               dw1 |= SO_BUFFER_ENABLE(i);
+            }
+         }
       }
 
       /* We always read the whole vertex.  This could be reduced at some
@@ -258,12 +262,30 @@ upload_3dstate_streamout(struct brw_context *brw, bool active,
 
       dw2 |= SET_FIELD(urb_entry_read_offset, SO_STREAM_3_VERTEX_READ_OFFSET);
       dw2 |= SET_FIELD(urb_entry_read_length - 1, SO_STREAM_3_VERTEX_READ_LENGTH);
+
+      if (brw->gen >= 8) {
+        /* Set buffer pitches; 0 means unbound. */
+        if (xfb_obj->Buffers[0])
+           dw3 |= linked_xfb_info->Buffers[0].Stride * 4;
+        if (xfb_obj->Buffers[1])
+           dw3 |= (linked_xfb_info->Buffers[1].Stride * 4) << 16;
+        if (xfb_obj->Buffers[2])
+           dw4 |= linked_xfb_info->Buffers[2].Stride * 4;
+        if (xfb_obj->Buffers[3])
+           dw4 |= (linked_xfb_info->Buffers[3].Stride * 4) << 16;
+      }
    }
 
-   BEGIN_BATCH(3);
-   OUT_BATCH(_3DSTATE_STREAMOUT << 16 | (3 - 2));
+   const int dwords = brw->gen >= 8 ? 5 : 3;
+
+   BEGIN_BATCH(dwords);
+   OUT_BATCH(_3DSTATE_STREAMOUT << 16 | (dwords - 2));
    OUT_BATCH(dw1);
    OUT_BATCH(dw2);
+   if (dwords > 3) {
+      OUT_BATCH(dw3);
+      OUT_BATCH(dw4);
+   }
    ADVANCE_BATCH();
 }
 
@@ -275,7 +297,11 @@ upload_sol_state(struct brw_context *brw)
    bool active = _mesa_is_xfb_active_and_unpaused(ctx);
 
    if (active) {
-      upload_3dstate_so_buffers(brw);
+      if (brw->gen >= 8)
+         gen8_upload_3dstate_so_buffers(brw);
+      else
+         upload_3dstate_so_buffers(brw);
+
       /* BRW_NEW_VUE_MAP_GEOM_OUT */
       gen7_upload_3dstate_so_decl_list(brw, &brw->vue_map_geom_out);
    }
index a72f5e1871ec759e82d5f7d42fef073d972ded88..21cc1290882327237d98041ca872a428f9841e33 100644 (file)
@@ -35,7 +35,7 @@
 #include "intel_buffer_objects.h"
 #include "main/transformfeedback.h"
 
-static void
+void
 gen8_upload_3dstate_so_buffers(struct brw_context *brw)
 {
    struct gl_context *ctx = &brw->ctx;
@@ -93,91 +93,3 @@ gen8_upload_3dstate_so_buffers(struct brw_context *brw)
    }
    brw_obj->zero_offsets = false;
 }
-
-static void
-gen8_upload_3dstate_streamout(struct brw_context *brw, bool active,
-                              struct brw_vue_map *vue_map)
-{
-   struct gl_context *ctx = &brw->ctx;
-
-   /* BRW_NEW_TRANSFORM_FEEDBACK */
-   struct gl_transform_feedback_object *xfb_obj =
-      ctx->TransformFeedback.CurrentObject;
-   const struct gl_transform_feedback_info *linked_xfb_info =
-      &xfb_obj->shader_program->LinkedTransformFeedback;
-   uint32_t dw1 = 0, dw2 = 0, dw3 = 0, dw4 = 0;
-
-   if (active) {
-      int urb_entry_read_offset = 0;
-      int urb_entry_read_length = (vue_map->num_slots + 1) / 2 -
-         urb_entry_read_offset;
-
-      dw1 |= SO_FUNCTION_ENABLE;
-      dw1 |= SO_STATISTICS_ENABLE;
-
-      /* _NEW_LIGHT */
-      if (ctx->Light.ProvokingVertex != GL_FIRST_VERTEX_CONVENTION)
-         dw1 |= SO_REORDER_TRAILING;
-
-      /* We always read the whole vertex.  This could be reduced at some
-       * point by reading less and offsetting the register index in the
-       * SO_DECLs.
-       */
-      dw2 |= SET_FIELD(urb_entry_read_offset, SO_STREAM_0_VERTEX_READ_OFFSET);
-      dw2 |= SET_FIELD(urb_entry_read_length - 1, SO_STREAM_0_VERTEX_READ_LENGTH);
-
-      dw2 |= SET_FIELD(urb_entry_read_offset, SO_STREAM_1_VERTEX_READ_OFFSET);
-      dw2 |= SET_FIELD(urb_entry_read_length - 1, SO_STREAM_1_VERTEX_READ_LENGTH);
-
-      dw2 |= SET_FIELD(urb_entry_read_offset, SO_STREAM_2_VERTEX_READ_OFFSET);
-      dw2 |= SET_FIELD(urb_entry_read_length - 1, SO_STREAM_2_VERTEX_READ_LENGTH);
-
-      dw2 |= SET_FIELD(urb_entry_read_offset, SO_STREAM_3_VERTEX_READ_OFFSET);
-      dw2 |= SET_FIELD(urb_entry_read_length - 1, SO_STREAM_3_VERTEX_READ_LENGTH);
-
-      /* Set buffer pitches; 0 means unbound. */
-      if (xfb_obj->Buffers[0])
-         dw3 |= linked_xfb_info->Buffers[0].Stride * 4;
-      if (xfb_obj->Buffers[1])
-         dw3 |= (linked_xfb_info->Buffers[1].Stride * 4) << 16;
-      if (xfb_obj->Buffers[2])
-         dw4 |= linked_xfb_info->Buffers[2].Stride * 4;
-      if (xfb_obj->Buffers[3])
-         dw4 |= (linked_xfb_info->Buffers[3].Stride * 4) << 16;
-   }
-
-   BEGIN_BATCH(5);
-   OUT_BATCH(_3DSTATE_STREAMOUT << 16 | (5 - 2));
-   OUT_BATCH(dw1);
-   OUT_BATCH(dw2);
-   OUT_BATCH(dw3);
-   OUT_BATCH(dw4);
-   ADVANCE_BATCH();
-}
-
-static void
-upload_sol_state(struct brw_context *brw)
-{
-   struct gl_context *ctx = &brw->ctx;
-   /* BRW_NEW_TRANSFORM_FEEDBACK */
-   bool active = _mesa_is_xfb_active_and_unpaused(ctx);
-
-   if (active) {
-      gen8_upload_3dstate_so_buffers(brw);
-      /* BRW_NEW_VUE_MAP_GEOM_OUT */
-      gen7_upload_3dstate_so_decl_list(brw, &brw->vue_map_geom_out);
-   }
-
-   gen8_upload_3dstate_streamout(brw, active, &brw->vue_map_geom_out);
-}
-
-const struct brw_tracked_state gen8_sol_state = {
-   .dirty = {
-      .mesa  = _NEW_LIGHT,
-      .brw   = BRW_NEW_BATCH |
-               BRW_NEW_BLORP |
-               BRW_NEW_TRANSFORM_FEEDBACK |
-               BRW_NEW_VUE_MAP_GEOM_OUT,
-   },
-   .emit = upload_sol_state,
-};