diff options
author | Christian König <[email protected]> | 2011-03-08 21:30:33 +0100 |
---|---|---|
committer | Christian König <[email protected]> | 2011-03-08 21:30:33 +0100 |
commit | 37a548c9d1db6bbf8712277f678d850f34d0e445 (patch) | |
tree | dd5792d09c70d8639226c549709a8819a9bae7ba /src/gallium/auxiliary | |
parent | 310eea52ca1e997295c84163066cc5d0fd4f8cf6 (diff) |
[g3dvl] start to cleanup the mess
Move the vertex buffer out of the mc code
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r-- | src/gallium/auxiliary/vl/vl_idct.c | 41 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_idct.h | 10 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c | 99 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h | 29 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_vertex_buffers.c | 9 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_vertex_buffers.h | 4 |
6 files changed, 37 insertions, 155 deletions
diff --git a/src/gallium/auxiliary/vl/vl_idct.c b/src/gallium/auxiliary/vl/vl_idct.c index b418aea9514..f191a898edd 100644 --- a/src/gallium/auxiliary/vl/vl_idct.c +++ b/src/gallium/auxiliary/vl/vl_idct.c @@ -394,11 +394,6 @@ init_state(struct vl_idct *idct) assert(idct); - idct->quad = vl_vb_upload_quads(idct->pipe, idct->blocks_x, idct->blocks_y); - - if(idct->quad.buffer == NULL) - return false; - for (i = 0; i < 4; ++i) { memset(&sampler, 0, sizeof(sampler)); sampler.wrap_s = PIPE_TEX_WRAP_REPEAT; @@ -427,8 +422,6 @@ init_state(struct vl_idct *idct) rs_state.gl_rasterization_rules = false; idct->rs_state = idct->pipe->create_rasterizer_state(idct->pipe, &rs_state); - idct->vertex_elems_state = vl_vb_get_elems_state(idct->pipe, false); - return true; } @@ -441,7 +434,6 @@ cleanup_state(struct vl_idct *idct) idct->pipe->delete_sampler_state(idct->pipe, idct->samplers.all[i]); idct->pipe->delete_rasterizer_state(idct->pipe, idct->rs_state); - idct->pipe->delete_vertex_elements_state(idct->pipe, idct->vertex_elems_state); } static bool @@ -500,31 +492,6 @@ cleanup_textures(struct vl_idct *idct, struct vl_idct_buffer *buffer) } } -static bool -init_vertex_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer, struct pipe_vertex_buffer stream) -{ - assert(idct && buffer); - - buffer->vertex_bufs.individual.quad.stride = idct->quad.stride; - 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.stream.stride = stream.stride; - buffer->vertex_bufs.individual.stream.buffer_offset = stream.buffer_offset; - pipe_resource_reference(&buffer->vertex_bufs.individual.stream.buffer, stream.buffer); - - return true; -} - -static void -cleanup_vertex_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer) -{ - assert(idct && buffer); - - pipe_resource_reference(&buffer->vertex_bufs.individual.quad.buffer, NULL); - pipe_resource_reference(&buffer->vertex_bufs.individual.stream.buffer, NULL); -} - struct pipe_resource * vl_idct_upload_matrix(struct pipe_context *pipe) { @@ -612,7 +579,7 @@ vl_idct_cleanup(struct vl_idct *idct) bool vl_idct_init_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer, - struct pipe_resource *dst, struct pipe_vertex_buffer stream) + struct pipe_resource *dst) { struct pipe_surface template; @@ -629,9 +596,6 @@ vl_idct_init_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer, if (!init_textures(idct, buffer)) return false; - if (!init_vertex_buffers(idct, buffer, stream)) - return false; - /* init state */ buffer->viewport[0].scale[0] = buffer->textures.individual.intermediate->width0; buffer->viewport[0].scale[1] = buffer->textures.individual.intermediate->height0; @@ -693,7 +657,6 @@ vl_idct_cleanup_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer) idct->pipe->surface_destroy(idct->pipe, buffer->fb_state[1].cbufs[0]); cleanup_textures(idct, buffer); - cleanup_vertex_buffers(idct, buffer); } void @@ -758,8 +721,6 @@ vl_idct_flush(struct vl_idct *idct, struct vl_idct_buffer *buffer, unsigned num_ num_verts = idct->blocks_x * idct->blocks_y * 4; idct->pipe->bind_rasterizer_state(idct->pipe, idct->rs_state); - idct->pipe->set_vertex_buffers(idct->pipe, 2, buffer->vertex_bufs.all); - idct->pipe->bind_vertex_elements_state(idct->pipe, idct->vertex_elems_state); /* first stage */ idct->pipe->set_framebuffer_state(idct->pipe, &buffer->fb_state[0]); diff --git a/src/gallium/auxiliary/vl/vl_idct.h b/src/gallium/auxiliary/vl/vl_idct.h index 78e4a46369d..0ff12cf466d 100644 --- a/src/gallium/auxiliary/vl/vl_idct.h +++ b/src/gallium/auxiliary/vl/vl_idct.h @@ -40,7 +40,6 @@ struct vl_idct unsigned blocks_x, blocks_y; void *rs_state; - void *vertex_elems_state; union { @@ -56,7 +55,6 @@ struct vl_idct void *matrix_fs, *transpose_fs; struct pipe_resource *matrix; - struct pipe_vertex_buffer quad; }; struct vl_idct_buffer @@ -86,12 +84,6 @@ struct vl_idct_buffer } individual; } textures; - union - { - struct pipe_vertex_buffer all[2]; - struct { struct pipe_vertex_buffer quad, stream; } individual; - } vertex_bufs; - struct pipe_transfer *tex_transfer; short *texels; }; @@ -106,7 +98,7 @@ bool vl_idct_init(struct vl_idct *idct, struct pipe_context *pipe, void vl_idct_cleanup(struct vl_idct *idct); bool vl_idct_init_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer, - struct pipe_resource *dst, struct pipe_vertex_buffer stream); + struct pipe_resource *dst); void vl_idct_cleanup_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer); diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c index d1b2144aea5..160388ad049 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c +++ b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c @@ -485,19 +485,10 @@ static bool init_buffers(struct vl_mpeg12_mc_renderer *r) { struct pipe_resource *idct_matrix; - - const unsigned mbw = - align(r->buffer_width, MACROBLOCK_WIDTH) / MACROBLOCK_WIDTH; - const unsigned mbh = - align(r->buffer_height, MACROBLOCK_HEIGHT) / MACROBLOCK_HEIGHT; - unsigned chroma_width, chroma_height, chroma_blocks_x, chroma_blocks_y; assert(r); - r->macroblocks_per_batch = - mbw * (r->bufmode == VL_MPEG12_MC_RENDERER_BUFFER_PICTURE ? mbh : 1); - if (!(idct_matrix = vl_idct_upload_matrix(r->pipe))) return false; @@ -530,12 +521,6 @@ init_buffers(struct vl_mpeg12_mc_renderer *r) chroma_blocks_x, chroma_blocks_y, TGSI_SWIZZLE_Z, idct_matrix)) return false; - r->quad = vl_vb_upload_quads(r->pipe, 1, 1); - r->vertex_elems_state = vl_vb_get_elems_state(r->pipe, true); - - if (r->vertex_elems_state == NULL) - return false; - r->vs = create_vert_shader(r); r->fs = create_frag_shader(r); @@ -556,8 +541,6 @@ cleanup_buffers(struct vl_mpeg12_mc_renderer *r) vl_idct_cleanup(&r->idct_y); vl_idct_cleanup(&r->idct_cr); vl_idct_cleanup(&r->idct_cb); - - r->pipe->delete_vertex_elements_state(r->pipe, r->vertex_elems_state); } static struct pipe_sampler_view @@ -623,19 +606,6 @@ grab_blocks(struct vl_mpeg12_mc_renderer *r, } static void -grab_macroblock(struct vl_mpeg12_mc_renderer *r, - struct vl_mpeg12_mc_buffer *buffer, - struct pipe_mpeg12_macroblock *mb) -{ - assert(r); - assert(mb); - assert(mb->blocks); - - vl_vb_add_block(&buffer->vertex_stream, mb, r->empty_block_mask); - grab_blocks(r, buffer, mb->mbx, mb->mby, mb->cbp, mb->blocks); -} - -static void texview_map_delete(const struct keymap *map, const void *key, void *data, void *user) @@ -655,22 +625,17 @@ vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer, struct pipe_context *pipe, unsigned buffer_width, unsigned buffer_height, - enum pipe_video_chroma_format chroma_format, - enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode) + enum pipe_video_chroma_format chroma_format) { assert(renderer); assert(pipe); - /* TODO: Implement other policies */ - assert(bufmode == VL_MPEG12_MC_RENDERER_BUFFER_PICTURE); - memset(renderer, 0, sizeof(struct vl_mpeg12_mc_renderer)); renderer->pipe = pipe; renderer->buffer_width = buffer_width; renderer->buffer_height = buffer_height; renderer->chroma_format = chroma_format; - renderer->bufmode = bufmode; /* TODO: Implement 422, 444 */ assert(chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420); @@ -721,13 +686,6 @@ vl_mpeg12_mc_init_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg1 buffer->past = NULL; buffer->future = NULL; - buffer->vertex_bufs.individual.quad.stride = renderer->quad.stride; - buffer->vertex_bufs.individual.quad.buffer_offset = renderer->quad.buffer_offset; - pipe_resource_reference(&buffer->vertex_bufs.individual.quad.buffer, renderer->quad.buffer); - - buffer->vertex_bufs.individual.stream = vl_vb_init(&buffer->vertex_stream, renderer->pipe, - renderer->macroblocks_per_batch); - memset(&template, 0, sizeof(struct pipe_resource)); template.target = PIPE_TEXTURE_2D; /* TODO: Accomodate HW that can't do this and also for cases when this isn't precise enough */ @@ -743,9 +701,7 @@ vl_mpeg12_mc_init_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg1 buffer->textures.individual.y = renderer->pipe->screen->resource_create(renderer->pipe->screen, &template); - if (!vl_idct_init_buffer(&renderer->idct_y, &buffer->idct_y, - buffer->textures.individual.y, - buffer->vertex_bufs.individual.stream)) + if (!vl_idct_init_buffer(&renderer->idct_y, &buffer->idct_y, buffer->textures.individual.y)) return false; if (renderer->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420) { @@ -760,14 +716,10 @@ vl_mpeg12_mc_init_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg1 buffer->textures.individual.cr = renderer->pipe->screen->resource_create(renderer->pipe->screen, &template); - if (!vl_idct_init_buffer(&renderer->idct_cb, &buffer->idct_cb, - buffer->textures.individual.cb, - buffer->vertex_bufs.individual.stream)) + if (!vl_idct_init_buffer(&renderer->idct_cb, &buffer->idct_cb, buffer->textures.individual.cb)) return false; - if (!vl_idct_init_buffer(&renderer->idct_cr, &buffer->idct_cr, - buffer->textures.individual.cr, - buffer->vertex_bufs.individual.stream)) + if (!vl_idct_init_buffer(&renderer->idct_cr, &buffer->idct_cr, buffer->textures.individual.cr)) return false; for (i = 0; i < 3; ++i) { @@ -794,13 +746,9 @@ vl_mpeg12_mc_cleanup_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mp for (i = 0; i < 3; ++i) { pipe_sampler_view_reference(&buffer->sampler_views.all[i], NULL); - pipe_resource_reference(&buffer->vertex_bufs.all[i].buffer, NULL); pipe_resource_reference(&buffer->textures.all[i], NULL); } - pipe_resource_reference(&buffer->vertex_bufs.individual.quad.buffer, NULL); - vl_vb_cleanup(&buffer->vertex_stream); - vl_idct_cleanup_buffer(&renderer->idct_y, &buffer->idct_y); vl_idct_cleanup_buffer(&renderer->idct_cb, &buffer->idct_cb); vl_idct_cleanup_buffer(&renderer->idct_cr, &buffer->idct_cr); @@ -818,8 +766,6 @@ vl_mpeg12_mc_map_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12 vl_idct_map_buffers(&renderer->idct_y, &buffer->idct_y); vl_idct_map_buffers(&renderer->idct_cr, &buffer->idct_cr); vl_idct_map_buffers(&renderer->idct_cb, &buffer->idct_cb); - - vl_vb_map(&buffer->vertex_stream, renderer->pipe); } void @@ -851,8 +797,10 @@ vl_mpeg12_mc_renderer_render_macroblocks(struct vl_mpeg12_mc_renderer *renderer, } for (i = 0; i < num_macroblocks; ++i) { - assert(mpeg12_macroblocks[i].base.codec == PIPE_VIDEO_CODEC_MPEG12); - grab_macroblock(renderer, buffer, &mpeg12_macroblocks[i]); + struct pipe_mpeg12_macroblock *mb = &mpeg12_macroblocks[i]; + + assert(mb->base.codec == PIPE_VIDEO_CODEC_MPEG12); + grab_blocks(renderer, buffer, mb->mbx, mb->mby, mb->cbp, mb->blocks); } } @@ -864,32 +812,26 @@ vl_mpeg12_mc_unmap_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg vl_idct_unmap_buffers(&renderer->idct_y, &buffer->idct_y); vl_idct_unmap_buffers(&renderer->idct_cr, &buffer->idct_cr); vl_idct_unmap_buffers(&renderer->idct_cb, &buffer->idct_cb); - - vl_vb_unmap(&buffer->vertex_stream, renderer->pipe); } void -vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_mc_buffer *buffer) +vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_mc_buffer *buffer, + unsigned not_empty_start_instance, unsigned not_empty_num_instances, + unsigned empty_start_instance, unsigned empty_num_instances) { - unsigned num_not_empty, num_empty; assert(renderer && buffer); - num_not_empty = buffer->vertex_stream.num_not_empty; - num_empty = buffer->vertex_stream.num_empty; - - if (num_not_empty == 0 && num_empty == 0) + if (not_empty_num_instances == 0 && empty_num_instances == 0) return; - vl_idct_flush(&renderer->idct_y, &buffer->idct_y, num_not_empty); - vl_idct_flush(&renderer->idct_cr, &buffer->idct_cr, num_not_empty); - vl_idct_flush(&renderer->idct_cb, &buffer->idct_cb, num_not_empty); + vl_idct_flush(&renderer->idct_y, &buffer->idct_y, not_empty_num_instances); + vl_idct_flush(&renderer->idct_cr, &buffer->idct_cr, not_empty_num_instances); + vl_idct_flush(&renderer->idct_cb, &buffer->idct_cb, not_empty_num_instances); renderer->fb_state.cbufs[0] = buffer->surface; renderer->pipe->bind_rasterizer_state(renderer->pipe, renderer->rs_state); renderer->pipe->set_framebuffer_state(renderer->pipe, &renderer->fb_state); renderer->pipe->set_viewport_state(renderer->pipe, &renderer->viewport); - renderer->pipe->set_vertex_buffers(renderer->pipe, 2, buffer->vertex_bufs.all); - renderer->pipe->bind_vertex_elements_state(renderer->pipe, renderer->vertex_elems_state); if (buffer->past) { buffer->sampler_views.individual.ref[0] = find_or_create_sampler_view(renderer, buffer->past); @@ -909,12 +851,13 @@ vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mp renderer->pipe->bind_vs_state(renderer->pipe, renderer->vs); renderer->pipe->bind_fs_state(renderer->pipe, renderer->fs); - if (num_not_empty > 0) - util_draw_arrays_instanced(renderer->pipe, PIPE_PRIM_QUADS, 0, 4, 0, num_not_empty); + if (not_empty_num_instances > 0) + util_draw_arrays_instanced(renderer->pipe, PIPE_PRIM_QUADS, 0, 4, + not_empty_start_instance, not_empty_num_instances); - if (num_empty > 0) + if (empty_num_instances > 0) util_draw_arrays_instanced(renderer->pipe, PIPE_PRIM_QUADS, 0, 4, - buffer->vertex_stream.size - num_empty, num_empty); + empty_start_instance, empty_num_instances); renderer->pipe->flush(renderer->pipe, PIPE_FLUSH_RENDER_CACHE, buffer->fence); @@ -922,6 +865,4 @@ vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mp pipe_surface_reference(&buffer->surface, NULL); pipe_surface_reference(&buffer->past, NULL); pipe_surface_reference(&buffer->future, NULL); - - vl_vb_restart(&buffer->vertex_stream); } diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h index c319064c70f..86a6518e3c2 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h +++ b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h @@ -39,13 +39,6 @@ struct pipe_context; struct pipe_macroblock; struct keymap; -/* A slice is video-width (rounded up to a multiple of macroblock width) x macroblock height */ -enum VL_MPEG12_MC_RENDERER_BUFFER_MODE -{ - VL_MPEG12_MC_RENDERER_BUFFER_SLICE, /* Saves memory at the cost of smaller batches */ - VL_MPEG12_MC_RENDERER_BUFFER_PICTURE /* Larger batches, more memory */ -}; - struct vl_mpeg12_mc_renderer { struct pipe_context *pipe; @@ -53,21 +46,16 @@ struct vl_mpeg12_mc_renderer unsigned buffer_height; enum pipe_video_chroma_format chroma_format; const unsigned (*empty_block_mask)[3][2][2]; - enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode; - unsigned macroblocks_per_batch; struct pipe_viewport_state viewport; struct pipe_framebuffer_state fb_state; struct vl_idct idct_y, idct_cr, idct_cb; - void *vertex_elems_state; void *rs_state; void *vs, *fs; - struct pipe_vertex_buffer quad; - union { void *all[5]; @@ -81,8 +69,6 @@ struct vl_mpeg12_mc_buffer { struct vl_idct_buffer idct_y, idct_cb, idct_cr; - struct vl_vertex_buffer vertex_stream; - union { struct pipe_sampler_view *all[5]; @@ -95,14 +81,6 @@ struct vl_mpeg12_mc_buffer struct { struct pipe_resource *y, *cb, *cr; } individual; } textures; - union - { - struct pipe_vertex_buffer all[2]; - struct { - struct pipe_vertex_buffer quad, stream; - } individual; - } vertex_bufs; - struct pipe_surface *surface, *past, *future; struct pipe_fence_handle **fence; }; @@ -111,8 +89,7 @@ bool vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer, struct pipe_context *pipe, unsigned picture_width, unsigned picture_height, - enum pipe_video_chroma_format chroma_format, - enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode); + enum pipe_video_chroma_format chroma_format); void vl_mpeg12_mc_renderer_cleanup(struct vl_mpeg12_mc_renderer *renderer); @@ -133,6 +110,8 @@ void vl_mpeg12_mc_renderer_render_macroblocks(struct vl_mpeg12_mc_renderer *rend void vl_mpeg12_mc_unmap_buffer(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_mc_buffer *buffer); -void vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_mc_buffer *buffer); +void vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer, struct vl_mpeg12_mc_buffer *buffer, + unsigned not_empty_start_instance, unsigned not_empty_num_instances, + unsigned empty_start_instance, unsigned empty_num_instances); #endif /* vl_mpeg12_mc_renderer_h */ diff --git a/src/gallium/auxiliary/vl/vl_vertex_buffers.c b/src/gallium/auxiliary/vl/vl_vertex_buffers.c index 2d602b96d3f..41e9809f744 100644 --- a/src/gallium/auxiliary/vl/vl_vertex_buffers.c +++ b/src/gallium/auxiliary/vl/vl_vertex_buffers.c @@ -333,10 +333,17 @@ vl_vb_unmap(struct vl_vertex_buffer *buffer, struct pipe_context *pipe) } void -vl_vb_restart(struct vl_vertex_buffer *buffer) +vl_vb_restart(struct vl_vertex_buffer *buffer, + unsigned *not_empty_start_instance, unsigned *not_empty_num_instances, + unsigned *empty_start_instance, unsigned *empty_num_instances) { assert(buffer); + *not_empty_start_instance = 0; + *not_empty_num_instances = buffer->num_not_empty; + *empty_start_instance = buffer->size - buffer->num_empty; + *empty_num_instances = buffer->num_empty; + buffer->num_not_empty = 0; buffer->num_empty = 0; } diff --git a/src/gallium/auxiliary/vl/vl_vertex_buffers.h b/src/gallium/auxiliary/vl/vl_vertex_buffers.h index 4400bda6274..0f7f47f2703 100644 --- a/src/gallium/auxiliary/vl/vl_vertex_buffers.h +++ b/src/gallium/auxiliary/vl/vl_vertex_buffers.h @@ -75,7 +75,9 @@ void vl_vb_add_block(struct vl_vertex_buffer *buffer, struct pipe_mpeg12_macrobl void vl_vb_unmap(struct vl_vertex_buffer *buffer, struct pipe_context *pipe); -void vl_vb_restart(struct vl_vertex_buffer *buffer); +void vl_vb_restart(struct vl_vertex_buffer *buffer, + unsigned *not_empty_start_instance, unsigned *not_empty_num_instances, + unsigned *empty_start_instance, unsigned *empty_num_instances); void vl_vb_cleanup(struct vl_vertex_buffer *buffer); |