Mesa (master): frontends/va: improve surface attribs processing

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Apr 16 13:39:38 UTC 2021


Module: Mesa
Branch: master
Commit: ebab3109876113f86ed189f26f409529c7abed67
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ebab3109876113f86ed189f26f409529c7abed67

Author: Simon Ser <contact at emersion.fr>
Date:   Thu Apr  8 14:10:55 2021 +0200

frontends/va: improve surface attribs processing

Instead of checking whether the attribute is settable for each
attrib type, check that once at the beginning of the loop.

Instead of having an if for each attrib type, use a switch.

Return an error if we encounter an unknown attribute. This allows
the caller to make sure settable attributes aren't ignored. The
intel media driver seems to just assert [1] that it doesn't encounter
unknown attributes.

[1]: https://github.com/intel/media-driver/blob/95d413e519a980f6a7178880ccbfedace092316c/media_driver/linux/common/ddi/media_libva.cpp#L2530

Signed-off-by: Simon Ser <contact at emersion.fr>
Reviewed-by: Leo Liu <leo.liu at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10104>

---

 src/gallium/frontends/va/surface.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/gallium/frontends/va/surface.c b/src/gallium/frontends/va/surface.c
index 2ceb180884e..d226575dc08 100644
--- a/src/gallium/frontends/va/surface.c
+++ b/src/gallium/frontends/va/surface.c
@@ -708,16 +708,16 @@ vlVaCreateSurfaces2(VADriverContextP ctx, unsigned int format,
    expected_fourcc = 0;
 
    for (i = 0; i < num_attribs && attrib_list; i++) {
-      if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
-          (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
+      if (!(attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE))
+         continue;
+
+      switch (attrib_list[i].type) {
+      case VASurfaceAttribPixelFormat:
          if (attrib_list[i].value.type != VAGenericValueTypeInteger)
             return VA_STATUS_ERROR_INVALID_PARAMETER;
          expected_fourcc = attrib_list[i].value.value.i;
-      }
-
-      if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
-          (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
-
+         break;
+      case VASurfaceAttribMemoryType:
          if (attrib_list[i].value.type != VAGenericValueTypeInteger)
             return VA_STATUS_ERROR_INVALID_PARAMETER;
 
@@ -729,13 +729,14 @@ vlVaCreateSurfaces2(VADriverContextP ctx, unsigned int format,
          default:
             return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
          }
-      }
-
-      if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
-          (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
+         break;
+      case VASurfaceAttribExternalBufferDescriptor:
          if (attrib_list[i].value.type != VAGenericValueTypePointer)
             return VA_STATUS_ERROR_INVALID_PARAMETER;
          memory_attribute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
+         break;
+      default:
+         return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
       }
    }
 



More information about the mesa-commit mailing list