gallium/video: remove pipe_video_buffer.chroma_format
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Wed, 5 Feb 2020 09:21:20 +0000 (10:21 +0100)
committerPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Thu, 27 Feb 2020 09:01:31 +0000 (10:01 +0100)
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>

23 files changed:
src/gallium/auxiliary/vl/vl_deint_filter.c
src/gallium/auxiliary/vl/vl_mpeg12_decoder.c
src/gallium/auxiliary/vl/vl_video_buffer.c
src/gallium/drivers/nouveau/nouveau_video.c
src/gallium/drivers/nouveau/nouveau_vp3_video.c
src/gallium/drivers/nouveau/nv50/nv84_video.c
src/gallium/drivers/r600/radeon_vce.c
src/gallium/drivers/radeon/radeon_uvd_enc.c
src/gallium/drivers/radeon/radeon_vce.c
src/gallium/drivers/radeon/radeon_vcn_enc.c
src/gallium/include/pipe/p_video_codec.h
src/gallium/state_trackers/omx/bellagio/vid_enc.c
src/gallium/state_trackers/omx/vid_dec_common.c
src/gallium/state_trackers/omx/vid_dec_h264_common.c
src/gallium/state_trackers/omx/vid_enc_common.c
src/gallium/state_trackers/va/image.c
src/gallium/state_trackers/va/postproc.c
src/gallium/state_trackers/va/surface.c
src/gallium/state_trackers/vdpau/decode.c
src/gallium/state_trackers/vdpau/mixer.c
src/gallium/state_trackers/vdpau/output.c
src/gallium/state_trackers/vdpau/surface.c
src/gallium/state_trackers/xvmc/surface.c

index ab64cebf806d92d1bfe0cd35cb4600072d5411b1..1b8dad59a1f96af339feb847c6b616761fcb4e9c 100644 (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)
index b7ef70f6ced62bb953917cae701ee046833f47bc..8a04158145a6a86f6b1d6bc7cbee8500fc4cd9a7 100644 (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,
index bcb19fdad2a29f0f2306a223f9ac1eebe8b5d9c3..f4fac6ca0bc7b1a4364babd0df794747214c707b 100644 (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;
 }
 
index 9394a6537695fc725c11e63165c0a4f523d4cc5f..5c94686625fe904aa353dab13078e123015738e5 100644 (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;
index 7c5ae25736da145306e0b78d12ded523d57f8a49..b28d31e0079d536387df0b16b10c30b5bd34e48d 100644 (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;
index 927f7a29f8e7cb4eba0b35334e158e5bbb979a02..0b5ebd48cc992205baa3328ee41d27b39632a60b 100644 (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;
index 16f48c694567c8404d44fbd46a18f3906faf0528..cd7cdb24b8979ecc2edededd8c4e3bb6e141c46f 100644 (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;
index 639e5043543218dfbee4a2ce854b1ffa3ce0a804..b2b742aab9b686c79ecc7820343902de48ee9062 100644 (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;
index 521dfb40a67bb7cb5d9f44652d058fae0a892753..66b4744a558d31e8f1df1d9fa917d71762f4acb5 100644 (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;
index 9cabbd4678e24357bacabec528f684c7108c174f..3225e9f8747548ae79ce1de132a8c9057924dbee 100644 (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;
index ab8b4fcb6057a32ab20b93451f01e2f44940717c..38255048d94380b3a555a93c1c88f8d13bcb9ee9 100644 (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;
index 8153103e97b2f993261cbd2d2796cb82872dc6de..7f4a673d3cd43603ac3e938bc62d74cbe81e0225 100644 (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;
index 21952513de1addfaa77291209993f6581eef4b08..5ca544f8386413919cd415930fe9fb00ef5ee275 100644 (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;
index 388852ba542e77ebf026a1844408678990fc5d84..4190251c90d3447b74b527edffd89d2042f6d225 100644 (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;
index c15c3516973e4631b0c4f3a8a7f8dbd34ca2cdf1..1cc0c130e5dc3e514069cb0589a86ff417a4d9ba 100644 (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;
index b0e32da3e8ba8b601988c6d10786930b7d290f72..89dd5baab075497a5c83db87eeffdf3b0f631d9c 100644 (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};
index 661e3bf941471139cc255f079dc210ef2f55085b..83293c8343fd40d6c014644a4b91b68b0651ded2 100644 (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;
index 47c6f9b06c90774647367a41d558623ae816cbc7..495a68b492cbc61d836b0c8839114a6ec1a321a1 100644 (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;
 
index 48dfb0e000370c85876744b0b8ac5b10c0a34c49..8d3c58714a86bffeceabe1d7dcbdad7c2ebcb6ac 100644 (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;
 
index a50232bfac3592aac9652a273472fc118d23e2e0..2e2bd20ef395d56781049c0154a99df81329b90f 100644 (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)
index cb0e2ffa57cf86e90c02ceb8afb2a19d7ef27d5c..ac8fc550bc746a9db1a496771a08f0bf48f49af9 100644 (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);
index e9d55a282e218ecd6ef8e1ea0fcd4e640b7539e3..1f1b0b3ef683b7c61ea2fd5c1025f669049bc0bf 100644 (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);
 }
 
index c450a2737673b04fe34a42a898a9d89008e09b20..03ee59482c69ed4bbc152836a7901cf66e2d0460 100644 (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