diff options
author | Christian König <[email protected]> | 2011-04-04 23:28:18 +0200 |
---|---|---|
committer | Christian König <[email protected]> | 2011-04-04 23:28:18 +0200 |
commit | 3a2b906805985e0a4258bcbaed4cdff758875514 (patch) | |
tree | cabe95ecc72a2dbcb811c45c5751fcd28f4cb5c1 /src/gallium | |
parent | ebd564587a46891cb2729c6a0ed84b7c27dc23ec (diff) |
[g3dvl] rename ycbcr buffer to video buffer and add some more functionality
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/auxiliary/Makefile | 2 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_idct.c | 1 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_idct.h | 2 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_mpeg12_context.c | 191 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_mpeg12_context.h | 15 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_video_buffer.c | 190 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_video_buffer.h (renamed from src/gallium/auxiliary/vl/vl_ycbcr_buffer.h) | 41 | ||||
-rw-r--r-- | src/gallium/auxiliary/vl/vl_ycbcr_buffer.c | 195 |
8 files changed, 312 insertions, 325 deletions
diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile index 0464df84e12..b4ad059ec90 100644 --- a/src/gallium/auxiliary/Makefile +++ b/src/gallium/auxiliary/Makefile @@ -154,7 +154,7 @@ C_SOURCES = \ vl/vl_csc.c \ vl/vl_idct.c \ vl/vl_vertex_buffers.c \ - vl/vl_ycbcr_buffer.c + vl/vl_video_buffer.c GALLIVM_SOURCES = \ gallivm/lp_bld_arit.c \ diff --git a/src/gallium/auxiliary/vl/vl_idct.c b/src/gallium/auxiliary/vl/vl_idct.c index 6bebac1e88a..c92659bc5b0 100644 --- a/src/gallium/auxiliary/vl/vl_idct.c +++ b/src/gallium/auxiliary/vl/vl_idct.c @@ -27,7 +27,6 @@ #include "vl_idct.h" #include "vl_vertex_buffers.h" -#include "vl_ycbcr_buffer.h" #include "vl_defines.h" #include "util/u_draw.h" #include <assert.h> diff --git a/src/gallium/auxiliary/vl/vl_idct.h b/src/gallium/auxiliary/vl/vl_idct.h index 2d6778d7ec4..fedebd3ff21 100644 --- a/src/gallium/auxiliary/vl/vl_idct.h +++ b/src/gallium/auxiliary/vl/vl_idct.h @@ -29,8 +29,6 @@ #define vl_idct_h #include <pipe/p_state.h> -#include "vl_vertex_buffers.h" -#include "vl_ycbcr_buffer.h" /* shader based inverse distinct cosinus transformation * expect usage of vl_vertex_buffers as a todo list diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_context.c b/src/gallium/auxiliary/vl/vl_mpeg12_context.c index 0eab9e3c614..a83c240bcd9 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_context.c +++ b/src/gallium/auxiliary/vl/vl_mpeg12_context.c @@ -62,7 +62,7 @@ upload_buffer(struct vl_mpeg12_context *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_y, mb->mbx * 2 + x, mb->mby * 2 + y, blocks); + vl_idct_add_block(&buffer->idct[0], mb->mbx * 2 + x, mb->mby * 2 + y, blocks); blocks += BLOCK_WIDTH * BLOCK_HEIGHT; } } @@ -73,10 +73,7 @@ upload_buffer(struct vl_mpeg12_context *ctx, for (tb = 1; tb < 3; ++tb) { if (mb->cbp & (*ctx->empty_block_mask)[tb][0][0]) { - if(tb == 1) - vl_idct_add_block(&buffer->idct_cb, mb->mbx, mb->mby, blocks); - else - vl_idct_add_block(&buffer->idct_cr, mb->mbx, mb->mby, blocks); + vl_idct_add_block(&buffer->idct[tb], mb->mbx, mb->mby, blocks); blocks += BLOCK_WIDTH * BLOCK_HEIGHT; } } @@ -89,16 +86,16 @@ vl_mpeg12_buffer_destroy(struct pipe_video_buffer *buffer) struct vl_mpeg12_context *ctx = (struct vl_mpeg12_context*)buf->base.context; assert(buf && ctx); - vl_ycbcr_buffer_cleanup(&buf->idct_source); - vl_ycbcr_buffer_cleanup(&buf->idct_2_mc); - vl_ycbcr_buffer_cleanup(&buf->render_result); + vl_video_buffer_cleanup(&buf->idct_source); + vl_video_buffer_cleanup(&buf->idct_2_mc); + vl_video_buffer_cleanup(&buf->render_result); vl_vb_cleanup(&buf->vertex_stream); - vl_idct_cleanup_buffer(&ctx->idct_y, &buf->idct_y); - vl_idct_cleanup_buffer(&ctx->idct_c, &buf->idct_cb); - vl_idct_cleanup_buffer(&ctx->idct_c, &buf->idct_cr); - vl_mpeg12_mc_cleanup_buffer(&buf->mc_y); - vl_mpeg12_mc_cleanup_buffer(&buf->mc_cb); - vl_mpeg12_mc_cleanup_buffer(&buf->mc_cr); + vl_idct_cleanup_buffer(&ctx->idct_y, &buf->idct[0]); + vl_idct_cleanup_buffer(&ctx->idct_c, &buf->idct[1]); + vl_idct_cleanup_buffer(&ctx->idct_c, &buf->idct[2]); + vl_mpeg12_mc_cleanup_buffer(&buf->mc[0]); + vl_mpeg12_mc_cleanup_buffer(&buf->mc[1]); + vl_mpeg12_mc_cleanup_buffer(&buf->mc[2]); FREE(buf); } @@ -114,9 +111,9 @@ vl_mpeg12_buffer_map(struct pipe_video_buffer *buffer) assert(ctx); vl_vb_map(&buf->vertex_stream, ctx->pipe); - vl_idct_map_buffers(&ctx->idct_y, &buf->idct_y); - vl_idct_map_buffers(&ctx->idct_c, &buf->idct_cb); - vl_idct_map_buffers(&ctx->idct_c, &buf->idct_cr); + vl_idct_map_buffers(&ctx->idct_y, &buf->idct[0]); + vl_idct_map_buffers(&ctx->idct_c, &buf->idct[1]); + vl_idct_map_buffers(&ctx->idct_c, &buf->idct[2]); } static void @@ -155,9 +152,9 @@ vl_mpeg12_buffer_unmap(struct pipe_video_buffer *buffer) assert(ctx); vl_vb_unmap(&buf->vertex_stream, ctx->pipe); - vl_idct_unmap_buffers(&ctx->idct_y, &buf->idct_y); - vl_idct_unmap_buffers(&ctx->idct_c, &buf->idct_cb); - vl_idct_unmap_buffers(&ctx->idct_c, &buf->idct_cr); + vl_idct_unmap_buffers(&ctx->idct_y, &buf->idct[0]); + vl_idct_unmap_buffers(&ctx->idct_c, &buf->idct[1]); + vl_idct_unmap_buffers(&ctx->idct_c, &buf->idct[2]); } static void @@ -169,56 +166,40 @@ vl_mpeg12_buffer_flush(struct pipe_video_buffer *buffer, struct vl_mpeg12_buffer *past = (struct vl_mpeg12_buffer *)refs[0]; struct vl_mpeg12_buffer *future = (struct vl_mpeg12_buffer *)refs[1]; - struct vl_ycbcr_surfaces *surfaces; - struct vl_ycbcr_sampler_views *sv_past; - struct vl_ycbcr_sampler_views *sv_future; + vl_surfaces *surfaces; + vl_sampler_views *sv_past; + vl_sampler_views *sv_future; struct pipe_sampler_view *sv_refs[2]; unsigned ne_start, ne_num, e_start, e_num; struct vl_mpeg12_context *ctx; + unsigned i; assert(buf); ctx = (struct vl_mpeg12_context *)buf->base.context; assert(ctx); - surfaces = vl_ycbcr_get_surfaces(&buf->render_result); + surfaces = vl_video_buffer_surfaces(&buf->render_result); - sv_past = past ? vl_ycbcr_get_sampler_views(&past->render_result) : NULL; - sv_future = future ? vl_ycbcr_get_sampler_views(&future->render_result) : NULL; + sv_past = past ? vl_video_buffer_sampler_views(&past->render_result) : NULL; + sv_future = future ? vl_video_buffer_sampler_views(&future->render_result) : NULL; vl_vb_restart(&buf->vertex_stream, &ne_start, &ne_num, &e_start, &e_num); ctx->pipe->set_vertex_buffers(ctx->pipe, 2, buf->vertex_bufs.all); ctx->pipe->bind_blend_state(ctx->pipe, ctx->blend); + for (i = 0; i < VL_MAX_PLANES; ++i) { + ctx->pipe->bind_vertex_elements_state(ctx->pipe, ctx->ves[i]); + vl_idct_flush(i == 0 ? &ctx->idct_y : &ctx->idct_c, &buf->idct[i], ne_num); - ctx->pipe->bind_vertex_elements_state(ctx->pipe, ctx->ves_y); - vl_idct_flush(&ctx->idct_y, &buf->idct_y, ne_num); - - sv_refs[0] = sv_past ? sv_past->y : NULL; - sv_refs[1] = sv_future ? sv_future->y : NULL; - - vl_mpeg12_mc_renderer_flush(&ctx->mc, &buf->mc_y, surfaces->y, - sv_refs, ne_start, ne_num, e_start, e_num, fence); - - ctx->pipe->bind_vertex_elements_state(ctx->pipe, ctx->ves_cb); - vl_idct_flush(&ctx->idct_c, &buf->idct_cb, ne_num); - - sv_refs[0] = sv_past ? sv_past->cb : NULL; - sv_refs[1] = sv_future ? sv_future->cb : NULL; - - vl_mpeg12_mc_renderer_flush(&ctx->mc, &buf->mc_cb, surfaces->cb, - sv_refs, ne_start, ne_num, e_start, e_num, fence); + sv_refs[0] = sv_past ? (*sv_past)[i] : NULL; + sv_refs[1] = sv_future ? (*sv_future)[i] : NULL; - ctx->pipe->bind_vertex_elements_state(ctx->pipe, ctx->ves_cr); - vl_idct_flush(&ctx->idct_c, &buf->idct_cr, ne_num); - - sv_refs[0] = sv_past ? sv_past->cr : NULL; - sv_refs[1] = sv_future ? sv_future->cr : NULL; - - vl_mpeg12_mc_renderer_flush(&ctx->mc, &buf->mc_cr, surfaces->cr, - sv_refs, ne_start, ne_num, e_start, e_num, fence); + vl_mpeg12_mc_renderer_flush(&ctx->mc, &buf->mc[i], (*surfaces)[i], + sv_refs, ne_start, ne_num, e_start, e_num, fence); + } } static void @@ -226,17 +207,17 @@ vl_mpeg12_buffer_get_sampler_views(struct pipe_video_buffer *buffer, struct pipe_sampler_view *sampler_views[3]) { struct vl_mpeg12_buffer *buf = (struct vl_mpeg12_buffer*)buffer; - struct vl_ycbcr_sampler_views *samplers; + vl_sampler_views *samplers; + unsigned i; assert(buf); - samplers = vl_ycbcr_get_sampler_views(&buf->render_result); + samplers = vl_video_buffer_sampler_views(&buf->render_result); assert(samplers); - pipe_sampler_view_reference(&sampler_views[0], samplers->y); - pipe_sampler_view_reference(&sampler_views[1], samplers->cb); - pipe_sampler_view_reference(&sampler_views[2], samplers->cr); + for (i = 0; i < VL_MAX_PLANES; ++i) + pipe_sampler_view_reference(&sampler_views[i], (*samplers)[i]); } static void @@ -257,9 +238,9 @@ vl_mpeg12_destroy(struct pipe_video_context *vpipe) vl_mpeg12_mc_renderer_cleanup(&ctx->mc); vl_idct_cleanup(&ctx->idct_y); vl_idct_cleanup(&ctx->idct_c); - ctx->pipe->delete_vertex_elements_state(ctx->pipe, ctx->ves_y); - ctx->pipe->delete_vertex_elements_state(ctx->pipe, ctx->ves_cb); - ctx->pipe->delete_vertex_elements_state(ctx->pipe, ctx->ves_cr); + ctx->pipe->delete_vertex_elements_state(ctx->pipe, ctx->ves[0]); + ctx->pipe->delete_vertex_elements_state(ctx->pipe, ctx->ves[1]); + ctx->pipe->delete_vertex_elements_state(ctx->pipe, ctx->ves[2]); pipe_resource_reference(&ctx->quads.buffer, NULL); ctx->pipe->destroy(ctx->pipe); @@ -307,11 +288,29 @@ vl_mpeg12_create_sampler_view(struct pipe_video_context *vpipe, static struct pipe_video_buffer * vl_mpeg12_create_buffer(struct pipe_video_context *vpipe) { + const enum pipe_format idct_source_formats[3] = { + PIPE_FORMAT_R16G16B16A16_SNORM, + PIPE_FORMAT_R16G16B16A16_SNORM, + PIPE_FORMAT_R16G16B16A16_SNORM + }; + + const enum pipe_format idct_2_mc_formats[3] = { + PIPE_FORMAT_R16_SNORM, + PIPE_FORMAT_R16_SNORM, + PIPE_FORMAT_R16_SNORM + }; + + const enum pipe_format render_result_formats[3] = { + PIPE_FORMAT_R8_SNORM, + PIPE_FORMAT_R8_SNORM, + PIPE_FORMAT_R8_SNORM + }; + struct vl_mpeg12_context *ctx = (struct vl_mpeg12_context*)vpipe; struct vl_mpeg12_buffer *buffer; - struct vl_ycbcr_sampler_views *idct_views, *mc_views; - struct vl_ycbcr_surfaces *idct_surfaces; + vl_sampler_views *idct_views, *mc_views; + vl_surfaces *idct_surfaces; assert(ctx); @@ -337,88 +336,88 @@ vl_mpeg12_create_buffer(struct pipe_video_context *vpipe) if (!buffer->vertex_bufs.individual.stream.buffer) goto error_vertex_stream; - if (!vl_ycbcr_buffer_init(&buffer->idct_source, ctx->pipe, - ctx->buffer_width, ctx->buffer_height, - ctx->base.chroma_format, - PIPE_FORMAT_R16G16B16A16_SNORM, + if (!vl_video_buffer_init(&buffer->idct_source, ctx->pipe, + ctx->buffer_width / 4, ctx->buffer_height, 1, + ctx->base.chroma_format, 3, + idct_source_formats, PIPE_USAGE_STREAM)) goto error_idct_source; - if (!vl_ycbcr_buffer_init(&buffer->idct_2_mc, ctx->pipe, - ctx->buffer_width, ctx->buffer_height, - ctx->base.chroma_format, - PIPE_FORMAT_R16_SNORM, + if (!vl_video_buffer_init(&buffer->idct_2_mc, ctx->pipe, + ctx->buffer_width, ctx->buffer_height, 1, + ctx->base.chroma_format, 3, + idct_2_mc_formats, PIPE_USAGE_STATIC)) goto error_idct_2_mc; - if (!vl_ycbcr_buffer_init(&buffer->render_result, ctx->pipe, - ctx->buffer_width, ctx->buffer_height, - ctx->base.chroma_format, - PIPE_FORMAT_R8_SNORM, + if (!vl_video_buffer_init(&buffer->render_result, ctx->pipe, + ctx->buffer_width, ctx->buffer_height, 1, + ctx->base.chroma_format, 3, + render_result_formats, PIPE_USAGE_STATIC)) goto error_render_result; - idct_views = vl_ycbcr_get_sampler_views(&buffer->idct_source); + idct_views = vl_video_buffer_sampler_views(&buffer->idct_source); if (!idct_views) goto error_idct_views; - idct_surfaces = vl_ycbcr_get_surfaces(&buffer->idct_2_mc); + idct_surfaces = vl_video_buffer_surfaces(&buffer->idct_2_mc); if (!idct_surfaces) goto error_idct_surfaces; - if (!vl_idct_init_buffer(&ctx->idct_y, &buffer->idct_y, - idct_views->y, idct_surfaces->y)) + if (!vl_idct_init_buffer(&ctx->idct_y, &buffer->idct[0], + (*idct_views)[0], (*idct_surfaces)[0])) goto error_idct_y; - if (!vl_idct_init_buffer(&ctx->idct_c, &buffer->idct_cb, - idct_views->cb, idct_surfaces->cb)) + if (!vl_idct_init_buffer(&ctx->idct_c, &buffer->idct[1], + (*idct_views)[1], (*idct_surfaces)[1])) goto error_idct_cb; - if (!vl_idct_init_buffer(&ctx->idct_c, &buffer->idct_cr, - idct_views->cr, idct_surfaces->cr)) + if (!vl_idct_init_buffer(&ctx->idct_c, &buffer->idct[2], + (*idct_views)[2], (*idct_surfaces)[2])) goto error_idct_cr; - mc_views = vl_ycbcr_get_sampler_views(&buffer->idct_2_mc); + mc_views = vl_video_buffer_sampler_views(&buffer->idct_2_mc); if (!mc_views) goto error_mc_views; - if(!vl_mpeg12_mc_init_buffer(&ctx->mc, &buffer->mc_y, mc_views->y)) + if(!vl_mpeg12_mc_init_buffer(&ctx->mc, &buffer->mc[0], (*mc_views)[0])) goto error_mc_y; - if(!vl_mpeg12_mc_init_buffer(&ctx->mc, &buffer->mc_cb, mc_views->cb)) + if(!vl_mpeg12_mc_init_buffer(&ctx->mc, &buffer->mc[1], (*mc_views)[1])) goto error_mc_cb; - if(!vl_mpeg12_mc_init_buffer(&ctx->mc, &buffer->mc_cr, mc_views->cr)) + if(!vl_mpeg12_mc_init_buffer(&ctx->mc, &buffer->mc[2], (*mc_views)[2])) goto error_mc_cr; return &buffer->base; error_mc_cr: - vl_mpeg12_mc_cleanup_buffer(&buffer->mc_cb); + vl_mpeg12_mc_cleanup_buffer(&buffer->mc[1]); error_mc_cb: - vl_mpeg12_mc_cleanup_buffer(&buffer->mc_y); + vl_mpeg12_mc_cleanup_buffer(&buffer->mc[0]); error_mc_y: error_mc_views: - vl_idct_cleanup_buffer(&ctx->idct_c, &buffer->idct_cr); + vl_idct_cleanup_buffer(&ctx->idct_c, &buffer->idct[2]); error_idct_cr: - vl_idct_cleanup_buffer(&ctx->idct_c, &buffer->idct_cb); + vl_idct_cleanup_buffer(&ctx->idct_c, &buffer->idct[1]); error_idct_cb: - vl_idct_cleanup_buffer(&ctx->idct_y, &buffer->idct_y); + vl_idct_cleanup_buffer(&ctx->idct_y, &buffer->idct[0]); error_idct_y: error_idct_surfaces: error_idct_views: - vl_ycbcr_buffer_cleanup(&buffer->render_result); + vl_video_buffer_cleanup(&buffer->render_result); error_render_result: - vl_ycbcr_buffer_cleanup(&buffer->idct_2_mc); + vl_video_buffer_cleanup(&buffer->idct_2_mc); error_idct_2_mc: - vl_ycbcr_buffer_cleanup(&buffer->idct_source); + vl_video_buffer_cleanup(&buffer->idct_source); error_idct_source: vl_vb_cleanup(&buffer->vertex_stream); @@ -692,9 +691,9 @@ vl_create_mpeg12_context(struct pipe_context *pipe, ctx->pot_buffers = pot_buffers; ctx->quads = vl_vb_upload_quads(ctx->pipe, 2, 2); - ctx->ves_y = vl_vb_get_elems_state(ctx->pipe, TGSI_SWIZZLE_X); - ctx->ves_cb = vl_vb_get_elems_state(ctx->pipe, TGSI_SWIZZLE_Y); - ctx->ves_cr = vl_vb_get_elems_state(ctx->pipe, TGSI_SWIZZLE_Z); + ctx->ves[0] = vl_vb_get_elems_state(ctx->pipe, TGSI_SWIZZLE_X); + ctx->ves[1] = vl_vb_get_elems_state(ctx->pipe, TGSI_SWIZZLE_Y); + ctx->ves[2] = vl_vb_get_elems_state(ctx->pipe, TGSI_SWIZZLE_Z); ctx->buffer_width = pot_buffers ? util_next_power_of_two(width) : align(width, MACROBLOCK_WIDTH); ctx->buffer_height = pot_buffers ? util_next_power_of_two(height) : align(height, MACROBLOCK_HEIGHT); diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_context.h b/src/gallium/auxiliary/vl/vl_mpeg12_context.h index 698522f16ea..94a5dad5571 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_context.h +++ b/src/gallium/auxiliary/vl/vl_mpeg12_context.h @@ -32,7 +32,8 @@ #include "vl_idct.h" #include "vl_mpeg12_mc_renderer.h" #include "vl_compositor.h" -#include "vl_ycbcr_buffer.h" +#include "vl_video_buffer.h" +#include "vl_vertex_buffers.h" struct pipe_screen; struct pipe_context; @@ -47,7 +48,7 @@ struct vl_mpeg12_context const unsigned (*empty_block_mask)[3][2][2]; struct pipe_vertex_buffer quads; - void *ves_y, *ves_cb, *ves_cr; + void *ves[VL_MAX_PLANES]; struct vl_idct idct_y, idct_c; struct vl_mpeg12_mc_renderer mc; @@ -61,9 +62,9 @@ struct vl_mpeg12_buffer { struct pipe_video_buffer base; - struct vl_ycbcr_buffer idct_source; - struct vl_ycbcr_buffer idct_2_mc; - struct vl_ycbcr_buffer render_result; + struct vl_video_buffer idct_source; + struct vl_video_buffer idct_2_mc; + struct vl_video_buffer render_result; struct vl_vertex_buffer vertex_stream; @@ -75,8 +76,8 @@ struct vl_mpeg12_buffer } individual; } vertex_bufs; - struct vl_idct_buffer idct_y, idct_cb, idct_cr; - struct vl_mpeg12_mc_buffer mc_y, mc_cb, mc_cr; + struct vl_idct_buffer idct[VL_MAX_PLANES]; + struct vl_mpeg12_mc_buffer mc[VL_MAX_PLANES]; }; /* drivers can call this function in their pipe_video_context constructors and pass it diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.c b/src/gallium/auxiliary/vl/vl_video_buffer.c new file mode 100644 index 00000000000..f0b3d192eb5 --- /dev/null +++ b/src/gallium/auxiliary/vl/vl_video_buffer.c @@ -0,0 +1,190 @@ +/************************************************************************** + * + * Copyright 2011 Christian König. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "vl_video_buffer.h" +#include <util/u_format.h> +#include <util/u_inlines.h> +#include <util/u_sampler.h> +#include <pipe/p_screen.h> +#include <pipe/p_context.h> +#include <assert.h> + +bool vl_video_buffer_init(struct vl_video_buffer *buffer, + struct pipe_context *pipe, + unsigned width, unsigned height, unsigned depth, + enum pipe_video_chroma_format chroma_format, + unsigned num_planes, + const enum pipe_format resource_format[VL_MAX_PLANES], + unsigned usage) +{ + struct pipe_resource templ; + unsigned i; + + assert(buffer && pipe); + assert(num_planes > 0 && num_planes <= VL_MAX_PLANES); + + memset(buffer, 0, sizeof(struct vl_video_buffer)); + buffer->pipe = pipe; + buffer->num_planes = num_planes; + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.format = resource_format[0]; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = depth; + templ.array_size = 1; + templ.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; + templ.usage = usage; + + buffer->resources[0] = pipe->screen->resource_create(pipe->screen, &templ); + if (!buffer->resources[0]) + goto error; + + if (num_planes == 1) { + assert(chroma_format == PIPE_VIDEO_CHROMA_FORMAT_444); + return true; + } + + templ.format = resource_format[1]; + if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420) { + if (depth > 1) + templ.depth0 /= 2; + else + templ.width0 /= 2; + templ.height0 /= 2; + } else if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_422) { + if (depth > 1) + templ.depth0 /= 2; + else + templ.height0 /= 2; + } + + buffer->resources[1] = pipe->screen->resource_create(pipe->screen, &templ); + if (!buffer->resources[1]) + goto error; + + if (num_planes == 2) + return true; + + templ.format = resource_format[2]; + buffer->resources[2] = pipe->screen->resource_create(pipe->screen, &templ); + if (!buffer->resources[2]) + goto error; + + return true; + +error: + for (i = 0; i < VL_MAX_PLANES; ++i) + pipe_resource_reference(&buffer->resources[i], NULL); + + return false; +} + +static inline void +adjust_swizzle(struct pipe_sampler_view *sv_templ) +{ + if (util_format_get_nr_components(sv_templ->format) == 1) { + sv_templ->swizzle_r = PIPE_SWIZZLE_RED; + sv_templ->swizzle_g = PIPE_SWIZZLE_RED; + sv_templ->swizzle_b = PIPE_SWIZZLE_RED; + sv_templ->swizzle_a = PIPE_SWIZZLE_RED; + } +} + +vl_sampler_views *vl_video_buffer_sampler_views(struct vl_video_buffer *buffer) +{ + struct pipe_sampler_view sv_templ; + struct pipe_context *pipe; + unsigned i; + + assert(buffer); + + pipe = buffer->pipe; + + for (i = 0; i < buffer->num_planes; ++i ) { + if (!buffer->sampler_views[i]) { + memset(&sv_templ, 0, sizeof(sv_templ)); + u_sampler_view_default_template(&sv_templ, buffer->resources[i], buffer->resources[i]->format); + adjust_swizzle(&sv_templ); + buffer->sampler_views[i] = pipe->create_sampler_view(pipe, buffer->resources[i], &sv_templ); + if (!buffer->sampler_views[i]) + goto error; + } + } + + return &buffer->sampler_views; + +error: + for (i = 0; i < buffer->num_planes; ++i ) + pipe_sampler_view_reference(&buffer->sampler_views[i], NULL); + + return NULL; +} + +vl_surfaces *vl_video_buffer_surfaces(struct vl_video_buffer *buffer) +{ + struct pipe_surface surf_templ; + struct pipe_context *pipe; + unsigned i; + + assert(buffer); + + pipe = buffer->pipe; + + for (i = 0; i < buffer->num_planes; ++i ) { + if (!buffer->surfaces[i]) { + memset(&surf_templ, 0, sizeof(surf_templ)); + surf_templ.format = buffer->resources[i]->format; + surf_templ.usage = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; + buffer->surfaces[i] = pipe->create_surface(pipe, buffer->resources[i], &surf_templ); + if (!buffer->surfaces[i]) + goto error; + } + } + + return &buffer->surfaces; + +error: + for (i = 0; i < buffer->num_planes; ++i ) + pipe_surface_reference(&buffer->surfaces[i], NULL); + + return NULL; +} + +void vl_video_buffer_cleanup(struct vl_video_buffer *buffer) +{ + unsigned i; + + assert(buffer); + + for (i = 0; i < VL_MAX_PLANES; ++i) { + pipe_surface_reference(&buffer->surfaces[i], NULL); + pipe_sampler_view_reference(&buffer->sampler_views[i], NULL); + pipe_resource_reference(&buffer->resources[i], NULL); + } +} diff --git a/src/gallium/auxiliary/vl/vl_ycbcr_buffer.h b/src/gallium/auxiliary/vl/vl_video_buffer.h index a116ed2a882..adba6c56e88 100644 --- a/src/gallium/auxiliary/vl/vl_ycbcr_buffer.h +++ b/src/gallium/auxiliary/vl/vl_video_buffer.h @@ -30,60 +30,55 @@ #include <pipe/p_state.h> +#define VL_MAX_PLANES 3 + /** * implementation of a planar ycbcr buffer */ /* resources of a buffer */ -struct vl_ycbcr_resources -{ - struct pipe_resource *y, *cb, *cr; -}; +typedef struct pipe_resource *vl_resources[VL_MAX_PLANES]; /* sampler views of a buffer */ -struct vl_ycbcr_sampler_views -{ - struct pipe_sampler_view *y, *cb, *cr; -}; +typedef struct pipe_sampler_view *vl_sampler_views[VL_MAX_PLANES]; /* surfaces of a buffer */ -struct vl_ycbcr_surfaces -{ - struct pipe_surface *y, *cb, *cr; -}; +typedef struct pipe_surface *vl_surfaces[VL_MAX_PLANES]; /* planar buffer for vl data upload and manipulation */ -struct vl_ycbcr_buffer +struct vl_video_buffer { - struct pipe_context *pipe; - struct vl_ycbcr_resources resources; - struct vl_ycbcr_sampler_views sampler_views; - struct vl_ycbcr_surfaces surfaces; + struct pipe_context *pipe; + unsigned num_planes; + vl_resources resources; + vl_sampler_views sampler_views; + vl_surfaces surfaces; }; /** * initialize a buffer, creating its resources */ -bool vl_ycbcr_buffer_init(struct vl_ycbcr_buffer *buffer, +bool vl_video_buffer_init(struct vl_video_buffer *buffer, struct pipe_context *pipe, - unsigned width, unsigned height, + unsigned width, unsigned height, unsigned depth, enum pipe_video_chroma_format chroma_format, - enum pipe_format resource_format, + unsigned num_planes, + const enum pipe_format resource_formats[VL_MAX_PLANES], unsigned usage); /** * create default sampler views for the buffer on demand */ -struct vl_ycbcr_sampler_views *vl_ycbcr_get_sampler_views(struct vl_ycbcr_buffer *buffer); +vl_sampler_views *vl_video_buffer_sampler_views(struct vl_video_buffer *buffer); /** * create default surfaces for the buffer on demand */ -struct vl_ycbcr_surfaces *vl_ycbcr_get_surfaces(struct vl_ycbcr_buffer *buffer); +vl_surfaces *vl_video_buffer_surfaces(struct vl_video_buffer *buffer); /** * cleanup the buffer destroying all its resources */ -void vl_ycbcr_buffer_cleanup(struct vl_ycbcr_buffer *buffer); +void vl_video_buffer_cleanup(struct vl_video_buffer *buffer); #endif diff --git a/src/gallium/auxiliary/vl/vl_ycbcr_buffer.c b/src/gallium/auxiliary/vl/vl_ycbcr_buffer.c deleted file mode 100644 index c67cec69723..00000000000 --- a/src/gallium/auxiliary/vl/vl_ycbcr_buffer.c +++ /dev/null @@ -1,195 +0,0 @@ -/************************************************************************** - * - * Copyright 2011 Christian König. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include "vl_ycbcr_buffer.h" -#include <util/u_format.h> -#include <util/u_inlines.h> -#include <util/u_sampler.h> -#include <pipe/p_screen.h> -#include <pipe/p_context.h> -#include <assert.h> - -bool vl_ycbcr_buffer_init(struct vl_ycbcr_buffer *buffer, - struct pipe_context *pipe, - unsigned width, unsigned height, - enum pipe_video_chroma_format chroma_format, - enum pipe_format resource_format, - unsigned usage) -{ - struct pipe_resource templ; - - assert(buffer && pipe); - - memset(buffer, 0, sizeof(struct vl_ycbcr_buffer)); - buffer->pipe = pipe; - - memset(&templ, 0, sizeof(templ)); - templ.target = PIPE_TEXTURE_2D; - templ.format = resource_format; - templ.width0 = width / util_format_get_nr_components(resource_format); - templ.height0 = height; - templ.depth0 = 1; - templ.array_size = 1; - templ.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; - templ.usage = usage; - - buffer->resources.y = pipe->screen->resource_create(pipe->screen, &templ); - if (!buffer->resources.y) - goto error_resource_y; - - if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420) { - templ.width0 /= 2; - templ.height0 /= 2; - } else if (chroma_format == PIPE_VIDEO_CHROMA_FORMAT_422) { - templ.height0 /= 2; - } - - buffer->resources.cb = pipe->screen->resource_create(pipe->screen, &templ); - if (!buffer->resources.cb) - goto error_resource_cb; - - buffer->resources.cr = pipe->screen->resource_create(pipe->screen, &templ); - if (!buffer->resources.cr) - goto error_resource_cr; - - return true; - -error_resource_cr: - pipe_resource_reference(&buffer->resources.cb, NULL); - -error_resource_cb: - pipe_resource_reference(&buffer->resources.y, NULL); - -error_resource_y: - return false; -} - -struct vl_ycbcr_sampler_views *vl_ycbcr_get_sampler_views(struct vl_ycbcr_buffer *buffer) -{ - struct pipe_sampler_view sv_templ; - struct pipe_context *pipe; - - assert(buffer); - - pipe = buffer->pipe; - - memset(&sv_templ, 0, sizeof(sv_templ)); - u_sampler_view_default_template(&sv_templ, buffer->resources.y, buffer->resources.y->format); - - if (util_format_get_nr_components(buffer->resources.y->format) == 1) { - sv_templ.swizzle_r = PIPE_SWIZZLE_RED; - sv_templ.swizzle_g = PIPE_SWIZZLE_RED; - sv_templ.swizzle_b = PIPE_SWIZZLE_RED; - sv_templ.swizzle_a = PIPE_SWIZZLE_RED; - } - - if (!buffer->sampler_views.y) { - buffer->sampler_views.y = pipe->create_sampler_view(pipe, buffer->resources.y, &sv_templ); - if (!buffer->sampler_views.y) - goto error; - } - - if (!buffer->sampler_views.cb) { - buffer->sampler_views.cb = pipe->create_sampler_view(pipe, buffer->resources.cb, &sv_templ); - if (!buffer->sampler_views.cb) - goto error; - } - - if (!buffer->sampler_views.cr) { - buffer->sampler_views.cr = pipe->create_sampler_view(pipe, buffer->resources.cr, &sv_templ); - if (!buffer->sampler_views.cr) - goto error; - } - - return &buffer->sampler_views; - -error: - pipe_sampler_view_reference(&buffer->sampler_views.y, NULL); - pipe_sampler_view_reference(&buffer->sampler_views.cb, NULL); - pipe_sampler_view_reference(&buffer->sampler_views.cr, NULL); - return NULL; -} - -struct vl_ycbcr_surfaces *vl_ycbcr_get_surfaces(struct vl_ycbcr_buffer *buffer) -{ - struct pipe_surface surf_templ; - struct pipe_context *pipe; - - assert(buffer); - - pipe = buffer->pipe; - - if (!buffer->surfaces.y) { - memset(&surf_templ, 0, sizeof(surf_templ)); - surf_templ.format = buffer->resources.y->format; - surf_templ.usage = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; - buffer->surfaces.y = pipe->create_surface(pipe, buffer->resources.y, &surf_templ); - if (!buffer->surfaces.y) - goto error; - } - - if (!buffer->surfaces.cb) { - memset(&surf_templ, 0, sizeof(surf_templ)); - surf_templ.format = buffer->resources.cb->format; - surf_templ.usage = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; - buffer->surfaces.cb = pipe->create_surface(pipe, buffer->resources.cb, &surf_templ); - if (!buffer->surfaces.cb) - goto error; - } - - if (!buffer->surfaces.cr) { - memset(&surf_templ, 0, sizeof(surf_templ)); - surf_templ.format = buffer->resources.cr->format; - surf_templ.usage = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; - buffer->surfaces.cr = pipe->create_surface(pipe, buffer->resources.cr, &surf_templ); - if (!buffer->surfaces.cr) - goto error; - } - - return &buffer->surfaces; - -error: - pipe_surface_reference(&buffer->surfaces.y, NULL); - pipe_surface_reference(&buffer->surfaces.cb, NULL); - pipe_surface_reference(&buffer->surfaces.cr, NULL); - return NULL; -} - -void vl_ycbcr_buffer_cleanup(struct vl_ycbcr_buffer *buffer) -{ - pipe_surface_reference(&buffer->surfaces.y, NULL); - pipe_surface_reference(&buffer->surfaces.cb, NULL); - pipe_surface_reference(&buffer->surfaces.cr, NULL); - - pipe_sampler_view_reference(&buffer->sampler_views.y, NULL); - pipe_sampler_view_reference(&buffer->sampler_views.cb, NULL); - pipe_sampler_view_reference(&buffer->sampler_views.cr, NULL); - - pipe_resource_reference(&buffer->resources.y, NULL); - pipe_resource_reference(&buffer->resources.cb, NULL); - pipe_resource_reference(&buffer->resources.cr, NULL); -} |