[g3dvl] start to cleanup the mess
authorChristian König <deathsimple@vodafone.de>
Tue, 8 Mar 2011 20:30:33 +0000 (21:30 +0100)
committerChristian König <deathsimple@vodafone.de>
Tue, 8 Mar 2011 20:30:33 +0000 (21:30 +0100)
Move the vertex buffer out of the mc code

src/gallium/auxiliary/vl/vl_idct.c
src/gallium/auxiliary/vl/vl_idct.h
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
src/gallium/drivers/r600/r600_video_context.c
src/gallium/drivers/softpipe/sp_video_context.c
src/gallium/drivers/softpipe/sp_video_context.h

index b418aea951409728aa205f068a743e24d3bfb58d..f191a898eddfa1eea486dd09710c1051d46f6a6f 100644 (file)
@@ -394,11 +394,6 @@ init_state(struct vl_idct *idct)
 
    assert(idct);
 
-   idct->quad = vl_vb_upload_quads(idct->pipe, idct->blocks_x, idct->blocks_y);
-
-   if(idct->quad.buffer == NULL)
-      return false;
-
    for (i = 0; i < 4; ++i) {
       memset(&sampler, 0, sizeof(sampler));
       sampler.wrap_s = PIPE_TEX_WRAP_REPEAT;
@@ -427,8 +422,6 @@ init_state(struct vl_idct *idct)
    rs_state.gl_rasterization_rules = false;
    idct->rs_state = idct->pipe->create_rasterizer_state(idct->pipe, &rs_state);
 
-   idct->vertex_elems_state = vl_vb_get_elems_state(idct->pipe, false);
-
    return true;
 }
 
@@ -441,7 +434,6 @@ cleanup_state(struct vl_idct *idct)
       idct->pipe->delete_sampler_state(idct->pipe, idct->samplers.all[i]);
 
    idct->pipe->delete_rasterizer_state(idct->pipe, idct->rs_state);
-   idct->pipe->delete_vertex_elements_state(idct->pipe, idct->vertex_elems_state);
 }
 
 static bool
@@ -500,31 +492,6 @@ cleanup_textures(struct vl_idct *idct, struct vl_idct_buffer *buffer)
    }
 }
 
-static bool
-init_vertex_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer, struct pipe_vertex_buffer stream)
-{
-   assert(idct && buffer);
-
-   buffer->vertex_bufs.individual.quad.stride = idct->quad.stride;
-   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.stream.stride = stream.stride;
-   buffer->vertex_bufs.individual.stream.buffer_offset = stream.buffer_offset;
-   pipe_resource_reference(&buffer->vertex_bufs.individual.stream.buffer, stream.buffer);
-
-   return true;
-}
-
-static void
-cleanup_vertex_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer)
-{
-   assert(idct && buffer);
-
-   pipe_resource_reference(&buffer->vertex_bufs.individual.quad.buffer, NULL);
-   pipe_resource_reference(&buffer->vertex_bufs.individual.stream.buffer, NULL);
-}
-
 struct pipe_resource *
 vl_idct_upload_matrix(struct pipe_context *pipe)
 {
@@ -612,7 +579,7 @@ vl_idct_cleanup(struct vl_idct *idct)
 
 bool
 vl_idct_init_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer,
-                    struct pipe_resource *dst, struct pipe_vertex_buffer stream)
+                    struct pipe_resource *dst)
 {
    struct pipe_surface template;
 
@@ -629,9 +596,6 @@ vl_idct_init_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer,
    if (!init_textures(idct, buffer))
       return false;
 
-   if (!init_vertex_buffers(idct, buffer, stream))
-      return false;
-
    /* init state */
    buffer->viewport[0].scale[0] = buffer->textures.individual.intermediate->width0;
    buffer->viewport[0].scale[1] = buffer->textures.individual.intermediate->height0;
@@ -693,7 +657,6 @@ vl_idct_cleanup_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer)
    idct->pipe->surface_destroy(idct->pipe, buffer->fb_state[1].cbufs[0]);
 
    cleanup_textures(idct, buffer);
-   cleanup_vertex_buffers(idct, buffer);
 }
 
 void
