vl: use u_format in vl_video_buffer_formats
authorMarek Olšák <marek.olsak@amd.com>
Thu, 19 Sep 2019 00:48:15 +0000 (20:48 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 9 Oct 2019 21:06:54 +0000 (17:06 -0400)
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/gallium/auxiliary/vl/vl_stubs.c
src/gallium/auxiliary/vl/vl_video_buffer.c
src/gallium/auxiliary/vl/vl_video_buffer.h
src/gallium/drivers/r600/r600_uvd.c
src/gallium/drivers/radeonsi/si_uvd.c
src/gallium/state_trackers/va/surface.c

index d3fce669e5515e81f9c4ac16e302753d5a4c608a..befd2468f49e6c3f2385c8a1bc4281081778fc59 100644 (file)
@@ -39,11 +39,11 @@ vl_create_decoder(struct pipe_context *pipe,
 /*
  * vl_video_buffer stubs
  */
-const enum pipe_format *
-vl_video_buffer_formats(struct pipe_screen *screen, enum pipe_format format)
+void
+vl_get_video_buffer_formats(struct pipe_screen *screen, enum pipe_format format,
+                            enum pipe_format out_format[VL_NUM_COMPONENTS])
 {
    assert(0);
-   return NULL;
 }
 
 bool
index 0c6bf5e129157b16cf4dc0bf1811f82f3ca90e42..b1769ee4f051ad0942248d4e0fba519ab4de1bff 100644 (file)
 
 #include "vl_video_buffer.h"
 
-const enum pipe_format const_resource_formats_YV12[3] = {
-   PIPE_FORMAT_R8_UNORM,
-   PIPE_FORMAT_R8_UNORM,
-   PIPE_FORMAT_R8_UNORM
-};
-
-const enum pipe_format const_resource_formats_NV12[3] = {
-   PIPE_FORMAT_R8_UNORM,
-   PIPE_FORMAT_R8G8_UNORM,
-   PIPE_FORMAT_NONE
-};
-
-const enum pipe_format const_resource_formats_YUVA[3] = {
-   PIPE_FORMAT_R8G8B8A8_UNORM,
-   PIPE_FORMAT_NONE,
-   PIPE_FORMAT_NONE
-};
-
-const enum pipe_format const_resource_formats_VUYA[3] = {
-   PIPE_FORMAT_B8G8R8A8_UNORM,
-   PIPE_FORMAT_NONE,
-   PIPE_FORMAT_NONE
-};
-
-const enum pipe_format const_resource_formats_YUVX[3] = {
-   PIPE_FORMAT_R8G8B8X8_UNORM,
-   PIPE_FORMAT_NONE,
-   PIPE_FORMAT_NONE
-};
-
-const enum pipe_format const_resource_formats_VUYX[3] = {
-   PIPE_FORMAT_B8G8R8X8_UNORM,
-   PIPE_FORMAT_NONE,
-   PIPE_FORMAT_NONE
-};
-
-const enum pipe_format const_resource_formats_YUYV[3] = {
-   PIPE_FORMAT_R8G8_R8B8_UNORM,
-   PIPE_FORMAT_NONE,
-   PIPE_FORMAT_NONE
-};
-
-const enum pipe_format const_resource_formats_UYVY[3] = {
-   PIPE_FORMAT_G8R8_B8R8_UNORM,
-   PIPE_FORMAT_NONE,
-   PIPE_FORMAT_NONE
-};
-
-const enum pipe_format const_resource_formats_P016[3] = {
-   PIPE_FORMAT_R16_UNORM,
-   PIPE_FORMAT_R16G16_UNORM,
-   PIPE_FORMAT_NONE
-};
-
 const unsigned const_resource_plane_order_YUV[3] = {
    0,
    1,
@@ -104,40 +50,22 @@ const unsigned const_resource_plane_order_YVU[3] = {
    1
 };
 
-const enum pipe_format *
-vl_video_buffer_formats(struct pipe_screen *screen, enum pipe_format format)
+void
+vl_get_video_buffer_formats(struct pipe_screen *screen, enum pipe_format format,
+                            enum pipe_format out_format[VL_NUM_COMPONENTS])
 {
-   switch(format) {
-   case PIPE_FORMAT_YV12:
-      return const_resource_formats_YV12;
-
-   case PIPE_FORMAT_NV12:
-      return const_resource_formats_NV12;
-
-   case PIPE_FORMAT_R8G8B8A8_UNORM:
-      return const_resource_formats_YUVA;
-
-   case PIPE_FORMAT_B8G8R8A8_UNORM:
-      return const_resource_formats_VUYA;
-
-   case PIPE_FORMAT_R8G8B8X8_UNORM:
-      return const_resource_formats_YUVX;
-
-   case PIPE_FORMAT_B8G8R8X8_UNORM:
-      return const_resource_formats_VUYX;
-
-   case PIPE_FORMAT_YUYV:
-      return const_resource_formats_YUYV;
-
-   case PIPE_FORMAT_UYVY:
-      return const_resource_formats_UYVY;
+   unsigned num_planes = util_format_get_num_planes(format);
+   unsigned i;
 
-   case PIPE_FORMAT_P016:
-      return const_resource_formats_P016;
+   for (i = 0; i < num_planes; i++)
+      out_format[i] = util_format_get_plane_format(format, i);
+   for (; i < VL_NUM_COMPONENTS; i++)
+      out_format[i] = PIPE_FORMAT_NONE;
 
-   default:
-      return NULL;
-   }
+   if (format == PIPE_FORMAT_YUYV)
+      out_format[0] = PIPE_FORMAT_R8G8_R8B8_UNORM;
+   else if (format == PIPE_FORMAT_UYVY)
+      out_format[0] = PIPE_FORMAT_G8R8_B8R8_UNORM;
 }
 
 const unsigned *
@@ -178,12 +106,10 @@ vl_video_buffer_is_format_supported(struct pipe_screen *screen,
                                     enum pipe_video_profile profile,
                                     enum pipe_video_entrypoint entrypoint)
 {
-   const enum pipe_format *resource_formats;
+   enum pipe_format resource_formats[VL_NUM_COMPONENTS];
    unsigned i;
 
-   resource_formats = vl_video_buffer_formats(screen, format);
-   if (!resource_formats)
-      return false;
+   vl_get_video_buffer_formats(screen, format, resource_formats);
 
    for (i = 0; i < VL_NUM_COMPONENTS; ++i) {
       enum pipe_format format = resource_formats[i];
@@ -328,7 +254,7 @@ vl_video_buffer_sampler_view_components(struct pipe_video_buffer *buffer)
    struct vl_video_buffer *buf = (struct vl_video_buffer *)buffer;
    struct pipe_sampler_view sv_templ;
    struct pipe_context *pipe;
-   const enum pipe_format *sampler_format;
+   enum pipe_format sampler_format[VL_NUM_COMPONENTS];
    const unsigned *plane_order;
    unsigned i, j, component;
 
@@ -336,7 +262,7 @@ vl_video_buffer_sampler_view_components(struct pipe_video_buffer *buffer)
 
    pipe = buf->base.context;
 
-   sampler_format = vl_video_buffer_formats(pipe->screen, buf->base.buffer_format);
+   vl_get_video_buffer_formats(pipe->screen, buf->base.buffer_format, sampler_format);
    plane_order = vl_video_buffer_plane_order(buf->base.buffer_format);
 
    for (component = 0, i = 0; i < buf->num_planes; ++i ) {
@@ -416,7 +342,7 @@ struct pipe_video_buffer *
 vl_video_buffer_create(struct pipe_context *pipe,
                        const struct pipe_video_buffer *tmpl)
 {
-   const enum pipe_format *resource_formats;
+   enum pipe_format resource_formats[VL_NUM_COMPONENTS];
    struct pipe_video_buffer templat, *result;
    bool pot_buffers;
 
@@ -431,9 +357,7 @@ vl_video_buffer_create(struct pipe_context *pipe,
       PIPE_VIDEO_CAP_NPOT_TEXTURES
    );
 
-   resource_formats = vl_video_buffer_formats(pipe->screen, tmpl->buffer_format);
-   if (!resource_formats)
-      return NULL;
+   vl_get_video_buffer_formats(pipe->screen, tmpl->buffer_format, resource_formats);
 
    templat = *tmpl;
    templat.width = pot_buffers ? util_next_power_of_two(tmpl->width)
index 5f21ab2650fa8a85c5748ff3883dbe17986adfd1..ae98341ae25bc268d2162d5c8d7f21ed4cadd2ec 100644 (file)
@@ -69,8 +69,9 @@ vl_video_buffer_adjust_size(unsigned *width, unsigned *height, unsigned plane,
 /**
  * get subformats for each plane
  */
-const enum pipe_format *
-vl_video_buffer_formats(struct pipe_screen *screen, enum pipe_format format);
+void
+vl_get_video_buffer_formats(struct pipe_screen *screen, enum pipe_format format,
+                            enum pipe_format out_format[VL_NUM_COMPONENTS]);
 
 /**
  * get YUV plane order
index ca4248aed6902fef56f2716e004067dbc8bfb8b3..2e7d7ee4d40419407f43e644c32a83568d36ec4b 100644 (file)
@@ -62,7 +62,7 @@ struct pipe_video_buffer *r600_video_buffer_create(struct pipe_context *pipe,
        struct r600_texture *resources[VL_NUM_COMPONENTS] = {};
        struct radeon_surf* surfaces[VL_NUM_COMPONENTS] = {};
        struct pb_buffer **pbs[VL_NUM_COMPONENTS] = {};
-       const enum pipe_format *resource_formats;
+       enum pipe_format resource_formats[3];
        struct pipe_video_buffer template;
        struct pipe_resource templ;
        unsigned i, array_size;
@@ -70,9 +70,7 @@ struct pipe_video_buffer *r600_video_buffer_create(struct pipe_context *pipe,
        assert(pipe);
 
        /* first create the needed resources as "normal" textures */
-       resource_formats = vl_video_buffer_formats(pipe->screen, tmpl->buffer_format);
-       if (!resource_formats)
-               return NULL;
+       vl_get_video_buffer_formats(pipe->screen, tmpl->buffer_format, resource_formats);
 
        array_size = tmpl->interlaced ? 2 : 1;
        template = *tmpl;
index 19d1b09f1c1dd96495c8a569283364a3828301a6..1469b6ac7f13a58ce12d2b1e954e7dabe32d0164 100644 (file)
@@ -44,7 +44,7 @@ struct pipe_video_buffer *si_video_buffer_create(struct pipe_context *pipe,
        struct si_texture *resources[VL_NUM_COMPONENTS] = {};
        struct radeon_surf *surfaces[VL_NUM_COMPONENTS] = {};
        struct pb_buffer **pbs[VL_NUM_COMPONENTS] = {};
-       const enum pipe_format *resource_formats;
+       enum pipe_format resource_formats[VL_NUM_COMPONENTS];
        struct pipe_video_buffer vidtemplate;
        struct pipe_resource templ;
        unsigned i, array_size;
@@ -52,9 +52,7 @@ struct pipe_video_buffer *si_video_buffer_create(struct pipe_context *pipe,
        assert(pipe);
 
        /* first create the needed resources as "normal" textures */
-       resource_formats = vl_video_buffer_formats(pipe->screen, tmpl->buffer_format);
-       if (!resource_formats)
-               return NULL;
+       vl_get_video_buffer_formats(pipe->screen, tmpl->buffer_format, resource_formats);
 
        array_size = tmpl->interlaced ? 2 : 1;
        vidtemplate = *tmpl;
index 86daf0f7988ecd8e69fea4decb354435215ec594..391eab65e69c806e8a76382686b9bfe4f7914e7c 100644 (file)
@@ -565,7 +565,7 @@ surface_from_external_memory(VADriverContextP ctx, vlVaSurface *surface,
    struct pipe_resource res_templ;
    struct winsys_handle whandle;
    struct pipe_resource *resources[VL_NUM_COMPONENTS];
-   const enum pipe_format *resource_formats = NULL;
+   enum pipe_format resource_formats[VL_NUM_COMPONENTS];
    VAStatus result;
    int i;
 
@@ -584,9 +584,7 @@ surface_from_external_memory(VADriverContextP ctx, vlVaSurface *surface,
    if (memory_attribute->num_planes > VL_NUM_COMPONENTS)
       return VA_STATUS_ERROR_INVALID_PARAMETER;
 
-   resource_formats = vl_video_buffer_formats(pscreen, templat->buffer_format);
-   if (!resource_formats)
-      return VA_STATUS_ERROR_INVALID_PARAMETER;
+   vl_get_video_buffer_formats(pscreen, templat->buffer_format, resource_formats);
 
    memset(&res_templ, 0, sizeof(res_templ));
    res_templ.target = PIPE_TEXTURE_2D;