Re: [Mesa-dev] [PATCH] st/va: use provided sizes and coords for vlVaGetImage
Acked-by: Christian König Am 10.10.2018 um 21:18 schrieb Ilia Mirkin: Reviewed-by: Ilia Mirkin On Wed, Oct 10, 2018 at 3:12 PM wrote: From: Boyuan Zhang vlVaGetImage should respect the width, height, and coordinates x and y that passed in. Therefore, pipe_box should be created with the passed in values instead of surface width/height. v2: add input size check, return error when size out of bounds v3: fix the size check for vaimage v4: add size adjustment for x and y coordinates Signed-off-by: Boyuan Zhang Cc: "18.2" Reviewed-by: Leo Liu --- src/gallium/state_trackers/va/image.c | 31 --- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/gallium/state_trackers/va/image.c b/src/gallium/state_trackers/va/image.c index 3f892c9..807fc83 100644 --- a/src/gallium/state_trackers/va/image.c +++ b/src/gallium/state_trackers/va/image.c @@ -353,6 +353,23 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, int x, int y, return VA_STATUS_ERROR_INVALID_IMAGE; } + if (x < 0 || y < 0) { + mtx_unlock(>mutex); + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + + if (x + width > surf->templat.width || + y + height > surf->templat.height) { + mtx_unlock(>mutex); + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + + if (width > vaimage->width || + height > vaimage->height) { + mtx_unlock(>mutex); + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + img_buf = handle_table_get(drv->htab, vaimage->buf); if (!img_buf) { mtx_unlock(>mutex); @@ -400,11 +417,19 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, int x, int y, } for (i = 0; i < vaimage->num_planes; i++) { - unsigned width, height; + unsigned box_w = align(width, 2); + unsigned box_h = align(height, 2); + unsigned box_x = x & ~1; + unsigned box_y = y & ~1; if (!views[i]) continue; - vlVaVideoSurfaceSize(surf, i, , ); + vl_video_buffer_adjust_size(_w, _h, i, + surf->templat.chroma_format, + surf->templat.interlaced); + vl_video_buffer_adjust_size(_x, _y, i, + surf->templat.chroma_format, + surf->templat.interlaced); for (j = 0; j < views[i]->texture->array_size; ++j) { - struct pipe_box box = {0, 0, j, width, height, 1}; + struct pipe_box box = {box_x, box_y, j, box_w, box_h, 1}; struct pipe_transfer *transfer; uint8_t *map; map = drv->pipe->transfer_map(drv->pipe, views[i]->texture, 0, -- 2.7.4 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] st/va: use provided sizes and coords for vlVaGetImage
Reviewed-by: Ilia Mirkin On Wed, Oct 10, 2018 at 3:12 PM wrote: > > From: Boyuan Zhang > > vlVaGetImage should respect the width, height, and coordinates x and y that > passed in. Therefore, pipe_box should be created with the passed in values > instead of surface width/height. > > v2: add input size check, return error when size out of bounds > v3: fix the size check for vaimage > v4: add size adjustment for x and y coordinates > > Signed-off-by: Boyuan Zhang > Cc: "18.2" > Reviewed-by: Leo Liu > --- > src/gallium/state_trackers/va/image.c | 31 --- > 1 file changed, 28 insertions(+), 3 deletions(-) > > diff --git a/src/gallium/state_trackers/va/image.c > b/src/gallium/state_trackers/va/image.c > index 3f892c9..807fc83 100644 > --- a/src/gallium/state_trackers/va/image.c > +++ b/src/gallium/state_trackers/va/image.c > @@ -353,6 +353,23 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, > int x, int y, >return VA_STATUS_ERROR_INVALID_IMAGE; > } > > + if (x < 0 || y < 0) { > + mtx_unlock(>mutex); > + return VA_STATUS_ERROR_INVALID_PARAMETER; > + } > + > + if (x + width > surf->templat.width || > + y + height > surf->templat.height) { > + mtx_unlock(>mutex); > + return VA_STATUS_ERROR_INVALID_PARAMETER; > + } > + > + if (width > vaimage->width || > + height > vaimage->height) { > + mtx_unlock(>mutex); > + return VA_STATUS_ERROR_INVALID_PARAMETER; > + } > + > img_buf = handle_table_get(drv->htab, vaimage->buf); > if (!img_buf) { >mtx_unlock(>mutex); > @@ -400,11 +417,19 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, > int x, int y, > } > > for (i = 0; i < vaimage->num_planes; i++) { > - unsigned width, height; > + unsigned box_w = align(width, 2); > + unsigned box_h = align(height, 2); > + unsigned box_x = x & ~1; > + unsigned box_y = y & ~1; >if (!views[i]) continue; > - vlVaVideoSurfaceSize(surf, i, , ); > + vl_video_buffer_adjust_size(_w, _h, i, > + surf->templat.chroma_format, > + surf->templat.interlaced); > + vl_video_buffer_adjust_size(_x, _y, i, > + surf->templat.chroma_format, > + surf->templat.interlaced); >for (j = 0; j < views[i]->texture->array_size; ++j) { > - struct pipe_box box = {0, 0, j, width, height, 1}; > + struct pipe_box box = {box_x, box_y, j, box_w, box_h, 1}; > struct pipe_transfer *transfer; > uint8_t *map; > map = drv->pipe->transfer_map(drv->pipe, views[i]->texture, 0, > -- > 2.7.4 > ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH] st/va: use provided sizes and coords for vlVaGetImage
From: Boyuan Zhang vlVaGetImage should respect the width, height, and coordinates x and y that passed in. Therefore, pipe_box should be created with the passed in values instead of surface width/height. v2: add input size check, return error when size out of bounds v3: fix the size check for vaimage v4: add size adjustment for x and y coordinates Signed-off-by: Boyuan Zhang Cc: "18.2" Reviewed-by: Leo Liu --- src/gallium/state_trackers/va/image.c | 31 --- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/gallium/state_trackers/va/image.c b/src/gallium/state_trackers/va/image.c index 3f892c9..807fc83 100644 --- a/src/gallium/state_trackers/va/image.c +++ b/src/gallium/state_trackers/va/image.c @@ -353,6 +353,23 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, int x, int y, return VA_STATUS_ERROR_INVALID_IMAGE; } + if (x < 0 || y < 0) { + mtx_unlock(>mutex); + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + + if (x + width > surf->templat.width || + y + height > surf->templat.height) { + mtx_unlock(>mutex); + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + + if (width > vaimage->width || + height > vaimage->height) { + mtx_unlock(>mutex); + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + img_buf = handle_table_get(drv->htab, vaimage->buf); if (!img_buf) { mtx_unlock(>mutex); @@ -400,11 +417,19 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, int x, int y, } for (i = 0; i < vaimage->num_planes; i++) { - unsigned width, height; + unsigned box_w = align(width, 2); + unsigned box_h = align(height, 2); + unsigned box_x = x & ~1; + unsigned box_y = y & ~1; if (!views[i]) continue; - vlVaVideoSurfaceSize(surf, i, , ); + vl_video_buffer_adjust_size(_w, _h, i, + surf->templat.chroma_format, + surf->templat.interlaced); + vl_video_buffer_adjust_size(_x, _y, i, + surf->templat.chroma_format, + surf->templat.interlaced); for (j = 0; j < views[i]->texture->array_size; ++j) { - struct pipe_box box = {0, 0, j, width, height, 1}; + struct pipe_box box = {box_x, box_y, j, box_w, box_h, 1}; struct pipe_transfer *transfer; uint8_t *map; map = drv->pipe->transfer_map(drv->pipe, views[i]->texture, 0, -- 2.7.4 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] st/va: use provided sizes and coords for vlVaGetImage
On Tue, Oct 9, 2018 at 4:32 PM wrote: > > From: Boyuan Zhang > > vlVaGetImage should respect the width, height, and coordinates x and y that > passed in. Therefore, pipe_box should be created with the passed in values > instead of surface width/height. > > v2: add input size check, return error when size out of bounds > v3: fix the size check for vaimage > > Signed-off-by: Boyuan Zhang > Cc: "18.2" > Reviewed-by: Leo Liu > --- > src/gallium/state_trackers/va/image.c | 26 +++--- > 1 file changed, 23 insertions(+), 3 deletions(-) > > diff --git a/src/gallium/state_trackers/va/image.c > b/src/gallium/state_trackers/va/image.c > index 3f892c9..71d2f49 100644 > --- a/src/gallium/state_trackers/va/image.c > +++ b/src/gallium/state_trackers/va/image.c > @@ -353,6 +353,23 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, > int x, int y, >return VA_STATUS_ERROR_INVALID_IMAGE; > } > > + if (x < 0 || y < 0) { > + mtx_unlock(>mutex); > + return VA_STATUS_ERROR_INVALID_PARAMETER; > + } > + > + if (x + width > surf->templat.width || > + y + height > surf->templat.height) { > + mtx_unlock(>mutex); > + return VA_STATUS_ERROR_INVALID_PARAMETER; > + } > + > + if (width > vaimage->width || > + height > vaimage->height) { > + mtx_unlock(>mutex); > + return VA_STATUS_ERROR_INVALID_PARAMETER; > + } > + > img_buf = handle_table_get(drv->htab, vaimage->buf); > if (!img_buf) { >mtx_unlock(>mutex); > @@ -400,11 +417,14 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, > int x, int y, > } > > for (i = 0; i < vaimage->num_planes; i++) { > - unsigned width, height; > + unsigned w = align(width, 2); > + unsigned h = align(height, 2); >if (!views[i]) continue; > - vlVaVideoSurfaceSize(surf, i, , ); > + vl_video_buffer_adjust_size(, , i, > + surf->templat.chroma_format, > + surf->templat.interlaced); You should adjust the x/y coords too (and probably round them down to 2, i.e. & ~1). Same transformation as for the w/h ought to work. All this round-by-2 stuff seems sketchy though. It's clearly bogus for the RGB formats, but it does seem prevalent elsewhere. I don't think it's necessary to fix here. Cheers, -ilia >for (j = 0; j < views[i]->texture->array_size; ++j) { > - struct pipe_box box = {0, 0, j, width, height, 1}; > + struct pipe_box box = {x, y, j, w, h, 1}; > struct pipe_transfer *transfer; > uint8_t *map; > map = drv->pipe->transfer_map(drv->pipe, views[i]->texture, 0, > -- > 2.7.4 > ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH] st/va: use provided sizes and coords for vlVaGetImage
From: Boyuan Zhang vlVaGetImage should respect the width, height, and coordinates x and y that passed in. Therefore, pipe_box should be created with the passed in values instead of surface width/height. v2: add input size check, return error when size out of bounds v3: fix the size check for vaimage Signed-off-by: Boyuan Zhang Cc: "18.2" Reviewed-by: Leo Liu --- src/gallium/state_trackers/va/image.c | 26 +++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/gallium/state_trackers/va/image.c b/src/gallium/state_trackers/va/image.c index 3f892c9..71d2f49 100644 --- a/src/gallium/state_trackers/va/image.c +++ b/src/gallium/state_trackers/va/image.c @@ -353,6 +353,23 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, int x, int y, return VA_STATUS_ERROR_INVALID_IMAGE; } + if (x < 0 || y < 0) { + mtx_unlock(>mutex); + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + + if (x + width > surf->templat.width || + y + height > surf->templat.height) { + mtx_unlock(>mutex); + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + + if (width > vaimage->width || + height > vaimage->height) { + mtx_unlock(>mutex); + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + img_buf = handle_table_get(drv->htab, vaimage->buf); if (!img_buf) { mtx_unlock(>mutex); @@ -400,11 +417,14 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, int x, int y, } for (i = 0; i < vaimage->num_planes; i++) { - unsigned width, height; + unsigned w = align(width, 2); + unsigned h = align(height, 2); if (!views[i]) continue; - vlVaVideoSurfaceSize(surf, i, , ); + vl_video_buffer_adjust_size(, , i, + surf->templat.chroma_format, + surf->templat.interlaced); for (j = 0; j < views[i]->texture->array_size; ++j) { - struct pipe_box box = {0, 0, j, width, height, 1}; + struct pipe_box box = {x, y, j, w, h, 1}; struct pipe_transfer *transfer; uint8_t *map; map = drv->pipe->transfer_map(drv->pipe, views[i]->texture, 0, -- 2.7.4 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] st/va: use provided sizes and coords for vlVaGetImage
On 2018-10-09 04:09 PM, Ilia Mirkin wrote: On Tue, Oct 9, 2018 at 4:03 PM wrote: From: Boyuan Zhang vlVaGetImage should respect the width, height, and coordinates x and y that passed in. Therefore, pipe_box should be created with the passed in values instead of surface width/height. v2: add input size check, return error when size out of bounds Signed-off-by: Boyuan Zhang Cc: "18.2" Reviewed-by: Leo Liu --- src/gallium/state_trackers/va/image.c | 26 +++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/gallium/state_trackers/va/image.c b/src/gallium/state_trackers/va/image.c index 3f892c9..449ae86 100644 --- a/src/gallium/state_trackers/va/image.c +++ b/src/gallium/state_trackers/va/image.c @@ -353,6 +353,23 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, int x, int y, return VA_STATUS_ERROR_INVALID_IMAGE; } + if (x < 0 || y < 0) { + mtx_unlock(>mutex); + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + + if (x + width > surf->templat.width || + y + height > surf->templat.height) { + mtx_unlock(>mutex); + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + + if (x + width > vaimage->width || + y + height > vaimage->height) { I believe the x/y offset is only meant for the surface, not for the image. e.g. x=100,y=100,width=100,height=100 would be able to work with a 100x100 image destination. I just checked the doc(va.h) again, it says x/y are the coordinates of the upper left source pixel. I guess "source" here means surface, so I believe you are right. Boyuan + mtx_unlock(>mutex); + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + img_buf = handle_table_get(drv->htab, vaimage->buf); if (!img_buf) { mtx_unlock(>mutex); @@ -400,11 +417,14 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, int x, int y, } for (i = 0; i < vaimage->num_planes; i++) { - unsigned width, height; + unsigned w = align(width, 2); + unsigned h = align(height, 2); if (!views[i]) continue; - vlVaVideoSurfaceSize(surf, i, , ); + vl_video_buffer_adjust_size(, , i, + surf->templat.chroma_format, + surf->templat.interlaced); for (j = 0; j < views[i]->texture->array_size; ++j) { - struct pipe_box box = {0, 0, j, width, height, 1}; + struct pipe_box box = {x, y, j, w, h, 1}; struct pipe_transfer *transfer; uint8_t *map; map = drv->pipe->transfer_map(drv->pipe, views[i]->texture, 0, -- 2.7.4 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH] st/va: use provided sizes and coords for vlVaGetImage
On Tue, Oct 9, 2018 at 4:03 PM wrote: > > From: Boyuan Zhang > > vlVaGetImage should respect the width, height, and coordinates x and y that > passed in. Therefore, pipe_box should be created with the passed in values > instead of surface width/height. > > v2: add input size check, return error when size out of bounds > > Signed-off-by: Boyuan Zhang > Cc: "18.2" > Reviewed-by: Leo Liu > --- > src/gallium/state_trackers/va/image.c | 26 +++--- > 1 file changed, 23 insertions(+), 3 deletions(-) > > diff --git a/src/gallium/state_trackers/va/image.c > b/src/gallium/state_trackers/va/image.c > index 3f892c9..449ae86 100644 > --- a/src/gallium/state_trackers/va/image.c > +++ b/src/gallium/state_trackers/va/image.c > @@ -353,6 +353,23 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, > int x, int y, >return VA_STATUS_ERROR_INVALID_IMAGE; > } > > + if (x < 0 || y < 0) { > + mtx_unlock(>mutex); > + return VA_STATUS_ERROR_INVALID_PARAMETER; > + } > + > + if (x + width > surf->templat.width || > + y + height > surf->templat.height) { > + mtx_unlock(>mutex); > + return VA_STATUS_ERROR_INVALID_PARAMETER; > + } > + > + if (x + width > vaimage->width || > + y + height > vaimage->height) { I believe the x/y offset is only meant for the surface, not for the image. e.g. x=100,y=100,width=100,height=100 would be able to work with a 100x100 image destination. > + mtx_unlock(>mutex); > + return VA_STATUS_ERROR_INVALID_PARAMETER; > + } > + > img_buf = handle_table_get(drv->htab, vaimage->buf); > if (!img_buf) { >mtx_unlock(>mutex); > @@ -400,11 +417,14 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, > int x, int y, > } > > for (i = 0; i < vaimage->num_planes; i++) { > - unsigned width, height; > + unsigned w = align(width, 2); > + unsigned h = align(height, 2); >if (!views[i]) continue; > - vlVaVideoSurfaceSize(surf, i, , ); > + vl_video_buffer_adjust_size(, , i, > + surf->templat.chroma_format, > + surf->templat.interlaced); >for (j = 0; j < views[i]->texture->array_size; ++j) { > - struct pipe_box box = {0, 0, j, width, height, 1}; > + struct pipe_box box = {x, y, j, w, h, 1}; > struct pipe_transfer *transfer; > uint8_t *map; > map = drv->pipe->transfer_map(drv->pipe, views[i]->texture, 0, > -- > 2.7.4 > ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH] st/va: use provided sizes and coords for vlVaGetImage
From: Boyuan Zhang vlVaGetImage should respect the width, height, and coordinates x and y that passed in. Therefore, pipe_box should be created with the passed in values instead of surface width/height. v2: add input size check, return error when size out of bounds Signed-off-by: Boyuan Zhang Cc: "18.2" Reviewed-by: Leo Liu --- src/gallium/state_trackers/va/image.c | 26 +++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/gallium/state_trackers/va/image.c b/src/gallium/state_trackers/va/image.c index 3f892c9..449ae86 100644 --- a/src/gallium/state_trackers/va/image.c +++ b/src/gallium/state_trackers/va/image.c @@ -353,6 +353,23 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, int x, int y, return VA_STATUS_ERROR_INVALID_IMAGE; } + if (x < 0 || y < 0) { + mtx_unlock(>mutex); + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + + if (x + width > surf->templat.width || + y + height > surf->templat.height) { + mtx_unlock(>mutex); + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + + if (x + width > vaimage->width || + y + height > vaimage->height) { + mtx_unlock(>mutex); + return VA_STATUS_ERROR_INVALID_PARAMETER; + } + img_buf = handle_table_get(drv->htab, vaimage->buf); if (!img_buf) { mtx_unlock(>mutex); @@ -400,11 +417,14 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, int x, int y, } for (i = 0; i < vaimage->num_planes; i++) { - unsigned width, height; + unsigned w = align(width, 2); + unsigned h = align(height, 2); if (!views[i]) continue; - vlVaVideoSurfaceSize(surf, i, , ); + vl_video_buffer_adjust_size(, , i, + surf->templat.chroma_format, + surf->templat.interlaced); for (j = 0; j < views[i]->texture->array_size; ++j) { - struct pipe_box box = {0, 0, j, width, height, 1}; + struct pipe_box box = {x, y, j, w, h, 1}; struct pipe_transfer *transfer; uint8_t *map; map = drv->pipe->transfer_map(drv->pipe, views[i]->texture, 0, -- 2.7.4 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev