[Mesa-dev] [PATCH 10/10] st/mesa: implement new DMA-buf based VDPAU interop
Marek Olšák
maraeo at gmail.com
Thu Mar 10 11:03:49 UTC 2016
Alright.
Marek
On Thu, Mar 10, 2016 at 11:50 AM, Christian König
<deathsimple at vodafone.de> wrote:
> Nouveau needs to be tested first, I have doubts that this will work out of
> the box for them as well.
>
> Christian.
>
>
> Am 10.03.2016 um 11:42 schrieb Marek Olšák:
>>
>> Reviewed-by: Marek Olšák <marek.olsak at amd.com>
>>
>> Why do we still need the gallium codepath?
>>
>> Marek
>>
>> On Tue, Mar 8, 2016 at 1:21 PM, Christian König <deathsimple at vodafone.de>
>> wrote:
>>>
>>> From: Christian König <christian.koenig at amd.com>
>>>
>>> Avoid using internal structures from another API.
>>>
>>> Signed-off-by: Christian König <christian.koenig at amd.com>
>>> ---
>>> src/mesa/state_tracker/st_vdpau.c | 176
>>> ++++++++++++++++++++++++++++----------
>>> 1 file changed, 129 insertions(+), 47 deletions(-)
>>>
>>> diff --git a/src/mesa/state_tracker/st_vdpau.c
>>> b/src/mesa/state_tracker/st_vdpau.c
>>> index 71dd15b..7ccbe7e 100644
>>> --- a/src/mesa/state_tracker/st_vdpau.c
>>> +++ b/src/mesa/state_tracker/st_vdpau.c
>>> @@ -40,6 +40,9 @@
>>> #include "pipe/p_video_codec.h"
>>>
>>> #include "state_tracker/vdpau_interop.h"
>>> +#include "state_tracker/vdpau_dmabuf.h"
>>> +#include "state_tracker/vdpau_funcs.h"
>>> +#include "state_tracker/drm_driver.h"
>>>
>>> #include "util/u_inlines.h"
>>>
>>> @@ -51,70 +54,149 @@
>>>
>>> #ifdef HAVE_ST_VDPAU
>>>
>>> +static struct pipe_resource *
>>> +st_vdpau_video_surface_gallium(struct gl_context *ctx, const GLvoid
>>> *vdpSurface,
>>> + GLuint index)
>>> +{
>>> + int (*getProcAddr)(uint32_t device, uint32_t id, void **ptr);
>>> + uint32_t device = (uintptr_t)ctx->vdpDevice;
>>> + struct pipe_sampler_view *sv;
>>> + VdpVideoSurfaceGallium *f;
>>> +
>>> + struct pipe_video_buffer *buffer;
>>> + struct pipe_sampler_view **samplers;
>>> +
>>> + getProcAddr = (void *)ctx->vdpGetProcAddress;
>>> + if (getProcAddr(device, VDP_FUNC_ID_VIDEO_SURFACE_GALLIUM,
>>> (void**)&f))
>>> + return NULL;
>>> +
>>> + buffer = f((uintptr_t)vdpSurface);
>>> + if (!buffer)
>>> + return NULL;
>>> +
>>> + samplers = buffer->get_sampler_view_planes(buffer);
>>> + if (!samplers)
>>> + return NULL;
>>> +
>>> + sv = samplers[index >> 1];
>>> + if (!sv)
>>> + return NULL;
>>> +
>>> + return sv->texture;
>>> +}
>>> +
>>> +static struct pipe_resource *
>>> +st_vdpau_output_surface_gallium(struct gl_context *ctx, const GLvoid
>>> *vdpSurface)
>>> +{
>>> + int (*getProcAddr)(uint32_t device, uint32_t id, void **ptr);
>>> + uint32_t device = (uintptr_t)ctx->vdpDevice;
>>> + VdpOutputSurfaceGallium *f;
>>> +
>>> + getProcAddr = (void *)ctx->vdpGetProcAddress;
>>> + if (getProcAddr(device, VDP_FUNC_ID_OUTPUT_SURFACE_GALLIUM,
>>> (void**)&f))
>>> + return NULL;
>>> +
>>> + return f((uintptr_t)vdpSurface);
>>> +}
>>> +
>>> +static struct pipe_resource *
>>> +st_vdpau_resource_from_description(struct gl_context *ctx,
>>> + const struct VdpSurfaceDMABufDesc
>>> *desc)
>>> +{
>>> + struct st_context *st = st_context(ctx);
>>> + struct pipe_resource templ, *res;
>>> + struct winsys_handle whandle;
>>> +
>>> + if (desc->handle == -1)
>>> + return NULL;
>>> +
>>> + memset(&templ, 0, sizeof(templ));
>>> + templ.target = PIPE_TEXTURE_2D;
>>> + templ.last_level = 0;
>>> + templ.depth0 = 1;
>>> + templ.array_size = 1;
>>> + templ.width0 = desc->width;
>>> + templ.height0 = desc->height;
>>> + templ.format = VdpFormatRGBAToPipe(desc->format);
>>> + templ.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
>>> + templ.usage = PIPE_USAGE_DEFAULT;
>>> +
>>> + memset(&whandle, 0, sizeof(whandle));
>>> + whandle.type = DRM_API_HANDLE_TYPE_FD;
>>> + whandle.handle = desc->handle;
>>> + whandle.offset = desc->offset;
>>> + whandle.stride = desc->stride;
>>> +
>>> + res = st->pipe->screen->resource_from_handle(st->pipe->screen,
>>> &templ, &whandle);
>>> + close(desc->handle);
>>> +
>>> + return res;
>>> +}
>>> +
>>> +static struct pipe_resource *
>>> +st_vdpau_output_surface_dma_buf(struct gl_context *ctx, const GLvoid
>>> *vdpSurface)
>>> +{
>>> + int (*getProcAddr)(uint32_t device, uint32_t id, void **ptr);
>>> + uint32_t device = (uintptr_t)ctx->vdpDevice;
>>> +
>>> + struct VdpSurfaceDMABufDesc desc;
>>> + VdpOutputSurfaceDMABuf *f;
>>> +
>>> + getProcAddr = (void *)ctx->vdpGetProcAddress;
>>> + if (getProcAddr(device, VDP_FUNC_ID_OUTPUT_SURFACE_DMA_BUF,
>>> (void**)&f))
>>> + return NULL;
>>> +
>>> + if (f((uintptr_t)vdpSurface, &desc) != VDP_STATUS_OK)
>>> + return NULL;
>>> +
>>> + return st_vdpau_resource_from_description(ctx, &desc);
>>> +}
>>> +
>>> +static struct pipe_resource *
>>> +st_vdpau_video_surface_dma_buf(struct gl_context *ctx, const GLvoid
>>> *vdpSurface,
>>> + GLuint index)
>>> +{
>>> + int (*getProcAddr)(uint32_t device, uint32_t id, void **ptr);
>>> + uint32_t device = (uintptr_t)ctx->vdpDevice;
>>> +
>>> + struct VdpSurfaceDMABufDesc desc;
>>> + VdpVideoSurfaceDMABuf *f;
>>> +
>>> + getProcAddr = (void *)ctx->vdpGetProcAddress;
>>> + if (getProcAddr(device, VDP_FUNC_ID_VIDEO_SURFACE_DMA_BUF,
>>> (void**)&f))
>>> + return NULL;
>>> +
>>> + if (f((uintptr_t)vdpSurface, index, &desc) != VDP_STATUS_OK)
>>> + return NULL;
>>> +
>>> + return st_vdpau_resource_from_description(ctx, &desc);
>>> +}
>>> +
>>> static void
>>> st_vdpau_map_surface(struct gl_context *ctx, GLenum target, GLenum
>>> access,
>>> GLboolean output, struct gl_texture_object
>>> *texObj,
>>> struct gl_texture_image *texImage,
>>> const GLvoid *vdpSurface, GLuint index)
>>> {
>>> - int (*getProcAddr)(uint32_t device, uint32_t id, void **ptr);
>>> - uint32_t device = (uintptr_t)ctx->vdpDevice;
>>> -
>>> struct st_context *st = st_context(ctx);
>>> struct st_texture_object *stObj = st_texture_object(texObj);
>>> struct st_texture_image *stImage = st_texture_image(texImage);
>>> -
>>> +
>>> struct pipe_resource *res;
>>> struct pipe_sampler_view templ, **sampler_view;
>>> mesa_format texFormat;
>>>
>>> - getProcAddr = (void *)ctx->vdpGetProcAddress;
>>> if (output) {
>>> - VdpOutputSurfaceGallium *f;
>>> -
>>> - if (getProcAddr(device, VDP_FUNC_ID_OUTPUT_SURFACE_GALLIUM,
>>> (void**)&f)) {
>>> - _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV");
>>> - return;
>>> - }
>>> -
>>> - res = f((uintptr_t)vdpSurface);
>>> + res = st_vdpau_output_surface_dma_buf(ctx, vdpSurface);
>>>
>>> - if (!res) {
>>> - _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV");
>>> - return;
>>> - }
>>> + if (!res)
>>> + res = st_vdpau_output_surface_gallium(ctx, vdpSurface);
>>>
>>> } else {
>>> - struct pipe_sampler_view *sv;
>>> - VdpVideoSurfaceGallium *f;
>>> -
>>> - struct pipe_video_buffer *buffer;
>>> - struct pipe_sampler_view **samplers;
>>> -
>>> - if (getProcAddr(device, VDP_FUNC_ID_VIDEO_SURFACE_GALLIUM,
>>> (void**)&f)) {
>>> - _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV");
>>> - return;
>>> - }
>>> -
>>> - buffer = f((uintptr_t)vdpSurface);
>>> - if (!buffer) {
>>> - _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV");
>>> - return;
>>> - }
>>> -
>>> - samplers = buffer->get_sampler_view_planes(buffer);
>>> - if (!samplers) {
>>> - _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV");
>>> - return;
>>> - }
>>> -
>>> - sv = samplers[index >> 1];
>>> - if (!sv) {
>>> - _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV");
>>> - return;
>>> - }
>>> -
>>> - res = sv->texture;
>>> + res = st_vdpau_video_surface_dma_buf(ctx, vdpSurface, index);
>>> +
>>> + if (!res)
>>> + res = st_vdpau_video_surface_gallium(ctx, vdpSurface, index);
>>> }
>>>
>>> if (!res) {
>>> --
>>> 2.5.0
>>>
>>> _______________________________________________
>>> mesa-dev mailing list
>>> mesa-dev at lists.freedesktop.org
>>> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
>
More information about the mesa-dev
mailing list