In preparation to using buffers clears with the hw engine(s).
v2: split out flipping to using hw buffer clears.
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
unsigned stream_handle;
unsigned frame_number;
+ struct pipe_screen *screen;
struct radeon_winsys* ws;
struct radeon_winsys_cs* cs;
buf = &dec->msg_fb_buffers[dec->cur_buffer];
/* and map it for CPU access */
- ptr = dec->ws->buffer_map(buf->cs_handle, dec->cs, PIPE_TRANSFER_WRITE);
+ ptr = dec->ws->buffer_map(buf->res->cs_buf, dec->cs, PIPE_TRANSFER_WRITE);
/* calc buffer offsets */
dec->msg = (struct ruvd_msg *)ptr;
buf = &dec->msg_fb_buffers[dec->cur_buffer];
/* unmap the buffer */
- dec->ws->buffer_unmap(buf->cs_handle);
+ dec->ws->buffer_unmap(buf->res->cs_buf);
dec->msg = NULL;
dec->fb = NULL;
/* and send it to the hardware */
- send_cmd(dec, RUVD_CMD_MSG_BUFFER, buf->cs_handle, 0,
+ send_cmd(dec, RUVD_CMD_MSG_BUFFER, buf->res->cs_buf, 0,
RADEON_USAGE_READ, RADEON_DOMAIN_GTT);
}
dec->bs_size = 0;
dec->bs_ptr = dec->ws->buffer_map(
- dec->bs_buffers[dec->cur_buffer].cs_handle,
+ dec->bs_buffers[dec->cur_buffer].res->cs_buf,
dec->cs, PIPE_TRANSFER_WRITE);
}
struct rvid_buffer *buf = &dec->bs_buffers[dec->cur_buffer];
unsigned new_size = dec->bs_size + sizes[i];
- if (new_size > buf->buf->size) {
- dec->ws->buffer_unmap(buf->cs_handle);
- if (!rvid_resize_buffer(dec->ws, dec->cs, buf, new_size)) {
+ if (new_size > buf->res->buf->size) {
+ dec->ws->buffer_unmap(buf->res->cs_buf);
+ if (!rvid_resize_buffer(dec->screen, dec->cs, buf, new_size)) {
RVID_ERR("Can't resize bitstream buffer!");
return;
}
- dec->bs_ptr = dec->ws->buffer_map(buf->cs_handle, dec->cs,
+ dec->bs_ptr = dec->ws->buffer_map(buf->res->cs_buf, dec->cs,
PIPE_TRANSFER_WRITE);
if (!dec->bs_ptr)
return;
bs_size = align(dec->bs_size, 128);
memset(dec->bs_ptr, 0, bs_size - dec->bs_size);
- dec->ws->buffer_unmap(bs_buf->cs_handle);
+ dec->ws->buffer_unmap(bs_buf->res->cs_buf);
map_msg_fb_buf(dec);
dec->msg->size = sizeof(*dec->msg);
dec->msg->body.decode.width_in_samples = dec->base.width;
dec->msg->body.decode.height_in_samples = dec->base.height;
- dec->msg->body.decode.dpb_size = dec->dpb.buf->size;
+ dec->msg->body.decode.dpb_size = dec->dpb.res->buf->size;
dec->msg->body.decode.bsd_size = bs_size;
dt = dec->set_dtb(dec->msg, (struct vl_video_buffer *)target);
send_msg_buf(dec);
- send_cmd(dec, RUVD_CMD_DPB_BUFFER, dec->dpb.cs_handle, 0,
+ send_cmd(dec, RUVD_CMD_DPB_BUFFER, dec->dpb.res->cs_buf, 0,
RADEON_USAGE_READWRITE, RADEON_DOMAIN_VRAM);
- send_cmd(dec, RUVD_CMD_BITSTREAM_BUFFER, bs_buf->cs_handle,
+ send_cmd(dec, RUVD_CMD_BITSTREAM_BUFFER, bs_buf->res->cs_buf,
0, RADEON_USAGE_READ, RADEON_DOMAIN_GTT);
send_cmd(dec, RUVD_CMD_DECODING_TARGET_BUFFER, dt, 0,
RADEON_USAGE_WRITE, RADEON_DOMAIN_VRAM);
- send_cmd(dec, RUVD_CMD_FEEDBACK_BUFFER, msg_fb_buf->cs_handle,
+ send_cmd(dec, RUVD_CMD_FEEDBACK_BUFFER, msg_fb_buf->res->cs_buf,
FB_BUFFER_OFFSET, RADEON_USAGE_WRITE, RADEON_DOMAIN_GTT);
set_reg(dec, RUVD_ENGINE_CNTL, 1);
dec->set_dtb = set_dtb;
dec->stream_handle = rvid_alloc_stream_handle();
+ dec->screen = context->screen;
dec->ws = ws;
dec->cs = ws->cs_create(ws, RING_UVD, NULL, NULL, NULL);
if (!dec->cs) {
for (i = 0; i < NUM_BUFFERS; ++i) {
unsigned msg_fb_size = FB_BUFFER_OFFSET + FB_BUFFER_SIZE;
STATIC_ASSERT(sizeof(struct ruvd_msg) <= FB_BUFFER_OFFSET);
- if (!rvid_create_buffer(dec->ws, &dec->msg_fb_buffers[i], msg_fb_size,
- RADEON_DOMAIN_VRAM, 0)) {
+ if (!rvid_create_buffer(dec->screen, &dec->msg_fb_buffers[i],
+ msg_fb_size, PIPE_USAGE_DEFAULT)) {
RVID_ERR("Can't allocated message buffers.\n");
goto error;
}
- if (!rvid_create_buffer(dec->ws, &dec->bs_buffers[i], bs_buf_size,
- RADEON_DOMAIN_GTT, 0)) {
+ if (!rvid_create_buffer(dec->screen, &dec->bs_buffers[i],
+ bs_buf_size, PIPE_USAGE_STAGING)) {
RVID_ERR("Can't allocated bitstream buffers.\n");
goto error;
}
rvid_clear_buffer(dec->ws, dec->cs, &dec->bs_buffers[i]);
}
- if (!rvid_create_buffer(dec->ws, &dec->dpb, dpb_size, RADEON_DOMAIN_VRAM, 0)) {
+ if (!rvid_create_buffer(dec->screen, &dec->dpb, dpb_size, PIPE_USAGE_DEFAULT)) {
RVID_ERR("Can't allocated dpb.\n");
goto error;
}
dec->msg->body.create.stream_type = profile2stream_type(dec->base.profile);
dec->msg->body.create.width_in_samples = dec->base.width;
dec->msg->body.create.height_in_samples = dec->base.height;
- dec->msg->body.create.dpb_size = dec->dpb.buf->size;
+ dec->msg->body.create.dpb_size = dec->dpb.res->buf->size;
send_msg_buf(dec);
flush(dec);
next_buffer(dec);
#if 0
static void dump_feedback(struct rvce_encoder *enc, struct rvid_buffer *fb)
{
- uint32_t *ptr = enc->ws->buffer_map(fb->cs_handle, enc->cs, PIPE_TRANSFER_READ_WRITE);
+ uint32_t *ptr = enc->ws->buffer_map(fb->res->cs_buf, enc->cs, PIPE_TRANSFER_READ_WRITE);
unsigned i = 0;
fprintf(stderr, "\n");
fprintf(stderr, "encStatus:\t\t\t%08x\n", ptr[i++]);
fprintf(stderr, "seiPrivatePackageOffset:\t%08x\n", ptr[i++]);
fprintf(stderr, "seiPrivatePackageSize:\t\t%08x\n", ptr[i++]);
fprintf(stderr, "\n");
- enc->ws->buffer_unmap(fb->cs_handle);
+ enc->ws->buffer_unmap(fb->res->cs_buf);
}
#endif
struct rvce_encoder *enc = (struct rvce_encoder*)encoder;
if (enc->stream_handle) {
struct rvid_buffer fb;
- rvid_create_buffer(enc->ws, &fb, 512, RADEON_DOMAIN_GTT, 0);
+ rvid_create_buffer(enc->screen, &fb, 512, PIPE_USAGE_STAGING);
enc->fb = &fb;
enc->session(enc);
enc->feedback(enc);
if (!enc->stream_handle) {
struct rvid_buffer fb;
enc->stream_handle = rvid_alloc_stream_handle();
- rvid_create_buffer(enc->ws, &fb, 512, RADEON_DOMAIN_GTT, 0);
+ rvid_create_buffer(enc->screen, &fb, 512, PIPE_USAGE_STAGING);
enc->fb = &fb;
enc->session(enc);
enc->create(enc);
enc->bs_size = destination->width0;
*fb = enc->fb = CALLOC_STRUCT(rvid_buffer);
- if (!rvid_create_buffer(enc->ws, enc->fb, 512, RADEON_DOMAIN_GTT, 0)) {
+ if (!rvid_create_buffer(enc->screen, enc->fb, 512, PIPE_USAGE_STAGING)) {
RVID_ERR("Can't create feedback buffer.\n");
return;
}
struct rvid_buffer *fb = feedback;
if (size) {
- uint32_t *ptr = enc->ws->buffer_map(fb->cs_handle, enc->cs, PIPE_TRANSFER_READ_WRITE);
+ uint32_t *ptr = enc->ws->buffer_map(fb->res->cs_buf, enc->cs, PIPE_TRANSFER_READ_WRITE);
if (ptr[1]) {
*size = ptr[4] - ptr[9];
*size = 0;
}
- enc->ws->buffer_unmap(fb->cs_handle);
+ enc->ws->buffer_unmap(fb->res->cs_buf);
}
//dump_feedback(enc, fb);
rvid_destroy_buffer(fb);
enc->base.get_feedback = rvce_get_feedback;
enc->get_buffer = get_buffer;
+ enc->screen = context->screen;
enc->ws = ws;
enc->cs = ws->cs_create(ws, RING_VCE, rvce_cs_flush, enc, NULL);
if (!enc->cs) {
cpb_size = cpb_size * 3 / 2;
cpb_size = cpb_size * enc->cpb_num;
tmp_buf->destroy(tmp_buf);
- if (!rvid_create_buffer(enc->ws, &enc->cpb, cpb_size, RADEON_DOMAIN_VRAM, 0)) {
+ if (!rvid_create_buffer(enc->screen, &enc->cpb, cpb_size, PIPE_USAGE_DEFAULT)) {
RVID_ERR("Can't create CPB buffer.\n");
goto error;
}
unsigned stream_handle;
+ struct pipe_screen *screen;
struct radeon_winsys* ws;
struct radeon_winsys_cs* cs;
#include "vl/vl_video_buffer.h"
#include "radeon/drm/radeon_winsys.h"
+#include "r600_pipe_common.h"
#include "radeon_video.h"
#include "radeon_vce.h"
static void feedback(struct rvce_encoder *enc)
{
RVCE_BEGIN(0x05000005); // feedback buffer
- RVCE_WRITE(enc->fb->cs_handle, enc->fb->domain); // feedbackRingAddressHi
+ RVCE_WRITE(enc->fb->res->cs_buf, enc->fb->res->domains); // feedbackRingAddressHi
RVCE_CS(0x00000000); // feedbackRingAddressLo
RVCE_CS(0x00000001); // feedbackRingSize
RVCE_END();
task_info(enc, 0x00000003);
RVCE_BEGIN(0x05000001); // context buffer
- RVCE_READWRITE(enc->cpb.cs_handle, enc->cpb.domain); // encodeContextAddressHi
+ RVCE_READWRITE(enc->cpb.res->cs_buf, enc->cpb.res->domains); // encodeContextAddressHi
RVCE_CS(0x00000000); // encodeContextAddressLo
RVCE_END();
}
/* create a buffer in the winsys */
-bool rvid_create_buffer(struct radeon_winsys *ws, struct rvid_buffer *buffer,
- unsigned size, enum radeon_bo_domain domain,
- enum radeon_bo_flag flags)
+bool rvid_create_buffer(struct pipe_screen *screen, struct rvid_buffer *buffer,
+ unsigned size, unsigned usage)
{
- buffer->domain = domain;
- buffer->flags = flags;
+ memset(buffer, 0, sizeof(*buffer));
+ buffer->usage = usage;
+ buffer->res = (struct r600_resource *)
+ pipe_buffer_create(screen, PIPE_BIND_CUSTOM, usage, size);
- buffer->buf = ws->buffer_create(ws, size, 4096, false, domain, flags);
- if (!buffer->buf)
- return false;
-
- buffer->cs_handle = ws->buffer_get_cs_handle(buffer->buf);
- if (!buffer->cs_handle)
- return false;
-
- return true;
+ return buffer->res != NULL;
}
/* destroy a buffer */
void rvid_destroy_buffer(struct rvid_buffer *buffer)
{
- pb_reference(&buffer->buf, NULL);
- buffer->cs_handle = NULL;
+ pipe_resource_reference((struct pipe_resource **)&buffer->res, NULL);
}
/* reallocate a buffer, preserving its content */
-bool rvid_resize_buffer(struct radeon_winsys *ws, struct radeon_winsys_cs *cs,
+bool rvid_resize_buffer(struct pipe_screen *screen, struct radeon_winsys_cs *cs,
struct rvid_buffer *new_buf, unsigned new_size)
{
- unsigned bytes = MIN2(new_buf->buf->size, new_size);
+ struct r600_common_screen *rscreen = (struct r600_common_screen *)screen;
+ struct radeon_winsys* ws = rscreen->ws;
+ unsigned bytes = MIN2(new_buf->res->buf->size, new_size);
struct rvid_buffer old_buf = *new_buf;
void *src = NULL, *dst = NULL;
- if (!rvid_create_buffer(ws, new_buf, new_size, new_buf->domain,
- new_buf->flags))
+ if (!rvid_create_buffer(screen, new_buf, new_size, new_buf->usage))
goto error;
- src = ws->buffer_map(old_buf.cs_handle, cs, PIPE_TRANSFER_READ);
+ src = ws->buffer_map(old_buf.res->cs_buf, cs, PIPE_TRANSFER_READ);
if (!src)
goto error;
- dst = ws->buffer_map(new_buf->cs_handle, cs, PIPE_TRANSFER_WRITE);
+ dst = ws->buffer_map(new_buf->res->cs_buf, cs, PIPE_TRANSFER_WRITE);
if (!dst)
goto error;
dst += bytes;
memset(dst, 0, new_size);
}
- ws->buffer_unmap(new_buf->cs_handle);
- ws->buffer_unmap(old_buf.cs_handle);
+ ws->buffer_unmap(new_buf->res->cs_buf);
+ ws->buffer_unmap(old_buf.res->cs_buf);
rvid_destroy_buffer(&old_buf);
return true;
error:
if (src)
- ws->buffer_unmap(old_buf.cs_handle);
+ ws->buffer_unmap(old_buf.res->cs_buf);
rvid_destroy_buffer(new_buf);
*new_buf = old_buf;
return false;
/* clear the buffer with zeros */
void rvid_clear_buffer(struct radeon_winsys *ws, struct radeon_winsys_cs *cs, struct rvid_buffer* buffer)
{
- void *ptr = ws->buffer_map(buffer->cs_handle, cs, PIPE_TRANSFER_WRITE);
- if (!ptr)
- return;
+ void *ptr = ws->buffer_map(buffer->res->cs_buf, cs, PIPE_TRANSFER_WRITE);
+ if (!ptr)
+ return;
- memset(ptr, 0, buffer->buf->size);
- ws->buffer_unmap(buffer->cs_handle);
+ memset(ptr, 0, buffer->res->buf->size);
+ ws->buffer_unmap(buffer->res->cs_buf);
}
/**
/* video buffer representation */
struct rvid_buffer
{
- enum radeon_bo_domain domain;
- enum radeon_bo_flag flags;
- struct pb_buffer* buf;
- struct radeon_winsys_cs_handle* cs_handle;
+ unsigned usage;
+ struct r600_resource *res;
};
/* generate an stream handle */
unsigned rvid_alloc_stream_handle(void);
/* create a buffer in the winsys */
-bool rvid_create_buffer(struct radeon_winsys *ws, struct rvid_buffer *buffer,
- unsigned size, enum radeon_bo_domain domain,
- enum radeon_bo_flag flags);
+bool rvid_create_buffer(struct pipe_screen *screen, struct rvid_buffer *buffer,
+ unsigned size, unsigned usage);
/* destroy a buffer */
void rvid_destroy_buffer(struct rvid_buffer *buffer);
/* reallocate a buffer, preserving its content */
-bool rvid_resize_buffer(struct radeon_winsys *ws, struct radeon_winsys_cs *cs,
+bool rvid_resize_buffer(struct pipe_screen *screen, struct radeon_winsys_cs *cs,
struct rvid_buffer *new_buf, unsigned new_size);
/* clear the buffer with zeros */