[g3dvl] no need to keep the idct matrix multiple times
authorChristian König <deathsimple@vodafone.de>
Thu, 25 Nov 2010 21:10:21 +0000 (22:10 +0100)
committerChristian König <deathsimple@vodafone.de>
Thu, 25 Nov 2010 21:10:21 +0000 (22:10 +0100)
src/gallium/auxiliary/vl/vl_idct.c
src/gallium/auxiliary/vl/vl_idct.h
src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c

index c1550cb365a6535321277e02cc2d8a03d1ffe9d3..5ee4e674d96cca4cdd946814c0f600a954030f93 100644 (file)
@@ -384,9 +384,6 @@ init_buffers(struct vl_idct *idct)
    template.bind = PIPE_BIND_SAMPLER_VIEW;
    template.flags = 0;
 
-   idct->textures.individual.transpose = idct->pipe->screen->resource_create(idct->pipe->screen, &template);
-   idct->textures.individual.matrix = idct->pipe->screen->resource_create(idct->pipe->screen, &template);
-
    template.format = idct->destination->format;
    template.width0 = idct->destination->width0;
    template.height0 = idct->destination->height0;
@@ -483,17 +480,8 @@ init_constants(struct vl_idct *idct)
    struct pipe_transfer *buf_transfer;
    struct vertex_shader_consts *vs_consts;
    struct vertex2f *v;
-   float *f;
-
-   struct pipe_box rect =
-   {
-      0, 0, 0,
-      BLOCK_WIDTH,
-      BLOCK_HEIGHT,
-      1
-   };
 
-   unsigned i, j, pitch;
+   unsigned i;
 
    /* quad vectors */
    v = pipe_buffer_map
@@ -507,42 +495,6 @@ init_constants(struct vl_idct *idct)
      memcpy(v + i * 4, &const_quad, sizeof(const_quad));
    pipe_buffer_unmap(idct->pipe, idct->vertex_bufs.individual.quad.buffer, buf_transfer);
 
-   /* transposed matrix */
-   buf_transfer = idct->pipe->get_transfer
-   (
-      idct->pipe, idct->textures.individual.transpose,
-      u_subresource(0, 0),
-      PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
-      &rect
-   );
-   pitch = buf_transfer->stride / util_format_get_blocksize(buf_transfer->resource->format);
-
-   f = idct->pipe->transfer_map(idct->pipe, buf_transfer);
-   for(i = 0; i < BLOCK_HEIGHT; ++i)
-      for(j = 0; j < BLOCK_WIDTH; ++j)
-         f[i * pitch * 4 + j] = const_matrix[j][i]; // transpose
-
-   idct->pipe->transfer_unmap(idct->pipe, buf_transfer);
-   idct->pipe->transfer_destroy(idct->pipe, buf_transfer);
-
-   /* matrix */
-   buf_transfer = idct->pipe->get_transfer
-   (
-      idct->pipe, idct->textures.individual.matrix,
-      u_subresource(0, 0),
-      PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
-      &rect
-   );
-   pitch = buf_transfer->stride / util_format_get_blocksize(buf_transfer->resource->format);
-
-   f = idct->pipe->transfer_map(idct->pipe, buf_transfer);
-   for(i = 0; i < BLOCK_HEIGHT; ++i)
-      for(j = 0; j < BLOCK_WIDTH; ++j)
-         f[i * pitch * 4 + j] = const_matrix[j][i]; // transpose
-
-   idct->pipe->transfer_unmap(idct->pipe, buf_transfer);
-   idct->pipe->transfer_destroy(idct->pipe, buf_transfer);
-
    /* normalisation constants */
    vs_consts = pipe_buffer_map
    (
@@ -610,12 +562,64 @@ cleanup_state(struct vl_idct *idct)
       idct->pipe->delete_sampler_state(idct->pipe, idct->samplers.all[i]);
 }
 
