vl: Don't wrap blocks in pipe_user_buffers.
authorYounes Manton <younes.m@gmail.com>
Fri, 12 Mar 2010 18:36:52 +0000 (13:36 -0500)
committerYounes Manton <younes.m@gmail.com>
Fri, 12 Mar 2010 18:36:52 +0000 (13:36 -0500)
Mallocing/free eat up a noticeable amount of CPU time for no
practical benefit.

src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c
src/gallium/include/pipe/p_video_state.h
src/gallium/state_trackers/xorg/xvmc/surface.c

index 2e611fca96bfae9d54071c9ed8a9e7e4419e305c..769ee38c46b57bbd5931361ed1993c3f1054721c 100644 (file)
@@ -1235,19 +1235,15 @@ static void
 grab_macroblock(struct vl_mpeg12_mc_renderer *r,
                 struct pipe_mpeg12_macroblock *mb)
 {
-   void *blocks;
-
    assert(r);
    assert(mb);
+   assert(mb->blocks);
    assert(r->num_macroblocks < r->macroblocks_per_batch);
 
    memcpy(&r->macroblock_buf[r->num_macroblocks], mb,
           sizeof(struct pipe_mpeg12_macroblock));
 
-   blocks = pipe_buffer_map(r->pipe->screen, mb->blocks,
-                            PIPE_BUFFER_USAGE_CPU_READ);
-   grab_blocks(r, mb->mbx, mb->mby, mb->dct_type, mb->cbp, blocks);
-   pipe_buffer_unmap(r->pipe->screen, mb->blocks);
+   grab_blocks(r, mb->mbx, mb->mby, mb->dct_type, mb->cbp, mb->blocks);
 
    ++r->num_macroblocks;
 }
@@ -1318,6 +1314,10 @@ vl_mpeg12_mc_renderer_cleanup(struct vl_mpeg12_mc_renderer *renderer)
    cleanup_pipe_state(renderer);
    cleanup_shaders(renderer);
    cleanup_buffers(renderer);
+
+   pipe_surface_reference(&renderer->surface, NULL);
+   pipe_surface_reference(&renderer->past, NULL);
+   pipe_surface_reference(&renderer->future, NULL);
 }
 
 void
@@ -1356,9 +1356,9 @@ vl_mpeg12_mc_renderer_render_macroblocks(struct vl_mpeg12_mc_renderer
       new_surface = true;
 
    if (new_surface) {
-      renderer->surface = surface;
-      renderer->past = past;
-      renderer->future = future;
+      pipe_surface_reference(&renderer->surface, surface);
+      pipe_surface_reference(&renderer->past, past);
+      pipe_surface_reference(&renderer->future, future);
       renderer->fence = fence;
       renderer->surface_tex_inv_size.x = 1.0f / surface->width;
       renderer->surface_tex_inv_size.y = 1.0f / surface->height;
@@ -1381,7 +1381,9 @@ vl_mpeg12_mc_renderer_render_macroblocks(struct vl_mpeg12_mc_renderer
          flush(renderer);
          xfer_buffers_map(renderer);
          /* Next time we get this surface it may have new ref frames */
-         renderer->surface = NULL;
+         pipe_surface_reference(&renderer->surface, NULL);
+         pipe_surface_reference(&renderer->past, NULL);
+         pipe_surface_reference(&renderer->future, NULL);
       }
    }
 }
index 79ce174701b0be47c74442cd48f1e7a587805ead..5eb963521391f385afe60ec5f419573422880d52 100644 (file)
@@ -90,7 +90,7 @@ struct pipe_mpeg12_macroblock
    enum pipe_mpeg12_dct_type dct_type;
    signed pmv[2][2][2];
    unsigned cbp;
-   struct pipe_buffer *blocks;
+   short *blocks;
 };
 
 #if 0
index a2d71b5c14eb418fad5fe43a63b966cddbe38fcf..d2c4e5f19caca272d94c4595bb80c4506198ce96 100644 (file)
@@ -178,8 +178,7 @@ MacroBlocksToPipe(struct pipe_screen *screen,
                pipe_macroblocks->pmv[j][k][l] = xvmc_mb->PMV[j][k][l];
 
       pipe_macroblocks->cbp = xvmc_mb->coded_block_pattern;
-      pipe_macroblocks->blocks = pipe_user_buffer_create(screen, xvmc_blocks->blocks + xvmc_mb->index * BLOCK_SIZE_SAMPLES,
-                                                         BLOCK_SIZE_BYTES);
+      pipe_macroblocks->blocks = xvmc_blocks->blocks + xvmc_mb->index * BLOCK_SIZE_SAMPLES;
 
       ++pipe_macroblocks;
       ++xvmc_mb;
@@ -320,9 +319,6 @@ Status XvMCRenderSurface(Display *dpy, XvMCContext *context, unsigned int pictur
    vpipe->decode_macroblocks(vpipe, p_vsfc, f_vsfc, num_macroblocks,
                              &pipe_macroblocks->base, target_surface_priv->render_fence);
 
-   for (i = 0; i < num_macroblocks; ++i)
-      vpipe->screen->buffer_destroy(pipe_macroblocks[i].blocks);
-
    XVMC_MSG(XVMC_TRACE, "[XvMC] Submitted surface %p for rendering.\n", target_surface);
 
    return Success;