From: Christian König Date: Wed, 8 Dec 2010 19:48:34 +0000 (+0100) Subject: [g3dvl] remove shadow buffering of vertex buffers X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1482b9a7f39ec8875fcd4137c35b3cb9ac0c0934;p=mesa.git [g3dvl] remove shadow buffering of vertex buffers --- diff --git a/src/gallium/auxiliary/vl/vl_idct.c b/src/gallium/auxiliary/vl/vl_idct.c index 168e6e88b2b..0a81134a789 100644 --- a/src/gallium/auxiliary/vl/vl_idct.c +++ b/src/gallium/auxiliary/vl/vl_idct.c @@ -464,14 +464,13 @@ init_vertex_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer) 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.pos = vl_vb_create_buffer(idct->pipe, idct->max_blocks, idct->vertex_buffer_stride); + buffer->vertex_bufs.individual.pos = vl_vb_init( + &buffer->blocks, idct->pipe, idct->max_blocks, 2, + idct->vertex_buffer_stride); if(buffer->vertex_bufs.individual.pos.buffer == NULL) return false; - if (!vl_vb_init(&buffer->blocks, idct->max_blocks, 2)) - return false; - return true; } @@ -668,6 +667,8 @@ vl_idct_map_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer) ); buffer->texels = idct->pipe->transfer_map(idct->pipe, buffer->tex_transfer); + + vl_vb_map(&buffer->blocks, idct->pipe); } void @@ -699,28 +700,17 @@ vl_idct_unmap_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer) idct->pipe->transfer_unmap(idct->pipe, buffer->tex_transfer); idct->pipe->transfer_destroy(idct->pipe, buffer->tex_transfer); + vl_vb_unmap(&buffer->blocks, idct->pipe); } void vl_idct_flush(struct vl_idct *idct, struct vl_idct_buffer *buffer) { - struct pipe_transfer *vec_transfer; - void *vectors; unsigned num_verts; assert(idct); - vectors = pipe_buffer_map - ( - idct->pipe, - buffer->vertex_bufs.individual.pos.buffer, - PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD, - &vec_transfer - ); - - num_verts = vl_vb_upload(&buffer->blocks, vectors); - - pipe_buffer_unmap(idct->pipe, buffer->vertex_bufs.individual.pos.buffer, vec_transfer); + num_verts = vl_vb_restart(&buffer->blocks); if(num_verts > 0) { diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c index ed2de7930e7..66e4fc0a07a 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c +++ b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c @@ -95,16 +95,6 @@ enum VS_OUTPUT VS_O_MV3 }; -static const unsigned const_mbtype_config[VL_NUM_MACROBLOCK_TYPES][2] = { - [VL_MACROBLOCK_TYPE_INTRA] = { 0, 0 }, - [VL_MACROBLOCK_TYPE_FWD_FRAME_PRED] = { 1, 1 }, - [VL_MACROBLOCK_TYPE_FWD_FIELD_PRED] = { 1, 2 }, - [VL_MACROBLOCK_TYPE_BKWD_FRAME_PRED] = { 1, 1 }, - [VL_MACROBLOCK_TYPE_BKWD_FIELD_PRED] = { 1, 2 }, - [VL_MACROBLOCK_TYPE_BI_FRAME_PRED] = { 2, 1 }, - [VL_MACROBLOCK_TYPE_BI_FIELD_PRED] = { 2, 2 } -}; - static void * create_vert_shader(struct vl_mpeg12_mc_renderer *r) { @@ -662,15 +652,19 @@ init_buffers(struct vl_mpeg12_mc_renderer *r) stride = vl_vb_element_helper(&vertex_elems[VS_I_VPOS], 9, 1); - r->vertex_bufs.individual.pos = vl_vb_create_buffer( - r->pipe, r->macroblocks_per_batch, stride); + r->vertex_bufs.individual.pos = vl_vb_init( + &r->pos, r->pipe, r->macroblocks_per_batch, + sizeof(struct vertex_stream_0) / sizeof(float), + stride); for (i = 0; i < 4; ++i) { /* motion vector 0..4 element */ vertex_elems[VS_I_MV0 + i].src_format = PIPE_FORMAT_R32G32_FLOAT; stride = vl_vb_element_helper(&vertex_elems[VS_I_MV0 + i], 1, i + 2); - r->vertex_bufs.individual.mv[i] = vl_vb_create_buffer( - r->pipe, r->macroblocks_per_batch, stride); + r->vertex_bufs.individual.mv[i] = vl_vb_init( + &r->mv[i], r->pipe, r->macroblocks_per_batch, + sizeof(struct vertex2f) / sizeof(float), + stride); } r->vertex_elems_state = r->pipe->create_vertex_elements_state( @@ -685,14 +679,6 @@ init_buffers(struct vl_mpeg12_mc_renderer *r) if (r->vs == NULL || r->fs == NULL) return false; - if (!vl_vb_init(&r->pos, r->macroblocks_per_batch, sizeof(struct vertex_stream_0) / sizeof(float))) - return false; - - for (i = 0; i < 4; ++i) { - if (!vl_vb_init(&r->mv[i], r->macroblocks_per_batch, sizeof(struct vertex2f) / sizeof(float))) - return false; - } - return true; } @@ -731,44 +717,6 @@ cleanup_buffers(struct vl_mpeg12_mc_renderer *r) r->pipe->delete_vertex_elements_state(r->pipe, r->vertex_elems_state); } -static void -upload_vertex_stream(struct vl_mpeg12_mc_renderer *r) -{ - struct vertex_stream_0 *pos; - struct vertex2f *mv[4]; - - struct pipe_transfer *buf_transfer[5]; - - unsigned i, j; - - assert(r); - - pos = (struct vertex_stream_0 *)pipe_buffer_map - ( - r->pipe, - r->vertex_bufs.individual.pos.buffer, - PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD, - &buf_transfer[0] - ); - - for (i = 0; i < 4; ++i) - mv[i] = (struct vertex2f *)pipe_buffer_map - ( - r->pipe, - r->vertex_bufs.individual.mv[i].buffer, - PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD, - &buf_transfer[i + 1] - ); - - vl_vb_upload(&r->pos, pos); - for (j = 0; j < 4; ++j) - vl_vb_upload(&r->mv[j], mv[j]); - - pipe_buffer_unmap(r->pipe, r->vertex_bufs.individual.pos.buffer, buf_transfer[0]); - for (i = 0; i < 4; ++i) - pipe_buffer_unmap(r->pipe, r->vertex_bufs.individual.mv[i].buffer, buf_transfer[i + 1]); -} - static struct pipe_sampler_view *find_or_create_sampler_view(struct vl_mpeg12_mc_renderer *r, struct pipe_surface *surface) { @@ -1100,6 +1048,8 @@ vl_mpeg12_mc_renderer_render_macroblocks(struct vl_mpeg12_mc_renderer void vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer) { + unsigned i; + assert(renderer); assert(renderer->num_macroblocks <= renderer->macroblocks_per_batch); @@ -1114,7 +1064,12 @@ vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer) vl_idct_flush(&renderer->idct_chroma, &renderer->idct_cr); vl_idct_flush(&renderer->idct_chroma, &renderer->idct_cb); - upload_vertex_stream(renderer); + vl_vb_unmap(&renderer->pos, renderer->pipe); + vl_vb_restart(&renderer->pos); + for(i = 0; i < 4; ++i) { + vl_vb_unmap(&renderer->mv[i], renderer->pipe); + vl_vb_restart(&renderer->mv[i]); + } renderer->fb_state.cbufs[0] = renderer->surface; renderer->pipe->bind_rasterizer_state(renderer->pipe, renderer->rs_state); @@ -1145,5 +1100,9 @@ vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer) vl_idct_map_buffers(&renderer->idct_chroma, &renderer->idct_cr); vl_idct_map_buffers(&renderer->idct_chroma, &renderer->idct_cb); + vl_vb_map(&renderer->pos, renderer->pipe); + for(i = 0; i < 4; ++i) + vl_vb_map(&renderer->mv[i], renderer->pipe); + renderer->num_macroblocks = 0; } diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h index e0349886fa2..e12ac50ae0d 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h +++ b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h @@ -46,19 +46,6 @@ enum VL_MPEG12_MC_RENDERER_BUFFER_MODE VL_MPEG12_MC_RENDERER_BUFFER_PICTURE /* Larger batches, more memory */ }; -enum VL_MACROBLOCK_TYPE -{ - VL_MACROBLOCK_TYPE_INTRA, - VL_MACROBLOCK_TYPE_FWD_FRAME_PRED, - VL_MACROBLOCK_TYPE_FWD_FIELD_PRED, - VL_MACROBLOCK_TYPE_BKWD_FRAME_PRED, - VL_MACROBLOCK_TYPE_BKWD_FIELD_PRED, - VL_MACROBLOCK_TYPE_BI_FRAME_PRED, - VL_MACROBLOCK_TYPE_BI_FIELD_PRED, - - VL_NUM_MACROBLOCK_TYPES -}; - struct vl_mpeg12_mc_renderer { struct pipe_context *pipe; diff --git a/src/gallium/auxiliary/vl/vl_vertex_buffers.c b/src/gallium/auxiliary/vl/vl_vertex_buffers.c index 4647685053b..4182bad784b 100644 --- a/src/gallium/auxiliary/vl/vl_vertex_buffers.c +++ b/src/gallium/auxiliary/vl/vl_vertex_buffers.c @@ -96,24 +96,6 @@ vl_vb_get_quad_vertex_element() return element; } -struct pipe_vertex_buffer -vl_vb_create_buffer(struct pipe_context *pipe, unsigned max_blocks, unsigned stride) -{ - struct pipe_vertex_buffer buf; - - buf.stride = stride; - buf.max_index = 4 * max_blocks - 1; - buf.buffer_offset = 0; - buf.buffer = pipe_buffer_create - ( - pipe->screen, - PIPE_BIND_VERTEX_BUFFER, - stride * 4 * max_blocks - ); - - return buf; -} - unsigned vl_vb_element_helper(struct pipe_vertex_element* elements, unsigned num_elements, unsigned vertex_buffer_index) @@ -132,30 +114,63 @@ vl_vb_element_helper(struct pipe_vertex_element* elements, unsigned num_elements return offset; } -bool -vl_vb_init(struct vl_vertex_buffer *buffer, unsigned max_blocks, unsigned num_elements) +struct pipe_vertex_buffer +vl_vb_init(struct vl_vertex_buffer *buffer, struct pipe_context *pipe, + unsigned max_blocks, unsigned num_elements, unsigned stride) { + struct pipe_vertex_buffer buf; + assert(buffer); buffer->num_verts = 0; buffer->num_elements = num_elements; - buffer->buffer = MALLOC(max_blocks * num_elements * sizeof(float) * 4); - return buffer->buffer != NULL; + + buf.stride = stride; + buf.max_index = 4 * max_blocks - 1; + buf.buffer_offset = 0; + buf.buffer = pipe_buffer_create + ( + pipe->screen, + PIPE_BIND_VERTEX_BUFFER, + stride * 4 * max_blocks + ); + + pipe_resource_reference(&buffer->resource, buf.buffer); + + vl_vb_map(buffer, pipe); + + return buf; } -unsigned -vl_vb_upload(struct vl_vertex_buffer *buffer, void *dst) +void +vl_vb_map(struct vl_vertex_buffer *buffer, struct pipe_context *pipe) { - unsigned todo; + assert(buffer && pipe); - assert(buffer); + buffer->vectors = pipe_buffer_map + ( + pipe, + buffer->resource, + PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD, + &buffer->transfer + ); +} - todo = buffer->num_verts; - buffer->num_verts = 0; +void +vl_vb_unmap(struct vl_vertex_buffer *buffer, struct pipe_context *pipe) +{ + assert(buffer && pipe); - if(todo) - memcpy(dst, buffer->buffer, sizeof(float) * buffer->num_elements * todo); + pipe_buffer_unmap(pipe, buffer->resource, buffer->transfer); +} + +unsigned +vl_vb_restart(struct vl_vertex_buffer *buffer) +{ + assert(buffer); + unsigned todo = buffer->num_verts; + buffer->num_verts = 0; return todo; } @@ -164,5 +179,5 @@ vl_vb_cleanup(struct vl_vertex_buffer *buffer) { assert(buffer); - FREE(buffer->buffer); + pipe_resource_reference(&buffer->resource, NULL); } diff --git a/src/gallium/auxiliary/vl/vl_vertex_buffers.h b/src/gallium/auxiliary/vl/vl_vertex_buffers.h index dae80fa767b..e312515dc30 100644 --- a/src/gallium/auxiliary/vl/vl_vertex_buffers.h +++ b/src/gallium/auxiliary/vl/vl_vertex_buffers.h @@ -35,19 +35,24 @@ struct vl_vertex_buffer { unsigned num_verts; unsigned num_elements; - float *buffer; + struct pipe_resource *resource; + struct pipe_transfer *transfer; + float *vectors; }; struct pipe_vertex_buffer vl_vb_upload_quads(struct pipe_context *pipe, unsigned max_blocks); struct pipe_vertex_element vl_vb_get_quad_vertex_element(); -struct pipe_vertex_buffer vl_vb_create_buffer(struct pipe_context *pipe, unsigned max_blocks, unsigned stride); - unsigned vl_vb_element_helper(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); +struct pipe_vertex_buffer vl_vb_init(struct vl_vertex_buffer *buffer, + struct pipe_context *pipe, + unsigned max_blocks, unsigned num_elements, + unsigned stride); + +void vl_vb_map(struct vl_vertex_buffer *buffer, struct pipe_context *pipe); static inline void vl_vb_add_block(struct vl_vertex_buffer *buffer, float *elements) @@ -58,13 +63,15 @@ vl_vb_add_block(struct vl_vertex_buffer *buffer, float *elements) assert(buffer); for(i = 0; i < 4; ++i) { - pos = buffer->buffer + buffer->num_verts * buffer->num_elements; + pos = buffer->vectors + buffer->num_verts * buffer->num_elements; memcpy(pos, elements, sizeof(float) * buffer->num_elements); buffer->num_verts++; } } -unsigned vl_vb_upload(struct vl_vertex_buffer *buffer, void *dst); +void vl_vb_unmap(struct vl_vertex_buffer *buffer, struct pipe_context *pipe); + +unsigned vl_vb_restart(struct vl_vertex_buffer *buffer); void vl_vb_cleanup(struct vl_vertex_buffer *buffer);