+struct pipe_resource *
+vl_idct_upload_matrix(struct pipe_context *pipe)
+{
+   struct pipe_resource template, *matrix;
+   struct pipe_transfer *buf_transfer;
+   unsigned i, j, pitch;
+   float *f;
+
+   struct pipe_box rect =
+   {
+      0, 0, 0,
+      BLOCK_WIDTH,
+      BLOCK_HEIGHT,
+      1
+   };
+
+   memset(&template, 0, sizeof(struct pipe_resource));
+   template.target = PIPE_TEXTURE_2D;
+   template.format = PIPE_FORMAT_R32G32B32A32_FLOAT;
+   template.last_level = 0;
+   template.width0 = 2;
+   template.height0 = 8;
+   template.depth0 = 1;
+   template.usage = PIPE_USAGE_IMMUTABLE;
+   template.bind = PIPE_BIND_SAMPLER_VIEW;
+   template.flags = 0;
+
+   matrix = pipe->screen->resource_create(pipe->screen, &template);
+
+   /* matrix */
+   buf_transfer = pipe->get_transfer
+   (
+      pipe, matrix,
+      u_subresource(0, 0),
+      PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
+      &rect
+   );
+   pitch = buf_transfer->stride / util_format_get_blocksize(buf_transfer->resource->format);
+
+   f = pipe->transfer_map(pipe, buf_transfer);
+   for(i = 0; i < BLOCK_HEIGHT; ++i)
+      for(j = 0; j < BLOCK_WIDTH; ++j)
+         f[i * pitch * 4 + j] = const_matrix[j][i]; // transpose
+
+   pipe->transfer_unmap(pipe, buf_transfer);
+   pipe->transfer_destroy(pipe, buf_transfer);
+
+   return matrix;
+}
+
 bool
-vl_idct_init(struct vl_idct *idct, struct pipe_context *pipe, struct pipe_resource *dst)
+vl_idct_init(struct vl_idct *idct, struct pipe_context *pipe, struct pipe_resource *dst, struct pipe_resource *matrix)
 {
    assert(idct && pipe && dst);
 
    idct->pipe = pipe;
+   pipe_resource_reference(&idct->textures.individual.matrix, matrix);
+   pipe_resource_reference(&idct->textures.individual.transpose, matrix);
    pipe_resource_reference(&idct->destination, dst);
 
    init_state(idct);
index 01df3f9103fd229bec81019708d500077bbe734d..ed64a308f3bf6a977c0ea31b5ba18d6df443cbbc 100644 (file)
@@ -97,7 +97,9 @@ struct vl_idct
    } surfaces;
 };
 
-bool vl_idct_init(struct vl_idct *idct, struct pipe_context *pipe, struct pipe_resource *dst);
+struct pipe_resource *vl_idct_upload_matrix(struct pipe_context *pipe);
+
+bool vl_idct_init(struct vl_idct *idct, struct pipe_context *pipe, struct pipe_resource *dst, struct pipe_resource *matrix);
 
 void vl_idct_cleanup(struct vl_idct *idct);
 
index 8099929b8b0525cf8af29489f1efff76172160d0..b756f2db6115817443c81e62caabfda954a1b370 100644 (file)
@@ -1295,8 +1295,11 @@ vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer,
                            enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode,
                            bool pot_buffers)
 {
+   struct pipe_resource *idct_matrix;
+
    assert(renderer);
    assert(pipe);
+
    /* TODO: Implement other policies */
    assert(bufmode == VL_MPEG12_MC_RENDERER_BUFFER_PICTURE);
    /* TODO: Non-pot buffers untested, probably doesn't work without changes to texcoord generation, vert shader, etc */
@@ -1332,13 +1335,16 @@ vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer,
    renderer->future = NULL;
    renderer->num_macroblocks = 0;
 
-   if(!vl_idct_init(&renderer->idct_y, pipe, renderer->textures.individual.y))
+   if(!(idct_matrix = vl_idct_upload_matrix(pipe)))
+      goto error_idct_matrix;
+
+   if(!vl_idct_init(&renderer->idct_y, pipe, renderer->textures.individual.y, idct_matrix))
       goto error_idct_y;
 
-   if(!vl_idct_init(&renderer->idct_cr, pipe, renderer->textures.individual.cr))
+   if(!vl_idct_init(&renderer->idct_cr, pipe, renderer->textures.individual.cr, idct_matrix))
       goto error_idct_cr;
 
-   if(!vl_idct_init(&renderer->idct_cb, pipe, renderer->textures.individual.cb))
+   if(!vl_idct_init(&renderer->idct_cb, pipe, renderer->textures.individual.cb, idct_matrix))
       goto error_idct_cb;
 
    return true;
@@ -1350,6 +1356,7 @@ error_idct_cr:
    vl_idct_cleanup(&renderer->idct_y);
 
 error_idct_y:
+error_idct_matrix:
    cleanup_buffers(renderer);
 
 error_buffers: