From 0b749d6dcb537472771d6fe6e454aafc916ab3fe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christian=20K=C3=B6nig?= Date: Wed, 8 Dec 2010 02:12:24 +0100 Subject: [PATCH] [g3dvl] split idct code into state and buffers --- src/gallium/auxiliary/vl/vl_idct.c | 390 ++++++++++-------- src/gallium/auxiliary/vl/vl_idct.h | 45 +- .../auxiliary/vl/vl_mpeg12_mc_renderer.c | 113 +++-- .../auxiliary/vl/vl_mpeg12_mc_renderer.h | 3 +- src/gallium/auxiliary/vl/vl_vertex_buffers.c | 57 ++- src/gallium/auxiliary/vl/vl_vertex_buffers.h | 12 +- 6 files changed, 343 insertions(+), 277 deletions(-) diff --git a/src/gallium/auxiliary/vl/vl_idct.c b/src/gallium/auxiliary/vl/vl_idct.c index f19cfc38d7b..168e6e88b2b 100644 --- a/src/gallium/auxiliary/vl/vl_idct.c +++ b/src/gallium/auxiliary/vl/vl_idct.c @@ -197,9 +197,6 @@ matrix_mul(struct ureg_program *shader, struct ureg_dst dst, struct ureg_dst l[2 static void * create_transpose_frag_shader(struct vl_idct *idct) { - struct pipe_resource *transpose = idct->textures.individual.transpose; - struct pipe_resource *intermediate = idct->textures.individual.intermediate; - struct ureg_program *shader; struct ureg_src block, tex, sampler[2]; @@ -221,8 +218,8 @@ create_transpose_frag_shader(struct vl_idct *idct) start[0] = ureg_imm1f(shader, 0.0f); start[1] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_START, TGSI_INTERPOLATE_CONSTANT); - fetch_four(shader, l, block, sampler[0], start[0], block, false, false, transpose->width0); - fetch_four(shader, r, tex, sampler[1], start[1], block, true, false, intermediate->height0); + fetch_four(shader, l, block, sampler[0], start[0], block, false, false, BLOCK_WIDTH / 4); + fetch_four(shader, r, tex, sampler[1], start[1], block, true, false, idct->buffer_height / 4); fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0); @@ -244,9 +241,6 @@ create_transpose_frag_shader(struct vl_idct *idct) static void * create_matrix_frag_shader(struct vl_idct *idct) { - struct pipe_resource *matrix = idct->textures.individual.matrix; - struct pipe_resource *source = idct->textures.individual.source; - struct ureg_program *shader; struct ureg_src tex, block, sampler[2]; @@ -278,21 +272,21 @@ create_matrix_frag_shader(struct vl_idct *idct) ureg_MOV(shader, ureg_writemask(t_tc, TGSI_WRITEMASK_Y), tex); for (i = 0; i < 4; ++i) { - fetch_four(shader, l[i], ureg_src(t_tc), sampler[0], start[0], block, false, false, source->width0); + fetch_four(shader, l[i], ureg_src(t_tc), sampler[0], start[0], block, false, false, idct->buffer_width / 4); ureg_MUL(shader, l[i][0], ureg_src(l[i][0]), ureg_imm1f(shader, STAGE1_SCALE)); ureg_MUL(shader, l[i][1], ureg_src(l[i][1]), ureg_imm1f(shader, STAGE1_SCALE)); if(i != 3) ureg_ADD(shader, ureg_writemask(t_tc, TGSI_WRITEMASK_Y), - ureg_src(t_tc), ureg_imm1f(shader, 1.0f / source->height0)); + ureg_src(t_tc), ureg_imm1f(shader, 1.0f / idct->buffer_height)); } for (i = 0; i < NR_RENDER_TARGETS; ++i) { #if NR_RENDER_TARGETS == 8 ureg_MOV(shader, ureg_writemask(t_tc, TGSI_WRITEMASK_X), ureg_imm1f(shader, 1.0f / BLOCK_WIDTH * i)); - fetch_four(shader, r, ureg_src(t_tc), sampler[1], start[1], block, true, true, matrix->width0); + fetch_four(shader, r, ureg_src(t_tc), sampler[1], start[1], block, true, true, BLOCK_WIDTH / 4); #elif NR_RENDER_TARGETS == 1 - fetch_four(shader, r, block, sampler[1], start[1], block, true, true, matrix->width0); + fetch_four(shader, r, block, sampler[1], start[1], block, true, true, BLOCK_WIDTH / 4); #else #error invalid number of render targets #endif @@ -339,13 +333,81 @@ cleanup_shaders(struct vl_idct *idct) } static bool -init_buffers(struct vl_idct *idct) +init_state(struct vl_idct *idct) +{ + struct pipe_vertex_element vertex_elems[NUM_VS_INPUTS]; + struct pipe_sampler_state sampler; + struct pipe_rasterizer_state rs_state; + unsigned i; + + assert(idct); + + idct->quad = vl_vb_upload_quads(idct->pipe, idct->max_blocks); + + if(idct->quad.buffer == NULL) + return false; + + for (i = 0; i < 4; ++i) { + memset(&sampler, 0, sizeof(sampler)); + sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler.compare_mode = PIPE_TEX_COMPARE_NONE; + sampler.compare_func = PIPE_FUNC_ALWAYS; + sampler.normalized_coords = 1; + /*sampler.shadow_ambient = ; */ + /*sampler.lod_bias = ; */ + sampler.min_lod = 0; + /*sampler.max_lod = ; */ + /*sampler.border_color[0] = ; */ + /*sampler.max_anisotropy = ; */ + idct->samplers.all[i] = idct->pipe->create_sampler_state(idct->pipe, &sampler); + } + + memset(&rs_state, 0, sizeof(rs_state)); + /*rs_state.sprite_coord_enable */ + rs_state.sprite_coord_mode = PIPE_SPRITE_COORD_UPPER_LEFT; + rs_state.point_quad_rasterization = true; + rs_state.point_size = BLOCK_WIDTH; + rs_state.gl_rasterization_rules = false; + idct->rs_state = idct->pipe->create_rasterizer_state(idct->pipe, &rs_state); + + vertex_elems[VS_I_RECT] = vl_vb_get_quad_vertex_element(); + + /* Pos element */ + vertex_elems[VS_I_VPOS].src_format = PIPE_FORMAT_R32G32_FLOAT; + + idct->vertex_buffer_stride = vl_vb_element_helper(&vertex_elems[VS_I_VPOS], 1, 1); + idct->vertex_elems_state = idct->pipe->create_vertex_elements_state(idct->pipe, 2, vertex_elems); + + return true; +} + +static void +cleanup_state(struct vl_idct *idct) +{ + unsigned i; + + for (i = 0; i < 4; ++i) + 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 +init_textures(struct vl_idct *idct, struct vl_idct_buffer *buffer) { struct pipe_resource template; struct pipe_sampler_view sampler_view; - struct pipe_vertex_element vertex_elems[2]; unsigned i; + assert(idct && buffer); + + /* create textures */ memset(&template, 0, sizeof(struct pipe_resource)); template.last_level = 0; template.depth0 = 1; @@ -354,149 +416,74 @@ init_buffers(struct vl_idct *idct) template.target = PIPE_TEXTURE_2D; template.format = PIPE_FORMAT_R16G16B16A16_SNORM; - template.width0 = idct->destination->width0 / 4; - template.height0 = idct->destination->height0; + template.width0 = idct->buffer_width / 4; + template.height0 = idct->buffer_height; template.depth0 = 1; template.usage = PIPE_USAGE_STREAM; - idct->textures.individual.source = idct->pipe->screen->resource_create(idct->pipe->screen, &template); + buffer->textures.individual.source = idct->pipe->screen->resource_create(idct->pipe->screen, &template); template.target = PIPE_TEXTURE_3D; template.format = PIPE_FORMAT_R16G16B16A16_SNORM; - template.width0 = idct->destination->width0 / NR_RENDER_TARGETS; - template.height0 = idct->destination->height0 / 4; + template.width0 = idct->buffer_width / NR_RENDER_TARGETS; + template.height0 = idct->buffer_height / 4; template.depth0 = NR_RENDER_TARGETS; template.usage = PIPE_USAGE_STATIC; - idct->textures.individual.intermediate = idct->pipe->screen->resource_create(idct->pipe->screen, &template); + buffer->textures.individual.intermediate = idct->pipe->screen->resource_create(idct->pipe->screen, &template); for (i = 0; i < 4; ++i) { - if(idct->textures.all[i] == NULL) + if(buffer->textures.all[i] == NULL) return false; /* a texture failed to allocate */ - u_sampler_view_default_template(&sampler_view, idct->textures.all[i], idct->textures.all[i]->format); - idct->sampler_views.all[i] = idct->pipe->create_sampler_view(idct->pipe, idct->textures.all[i], &sampler_view); + u_sampler_view_default_template(&sampler_view, buffer->textures.all[i], buffer->textures.all[i]->format); + buffer->sampler_views.all[i] = idct->pipe->create_sampler_view(idct->pipe, buffer->textures.all[i], &sampler_view); } - 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; - - /* 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; - - idct->vertex_elems_state = idct->pipe->create_vertex_elements_state(idct->pipe, 2, vertex_elems); - return true; } static void -cleanup_buffers(struct vl_idct *idct) +cleanup_textures(struct vl_idct *idct, struct vl_idct_buffer *buffer) { unsigned i; - assert(idct); + assert(idct && buffer); for (i = 0; i < 4; ++i) { - pipe_sampler_view_reference(&idct->sampler_views.all[i], NULL); - pipe_resource_reference(&idct->textures.all[i], NULL); + pipe_sampler_view_reference(&buffer->sampler_views.all[i], NULL); + pipe_resource_reference(&buffer->textures.all[i], NULL); } - - idct->pipe->delete_vertex_elements_state(idct->pipe, idct->vertex_elems_state); - pipe_resource_reference(&idct->vertex_bufs.individual.quad.buffer, NULL); - pipe_resource_reference(&idct->vertex_bufs.individual.pos.buffer, NULL); } -static void -init_state(struct vl_idct *idct) +static bool +init_vertex_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer) { - struct pipe_sampler_state sampler; - struct pipe_rasterizer_state rs_state; - unsigned i; - - idct->viewport[0].scale[0] = idct->textures.individual.intermediate->width0; - idct->viewport[0].scale[1] = idct->textures.individual.intermediate->height0; + assert(idct && buffer); - idct->viewport[1].scale[0] = idct->destination->width0; - idct->viewport[1].scale[1] = idct->destination->height0; + buffer->vertex_bufs.individual.quad.stride = idct->quad.stride; + buffer->vertex_bufs.individual.quad.max_index = idct->quad.max_index; + buffer->vertex_bufs.individual.quad.buffer_offset = idct->quad.buffer_offset; + pipe_resource_reference(&buffer->vertex_bufs.individual.quad.buffer, idct->quad.buffer); - idct->fb_state[0].width = idct->textures.individual.intermediate->width0; - idct->fb_state[0].height = idct->textures.individual.intermediate->height0; + buffer->vertex_bufs.individual.pos = vl_vb_create_buffer(idct->pipe, idct->max_blocks, idct->vertex_buffer_stride); - idct->fb_state[0].nr_cbufs = NR_RENDER_TARGETS; - for(i = 0; i < NR_RENDER_TARGETS; ++i) { - idct->fb_state[0].cbufs[i] = idct->pipe->screen->get_tex_surface( - idct->pipe->screen, idct->textures.individual.intermediate, 0, 0, i, - PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET); - } - - idct->fb_state[1].width = idct->destination->width0; - idct->fb_state[1].height = idct->destination->height0; - - idct->fb_state[1].nr_cbufs = 1; - idct->fb_state[1].cbufs[0] = idct->pipe->screen->get_tex_surface( - idct->pipe->screen, idct->destination, 0, 0, 0, - PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET); - - for(i = 0; i < 2; ++i) { - idct->viewport[i].scale[2] = 1; - idct->viewport[i].scale[3] = 1; - idct->viewport[i].translate[0] = 0; - idct->viewport[i].translate[1] = 0; - idct->viewport[i].translate[2] = 0; - idct->viewport[i].translate[3] = 0; - - idct->fb_state[i].zsbuf = NULL; - } + if(buffer->vertex_bufs.individual.pos.buffer == NULL) + return false; - for (i = 0; i < 4; ++i) { - memset(&sampler, 0, sizeof(sampler)); - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; - sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; - sampler.compare_mode = PIPE_TEX_COMPARE_NONE; - sampler.compare_func = PIPE_FUNC_ALWAYS; - sampler.normalized_coords = 1; - /*sampler.shadow_ambient = ; */ - /*sampler.lod_bias = ; */ - sampler.min_lod = 0; - /*sampler.max_lod = ; */ - /*sampler.border_color[0] = ; */ - /*sampler.max_anisotropy = ; */ - idct->samplers.all[i] = idct->pipe->create_sampler_state(idct->pipe, &sampler); - } + if (!vl_vb_init(&buffer->blocks, idct->max_blocks, 2)) + return false; - memset(&rs_state, 0, sizeof(rs_state)); - /*rs_state.sprite_coord_enable */ - rs_state.sprite_coord_mode = PIPE_SPRITE_COORD_UPPER_LEFT; - rs_state.point_quad_rasterization = true; - rs_state.point_size = BLOCK_WIDTH; - rs_state.gl_rasterization_rules = false; - idct->rs_state = idct->pipe->create_rasterizer_state(idct->pipe, &rs_state); + return true; } static void -cleanup_state(struct vl_idct *idct) +cleanup_vertex_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer) { - unsigned i; + assert(idct && buffer); - for(i = 0; i < NR_RENDER_TARGETS; ++i) { - idct->pipe->screen->tex_surface_destroy(idct->fb_state[0].cbufs[i]); - } + pipe_resource_reference(&buffer->vertex_bufs.individual.quad.buffer, NULL); + pipe_resource_reference(&buffer->vertex_bufs.individual.pos.buffer, NULL); - idct->pipe->screen->tex_surface_destroy(idct->fb_state[1].cbufs[0]); - - for (i = 0; i < 4; ++i) - idct->pipe->delete_sampler_state(idct->pipe, idct->samplers.all[i]); - - idct->pipe->delete_rasterizer_state(idct->pipe, idct->rs_state); + vl_vb_cleanup(&buffer->blocks); } struct pipe_resource * @@ -549,85 +536,142 @@ vl_idct_upload_matrix(struct pipe_context *pipe) return matrix; } -bool -vl_idct_init(struct vl_idct *idct, struct pipe_context *pipe, struct pipe_resource *dst, struct pipe_resource *matrix) +bool vl_idct_init(struct vl_idct *idct, struct pipe_context *pipe, + unsigned buffer_width, unsigned buffer_height, + struct pipe_resource *matrix) { - assert(idct && pipe && dst); + assert(idct && pipe && matrix); idct->pipe = pipe; - idct->buffer_width = dst->width0; - idct->buffer_height = dst->height0; - - pipe_resource_reference(&idct->textures.individual.matrix, matrix); - pipe_resource_reference(&idct->textures.individual.transpose, matrix); - pipe_resource_reference(&idct->destination, dst); + idct->buffer_width = buffer_width; + idct->buffer_height = buffer_height; + pipe_resource_reference(&idct->matrix, matrix); idct->max_blocks = - align(idct->destination->width0, BLOCK_WIDTH) / BLOCK_WIDTH * - align(idct->destination->height0, BLOCK_HEIGHT) / BLOCK_HEIGHT * - idct->destination->depth0; + align(buffer_width, BLOCK_WIDTH) / BLOCK_WIDTH * + align(buffer_height, BLOCK_HEIGHT) / BLOCK_HEIGHT; - if(!init_buffers(idct)) + if(!init_shaders(idct)) return false; - if(!init_shaders(idct)) { - cleanup_buffers(idct); + if(!init_state(idct)) { + cleanup_shaders(idct); return false; } - if(!vl_vb_init(&idct->blocks, idct->max_blocks, 2)) { - cleanup_shaders(idct); - cleanup_buffers(idct); + return true; +} + +void +vl_idct_cleanup(struct vl_idct *idct) +{ + cleanup_shaders(idct); + cleanup_state(idct); + + pipe_resource_reference(&idct->matrix, NULL); +} + +bool +vl_idct_init_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer, struct pipe_resource *dst) +{ + unsigned i; + + assert(buffer); + assert(idct); + assert(dst); + + pipe_resource_reference(&buffer->textures.individual.matrix, idct->matrix); + pipe_resource_reference(&buffer->textures.individual.transpose, idct->matrix); + pipe_resource_reference(&buffer->destination, dst); + + if (!init_textures(idct, buffer)) return false; + + if (!init_vertex_buffers(idct, buffer)) + return false; + + /* init state */ + buffer->viewport[0].scale[0] = buffer->textures.individual.intermediate->width0; + buffer->viewport[0].scale[1] = buffer->textures.individual.intermediate->height0; + + buffer->viewport[1].scale[0] = buffer->destination->width0; + buffer->viewport[1].scale[1] = buffer->destination->height0; + + buffer->fb_state[0].width = buffer->textures.individual.intermediate->width0; + buffer->fb_state[0].height = buffer->textures.individual.intermediate->height0; + + buffer->fb_state[0].nr_cbufs = NR_RENDER_TARGETS; + for(i = 0; i < NR_RENDER_TARGETS; ++i) { + buffer->fb_state[0].cbufs[i] = idct->pipe->screen->get_tex_surface( + idct->pipe->screen, buffer->textures.individual.intermediate, 0, 0, i, + PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET); } - init_state(idct); + buffer->fb_state[1].width = buffer->destination->width0; + buffer->fb_state[1].height = buffer->destination->height0; - vl_idct_map_buffers(idct); + buffer->fb_state[1].nr_cbufs = 1; + buffer->fb_state[1].cbufs[0] = idct->pipe->screen->get_tex_surface( + idct->pipe->screen, buffer->destination, 0, 0, 0, + PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET); + + for(i = 0; i < 2; ++i) { + buffer->viewport[i].scale[2] = 1; + buffer->viewport[i].scale[3] = 1; + buffer->viewport[i].translate[0] = 0; + buffer->viewport[i].translate[1] = 0; + buffer->viewport[i].translate[2] = 0; + buffer->viewport[i].translate[3] = 0; + + buffer->fb_state[i].zsbuf = NULL; + } return true; } void -vl_idct_cleanup(struct vl_idct *idct) +vl_idct_cleanup_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer) { - vl_idct_unmap_buffers(idct); + unsigned i; - vl_vb_cleanup(&idct->blocks); - cleanup_shaders(idct); - cleanup_buffers(idct); + assert(buffer); - cleanup_state(idct); + for(i = 0; i < NR_RENDER_TARGETS; ++i) { + idct->pipe->screen->tex_surface_destroy(buffer->fb_state[0].cbufs[i]); + } + + idct->pipe->screen->tex_surface_destroy(buffer->fb_state[1].cbufs[0]); - pipe_resource_reference(&idct->destination, NULL); + cleanup_textures(idct, buffer); + cleanup_vertex_buffers(idct, buffer); } void -vl_idct_map_buffers(struct vl_idct *idct) +vl_idct_map_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer) { assert(idct); struct pipe_box rect = { 0, 0, 0, - idct->textures.individual.source->width0, - idct->textures.individual.source->height0, + buffer->textures.individual.source->width0, + buffer->textures.individual.source->height0, 1 }; - idct->tex_transfer = idct->pipe->get_transfer + buffer->tex_transfer = idct->pipe->get_transfer ( - idct->pipe, idct->textures.individual.source, + idct->pipe, buffer->textures.individual.source, u_subresource(0, 0), PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD, &rect ); - idct->texels = idct->pipe->transfer_map(idct->pipe, idct->tex_transfer); + buffer->texels = idct->pipe->transfer_map(idct->pipe, buffer->tex_transfer); } void -vl_idct_add_block(struct vl_idct *idct, unsigned x, unsigned y, short *block) +vl_idct_add_block(struct vl_idct_buffer *buffer, unsigned x, unsigned y, short *block) { struct vertex2f v; unsigned tex_pitch; @@ -635,30 +679,30 @@ vl_idct_add_block(struct vl_idct *idct, unsigned x, unsigned y, short *block) unsigned i; - assert(idct); + assert(buffer); - tex_pitch = idct->tex_transfer->stride / sizeof(short); - texels = idct->texels + y * tex_pitch * BLOCK_HEIGHT + x * BLOCK_WIDTH; + 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)); v.x = x; v.y = y; - vl_vb_add_block(&idct->blocks, (float*)&v); + vl_vb_add_block(&buffer->blocks, (float*)&v); } void -vl_idct_unmap_buffers(struct vl_idct *idct) +vl_idct_unmap_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer) { - assert(idct); + assert(idct && buffer); - idct->pipe->transfer_unmap(idct->pipe, idct->tex_transfer); - idct->pipe->transfer_destroy(idct->pipe, idct->tex_transfer); + 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) +vl_idct_flush(struct vl_idct *idct, struct vl_idct_buffer *buffer) { struct pipe_transfer *vec_transfer; void *vectors; @@ -669,34 +713,34 @@ vl_idct_flush(struct vl_idct *idct) vectors = pipe_buffer_map ( idct->pipe, - idct->vertex_bufs.individual.pos.buffer, + buffer->vertex_bufs.individual.pos.buffer, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD, &vec_transfer ); - num_verts = vl_vb_upload(&idct->blocks, vectors); + num_verts = vl_vb_upload(&buffer->blocks, vectors); - pipe_buffer_unmap(idct->pipe, idct->vertex_bufs.individual.pos.buffer, vec_transfer); + pipe_buffer_unmap(idct->pipe, buffer->vertex_bufs.individual.pos.buffer, vec_transfer); if(num_verts > 0) { idct->pipe->bind_rasterizer_state(idct->pipe, idct->rs_state); - idct->pipe->set_vertex_buffers(idct->pipe, 2, idct->vertex_bufs.all); + idct->pipe->set_vertex_buffers(idct->pipe, 2, buffer->vertex_bufs.all); idct->pipe->bind_vertex_elements_state(idct->pipe, idct->vertex_elems_state); idct->pipe->bind_vs_state(idct->pipe, idct->vs); /* first stage */ - idct->pipe->set_framebuffer_state(idct->pipe, &idct->fb_state[0]); - idct->pipe->set_viewport_state(idct->pipe, &idct->viewport[0]); - idct->pipe->set_fragment_sampler_views(idct->pipe, 2, idct->sampler_views.stage[0]); + idct->pipe->set_framebuffer_state(idct->pipe, &buffer->fb_state[0]); + idct->pipe->set_viewport_state(idct->pipe, &buffer->viewport[0]); + idct->pipe->set_fragment_sampler_views(idct->pipe, 2, buffer->sampler_views.stage[0]); idct->pipe->bind_fragment_sampler_states(idct->pipe, 2, idct->samplers.stage[0]); idct->pipe->bind_fs_state(idct->pipe, idct->matrix_fs); util_draw_arrays(idct->pipe, PIPE_PRIM_QUADS, 0, num_verts); /* second stage */ - idct->pipe->set_framebuffer_state(idct->pipe, &idct->fb_state[1]); - idct->pipe->set_viewport_state(idct->pipe, &idct->viewport[1]); - idct->pipe->set_fragment_sampler_views(idct->pipe, 2, idct->sampler_views.stage[1]); + idct->pipe->set_framebuffer_state(idct->pipe, &buffer->fb_state[1]); + idct->pipe->set_viewport_state(idct->pipe, &buffer->viewport[1]); + idct->pipe->set_fragment_sampler_views(idct->pipe, 2, buffer->sampler_views.stage[1]); idct->pipe->bind_fragment_sampler_states(idct->pipe, 2, idct->samplers.stage[1]); idct->pipe->bind_fs_state(idct->pipe, idct->transpose_fs); util_draw_arrays(idct->pipe, PIPE_PRIM_QUADS, 0, num_verts); diff --git a/src/gallium/auxiliary/vl/vl_idct.h b/src/gallium/auxiliary/vl/vl_idct.h index 2e98f22bea2..6076bdec46c 100644 --- a/src/gallium/auxiliary/vl/vl_idct.h +++ b/src/gallium/auxiliary/vl/vl_idct.h @@ -31,10 +31,6 @@ #include #include "vl_vertex_buffers.h" -struct vl_idct_buffer -{ -}; - struct vl_idct { struct pipe_context *pipe; @@ -44,13 +40,7 @@ struct vl_idct unsigned max_blocks; - struct pipe_viewport_state viewport[2]; - struct pipe_framebuffer_state fb_state[2]; - - struct pipe_resource *destination; - void *rs_state; - void *vertex_elems_state; union @@ -63,6 +53,22 @@ struct vl_idct } individual; } samplers; + void *vs; + void *matrix_fs, *transpose_fs; + + struct pipe_resource *matrix; + struct pipe_vertex_buffer quad; + + unsigned vertex_buffer_stride; +}; + +struct vl_idct_buffer +{ + struct pipe_viewport_state viewport[2]; + struct pipe_framebuffer_state fb_state[2]; + + struct pipe_resource *destination; + union { struct pipe_sampler_view *all[4]; @@ -73,9 +79,6 @@ struct vl_idct } individual; } sampler_views; - void *vs; - void *matrix_fs, *transpose_fs; - union { struct pipe_resource *all[4]; @@ -100,16 +103,22 @@ struct vl_idct 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); +bool vl_idct_init(struct vl_idct *idct, struct pipe_context *pipe, + unsigned buffer_width, unsigned buffer_height, + struct pipe_resource *matrix); void vl_idct_cleanup(struct vl_idct *idct); -void vl_idct_map_buffers(struct vl_idct *idct); +bool vl_idct_init_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer, struct pipe_resource *dst); + +void vl_idct_cleanup_buffer(struct vl_idct *idct, struct vl_idct_buffer *buffer); + +void vl_idct_map_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer); -void vl_idct_add_block(struct vl_idct *idct, unsigned x, unsigned y, short *block); +void vl_idct_add_block(struct vl_idct_buffer *buffer, unsigned x, unsigned y, short *block); -void vl_idct_unmap_buffers(struct vl_idct *idct); +void vl_idct_unmap_buffers(struct vl_idct *idct, struct vl_idct_buffer *buffer); -void vl_idct_flush(struct vl_idct *idct); +void vl_idct_flush(struct vl_idct *idct, struct vl_idct_buffer *buffer); #endif diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c index 5ee9836f293..28de8c9a81a 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c +++ b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.c @@ -593,6 +593,7 @@ cleanup_pipe_state(struct vl_mpeg12_mc_renderer *r) static bool init_buffers(struct vl_mpeg12_mc_renderer *r) { + struct pipe_resource *idct_matrix; struct pipe_resource template; struct pipe_vertex_element vertex_elems[NUM_VS_INPUTS]; struct pipe_sampler_view sampler_view; @@ -602,7 +603,7 @@ init_buffers(struct vl_mpeg12_mc_renderer *r) const unsigned mbh = align(r->buffer_height, MACROBLOCK_HEIGHT) / MACROBLOCK_HEIGHT; - unsigned i; + unsigned i, stride; assert(r); @@ -624,6 +625,17 @@ init_buffers(struct vl_mpeg12_mc_renderer *r) r->textures.individual.y = r->pipe->screen->resource_create(r->pipe->screen, &template); + if (!(idct_matrix = vl_idct_upload_matrix(r->pipe))) + return false; + + if (!vl_idct_init(&r->idct_luma, r->pipe, r->buffer_width, r->buffer_height, idct_matrix)) + return false; + + if (!vl_idct_init_buffer(&r->idct_luma, &r->idct_y, r->textures.individual.y)) + return false; + + vl_idct_map_buffers(&r->idct_luma, &r->idct_y); + if (r->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420) { template.width0 = r->buffer_width / 2; template.height0 = r->buffer_height / 2; @@ -636,6 +648,19 @@ init_buffers(struct vl_mpeg12_mc_renderer *r) r->textures.individual.cr = r->pipe->screen->resource_create(r->pipe->screen, &template); + if(!vl_idct_init(&r->idct_chroma, r->pipe, template.width0, template.height0, idct_matrix)) + return false; + + if (!vl_idct_init_buffer(&r->idct_chroma, &r->idct_cb, r->textures.individual.cb)) + return false; + + vl_idct_map_buffers(&r->idct_chroma, &r->idct_cb); + + if (!vl_idct_init_buffer(&r->idct_chroma, &r->idct_cr, r->textures.individual.cr)) + return false; + + vl_idct_map_buffers(&r->idct_chroma, &r->idct_cr); + for (i = 0; i < 3; ++i) { u_sampler_view_default_template(&sampler_view, r->textures.all[i], @@ -645,7 +670,8 @@ init_buffers(struct vl_mpeg12_mc_renderer *r) memset(&vertex_elems, 0, sizeof(vertex_elems)); - r->vertex_bufs.individual.quad = vl_vb_upload_quads(r->pipe, r->macroblocks_per_batch, &vertex_elems[VS_I_RECT]); + vertex_elems[VS_I_RECT] = vl_vb_get_quad_vertex_element(); + r->vertex_bufs.individual.quad = vl_vb_upload_quads(r->pipe, r->macroblocks_per_batch); /* Position element */ vertex_elems[VS_I_VPOS].src_format = PIPE_FORMAT_R32G32_FLOAT; @@ -665,16 +691,17 @@ init_buffers(struct vl_mpeg12_mc_renderer *r) /* progressive=0.0f interlaced=1.0f */ vertex_elems[VS_I_INTERLACED].src_format = PIPE_FORMAT_R32_FLOAT; + stride = vl_vb_element_helper(&vertex_elems[VS_I_VPOS], 6, 1); + r->vertex_bufs.individual.pos = vl_vb_create_buffer( - r->pipe, r->macroblocks_per_batch, - &vertex_elems[VS_I_VPOS], 6, 1); + r->pipe, r->macroblocks_per_batch, 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, - &vertex_elems[VS_I_MV0 + i], 1, i + 2); + r->pipe, r->macroblocks_per_batch, stride); } for(i = 0; i < VL_NUM_MACROBLOCK_TYPES; ++i) @@ -698,6 +725,17 @@ cleanup_buffers(struct vl_mpeg12_mc_renderer *r) for(i = 0; iidct_luma, &r->idct_y); + vl_idct_unmap_buffers(&r->idct_chroma, &r->idct_cb); + vl_idct_unmap_buffers(&r->idct_chroma, &r->idct_cr); + + vl_idct_cleanup_buffer(&r->idct_luma, &r->idct_y); + vl_idct_cleanup_buffer(&r->idct_chroma, &r->idct_cb); + vl_idct_cleanup_buffer(&r->idct_chroma, &r->idct_cr); + + vl_idct_cleanup(&r->idct_luma); + vl_idct_cleanup(&r->idct_chroma); } static enum VL_MACROBLOCK_TYPE @@ -1048,8 +1086,6 @@ vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer, enum pipe_video_chroma_format chroma_format, enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode) { - struct pipe_resource *idct_matrix; - assert(renderer); assert(pipe); @@ -1080,30 +1116,8 @@ vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer, renderer->future = NULL; renderer->num_macroblocks = 0; - 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, idct_matrix)) - goto error_idct_cr; - - if(!vl_idct_init(&renderer->idct_cb, pipe, renderer->textures.individual.cb, idct_matrix)) - goto error_idct_cb; - return true; -error_idct_cb: - vl_idct_cleanup(&renderer->idct_cr); - -error_idct_cr: - vl_idct_cleanup(&renderer->idct_y); - -error_idct_y: -error_idct_matrix: - cleanup_buffers(renderer); - error_buffers: cleanup_pipe_state(renderer); @@ -1117,10 +1131,6 @@ vl_mpeg12_mc_renderer_cleanup(struct vl_mpeg12_mc_renderer *renderer) { assert(renderer); - vl_idct_cleanup(&renderer->idct_y); - vl_idct_cleanup(&renderer->idct_cr); - vl_idct_cleanup(&renderer->idct_cb); - util_delete_keymap(renderer->texview_map, renderer->pipe); cleanup_pipe_state(renderer); cleanup_buffers(renderer); @@ -1141,27 +1151,12 @@ vl_mpeg12_mc_renderer_render_macroblocks(struct vl_mpeg12_mc_renderer *mpeg12_macroblocks, struct pipe_fence_handle **fence) { - bool new_surface = false; - assert(renderer); assert(surface); assert(num_macroblocks); assert(mpeg12_macroblocks); - if (renderer->surface) { - if (surface != renderer->surface) { - new_surface = true; - } else { - - /* If the surface we're rendering hasn't changed the ref frames shouldn't change. */ - assert(renderer->past == past); - assert(renderer->future == future); - } - } - else - new_surface = true; - - if (new_surface) { + if (surface != renderer->surface) { pipe_surface_reference(&renderer->surface, surface); pipe_surface_reference(&renderer->past, past); pipe_surface_reference(&renderer->future, future); @@ -1203,13 +1198,13 @@ vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer) if (renderer->num_macroblocks == 0) return; - vl_idct_unmap_buffers(&renderer->idct_y); - vl_idct_unmap_buffers(&renderer->idct_cr); - vl_idct_unmap_buffers(&renderer->idct_cb); + vl_idct_unmap_buffers(&renderer->idct_luma, &renderer->idct_y); + vl_idct_unmap_buffers(&renderer->idct_chroma, &renderer->idct_cr); + vl_idct_unmap_buffers(&renderer->idct_chroma, &renderer->idct_cb); - vl_idct_flush(&renderer->idct_y); - vl_idct_flush(&renderer->idct_cr); - vl_idct_flush(&renderer->idct_cb); + vl_idct_flush(&renderer->idct_luma, &renderer->idct_y); + vl_idct_flush(&renderer->idct_chroma, &renderer->idct_cr); + vl_idct_flush(&renderer->idct_chroma, &renderer->idct_cb); upload_vertex_stream(renderer, num_verts); @@ -1225,9 +1220,9 @@ vl_mpeg12_mc_renderer_flush(struct vl_mpeg12_mc_renderer *renderer) renderer->pipe->flush(renderer->pipe, PIPE_FLUSH_RENDER_CACHE, renderer->fence); - vl_idct_map_buffers(&renderer->idct_y); - vl_idct_map_buffers(&renderer->idct_cr); - vl_idct_map_buffers(&renderer->idct_cb); + vl_idct_map_buffers(&renderer->idct_luma, &renderer->idct_y); + vl_idct_map_buffers(&renderer->idct_chroma, &renderer->idct_cr); + vl_idct_map_buffers(&renderer->idct_chroma, &renderer->idct_cb); 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 6ce9cbe390c..f1c7a2a4012 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h +++ b/src/gallium/auxiliary/vl/vl_mpeg12_mc_renderer.h @@ -80,7 +80,8 @@ struct vl_mpeg12_mc_renderer struct pipe_viewport_state viewport; struct pipe_framebuffer_state fb_state; - struct vl_idct idct_y, idct_cb, idct_cr; + struct vl_idct idct_luma, idct_chroma; + struct vl_idct_buffer idct_y, idct_cb, idct_cr; void *rs_state; diff --git a/src/gallium/auxiliary/vl/vl_vertex_buffers.c b/src/gallium/auxiliary/vl/vl_vertex_buffers.c index 4e0d704a23d..4647685053b 100644 --- a/src/gallium/auxiliary/vl/vl_vertex_buffers.c +++ b/src/gallium/auxiliary/vl/vl_vertex_buffers.c @@ -40,7 +40,7 @@ static const struct quadf const_quad = { }; struct pipe_vertex_buffer -vl_vb_upload_quads(struct pipe_context *pipe, unsigned max_blocks, struct pipe_vertex_element* element) +vl_vb_upload_quads(struct pipe_context *pipe, unsigned max_blocks) { struct pipe_vertex_buffer quad; struct pipe_transfer *buf_transfer; @@ -50,13 +50,6 @@ vl_vb_upload_quads(struct pipe_context *pipe, unsigned max_blocks, struct pipe_v 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); @@ -89,34 +82,56 @@ vl_vb_upload_quads(struct pipe_context *pipe, unsigned max_blocks, struct pipe_v return quad; } +struct pipe_vertex_element +vl_vb_get_quad_vertex_element() +{ + struct pipe_vertex_element element; + + /* setup rectangle element */ + element.src_offset = 0; + element.instance_divisor = 0; + element.vertex_buffer_index = 0; + element.src_format = PIPE_FORMAT_R32G32_FLOAT; + + return 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) +vl_vb_create_buffer(struct pipe_context *pipe, unsigned max_blocks, unsigned stride) { 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.stride = stride; 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 + stride * 4 * max_blocks ); return buf; } +unsigned +vl_vb_element_helper(struct pipe_vertex_element* elements, unsigned num_elements, + unsigned vertex_buffer_index) +{ + unsigned i, offset = 0; + + assert(elements && num_elements); + + for ( i = 0; i < num_elements; ++i ) { + elements[i].src_offset = offset; + elements[i].instance_divisor = 0; + elements[i].vertex_buffer_index = vertex_buffer_index; + offset += util_format_get_blocksize(elements[i].src_format); + } + + return offset; +} + 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 cf71f029a79..dae80fa767b 100644 --- a/src/gallium/auxiliary/vl/vl_vertex_buffers.h +++ b/src/gallium/auxiliary/vl/vl_vertex_buffers.h @@ -38,12 +38,14 @@ struct vl_vertex_buffer float *buffer; }; -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_upload_quads(struct pipe_context *pipe, unsigned max_blocks); -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_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); -- 2.30.2