frontends/va: Allow drivers to allocate and use encode DPB surface buffers

Drivers can now allocate these buffers and use them directly.

(cherry picked from commit a4ef6eccb5c78c8080a944d8dd08f829902afc60)
See https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30843#note_2544865
for more details about discussion/cherry-picking.

Signed-off-by: David Rosca <david.rosca@amd.com>
Reviewed-By: Sil Vilerino <sivileri@microsoft.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30908>
This commit is contained in:
David Rosca
2024-08-25 10:49:39 +02:00
committed by Marge Bot
parent bab6f2a1ec
commit e751cb074a
4 changed files with 43 additions and 0 deletions

View File

@@ -72,6 +72,12 @@ vlVaHandleVAEncPictureParameterBufferTypeH264(vlVaDriver *drv, vlVaContext *cont
if (!context->desc.h264enc.dpb[i].id) {
assert(!surf->is_dpb);
surf->is_dpb = true;
if (surf->buffer) {
surf->buffer->destroy(surf->buffer);
surf->buffer = NULL;
}
if (context->decoder && context->decoder->create_dpb_buffer)
surf->buffer = context->decoder->create_dpb_buffer(context->decoder, &context->desc.base, &surf->templat);
vlVaSetSurfaceContext(drv, surf, context);
context->desc.h264enc.dpb_size++;
break;
@@ -84,6 +90,7 @@ vlVaHandleVAEncPictureParameterBufferTypeH264(vlVaDriver *drv, vlVaContext *cont
context->desc.h264enc.dpb[i].frame_idx = h264->CurrPic.frame_idx;
context->desc.h264enc.dpb[i].pic_order_cnt = h264->CurrPic.TopFieldOrderCnt;
context->desc.h264enc.dpb[i].is_ltr = h264->CurrPic.flags & VA_PICTURE_H264_LONG_TERM_REFERENCE;
context->desc.h264enc.dpb[i].buffer = surf->buffer;
context->desc.h264enc.p_remain = context->desc.h264enc.gop_size - context->desc.h264enc.gop_cnt - context->desc.h264enc.i_remain;
@@ -240,6 +247,16 @@ vlVaHandleVAEncSequenceParameterBufferTypeH264(vlVaDriver *drv, vlVaContext *con
if (!context->decoder)
return VA_STATUS_ERROR_ALLOCATION_FAILED;
struct pipe_h264_enc_dpb_entry *dpb =
&context->desc.h264enc.dpb[context->desc.h264enc.dpb_curr_pic];
if (dpb->id && !dpb->buffer && context->decoder->create_dpb_buffer) {
vlVaSurface *surf = handle_table_get(drv->htab, dpb->id);
if (!surf)
return VA_STATUS_ERROR_INVALID_PARAMETER;
surf->buffer = context->decoder->create_dpb_buffer(context->decoder, &context->desc.base, &surf->templat);
dpb->buffer = surf->buffer;
}
getEncParamPresetH264(context);
context->desc.h264enc.rate_ctrl[0].vbv_buffer_size = 20000000;
context->desc.h264enc.rate_ctrl[0].vbv_buf_lv = 48;

View File

@@ -80,6 +80,12 @@ vlVaHandleVAEncPictureParameterBufferTypeHEVC(vlVaDriver *drv, vlVaContext *cont
if (!context->desc.h265enc.dpb[i].id) {
assert(!surf->is_dpb);
surf->is_dpb = true;
if (surf->buffer) {
surf->buffer->destroy(surf->buffer);
surf->buffer = NULL;
}
if (context->decoder && context->decoder->create_dpb_buffer)
surf->buffer = context->decoder->create_dpb_buffer(context->decoder, &context->desc.base, &surf->templat);
vlVaSetSurfaceContext(drv, surf, context);
context->desc.h265enc.dpb_size++;
break;
@@ -91,6 +97,7 @@ vlVaHandleVAEncPictureParameterBufferTypeHEVC(vlVaDriver *drv, vlVaContext *cont
context->desc.h265enc.dpb[i].id = h265->decoded_curr_pic.picture_id;
context->desc.h265enc.dpb[i].pic_order_cnt = h265->decoded_curr_pic.pic_order_cnt;
context->desc.h265enc.dpb[i].is_ltr = h265->decoded_curr_pic.flags & VA_PICTURE_HEVC_LONG_TERM_REFERENCE;
context->desc.h265enc.dpb[i].buffer = surf->buffer;
context->desc.h265enc.pic_order_cnt = h265->decoded_curr_pic.pic_order_cnt;
coded_buf = handle_table_get(drv->htab, h265->coded_buf);
@@ -251,6 +258,16 @@ vlVaHandleVAEncSequenceParameterBufferTypeHEVC(vlVaDriver *drv, vlVaContext *con
if (!context->decoder)
return VA_STATUS_ERROR_ALLOCATION_FAILED;
struct pipe_h265_enc_dpb_entry *dpb =
&context->desc.h265enc.dpb[context->desc.h265enc.dpb_curr_pic];
if (dpb->id && !dpb->buffer && context->decoder->create_dpb_buffer) {
vlVaSurface *surf = handle_table_get(drv->htab, dpb->id);
if (!surf)
return VA_STATUS_ERROR_INVALID_PARAMETER;
surf->buffer = context->decoder->create_dpb_buffer(context->decoder, &context->desc.base, &surf->templat);
dpb->buffer = surf->buffer;
}
getEncParamPresetH265(context);
context->desc.h265enc.rc[0].vbv_buffer_size = 20000000;
context->desc.h265enc.rc[0].vbv_buf_lv = 48;

View File

@@ -201,6 +201,13 @@ struct pipe_video_codec
struct pipe_picture_desc *picture,
void* bitstream_buf,
unsigned *size);
/**
* Creates a DPB buffer used for a single reconstructed picture.
*/
struct pipe_video_buffer *(*create_dpb_buffer)(struct pipe_video_codec *codec,
struct pipe_picture_desc *picture,
const struct pipe_video_buffer *templat);
};
/**

View File

@@ -719,6 +719,7 @@ struct pipe_h264_enc_dpb_entry
uint32_t frame_idx;
uint32_t pic_order_cnt;
bool is_ltr;
struct pipe_video_buffer *buffer;
};
struct pipe_h264_enc_picture_desc
@@ -1106,6 +1107,7 @@ struct pipe_h265_enc_dpb_entry
uint32_t id;
uint32_t pic_order_cnt;
bool is_ltr;
struct pipe_video_buffer *buffer;
};
struct pipe_h265_enc_picture_desc