Sophie

Sophie

distrib > Mageia > 9 > armv7hl > by-pkgid > 6a12de61d013b5a1cf6f02cf41fe8e6b > files > 1

mesa-24.0.5-1.mga9.src.rpm

From d875717c7d7d566fa454f14b5bd8c28a354cdfd8 Mon Sep 17 00:00:00 2001
From: Hannes Mann <hannesmann2000@gmail.com>
Date: Mon, 20 Nov 2023 23:16:50 +0100
Subject: [PATCH 1/2] gallium/pipe: Add contiguous planes per-surface attribute

Attribute is set when textures are created by compatible drivers, but
not when importing from DMA-BUF.
---
 src/gallium/auxiliary/vl/vl_video_buffer.c       | 1 +
 src/gallium/drivers/d3d12/d3d12_video_buffer.cpp | 1 +
 src/gallium/drivers/r600/r600_uvd.c              | 1 +
 src/gallium/frontends/va/image.c                 | 5 +++--
 src/gallium/include/pipe/p_video_codec.h         | 1 +
 5 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/gallium/auxiliary/vl/vl_video_buffer.c b/src/gallium/auxiliary/vl/vl_video_buffer.c
index 69cc4563df726..c39717f2b4e77 100644
--- a/src/gallium/auxiliary/vl/vl_video_buffer.c
+++ b/src/gallium/auxiliary/vl/vl_video_buffer.c
@@ -535,5 +535,6 @@ vl_video_buffer_create_as_resource(struct pipe_context *pipe,
    struct pipe_video_buffer vidtemplate = *tmpl;
    vidtemplate.width = templ.width0;
    vidtemplate.height = templ.height0 * array_size;
+   vidtemplate.contiguous_planes = true;
    return vl_video_buffer_create_ex2(pipe, &vidtemplate, resources);
 }
diff --git a/src/gallium/drivers/d3d12/d3d12_video_buffer.cpp b/src/gallium/drivers/d3d12/d3d12_video_buffer.cpp
index f1e08ecc8d437..8f656a335369b 100644
--- a/src/gallium/drivers/d3d12/d3d12_video_buffer.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_video_buffer.cpp
@@ -59,6 +59,7 @@
    pD3D12VideoBuffer->base.width         = tmpl->width;
    pD3D12VideoBuffer->base.height        = tmpl->height;
    pD3D12VideoBuffer->base.interlaced    = tmpl->interlaced;
+   pD3D12VideoBuffer->base.contiguous_planes = true;
    pD3D12VideoBuffer->base.associated_data = nullptr;
    pD3D12VideoBuffer->base.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET | PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_CUSTOM;
 
diff --git a/src/gallium/drivers/r600/r600_uvd.c b/src/gallium/drivers/r600/r600_uvd.c
index 6f893bdb339db..57a74156ba681 100644
--- a/src/gallium/drivers/r600/r600_uvd.c
+++ b/src/gallium/drivers/r600/r600_uvd.c
@@ -78,6 +78,7 @@ struct pipe_video_buffer *r600_video_buffer_create(struct pipe_context *pipe,
 	template = *tmpl;
 	template.width = align(tmpl->width, VL_MACROBLOCK_WIDTH);
 	template.height = align(tmpl->height / array_size, VL_MACROBLOCK_HEIGHT);
+	template.contiguous_planes = true;
 
 	vl_video_buffer_template(&templ, &template, resource_formats[0], 1, array_size,
 									 PIPE_USAGE_DEFAULT, 0, chroma_format);
diff --git a/src/gallium/frontends/va/image.c b/src/gallium/frontends/va/image.c
index f6f177bfe0da4..b0da783b9ab2e 100644
--- a/src/gallium/frontends/va/image.c
+++ b/src/gallium/frontends/va/image.c
@@ -277,9 +277,10 @@ vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image)
                                    PIPE_VIDEO_CAP_SUPPORTS_PROGRESSIVE))
          return VA_STATUS_ERROR_OPERATION_FAILED;
    } else if (util_format_get_num_planes(surf->buffer->buffer_format) >= 2 &&
-              !screen->get_video_param(screen, PIPE_VIDEO_PROFILE_UNKNOWN,
+              (!screen->get_video_param(screen, PIPE_VIDEO_PROFILE_UNKNOWN,
                                        PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
-                                       PIPE_VIDEO_CAP_SUPPORTS_CONTIGUOUS_PLANES_MAP)) {
+                                       PIPE_VIDEO_CAP_SUPPORTS_CONTIGUOUS_PLANES_MAP) ||
+               !surf->buffer->contiguous_planes)) {
       return VA_STATUS_ERROR_OPERATION_FAILED;
    }
 
diff --git a/src/gallium/include/pipe/p_video_codec.h b/src/gallium/include/pipe/p_video_codec.h
index c94c699e29855..5facab197e506 100644
--- a/src/gallium/include/pipe/p_video_codec.h
+++ b/src/gallium/include/pipe/p_video_codec.h
@@ -212,6 +212,7 @@ struct pipe_video_buffer
    unsigned height;
    bool interlaced;
    unsigned bind;
