[g3dvl] remove shadow buffering of vertex buffers
authorChristian König <deathsimple@vodafone.de>
Wed, 8 Dec 2010 19:48:34 +0000 (20:48 +0100)
committerChristian König <deathsimple@vodafone.de>
Wed, 8 Dec 2010 19:48:34 +0000 (20:48 +0100)
src/gallium/auxiliary/vl/vl_idct.c
src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c
src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h
src/gallium/auxiliary/vl/vl_vertex_buffers.c
src/gallium/auxiliary/vl/vl_vertex_buffers.h

index 168e6e88b2bc53d64d874749416859ffc48dff41..0a81134a789b33fb03825d1d9f0f2000530174bf 100644 (file)
@@ -464,14 +464,13 @@ init_vertex_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer)
    buffer->vertex_bufs.individual.quad.buffer_offset = idct->quad.buffer_offset;
    pipe_resource_reference(&buffer->vertex_bufs.individual.quad.buffer, idct->quad.buffer);
 
-   buffer->vertex_bufs.individual.pos = vl_vb_create_buffer(idct->pipe, idct->max_blocks, idct->vertex_buffer_stride);
+   buffer->vertex_bufs.individual.pos = vl_vb_init(
+      &buffer->blocks, idct->pipe, idct->max_blocks, 2,
+      idct->vertex_buffer_stride);
 
    if(buffer->vertex_bufs.individual.pos.buffer == NULL)
       return false;
 
-   if (!vl_vb_init(&buffer->blocks, idct->max_blocks, 2))
-      return false;
-
    return true;
 }
 
@@ -668,6 +667,8 @@ vl_idct_map_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer)
    );
 
    buffer->texels = idct->pipe->transfer_map(idct->pipe, buffer->tex_transfer);
+
+   vl_vb_map(&buffer->blocks, idct->pipe);
 }
 
 void
@@ -699,28 +700,17 @@ vl_idct_unmap_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer)
 
    idct->pipe->transfer_unmap(idct->pipe, buffer->tex_transfer);
    idct->pipe->transfer_destroy(idct->pipe, buffer->tex_transfer);
