ilo: emit 3DPRIMITIVE from gen6_3dprimitive_info
authorChia-I Wu <olvaffe@gmail.com>
Mon, 22 Jun 2015 06:27:19 +0000 (14:27 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Mon, 22 Jun 2015 07:18:57 +0000 (15:18 +0800)
It allows us to remove ilo_ib_state::draw_start_offset and
ILO_PRIM_RECTANGLES.  gen6_3d_translate_pipe_prim() is also replaced by
ilo_translate_draw_mode().

src/gallium/drivers/ilo/core/ilo_builder_3d.h
src/gallium/drivers/ilo/core/ilo_builder_3d_top.h
src/gallium/drivers/ilo/core/ilo_core.h
src/gallium/drivers/ilo/ilo_blitter.h
src/gallium/drivers/ilo/ilo_blitter_rectlist.c
src/gallium/drivers/ilo/ilo_render_gen.h
src/gallium/drivers/ilo/ilo_render_gen6.c
src/gallium/drivers/ilo/ilo_render_gen7.c
src/gallium/drivers/ilo/ilo_render_gen8.c
src/gallium/drivers/ilo/ilo_state.c
src/gallium/drivers/ilo/ilo_state.h

index 8d8a79599bd77e72927f0f5a672377bd36b7f2ee..fb8b53cbe230dd22e45b6148da07569790a50df5 100644 (file)
 #include "ilo_builder_3d_top.h"
 #include "ilo_builder_3d_bottom.h"
 
+struct gen6_3dprimitive_info {
+   enum gen_3dprim_type topology;
+   bool indexed;
+
+   uint32_t vertex_count;
+   uint32_t vertex_start;
+   uint32_t instance_count;
+   uint32_t instance_start;
+   int32_t vertex_base;
+};
+
 static inline void
 gen6_3DPRIMITIVE(struct ilo_builder *builder,
-                 const struct pipe_draw_info *info,
-                 int64_t start_offset)
+                 const struct gen6_3dprimitive_info *info)
 {
    const uint8_t cmd_len = 6;
-   const int prim = gen6_3d_translate_pipe_prim(info->mode);
-   const int vb_access = (info->indexed) ?
-      GEN6_3DPRIM_DW0_ACCESS_RANDOM : GEN6_3DPRIM_DW0_ACCESS_SEQUENTIAL;
    uint32_t *dw;
 
    ILO_DEV_ASSERT(builder->dev, 6, 6);
 
    ilo_builder_batch_pointer(builder, cmd_len, &dw);
 
-   dw[0] = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) |
-           vb_access |
-           prim << GEN6_3DPRIM_DW0_TYPE__SHIFT |
-           (cmd_len - 2);
-   dw[1] = info->count;
-   dw[2] = info->start + start_offset;
+   dw[0] = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2) |
+           info->topology << GEN6_3DPRIM_DW0_TYPE__SHIFT;
+   if (info->indexed)
+      dw[0] |= GEN6_3DPRIM_DW0_ACCESS_RANDOM;
+
+   dw[1] = info->vertex_count;
+   dw[2] = info->vertex_start;
    dw[3] = info->instance_count;
