From 9d2e630cd02362bfa8f090640a55cf2dea9d64b3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christian=20K=C3=B6nig?= Date: Thu, 7 Apr 2011 19:24:22 +0200 Subject: [PATCH] [g3dvl] move mapping/unmapping and uploading of blocks out of idct code --- src/gallium/auxiliary/vl/vl_idct.c | 54 -------------- src/gallium/auxiliary/vl/vl_idct.h | 12 --- src/gallium/auxiliary/vl/vl_mpeg12_decoder.c | 77 ++++++++++++++++++-- src/gallium/auxiliary/vl/vl_mpeg12_decoder.h | 3 + 4 files changed, 72 insertions(+), 74 deletions(-) diff --git a/src/gallium/auxiliary/vl/vl_idct.c b/src/gallium/auxiliary/vl/vl_idct.c index c92659bc5b0..a7b8a18dec3 100644 --- a/src/gallium/auxiliary/vl/vl_idct.c +++ b/src/gallium/auxiliary/vl/vl_idct.c @@ -702,60 +702,6 @@ vl_idct_cleanup_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer) cleanup_intermediate(idct, buffer); } -void -vl_idct_map_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer) -{ - struct pipe_resource *tex; - - assert(idct && buffer); - - tex = buffer->sampler_views.individual.source->texture; - - struct pipe_box rect = - { - 0, 0, 0, - tex->width0, - tex->height0, - 1 - }; - - buffer->tex_transfer = idct->pipe->get_transfer - ( - idct->pipe, tex, - 0, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD, - &rect - ); - - buffer->texels = idct->pipe->transfer_map(idct->pipe, buffer->tex_transfer); -} - -void -vl_idct_add_block(struct vl_idct_buffer *buffer, unsigned x, unsigned y, short *block) -{ - unsigned tex_pitch; - short *texels; - - unsigned i; - - assert(buffer); - assert(block); - - tex_pitch = buffer->tex_transfer->stride / sizeof(short); - texels = buffer->texels + y * tex_pitch * BLOCK_HEIGHT + x * BLOCK_WIDTH; - - for (i = 0; i < BLOCK_HEIGHT; ++i) - memcpy(texels + i * tex_pitch, block + i * BLOCK_WIDTH, BLOCK_WIDTH * sizeof(short)); -} - -void -vl_idct_unmap_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer) -{ - assert(idct && buffer); - - idct->pipe->transfer_unmap(idct->pipe, buffer->tex_transfer); - idct->pipe->transfer_destroy(idct->pipe, buffer->tex_transfer); -} - void vl_idct_flush(struct vl_idct *idct, struct vl_idct_buffer *buffer, unsigned num_instances) { diff --git a/src/gallium/auxiliary/vl/vl_idct.h b/src/gallium/auxiliary/vl/vl_idct.h index fedebd3ff21..cd62cde449b 100644 --- a/src/gallium/auxiliary/vl/vl_idct.h +++ b/src/gallium/auxiliary/vl/vl_idct.h @@ -66,9 +66,6 @@ struct vl_idct_buffer struct pipe_sampler_view *transpose, *intermediate; } individual; } sampler_views; - - struct pipe_transfer *tex_transfer; - short *texels; }; /* upload the idct matrix, which can be shared by all idct instances of a pipe */ @@ -90,15 +87,6 @@ bool vl_idct_init_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer, /* cleanup a buffer of an idct instance */ void vl_idct_cleanup_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer); -/* map a buffer for use with vl_idct_add_block */ -void vl_idct_map_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer); - -/* add an block of to be tranformed data a the given x and y coordinate */ -void vl_idct_add_block(struct vl_idct_buffer *buffer, unsigned x, unsigned y, short *block); - -/* unmaps the buffers before flushing */ -void vl_idct_unmap_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer); - /* flush the buffer and start rendering, vertex buffers needs to be setup before calling this */ void vl_idct_flush(struct vl_idct *idct, struct vl_idct_buffer *buffer, unsigned num_verts); diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c index c07b1bb369e..24f385681c2 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c +++ b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c @@ -50,6 +50,58 @@ static const unsigned const_empty_block_mask_420[3][2][2] = { { { 0x01, 0x01 }, { 0x01, 0x01 } } }; +static void +map_buffers(struct vl_mpeg12_decoder *ctx, struct vl_mpeg12_buffer *buffer) +{ + struct pipe_sampler_view **sampler_views; + struct pipe_resource *tex; + unsigned i; + + assert(ctx && buffer); + + sampler_views = buffer->idct_source->get_sampler_views(buffer->idct_source); + assert(sampler_views); + + for (i = 0; i < VL_MAX_PLANES; ++i) { + tex = sampler_views[i]->texture; + + struct pipe_box rect = + { + 0, 0, 0, + tex->width0, + tex->height0, + 1 + }; + + buffer->tex_transfer[i] = ctx->pipe->get_transfer + ( + ctx->pipe, tex, + 0, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD, + &rect + ); + + buffer->texels[i] = ctx->pipe->transfer_map(ctx->pipe, buffer->tex_transfer[i]); + } +} + +static void +upload_block(struct vl_mpeg12_buffer *buffer, unsigned plane, unsigned x, unsigned y, short *block) +{ + unsigned tex_pitch; + short *texels; + + unsigned i; + + assert(buffer); + assert(block); + + tex_pitch = buffer->tex_transfer[plane]->stride / sizeof(short); + texels = buffer->texels[plane] + y * tex_pitch * BLOCK_HEIGHT + x * BLOCK_WIDTH; + + for (i = 0; i < BLOCK_HEIGHT; ++i) + memcpy(texels + i * tex_pitch, block + i * BLOCK_WIDTH, BLOCK_WIDTH * sizeof(short)); +} + static void upload_buffer(struct vl_mpeg12_decoder *ctx, struct vl_mpeg12_buffer *buffer, @@ -67,7 +119,7 @@ upload_buffer(struct vl_mpeg12_decoder *ctx, for (y = 0; y < 2; ++y) { for (x = 0; x < 2; ++x, ++tb) { if (mb->cbp & (*ctx->empty_block_mask)[0][y][x]) { - vl_idct_add_block(&buffer->idct[0], mb->mbx * 2 + x, mb->mby * 2 + y, blocks); + upload_block(buffer, 0, mb->mbx * 2 + x, mb->mby * 2 + y, blocks); blocks += BLOCK_WIDTH * BLOCK_HEIGHT; } } @@ -78,12 +130,25 @@ upload_buffer(struct vl_mpeg12_decoder *ctx, for (tb = 1; tb < 3; ++tb) { if (mb->cbp & (*ctx->empty_block_mask)[tb][0][0]) { - vl_idct_add_block(&buffer->idct[tb], mb->mbx, mb->mby, blocks); + upload_block(buffer, tb, mb->mbx, mb->mby, blocks); blocks += BLOCK_WIDTH * BLOCK_HEIGHT; } } } +static void +unmap_buffers(struct vl_mpeg12_decoder *ctx, struct vl_mpeg12_buffer *buffer) +{ + unsigned i; + + assert(ctx && buffer); + + for (i = 0; i < VL_MAX_PLANES; ++i) { + ctx->pipe->transfer_unmap(ctx->pipe, buffer->tex_transfer[i]); + ctx->pipe->transfer_destroy(ctx->pipe, buffer->tex_transfer[i]); + } +} + static void vl_mpeg12_buffer_destroy(struct pipe_video_decode_buffer *buffer) { @@ -115,9 +180,7 @@ vl_mpeg12_buffer_map(struct pipe_video_decode_buffer *buffer) assert(dec); vl_vb_map(&buf->vertex_stream, dec->pipe); - vl_idct_map_buffers(&dec->idct_y, &buf->idct[0]); - vl_idct_map_buffers(&dec->idct_c, &buf->idct[1]); - vl_idct_map_buffers(&dec->idct_c, &buf->idct[2]); + map_buffers(dec, buf); } static void @@ -156,9 +219,7 @@ vl_mpeg12_buffer_unmap(struct pipe_video_decode_buffer *buffer) assert(dec); vl_vb_unmap(&buf->vertex_stream, dec->pipe); - vl_idct_unmap_buffers(&dec->idct_y, &buf->idct[0]); - vl_idct_unmap_buffers(&dec->idct_c, &buf->idct[1]); - vl_idct_unmap_buffers(&dec->idct_c, &buf->idct[2]); + unmap_buffers(dec, buf); } static void diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.h b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.h index f7dc2d5799a..69d649b179a 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.h +++ b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.h @@ -76,6 +76,9 @@ struct vl_mpeg12_buffer struct vl_idct_buffer idct[VL_MAX_PLANES]; struct vl_mpeg12_mc_buffer mc[VL_MAX_PLANES]; + + struct pipe_transfer *tex_transfer[VL_MAX_PLANES]; + short *texels[VL_MAX_PLANES]; }; /* drivers can call this function in their pipe_video_context constructors and pass it -- 2.30.2