+   vl_vb_unmap(&buffer->blocks, idct->pipe);
 }
 
 void
 vl_idct_flush(struct vl_idct *idct, struct vl_idct_buffer *buffer)
 {
-   struct pipe_transfer *vec_transfer;
-   void *vectors;
    unsigned num_verts;
 
    assert(idct);
 
-   vectors = pipe_buffer_map
-   (
-      idct->pipe,
-      buffer->vertex_bufs.individual.pos.buffer,
-      PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
-      &vec_transfer
-   );
-
-   num_verts = vl_vb_upload(&buffer->blocks, vectors);
-
-   pipe_buffer_unmap(idct->pipe, buffer->vertex_bufs.individual.pos.buffer, vec_transfer);
+   num_verts = vl_vb_restart(&buffer->blocks);
 
    if(num_verts > 0) {
 
index ed2de7930e7a6c4f8721cd7cad652985f6848d99..66e4fc0a07a716a29e468c3fa7d9782975448c1c 100644 (file)
@@ -95,16 +95,6 @@ enum VS_OUTPUT
    VS_O_MV3
 };
 
-static const unsigned const_mbtype_config[VL_NUM_MACROBLOCK_TYPES][2] = {
-   [VL_MACROBLOCK_TYPE_INTRA]           = { 0, 0 },
-   [VL_MACROBLOCK_TYPE_FWD_FRAME_PRED]  = { 1, 1 },
-   [VL_MACROBLOCK_TYPE_FWD_FIELD_PRED]  = { 1, 2 },
-   [VL_MACROBLOCK_TYPE_BKWD_FRAME_PRED] = { 1, 1 },
-   [VL_MACROBLOCK_TYPE_BKWD_FIELD_PRED] = { 1, 2 },
-   [VL_MACROBLOCK_TYPE_BI_FRAME_PRED]   = { 2, 1 },
-   [VL_MACROBLOCK_TYPE_BI_FIELD_PRED]   = { 2, 2 }
-};
-
 static void *
 create_vert_shader(struct vl_mpeg12_mc_renderer *r)
 {
@@ -662,15 +652,19 @@ init_buffers(struct vl_mpeg12_mc_renderer *r)
 
    stride = vl_vb_element_helper(&vertex_elems[VS_I_VPOS], 9, 1);
 
-   r->vertex_bufs.individual.pos = vl_vb_create_buffer(
-      r->pipe, r->macroblocks_per_batch, stride);
+   r->vertex_bufs.individual.pos = vl_vb_init(
+      &r->pos, r->pipe, r->macroblocks_per_batch, 
+      sizeof(struct vertex_stream_0) / sizeof(float),
+      stride);
 
    for (i = 0; i < 4; ++i) {
       /* motion vector 0..4 element */
       vertex_elems[VS_I_MV0 + i].src_format = PIPE_FORMAT_R32G32_FLOAT;
       stride = vl_vb_element_helper(&vertex_elems[VS_I_MV0 + i], 1, i + 2);
-      r->vertex_bufs.individual.mv[i] = vl_vb_create_buffer(
-         r->pipe, r->macroblocks_per_batch, stride);
+      r->vertex_bufs.individual.mv[i] = vl_vb_init(
+         &r->mv[i], r->pipe, r->macroblocks_per_batch,
+         sizeof(struct vertex2f) / sizeof(float),
+         stride);
    }
 
    r->vertex_elems_state = r->pipe->create_vertex_elements_state(
@@ -685,14 +679,6 @@ init_buffers(struct vl_mpeg12_mc_renderer *r)
    if (r->vs == NULL || r->fs == NULL)
       return false;
 
-   if (!vl_vb_init(&r->pos, r->macroblocks_per_batch, sizeof(struct vertex_stream_0) / sizeof(float)))
-      return false;
-
-   for (i = 0; i < 4; ++i) {
-      if (!vl_vb_init(&r->mv[i], r->macroblocks_per_batch, sizeof(struct vertex2f) / sizeof(float)))
-         return false;
-   }
-
    return true;
 }
 
@@ -731,44 +717,6 @@ cleanup_buffers(struct vl_mpeg12_mc_renderer *r)
    r->pipe->delete_vertex_elements_state(r->pipe, r->vertex_elems_state);
 }
 
-static void
-upload_vertex_stream(struct vl_mpeg12_mc_renderer *r)
-{
-   struct vertex_stream_0 *pos;
-   struct vertex2f *mv[4];
-
-   struct pipe_transfer *buf_transfer[5];
-
-   unsigned i, j;
-
-   assert(r);
-
-   pos = (struct vertex_stream_0 *)pipe_buffer_map
-   (
-      r->pipe,
-      r->vertex_bufs.individual.pos.buffer,
-      PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
-      &buf_transfer[0]
-   );
-
-   for (i = 0; i < 4; ++i)
-      mv[i] = (struct vertex2f *)pipe_buffer_map
-      (
-         r->pipe,
-         r->vertex_bufs.individual.mv[i].buffer,
-         PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
-         &buf_transfer[i + 1]
-      );
-
-   vl_vb_upload(&r->pos, pos);
-   for (j = 0; j < 4; ++j)
-      vl_vb_upload(&r->mv[j], mv[j]);
-
-   pipe_buffer_unmap(r->pipe, r->vertex_bufs.individual.pos.buffer, buf_transfer[0]);
-   for (i = 0; i < 4; ++i)
-      pipe_buffer_unmap(r->pipe, r->vertex_bufs.individual.mv[i].buffer, buf_transfer[i + 1]);
-}
-
 static struct pipe_sampler_view
 *find_or_create_sampler_view(struct vl_mpeg12_mc_renderer *r, struct pipe_surface *surface)
 {
@@ -1100,6 +1048,8 @@ vl_mpeg12_mc_renderer_render_macroblocks(struct vl_mpeg12_mc_renderer
 void
 vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer)
 {
+   unsigned i;
+
    assert(renderer);
    assert(renderer->num_macroblocks <= renderer->macroblocks_per_batch);
 
@@ -1114,7 +1064,12 @@ vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer)
    vl_idct_flush(&renderer->idct_chroma, &renderer->idct_cr);
    vl_idct_flush(&renderer->idct_chroma, &renderer->idct_cb);
 
-   upload_vertex_stream(renderer);
+   vl_vb_unmap(&renderer->pos, renderer->pipe);
+   vl_vb_restart(&renderer->pos);
+   for(i = 0; i < 4; ++i) {
+      vl_vb_unmap(&renderer->mv[i], renderer->pipe);
+      vl_vb_restart(&renderer->mv[i]);
+   }
 
    renderer->fb_state.cbufs[0] = renderer->surface;
    renderer->pipe->bind_rasterizer_state(renderer->pipe, renderer->rs_state);
@@ -1145,5 +1100,9 @@ vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer)
    vl_idct_map_buffers(&renderer->idct_chroma, &renderer->idct_cr);
    vl_idct_map_buffers(&renderer->idct_chroma, &renderer->idct_cb);
 
+   vl_vb_map(&renderer->pos, renderer->pipe);
+   for(i = 0; i < 4; ++i)
+      vl_vb_map(&renderer->mv[i], renderer->pipe);
+
    renderer->num_macroblocks = 0;
 }
