diff options
author | Christian König <[email protected]> | 2010-12-07 20:13:37 +0100 |
---|---|---|
committer | Christian König <[email protected]> | 2010-12-07 20:13:37 +0100 |
commit | bfb4fb057d92869f98dc627d53d3e1b7d031d93f (patch) | |
tree | a400b1d8a74826fd77a9b7086fbc04bd65180d7d /src | |
parent | eb7452e267974f9ff971b752046c512963f59f81 (diff) |
[g3dvl] move vertex buffer handling into vl_vertex_buffer.c
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/auxiliary/vl/vl_idct.c | 27 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c | 84 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_vertex_buffers.c | 38 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_vertex_buffers.h | 7 |
4 files changed, 60 insertions, 96 deletions
diff --git a/src/gallium/auxiliary/vl/vl_idct.c b/src/gallium/auxiliary/vl/vl_idct.c index 6aae28d465c..7de778e1036 100644 --- a/src/gallium/auxiliary/vl/vl_idct.c +++ b/src/gallium/auxiliary/vl/vl_idct.c @@ -376,36 +376,19 @@ init_buffers(struct vl_idct *idct) idct->sampler_views.all[i] = idct->pipe->create_sampler_view(idct->pipe, idct->textures.all[i], &sampler_view); } - idct->vertex_bufs.individual.quad = vl_vb_upload_quads(idct->pipe, idct->max_blocks); + idct->vertex_bufs.individual.quad = vl_vb_upload_quads(idct->pipe, idct->max_blocks, &vertex_elems[VS_I_RECT]); if(idct->vertex_bufs.individual.quad.buffer == NULL) return false; - idct->vertex_bufs.individual.pos.stride = sizeof(struct vertex2f); - idct->vertex_bufs.individual.pos.max_index = 4 * idct->max_blocks - 1; - idct->vertex_bufs.individual.pos.buffer_offset = 0; - idct->vertex_bufs.individual.pos.buffer = pipe_buffer_create - ( - idct->pipe->screen, - PIPE_BIND_VERTEX_BUFFER, - sizeof(struct vertex2f) * 4 * idct->max_blocks - ); + /* Pos element */ + vertex_elems[VS_I_VPOS].src_format = PIPE_FORMAT_R32G32_FLOAT; + + idct->vertex_bufs.individual.pos = vl_vb_create_buffer(idct->pipe, idct->max_blocks, &vertex_elems[VS_I_VPOS], 1, 1); if(idct->vertex_bufs.individual.pos.buffer == NULL) return false; - /* Rect element */ - vertex_elems[0].src_offset = 0; - vertex_elems[0].instance_divisor = 0; - vertex_elems[0].vertex_buffer_index = 0; - vertex_elems[0].src_format = PIPE_FORMAT_R32G32_FLOAT; - - /* Pos element */ - vertex_elems[1].src_offset = 0; - vertex_elems[1].instance_divisor = 0; - vertex_elems[1].vertex_buffer_index = 1; - vertex_elems[1].src_format = PIPE_FORMAT_R32G32_FLOAT; - idct->vertex_elems_state = idct->pipe->create_vertex_elements_state(idct->pipe, 2, vertex_elems); return true; diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c index 9983b47692d..dba49e5f087 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c +++ b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c @@ -648,99 +648,39 @@ init_buffers(struct vl_mpeg12_mc_renderer *r) r->sampler_views.all[i] = r->pipe->create_sampler_view(r->pipe, r->textures.all[i], &sampler_view); } - r->vertex_bufs.individual.quad = vl_vb_upload_quads(r->pipe, r->macroblocks_per_batch); - - r->vertex_bufs.individual.pos.stride = sizeof(struct vertex_stream_0); - r->vertex_bufs.individual.pos.max_index = 4 * r->macroblocks_per_batch - 1; - r->vertex_bufs.individual.pos.buffer_offset = 0; - /* XXX: Create with usage DYNAMIC or STREAM */ - r->vertex_bufs.individual.pos.buffer = pipe_buffer_create - ( - r->pipe->screen, - PIPE_BIND_VERTEX_BUFFER, - sizeof(struct vertex_stream_0) * 4 * r->macroblocks_per_batch - ); - - for (i = 0; i < 4; ++i) { - r->vertex_bufs.individual.mv[i].stride = sizeof(struct vertex2f); - r->vertex_bufs.individual.mv[i].max_index = 4 * r->macroblocks_per_batch - 1; - r->vertex_bufs.individual.mv[i].buffer_offset = 0; - /* XXX: Create with usage DYNAMIC or STREAM */ - r->vertex_bufs.individual.mv[i].buffer = pipe_buffer_create - ( - r->pipe->screen, - PIPE_BIND_VERTEX_BUFFER, - sizeof(struct vertex2f) * 4 * r->macroblocks_per_batch - ); - } - memset(&vertex_elems, 0, sizeof(vertex_elems)); - /* Rectangle element */ - vertex_elems[VS_I_RECT].src_offset = 0; - vertex_elems[VS_I_RECT].instance_divisor = 0; - vertex_elems[VS_I_RECT].vertex_buffer_index = 0; - vertex_elems[VS_I_RECT].src_format = PIPE_FORMAT_R32G32_FLOAT; + r->vertex_bufs.individual.quad = vl_vb_upload_quads(r->pipe, r->macroblocks_per_batch, &vertex_elems[VS_I_RECT]); /* Position element */ - vertex_elems[VS_I_VPOS].src_offset = 0; - vertex_elems[VS_I_VPOS].instance_divisor = 0; - vertex_elems[VS_I_VPOS].vertex_buffer_index = 1; vertex_elems[VS_I_VPOS].src_format = PIPE_FORMAT_R32G32_FLOAT; /* y, cr, cb empty block element top left block */ - vertex_elems[VS_I_EB_0_0].src_offset = sizeof(float) * 2; - vertex_elems[VS_I_EB_0_0].instance_divisor = 0; - vertex_elems[VS_I_EB_0_0].vertex_buffer_index = 1; vertex_elems[VS_I_EB_0_0].src_format = PIPE_FORMAT_R32G32B32_FLOAT; /* y, cr, cb empty block element top right block */ - vertex_elems[VS_I_EB_0_1].src_offset = sizeof(float) * 5; - vertex_elems[VS_I_EB_0_1].instance_divisor = 0; - vertex_elems[VS_I_EB_0_1].vertex_buffer_index = 1; vertex_elems[VS_I_EB_0_1].src_format = PIPE_FORMAT_R32G32B32_FLOAT; /* y, cr, cb empty block element bottom left block */ - vertex_elems[VS_I_EB_1_0].src_offset = sizeof(float) * 8; - vertex_elems[VS_I_EB_1_0].instance_divisor = 0; - vertex_elems[VS_I_EB_1_0].vertex_buffer_index = 1; vertex_elems[VS_I_EB_1_0].src_format = PIPE_FORMAT_R32G32B32_FLOAT; /* y, cr, cb empty block element bottom right block */ - vertex_elems[VS_I_EB_1_1].src_offset = sizeof(float) * 11; - vertex_elems[VS_I_EB_1_1].instance_divisor = 0; - vertex_elems[VS_I_EB_1_1].vertex_buffer_index = 1; vertex_elems[VS_I_EB_1_1].src_format = PIPE_FORMAT_R32G32B32_FLOAT; /* progressive=0.0f interlaced=1.0f */ - vertex_elems[VS_I_INTERLACED].src_offset = sizeof(float) * 14; - vertex_elems[VS_I_INTERLACED].instance_divisor = 0; - vertex_elems[VS_I_INTERLACED].vertex_buffer_index = 1; vertex_elems[VS_I_INTERLACED].src_format = PIPE_FORMAT_R32_FLOAT; - /* First ref surface top field texcoord element */ - vertex_elems[VS_I_MV0].src_offset = 0; - vertex_elems[VS_I_MV0].instance_divisor = 0; - vertex_elems[VS_I_MV0].vertex_buffer_index = 2; - vertex_elems[VS_I_MV0].src_format = PIPE_FORMAT_R32G32_FLOAT; - - /* First ref surface bottom field texcoord element */ - vertex_elems[VS_I_MV1].src_offset = 0; - vertex_elems[VS_I_MV1].instance_divisor = 0; - vertex_elems[VS_I_MV1].vertex_buffer_index = 3; - vertex_elems[VS_I_MV1].src_format = PIPE_FORMAT_R32G32_FLOAT; - - /* Second ref surface top field texcoord element */ - vertex_elems[VS_I_MV2].src_offset = 0; - vertex_elems[VS_I_MV2].instance_divisor = 0; - vertex_elems[VS_I_MV2].vertex_buffer_index = 4; - vertex_elems[VS_I_MV2].src_format = PIPE_FORMAT_R32G32_FLOAT; - - /* Second ref surface bottom field texcoord element */ - vertex_elems[VS_I_MV3].src_offset = 0; - vertex_elems[VS_I_MV3].instance_divisor = 0; - vertex_elems[VS_I_MV3].vertex_buffer_index = 5; - vertex_elems[VS_I_MV3].src_format = PIPE_FORMAT_R32G32_FLOAT; + r->vertex_bufs.individual.pos = vl_vb_create_buffer( + r->pipe, r->macroblocks_per_batch, + &vertex_elems[VS_I_VPOS], 6, 1); + + for (i = 0; i < 4; ++i) { + /* motion vector 0..4 element */ + vertex_elems[VS_I_MV0 + i].src_format = PIPE_FORMAT_R32G32_FLOAT; + r->vertex_bufs.individual.mv[i] = vl_vb_create_buffer( + r->pipe, r->macroblocks_per_batch, + &vertex_elems[VS_I_MV0 + i], 1, i + 2); + } for(i = 0; i < VL_NUM_MACROBLOCK_TYPES; ++i) init_mbtype_handler(r, i, vertex_elems); diff --git a/src/gallium/auxiliary/vl/vl_vertex_buffers.c b/src/gallium/auxiliary/vl/vl_vertex_buffers.c index dba69f9a6a2..4e0d704a23d 100644 --- a/src/gallium/auxiliary/vl/vl_vertex_buffers.c +++ b/src/gallium/auxiliary/vl/vl_vertex_buffers.c @@ -30,6 +30,7 @@ #include <pipe/p_screen.h> #include <util/u_memory.h> #include <util/u_inlines.h> +#include <util/u_format.h> #include "vl_vertex_buffers.h" #include "vl_types.h" @@ -39,7 +40,7 @@ static const struct quadf const_quad = { }; struct pipe_vertex_buffer -vl_vb_upload_quads(struct pipe_context *pipe, unsigned max_blocks) +vl_vb_upload_quads(struct pipe_context *pipe, unsigned max_blocks, struct pipe_vertex_element* element) { struct pipe_vertex_buffer quad; struct pipe_transfer *buf_transfer; @@ -49,6 +50,13 @@ vl_vb_upload_quads(struct pipe_context *pipe, unsigned max_blocks) assert(pipe); assert(max_blocks); + assert(element); + + /* setup rectangle element */ + element->src_offset = 0; + element->instance_divisor = 0; + element->vertex_buffer_index = 0; + element->src_format = PIPE_FORMAT_R32G32_FLOAT; /* create buffer */ quad.stride = sizeof(struct vertex2f); @@ -81,6 +89,34 @@ vl_vb_upload_quads(struct pipe_context *pipe, unsigned max_blocks) return quad; } +struct pipe_vertex_buffer +vl_vb_create_buffer(struct pipe_context *pipe, unsigned max_blocks, + struct pipe_vertex_element *elements, unsigned num_elements, + unsigned vertex_buffer_index) +{ + struct pipe_vertex_buffer buf; + unsigned i, size = 0; + + for ( i = 0; i < num_elements; ++i ) { + elements[i].src_offset = size; + elements[i].instance_divisor = 0; + elements[i].vertex_buffer_index = vertex_buffer_index; + size += util_format_get_blocksize(elements[i].src_format); + } + + buf.stride = size; + buf.max_index = 4 * max_blocks - 1; + buf.buffer_offset = 0; + buf.buffer = pipe_buffer_create + ( + pipe->screen, + PIPE_BIND_VERTEX_BUFFER, + size * 4 * max_blocks + ); + + return buf; +} + bool vl_vb_init(struct vl_vertex_buffer *buffer, unsigned max_blocks, unsigned num_elements) { diff --git a/src/gallium/auxiliary/vl/vl_vertex_buffers.h b/src/gallium/auxiliary/vl/vl_vertex_buffers.h index 8d7c0e6a275..cf71f029a79 100644 --- a/src/gallium/auxiliary/vl/vl_vertex_buffers.h +++ b/src/gallium/auxiliary/vl/vl_vertex_buffers.h @@ -38,7 +38,12 @@ struct vl_vertex_buffer float *buffer; }; -struct pipe_vertex_buffer vl_vb_upload_quads(struct pipe_context *pipe, unsigned max_blocks); +struct pipe_vertex_buffer vl_vb_upload_quads(struct pipe_context *pipe, unsigned max_blocks, + struct pipe_vertex_element* element); + +struct pipe_vertex_buffer vl_vb_create_buffer(struct pipe_context *pipe, unsigned max_blocks, + 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); |