mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 03:31:05 +00:00
vaallocator: use VADRMPRIMESurfaceDescriptor to create surfaces
To import DMAbufs we used VASurfaceAttribExternalBuffers which works, but it's not specific for DRM PRIME 2, since it lacks of many metadata. This patch replaces VASurfaceAttribExternalBuffers with VADRMPRIMESurfaceDescriptor in va_create_surfaces(). Still, this patch assumes linear modifier only. The hack for RGB surfaces in I965 driver was pushed down into va_create_surfaces() to avoid handling both structures. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5264>
This commit is contained in:
parent
76115528ac
commit
d1210d6dc0
3 changed files with 89 additions and 38 deletions
|
@ -545,7 +545,6 @@ _va_create_surface_and_export_to_dmabuf (GstVaDisplay * display,
|
||||||
{
|
{
|
||||||
VADRMPRIMESurfaceDescriptor desc = { 0, };
|
VADRMPRIMESurfaceDescriptor desc = { 0, };
|
||||||
guint32 i, fourcc, rt_format, export_flags;
|
guint32 i, fourcc, rt_format, export_flags;
|
||||||
VASurfaceAttribExternalBuffers *extbuf = NULL, ext_buf;
|
|
||||||
GstVideoFormat format;
|
GstVideoFormat format;
|
||||||
VASurfaceID surface;
|
VASurfaceID surface;
|
||||||
guint64 prev_modifier = DRM_FORMAT_MOD_INVALID;
|
guint64 prev_modifier = DRM_FORMAT_MOD_INVALID;
|
||||||
|
@ -559,24 +558,9 @@ _va_create_surface_and_export_to_dmabuf (GstVaDisplay * display,
|
||||||
if (fourcc == 0 || rt_format == 0)
|
if (fourcc == 0 || rt_format == 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* HACK(victor): disable tiling for i965 driver for RGB formats */
|
|
||||||
if (GST_VA_DISPLAY_IS_IMPLEMENTATION (display, INTEL_I965)
|
|
||||||
&& GST_VIDEO_INFO_IS_RGB (info)) {
|
|
||||||
/* *INDENT-OFF* */
|
|
||||||
ext_buf = (VASurfaceAttribExternalBuffers) {
|
|
||||||
.width = GST_VIDEO_INFO_WIDTH (info),
|
|
||||||
.height = GST_VIDEO_INFO_HEIGHT (info),
|
|
||||||
.num_planes = GST_VIDEO_INFO_N_PLANES (info),
|
|
||||||
.pixel_format = fourcc,
|
|
||||||
};
|
|
||||||
/* *INDENT-ON* */
|
|
||||||
|
|
||||||
extbuf = &ext_buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!va_create_surfaces (display, rt_format, fourcc,
|
if (!va_create_surfaces (display, rt_format, fourcc,
|
||||||
GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info),
|
GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info),
|
||||||
usage_hint, modifiers, num_modifiers, extbuf, &surface, 1))
|
usage_hint, modifiers, num_modifiers, NULL, &surface, 1))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* workaround for missing layered dmabuf formats in i965 */
|
/* workaround for missing layered dmabuf formats in i965 */
|
||||||
|
@ -1044,6 +1028,26 @@ gst_va_dmabuf_allocator_get_format (GstAllocator * allocator,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_is_fd_repeated (uintptr_t fds[GST_VIDEO_MAX_PLANES], guint cur, guint * prev)
|
||||||
|
{
|
||||||
|
guint i;
|
||||||
|
|
||||||
|
g_assert (cur <= GST_VIDEO_MAX_PLANES);
|
||||||
|
|
||||||
|
if (cur == 0)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
for (i = 0; i < cur; i++) {
|
||||||
|
if (fds[i] == fds[cur]) {
|
||||||
|
if (prev)
|
||||||
|
*prev = i;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_va_dmabuf_memories_setup:
|
* gst_va_dmabuf_memories_setup:
|
||||||
* @display: a #GstVaDisplay
|
* @display: a #GstVaDisplay
|
||||||
|
@ -1073,18 +1077,16 @@ gst_va_dmabuf_memories_setup (GstVaDisplay * display, GstVideoInfo * info,
|
||||||
GstVideoFormat format;
|
GstVideoFormat format;
|
||||||
GstVaBufferSurface *buf;
|
GstVaBufferSurface *buf;
|
||||||
/* *INDENT-OFF* */
|
/* *INDENT-OFF* */
|
||||||
VASurfaceAttribExternalBuffers ext_buf = {
|
VADRMPRIMESurfaceDescriptor desc = {
|
||||||
.width = GST_VIDEO_INFO_WIDTH (info),
|
.width = GST_VIDEO_INFO_WIDTH (info),
|
||||||
.height = GST_VIDEO_INFO_HEIGHT (info),
|
.height = GST_VIDEO_INFO_HEIGHT (info),
|
||||||
.data_size = GST_VIDEO_INFO_SIZE (info),
|
/* GStreamer can only describe one PRIME layer */
|
||||||
.num_planes = GST_VIDEO_INFO_N_PLANES (info),
|
.num_layers = 1,
|
||||||
.buffers = fds,
|
|
||||||
.num_buffers = GST_VIDEO_INFO_N_PLANES (info),
|
|
||||||
};
|
};
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
VASurfaceID surface;
|
VASurfaceID surface;
|
||||||
guint32 fourcc, rt_format;
|
guint32 fourcc, rt_format;
|
||||||
guint i, n_planes;
|
guint i, j, prev, n_planes;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_VA_DISPLAY (display), FALSE);
|
g_return_val_if_fail (GST_IS_VA_DISPLAY (display), FALSE);
|
||||||
|
@ -1103,21 +1105,38 @@ gst_va_dmabuf_memories_setup (GstVaDisplay * display, GstVideoInfo * info,
|
||||||
if (fourcc == 0)
|
if (fourcc == 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
ext_buf.pixel_format = fourcc;
|
desc.fourcc = fourcc;
|
||||||
|
desc.layers[0].num_planes = n_planes;
|
||||||
|
/* FIXME: use GstVideoInfoDmaDrm */
|
||||||
|
desc.layers[0].drm_format = gst_va_drm_fourcc_from_video_format (format);
|
||||||
|
|
||||||
for (i = 0; i < n_planes; i++) {
|
for (i = j = 0; i < n_planes; i++) {
|
||||||
ext_buf.pitches[i] = GST_VIDEO_INFO_PLANE_STRIDE (info, i);
|
desc.layers[0].pitch[i] = GST_VIDEO_INFO_PLANE_STRIDE (info, i);
|
||||||
ext_buf.offsets[i] = offset[i];
|
desc.layers[0].offset[i] = offset[i];
|
||||||
|
|
||||||
|
if (_is_fd_repeated (fds, i, &prev)) {
|
||||||
|
desc.layers[0].object_index[i] = prev;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = va_create_surfaces (display, rt_format, ext_buf.pixel_format,
|
desc.objects[j].fd = fds[i];
|
||||||
ext_buf.width, ext_buf.height, usage_hint, NULL, 0, &ext_buf, &surface,
|
desc.objects[j].size = _get_fd_size (fds[i]);
|
||||||
1);
|
/* FIXME: use GstVideoInfoDmaDrm */
|
||||||
|
desc.objects[j].drm_format_modifier = DRM_FORMAT_MOD_LINEAR;
|
||||||
|
|
||||||
|
desc.layers[0].object_index[i] = j;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
|
||||||
|
desc.num_objects = j;
|
||||||
|
|
||||||
|
ret = va_create_surfaces (display, rt_format, fourcc, desc.width, desc.height,
|
||||||
|
usage_hint, NULL, 0, &desc, &surface, 1);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
GST_LOG_OBJECT (display, "Created surface %#x [%dx%d]", surface,
|
GST_LOG_OBJECT (display, "Created surface %#x [%dx%d]", surface, desc.width,
|
||||||
ext_buf.width, ext_buf.height);
|
desc.height);
|
||||||
|
|
||||||
buf = gst_va_buffer_surface_new (surface);
|
buf = gst_va_buffer_surface_new (surface);
|
||||||
buf->display = gst_object_ref (display);
|
buf->display = gst_object_ref (display);
|
||||||
|
|
|
@ -48,10 +48,25 @@ va_destroy_surfaces (GstVaDisplay * display, VASurfaceID * surfaces,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_rt_format_is_rgb (guint rt_format)
|
||||||
|
{
|
||||||
|
switch (rt_format) {
|
||||||
|
case VA_RT_FORMAT_RGB16:
|
||||||
|
case VA_RT_FORMAT_RGB32:
|
||||||
|
case VA_RT_FORMAT_RGB32_10:
|
||||||
|
return TRUE;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
va_create_surfaces (GstVaDisplay * display, guint rt_format, guint fourcc,
|
va_create_surfaces (GstVaDisplay * display, guint rt_format, guint fourcc,
|
||||||
guint width, guint height, gint usage_hint, guint64 * modifiers,
|
guint width, guint height, gint usage_hint, guint64 * modifiers,
|
||||||
guint num_modifiers, VASurfaceAttribExternalBuffers * ext_buf,
|
guint num_modifiers, VADRMPRIMESurfaceDescriptor * desc,
|
||||||
VASurfaceID * surfaces, guint num_surfaces)
|
VASurfaceID * surfaces, guint num_surfaces)
|
||||||
{
|
{
|
||||||
VADisplay dpy = gst_va_display_get_va_dpy (display);
|
VADisplay dpy = gst_va_display_get_va_dpy (display);
|
||||||
|
@ -67,8 +82,8 @@ va_create_surfaces (GstVaDisplay * display, guint rt_format, guint fourcc,
|
||||||
.type = VASurfaceAttribMemoryType,
|
.type = VASurfaceAttribMemoryType,
|
||||||
.flags = VA_SURFACE_ATTRIB_SETTABLE,
|
.flags = VA_SURFACE_ATTRIB_SETTABLE,
|
||||||
.value.type = VAGenericValueTypeInteger,
|
.value.type = VAGenericValueTypeInteger,
|
||||||
.value.value.i = (ext_buf && ext_buf->num_buffers > 0)
|
.value.value.i = (desc && desc->num_objects > 0)
|
||||||
? VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME
|
? VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2
|
||||||
: VA_SURFACE_ATTRIB_MEM_TYPE_VA,
|
: VA_SURFACE_ATTRIB_MEM_TYPE_VA,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -76,6 +91,12 @@ va_create_surfaces (GstVaDisplay * display, guint rt_format, guint fourcc,
|
||||||
.num_modifiers = num_modifiers,
|
.num_modifiers = num_modifiers,
|
||||||
.modifiers = modifiers,
|
.modifiers = modifiers,
|
||||||
};
|
};
|
||||||
|
VASurfaceAttribExternalBuffers extbuf = {
|
||||||
|
.width = width,
|
||||||
|
.height = height,
|
||||||
|
.num_planes = 1,
|
||||||
|
.pixel_format = fourcc,
|
||||||
|
};
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
VAStatus status;
|
VAStatus status;
|
||||||
guint num_attrs = 2;
|
guint num_attrs = 2;
|
||||||
|
@ -95,13 +116,24 @@ va_create_surfaces (GstVaDisplay * display, guint rt_format, guint fourcc,
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ext_buf) {
|
if (desc && desc->num_objects > 0) {
|
||||||
/* *INDENT-OFF* */
|
/* *INDENT-OFF* */
|
||||||
attrs[num_attrs++] = (VASurfaceAttrib) {
|
attrs[num_attrs++] = (VASurfaceAttrib) {
|
||||||
.type = VASurfaceAttribExternalBufferDescriptor,
|
.type = VASurfaceAttribExternalBufferDescriptor,
|
||||||
.flags = VA_SURFACE_ATTRIB_SETTABLE,
|
.flags = VA_SURFACE_ATTRIB_SETTABLE,
|
||||||
.value.type = VAGenericValueTypePointer,
|
.value.type = VAGenericValueTypePointer,
|
||||||
.value.value.p = ext_buf,
|
.value.value.p = desc,
|
||||||
|
};
|
||||||
|
/* *INDENT-ON* */
|
||||||
|
} else if (GST_VA_DISPLAY_IS_IMPLEMENTATION (display, INTEL_I965)
|
||||||
|
&& _rt_format_is_rgb (rt_format)) {
|
||||||
|
/* HACK(victor): disable tiling for i965 driver for RGB formats */
|
||||||
|
/* *INDENT-OFF* */
|
||||||
|
attrs[num_attrs++] = (VASurfaceAttrib) {
|
||||||
|
.type = VASurfaceAttribExternalBufferDescriptor,
|
||||||
|
.flags = VA_SURFACE_ATTRIB_SETTABLE,
|
||||||
|
.value.type = VAGenericValueTypePointer,
|
||||||
|
.value.value.p = &extbuf,
|
||||||
};
|
};
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ gboolean va_create_surfaces (GstVaDisplay * displa
|
||||||
gint usage_hint,
|
gint usage_hint,
|
||||||
guint64 * modifiers,
|
guint64 * modifiers,
|
||||||
guint num_modifiers,
|
guint num_modifiers,
|
||||||
VASurfaceAttribExternalBuffers * ext_buf,
|
VADRMPRIMESurfaceDescriptor * desc,
|
||||||
VASurfaceID * surfaces,
|
VASurfaceID * surfaces,
|
||||||
guint num_surfaces);
|
guint num_surfaces);
|
||||||
gboolean va_destroy_surfaces (GstVaDisplay * display,
|
gboolean va_destroy_surfaces (GstVaDisplay * display,
|
||||||
|
|
Loading…
Reference in a new issue