From f23b45dce3888112b7d26a623ab1280ce86533a1 Mon Sep 17 00:00:00 2001 From: "Xiong, James" Date: Thu, 5 Apr 2018 11:58:14 -0700 Subject: i965: return the fourcc saved in __DRIimage when possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When creating a image from a texture, the image's dri_format is set to the first plane's format, and used to look up for the fourcc. e.g. for FOURCC_NV12 texture, the dri_format is set to __DRI_IMAGE_FORMAT_R8, we end up with a wrong entry in function intel_lookup_fourcc(): { __DRI_IMAGE_FOURCC_R8, __DRI_IMAGE_COMPONENTS_R, 1, { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, } }, instead of the correct one: { __DRI_IMAGE_FOURCC_NV12, __DRI_IMAGE_COMPONENTS_Y_UV, 2, { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88, 2 } } }, as a result, a wrong fourcc __DRI_IMAGE_FOURCC_R8 was returned. To fix this bug, the image inherits the texture's planar_format that has the original fourcc; Upon querying, if planar_format is set, return the saved fourcc; Otherwise fall back to the old way. v3: add a bug description and "cc mesa-stable" tag (Jason) remove redundant null pointer check (Tapani) squash 2 patches into one (James) v2: fall back to intel_lookup_fourcc() when planar_format is NULL (Dongwon & Matt Roper) Cc: mesa-stable@lists.freedesktop.org Signed-off-by: Xiong, James Reviewed-by: Tapani Pälli --- src/mesa/drivers/dri/i965/intel_screen.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c index dcb98dab03a..29cb7ad57d7 100644 --- a/src/mesa/drivers/dri/i965/intel_screen.c +++ b/src/mesa/drivers/dri/i965/intel_screen.c @@ -388,10 +388,16 @@ intel_image_format_lookup(int fourcc) return NULL; } -static boolean intel_lookup_fourcc(int dri_format, int *fourcc) +static boolean +intel_image_get_fourcc(__DRIimage *image, int *fourcc) { + if (image->planar_format) { + *fourcc = image->planar_format->fourcc; + return true; + } + for (unsigned i = 0; i < ARRAY_SIZE(intel_image_formats); i++) { - if (intel_image_formats[i].planes[0].dri_format == dri_format) { + if (intel_image_formats[i].planes[0].dri_format == image->dri_format) { *fourcc = intel_image_formats[i].fourcc; return true; } @@ -578,6 +584,7 @@ intel_create_image_from_texture(__DRIcontext *context, int target, intel_setup_image_from_mipmap_tree(brw, image, iobj->mt, level, zoffset); image->dri_format = driGLFormatToImageFormat(image->format); image->has_depthstencil = iobj->mt->stencil_mt? true : false; + image->planar_format = iobj->planar_format; if (image->dri_format == MESA_FORMAT_NONE) { *error = __DRI_IMAGE_ERROR_BAD_PARAMETER; free(image); @@ -869,7 +876,7 @@ intel_query_image(__DRIimage *image, int attrib, int *value) case __DRI_IMAGE_ATTRIB_FD: return !brw_bo_gem_export_to_prime(image->bo, value); case __DRI_IMAGE_ATTRIB_FOURCC: - return intel_lookup_fourcc(image->dri_format, value); + return intel_image_get_fourcc(image, value); case __DRI_IMAGE_ATTRIB_NUM_PLANES: if (isl_drm_modifier_has_aux(image->modifier)) { assert(!image->planar_format || image->planar_format->nplanes == 1); -- cgit v1.2.3