+   bool contiguous_planes;
 
    /**
     * destroy this video buffer
-- 
GitLab


From fc8fef70380a00eea70372af7e618a38ff2b2622 Mon Sep 17 00:00:00 2001
From: Hannes Mann <hannesmann2000@gmail.com>
Date: Mon, 20 Nov 2023 23:17:31 +0100
Subject: [PATCH 2/2] frontends/va: Only export one handle for contiguous
 planes

If the driver stores all planes contiguously in memory, only one BO
needs to be exported from vaExportSurfaceHandle. This is required
for Chromium's VaapiVideoDecoder to work on radeonsi and r600.
---
 src/gallium/frontends/va/surface.c | 64 +++++++++++++++++++-----------
 1 file changed, 41 insertions(+), 23 deletions(-)

diff --git a/src/gallium/frontends/va/surface.c b/src/gallium/frontends/va/surface.c
index 0f92246c2f6e2..072314ee2b970 100644
--- a/src/gallium/frontends/va/surface.c
+++ b/src/gallium/frontends/va/surface.c
@@ -1633,8 +1633,11 @@ vlVaExportSurfaceHandle(VADriverContextP ctx,
 #else
    VADRMPRIMESurfaceDescriptor *desc = descriptor;
    desc->fourcc = PipeFormatToVaFourcc(surf->buffer->buffer_format);
-   desc->width  = surf->templat.width;
+   desc->width = surf->templat.width;
    desc->height = surf->templat.height;
+   desc->num_objects = 0;
+
+   bool supports_contiguous_planes = screen->resource_get_info && surf->buffer->contiguous_planes;
 
    for (p = 0; p < ARRAY_SIZE(desc->objects); p++) {
       struct winsys_handle whandle;
@@ -1652,37 +1655,52 @@ vlVaExportSurfaceHandle(VADriverContextP ctx,
          goto fail;
       }
 
-      memset(&whandle, 0, sizeof(whandle));
-      whandle.type = WINSYS_HANDLE_TYPE_FD;
+      /* If the driver stores all planes contiguously in memory, only one
+       * handle needs to be exported. resource_get_info is used to obtain
+       * pitch and offset for each layer. */
+      if (!desc->num_objects || !supports_contiguous_planes) {
+         memset(&whandle, 0, sizeof(whandle));
+         whandle.type = WINSYS_HANDLE_TYPE_FD;
 
-      if (!screen->resource_get_handle(screen, drv->pipe, resource,
-                                       &whandle, usage)) {
-         ret = VA_STATUS_ERROR_INVALID_SURFACE;
-         goto fail;
-      }
+         if (!screen->resource_get_handle(screen, drv->pipe, resource,
+                                          &whandle, usage)) {
+            ret = VA_STATUS_ERROR_INVALID_SURFACE;
+            goto fail;
+         }
 
-      desc->objects[p].fd   = (int)whandle.handle;
-      /* As per VADRMPRIMESurfaceDescriptor documentation, size must be the
-       * "Total size of this object (may include regions which are not part
-       * of the surface)."" */
-      desc->objects[p].size = (uint32_t) whandle.size;
-      desc->objects[p].drm_format_modifier = whandle.modifier;
+         desc->objects[desc->num_objects].fd = (int) whandle.handle;
+         /* As per VADRMPRIMESurfaceDescriptor documentation, size must be the
+         * "Total size of this object (may include regions which are not part
+         * of the surface)."" */
+         desc->objects[desc->num_objects].size = (uint32_t) whandle.size;
+         desc->objects[desc->num_objects].drm_format_modifier = whandle.modifier;
+
+         desc->num_objects++;
+      }
 
       if (flags & VA_EXPORT_SURFACE_COMPOSED_LAYERS) {
-         desc->layers[0].object_index[p] = p;
-         desc->layers[0].offset[p]       = whandle.offset;
-         desc->layers[0].pitch[p]        = whandle.stride;
+         desc->layers[0].object_index[p] = desc->num_objects - 1;
+
+         if (supports_contiguous_planes) {
+            screen->resource_get_info(screen, resource, &desc->layers[0].pitch[p], &desc->layers[0].offset[p]);
+         } else {
+            desc->layers[0].pitch[p] = whandle.stride;
+            desc->layers[0].offset[p] = whandle.offset;
+         }
       } else {
          desc->layers[p].drm_format      = drm_format;
          desc->layers[p].num_planes      = 1;
-         desc->layers[p].object_index[0] = p;
-         desc->layers[p].offset[0]       = whandle.offset;
-         desc->layers[p].pitch[0]        = whandle.stride;
+         desc->layers[p].object_index[0] = desc->num_objects - 1;
+
+         if (supports_contiguous_planes) {
+            screen->resource_get_info(screen, resource, &desc->layers[p].pitch[0], &desc->layers[p].offset[0]);
+         } else {
+            desc->layers[p].pitch[0] = whandle.stride;
+            desc->layers[p].offset[0] = whandle.offset;
+         }
       }
    }
 
-   desc->num_objects = p;
-
    if (flags & VA_EXPORT_SURFACE_COMPOSED_LAYERS) {
       uint32_t drm_format = pipe_format_to_drm_format(surf->buffer->buffer_format);
       if (drm_format == DRM_FORMAT_INVALID) {
@@ -1704,7 +1722,7 @@ vlVaExportSurfaceHandle(VADriverContextP ctx,
 
 fail:
 #ifndef _WIN32
-   for (i = 0; i < p; i++)
+   for (i = 0; i < desc->num_objects; i++)
       close(desc->objects[i].fd);
 #else
    if(whandle.handle)
-- 
GitLab