Need support to add NV12 format in mesa code

"Gurpreet Kaur (QUIC)" <[email protected]>
Newsgroups gmane.comp.video.mesa3d.devel
Message-ID <BYAPR02MB5381090ED6F649F458BCF38D985BA@BYAPR02MB5381.namprd02.prod.outlook.com>
Hi All,

While trying to add support of GBM_FORMAT_NV12 format in mesa GBM, we are facing some issues to modify u_format.csv file.

Progress till now:
Initially we have faced gbm_dri_bo_create API failure because gbm_format_to_dri_format API was returning 0. Since gbm_dri_visual_table does not have mapping for GBM_FORMAT_NV12. So, this has been resolved by adding mapping for GBM_FORMAT_NV12 as:
diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 560b97f2b70..67e23d5b368 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -605,6 +605,9 @@ static const struct gbm_dri_visual gbm_dri_visuals_table[] = {
      { 16, 16, 16, 16 },
      true,
    },
+   {
+      GBM_FORMAT_NV12, __DRI_IMAGE_FORMAT_NV12,
+   },
};

After that it required additional changes, as loader_dri_create_image was not successful which eventually is calling dri2_create_image_common. Based on format, we are getting dri_format_mapping and mapping for __DRI_IMAGE_FORMAT_NV12 was missing. So, resolved this by adding below changes:

diff --git a/src/gallium/frontends/dri/dri_helpers.c b/src/gallium/frontends/dri/dri_helpers.c
index 215fb4e4e3a..6ae1fc85d12 100644
--- a/src/gallium/frontends/dri/dri_helpers.c
+++ b/src/gallium/frontends/dri/dri_helpers.c
@@ -484,6 +484,11 @@ static const struct dri2_format_mapping dri2_format_table[] = {
         __DRI_IMAGE_COMPONENTS_RG,        PIPE_FORMAT_RG1616_UNORM, 1,
         { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR1616 } } },
+      { DRM_FORMAT_NV12,          __DRI_IMAGE_FORMAT_NV12,
+        __DRI_IMAGE_COMPONENTS_Y_UV,      PIPE_FORMAT_NV12, 2,
+        { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8 },
+          { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88 } } },

Then in kms_sw_displaytarget_create API, DRM_IOCTL_MODE_CREATE_DUMB was getting failed with return value as -1. As util_format_get_blocksizebits was returning bpp value as zero which is incorrect for NV12 format. When we manually pass bpp value as 8, then we can see gbm_bo_create API is successful.



diff --git a/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
index c91f7e2ca9a..6a649e9c173 100644
--- a/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
+++ b/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
@@ -181,25 +181,33 @@ kms_sw_displaytarget_create(struct sw_winsys *ws,
    kms_sw_dt->ro_mapped = MAP_FAILED;
    kms_sw_dt->format = format;
    memset(&create_req, 0, sizeof(create_req));
    create_req.bpp = util_format_get_blocksizebits(format);
+   if(format == 213)
+      create_req.bpp = 8;

Next Challenge:
Next challenge for us is to get correct bpp value which is 8. As format description is coming from u_format.csv file. We have tried to modify u_format.csv file for PIPE_FORMAT_NV12 row by adding number of bits in a cell,  but that does not seem to be working. We need help for the same how to modify u_format.csv as it is getting generated at compile time.
Please provide your valuable feedback how we can add bpp value in u_format.csv.

Thanks,
Gurpreet
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.