@@ -758,8 +721,6 @@ vl_idct_flush(struct vl_idct *idct, struct vl_idct_buffer *buffer, unsigned num_
       num_verts = idct->blocks_x * idct->blocks_y * 4;
 
       idct->pipe->bind_rasterizer_state(idct->pipe, idct->rs_state);
-      idct->pipe->set_vertex_buffers(idct->pipe, 2, buffer->vertex_bufs.all);
-      idct->pipe->bind_vertex_elements_state(idct->pipe, idct->vertex_elems_state);
 
       /* first stage */
       idct->pipe->set_framebuffer_state(idct->pipe, &buffer->fb_state[0]);
index 78e4a46369dcb068c88251c9142c884e85a008f3..0ff12cf466d671621eef9c3519c597331d8c9b62 100644 (file)
@@ -40,7 +40,6 @@ struct vl_idct
    unsigned blocks_x, blocks_y;
 
    void *rs_state;
-   void *vertex_elems_state;
 
    union
    {
@@ -56,7 +55,6 @@ struct vl_idct
    void *matrix_fs, *transpose_fs;
 
    struct pipe_resource *matrix;
-   struct pipe_vertex_buffer quad;
 };
 
 struct vl_idct_buffer
@@ -86,12 +84,6 @@ struct vl_idct_buffer
       } individual;
    } textures;
 
-   union
-   {
-      struct pipe_vertex_buffer all[2];
-      struct { struct pipe_vertex_buffer quad, stream; } individual;
-   } vertex_bufs;
-
    struct pipe_transfer *tex_transfer;
    short *texels;
 };
@@ -106,7 +98,7 @@ bool vl_idct_init(struct vl_idct *idct, struct pipe_context *pipe,
 void vl_idct_cleanup(struct vl_idct *idct);
 
 bool vl_idct_init_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer,
-                         struct pipe_resource *dst, struct pipe_vertex_buffer stream);
+                         struct pipe_resource *dst);
 
 void vl_idct_cleanup_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer);
 
index d1b2144aea51e23056665c6aab224170be42b557..160388ad049e5b9a9fe9dc039364ce0e31780f3f 100644 (file)
@@ -485,19 +485,10 @@ static bool
 init_buffers(struct vl_mpeg12_mc_renderer *r)
 {
    struct pipe_resource *idct_matrix;
-
-   const unsigned mbw =
-      align(r->buffer_width, MACROBLOCK_WIDTH) / MACROBLOCK_WIDTH;
-   const unsigned mbh =
-      align(r->buffer_height, MACROBLOCK_HEIGHT) / MACROBLOCK_HEIGHT;
-
    unsigned chroma_width, chroma_height, chroma_blocks_x, chroma_blocks_y;
 
    assert(r);
 
-   r->macroblocks_per_batch =
-      mbw * (r->bufmode == VL_MPEG12_MC_RENDERER_BUFFER_PICTURE ? mbh : 1);
-
    if (!(idct_matrix = vl_idct_upload_matrix(r->pipe)))
       return false;
 
@@ -530,12 +521,6 @@ init_buffers(struct vl_mpeg12_mc_renderer *r)
                     chroma_blocks_x, chroma_blocks_y, TGSI_SWIZZLE_Z, idct_matrix))
       return false;
 
-   r->quad = vl_vb_upload_quads(r->pipe, 1, 1);
-   r->vertex_elems_state = vl_vb_get_elems_state(r->pipe, true);
-
-   if (r->vertex_elems_state == NULL)
-      return false;
-
    r->vs = create_vert_shader(r);
    r->fs = create_frag_shader(r);
 
@@ -556,8 +541,6 @@ cleanup_buffers(struct vl_mpeg12_mc_renderer *r)
    vl_idct_cleanup(&r->idct_y);
    vl_idct_cleanup(&r->idct_cr);
    vl_idct_cleanup(&r->idct_cb);
-
-   r->pipe->delete_vertex_elements_state(r->pipe, r->vertex_elems_state);
 }
 
 static struct pipe_sampler_view
@@ -622,19 +605,6 @@ grab_blocks(struct vl_mpeg12_mc_renderer *r,
    }
 }
 
