2014-07-02 16:35:28 -04:00
|
|
|
/**************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2010 Thomas Balling Sørensen & Orasanu Lucian.
|
|
|
|
|
* Copyright 2014 Advanced Micro Devices, Inc.
|
|
|
|
|
* All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
|
* the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
|
* of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
|
|
|
|
|
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2015-10-30 11:42:52 +00:00
|
|
|
#include "pipe/p_screen.h"
|
2019-12-03 18:01:31 -05:00
|
|
|
#include "frontend/drm_driver.h"
|
2014-07-04 12:44:36 -04:00
|
|
|
#include "util/u_memory.h"
|
|
|
|
|
#include "util/u_handle_table.h"
|
2015-10-30 11:42:52 +00:00
|
|
|
#include "util/u_transfer.h"
|
|
|
|
|
#include "vl/vl_winsys.h"
|
2014-07-04 12:44:36 -04:00
|
|
|
|
2014-07-02 16:35:28 -04:00
|
|
|
#include "va_private.h"
|
|
|
|
|
|
2022-09-07 13:42:04 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
#include <va/va_win32.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-07-02 16:35:28 -04:00
|
|
|
VAStatus
|
|
|
|
|
vlVaCreateBuffer(VADriverContextP ctx, VAContextID context, VABufferType type,
|
|
|
|
|
unsigned int size, unsigned int num_elements, void *data,
|
|
|
|
|
VABufferID *buf_id)
|
|
|
|
|
{
|
2015-12-16 20:58:49 +01:00
|
|
|
vlVaDriver *drv;
|
2014-07-04 12:44:36 -04:00
|
|
|
vlVaBuffer *buf;
|
|
|
|
|
|
2014-07-02 16:35:28 -04:00
|
|
|
if (!ctx)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_CONTEXT;
|
|
|
|
|
|
2014-07-04 12:44:36 -04:00
|
|
|
buf = CALLOC(1, sizeof(vlVaBuffer));
|
|
|
|
|
if (!buf)
|
|
|
|
|
return VA_STATUS_ERROR_ALLOCATION_FAILED;
|
|
|
|
|
|
|
|
|
|
buf->type = type;
|
|
|
|
|
buf->size = size;
|
|
|
|
|
buf->num_elements = num_elements;
|
|
|
|
|
buf->data = MALLOC(size * num_elements);
|
|
|
|
|
|
|
|
|
|
if (!buf->data) {
|
|
|
|
|
FREE(buf);
|
|
|
|
|
return VA_STATUS_ERROR_ALLOCATION_FAILED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
|
memcpy(buf->data, data, size * num_elements);
|
|
|
|
|
|
2015-12-16 20:58:49 +01:00
|
|
|
drv = VL_VA_DRIVER(ctx);
|
2017-03-05 12:12:30 +11:00
|
|
|
mtx_lock(&drv->mutex);
|
2015-12-16 20:58:49 +01:00
|
|
|
*buf_id = handle_table_add(drv->htab, buf);
|
2017-03-05 12:32:06 +11:00
|
|
|
mtx_unlock(&drv->mutex);
|
2014-07-04 12:44:36 -04:00
|
|
|
|
|
|
|
|
return VA_STATUS_SUCCESS;
|
2014-07-02 16:35:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VAStatus
|
|
|
|
|
vlVaBufferSetNumElements(VADriverContextP ctx, VABufferID buf_id,
|
|
|
|
|
unsigned int num_elements)
|
|
|
|
|
{
|
2015-12-16 20:58:49 +01:00
|
|
|
vlVaDriver *drv;
|
2014-07-04 12:44:36 -04:00
|
|
|
vlVaBuffer *buf;
|
|
|
|
|
|
2014-07-02 16:35:28 -04:00
|
|
|
if (!ctx)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_CONTEXT;
|
|
|
|
|
|
2015-12-16 20:58:49 +01:00
|
|
|
drv = VL_VA_DRIVER(ctx);
|
2017-03-05 12:12:30 +11:00
|
|
|
mtx_lock(&drv->mutex);
|
2015-12-16 20:58:49 +01:00
|
|
|
buf = handle_table_get(drv->htab, buf_id);
|
2017-03-05 12:32:06 +11:00
|
|
|
mtx_unlock(&drv->mutex);
|
2015-10-30 11:42:51 +00:00
|
|
|
if (!buf)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_BUFFER;
|
|
|
|
|
|
2015-10-30 11:42:52 +00:00
|
|
|
if (buf->derived_surface.resource)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_BUFFER;
|
|
|
|
|
|
2014-07-04 12:44:36 -04:00
|
|
|
buf->data = REALLOC(buf->data, buf->size * buf->num_elements,
|
|
|
|
|
buf->size * num_elements);
|
|
|
|
|
buf->num_elements = num_elements;
|
|
|
|
|
|
|
|
|
|
if (!buf->data)
|
|
|
|
|
return VA_STATUS_ERROR_ALLOCATION_FAILED;
|
|
|
|
|
|
|
|
|
|
return VA_STATUS_SUCCESS;
|
2014-07-02 16:35:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VAStatus
|
|
|
|
|
vlVaMapBuffer(VADriverContextP ctx, VABufferID buf_id, void **pbuff)
|
|
|
|
|
{
|
2015-10-30 11:42:52 +00:00
|
|
|
vlVaDriver *drv;
|
2014-07-04 12:44:36 -04:00
|
|
|
vlVaBuffer *buf;
|
|
|
|
|
|
2014-07-02 16:35:28 -04:00
|
|
|
if (!ctx)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_CONTEXT;
|
|
|
|
|
|
2015-10-30 11:42:52 +00:00
|
|
|
drv = VL_VA_DRIVER(ctx);
|
|
|
|
|
if (!drv)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_CONTEXT;
|
|
|
|
|
|
2015-10-30 11:42:51 +00:00
|
|
|
if (!pbuff)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
2017-03-05 12:12:30 +11:00
|
|
|
mtx_lock(&drv->mutex);
|
2015-10-30 11:42:52 +00:00
|
|
|
buf = handle_table_get(drv->htab, buf_id);
|
2015-12-16 20:58:49 +01:00
|
|
|
if (!buf || buf->export_refcount > 0) {
|
2017-03-05 12:32:06 +11:00
|
|
|
mtx_unlock(&drv->mutex);
|
2015-10-30 11:42:53 +00:00
|
|
|
return VA_STATUS_ERROR_INVALID_BUFFER;
|
2015-12-16 20:58:49 +01:00
|
|
|
}
|
2015-10-30 11:42:53 +00:00
|
|
|
|
2015-10-30 11:42:52 +00:00
|
|
|
if (buf->derived_surface.resource) {
|
2017-09-26 09:11:52 -04:00
|
|
|
struct pipe_resource *resource;
|
2022-09-07 13:42:04 -04:00
|
|
|
struct pipe_box box;
|
2022-07-12 09:42:58 -04:00
|
|
|
void *(*map_func)(struct pipe_context *,
|
|
|
|
|
struct pipe_resource *resource,
|
|
|
|
|
unsigned level,
|
|
|
|
|
unsigned usage, /* a combination of PIPE_MAP_x */
|
|
|
|
|
const struct pipe_box *,
|
|
|
|
|
struct pipe_transfer **out_transfer);
|
2017-09-26 09:11:52 -04:00
|
|
|
|
2022-09-07 13:42:04 -04:00
|
|
|
memset(&box, 0, sizeof(box));
|
2017-09-26 09:11:52 -04:00
|
|
|
resource = buf->derived_surface.resource;
|
|
|
|
|
box.width = resource->width0;
|
|
|
|
|
box.height = resource->height0;
|
|
|
|
|
box.depth = resource->depth0;
|
2022-07-12 09:42:58 -04:00
|
|
|
|
|
|
|
|
if (resource->target == PIPE_BUFFER)
|
|
|
|
|
map_func = drv->pipe->buffer_map;
|
|
|
|
|
else
|
|
|
|
|
map_func = drv->pipe->texture_map;
|
|
|
|
|
|
2022-12-18 18:01:37 +01:00
|
|
|
*pbuff = map_func(drv->pipe, resource, 0,
|
|
|
|
|
buf->type == VAEncCodedBufferType ?
|
|
|
|
|
PIPE_MAP_READ : PIPE_MAP_WRITE,
|
2022-07-12 09:42:58 -04:00
|
|
|
&box, &buf->derived_surface.transfer);
|
2017-03-05 12:32:06 +11:00
|
|
|
mtx_unlock(&drv->mutex);
|
2015-10-30 11:42:52 +00:00
|
|
|
|
|
|
|
|
if (!buf->derived_surface.transfer || !*pbuff)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_BUFFER;
|
|
|
|
|
|
2016-07-21 19:40:18 -04:00
|
|
|
if (buf->type == VAEncCodedBufferType) {
|
|
|
|
|
((VACodedBufferSegment*)buf->data)->buf = *pbuff;
|
|
|
|
|
((VACodedBufferSegment*)buf->data)->size = buf->coded_size;
|
|
|
|
|
((VACodedBufferSegment*)buf->data)->next = NULL;
|
|
|
|
|
*pbuff = buf->data;
|
|
|
|
|
}
|
2015-10-30 11:42:52 +00:00
|
|
|
} else {
|
2017-03-05 12:32:06 +11:00
|
|
|
mtx_unlock(&drv->mutex);
|
2015-10-30 11:42:52 +00:00
|
|
|
*pbuff = buf->data;
|
|
|
|
|
}
|
2014-07-04 12:44:36 -04:00
|
|
|
|
|
|
|
|
return VA_STATUS_SUCCESS;
|
2014-07-02 16:35:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VAStatus
|
|
|
|
|
vlVaUnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
|
|
|
|
|
{
|
2015-10-30 11:42:52 +00:00
|
|
|
vlVaDriver *drv;
|
2014-07-04 12:44:36 -04:00
|
|
|
vlVaBuffer *buf;
|
2022-07-12 09:42:58 -04:00
|
|
|
struct pipe_resource *resource;
|
2014-07-04 12:44:36 -04:00
|
|
|
|
2014-07-02 16:35:28 -04:00
|
|
|
if (!ctx)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_CONTEXT;
|
|
|
|
|
|
2015-10-30 11:42:52 +00:00
|
|
|
drv = VL_VA_DRIVER(ctx);
|
|
|
|
|
if (!drv)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_CONTEXT;
|
|
|
|
|
|
2017-03-05 12:12:30 +11:00
|
|
|
mtx_lock(&drv->mutex);
|
2015-10-30 11:42:52 +00:00
|
|
|
buf = handle_table_get(drv->htab, buf_id);
|
2015-12-16 20:58:49 +01:00
|
|
|
if (!buf || buf->export_refcount > 0) {
|
2017-03-05 12:32:06 +11:00
|
|
|
mtx_unlock(&drv->mutex);
|
2015-10-30 11:42:53 +00:00
|
|
|
return VA_STATUS_ERROR_INVALID_BUFFER;
|
2015-12-16 20:58:49 +01:00
|
|
|
}
|
2015-10-30 11:42:53 +00:00
|
|
|
|
2022-07-12 09:42:58 -04:00
|
|
|
resource = buf->derived_surface.resource;
|
|
|
|
|
if (resource) {
|
|
|
|
|
void (*unmap_func)(struct pipe_context *pipe,
|
|
|
|
|
struct pipe_transfer *transfer);
|
|
|
|
|
|
2015-12-16 20:58:49 +01:00
|
|
|
if (!buf->derived_surface.transfer) {
|
2017-03-05 12:32:06 +11:00
|
|
|
mtx_unlock(&drv->mutex);
|
2015-11-06 09:45:11 +00:00
|
|
|
return VA_STATUS_ERROR_INVALID_BUFFER;
|
2015-12-16 20:58:49 +01:00
|
|
|
}
|
2015-10-30 11:42:52 +00:00
|
|
|
|
2022-07-12 09:42:58 -04:00
|
|
|
if (resource->target == PIPE_BUFFER)
|
|
|
|
|
unmap_func = pipe_buffer_unmap;
|
|
|
|
|
else
|
|
|
|
|
unmap_func = pipe_texture_unmap;
|
|
|
|
|
|
|
|
|
|
unmap_func(drv->pipe, buf->derived_surface.transfer);
|
2015-11-06 09:45:11 +00:00
|
|
|
buf->derived_surface.transfer = NULL;
|
2015-10-30 11:42:52 +00:00
|
|
|
}
|
2017-03-05 12:32:06 +11:00
|
|
|
mtx_unlock(&drv->mutex);
|
2014-07-04 12:44:36 -04:00
|
|
|
|
|
|
|
|
return VA_STATUS_SUCCESS;
|
2014-07-02 16:35:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VAStatus
|
2014-07-04 12:44:36 -04:00
|
|
|
vlVaDestroyBuffer(VADriverContextP ctx, VABufferID buf_id)
|
2014-07-02 16:35:28 -04:00
|
|
|
{
|
2015-12-16 20:58:49 +01:00
|
|
|
vlVaDriver *drv;
|
2014-07-04 12:44:36 -04:00
|
|
|
vlVaBuffer *buf;
|
|
|
|
|
|
2014-07-02 16:35:28 -04:00
|
|
|
if (!ctx)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_CONTEXT;
|
|
|
|
|
|
2015-12-16 20:58:49 +01:00
|
|
|
drv = VL_VA_DRIVER(ctx);
|
2017-03-05 12:12:30 +11:00
|
|
|
mtx_lock(&drv->mutex);
|
2015-12-16 20:58:49 +01:00
|
|
|
buf = handle_table_get(drv->htab, buf_id);
|
|
|
|
|
if (!buf) {
|
2017-03-05 12:32:06 +11:00
|
|
|
mtx_unlock(&drv->mutex);
|
2014-07-04 12:44:36 -04:00
|
|
|
return VA_STATUS_ERROR_INVALID_BUFFER;
|
2015-12-16 20:58:49 +01:00
|
|
|
}
|
2014-07-04 12:44:36 -04:00
|
|
|
|
2020-07-16 16:57:54 -04:00
|
|
|
if (buf->derived_surface.resource) {
|
2015-11-06 09:45:11 +00:00
|
|
|
pipe_resource_reference(&buf->derived_surface.resource, NULL);
|
2015-10-30 11:42:52 +00:00
|
|
|
|
2020-07-16 16:57:54 -04:00
|
|
|
if (buf->derived_image_buffer)
|
|
|
|
|
buf->derived_image_buffer->destroy(buf->derived_image_buffer);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-04 12:44:36 -04:00
|
|
|
FREE(buf->data);
|
|
|
|
|
FREE(buf);
|
2014-10-27 10:43:20 -05:00
|
|
|
handle_table_remove(VL_VA_DRIVER(ctx)->htab, buf_id);
|
2017-03-05 12:32:06 +11:00
|
|
|
mtx_unlock(&drv->mutex);
|
2014-07-04 12:44:36 -04:00
|
|
|
|
|
|
|
|
return VA_STATUS_SUCCESS;
|
2014-07-02 16:35:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VAStatus
|
|
|
|
|
vlVaBufferInfo(VADriverContextP ctx, VABufferID buf_id, VABufferType *type,
|
|
|
|
|
unsigned int *size, unsigned int *num_elements)
|
|
|
|
|
{
|
2015-12-16 20:58:49 +01:00
|
|
|
vlVaDriver *drv;
|
2014-07-04 12:44:36 -04:00
|
|
|
vlVaBuffer *buf;
|
|
|
|
|
|
2014-07-02 16:35:28 -04:00
|
|
|
if (!ctx)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_CONTEXT;
|
|
|
|
|
|
2015-12-16 20:58:49 +01:00
|
|
|
drv = VL_VA_DRIVER(ctx);
|
2017-03-05 12:12:30 +11:00
|
|
|
mtx_lock(&drv->mutex);
|
2015-12-16 20:58:49 +01:00
|
|
|
buf = handle_table_get(drv->htab, buf_id);
|
2017-03-05 12:32:06 +11:00
|
|
|
mtx_unlock(&drv->mutex);
|
2014-07-04 12:44:36 -04:00
|
|
|
if (!buf)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_BUFFER;
|
|
|
|
|
|
|
|
|
|
*type = buf->type;
|
|
|
|
|
*size = buf->size;
|
|
|
|
|
*num_elements = buf->num_elements;
|
|
|
|
|
|
|
|
|
|
return VA_STATUS_SUCCESS;
|
2014-07-02 16:35:28 -04:00
|
|
|
}
|
2015-10-30 11:42:53 +00:00
|
|
|
|
|
|
|
|
VAStatus
|
|
|
|
|
vlVaAcquireBufferHandle(VADriverContextP ctx, VABufferID buf_id,
|
|
|
|
|
VABufferInfo *out_buf_info)
|
|
|
|
|
{
|
2015-12-08 14:28:13 +01:00
|
|
|
vlVaDriver *drv;
|
2015-10-30 11:42:53 +00:00
|
|
|
uint32_t i;
|
|
|
|
|
uint32_t mem_type;
|
|
|
|
|
vlVaBuffer *buf ;
|
|
|
|
|
struct pipe_screen *screen;
|
|
|
|
|
|
|
|
|
|
/* List of supported memory types, in preferred order. */
|
|
|
|
|
static const uint32_t mem_types[] = {
|
2022-09-07 13:42:04 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
VA_SURFACE_ATTRIB_MEM_TYPE_NTHANDLE,
|
|
|
|
|
VA_SURFACE_ATTRIB_MEM_TYPE_D3D12_RESOURCE,
|
|
|
|
|
#else
|
2015-10-30 11:42:53 +00:00
|
|
|
VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME,
|
2022-09-07 13:42:04 -04:00
|
|
|
#endif
|
2015-10-30 11:42:53 +00:00
|
|
|
0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!ctx)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_CONTEXT;
|
|
|
|
|
|
2015-12-16 20:58:49 +01:00
|
|
|
drv = VL_VA_DRIVER(ctx);
|
|
|
|
|
screen = VL_VA_PSCREEN(ctx);
|
2017-03-05 12:12:30 +11:00
|
|
|
mtx_lock(&drv->mutex);
|
2015-10-30 11:42:53 +00:00
|
|
|
buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, buf_id);
|
2017-03-05 12:32:06 +11:00
|
|
|
mtx_unlock(&drv->mutex);
|
2015-10-30 11:42:53 +00:00
|
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_BUFFER;
|
|
|
|
|
|
|
|
|
|
/* Only VA surface|image like buffers are supported for now .*/
|
|
|
|
|
if (buf->type != VAImageBufferType)
|
|
|
|
|
return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
|
|
|
|
|
|
|
|
|
|
if (!out_buf_info)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
|
|
if (!out_buf_info->mem_type)
|
|
|
|
|
mem_type = mem_types[0];
|
|
|
|
|
else {
|
|
|
|
|
mem_type = 0;
|
|
|
|
|
for (i = 0; mem_types[i] != 0; i++) {
|
|
|
|
|
if (out_buf_info->mem_type & mem_types[i]) {
|
|
|
|
|
mem_type = out_buf_info->mem_type;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!mem_type)
|
|
|
|
|
return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!buf->derived_surface.resource)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_BUFFER;
|
|
|
|
|
|
|
|
|
|
if (buf->export_refcount > 0) {
|
|
|
|
|
if (buf->export_state.mem_type != mem_type)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_PARAMETER;
|
|
|
|
|
} else {
|
|
|
|
|
VABufferInfo * const buf_info = &buf->export_state;
|
|
|
|
|
|
|
|
|
|
switch (mem_type) {
|
2022-09-07 13:42:04 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
case VA_SURFACE_ATTRIB_MEM_TYPE_D3D12_RESOURCE:
|
|
|
|
|
case VA_SURFACE_ATTRIB_MEM_TYPE_NTHANDLE:
|
|
|
|
|
#else
|
|
|
|
|
case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME:
|
|
|
|
|
#endif
|
|
|
|
|
{
|
2015-10-30 11:42:53 +00:00
|
|
|
struct winsys_handle whandle;
|
|
|
|
|
|
2017-03-05 12:12:30 +11:00
|
|
|
mtx_lock(&drv->mutex);
|
2015-12-08 14:28:13 +01:00
|
|
|
drv->pipe->flush(drv->pipe, NULL, 0);
|
|
|
|
|
|
2015-10-30 11:42:53 +00:00
|
|
|
memset(&whandle, 0, sizeof(whandle));
|
2018-05-29 11:21:38 +10:00
|
|
|
whandle.type = WINSYS_HANDLE_TYPE_FD;
|
2015-10-30 11:42:53 +00:00
|
|
|
|
2022-09-07 13:42:04 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
if (mem_type == VA_SURFACE_ATTRIB_MEM_TYPE_D3D12_RESOURCE)
|
|
|
|
|
whandle.type = WINSYS_HANDLE_TYPE_D3D12_RES;
|
|
|
|
|
#endif
|
2016-08-21 12:24:59 +02:00
|
|
|
if (!screen->resource_get_handle(screen, drv->pipe,
|
|
|
|
|
buf->derived_surface.resource,
|
2018-10-25 15:33:00 -04:00
|
|
|
&whandle, PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE)) {
|
2017-03-05 12:32:06 +11:00
|
|
|
mtx_unlock(&drv->mutex);
|
2015-10-30 11:42:53 +00:00
|
|
|
return VA_STATUS_ERROR_INVALID_BUFFER;
|
2017-01-04 11:42:13 +01:00
|
|
|
}
|
|
|
|
|
|
2017-03-05 12:32:06 +11:00
|
|
|
mtx_unlock(&drv->mutex);
|
2015-10-30 11:42:53 +00:00
|
|
|
|
|
|
|
|
buf_info->handle = (intptr_t)whandle.handle;
|
2022-09-07 13:42:04 -04:00
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
if (mem_type == VA_SURFACE_ATTRIB_MEM_TYPE_D3D12_RESOURCE)
|
|
|
|
|
buf_info->handle = (intptr_t)whandle.com_obj;
|
|
|
|
|
#endif
|
2015-10-30 11:42:53 +00:00
|
|
|
break;
|
2015-11-06 09:45:17 +00:00
|
|
|
}
|
2015-10-30 11:42:53 +00:00
|
|
|
default:
|
|
|
|
|
return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-06 09:45:17 +00:00
|
|
|
buf_info->type = buf->type;
|
|
|
|
|
buf_info->mem_type = mem_type;
|
|
|
|
|
buf_info->mem_size = buf->num_elements * buf->size;
|
2015-10-30 11:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buf->export_refcount++;
|
|
|
|
|
|
|
|
|
|
*out_buf_info = buf->export_state;
|
|
|
|
|
|
|
|
|
|
return VA_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VAStatus
|
|
|
|
|
vlVaReleaseBufferHandle(VADriverContextP ctx, VABufferID buf_id)
|
|
|
|
|
{
|
2015-12-16 20:58:49 +01:00
|
|
|
vlVaDriver *drv;
|
2015-10-30 11:42:53 +00:00
|
|
|
vlVaBuffer *buf;
|
|
|
|
|
|
|
|
|
|
if (!ctx)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_CONTEXT;
|
|
|
|
|
|
2015-12-16 20:58:49 +01:00
|
|
|
drv = VL_VA_DRIVER(ctx);
|
2017-03-05 12:12:30 +11:00
|
|
|
mtx_lock(&drv->mutex);
|
2015-12-16 20:58:49 +01:00
|
|
|
buf = handle_table_get(drv->htab, buf_id);
|
2017-03-05 12:32:06 +11:00
|
|
|
mtx_unlock(&drv->mutex);
|
2015-10-30 11:42:53 +00:00
|
|
|
|
|
|
|
|
if (!buf)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_BUFFER;
|
|
|
|
|
|
|
|
|
|
if (buf->export_refcount == 0)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_BUFFER;
|
|
|
|
|
|
|
|
|
|
if (--buf->export_refcount == 0) {
|
|
|
|
|
VABufferInfo * const buf_info = &buf->export_state;
|
|
|
|
|
|
|
|
|
|
switch (buf_info->mem_type) {
|
2022-09-07 13:42:04 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
case VA_SURFACE_ATTRIB_MEM_TYPE_D3D12_RESOURCE:
|
|
|
|
|
// Do nothing for this case.
|
|
|
|
|
break;
|
|
|
|
|
case VA_SURFACE_ATTRIB_MEM_TYPE_NTHANDLE:
|
|
|
|
|
CloseHandle((HANDLE) buf_info->handle);
|
|
|
|
|
break;
|
|
|
|
|
#else
|
2015-10-30 11:42:53 +00:00
|
|
|
case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME:
|
|
|
|
|
close((intptr_t)buf_info->handle);
|
|
|
|
|
break;
|
2022-09-07 13:42:04 -04:00
|
|
|
#endif
|
2015-10-30 11:42:53 +00:00
|
|
|
default:
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_BUFFER;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buf_info->mem_type = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return VA_STATUS_SUCCESS;
|
|
|
|
|
}
|
2022-09-17 09:46:11 -04:00
|
|
|
|
2022-09-22 12:53:25 -04:00
|
|
|
#if VA_CHECK_VERSION(1, 15, 0)
|
2022-09-17 09:46:11 -04:00
|
|
|
VAStatus
|
|
|
|
|
vlVaSyncBuffer(VADriverContextP ctx, VABufferID buf_id, uint64_t timeout_ns)
|
|
|
|
|
{
|
|
|
|
|
vlVaDriver *drv;
|
|
|
|
|
vlVaContext *context;
|
|
|
|
|
vlVaBuffer *buf;
|
|
|
|
|
|
|
|
|
|
if (!ctx)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_CONTEXT;
|
|
|
|
|
|
|
|
|
|
drv = VL_VA_DRIVER(ctx);
|
|
|
|
|
if (!drv)
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_CONTEXT;
|
|
|
|
|
|
|
|
|
|
/* Some apps like ffmpeg check for vaSyncBuffer to be present
|
|
|
|
|
to do async enqueuing of multiple vaEndPicture encode calls
|
|
|
|
|
before calling vaSyncBuffer with a pre-defined latency
|
|
|
|
|
If vaSyncBuffer is not implemented, they fallback to the
|
|
|
|
|
usual synchronous pairs of { vaEndPicture + vaSyncSurface }
|
|
|
|
|
|
|
|
|
|
As this might require the driver to support multiple
|
|
|
|
|
operations and/or store multiple feedback values before sync
|
|
|
|
|
fallback to backward compatible behaviour unless driver
|
|
|
|
|
explicitly supports PIPE_VIDEO_CAP_ENC_SUPPORTS_ASYNC_OPERATION
|
|
|
|
|
*/
|
|
|
|
|
if (!drv->pipe->screen->get_video_param(drv->pipe->screen,
|
|
|
|
|
PIPE_VIDEO_PROFILE_UNKNOWN,
|
|
|
|
|
PIPE_VIDEO_ENTRYPOINT_ENCODE,
|
|
|
|
|
PIPE_VIDEO_CAP_ENC_SUPPORTS_ASYNC_OPERATION))
|
|
|
|
|
return VA_STATUS_ERROR_UNIMPLEMENTED;
|
|
|
|
|
|
|
|
|
|
/* vaSyncBuffer spec states that "If timeout is zero, the function returns immediately." */
|
|
|
|
|
if (timeout_ns == 0)
|
|
|
|
|
return VA_STATUS_ERROR_TIMEDOUT;
|
|
|
|
|
|
|
|
|
|
if (timeout_ns != VA_TIMEOUT_INFINITE)
|
|
|
|
|
return VA_STATUS_ERROR_UNIMPLEMENTED;
|
|
|
|
|
|
|
|
|
|
mtx_lock(&drv->mutex);
|
|
|
|
|
buf = handle_table_get(drv->htab, buf_id);
|
|
|
|
|
|
|
|
|
|
if (!buf) {
|
|
|
|
|
mtx_unlock(&drv->mutex);
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_BUFFER;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!buf->feedback) {
|
|
|
|
|
/* No outstanding operation: nothing to do. */
|
|
|
|
|
mtx_unlock(&drv->mutex);
|
|
|
|
|
return VA_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context = handle_table_get(drv->htab, buf->ctx);
|
|
|
|
|
if (!context) {
|
|
|
|
|
mtx_unlock(&drv->mutex);
|
|
|
|
|
return VA_STATUS_ERROR_INVALID_CONTEXT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vlVaSurface* surf = handle_table_get(drv->htab, buf->associated_encode_input_surf);
|
|
|
|
|
|
|
|
|
|
if ((buf->feedback) && (context->decoder->entrypoint == PIPE_VIDEO_ENTRYPOINT_ENCODE)) {
|
|
|
|
|
context->decoder->get_feedback(context->decoder, buf->feedback, &(buf->coded_size));
|
|
|
|
|
buf->feedback = NULL;
|
|
|
|
|
/* Also mark the associated render target (encode source texture) surface as done
|
|
|
|
|
in case they call vaSyncSurface on it to avoid getting the feedback twice*/
|
|
|
|
|
if(surf)
|
|
|
|
|
{
|
|
|
|
|
surf->feedback = NULL;
|
|
|
|
|
buf->associated_encode_input_surf = VA_INVALID_ID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mtx_unlock(&drv->mutex);
|
|
|
|
|
return VA_STATUS_SUCCESS;
|
|
|
|
|
}
|
2022-09-22 12:53:25 -04:00
|
|
|
#endif
|