diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.c b/src/gallium/auxiliary/vl/vl_video_buffer.c index e1360beb6ff..2f11c26b73f 100644 --- a/src/gallium/auxiliary/vl/vl_video_buffer.c +++ b/src/gallium/auxiliary/vl/vl_video_buffer.c @@ -291,7 +291,7 @@ vl_video_buffer_sampler_view_components(struct pipe_video_buffer *buffer) struct pipe_context *pipe; enum pipe_format sampler_format[VL_NUM_COMPONENTS]; const unsigned *plane_order; - unsigned i, j, component; + unsigned i, j, component, num_planes; assert(buf); @@ -299,8 +299,9 @@ vl_video_buffer_sampler_view_components(struct pipe_video_buffer *buffer) vl_get_video_buffer_formats(pipe->screen, buf->base.buffer_format, sampler_format); plane_order = vl_video_buffer_plane_order(buf->base.buffer_format); + num_planes = util_format_get_num_planes(buf->base.buffer_format); - for (component = 0, i = 0; i < buf->num_planes; ++i ) { + for (component = 0, i = 0; i < num_planes; ++i) { struct pipe_resource *res = buf->resources[plane_order[i]]; const struct util_format_description *desc = util_format_description(res->format); unsigned nr_components = util_format_get_nr_components(res->format); @@ -478,12 +479,14 @@ vl_video_buffer_create_ex2(struct pipe_context *pipe, struct pipe_resource *resources[VL_NUM_COMPONENTS]) { struct vl_video_buffer *buffer; - unsigned i; + unsigned i, num_planes; buffer = CALLOC_STRUCT(vl_video_buffer); if (!buffer) return NULL; + num_planes = util_format_get_num_planes(tmpl->buffer_format); + buffer->base = *tmpl; buffer->base.context = pipe; buffer->base.destroy = vl_video_buffer_destroy; @@ -491,12 +494,14 @@ vl_video_buffer_create_ex2(struct pipe_context *pipe, buffer->base.get_sampler_view_planes = vl_video_buffer_sampler_view_planes; buffer->base.get_sampler_view_components = vl_video_buffer_sampler_view_components; buffer->base.get_surfaces = vl_video_buffer_surfaces; - buffer->num_planes = 0; - for (i = 0; i < VL_NUM_COMPONENTS; ++i) { + for (i = 0; i < num_planes; ++i) buffer->resources[i] = resources[i]; - if (resources[i]) - buffer->num_planes++; + + /* Ignore auxiliary planes. */ + for (; i < VL_NUM_COMPONENTS; ++i) { + struct pipe_resource *res = resources[i]; + pipe_resource_reference(&res, NULL); } return &buffer->base; diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.h b/src/gallium/auxiliary/vl/vl_video_buffer.h index 8363bc678ed..67b6424b1ac 100644 --- a/src/gallium/auxiliary/vl/vl_video_buffer.h +++ b/src/gallium/auxiliary/vl/vl_video_buffer.h @@ -41,7 +41,6 @@ struct vl_video_buffer { struct pipe_video_buffer base; - unsigned num_planes; struct pipe_resource *resources[VL_NUM_COMPONENTS]; struct pipe_sampler_view *sampler_view_planes[VL_NUM_COMPONENTS]; struct pipe_sampler_view *sampler_view_components[VL_NUM_COMPONENTS];