-static void
-grab_macroblock(struct vl_mpeg12_mc_renderer *r,
-                struct vl_mpeg12_mc_buffer *buffer,
-                struct pipe_mpeg12_macroblock *mb)
-{
-   assert(r);
-   assert(mb);
-   assert(mb->blocks);
-
-   vl_vb_add_block(&buffer->vertex_stream, mb, r->empty_block_mask);
-   grab_blocks(r, buffer, mb->mbx, mb->mby, mb->cbp, mb->blocks);
-}
-
 static void
 texview_map_delete(const struct keymap *map,
                    const void *key, void *data,
@@ -655,22 +625,17 @@ vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer,
                            struct pipe_context *pipe,
                            unsigned buffer_width,
                            unsigned buffer_height,
-                           enum pipe_video_chroma_format chroma_format,
-                           enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode)
+                           enum pipe_video_chroma_format chroma_format)
 {
    assert(renderer);
    assert(pipe);
 
-   /* TODO: Implement other policies */
-   assert(bufmode == VL_MPEG12_MC_RENDERER_BUFFER_PICTURE);
-
    memset(renderer, 0, sizeof(struct vl_mpeg12_mc_renderer));
 
    renderer->pipe = pipe;
    renderer->buffer_width = buffer_width;
    renderer->buffer_height = buffer_height;
    renderer->chroma_format = chroma_format;
-   renderer->bufmode = bufmode;
 
    /* TODO: Implement 422, 444 */
    assert(chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420);
@@ -721,13 +686,6 @@ vl_mpeg12_mc_init_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg1
    buffer->past = NULL;
    buffer->future = NULL;
 
-   buffer->vertex_bufs.individual.quad.stride = renderer->quad.stride;
-   buffer->vertex_bufs.individual.quad.buffer_offset = renderer->quad.buffer_offset;
-   pipe_resource_reference(&buffer->vertex_bufs.individual.quad.buffer, renderer->quad.buffer);
-
-   buffer->vertex_bufs.individual.stream = vl_vb_init(&buffer->vertex_stream, renderer->pipe,
-                                                      renderer->macroblocks_per_batch);
-
    memset(&template, 0, sizeof(struct pipe_resource));
    template.target = PIPE_TEXTURE_2D;
    /* TODO: Accomodate HW that can't do this and also for cases when this isn't precise enough */
@@ -743,9 +701,7 @@ vl_mpeg12_mc_init_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg1
 
    buffer->textures.individual.y = renderer->pipe->screen->resource_create(renderer->pipe->screen, &template);
 
-   if (!vl_idct_init_buffer(&renderer->idct_y, &buffer->idct_y,
-                            buffer->textures.individual.y,
-                            buffer->vertex_bufs.individual.stream))
+   if (!vl_idct_init_buffer(&renderer->idct_y, &buffer->idct_y, buffer->textures.individual.y))
       return false;
 
    if (renderer->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420) {
@@ -760,14 +716,10 @@ vl_mpeg12_mc_init_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg1
    buffer->textures.individual.cr =
       renderer->pipe->screen->resource_create(renderer->pipe->screen, &template);
 
-   if (!vl_idct_init_buffer(&renderer->idct_cb, &buffer->idct_cb,
-                            buffer->textures.individual.cb,
-                            buffer->vertex_bufs.individual.stream))
+   if (!vl_idct_init_buffer(&renderer->idct_cb, &buffer->idct_cb, buffer->textures.individual.cb))
       return false;
 
-   if (!vl_idct_init_buffer(&renderer->idct_cr, &buffer->idct_cr,
-                            buffer->textures.individual.cr,
-                            buffer->vertex_bufs.individual.stream))
+   if (!vl_idct_init_buffer(&renderer->idct_cr, &buffer->idct_cr, buffer->textures.individual.cr))
       return false;
 
    for (i = 0; i < 3; ++i) {
@@ -794,13 +746,9 @@ vl_mpeg12_mc_cleanup_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mp
 
    for (i = 0; i < 3; ++i) {
       pipe_sampler_view_reference(&buffer->sampler_views.all[i], NULL);
-      pipe_resource_reference(&buffer->vertex_bufs.all[i].buffer, NULL);
       pipe_resource_reference(&buffer->textures.all[i], NULL);
    }
 
-   pipe_resource_reference(&buffer->vertex_bufs.individual.quad.buffer, NULL);
-   vl_vb_cleanup(&buffer->vertex_stream);
-
    vl_idct_cleanup_buffer(&renderer->idct_y, &buffer->idct_y);
    vl_idct_cleanup_buffer(&renderer->idct_cb, &buffer->idct_cb);
    vl_idct_cleanup_buffer(&renderer->idct_cr, &buffer->idct_cr);
@@ -818,8 +766,6 @@ vl_mpeg12_mc_map_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12
    vl_idct_map_buffers(&renderer->idct_y, &buffer->idct_y);
    vl_idct_map_buffers(&renderer->idct_cr, &buffer->idct_cr);
    vl_idct_map_buffers(&renderer->idct_cb, &buffer->idct_cb);
-
-   vl_vb_map(&buffer->vertex_stream, renderer->pipe);
 }
 
 void
@@ -851,8 +797,10 @@ vl_mpeg12_mc_renderer_render_macroblocks(struct vl_mpeg12_mc_renderer *renderer,
    }
 
    for (i = 0; i < num_macroblocks; ++i) {
-      assert(mpeg12_macroblocks[i].base.codec == PIPE_VIDEO_CODEC_MPEG12);
-      grab_macroblock(renderer, buffer, &mpeg12_macroblocks[i]);
+      struct pipe_mpeg12_macroblock *mb = &mpeg12_macroblocks[i];
+
+      assert(mb->base.codec == PIPE_VIDEO_CODEC_MPEG12);
+      grab_blocks(renderer, buffer, mb->mbx, mb->mby, mb->cbp, mb->blocks);
    }
 }
 
@@ -864,32 +812,26 @@ vl_mpeg12_mc_unmap_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg
    vl_idct_unmap_buffers(&renderer->idct_y, &buffer->idct_y);
    vl_idct_unmap_buffers(&renderer->idct_cr, &buffer->idct_cr);
    vl_idct_unmap_buffers(&renderer->idct_cb, &buffer->idct_cb);
-
-   vl_vb_unmap(&buffer->vertex_stream, renderer->pipe);
 }
 
 void
-vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_mc_buffer *buffer)
+vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_mc_buffer *buffer,
+                            unsigned not_empty_start_instance, unsigned not_empty_num_instances,
+                            unsigned empty_start_instance, unsigned empty_num_instances)
 {
-   unsigned num_not_empty, num_empty;
    assert(renderer && buffer);
 
-   num_not_empty = buffer->vertex_stream.num_not_empty;
-   num_empty = buffer->vertex_stream.num_empty;
-
-   if (num_not_empty == 0 && num_empty == 0)
+   if (not_empty_num_instances == 0 && empty_num_instances == 0)
       return;
 
-   vl_idct_flush(&renderer->idct_y, &buffer->idct_y, num_not_empty);
-   vl_idct_flush(&renderer->idct_cr, &buffer->idct_cr, num_not_empty);
-   vl_idct_flush(&renderer->idct_cb, &buffer->idct_cb, num_not_empty);
+   vl_idct_flush(&renderer->idct_y, &buffer->idct_y, not_empty_num_instances);
+   vl_idct_flush(&renderer->idct_cr, &buffer->idct_cr, not_empty_num_instances);
+   vl_idct_flush(&renderer->idct_cb, &buffer->idct_cb, not_empty_num_instances);
 
    renderer->fb_state.cbufs[0] = buffer->surface;
    renderer->pipe->bind_rasterizer_state(renderer->pipe, renderer->rs_state);
    renderer->pipe->set_framebuffer_state(renderer->pipe, &renderer->fb_state);
    renderer->pipe->set_viewport_state(renderer->pipe, &renderer->viewport);
-   renderer->pipe->set_vertex_buffers(renderer->pipe, 2, buffer->vertex_bufs.all);
-   renderer->pipe->bind_vertex_elements_state(renderer->pipe, renderer->vertex_elems_state);
 
    if (buffer->past) {
       buffer->sampler_views.individual.ref[0] = find_or_create_sampler_view(renderer, buffer->past);
@@ -909,12 +851,13 @@ vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mp
    renderer->pipe->bind_vs_state(renderer->pipe, renderer->vs);
    renderer->pipe->bind_fs_state(renderer->pipe, renderer->fs);
 
-   if (num_not_empty > 0)
-      util_draw_arrays_instanced(renderer->pipe, PIPE_PRIM_QUADS, 0, 4, 0, num_not_empty);
+   if (not_empty_num_instances > 0)
+      util_draw_arrays_instanced(renderer->pipe, PIPE_PRIM_QUADS, 0, 4,
+                                 not_empty_start_instance, not_empty_num_instances);
 
-   if (num_empty > 0)
+   if (empty_num_instances > 0)
       util_draw_arrays_instanced(renderer->pipe, PIPE_PRIM_QUADS, 0, 4,
-                                 buffer->vertex_stream.size - num_empty, num_empty);
+                                 empty_start_instance, empty_num_instances);
 
    renderer->pipe->flush(renderer->pipe, PIPE_FLUSH_RENDER_CACHE, buffer->fence);
 
@@ -922,6 +865,4 @@ vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mp
    pipe_surface_reference(&buffer->surface, NULL);
    pipe_surface_reference(&buffer->past, NULL);
    pipe_surface_reference(&buffer->future, NULL);
-
-   vl_vb_restart(&buffer->vertex_stream);
 }