index e0349886fa2ebb26195786729beaa6035f9943c7..e12ac50ae0d6971ac50abefc62e96c506ee29ae4 100644 (file)
@@ -46,19 +46,6 @@ enum VL_MPEG12_MC_RENDERER_BUFFER_MODE
    VL_MPEG12_MC_RENDERER_BUFFER_PICTURE /* Larger batches, more memory */
 };
 
-enum VL_MACROBLOCK_TYPE
-{
-   VL_MACROBLOCK_TYPE_INTRA,
-   VL_MACROBLOCK_TYPE_FWD_FRAME_PRED,
-   VL_MACROBLOCK_TYPE_FWD_FIELD_PRED,
-   VL_MACROBLOCK_TYPE_BKWD_FRAME_PRED,
-   VL_MACROBLOCK_TYPE_BKWD_FIELD_PRED,
-   VL_MACROBLOCK_TYPE_BI_FRAME_PRED,
-   VL_MACROBLOCK_TYPE_BI_FIELD_PRED,
-
-   VL_NUM_MACROBLOCK_TYPES
-};
-
 struct vl_mpeg12_mc_renderer
 {
    struct pipe_context *pipe;
index 4647685053b4fc1d944d8b1a3d41ee939e61b6e9..4182bad784ba117f979f6f2ff8e32ceb98fad1b3 100644 (file)
@@ -96,24 +96,6 @@ vl_vb_get_quad_vertex_element()
    return element;
 }
 
-struct pipe_vertex_buffer
-vl_vb_create_buffer(struct pipe_context *pipe, unsigned max_blocks, unsigned stride)
-{
-   struct pipe_vertex_buffer buf;
-
-   buf.stride = stride;
-   buf.max_index = 4 * max_blocks - 1;
-   buf.buffer_offset = 0;
-   buf.buffer = pipe_buffer_create
-   (
-      pipe->screen,
-      PIPE_BIND_VERTEX_BUFFER,
-      stride * 4 * max_blocks
-   );
-
-   return buf;
-}
-
 unsigned
 vl_vb_element_helper(struct pipe_vertex_element* elements, unsigned num_elements,
                               unsigned vertex_buffer_index)
@@ -132,30 +114,63 @@ vl_vb_element_helper(struct pipe_vertex_element* elements, unsigned num_elements
    return offset;
 }
 
-bool
-vl_vb_init(struct vl_vertex_buffer *buffer, unsigned max_blocks, unsigned num_elements)
+struct pipe_vertex_buffer
+vl_vb_init(struct vl_vertex_buffer *buffer, struct pipe_context *pipe,
+           unsigned max_blocks, unsigned num_elements, unsigned stride)
 {
+   struct pipe_vertex_buffer buf;
+
    assert(buffer);
 
    buffer->num_verts = 0;
    buffer->num_elements = num_elements;
-   buffer->buffer = MALLOC(max_blocks * num_elements * sizeof(float) * 4);
-   return buffer->buffer != NULL;
+
+   buf.stride = stride;
+   buf.max_index = 4 * max_blocks - 1;
+   buf.buffer_offset = 0;
+   buf.buffer = pipe_buffer_create
+   (
+      pipe->screen,
+      PIPE_BIND_VERTEX_BUFFER,
+      stride * 4 * max_blocks
+   );
+
+   pipe_resource_reference(&buffer->resource, buf.buffer);
+
+   vl_vb_map(buffer, pipe);
+
+   return buf;
 }
 
