ilo: use dynamic bo for rectlist vertices
authorChia-I Wu <olvaffe@gmail.com>
Sat, 27 Sep 2014 16:41:42 +0000 (00:41 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Tue, 30 Sep 2014 08:41:31 +0000 (16:41 +0800)
The size is always 24 bytes.  We can upload them to the dynamic buffer.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
src/gallium/drivers/ilo/ilo_blitter.c
src/gallium/drivers/ilo/ilo_blitter.h
src/gallium/drivers/ilo/ilo_blitter_rectlist.c
src/gallium/drivers/ilo/ilo_builder.h
src/gallium/drivers/ilo/ilo_builder_3d_top.h
src/gallium/drivers/ilo/ilo_render.c
src/gallium/drivers/ilo/ilo_render_dynamic.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

index d08563da436fdbf40c54d942f16370dd5d22edf3..103359203642627041ff29499b96f6bc9cd44b6a 100644 (file)
@@ -70,10 +70,5 @@ ilo_blitter_destroy(struct ilo_blitter *blitter)
    if (blitter->pipe_blitter)
       util_blitter_destroy(blitter->pipe_blitter);
 
-   if (blitter->buffer.res) {
-      struct pipe_screen *screen = blitter->ilo->base.screen;
-      screen->resource_destroy(screen, blitter->buffer.res);
-   }
-
    FREE(blitter);
 }
