2013-10-17 13:21:40 +01:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright 2013 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.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
2020-03-27 19:42:29 +00:00
|
|
|
#include "radeon_video.h"
|
2013-10-17 13:21:40 +01:00
|
|
|
|
2020-03-27 19:42:29 +00:00
|
|
|
#include "radeon_vce.h"
|
|
|
|
#include "radeonsi/si_pipe.h"
|
2013-10-17 13:21:40 +01:00
|
|
|
#include "util/u_memory.h"
|
|
|
|
#include "util/u_video.h"
|
|
|
|
#include "vl/vl_defines.h"
|
|
|
|
#include "vl/vl_video_buffer.h"
|
|
|
|
|
2020-03-27 19:42:29 +00:00
|
|
|
#include <unistd.h>
|
2013-10-17 13:21:40 +01:00
|
|
|
|
|
|
|
/* generate an stream handle */
|
2017-09-13 01:26:26 +01:00
|
|
|
unsigned si_vid_alloc_stream_handle()
|
2013-10-17 13:21:40 +01:00
|
|
|
{
|
2020-03-27 19:42:29 +00:00
|
|
|
static unsigned counter = 0;
|
|
|
|
unsigned stream_handle = 0;
|
|
|
|
unsigned pid = getpid();
|
|
|
|
int i;
|
2013-10-17 13:21:40 +01:00
|
|
|
|
2020-03-27 19:42:29 +00:00
|
|
|
for (i = 0; i < 32; ++i)
|
|
|
|
stream_handle |= ((pid >> i) & 1) << (31 - i);
|
2013-10-17 13:21:40 +01:00
|
|
|
|
2020-03-27 19:42:29 +00:00
|
|
|
stream_handle ^= ++counter;
|
|
|
|
return stream_handle;
|
2013-10-17 13:21:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create a buffer in the winsys */
|
2020-03-27 19:42:29 +00:00
|
|
|
bool si_vid_create_buffer(struct pipe_screen *screen, struct rvid_buffer *buffer, unsigned size,
|
|
|
|
unsigned usage)
|
2013-10-17 13:21:40 +01:00
|
|
|
{
|
2020-03-27 19:42:29 +00:00
|
|
|
memset(buffer, 0, sizeof(*buffer));
|
|
|
|
buffer->usage = usage;
|
2016-09-30 10:26:13 +01:00
|
|
|
|
2020-03-27 19:42:29 +00:00
|
|
|
/* Hardware buffer placement restrictions require the kernel to be
|
|
|
|
* able to move buffers around individually, so request a
|
|
|
|
* non-sub-allocated buffer.
|
|
|
|
*/
|
|
|
|
buffer->res = si_resource(pipe_buffer_create(screen, PIPE_BIND_SHARED, usage, size));
|
2014-01-21 18:49:06 +00:00
|
|
|
|
2020-03-27 19:42:29 +00:00
|
|
|
return buffer->res != NULL;
|
2013-10-17 13:21:40 +01:00
|
|
|
}
|
|
|
|
|
2020-10-27 08:33:27 +00:00
|
|
|
/* create a tmz buffer in the winsys */
|
|
|
|
bool si_vid_create_tmz_buffer(struct pipe_screen *screen, struct rvid_buffer *buffer, unsigned size,
|
|
|
|
unsigned usage)
|
|
|
|
{
|
|
|
|
memset(buffer, 0, sizeof(*buffer));
|
|
|
|
buffer->usage = usage;
|
|
|
|
buffer->res = si_resource(pipe_buffer_create(screen, PIPE_BIND_SHARED | PIPE_BIND_PROTECTED,
|
|
|
|
usage, size));
|
|
|
|
return buffer->res != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-17 13:21:40 +01:00
|
|
|
/* destroy a buffer */
|
2017-09-13 01:26:26 +01:00
|
|
|
void si_vid_destroy_buffer(struct rvid_buffer *buffer)
|
2013-10-17 13:21:40 +01:00
|
|
|
{
|
2020-03-27 19:42:29 +00:00
|
|
|
si_resource_reference(&buffer->res, NULL);
|
2013-10-17 13:21:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* reallocate a buffer, preserving its content */
|
2018-06-19 02:07:10 +01:00
|
|
|
bool si_vid_resize_buffer(struct pipe_screen *screen, struct radeon_cmdbuf *cs,
|
2020-03-27 19:42:29 +00:00
|
|
|
struct rvid_buffer *new_buf, unsigned new_size)
|
2013-10-17 13:21:40 +01:00
|
|
|
{
|
2020-03-27 19:42:29 +00:00
|
|
|
struct si_screen *sscreen = (struct si_screen *)screen;
|
|
|
|
struct radeon_winsys *ws = sscreen->ws;
|
|
|
|
unsigned bytes = MIN2(new_buf->res->buf->size, new_size);
|
|
|
|
struct rvid_buffer old_buf = *new_buf;
|
|
|
|
void *src = NULL, *dst = NULL;
|
|
|
|
|
|
|
|
if (!si_vid_create_buffer(screen, new_buf, new_size, new_buf->usage))
|
|
|
|
goto error;
|
|
|
|
|
2021-03-23 22:33:41 +00:00
|
|
|
src = ws->buffer_map(ws, old_buf.res->buf, cs, PIPE_MAP_READ | RADEON_MAP_TEMPORARY);
|
2020-03-27 19:42:29 +00:00
|
|
|
if (!src)
|
|
|
|
goto error;
|
|
|
|
|
2021-03-23 22:33:41 +00:00
|
|
|
dst = ws->buffer_map(ws, new_buf->res->buf, cs, PIPE_MAP_WRITE | RADEON_MAP_TEMPORARY);
|
2020-03-27 19:42:29 +00:00
|
|
|
if (!dst)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
memcpy(dst, src, bytes);
|
|
|
|
if (new_size > bytes) {
|
|
|
|
new_size -= bytes;
|
|
|
|
dst += bytes;
|
|
|
|
memset(dst, 0, new_size);
|
|
|
|
}
|
2021-03-23 22:33:41 +00:00
|
|
|
ws->buffer_unmap(ws, new_buf->res->buf);
|
|
|
|
ws->buffer_unmap(ws, old_buf.res->buf);
|
2020-03-27 19:42:29 +00:00
|
|
|
si_vid_destroy_buffer(&old_buf);
|
|
|
|
return true;
|
2013-10-17 13:21:40 +01:00
|
|
|
|
|
|
|
error:
|
2020-03-27 19:42:29 +00:00
|
|
|
if (src)
|
2021-03-23 22:33:41 +00:00
|
|
|
ws->buffer_unmap(ws, old_buf.res->buf);
|
2020-03-27 19:42:29 +00:00
|
|
|
si_vid_destroy_buffer(new_buf);
|
|
|
|
*new_buf = old_buf;
|
|
|
|
return false;
|
2013-10-17 13:21:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* clear the buffer with zeros */
|
2020-03-27 19:42:29 +00:00
|
|
|
void si_vid_clear_buffer(struct pipe_context *context, struct rvid_buffer *buffer)
|
2013-10-17 13:21:40 +01:00
|
|
|
{
|
2020-03-27 19:42:29 +00:00
|
|
|
struct si_context *sctx = (struct si_context *)context;
|
2020-12-03 22:57:45 +00:00
|
|
|
uint32_t zero = 0;
|
2013-10-17 13:21:40 +01:00
|
|
|
|
2020-12-03 22:57:45 +00:00
|
|
|
sctx->b.clear_buffer(&sctx->b, &buffer->res->b.b, 0, buffer->res->b.b.width0, &zero, 4);
|
2020-03-27 19:42:29 +00:00
|
|
|
context->flush(context, NULL, 0);
|
2013-10-17 13:21:40 +01:00
|
|
|
}
|