-unsigned
-vl_vb_upload(struct vl_vertex_buffer *buffer, void *dst)
+void
+vl_vb_map(struct vl_vertex_buffer *buffer, struct pipe_context *pipe)
 {
-   unsigned todo;
+   assert(buffer && pipe);
 
-   assert(buffer);
+   buffer->vectors = pipe_buffer_map
+   (
+      pipe,
+      buffer->resource,
+      PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
+      &buffer->transfer
+   );
+}
 
-   todo = buffer->num_verts;
-   buffer->num_verts = 0;
+void
+vl_vb_unmap(struct vl_vertex_buffer *buffer, struct pipe_context *pipe)
+{
+   assert(buffer && pipe);
 
-   if(todo)
-      memcpy(dst, buffer->buffer, sizeof(float) * buffer->num_elements * todo);
+   pipe_buffer_unmap(pipe, buffer->resource, buffer->transfer);
+}
+
+unsigned
+vl_vb_restart(struct vl_vertex_buffer *buffer)
+{
+   assert(buffer);
 
+   unsigned todo = buffer->num_verts;
+   buffer->num_verts = 0;
    return todo;
 }
 
@@ -164,5 +179,5 @@ vl_vb_cleanup(struct vl_vertex_buffer *buffer)
 {
    assert(buffer);
 
-   FREE(buffer->buffer);
+   pipe_resource_reference(&buffer->resource, NULL);
 }
index dae80fa767bfc8c07bb353ddbba0b68eda81c60c..e312515dc3090f49ac2fd83afc0373d482d42c73 100644 (file)
@@ -35,19 +35,24 @@ struct vl_vertex_buffer
 {
    unsigned num_verts;
    unsigned num_elements;
-   float *buffer;
+   struct pipe_resource *resource;
+   struct pipe_transfer *transfer;
+   float *vectors;
 };
 
 struct pipe_vertex_buffer vl_vb_upload_quads(struct pipe_context *pipe, unsigned max_blocks);
 
 struct pipe_vertex_element vl_vb_get_quad_vertex_element();
 
-struct pipe_vertex_buffer vl_vb_create_buffer(struct pipe_context *pipe, unsigned max_blocks, unsigned stride);
-
 unsigned vl_vb_element_helper(struct pipe_vertex_element* elements, unsigned num_elements,
                               unsigned vertex_buffer_index);
 
-bool vl_vb_init(struct vl_vertex_buffer *buffer, unsigned max_blocks, unsigned num_elements);
+struct pipe_vertex_buffer vl_vb_init(struct vl_vertex_buffer *buffer,
+                                     struct pipe_context *pipe,
+                                     unsigned max_blocks, unsigned num_elements,
+                                     unsigned stride);
+
+void vl_vb_map(struct vl_vertex_buffer *buffer, struct pipe_context *pipe);
 
 static inline void
 vl_vb_add_block(struct vl_vertex_buffer *buffer, float *elements)
@@ -58,13 +63,15 @@ vl_vb_add_block(struct vl_vertex_buffer *buffer, float *elements)
    assert(buffer);
 
    for(i = 0; i < 4; ++i) {
-      pos = buffer->buffer + buffer->num_verts * buffer->num_elements;
+      pos = buffer->vectors + buffer->num_verts * buffer->num_elements;
       memcpy(pos, elements, sizeof(float) * buffer->num_elements);
       buffer->num_verts++;
    }
 }
 
-unsigned vl_vb_upload(struct vl_vertex_buffer *buffer, void *dst);
+void vl_vb_unmap(struct vl_vertex_buffer *buffer, struct pipe_context *pipe);
+
+unsigned vl_vb_restart(struct vl_vertex_buffer *buffer);
 
 void vl_vb_cleanup(struct vl_vertex_buffer *buffer);