gallium/video: remove pipe_video_buffer.chroma_format

chroma_format depends on buffer_format so use the format_to_chroma_format
helper instead of storing it next to buffer_format.
This avoids bugs where one value is changed without updating the other.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Acked-by: Leo Liu <leo.liu@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3738>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2020-02-05 10:21:20 +01:00
parent 87807298a3
commit 24f2b0a856
23 changed files with 26 additions and 37 deletions

View File

@ -262,7 +262,6 @@ vl_deint_filter_init(struct vl_deint_filter *filter, struct pipe_context *pipe,
PIPE_VIDEO_ENTRYPOINT_UNKNOWN,
PIPE_VIDEO_CAP_PREFERED_FORMAT
);
templ.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420;
templ.width = video_width;
templ.height = video_height;
templ.interlaced = true;
@ -420,7 +419,7 @@ vl_deint_filter_check_buffers(struct vl_deint_filter *filter,
struct pipe_video_buffer *bufs[] = { prevprev, prev, cur, next };
for (i = 0; i < 4; i++) {
if (bufs[i]->chroma_format != PIPE_VIDEO_CHROMA_FORMAT_420)
if (pipe_format_to_chroma_format(bufs[i]->buffer_format) != PIPE_VIDEO_CHROMA_FORMAT_420)
return false;
if (bufs[i]->width < filter->video_width ||
bufs[i]->height < filter->video_height)

View File

@ -982,10 +982,10 @@ init_idct(struct vl_mpeg12_decoder *dec, const struct format_config* format_conf
nr_of_idct_render_targets = 1;
formats[0] = formats[1] = formats[2] = format_config->idct_source_format;
assert(pipe_format_to_chroma_format(formats[0]) == dec->base.chroma_format);
memset(&templat, 0, sizeof(templat));
templat.width = dec->base.width / 4;
templat.height = dec->base.height;
templat.chroma_format = dec->base.chroma_format;
dec->idct_source = vl_video_buffer_create_ex
(
dec->context, &templat,
@ -996,10 +996,10 @@ init_idct(struct vl_mpeg12_decoder *dec, const struct format_config* format_conf
goto error_idct_source;
formats[0] = formats[1] = formats[2] = format_config->mc_source_format;
assert(pipe_format_to_chroma_format(formats[0]) == dec->base.chroma_format);
memset(&templat, 0, sizeof(templat));
templat.width = dec->base.width / nr_of_idct_render_targets;
templat.height = dec->base.height / 4;
templat.chroma_format = dec->base.chroma_format;
dec->mc_source = vl_video_buffer_create_ex
(
dec->context, &templat,
@ -1047,10 +1047,10 @@ init_mc_source_widthout_idct(struct vl_mpeg12_decoder *dec, const struct format_
struct pipe_video_buffer templat;
formats[0] = formats[1] = formats[2] = format_config->mc_source_format;
assert(pipe_format_to_chroma_format(formats[0]) == dec->base.chroma_format);
memset(&templat, 0, sizeof(templat));
templat.width = dec->base.width;
templat.height = dec->base.height;
templat.chroma_format = dec->base.chroma_format;
dec->mc_source = vl_video_buffer_create_ex
(
dec->context, &templat,

View File

@ -188,7 +188,7 @@ vl_video_buffer_template(struct pipe_resource *templ,
templ->usage = usage;
vl_video_buffer_adjust_size(&templ->width0, &height, plane,
tmpl->chroma_format, false);
pipe_format_to_chroma_format(tmpl->buffer_format), false);
templ->height0 = height;
}

View File

@ -782,7 +782,7 @@ nouveau_video_buffer_create(struct pipe_context *pipe,
screen->device->chipset < 0x40)
return vl_video_buffer_create(pipe, templat);
assert(templat->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420);
assert(pipe_format_to_chroma_format(templat->buffer_format) == PIPE_VIDEO_CHROMA_FORMAT_420);
width = align(templat->width, 64);
height = align(templat->height, 64);
@ -795,7 +795,6 @@ nouveau_video_buffer_create(struct pipe_context *pipe,
buffer->base.get_sampler_view_planes = nouveau_video_buffer_sampler_view_planes;
buffer->base.get_sampler_view_components = nouveau_video_buffer_sampler_view_components;
buffer->base.get_surfaces = nouveau_video_buffer_surfaces;
buffer->base.chroma_format = templat->chroma_format;
buffer->base.buffer_format = templat->buffer_format;
buffer->base.width = width;
buffer->base.height = height;

View File

@ -89,7 +89,7 @@ nouveau_vp3_video_buffer_create(struct pipe_context *pipe,
return vl_video_buffer_create(pipe, templat);
assert(templat->interlaced);
assert(templat->chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420);
assert(pipe_format_to_chroma_format(templat->buffer_format) == PIPE_VIDEO_CHROMA_FORMAT_420);
buffer = CALLOC_STRUCT(nouveau_vp3_video_buffer);
if (!buffer)
@ -98,7 +98,6 @@ nouveau_vp3_video_buffer_create(struct pipe_context *pipe,
buffer->base.buffer_format = templat->buffer_format;
buffer->base.context = pipe;
buffer->base.destroy = nouveau_vp3_video_buffer_destroy;
buffer->base.chroma_format = templat->chroma_format;
buffer->base.width = templat->width;
buffer->base.height = templat->height;
buffer->base.get_sampler_view_planes = nouveau_vp3_video_buffer_sampler_view_planes;

View File

@ -619,7 +619,7 @@ nv84_video_buffer_create(struct pipe_context *pipe,
debug_printf("Require interlaced video buffers\n");
return NULL;
}
if (template->chroma_format != PIPE_VIDEO_CHROMA_FORMAT_420) {
if (pipe_format_to_chroma_format(template->buffer_format) != PIPE_VIDEO_CHROMA_FORMAT_420) {
debug_printf("Must use 4:2:0 format\n");
return NULL;
}
@ -638,7 +638,6 @@ nv84_video_buffer_create(struct pipe_context *pipe,
buffer->base.buffer_format = template->buffer_format;
buffer->base.context = pipe;
buffer->base.destroy = nv84_video_buffer_destroy;
buffer->base.chroma_format = template->chroma_format;
buffer->base.width = template->width;
buffer->base.height = template->height;
buffer->base.get_sampler_view_planes = nv84_video_buffer_sampler_view_planes;

View File

@ -438,7 +438,6 @@ struct pipe_video_codec *rvce_create_encoder(struct pipe_context *context,
}
templat.buffer_format = PIPE_FORMAT_NV12;
templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420;
templat.width = enc->base.width;
templat.height = enc->base.height;
templat.interlaced = false;

View File

@ -327,7 +327,6 @@ radeon_uvd_create_encoder(struct pipe_context *context,
enc->si = &si;
templat.buffer_format = PIPE_FORMAT_NV12;
templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420;
templat.width = enc->base.width;
templat.height = enc->base.height;
templat.interlaced = false;

View File

@ -448,7 +448,6 @@ struct pipe_video_codec *si_vce_create_encoder(struct pipe_context *context,
}
templat.buffer_format = PIPE_FORMAT_NV12;
templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420;
templat.width = enc->base.width;
templat.height = enc->base.height;
templat.interlaced = false;

View File

@ -401,7 +401,6 @@ struct pipe_video_codec *radeon_create_encoder(struct pipe_context *context,
enc->si = &si;
templat.buffer_format = PIPE_FORMAT_NV12;
templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420;
templat.width = enc->base.width;
templat.height = enc->base.height;
templat.interlaced = false;

View File

@ -122,7 +122,6 @@ struct pipe_video_buffer
struct pipe_context *context;
enum pipe_format buffer_format;
enum pipe_video_chroma_format chroma_format;
unsigned width;
unsigned height;
bool interlaced;

View File

@ -547,7 +547,6 @@ static OMX_ERRORTYPE vid_enc_SetConfig(OMX_HANDLETYPE handle, OMX_INDEXTYPE idx,
struct pipe_video_buffer templat = {};
templat.buffer_format = PIPE_FORMAT_NV12;
templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420;
templat.width = priv->scale.xWidth;
templat.height = priv->scale.xHeight;
templat.interlaced = false;

View File

@ -52,7 +52,6 @@ void vid_dec_NeedTarget(vid_dec_PrivateType *priv)
if (!priv->target) {
memset(&templat, 0, sizeof(templat));
templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420;
templat.width = priv->codec->width;
templat.height = priv->codec->height;
templat.buffer_format = pscreen->get_video_param(
@ -132,7 +131,9 @@ void vid_dec_FillOutput(vid_dec_PrivateType *priv, struct pipe_video_buffer *buf
if (!views[i]) continue;
width = def->nFrameWidth;
height = def->nFrameHeight;
vl_video_buffer_adjust_size(&width, &height, i, buf->chroma_format, buf->interlaced);
vl_video_buffer_adjust_size(&width, &height, i,
pipe_format_to_chroma_format(buf->buffer_format),
buf->interlaced);
for (j = 0; j < views[i]->texture->array_size; ++j) {
struct pipe_box box = {0, 0, j, width, height, 1};
struct pipe_transfer *transfer;

View File

@ -1096,7 +1096,6 @@ void vid_dec_FrameDecoded_common(vid_dec_PrivateType* priv, OMX_BUFFERHEADERTYPE
port = tiz_krn_get_port(tiz_get_krn(handleOf (priv)), OMX_VID_DEC_AVC_INPUT_PORT_INDEX);
#endif
memset(&templat, 0, sizeof(templat));
templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420;
#if ENABLE_ST_OMX_BELLAGIO
templat.width = port->sPortParam.format.video.nFrameWidth;
templat.height = port->sPortParam.format.video.nFrameHeight;

View File

@ -194,7 +194,6 @@ struct encode_task *enc_NeedTask_common(vid_enc_PrivateType * priv, OMX_VIDEO_PO
return NULL;
templat.buffer_format = PIPE_FORMAT_NV12;
templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420;
templat.width = def->nFrameWidth;
templat.height = def->nFrameHeight;
templat.interlaced = false;

View File

@ -65,7 +65,7 @@ vlVaVideoSurfaceSize(vlVaSurface *p_surf, int component,
*height = p_surf->templat.height;
vl_video_buffer_adjust_size(width, height, component,
p_surf->templat.chroma_format,
pipe_format_to_chroma_format(p_surf->templat.buffer_format),
p_surf->templat.interlaced);
}
@ -453,10 +453,10 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, int x, int y,
unsigned box_y = y & ~1;
if (!views[i]) continue;
vl_video_buffer_adjust_size(&box_w, &box_h, i,
surf->templat.chroma_format,
pipe_format_to_chroma_format(surf->templat.buffer_format),
surf->templat.interlaced);
vl_video_buffer_adjust_size(&box_x, &box_y, i,
surf->templat.chroma_format,
pipe_format_to_chroma_format(surf->templat.buffer_format),
surf->templat.interlaced);
for (j = 0; j < views[i]->texture->array_size; ++j) {
struct pipe_box box = {box_x, box_y, j, box_w, box_h, 1};

View File

@ -97,9 +97,11 @@ static void vlVaGetBox(struct pipe_video_buffer *buf, unsigned idx,
width = region->width;
height = region->height;
vl_video_buffer_adjust_size(&x, &y, plane, buf->chroma_format,
vl_video_buffer_adjust_size(&x, &y, plane,
pipe_format_to_chroma_format(buf->buffer_format),
buf->interlaced);
vl_video_buffer_adjust_size(&width, &height, plane, buf->chroma_format,
vl_video_buffer_adjust_size(&width, &height, plane,
pipe_format_to_chroma_format(buf->buffer_format),
buf->interlaced);
box->x = region->x < 0 ? -x : x;

View File

@ -786,8 +786,6 @@ vlVaCreateSurfaces2(VADriverContextP ctx, unsigned int format,
templat.buffer_format = expected_format;
}
templat.chroma_format = ChromaToPipe(format);
templat.width = width;
templat.height = height;

View File

@ -600,7 +600,8 @@ vlVdpDecoderRender(VdpDecoder decoder,
if (vlsurf->device != vldecoder->device)
return VDP_STATUS_HANDLE_DEVICE_MISMATCH;
if (vlsurf->video_buffer != NULL && vlsurf->video_buffer->chroma_format != dec->chroma_format)
if (vlsurf->video_buffer != NULL &&
pipe_format_to_chroma_format(vlsurf->video_buffer->buffer_format) != dec->chroma_format)
// TODO: Recreate decoder with correct chroma
return VDP_STATUS_INVALID_CHROMA_TYPE;

View File

@ -272,7 +272,7 @@ VdpStatus vlVdpVideoMixerRender(VdpVideoMixer mixer,
if (vmixer->video_width > video_buffer->width ||
vmixer->video_height > video_buffer->height ||
vmixer->chroma_format != video_buffer->chroma_format)
vmixer->chroma_format != pipe_format_to_chroma_format(video_buffer->buffer_format))
return VDP_STATUS_INVALID_SIZE;
if (layer_count > vmixer->max_layers)

View File

@ -465,7 +465,6 @@ vlVdpOutputSurfacePutBitsYCbCr(VdpOutputSurface surface,
mtx_lock(&vlsurface->device->mutex);
memset(&vtmpl, 0, sizeof(vtmpl));
vtmpl.buffer_format = format;
vtmpl.chroma_format = FormatYCBCRToPipeChroma(source_ycbcr_format);
if (destination_rect) {
vtmpl.width = abs(destination_rect->x0-destination_rect->x1);

View File

@ -89,7 +89,7 @@ vlVdpVideoSurfaceCreate(VdpDevice device, VdpChromaType chroma_type,
PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
PIPE_VIDEO_CAP_PREFERED_FORMAT
);
p_surf->templat.chroma_format = ChromaToPipe(chroma_type);
assert(pipe_format_to_chroma_format(p_surf->templat.buffer_format) == ChromaToPipe(chroma_type));
p_surf->templat.width = width;
p_surf->templat.height = height;
p_surf->templat.interlaced = pipe->screen->get_video_param
@ -168,11 +168,11 @@ vlVdpVideoSurfaceGetParameters(VdpVideoSurface surface,
if (p_surf->video_buffer) {
*width = p_surf->video_buffer->width;
*height = p_surf->video_buffer->height;
*chroma_type = PipeToChroma(p_surf->video_buffer->chroma_format);
*chroma_type = PipeToChroma(pipe_format_to_chroma_format(p_surf->video_buffer->buffer_format));
} else {
*width = p_surf->templat.width;
*height = p_surf->templat.height;
*chroma_type = PipeToChroma(p_surf->templat.chroma_format);
*chroma_type = PipeToChroma(pipe_format_to_chroma_format(p_surf->templat.buffer_format));
}
return VDP_STATUS_OK;
@ -186,7 +186,7 @@ vlVdpVideoSurfaceSize(vlVdpSurface *p_surf, int component,
*height = p_surf->templat.height;
vl_video_buffer_adjust_size(width, height, component,
p_surf->templat.chroma_format,
pipe_format_to_chroma_format(p_surf->templat.buffer_format),
p_surf->templat.interlaced);
}

View File

@ -182,7 +182,7 @@ Status XvMCCreateSurface(Display *dpy, XvMCContext *context, XvMCSurface *surfac
context_priv->decoder->entrypoint,
PIPE_VIDEO_CAP_PREFERED_FORMAT
);
tmpl.chroma_format = context_priv->decoder->chroma_format;
assert(pipe_format_to_chroma_format(tmpl.buffer_format) == context_priv->decoder->chroma_format);
tmpl.width = context_priv->decoder->width;
tmpl.height = context_priv->decoder->height;
tmpl.interlaced = pipe->screen->get_video_param