index c319064c70f4d33f9a6af35394e5f7aecdce50d4..86a6518e3c2c00524073916246acdd96ffe909c6 100644 (file)
@@ -39,13 +39,6 @@ struct pipe_context;
 struct pipe_macroblock;
 struct keymap;
 
-/* A slice is video-width (rounded up to a multiple of macroblock width) x macroblock height */
-enum VL_MPEG12_MC_RENDERER_BUFFER_MODE
-{
-   VL_MPEG12_MC_RENDERER_BUFFER_SLICE,  /* Saves memory at the cost of smaller batches */
-   VL_MPEG12_MC_RENDERER_BUFFER_PICTURE /* Larger batches, more memory */
-};
-
 struct vl_mpeg12_mc_renderer
 {
    struct pipe_context *pipe;
@@ -53,21 +46,16 @@ struct vl_mpeg12_mc_renderer
    unsigned buffer_height;
    enum pipe_video_chroma_format chroma_format;
    const unsigned (*empty_block_mask)[3][2][2];
-   enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode;
-   unsigned macroblocks_per_batch;
 
    struct pipe_viewport_state viewport;
    struct pipe_framebuffer_state fb_state;
 
    struct vl_idct idct_y, idct_cr, idct_cb;
 
-   void *vertex_elems_state;
    void *rs_state;
 
    void *vs, *fs;
 
-   struct pipe_vertex_buffer quad;
-
    union
    {
       void *all[5];
@@ -81,8 +69,6 @@ struct vl_mpeg12_mc_buffer
 {
    struct vl_idct_buffer idct_y, idct_cb, idct_cr;
 
-   struct vl_vertex_buffer vertex_stream;
-
    union
    {
       struct pipe_sampler_view *all[5];
@@ -95,14 +81,6 @@ struct vl_mpeg12_mc_buffer
       struct { struct pipe_resource *y, *cb, *cr; } individual;
    } textures;
 
-   union
-   {
-      struct pipe_vertex_buffer all[2];
-      struct {
-         struct pipe_vertex_buffer quad, stream;
-      } individual;
-   } vertex_bufs;
-
    struct pipe_surface *surface, *past, *future;
    struct pipe_fence_handle **fence;
 };
@@ -111,8 +89,7 @@ bool vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer,
                                 struct pipe_context *pipe,
                                 unsigned picture_width,
                                 unsigned picture_height,
-                                enum pipe_video_chroma_format chroma_format,
-                                enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode);
+                                enum pipe_video_chroma_format chroma_format);
 
 void vl_mpeg12_mc_renderer_cleanup(struct vl_mpeg12_mc_renderer *renderer);
 
@@ -133,6 +110,8 @@ void vl_mpeg12_mc_renderer_render_macroblocks(struct vl_mpeg12_mc_renderer *rend
 
 void vl_mpeg12_mc_unmap_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_mc_buffer *buffer);
 
-void vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_mc_buffer *buffer);
+void vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_mc_buffer *buffer,
+                                 unsigned not_empty_start_instance, unsigned not_empty_num_instances,
+                                 unsigned empty_start_instance, unsigned empty_num_instances);
 
 #endif /* vl_mpeg12_mc_renderer_h */
index 2d602b96d3fdc956ea69b75ce50ce51e7684198c..41e9809f7447745cff5c80bb28321f31ca8559d9 100644 (file)
@@ -333,10 +333,17 @@ vl_vb_unmap(struct vl_vertex_buffer *buffer, struct pipe_context *pipe)
 }
 
 void
-vl_vb_restart(struct vl_vertex_buffer *buffer)
+vl_vb_restart(struct vl_vertex_buffer *buffer,
+              unsigned *not_empty_start_instance, unsigned *not_empty_num_instances,
+              unsigned *empty_start_instance, unsigned *empty_num_instances)
 {
    assert(buffer);
 
+   *not_empty_start_instance = 0;
+   *not_empty_num_instances = buffer->num_not_empty;
+   *empty_start_instance = buffer->size - buffer->num_empty;
+   *empty_num_instances = buffer->num_empty;
+
    buffer->num_not_empty = 0;
    buffer->num_empty = 0;
 }