index 1c36e361a76c94a5fb872a1c75428648e79ab299..4284f415c1cf8947c2d053497f2cb5b18d5c19e1 100644 (file)
@@ -62,13 +62,8 @@ struct ilo_blitter {
 
    bool initialized;
 
-   struct {
-      struct pipe_resource *res;
-      unsigned offset, size;
-   } buffer;
-
+   float vertices[3][2];
    struct ilo_ve_state ve;
-   struct ilo_vb_state vb;
    struct pipe_draw_info draw;
 
    struct ilo_viewport_cso viewport;
index aafb5f1044376de533aa0a404c3fb8c1ab70d791..699a7decbef94e024141b569d01d3cfbeac10649 100644 (file)
 static bool
 ilo_blitter_set_invariants(struct ilo_blitter *blitter)
 {
-   struct pipe_screen *screen = blitter->ilo->base.screen;
-   struct pipe_resource templ;
    struct pipe_vertex_element velems[2];
    struct pipe_viewport_state vp;
 
    if (blitter->initialized)
       return true;
 
-   blitter->buffer.size = 4096;
-
-   /* allocate the vertex buffer */
-   memset(&templ, 0, sizeof(templ));
-   templ.target = PIPE_BUFFER;
-   templ.width0 = blitter->buffer.size;
-   templ.usage = PIPE_USAGE_STREAM;
-   templ.bind = PIPE_BIND_VERTEX_BUFFER;
-   blitter->buffer.res = screen->resource_create(screen, &templ);
-   if (!blitter->buffer.res)
-      return false;
-
-   /* do not increase reference count */
-   blitter->vb.states[0].buffer = blitter->buffer.res;
-
    /* only vertex X and Y */
-   blitter->vb.states[0].stride = 2 * sizeof(float);
-   blitter->vb.enabled_mask = 0x1;
    memset(&velems, 0, sizeof(velems));
    velems[1].src_format = PIPE_FORMAT_R32G32_FLOAT;
    ilo_gpe_init_ve(blitter->ilo->dev, 2, velems, &blitter->ve);
@@ -120,10 +101,6 @@ ilo_blitter_set_rectlist(struct ilo_blitter *blitter,
                          unsigned x, unsigned y,
                          unsigned width, unsigned height)
 {
-   unsigned usage = PIPE_TRANSFER_WRITE | PIPE_TRANSFER_UNSYNCHRONIZED;
-   float vertices[3][2];
-   struct pipe_box box;
-
    /*
     * From the Sandy Bridge PRM, volume 2 part 1, page 11:
     *
@@ -132,28 +109,12 @@ ilo_blitter_set_rectlist(struct ilo_blitter *blitter,
     *      by the definition of a rectangle. V0=LowerRight, V1=LowerLeft,
     *      V2=UpperLeft. Implied V3 = V0- V1+V2."
     */
-   vertices[0][0] = (float) (x + width);
-   vertices[0][1] = (float) (y + height);
-   vertices[1][0] = (float) x;
-   vertices[1][1] = (float) (y + height);
-   vertices[2][0] = (float) x;
-   vertices[2][1] = (float) y;
-
-   /* buffer is full */
-   if (blitter->buffer.offset + sizeof(vertices) > blitter->buffer.size) {
-      if (!ilo_buffer_rename_bo(ilo_buffer(blitter->buffer.res)))
-         usage &= ~PIPE_TRANSFER_UNSYNCHRONIZED;
-
-      blitter->buffer.offset = 0;
-   }
-
-   u_box_1d(blitter->buffer.offset, sizeof(vertices), &box);
-
-   blitter->ilo->base.transfer_inline_write(&blitter->ilo->base,
-         blitter->buffer.res, 0, usage, &box, vertices, 0, 0);
-
-   blitter->vb.states[0].buffer_offset = blitter->buffer.offset;
-   blitter->buffer.offset += sizeof(vertices);
+   blitter->vertices[0][0] = (float) (x + width);
+   blitter->vertices[0][1] = (float) (y + height);
+   blitter->vertices[1][0] = (float) x;
+   blitter->vertices[1][1] = (float) (y + height);
+   blitter->vertices[2][0] = (float) x;
+   blitter->vertices[2][1] = (float) y;
 }
 
 static void
index 259487e1346de89a2501248f4272b263c78e719a..38b1c8368402b022b55bff1aa47784a9a9cc3ccc 100644 (file)
@@ -283,7 +283,8 @@ ilo_builder_dynamic_pointer(struct ilo_builder *builder,
    struct ilo_builder_writer *writer = &builder->writers[which];
 
    /* all states are at least aligned to 32-bytes */
-   assert(alignment % 32 == 0);
+   if (item != ILO_BUILDER_ITEM_BLOB)
+      assert(alignment % 32 == 0);
 
    *dw = (uint32_t *) ((char *) writer->ptr + offset);
 
index fb7b92740f37ff015d3595d24544abe8d03e0768..4d0750f875372674a56572429b78d0e7dc1d4f19 100644 (file)
@@ -408,6 +408,36 @@ gen6_3DSTATE_VERTEX_BUFFERS(struct ilo_builder *builder,
    }
 }
 
+/* the user vertex buffer must be uploaded with gen6_user_vertex_buffer() */
+static inline void
+gen6_user_3DSTATE_VERTEX_BUFFERS(struct ilo_builder *builder,
+                                 uint32_t vb_begin, uint32_t vb_end,
+                                 uint32_t stride)
+{
+   const struct ilo_builder_writer *bat =
+      &builder->writers[ILO_BUILDER_WRITER_BATCH];
+   const uint8_t cmd_len = 1 + 4;
+   uint32_t *dw;
+   unsigned pos;
+
+   ILO_DEV_ASSERT(builder->dev, 6, 7.5);
+
+   pos = ilo_builder_batch_pointer(builder, cmd_len, &dw);
+
+   dw[0] = GEN6_RENDER_CMD(3D, 3DSTATE_VERTEX_BUFFERS) | (cmd_len - 2);
+   dw++;
+   pos++;
+
+   /* VERTEX_BUFFER_STATE */
+   dw[0] = 0 << GEN6_VB_STATE_DW0_INDEX__SHIFT |
+           GEN6_VB_STATE_DW0_ACCESS_VERTEXDATA |
+           stride << GEN6_VB_STATE_DW0_PITCH__SHIFT;
+   dw[3] = 0;
+
+   ilo_builder_batch_reloc(builder, pos + 1, bat->bo, vb_begin, 0);
+   ilo_builder_batch_reloc(builder, pos + 2, bat->bo, vb_end, 0);
+}
+
 static inline void
 ve_init_cso_with_components(const struct ilo_dev_info *dev,
                             int comp0, int comp1, int comp2, int comp3,
@@ -1619,4 +1649,19 @@ gen6_push_constant_buffer(struct ilo_builder *builder,
    return state_offset;
 }
 
+static inline uint32_t
+gen6_user_vertex_buffer(struct ilo_builder *builder,
+                        int size, const void *vertices)
+{
+   const int state_align = 8;
+   const int state_len = size / 4;
+
+   ILO_DEV_ASSERT(builder->dev, 6, 7.5);
+
+   assert(size % 4 == 0);
+
+   return ilo_builder_dynamic_write(builder, ILO_BUILDER_ITEM_BLOB,
+         state_align, state_len, vertices);
+}
+
 #endif /* ILO_BUILDER_3D_TOP_H */
index ae778584972417d742a23316479a6713c0984aaf..945d4cdb5aaca6e5e54d973bd6598e0d641e7349 100644 (file)
@@ -367,10 +367,13 @@ void
 ilo_render_emit_rectlist(struct ilo_render *render,
                          const struct ilo_blitter *blitter)
 {
+   struct ilo_render_rectlist_session session;
+
    ILO_DEV_ASSERT(render->dev, 6, 7.5);
 
-   ilo_render_emit_rectlist_dynamic_states(render, blitter);
-   ilo_render_emit_rectlist_commands(render, blitter);
+   memset(&session, 0, sizeof(session));
+   ilo_render_emit_rectlist_dynamic_states(render, blitter, &session);
+   ilo_render_emit_rectlist_commands(render, blitter, &session);
 }
 
 int
index 74d788dd5152699f15aa77892312e9f723e567d1..dfd29c3c3acb40d878e8471c29078a1d08fb6506 100644 (file)
@@ -395,17 +395,23 @@ ilo_render_get_rectlist_dynamic_states_len(const struct ilo_render *render,
 {
    ILO_DEV_ASSERT(render->dev, 6, 7.5);
 
-   return 64;
+   return 96;
 }
 
 void
 ilo_render_emit_rectlist_dynamic_states(struct ilo_render *render,
-                                        const struct ilo_blitter *blitter)
+                                        const struct ilo_blitter *blitter,
+                                        struct ilo_render_rectlist_session *session)
 {
    const unsigned dynamic_used = ilo_builder_dynamic_used(render->builder);
 
    ILO_DEV_ASSERT(render->dev, 6, 7.5);
 
+   /* both are inclusive */
+   session->vb_start = gen6_user_vertex_buffer(render->builder,
+         sizeof(blitter->vertices), (const void *) blitter->vertices);
+   session->vb_end = session->vb_start + sizeof(blitter->vertices) - 1;
+
    if (blitter->uses & ILO_BLITTER_USE_DSA) {
       render->state.DEPTH_STENCIL_STATE =
          gen6_DEPTH_STENCIL_STATE(render->builder, &blitter->dsa);
index 8c874979cacd52b853571385f9ced8e035ff6b9d..f21df4a5a2caff23cfce3cbdf7c9619fe55232de 100644 (file)
@@ -157,6 +157,11 @@ struct ilo_render_draw_session {
    int num_surfaces[PIPE_SHADER_TYPES];
 };
 
+struct ilo_render_rectlist_session {
+   uint32_t vb_start;
+   uint32_t vb_end;
+};
+
 int
 ilo_render_get_draw_commands_len_gen6(const struct ilo_render *render,
                                       const struct ilo_state_vector *vec);
@@ -214,22 +219,25 @@ ilo_render_get_rectlist_commands_len(const struct ilo_render *render,
 
 void
 ilo_render_emit_rectlist_commands_gen6(struct ilo_render *r,
-                                       const struct ilo_blitter *blitter);
+                                       const struct ilo_blitter *blitter,
+                                       const struct ilo_render_rectlist_session *session);
 
 void
 ilo_render_emit_rectlist_commands_gen7(struct ilo_render *r,
-                                       const struct ilo_blitter *blitter);
+                                       const struct ilo_blitter *blitter,
+                                       const struct ilo_render_rectlist_session *session);
 
 static inline void
 ilo_render_emit_rectlist_commands(struct ilo_render *render,
-                                  const struct ilo_blitter *blitter)
+                                  const struct ilo_blitter *blitter,
+                                  const struct ilo_render_rectlist_session *session)
 {
    const unsigned batch_used = ilo_builder_batch_used(render->builder);
 
    if (ilo_dev_gen(render->dev) >= ILO_GEN(7))
-      ilo_render_emit_rectlist_commands_gen7(render, blitter);
+      ilo_render_emit_rectlist_commands_gen7(render, blitter, session);
    else
-      ilo_render_emit_rectlist_commands_gen6(render, blitter);
+      ilo_render_emit_rectlist_commands_gen6(render, blitter, session);
 
    assert(ilo_builder_batch_used(render->builder) <= batch_used +
          ilo_render_get_rectlist_commands_len(render, blitter));
@@ -250,7 +258,8 @@ ilo_render_get_rectlist_dynamic_states_len(const struct ilo_render *render,
 
 void
 ilo_render_emit_rectlist_dynamic_states(struct ilo_render *render,
-                                        const struct ilo_blitter *blitter);
+                                        const struct ilo_blitter *blitter,
+                                        struct ilo_render_rectlist_session *session);
 
 int
 ilo_render_get_draw_surface_states_len(const struct ilo_render *render,
index cd84e0ceacea6222634a9fd002d8745b386760cc..9369f6326d51c2845d4023c8342333b5c67e1c5e 100644 (file)
@@ -963,7 +963,8 @@ ilo_render_get_rectlist_commands_len_gen6(const struct ilo_render *render,
 
 void
 ilo_render_emit_rectlist_commands_gen6(struct ilo_render *r,
-                                       const struct ilo_blitter *blitter)
+                                       const struct ilo_blitter *blitter,
+                                       const struct ilo_render_rectlist_session *session)
 {
    ILO_DEV_ASSERT(r->dev, 6, 6);
 
@@ -973,8 +974,9 @@ ilo_render_emit_rectlist_commands_gen6(struct ilo_render *r,
 
    gen6_state_base_address(r->builder, true);
 
-   gen6_3DSTATE_VERTEX_BUFFERS(r->builder,
-         &blitter->ve, &blitter->vb);
+   gen6_user_3DSTATE_VERTEX_BUFFERS(r->builder,
+         session->vb_start, session->vb_end,
+         sizeof(blitter->vertices[0]));
 
    gen6_3DSTATE_VERTEX_ELEMENTS(r->builder,
          &blitter->ve, false, false);
index 6714c80c877f8bc953a4c0ce6435d8e497b432f0..a39944e67b2b06e95642acd4810fe7a854d917cf 100644 (file)
@@ -826,7 +826,8 @@ gen7_rectlist_wm_multisample(struct ilo_render *r,
 
 void
 ilo_render_emit_rectlist_commands_gen7(struct ilo_render *r,
-                                       const struct ilo_blitter *blitter)
+                                       const struct ilo_blitter *blitter,
+                                       const struct ilo_render_rectlist_session *session)
 {
    ILO_DEV_ASSERT(r->dev, 7, 7.5);
 
@@ -834,8 +835,9 @@ ilo_render_emit_rectlist_commands_gen7(struct ilo_render *r,
 
    gen6_state_base_address(r->builder, true);
 
-   gen6_3DSTATE_VERTEX_BUFFERS(r->builder,
-         &blitter->ve, &blitter->vb);
+   gen6_user_3DSTATE_VERTEX_BUFFERS(r->builder,
+         session->vb_start, session->vb_end,
+         sizeof(blitter->vertices[0]));
 
    gen6_3DSTATE_VERTEX_ELEMENTS(r->builder,
          &blitter->ve, false, false);