-   dw[4] = info->start_instance;
-   dw[5] = info->index_bias;
+   dw[4] = info->instance_start;
+   dw[5] = info->vertex_base;
 }
 
 static inline void
 gen7_3DPRIMITIVE(struct ilo_builder *builder,
-                 const struct pipe_draw_info *info,
-                 int64_t start_offset)
+                 const struct gen6_3dprimitive_info *info)
 {
    const uint8_t cmd_len = 7;
-   const int prim = gen6_3d_translate_pipe_prim(info->mode);
-   const int vb_access = (info->indexed) ?
-      GEN7_3DPRIM_DW1_ACCESS_RANDOM : GEN7_3DPRIM_DW1_ACCESS_SEQUENTIAL;
    uint32_t *dw;
 
    ILO_DEV_ASSERT(builder->dev, 7, 8);
@@ -77,12 +81,16 @@ gen7_3DPRIMITIVE(struct ilo_builder *builder,
    ilo_builder_batch_pointer(builder, cmd_len, &dw);
 
    dw[0] = GEN6_RENDER_CMD(3D, 3DPRIMITIVE) | (cmd_len - 2);
-   dw[1] = vb_access | prim;
-   dw[2] = info->count;
-   dw[3] = info->start + start_offset;
+
+   dw[1] = info->topology << GEN7_3DPRIM_DW1_TYPE__SHIFT;
+   if (info->indexed)
+      dw[1] |= GEN7_3DPRIM_DW1_ACCESS_RANDOM;
+
+   dw[2] = info->vertex_count;
+   dw[3] = info->vertex_start;
    dw[4] = info->instance_count;
-   dw[5] = info->start_instance;
-   dw[6] = info->index_bias;
+   dw[5] = info->instance_start;
+   dw[6] = info->vertex_base;
 }
 
 #endif /* ILO_BUILDER_3D_H */
index 42d171fc0d215dd884281951bd23375cd4479136..8d30095e6f6ef9f4b0d660469516b2f67181f0a2 100644 (file)
@@ -217,35 +217,6 @@ gen6_3DSTATE_VF_STATISTICS(struct ilo_builder *builder,
    ilo_builder_batch_write(builder, cmd_len, &dw0);
 }
 
-/**
- * Translate a pipe primitive type to the matching hardware primitive type.
- */
-static inline int
-gen6_3d_translate_pipe_prim(unsigned prim)
-{
-   static const int prim_mapping[ILO_PRIM_MAX] = {
-      [PIPE_PRIM_POINTS]                     = GEN6_3DPRIM_POINTLIST,
-      [PIPE_PRIM_LINES]                      = GEN6_3DPRIM_LINELIST,
-      [PIPE_PRIM_LINE_LOOP]                  = GEN6_3DPRIM_LINELOOP,
-      [PIPE_PRIM_LINE_STRIP]                 = GEN6_3DPRIM_LINESTRIP,
-      [PIPE_PRIM_TRIANGLES]                  = GEN6_3DPRIM_TRILIST,
-      [PIPE_PRIM_TRIANGLE_STRIP]             = GEN6_3DPRIM_TRISTRIP,
-      [PIPE_PRIM_TRIANGLE_FAN]               = GEN6_3DPRIM_TRIFAN,
-      [PIPE_PRIM_QUADS]                      = GEN6_3DPRIM_QUADLIST,
-      [PIPE_PRIM_QUAD_STRIP]                 = GEN6_3DPRIM_QUADSTRIP,
-      [PIPE_PRIM_POLYGON]                    = GEN6_3DPRIM_POLYGON,
-      [PIPE_PRIM_LINES_ADJACENCY]            = GEN6_3DPRIM_LINELIST_ADJ,
-      [PIPE_PRIM_LINE_STRIP_ADJACENCY]       = GEN6_3DPRIM_LINESTRIP_ADJ,
-      [PIPE_PRIM_TRIANGLES_ADJACENCY]        = GEN6_3DPRIM_TRILIST_ADJ,
-      [PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY]   = GEN6_3DPRIM_TRISTRIP_ADJ,
-      [ILO_PRIM_RECTANGLES]                  = GEN6_3DPRIM_RECTLIST,
-   };
-
-   assert(prim_mapping[prim]);
-
-   return prim_mapping[prim];
-}
-
 static inline void
 gen8_3DSTATE_VF_TOPOLOGY(struct ilo_builder *builder,
                          enum gen_3dprim_type topology)
index 3587d3930f3757feb15612507aa2c5ccd71b277d..0a7f7d9d3feeefc98a057c15399907f516843c69 100644 (file)
@@ -40,7 +40,4 @@
 #include "util/u_memory.h"
 #include "util/u_pointer.h"
 
-#define ILO_PRIM_RECTANGLES PIPE_PRIM_MAX
-#define ILO_PRIM_MAX (PIPE_PRIM_MAX + 1)
-
 #endif /* ILO_CORE_H */
index 6af6046e1a913118fcb8cc64beee39d40a83602c..4eba8481c2856f73a2a9d516ec46d6643ed7fe85 100644 (file)
@@ -58,7 +58,7 @@ struct ilo_blitter {
    bool initialized;
 
    float vertices[3][2];
-   struct pipe_draw_info draw;
+   struct gen6_3dprimitive_info draw_info;
 
    uint32_t vf_data[4];
    struct ilo_state_vf vf;
index afdb037782464da220e633b40262fde140ee505c..13c8f50068034ec7af0ac7b40f7d18acc3910137 100644 (file)
@@ -45,9 +45,9 @@ ilo_blitter_set_invariants(struct ilo_blitter *blitter)
       return true;
 
    /* a rectangle has 3 vertices in a RECTLIST */
-   util_draw_init_info(&blitter->draw);
-   blitter->draw.mode = ILO_PRIM_RECTANGLES;
-   blitter->draw.count = 3;
+   blitter->draw_info.topology = GEN6_3DPRIM_RECTLIST;
+   blitter->draw_info.vertex_count = 3;
+   blitter->draw_info.instance_count = 1;
 
    memset(&elem, 0, sizeof(elem));
    /* only vertex X and Y */
index aae4ef2f373a1c697d805f1507f73d1202a60801..6b1337500438f61619ccb1bd17bf09ed6b10b07d 100644 (file)
@@ -389,11 +389,8 @@ ilo_render_pipe_control(struct ilo_render *r, uint32_t dw1)
  */
 static inline void
 ilo_render_3dprimitive(struct ilo_render *r,
-                       const struct pipe_draw_info *info,
-                       const struct ilo_ib_state *ib)
+                       const struct gen6_3dprimitive_info *info)
 {
-   const int64_t start_offset = (info->indexed) ? ib->draw_start_offset : 0;
-
    ILO_DEV_ASSERT(r->dev, 6, 8);
 
    if (r->state.deferred_pipe_control_dw1)
@@ -401,9 +398,9 @@ ilo_render_3dprimitive(struct ilo_render *r,
 
    /* 3DPRIMITIVE */
    if (ilo_dev_gen(r->dev) >= ILO_GEN(7))
-      gen7_3DPRIMITIVE(r->builder, info, start_offset);
+      gen7_3DPRIMITIVE(r->builder, info);
    else
-      gen6_3DPRIMITIVE(r->builder, info, start_offset);
+      gen6_3DPRIMITIVE(r->builder, info);
 
    r->state.current_pipe_control_dw1 = 0;
    assert(!r->state.deferred_pipe_control_dw1);
index b2bc2dcface32eab97f63999815c9a03935c84dc..c1f759f304377d0827ba1f0d01c9a8398536d965 100644 (file)
@@ -806,7 +806,7 @@ ilo_render_emit_draw_commands_gen6(struct ilo_render *render,
    gen6_draw_sf_rect(render, vec, session);
    gen6_draw_vf(render, vec, session);
 
-   ilo_render_3dprimitive(render, vec->draw, &vec->ib);
+   ilo_render_3dprimitive(render, &vec->draw_info);
 }
 
 static void
@@ -926,7 +926,7 @@ ilo_render_emit_rectlist_commands_gen6(struct ilo_render *r,
    gen6_3DSTATE_DRAWING_RECTANGLE(r->builder, 0, 0,
          blitter->fb.width, blitter->fb.height);
 
-   ilo_render_3dprimitive(r, &blitter->draw, NULL);
+   ilo_render_3dprimitive(r, &blitter->draw_info);
 }
 
 int
index 4c54edeeb961f9c80027722b694f91adbe8adbba..6623a8bcb43616eaed9af1dbf201f43072ec365a 100644 (file)
@@ -649,7 +649,7 @@ ilo_render_emit_draw_commands_gen7(struct ilo_render *render,
    gen6_draw_sf_rect(render, vec, session);
    gen6_draw_vf(render, vec, session);
 
-   ilo_render_3dprimitive(render, vec->draw, &vec->ib);
+   ilo_render_3dprimitive(render, &vec->draw_info);
 }
 
 static void
@@ -804,7 +804,7 @@ ilo_render_emit_rectlist_commands_gen7(struct ilo_render *r,
    if (ilo_dev_gen(r->dev) == ILO_GEN(7))
       gen7_wa_post_ps_and_later(r);
 
-   ilo_render_3dprimitive(r, &blitter->draw, NULL);
+   ilo_render_3dprimitive(r, &blitter->draw_info);
 }
 
 int
index f86871f852f9c88797336eb19b954976862f285c..65494b4058a19689700b9126e189bb5fd9ab247a 100644 (file)
@@ -220,8 +220,7 @@ gen8_draw_vf(struct ilo_render *r,
    if (session->vf_delta.dirty & ILO_STATE_VF_3DSTATE_VERTEX_ELEMENTS)
       gen6_3DSTATE_VERTEX_ELEMENTS(r->builder, &vec->ve->vf);
 
-   gen8_3DSTATE_VF_TOPOLOGY(r->builder,
-         gen6_3d_translate_pipe_prim(vec->draw->mode));
+   gen8_3DSTATE_VF_TOPOLOGY(r->builder, vec->draw_info.topology);
 
    if (session->vf_delta.dirty & ILO_STATE_VF_3DSTATE_VF_INSTANCING) {
       const uint8_t attr_count = ilo_state_vf_get_attr_count(&vec->ve->vf);
@@ -270,7 +269,7 @@ ilo_render_emit_draw_commands_gen8(struct ilo_render *render,
    gen6_draw_sf_rect(render, vec, session);
    gen8_draw_vf(render, vec, session);
 
-   ilo_render_3dprimitive(render, vec->draw, &vec->ib);
+   ilo_render_3dprimitive(render, &vec->draw_info);
 }
 
 int
index 4252dbe56139816286fba5a2137ca6ea0783ebba..63534f33fa76b1545706d974427cdc832c251a0f 100644 (file)
@@ -25,7 +25,6 @@
  *    Chia-I Wu <olv@lunarg.com>
  */
 
-#include "core/ilo_builder_3d.h" /* for gen6_3d_translate_pipe_prim() */
 #include "util/u_dual_blend.h"
 #include "util/u_dynarray.h"
 #include "util/u_framebuffer.h"
 #include "ilo_shader.h"
 #include "ilo_state.h"
 
+/**
+ * Translate a pipe primitive type to the matching hardware primitive type.
+ */
+static enum gen_3dprim_type
+ilo_translate_draw_mode(unsigned mode)
+{
+   static const enum gen_3dprim_type prim_mapping[PIPE_PRIM_MAX] = {
+      [PIPE_PRIM_POINTS]                     = GEN6_3DPRIM_POINTLIST,
+      [PIPE_PRIM_LINES]                      = GEN6_3DPRIM_LINELIST,
+      [PIPE_PRIM_LINE_LOOP]                  = GEN6_3DPRIM_LINELOOP,
+      [PIPE_PRIM_LINE_STRIP]                 = GEN6_3DPRIM_LINESTRIP,
+      [PIPE_PRIM_TRIANGLES]                  = GEN6_3DPRIM_TRILIST,
+      [PIPE_PRIM_TRIANGLE_STRIP]             = GEN6_3DPRIM_TRISTRIP,
+      [PIPE_PRIM_TRIANGLE_FAN]               = GEN6_3DPRIM_TRIFAN,
+      [PIPE_PRIM_QUADS]                      = GEN6_3DPRIM_QUADLIST,
+      [PIPE_PRIM_QUAD_STRIP]                 = GEN6_3DPRIM_QUADSTRIP,
+      [PIPE_PRIM_POLYGON]                    = GEN6_3DPRIM_POLYGON,
+      [PIPE_PRIM_LINES_ADJACENCY]            = GEN6_3DPRIM_LINELIST_ADJ,
+      [PIPE_PRIM_LINE_STRIP_ADJACENCY]       = GEN6_3DPRIM_LINESTRIP_ADJ,
+      [PIPE_PRIM_TRIANGLES_ADJACENCY]        = GEN6_3DPRIM_TRILIST_ADJ,
+      [PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY]   = GEN6_3DPRIM_TRISTRIP_ADJ,
+   };
+
+   assert(prim_mapping[mode]);
+
+   return prim_mapping[mode];
+}
+
 static enum gen_index_format
 ilo_translate_index_size(unsigned index_size)
 {
@@ -386,6 +413,7 @@ finalize_index_buffer(struct ilo_context *ilo)
           vec->ib.state.offset % vec->ib.state.index_size));
    struct pipe_resource *current_hw_res = NULL;
    struct ilo_state_index_buffer_info info;
+   int64_t vertex_start_bias = 0;
 
    if (!(vec->dirty & ILO_DIRTY_IB) && !need_upload)
       return;
@@ -410,25 +438,23 @@ finalize_index_buffer(struct ilo_context *ilo)
 
       /* the HW offset should be aligned */
       assert(hw_offset % vec->ib.state.index_size == 0);
-      vec->ib.draw_start_offset = hw_offset / vec->ib.state.index_size;
+      vertex_start_bias = hw_offset / vec->ib.state.index_size;
 
       /*
        * INDEX[vec->draw->start] in the original buffer is INDEX[0] in the HW
        * resource
        */
-      vec->ib.draw_start_offset -= vec->draw->start;
+      vertex_start_bias -= vec->draw->start;
    } else {
       pipe_resource_reference(&vec->ib.hw_resource, vec->ib.state.buffer);
 
       /* note that index size may be zero when the draw is not indexed */
-      if (vec->draw->indexed) {
-         vec->ib.draw_start_offset =
-            vec->ib.state.offset / vec->ib.state.index_size;
-      } else {
-         vec->ib.draw_start_offset = 0;
-      }
+      if (vec->draw->indexed)
+         vertex_start_bias = vec->ib.state.offset / vec->ib.state.index_size;
    }
 
+   vec->draw_info.vertex_start += vertex_start_bias;
+
    /* treat the IB as clean if the HW states do not change */
    if (vec->ib.hw_resource == current_hw_res &&
        vec->ib.hw_index_size == vec->ib.state.index_size)
@@ -456,8 +482,6 @@ finalize_vertex_elements(struct ilo_context *ilo)
    const struct ilo_dev *dev = ilo->dev;
    struct ilo_state_vector *vec = &ilo->state_vector;
    struct ilo_ve_state *ve = vec->ve;
-   const enum gen_3dprim_type topology =
-      gen6_3d_translate_pipe_prim(vec->draw->mode);
    const bool last_element_edge_flag = (vec->vs &&
          ilo_shader_get_kernel_param(vec->vs, ILO_KERNEL_VS_INPUT_EDGEFLAG));
    const bool prepend_vertexid = (vec->vs &&
@@ -469,14 +493,14 @@ finalize_vertex_elements(struct ilo_context *ilo)
       ilo_translate_index_size(vec->ib.state.index_size) : GEN6_INDEX_DWORD;
 
    /* check for non-orthogonal states */
-   if (ve->vf_params.cv_topology != topology ||
+   if (ve->vf_params.cv_topology != vec->draw_info.topology ||
        ve->vf_params.prepend_vertexid != prepend_vertexid ||
        ve->vf_params.prepend_instanceid != prepend_instanceid ||
        ve->vf_params.last_element_edge_flag != last_element_edge_flag ||
        ve->vf_params.cv_index_format != index_format ||
        ve->vf_params.cut_index_enable != vec->draw->primitive_restart ||
        ve->vf_params.cut_index != vec->draw->restart_index) {
-      ve->vf_params.cv_topology = topology;
+      ve->vf_params.cv_topology = vec->draw_info.topology;
       ve->vf_params.prepend_vertexid = prepend_vertexid;
       ve->vf_params.prepend_instanceid = prepend_instanceid;
       ve->vf_params.last_element_edge_flag = last_element_edge_flag;
@@ -769,6 +793,14 @@ ilo_finalize_3d_states(struct ilo_context *ilo,
 {
    ilo->state_vector.draw = draw;
 
+   ilo->state_vector.draw_info.topology = ilo_translate_draw_mode(draw->mode);
+   ilo->state_vector.draw_info.indexed = draw->indexed;
+   ilo->state_vector.draw_info.vertex_count = draw->count;
+   ilo->state_vector.draw_info.vertex_start = draw->start;
+   ilo->state_vector.draw_info.instance_count = draw->instance_count;
+   ilo->state_vector.draw_info.instance_start = draw->start_instance;
+   ilo->state_vector.draw_info.vertex_base = draw->index_bias;
+
    finalize_blend(ilo);
    finalize_shader_states(&ilo->state_vector);
    finalize_constant_buffers(ilo);
index 537e5db120b7b578b916e4cc091d92dcc404080e..3e6fd8a2554408859eb5301463c36199cc55e38a 100644 (file)
@@ -28,6 +28,7 @@
 #ifndef ILO_STATE_H
 #define ILO_STATE_H
 
+#include "core/ilo_builder_3d.h" /* for gen6_3dprimitive_info */
 #include "core/ilo_state_cc.h"
 #include "core/ilo_state_compute.h"
 #include "core/ilo_state_raster.h"
@@ -169,8 +170,6 @@ struct ilo_ib_state {
    struct pipe_resource *hw_resource;
    unsigned hw_index_size;
    struct ilo_state_index_buffer ib;
-   /* an offset to be added to pipe_draw_info::start */
-   int64_t draw_start_offset;
 };
 
 struct ilo_cbuf_cso {
@@ -339,6 +338,7 @@ struct ilo_global_binding {
 
 struct ilo_state_vector {
    const struct pipe_draw_info *draw;
+   struct gen6_3dprimitive_info draw_info;
 
    uint32_t dirty;