index 4400bda6274061f0983ac9ed662b4ac71c85dcae..0f7f47f2703acd7a3e562f63151fa0964e06c181 100644 (file)
@@ -75,7 +75,9 @@ void vl_vb_add_block(struct vl_vertex_buffer *buffer, struct pipe_mpeg12_macrobl
 
 void vl_vb_unmap(struct vl_vertex_buffer *buffer, struct pipe_context *pipe);
 
-void vl_vb_restart(struct vl_vertex_buffer *buffer);
+void vl_vb_restart(struct vl_vertex_buffer *buffer,
+                   unsigned *not_empty_start_instance, unsigned *not_empty_num_instances,
+                   unsigned *empty_start_instance, unsigned *empty_num_instances);
 
 void vl_vb_cleanup(struct vl_vertex_buffer *buffer);
 
index b3885db0f552e51837a0b15afb10dd46457eefa0..8a569cd0c65aee0310fa981d78dd143875bb3c91 100644 (file)
@@ -15,7 +15,6 @@ r600_video_create(struct pipe_screen *screen, enum pipe_video_profile profile,
       return NULL;
 
    return sp_video_create_ex(pipe, profile, chroma_format, width, height,
-                             VL_MPEG12_MC_RENDERER_BUFFER_PICTURE,
                              true,
                              PIPE_FORMAT_VUYX);
 }
index daebbc54ad8dddb7e9a88d4e5eff38cda47b2867..e733399b59ad509eeaae1093b8c28ff4b2796ac6 100644 (file)
 #include "sp_public.h"
 #include "sp_texture.h"
 
+#define MACROBLOCK_WIDTH 16
+#define MACROBLOCK_HEIGHT 16
+
 #define NUM_BUFFERS 2
 
 static void
 flush_buffer(struct sp_mpeg12_context *ctx)
 {
+   unsigned ne_start, ne_num, e_start, e_num;
    assert(ctx);
 
-   if(ctx->mc_buffer != NULL) {
+   if(ctx->cur_buffer != NULL) {
+
+      vl_vb_unmap(&ctx->cur_buffer->vertex_stream, ctx->pipe);
+      vl_mpeg12_mc_unmap_buffer(&ctx->mc_renderer, &ctx->cur_buffer->mc);
+      vl_vb_restart(&ctx->cur_buffer->vertex_stream, &ne_start, &ne_num, &e_start, &e_num);
 
-      vl_mpeg12_mc_unmap_buffer(&ctx->mc_renderer, ctx->mc_buffer);
-      vl_mpeg12_mc_renderer_flush(&ctx->mc_renderer, ctx->mc_buffer);
+      ctx->pipe->set_vertex_buffers(ctx->pipe, 2, ctx->cur_buffer->vertex_bufs.all);
+      ctx->pipe->bind_vertex_elements_state(ctx->pipe, ctx->vertex_elems_state);
+      vl_mpeg12_mc_renderer_flush(&ctx->mc_renderer, &ctx->cur_buffer->mc, ne_start, ne_num, e_start, e_num);
 
-      ctx->mc_buffer = NULL;
+      ctx->cur_buffer = NULL;
    }
 }
 
@@ -58,21 +67,28 @@ static void
 rotate_buffer(struct sp_mpeg12_context *ctx)
 {
    static unsigned key = 0;
-   struct vl_mpeg12_mc_buffer *buffer;
+   struct sp_mpeg12_buffer *buffer;
 
    assert(ctx);
 
    flush_buffer(ctx);
 
-   buffer = (struct vl_mpeg12_mc_buffer*)util_keymap_lookup(ctx->buffer_map, &key);
+   buffer = (struct sp_mpeg12_buffer*)util_keymap_lookup(ctx->buffer_map, &key);
    if (!buffer) {
       boolean added_to_map;
 
-      buffer = CALLOC_STRUCT(vl_mpeg12_mc_buffer);
+      buffer = CALLOC_STRUCT(sp_mpeg12_buffer);
       if (buffer == NULL)
          return;
 
-      if(!vl_mpeg12_mc_init_buffer(&ctx->mc_renderer, buffer)) {
+      buffer->vertex_bufs.individual.quad.stride = ctx->quads.stride;
+      buffer->vertex_bufs.individual.quad.buffer_offset = ctx->quads.buffer_offset;
+      pipe_resource_reference(&buffer->vertex_bufs.individual.quad.buffer, ctx->quads.buffer);
+
+      buffer->vertex_bufs.individual.stream = vl_vb_init(&buffer->vertex_stream, ctx->pipe,
+                                                         ctx->vertex_buffer_size);
+
+      if(!vl_mpeg12_mc_init_buffer(&ctx->mc_renderer, &buffer->mc)) {
          FREE(buffer);
          return;
       }
@@ -82,9 +98,10 @@ rotate_buffer(struct sp_mpeg12_context *ctx)
    }
    ++key;
    key %= NUM_BUFFERS;
-   ctx->mc_buffer = buffer;
+   ctx->cur_buffer = buffer;
 
-   vl_mpeg12_mc_map_buffer(&ctx->mc_renderer, ctx->mc_buffer);
+   vl_vb_map(&ctx->cur_buffer->vertex_stream, ctx->pipe);
+   vl_mpeg12_mc_map_buffer(&ctx->mc_renderer, &ctx->cur_buffer->mc);
 }
 
 static void
@@ -93,14 +110,15 @@ delete_buffer(const struct keymap *map,
               void *user)
 {
    struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)user;
-   struct vl_mpeg12_mc_buffer *buf = (struct vl_mpeg12_mc_buffer*)data;
+   struct sp_mpeg12_buffer *buf = (struct sp_mpeg12_buffer*)data;
 
    assert(map);
    assert(key);
    assert(data);
    assert(user);
 
-   vl_mpeg12_mc_cleanup_buffer(&ctx->mc_renderer, buf);
+   vl_vb_cleanup(&buf->vertex_stream);
+   vl_mpeg12_mc_cleanup_buffer(&ctx->mc_renderer, &buf->mc);
 }
 
 static void
@@ -124,6 +142,8 @@ sp_mpeg12_destroy(struct pipe_video_context *vpipe)
    vl_compositor_cleanup(&ctx->compositor);
    util_delete_keymap(ctx->buffer_map, ctx);
    vl_mpeg12_mc_renderer_cleanup(&ctx->mc_renderer);
+   ctx->pipe->delete_vertex_elements_state(ctx->pipe, ctx->vertex_elems_state);
+   pipe_resource_reference(&ctx->quads.buffer, NULL);
    ctx->pipe->destroy(ctx->pipe);
 
    FREE(ctx);
@@ -194,16 +214,20 @@ sp_mpeg12_decode_macroblocks(struct pipe_video_context *vpipe,
 {
    struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
    struct pipe_mpeg12_macroblock *mpeg12_macroblocks = (struct pipe_mpeg12_macroblock*)macroblocks;
+   unsigned i;
 
    assert(vpipe);
    assert(num_macroblocks);
    assert(macroblocks);
    assert(macroblocks->codec == PIPE_VIDEO_CODEC_MPEG12);
    assert(ctx->decode_target);
-   assert(ctx->mc_buffer);
+   assert(ctx->cur_buffer);
+
+   for ( i = 0; i < num_macroblocks; ++i )
+      vl_vb_add_block(&ctx->cur_buffer->vertex_stream, &mpeg12_macroblocks[i], ctx->mc_renderer.empty_block_mask);
 
    vl_mpeg12_mc_renderer_render_macroblocks(&ctx->mc_renderer,
-                                            ctx->mc_buffer,
+                                            &ctx->cur_buffer->mc,
                                             ctx->decode_target,
                                             past, future, num_macroblocks,
                                             mpeg12_macroblocks, fence);
@@ -411,7 +435,7 @@ sp_mpeg12_set_decode_target(struct pipe_video_context *vpipe,
    assert(vpipe);
    assert(dt);
 
-   if (ctx->decode_target != dt || ctx->mc_buffer == NULL) {
+   if (ctx->decode_target != dt || ctx->cur_buffer == NULL) {
       rotate_buffer(ctx);
 
       pipe_surface_reference(&ctx->decode_target, dt);
@@ -466,7 +490,7 @@ init_pipe_state(struct sp_mpeg12_context *ctx)
    rast.offset_units = 1;
    rast.offset_scale = 1;
    rast.gl_rasterization_rules = 1;
-   
+
    ctx->rast = ctx->pipe->create_rasterizer_state(ctx->pipe, &rast);
    ctx->pipe->bind_rasterizer_state(ctx->pipe, ctx->rast);
 
@@ -514,7 +538,6 @@ static struct pipe_video_context *
 sp_mpeg12_create(struct pipe_context *pipe, enum pipe_video_profile profile,
                  enum pipe_video_chroma_format chroma_format,
                  unsigned width, unsigned height,
-                 enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode,
                  bool pot_buffers,
                  enum pipe_format decode_format)
 {
@@ -531,8 +554,8 @@ sp_mpeg12_create(struct pipe_context *pipe, enum pipe_video_profile profile,
    /* TODO: Non-pot buffers untested, probably doesn't work without changes to texcoord generation, vert shader, etc */
    assert(pot_buffers);
 
-   buffer_width = pot_buffers ? util_next_power_of_two(width) : width; 
-   buffer_height = pot_buffers ? util_next_power_of_two(height) : height; 
+   buffer_width = pot_buffers ? util_next_power_of_two(width) : width;
+   buffer_height = pot_buffers ? util_next_power_of_two(height) : height;
 
    ctx->base.profile = profile;
    ctx->base.chroma_format = chroma_format;
@@ -564,9 +587,18 @@ sp_mpeg12_create(struct pipe_context *pipe, enum pipe_video_profile profile,
    ctx->pipe = pipe;
    ctx->decode_format = decode_format;
 
+   ctx->quads = vl_vb_upload_quads(ctx->pipe, 2, 2);
+   ctx->vertex_buffer_size = width / MACROBLOCK_WIDTH * height / MACROBLOCK_HEIGHT;
+   ctx->vertex_elems_state = vl_vb_get_elems_state(ctx->pipe, true);
+
+   if (ctx->vertex_elems_state == NULL) {
+      ctx->pipe->destroy(ctx->pipe);
+      FREE(ctx);
+      return NULL;
+   }
+
    if (!vl_mpeg12_mc_renderer_init(&ctx->mc_renderer, ctx->pipe,
-                                   buffer_width, buffer_height, chroma_format,
-                                   bufmode)) {
+                                   buffer_width, buffer_height, chroma_format)) {
       ctx->pipe->destroy(ctx->pipe);
       FREE(ctx);
       return NULL;
@@ -618,7 +650,6 @@ sp_video_create(struct pipe_screen *screen, enum pipe_video_profile profile,
    return sp_video_create_ex(pipe, profile,
                              chroma_format,
                              width, height,
-                             VL_MPEG12_MC_RENDERER_BUFFER_PICTURE,
                              true,
                              PIPE_FORMAT_XYUV);
 }
@@ -627,7 +658,6 @@ struct pipe_video_context *
 sp_video_create_ex(struct pipe_context *pipe, enum pipe_video_profile profile,
                    enum pipe_video_chroma_format chroma_format,
                    unsigned width, unsigned height,
-                   enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode,
                    bool pot_buffers,
                    enum pipe_format decode_format)
 {
@@ -639,7 +669,6 @@ sp_video_create_ex(struct pipe_context *pipe, enum pipe_video_profile profile,
          return sp_mpeg12_create(pipe, profile,
                                  chroma_format,
                                  width, height,
-                                 bufmode,
                                  pot_buffers,
                                  decode_format);
       default:
index 9b60bad6b8f6fadf345468a3b4543c6715087d84..7e04a6d3bc2405d716e95a7960b02f77896f63e3 100644 (file)
 struct pipe_screen;
 struct pipe_context;
 
+struct sp_mpeg12_buffer
+{
+   struct vl_vertex_buffer vertex_stream;
+
+   union
+   {
+      struct pipe_vertex_buffer all[2];
+      struct {
+         struct pipe_vertex_buffer quad, stream;
+      } individual;
+   } vertex_bufs;
+
+   struct vl_mpeg12_mc_buffer mc;
+};
+
 struct sp_mpeg12_context
 {
    struct pipe_video_context base;
    struct pipe_context *pipe;
    struct pipe_surface *decode_target;
+
+   struct pipe_vertex_buffer quads;
+   unsigned vertex_buffer_size;
+   void *vertex_elems_state;
+
    struct vl_mpeg12_mc_renderer mc_renderer;
+
    struct keymap *buffer_map;
-   struct vl_mpeg12_mc_buffer *mc_buffer;
+   struct sp_mpeg12_buffer *cur_buffer;
    struct vl_compositor compositor;
 
    void *rast;
@@ -63,7 +84,6 @@ struct pipe_video_context *
 sp_video_create_ex(struct pipe_context *pipe, enum pipe_video_profile profile,
                    enum pipe_video_chroma_format chroma_format,
                    unsigned width, unsigned height,
-                   enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode,
                    bool pot_buffers,
                    enum pipe_format decode_format);