<div dir="ltr">On 15 June 2016 at 14:07, Christian König <span dir="ltr"><<a href="mailto:deathsimple@vodafone.de" target="_blank">deathsimple@vodafone.de</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Please split that up into multiple parts. E.g. adding the config structure, new image format support etc..<br>
<br>
Julien, can you take a look as well if you have time and work a bit with Boyuan to get this cleaned up?<br></blockquote><div><br></div><div>Hi,<br></div><div>I'll be happy to do that, I can find some time next week I think.<br></div><div>Cheers<br></div><div>Julien<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Thanks in advance,<br>
Christian.<div class="HOEnZb"><div class="h5"><br>
<br>
Am 14.06.2016 um 22:14 schrieb Boyuan Zhang:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Signed-off-by: Boyuan Zhang <<a href="mailto:boyuan.zhang@amd.com" target="_blank">boyuan.zhang@amd.com</a>><br>
---<br>
src/gallium/state_trackers/va/buffer.c | 6 ++<br>
src/gallium/state_trackers/va/config.c | 104 +++++++++++++++---<br>
src/gallium/state_trackers/va/context.c | 72 ++++++++-----<br>
src/gallium/state_trackers/va/image.c | 126 +++++++++++++++++++---<br>
src/gallium/state_trackers/va/picture.c | 165 ++++++++++++++++++++++++++++-<br>
src/gallium/state_trackers/va/surface.c | 16 ++-<br>
src/gallium/state_trackers/va/va_private.h | 9 ++<br>
7 files changed, 441 insertions(+), 57 deletions(-)<br>
<br>
diff --git a/src/gallium/state_trackers/va/buffer.c b/src/gallium/state_trackers/va/buffer.c<br>
index 7d3167b..dfcebbe 100644<br>
--- a/src/gallium/state_trackers/va/buffer.c<br>
+++ b/src/gallium/state_trackers/va/buffer.c<br>
@@ -133,6 +133,12 @@ vlVaMapBuffer(VADriverContextP ctx, VABufferID buf_id, void **pbuff)<br>
if (!buf->derived_surface.transfer || !*pbuff)<br>
return VA_STATUS_ERROR_INVALID_BUFFER;<br>
+ if (buf->type == VAEncCodedBufferType) {<br>
+ ((VACodedBufferSegment*)buf->data)->buf = *pbuff;<br>
+ ((VACodedBufferSegment*)buf->data)->size = buf->coded_size;<br>
+ ((VACodedBufferSegment*)buf->data)->next = NULL;<br>
+ *pbuff = buf->data;<br>
+ }<br>
} else {<br>
pipe_mutex_unlock(drv->mutex);<br>
*pbuff = buf->data;<br>
diff --git a/src/gallium/state_trackers/va/config.c b/src/gallium/state_trackers/va/config.c<br>
index 9ca0aa8..04d214d 100644<br>
--- a/src/gallium/state_trackers/va/config.c<br>
+++ b/src/gallium/state_trackers/va/config.c<br>
@@ -34,6 +34,8 @@<br>
#include "va_private.h"<br>
+#include "util/u_handle_table.h"<br>
+<br>
DEBUG_GET_ONCE_BOOL_OPTION(mpeg4, "VAAPI_MPEG4_ENABLED", false)<br>
VAStatus<br>
@@ -72,6 +74,7 @@ vlVaQueryConfigEntrypoints(VADriverContextP ctx, VAProfile profile,<br>
{<br>
struct pipe_screen *pscreen;<br>
enum pipe_video_profile p;<br>
+ int va_status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;<br>
if (!ctx)<br>
return VA_STATUS_ERROR_INVALID_CONTEXT;<br>
@@ -88,12 +91,18 @@ vlVaQueryConfigEntrypoints(VADriverContextP ctx, VAProfile profile,<br>
return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;<br>
pscreen = VL_VA_PSCREEN(ctx);<br>
- if (!pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM, PIPE_VIDEO_CAP_SUPPORTED))<br>
- return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;<br>
-<br>
- entrypoint_list[(*num_entrypoints)++] = VAEntrypointVLD;<br>
+ if (pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM, PIPE_VIDEO_CAP_SUPPORTED)) {<br>
+ entrypoint_list[(*num_entrypoints)++] = VAEntrypointVLD;<br>
+ va_status = VA_STATUS_SUCCESS;<br>
+ }<br>
+ if (pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_ENCODE, PIPE_VIDEO_CAP_SUPPORTED) &&<br>
+ p == PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE) {<br>
+ entrypoint_list[(*num_entrypoints)++] = VAEntrypointEncSlice;<br>
+ entrypoint_list[(*num_entrypoints)++] = VAEntrypointEncPicture;<br>
+ va_status = VA_STATUS_SUCCESS;<br>
+ }<br>
- return VA_STATUS_SUCCESS;<br>
+ return va_status;<br>
}<br>
VAStatus<br>
@@ -112,7 +121,7 @@ vlVaGetConfigAttributes(VADriverContextP ctx, VAProfile profile, VAEntrypoint en<br>
value = VA_RT_FORMAT_YUV420;<br>
break;<br>
case VAConfigAttribRateControl:<br>
- value = VA_RC_NONE;<br>
+ value = VA_RC_CQP | VA_RC_CBR;<br>
break;<br>
default:<br>
value = VA_ATTRIB_NOT_SUPPORTED;<br>
@@ -128,14 +137,27 @@ VAStatus<br>
vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint,<br>
VAConfigAttrib *attrib_list, int num_attribs, VAConfigID *config_id)<br>
{<br>
+ vlVaDriver *drv;<br>
+ vlVaConfig *config;<br>
struct pipe_screen *pscreen;<br>
enum pipe_video_profile p;<br>
if (!ctx)<br>
return VA_STATUS_ERROR_INVALID_CONTEXT;<br>
+ drv = VL_VA_DRIVER(ctx);<br>
+<br>
+ if (!drv)<br>
+ return VA_STATUS_ERROR_INVALID_CONTEXT;<br>
+<br>
+ config = CALLOC(1, sizeof(vlVaConfig));<br>
+ if (!config)<br>
+ return VA_STATUS_ERROR_ALLOCATION_FAILED;<br>
+<br>
if (profile == VAProfileNone && entrypoint == VAEntrypointVideoProc) {<br>
- *config_id = PIPE_VIDEO_PROFILE_UNKNOWN;<br>
+ config->entrypoint = VAEntrypointVideoProc;<br>
+ config->profile = PIPE_VIDEO_PROFILE_UNKNOWN;<br>
+ *config_id = handle_table_add(drv->htab, config);<br>
return VA_STATUS_SUCCESS;<br>
}<br>
@@ -144,13 +166,36 @@ vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoin<br>
return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;<br>
pscreen = VL_VA_PSCREEN(ctx);<br>
- if (!pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM, PIPE_VIDEO_CAP_SUPPORTED))<br>
- return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;<br>
-<br>
- if (entrypoint != VAEntrypointVLD)<br>
+ if (entrypoint == VAEntrypointVLD) {<br>
+ if (!pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM, PIPE_VIDEO_CAP_SUPPORTED))<br>
+ return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;<br>
+ }<br>
+ else if (entrypoint == VAEntrypointEncSlice) {<br>
+ if (!pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_ENCODE, PIPE_VIDEO_CAP_SUPPORTED))<br>
+ return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;<br>
+ }<br>
+ else<br>
return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;<br>
- *config_id = p;<br>
+ if (entrypoint == VAEntrypointEncSlice || entrypoint == VAEntrypointEncPicture)<br>
+ config->entrypoint = PIPE_VIDEO_ENTRYPOINT_ENCODE;<br>
+ else<br>
+ config->entrypoint = PIPE_VIDEO_ENTRYPOINT_BITSTREAM;<br>
+<br>
+ config->profile = p;<br>
+<br>
+ for (int i = 0; i <num_attribs ; i++) {<br>
+ if (attrib_list[i].type == VAConfigAttribRateControl) {<br>
+ if (attrib_list[i].value == VA_RC_CBR)<br>
+ config->rc = PIPE_H264_ENC_RATE_CONTROL_METHOD_CONSTANT;<br>
+ else if (attrib_list[i].value == VA_RC_VBR)<br>
+ config->rc = PIPE_H264_ENC_RATE_CONTROL_METHOD_VARIABLE;<br>
+ else<br>
+ config->rc = PIPE_H264_ENC_RATE_CONTROL_METHOD_DISABLE;<br>
+ }<br>
+ }<br>
+<br>
+ *config_id = handle_table_add(drv->htab, config);<br>
return VA_STATUS_SUCCESS;<br>
}<br>
@@ -158,9 +203,25 @@ vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoin<br>
VAStatus<br>
vlVaDestroyConfig(VADriverContextP ctx, VAConfigID config_id)<br>
{<br>
+ vlVaDriver *drv;<br>
+ vlVaConfig *config;<br>
+<br>
if (!ctx)<br>
return VA_STATUS_ERROR_INVALID_CONTEXT;<br>
+ drv = VL_VA_DRIVER(ctx);<br>
+<br>
+ if (!drv)<br>
+ return VA_STATUS_ERROR_INVALID_CONTEXT;<br>
+<br>
+ config = handle_table_get(drv->htab, config_id);<br>
+<br>
+ if (!config)<br>
+ return VA_STATUS_ERROR_INVALID_CONFIG;<br>
+<br>
+ FREE(config);<br>
+ handle_table_remove(drv->htab, config_id);<br>
+<br>
return VA_STATUS_SUCCESS;<br>
}<br>
@@ -168,18 +229,31 @@ VAStatus<br>
vlVaQueryConfigAttributes(VADriverContextP ctx, VAConfigID config_id, VAProfile *profile,<br>
VAEntrypoint *entrypoint, VAConfigAttrib *attrib_list, int *num_attribs)<br>
{<br>
+ vlVaDriver *drv;<br>
+ vlVaConfig *config;<br>
+<br>
if (!ctx)<br>
return VA_STATUS_ERROR_INVALID_CONTEXT;<br>
- *profile = PipeToProfile(config_id);<br>
+ drv = VL_VA_DRIVER(ctx);<br>
+<br>
+ if (!drv)<br>
+ return VA_STATUS_ERROR_INVALID_CONTEXT;<br>
+<br>
+ config = handle_table_get(drv->htab, config_id);<br>
+<br>
+ if (!config)<br>
+ return VA_STATUS_ERROR_INVALID_CONFIG;<br>
+<br>
+ *profile = PipeToProfile(config->profile);<br>
- if (config_id == PIPE_VIDEO_PROFILE_UNKNOWN) {<br>
+ if (config->profile == PIPE_VIDEO_PROFILE_UNKNOWN) {<br>
*entrypoint = VAEntrypointVideoProc;<br>
*num_attribs = 0;<br>
return VA_STATUS_SUCCESS;<br>
}<br>
- *entrypoint = VAEntrypointVLD;<br>
+ *entrypoint = config->entrypoint;<br>
*num_attribs = 1;<br>
attrib_list[0].type = VAConfigAttribRTFormat;<br>
diff --git a/src/gallium/state_trackers/va/context.c b/src/gallium/state_trackers/va/context.c<br>
index 402fbb2..154f584 100644<br>
--- a/src/gallium/state_trackers/va/context.c<br>
+++ b/src/gallium/state_trackers/va/context.c<br>
@@ -195,18 +195,21 @@ vlVaCreateContext(VADriverContextP ctx, VAConfigID config_id, int picture_width,<br>
{<br>
vlVaDriver *drv;<br>
vlVaContext *context;<br>
+ vlVaConfig *config;<br>
int is_vpp;<br>
if (!ctx)<br>
return VA_STATUS_ERROR_INVALID_CONTEXT;<br>
- is_vpp = config_id == PIPE_VIDEO_PROFILE_UNKNOWN && !picture_width &&<br>
+ drv = VL_VA_DRIVER(ctx);<br>
+ config = handle_table_get(drv->htab, config_id);<br>
+<br>
+ is_vpp = config->profile == PIPE_VIDEO_PROFILE_UNKNOWN && !picture_width &&<br>
!picture_height && !flag && !render_targets && !num_render_targets;<br>
if (!(picture_width && picture_height) && !is_vpp)<br>
return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;<br>
- drv = VL_VA_DRIVER(ctx);<br>
context = CALLOC(1, sizeof(vlVaContext));<br>
if (!context)<br>
return VA_STATUS_ERROR_ALLOCATION_FAILED;<br>
@@ -218,13 +221,27 @@ vlVaCreateContext(VADriverContextP ctx, VAConfigID config_id, int picture_width,<br>
return VA_STATUS_ERROR_INVALID_CONTEXT;<br>
}<br>
} else {<br>
- context->templat.profile = config_id;<br>
- context->templat.entrypoint = PIPE_VIDEO_ENTRYPOINT_BITSTREAM;<br>
+ context->templat.profile = config->profile;<br>
+ context->templat.entrypoint = config->entrypoint;<br>
context->templat.chroma_format = PIPE_VIDEO_CHROMA_FORMAT_420;<br>
context->templat.width = picture_width;<br>
context->templat.height = picture_height;<br>
context->templat.expect_chunked_decode = true;<br>
+ if ((config->entrypoint == PIPE_VIDEO_ENTRYPOINT_ENCODE)<br>
+ && (u_reduce_video_profile(context->templat.profile) ==<br>
+ PIPE_VIDEO_FORMAT_MPEG4_AVC)) {<br>
+ context->templat.max_references = num_render_targets;<br>
+ context->templat.level = u_get_h264_level(context->templat.width,<br>
+ context->templat.height,<br>
+ &context->templat.max_references);<br>
+<br>
+ context->decoder = drv->pipe->create_video_codec(drv->pipe,<br>
+ &context->templat);<br>
+ if (!context->decoder)<br>
+ return VA_STATUS_ERROR_ALLOCATION_FAILED;<br>
+ }<br>
+<br>
switch (u_reduce_video_profile(context->templat.profile)) {<br>
case PIPE_VIDEO_FORMAT_MPEG12:<br>
case PIPE_VIDEO_FORMAT_VC1:<br>
@@ -234,16 +251,18 @@ vlVaCreateContext(VADriverContextP ctx, VAConfigID config_id, int picture_width,<br>
case PIPE_VIDEO_FORMAT_MPEG4_AVC:<br>
context->templat.max_references = 0;<br>
- context->desc.h264.pps = CALLOC_STRUCT(pipe_h264_pps);<br>
- if (!context->desc.h264.pps) {<br>
- FREE(context);<br>
- return VA_STATUS_ERROR_ALLOCATION_FAILED;<br>
- }<br>
- context->desc.h264.pps->sps = CALLOC_STRUCT(pipe_h264_sps);<br>
- if (!context->desc.h264.pps->sps) {<br>
- FREE(context->desc.h264.pps);<br>
- FREE(context);<br>
- return VA_STATUS_ERROR_ALLOCATION_FAILED;<br>
+ if (config->entrypoint != PIPE_VIDEO_ENTRYPOINT_ENCODE) {<br>
+ context->desc.h264.pps = CALLOC_STRUCT(pipe_h264_pps);<br>
+ if (!context->desc.h264.pps) {<br>
+ FREE(context);<br>
+ return VA_STATUS_ERROR_ALLOCATION_FAILED;<br>
+ }<br>
+ context->desc.h264.pps->sps = CALLOC_STRUCT(pipe_h264_sps);<br>
+ if (!context->desc.h264.pps->sps) {<br>
+ FREE(context->desc.h264.pps);<br>
+ FREE(context);<br>
+ return VA_STATUS_ERROR_ALLOCATION_FAILED;<br>
+ }<br>
}<br>
break;<br>
@@ -267,7 +286,10 @@ vlVaCreateContext(VADriverContextP ctx, VAConfigID config_id, int picture_width,<br>
}<br>
}<br>
- context->desc.base.profile = config_id;<br>
+ context->desc.base.profile = config->profile;<br>
+ context->desc.base.entry_point = config->entrypoint;<br>
+ if (config->entrypoint == PIPE_VIDEO_ENTRYPOINT_ENCODE)<br>
+ context->desc.h264enc.rate_ctrl.rate_ctrl_method = config->rc;<br>
pipe_mutex_lock(drv->mutex);<br>
*context_id = handle_table_add(drv->htab, context);<br>
pipe_mutex_unlock(drv->mutex);<br>
@@ -293,15 +315,17 @@ vlVaDestroyContext(VADriverContextP ctx, VAContextID context_id)<br>
}<br>
if (context->decoder) {<br>
- if (u_reduce_video_profile(context->decoder->profile) ==<br>
- PIPE_VIDEO_FORMAT_MPEG4_AVC) {<br>
- FREE(context->desc.h264.pps->sps);<br>
- FREE(context->desc.h264.pps);<br>
- }<br>
- if (u_reduce_video_profile(context->decoder->profile) ==<br>
- PIPE_VIDEO_FORMAT_HEVC) {<br>
- FREE(context->desc.h265.pps->sps);<br>
- FREE(context->desc.h265.pps);<br>
+ if (context->desc.base.entry_point != PIPE_VIDEO_ENTRYPOINT_ENCODE) {<br>
+ if (u_reduce_video_profile(context->decoder->profile) ==<br>
+ PIPE_VIDEO_FORMAT_MPEG4_AVC) {<br>
+ FREE(context->desc.h264.pps->sps);<br>
+ FREE(context->desc.h264.pps);<br>
+ }<br>
+ if (u_reduce_video_profile(context->decoder->profile) ==<br>
+ PIPE_VIDEO_FORMAT_HEVC) {<br>
+ FREE(context->desc.h265.pps->sps);<br>
+ FREE(context->desc.h265.pps);<br>
+ }<br>
}<br>
context->decoder->destroy(context->decoder);<br>
}<br>
diff --git a/src/gallium/state_trackers/va/image.c b/src/gallium/state_trackers/va/image.c<br>
index 1b956e3..168f077 100644<br>
--- a/src/gallium/state_trackers/va/image.c<br>
+++ b/src/gallium/state_trackers/va/image.c<br>
@@ -185,10 +185,12 @@ vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image)<br>
vlVaSurface *surf;<br>
vlVaBuffer *img_buf;<br>
VAImage *img;<br>
+ struct pipe_sampler_view **views;<br>
struct pipe_surface **surfaces;<br>
int w;<br>
int h;<br>
int i;<br>
+ int pitch[3];<br>
if (!ctx)<br>
return VA_STATUS_ERROR_INVALID_CONTEXT;<br>
@@ -200,7 +202,7 @@ vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image)<br>
surf = handle_table_get(drv->htab, surface);<br>
- if (!surf || !surf->buffer || surf->buffer->interlaced)<br>
+ if (!surf || !surf->buffer)<br>
return VA_STATUS_ERROR_INVALID_SURFACE;<br>
surfaces = surf->buffer->get_surfaces(surf->buffer);<br>
@@ -220,6 +222,51 @@ vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image)<br>
w = align(surf->buffer->width, 2);<br>
h = align(surf->buffer->height, 2);<br>
+ switch (img->format.fourcc) {<br>
+ case VA_FOURCC('N','V','1','2'):<br>
+ img->num_planes = 2;<br>
+ break;<br>
+<br>
+ case VA_FOURCC('I','4','2','0'):<br>
+ case VA_FOURCC('Y','V','1','2'):<br>
+ img->num_planes = 3;<br>
+ break;<br>
+<br>
+ case VA_FOURCC('U','Y','V','Y'):<br>
+ case VA_FOURCC('Y','U','Y','V'):<br>
+ case VA_FOURCC('B','G','R','A'):<br>
+ case VA_FOURCC('R','G','B','A'):<br>
+ case VA_FOURCC('B','G','R','X'):<br>
+ case VA_FOURCC('R','G','B','X'):<br>
+ img->num_planes = 1;<br>
+ break;<br>
+<br>
+ default:<br>
+ /* VaDeriveImage is designed for contiguous planes. */<br>
+ FREE(img);<br>
+ return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;<br>
+ }<br>
+<br>
+ views = surf->buffer->get_sampler_view_planes(surf->buffer);<br>
+ if (!views)<br>
+ return VA_STATUS_ERROR_OPERATION_FAILED;<br>
+<br>
+ for (i = 0; i < img->num_planes; i++) {<br>
+ unsigned width, height;<br>
+ if (!views[i]) continue;<br>
+ vlVaVideoSurfaceSize(surf, i, &width, &height);<br>
+ struct pipe_box box = {0, 0, 0, width, height, 1};<br>
+ struct pipe_transfer *transfer;<br>
+ uint8_t *map;<br>
+ map = drv->pipe->transfer_map(drv->pipe, views[i]->texture, 0,<br>
+ PIPE_TRANSFER_READ, &box, &transfer);<br>
+ if (!map)<br>
+ return VA_STATUS_ERROR_OPERATION_FAILED;<br>
+<br>
+ pitch[i] = transfer->stride;<br>
+ pipe_transfer_unmap(drv->pipe, transfer);<br>
+ }<br>
+<br>
for (i = 0; i < ARRAY_SIZE(formats); ++i) {<br>
if (img->format.fourcc == formats[i].fourcc) {<br>
img->format = formats[i];<br>
@@ -228,12 +275,33 @@ vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image)<br>
}<br>
switch (img->format.fourcc) {<br>
+ case VA_FOURCC('N','V','1','2'):<br>
+ img->num_planes = 2;<br>
+ img->pitches[0] = pitch[0];<br>
+ img->offsets[0] = 0;<br>
+ img->pitches[1] = pitch[1];<br>
+ img->offsets[1] = pitch[0] * h;<br>
+ img->data_size = pitch[0] * h + pitch[1] * h / 2;<br>
+ break;<br>
+<br>
+ case VA_FOURCC('I','4','2','0'):<br>
+ case VA_FOURCC('Y','V','1','2'):<br>
+ img->num_planes = 3;<br>
+ img->pitches[0] = pitch[0];<br>
+ img->offsets[0] = 0;<br>
+ img->pitches[1] = pitch[1];<br>
+ img->offsets[1] = pitch[0] * h;<br>
+ img->pitches[2] = pitch[2];<br>
+ img->offsets[2] = pitch[0] * h + pitch[1] * h / 4;<br>
+ img->data_size = pitch[0] * h + pitch[1] * h / 4 + pitch[2] * h / 4;<br>
+ break;<br>
+<br>
case VA_FOURCC('U','Y','V','Y'):<br>
case VA_FOURCC('Y','U','Y','V'):<br>
img->num_planes = 1;<br>
- img->pitches[0] = w * 2;<br>
+ img->pitches[0] = pitch[0] * 2;<br>
img->offsets[0] = 0;<br>
- img->data_size = w * h * 2;<br>
+ img->data_size = pitch[0] * h * 2;<br>
break;<br>
case VA_FOURCC('B','G','R','A'):<br>
@@ -241,9 +309,9 @@ vlVaDeriveImage(VADriverContextP ctx, VASurfaceID surface, VAImage *image)<br>
case VA_FOURCC('B','G','R','X'):<br>
case VA_FOURCC('R','G','B','X'):<br>
img->num_planes = 1;<br>
- img->pitches[0] = w * 4;<br>
+ img->pitches[0] = pitch[0] * 4;<br>
img->offsets[0] = 0;<br>
- img->data_size = w * h * 4;<br>
+ img->data_size = pitch[0] * h * 4;<br>
break;<br>
default:<br>
@@ -431,7 +499,7 @@ vlVaPutImage(VADriverContextP ctx, VASurfaceID surface, VAImageID image,<br>
VAImage *vaimage;<br>
struct pipe_sampler_view **views;<br>
enum pipe_format format;<br>
- void *data[3];<br>
+ uint8_t *data[3];<br>
unsigned pitches[3], i, j;<br>
if (!ctx)<br>
@@ -471,7 +539,9 @@ vlVaPutImage(VADriverContextP ctx, VASurfaceID surface, VAImageID image,<br>
return VA_STATUS_ERROR_OPERATION_FAILED;<br>
}<br>
- if (format != surf->buffer->buffer_format) {<br>
+ if ((format != surf->buffer->buffer_format) &&<br>
+ ((format != PIPE_FORMAT_YV12) || (surf->buffer->buffer_format != PIPE_FORMAT_NV12)) &&<br>
+ ((format != PIPE_FORMAT_IYUV) || (surf->buffer->buffer_format != PIPE_FORMAT_NV12))) {<br>
struct pipe_video_buffer *tmp_buf;<br>
struct pipe_video_buffer templat = surf->templat;<br>
@@ -513,12 +583,42 @@ vlVaPutImage(VADriverContextP ctx, VASurfaceID surface, VAImageID image,<br>
unsigned width, height;<br>
if (!views[i]) continue;<br>
vlVaVideoSurfaceSize(surf, i, &width, &height);<br>
- for (j = 0; j < views[i]->texture->array_size; ++j) {<br>
- struct pipe_box dst_box = {0, 0, j, width, height, 1};<br>
- drv->pipe->transfer_inline_write(drv->pipe, views[i]->texture, 0,<br>
- PIPE_TRANSFER_WRITE, &dst_box,<br>
- data[i] + pitches[i] * j,<br>
- pitches[i] * views[i]->texture->array_size, 0);<br>
+ if ((format == PIPE_FORMAT_YV12) || (format == PIPE_FORMAT_IYUV) &&<br>
+ (surf->buffer->buffer_format == PIPE_FORMAT_NV12) && (i == 1)) {<br>
+ struct pipe_transfer *transfer = NULL;<br>
+ uint8_t *map = NULL;<br>
+ struct pipe_box dst_box_1 = {0, 0, 0, width, height, 1};<br>
+ map = drv->pipe->transfer_map(drv->pipe,<br>
+ views[i]->texture,<br>
+ 0,<br>
+ PIPE_TRANSFER_DISCARD_RANGE,<br>
+ &dst_box_1, &transfer);<br>
+ if (map == NULL)<br>
+ return VA_STATUS_ERROR_OPERATION_FAILED;<br>
+<br>
+ bool odd = false;<br>
+ for (unsigned int k = 0; k < ((vaimage->offsets[1])/2) ; k++){<br>
+ if (odd == false) {<br>
+ map[k] = data[i][k/2];<br>
+ odd = true;<br>
+ }<br>
+ else {<br>
+ map[k] = data[i+1][k/2];<br>
+ odd = false;<br>
+ }<br>
+ }<br>
+ pipe_transfer_unmap(drv->pipe, transfer);<br>
+ pipe_mutex_unlock(drv->mutex);<br>
+ return VA_STATUS_SUCCESS;<br>
+ }<br>
+ else {<br>
+ for (j = 0; j < views[i]->texture->array_size; ++j) {<br>
+ struct pipe_box dst_box = {0, 0, j, width, height, 1};<br>
+ drv->pipe->transfer_inline_write(drv->pipe, views[i]->texture, 0,<br>
+ PIPE_TRANSFER_WRITE, &dst_box,<br>
+ data[i] + pitches[i] * j,<br>
+ pitches[i] * views[i]->texture->array_size, 0);<br>
+ }<br>
}<br>
}<br>
pipe_mutex_unlock(drv->mutex);<br>
diff --git a/src/gallium/state_trackers/va/picture.c b/src/gallium/state_trackers/va/picture.c<br>
index 89ac024..973b862 100644<br>
--- a/src/gallium/state_trackers/va/picture.c<br>
+++ b/src/gallium/state_trackers/va/picture.c<br>
@@ -78,7 +78,8 @@ vlVaBeginPicture(VADriverContextP ctx, VAContextID context_id, VASurfaceID rende<br>
return VA_STATUS_SUCCESS;<br>
}<br>
- context->decoder->begin_frame(context->decoder, context->target, &context->desc.base);<br>
+ if (context->decoder->entrypoint != PIPE_VIDEO_ENTRYPOINT_ENCODE)<br>
+ context->decoder->begin_frame(context->decoder, context->target, &context->desc.base);<br>
return VA_STATUS_SUCCESS;<br>
}<br>
@@ -278,6 +279,134 @@ handleVASliceDataBufferType(vlVaContext *context, vlVaBuffer *buf)<br>
num_buffers, (const void * const*)buffers, sizes);<br>
}<br>
+static VAStatus<br>
+handleVAEncMiscParameterTypeRateControl(vlVaContext *context, VAEncMiscParameterBuffer *misc)<br>
+{<br>
+ VAEncMiscParameterRateControl *rc = (VAEncMiscParameterRateControl *)misc->data;<br>
+ if (context->desc.h264enc.rate_ctrl.rate_ctrl_method ==<br>
+ PIPE_H264_ENC_RATE_CONTROL_METHOD_CONSTANT)<br>
+ context->desc.h264enc.rate_ctrl.target_bitrate = rc->bits_per_second;<br>
+ else<br>
+ context->desc.h264enc.rate_ctrl.target_bitrate = rc->bits_per_second * rc->target_percentage;<br>
+ context->desc.h264enc.rate_ctrl.peak_bitrate = rc->bits_per_second;<br>
+ if (context->desc.h264enc.rate_ctrl.target_bitrate < 2000000)<br>
+ context->desc.h264enc.rate_ctrl.vbv_buffer_size = MIN2((context->desc.h264enc.rate_ctrl.target_bitrate * 2.75), 2000000);<br>
+ else<br>
+ context->desc.h264enc.rate_ctrl.vbv_buffer_size = context->desc.h264enc.rate_ctrl.target_bitrate;<br>
+<br>
+ return VA_STATUS_SUCCESS;<br>
+}<br>
+<br>
+static VAStatus<br>
+handleVAEncSequenceParameterBufferType(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf)<br>
+{<br>
+ VAEncSequenceParameterBufferH264 *h264 = (VAEncSequenceParameterBufferH264 *)buf->data;<br>
+ context->decoder->max_references = h264->max_num_ref_frames;<br>
+ context->desc.h264enc.gop_size = h264->intra_idr_period;<br>
+ return VA_STATUS_SUCCESS;<br>
+}<br>
+<br>
+static VAStatus<br>
+handleVAEncMiscParameterBufferType(vlVaContext *context, vlVaBuffer *buf)<br>
+{<br>
+ VAStatus vaStatus = VA_STATUS_SUCCESS;<br>
+ VAEncMiscParameterBuffer *misc;<br>
+ misc = buf->data;<br>
+<br>
+ switch (misc->type) {<br>
+ case VAEncMiscParameterTypeRateControl:<br>
+ vaStatus = handleVAEncMiscParameterTypeRateControl(context, misc);<br>
+ break;<br>
+<br>
+ default:<br>
+ break;<br>
+ }<br>
+<br>
+ return vaStatus;<br>
+}<br>
+<br>
+static VAStatus<br>
+handleVAEncPictureParameterBufferType(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf)<br>
+{<br>
+ VAEncPictureParameterBufferH264 *h264;<br>
+ vlVaBuffer *coded_buf;<br>
+<br>
+ h264 = buf->data;<br>
+ context->desc.h264enc.frame_num = h264->frame_num;<br>
+ context->desc.h264enc.not_referenced = false;<br>
+ context->desc.h264enc.is_idr = (h264->pic_fields.bits.idr_pic_flag == 1);<br>
+ context->desc.h264enc.pic_order_cnt = h264->CurrPic.TopFieldOrderCnt / 2;<br>
+ if (context->desc.h264enc.is_idr)<br>
+ context->desc.h264enc.i_remain = 1;<br>
+ else<br>
+ context->desc.h264enc.i_remain = 0;<br>
+<br>
+ context->desc.h264enc.p_remain = context->desc.h264enc.gop_size - context->desc.h264enc.gop_cnt - context->desc.h264enc.i_remain;<br>
+<br>
+ coded_buf = handle_table_get(drv->htab, h264->coded_buf);<br>
+ coded_buf->derived_surface.resource = pipe_buffer_create(drv->pipe->screen, PIPE_BIND_VERTEX_BUFFER,<br>
+ PIPE_USAGE_STREAM, coded_buf->size);<br>
+ context->coded_buf = coded_buf;<br>
+<br>
+ context->desc.h264enc.frame_idx[h264->CurrPic.picture_id] = h264->frame_num;<br>
+ if (context->desc.h264enc.is_idr)<br>
+ context->desc.h264enc.picture_type = PIPE_H264_ENC_PICTURE_TYPE_IDR;<br>
+ else<br>
+ context->desc.h264enc.picture_type = PIPE_H264_ENC_PICTURE_TYPE_P;<br>
+<br>
+ context->desc.h264enc.frame_num_cnt++;<br>
+ context->desc.h264enc.gop_cnt++;<br>
+ if (context->desc.h264enc.gop_cnt == context->desc.h264enc.gop_size)<br>
+ context->desc.h264enc.gop_cnt = 0;<br>
+<br>
+ return VA_STATUS_SUCCESS;<br>
+}<br>
+<br>
+static VAStatus<br>
+handleVAEncSliceParameterBufferType(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf)<br>
+{<br>
+ VAEncSliceParameterBufferH264 *h264;<br>
+<br>
+ h264 = buf->data;<br>
+ context->desc.h264enc.ref_idx_l0 = VA_INVALID_ID;<br>
+ context->desc.h264enc.ref_idx_l1 = VA_INVALID_ID;<br>
+ context->desc.h264enc.has_ref_pic_list = false;<br>
+<br>
+ for (int i = 0; i < 32; i++) {<br>
+ if (h264->RefPicList0[i].picture_id == VA_INVALID_ID)<br>
+ context->desc.h264enc.ref_pic_list_0[i] = VA_INVALID_ID;<br>
+ else {<br>
+ context->desc.h264enc.ref_pic_list_0[i] = context->desc.h264enc.frame_idx[h264->RefPicList0[i].picture_id];<br>
+ if (context->desc.h264enc.ref_idx_l0 == VA_INVALID_ID)<br>
+ context->desc.h264enc.ref_idx_l0 = context->desc.h264enc.frame_idx[h264->RefPicList0[i].picture_id];<br>
+ context->desc.h264enc.has_ref_pic_list = true;<br>
+ }<br>
+ if (h264->RefPicList1[i].picture_id == VA_INVALID_ID || h264->slice_type != 1)<br>
+ context->desc.h264enc.ref_pic_list_1[i] = VA_INVALID_ID;<br>
+ else {<br>
+ context->desc.h264enc.ref_pic_list_1[i] = context->desc.h264enc.frame_idx[h264->RefPicList1[i].picture_id];<br>
+ if (context->desc.h264enc.ref_idx_l1 == VA_INVALID_ID)<br>
+ context->desc.h264enc.ref_idx_l1 = context->desc.h264enc.frame_idx[h264->RefPicList1[i].picture_id];<br>
+ context->desc.h264enc.has_ref_pic_list = true;<br>
+ }<br>
+ }<br>
+<br>
+ if (h264->slice_type == 1)<br>
+ context->desc.h264enc.picture_type = PIPE_H264_ENC_PICTURE_TYPE_B;<br>
+ else if (h264->slice_type == 0)<br>
+ context->desc.h264enc.picture_type = PIPE_H264_ENC_PICTURE_TYPE_P;<br>
+ else if (h264->slice_type == 2) {<br>
+ if (context->desc.h264enc.is_idr){<br>
+ context->desc.h264enc.picture_type = PIPE_H264_ENC_PICTURE_TYPE_IDR;<br>
+ context->desc.h264enc.idr_pic_id++;<br>
+ } else<br>
+ context->desc.h264enc.picture_type = PIPE_H264_ENC_PICTURE_TYPE_I;<br>
+ } else<br>
+ context->desc.h264enc.picture_type = PIPE_H264_ENC_PICTURE_TYPE_SKIP;<br>
+<br>
+ return VA_STATUS_SUCCESS;<br>
+}<br>
+<br>
VAStatus<br>
vlVaRenderPicture(VADriverContextP ctx, VAContextID context_id, VABufferID *buffers, int num_buffers)<br>
{<br>
@@ -328,6 +457,22 @@ vlVaRenderPicture(VADriverContextP ctx, VAContextID context_id, VABufferID *buff<br>
vaStatus = vlVaHandleVAProcPipelineParameterBufferType(drv, context, buf);<br>
break;<br>
+ case VAEncSequenceParameterBufferType:<br>
+ vaStatus = handleVAEncSequenceParameterBufferType(drv, context, buf);<br>
+ break;<br>
+<br>
+ case VAEncMiscParameterBufferType:<br>
+ vaStatus = handleVAEncMiscParameterBufferType(context, buf);<br>
+ break;<br>
+<br>
+ case VAEncPictureParameterBufferType:<br>
+ vaStatus = handleVAEncPictureParameterBufferType(drv, context, buf);<br>
+ break;<br>
+<br>
+ case VAEncSliceParameterBufferType:<br>
+ vaStatus = handleVAEncSliceParameterBufferType(drv, context, buf);<br>
+ break;<br>
+<br>
default:<br>
break;<br>
}<br>
@@ -342,6 +487,9 @@ vlVaEndPicture(VADriverContextP ctx, VAContextID context_id)<br>
{<br>
vlVaDriver *drv;<br>
vlVaContext *context;<br>
+ vlVaBuffer *coded_buf;<br>
+ unsigned int coded_size;<br>
+ void *feedback;<br>
if (!ctx)<br>
return VA_STATUS_ERROR_INVALID_CONTEXT;<br>
@@ -365,7 +513,20 @@ vlVaEndPicture(VADriverContextP ctx, VAContextID context_id)<br>
}<br>
context->mpeg4.frame_num++;<br>
- context->decoder->end_frame(context->decoder, context->target, &context->desc.base);<br>
+<br>
+ if (context->decoder->entrypoint == PIPE_VIDEO_ENTRYPOINT_ENCODE) {<br>
+ coded_buf = context->coded_buf;<br>
+ context->desc.h264enc.enable_low_level_control = true;<br>
+ context->decoder->begin_frame(context->decoder, context->target, &context->desc.base);<br>
+ context->decoder->encode_bitstream(context->decoder, context->target,<br>
+ coded_buf->derived_surface.resource, &feedback);<br>
+ context->decoder->end_frame(context->decoder, context->target, &context->desc.base);<br>
+ context->decoder->flush(context->decoder);<br>
+ context->decoder->get_feedback(context->decoder, feedback, &coded_size);<br>
+ coded_buf->coded_size = coded_size;<br>
+ }<br>
+ else<br>
+ context->decoder->end_frame(context->decoder, context->target, &context->desc.base);<br>
return VA_STATUS_SUCCESS;<br>
}<br>
diff --git a/src/gallium/state_trackers/va/surface.c b/src/gallium/state_trackers/va/surface.c<br>
index 5efb893..1c56757 100644<br>
--- a/src/gallium/state_trackers/va/surface.c<br>
+++ b/src/gallium/state_trackers/va/surface.c<br>
@@ -43,6 +43,8 @@<br>
#include "va_private.h"<br>
+DEBUG_GET_ONCE_BOOL_OPTION(nointerlace, "DISABLE_INTERLACE", FALSE);<br>
+<br>
#include <va/va_drmcommon.h><br>
static const enum pipe_format vpp_surface_formats[] = {<br>
@@ -315,17 +317,18 @@ vlVaUnlockSurface(VADriverContextP ctx, VASurfaceID surface)<br>
}<br>
VAStatus<br>
-vlVaQuerySurfaceAttributes(VADriverContextP ctx, VAConfigID config,<br>
+vlVaQuerySurfaceAttributes(VADriverContextP ctx, VAConfigID config_id,<br>
VASurfaceAttrib *attrib_list, unsigned int *num_attribs)<br>
{<br>
vlVaDriver *drv;<br>
+ vlVaConfig *config;<br>
VASurfaceAttrib *attribs;<br>
struct pipe_screen *pscreen;<br>
int i, j;<br>
STATIC_ASSERT(ARRAY_SIZE(vpp_surface_formats) <= VL_VA_MAX_IMAGE_FORMATS);<br>
- if (config == VA_INVALID_ID)<br>
+ if (config_id == VA_INVALID_ID)<br>
return VA_STATUS_ERROR_INVALID_CONFIG;<br>
if (!attrib_list && !num_attribs)<br>
@@ -344,6 +347,11 @@ vlVaQuerySurfaceAttributes(VADriverContextP ctx, VAConfigID config,<br>
if (!drv)<br>
return VA_STATUS_ERROR_INVALID_CONTEXT;<br>
+ config = handle_table_get(drv->htab, config_id);<br>
+<br>
+ if (!config)<br>
+ return VA_STATUS_ERROR_INVALID_CONFIG;<br>
+<br>
pscreen = VL_VA_PSCREEN(ctx);<br>
if (!pscreen)<br>
@@ -359,7 +367,7 @@ vlVaQuerySurfaceAttributes(VADriverContextP ctx, VAConfigID config,<br>
/* vlVaCreateConfig returns PIPE_VIDEO_PROFILE_UNKNOWN<br>
* only for VAEntrypointVideoProc. */<br>
- if (config == PIPE_VIDEO_PROFILE_UNKNOWN) {<br>
+ if (config->profile == PIPE_VIDEO_PROFILE_UNKNOWN) {<br>
for (j = 0; j < ARRAY_SIZE(vpp_surface_formats); ++j) {<br>
attribs[i].type = VASurfaceAttribPixelFormat;<br>
attribs[i].value.type = VAGenericValueTypeInteger;<br>
@@ -608,6 +616,8 @@ vlVaCreateSurfaces2(VADriverContextP ctx, unsigned int format,<br>
templat.width = width;<br>
templat.height = height;<br>
+ if (debug_get_option_nointerlace())<br>
+ templat.interlaced = false;<br>
memset(surfaces, VA_INVALID_ID, num_surfaces * sizeof(VASurfaceID));<br>
diff --git a/src/gallium/state_trackers/va/va_private.h b/src/gallium/state_trackers/va/va_private.h<br>
index d91de44..6d3ac38 100644<br>
--- a/src/gallium/state_trackers/va/va_private.h<br>
+++ b/src/gallium/state_trackers/va/va_private.h<br>
@@ -229,6 +229,7 @@ typedef struct {<br>
struct pipe_vc1_picture_desc vc1;<br>
struct pipe_h264_picture_desc h264;<br>
struct pipe_h265_picture_desc h265;<br>
+ struct pipe_h264_enc_picture_desc h264enc;<br>
} desc;<br>
struct {<br>
@@ -241,9 +242,16 @@ typedef struct {<br>
} mpeg4;<br>
struct vl_deint_filter *deint;<br>
+ struct vlVaBuffer *coded_buf;<br>
} vlVaContext;<br>
typedef struct {<br>
+ VAEntrypoint entrypoint;<br>
+ enum pipe_video_profile profile;<br>
+ enum pipe_h264_enc_rate_control_method rc;<br>
+} vlVaConfig;<br>
+<br>
+typedef struct {<br>
VABufferType type;<br>
unsigned int size;<br>
unsigned int num_elements;<br>
@@ -254,6 +262,7 @@ typedef struct {<br>
} derived_surface;<br>
unsigned int export_refcount;<br>
VABufferInfo export_state;<br>
+ unsigned int coded_size;<br>
} vlVaBuffer;<br>
typedef struct {<br>
</blockquote>
<br></div></div><div class="HOEnZb"><div class="h5">
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br></div></div>