Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit 43a75ea

Browse files
laureatianxhaihao
authored andcommitted
Add imported surface alignment check
This fixes issues #62 #62 Signed-off-by: Wang Tiantian <[email protected]> Reviewed-by: Zhao Yakui <[email protected]>
1 parent 01e6028 commit 43a75ea

File tree

1 file changed

+79
-31
lines changed

1 file changed

+79
-31
lines changed

src/i965_drv_video.c

+79-31
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,18 @@ i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
13611361
object_heap_free(heap, obj);
13621362
}
13631363

1364+
/* byte-per-pixel of the first plane */
1365+
static int
1366+
bpp_1stplane_by_fourcc(unsigned int fourcc)
1367+
{
1368+
const i965_fourcc_info *info = get_fourcc_info(fourcc);
1369+
1370+
if (info && (info->flag & I_S))
1371+
return info->bpp[0] / 8;
1372+
else
1373+
return 0;
1374+
}
1375+
13641376
static VAStatus
13651377
i965_surface_native_memory(VADriverContextP ctx,
13661378
struct object_surface *obj_surface,
@@ -1392,7 +1404,22 @@ i965_suface_external_memory(VADriverContextP ctx,
13921404
int index)
13931405
{
13941406
struct i965_driver_data *i965 = i965_driver_data(ctx);
1407+
unsigned int tiling,swizzle;
13951408

1409+
obj_surface->size = memory_attibute->data_size;
1410+
if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
1411+
obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
1412+
"gem flinked vaapi surface",
1413+
memory_attibute->buffers[index]);
1414+
else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
1415+
obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
1416+
memory_attibute->buffers[index],
1417+
obj_surface->size);
1418+
1419+
if (!obj_surface->bo)
1420+
return VA_STATUS_ERROR_INVALID_PARAMETER;
1421+
1422+
dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
13961423
if (!memory_attibute ||
13971424
!memory_attibute->buffers ||
13981425
index > memory_attibute->num_buffers)
@@ -1404,15 +1431,33 @@ i965_suface_external_memory(VADriverContextP ctx,
14041431

14051432
obj_surface->fourcc = memory_attibute->pixel_format;
14061433
obj_surface->width = memory_attibute->pitches[0];
1407-
obj_surface->size = memory_attibute->data_size;
1434+
int bpp_1stplane = bpp_1stplane_by_fourcc(obj_surface->fourcc);
1435+
ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1436+
ASSERT_RET(obj_surface->width >= obj_surface->orig_width * bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
14081437

14091438
if (memory_attibute->num_planes == 1)
14101439
obj_surface->height = memory_attibute->data_size / obj_surface->width;
14111440
else
14121441
obj_surface->height = memory_attibute->offsets[1] / obj_surface->width;
1442+
ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
1443+
ASSERT_RET(obj_surface->height >= obj_surface->orig_height, VA_STATUS_ERROR_INVALID_PARAMETER);
1444+
1445+
if (tiling) {
1446+
ASSERT_RET(IS_ALIGNED(obj_surface->width,128),VA_STATUS_ERROR_INVALID_PARAMETER);
1447+
ASSERT_RET(IS_ALIGNED(obj_surface->height,32),VA_STATUS_ERROR_INVALID_PARAMETER);
1448+
} else {
1449+
ASSERT_RET(IS_ALIGNED(obj_surface->width,i965->codec_info->min_linear_wpitch),VA_STATUS_ERROR_INVALID_PARAMETER);
1450+
ASSERT_RET(IS_ALIGNED(obj_surface->height,i965->codec_info->min_linear_wpitch),VA_STATUS_ERROR_INVALID_PARAMETER);
1451+
}
14131452

14141453
obj_surface->x_cb_offset = 0; /* X offset is always 0 */
14151454
obj_surface->x_cr_offset = 0;
1455+
if ((obj_surface->fourcc == VA_FOURCC_I420 ||
1456+
obj_surface->fourcc == VA_FOURCC_IYUV ||
1457+
obj_surface->fourcc == VA_FOURCC_I010 ||
1458+
obj_surface->fourcc == VA_FOURCC_YV12 ||
1459+
obj_surface->fourcc == VA_FOURCC_YV16) && tiling)
1460+
return VA_STATUS_ERROR_INVALID_PARAMETER;
14161461

14171462
switch (obj_surface->fourcc) {
14181463
case VA_FOURCC_NV12:
@@ -1426,6 +1471,10 @@ i965_suface_external_memory(VADriverContextP ctx,
14261471
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
14271472
obj_surface->cb_cr_height = obj_surface->orig_height / 2;
14281473
obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1474+
if (tiling)
1475+
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch,128),VA_STATUS_ERROR_INVALID_PARAMETER);
1476+
else
1477+
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch,i965->codec_info->min_linear_wpitch),VA_STATUS_ERROR_INVALID_PARAMETER);
14291478

14301479
break;
14311480

@@ -1440,7 +1489,11 @@ i965_suface_external_memory(VADriverContextP ctx,
14401489
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
14411490
obj_surface->cb_cr_height = obj_surface->orig_height / 2;
14421491
obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1443-
1492+
if (tiling)
1493+
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch,128),VA_STATUS_ERROR_INVALID_PARAMETER);
1494+
else
1495+
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch,i965->codec_info->min_linear_wpitch),VA_STATUS_ERROR_INVALID_PARAMETER);
1496+
14441497
break;
14451498

14461499
case VA_FOURCC_I420:
@@ -1456,6 +1509,10 @@ i965_suface_external_memory(VADriverContextP ctx,
14561509
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
14571510
obj_surface->cb_cr_height = obj_surface->orig_height / 2;
14581511
obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1512+
if (tiling)
1513+
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch,128),VA_STATUS_ERROR_INVALID_PARAMETER);
1514+
else
1515+
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch,i965->codec_info->min_linear_wpitch),VA_STATUS_ERROR_INVALID_PARAMETER);
14591516

14601517
break;
14611518

@@ -1489,7 +1546,7 @@ i965_suface_external_memory(VADriverContextP ctx,
14891546

14901547
case VA_FOURCC_Y800: /* monochrome surface */
14911548
ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
1492-
1549+
14931550
obj_surface->subsampling = SUBSAMPLE_YUV400;
14941551
obj_surface->y_cb_offset = 0;
14951552
obj_surface->y_cr_offset = 0;
@@ -1509,7 +1566,10 @@ i965_suface_external_memory(VADriverContextP ctx,
15091566
obj_surface->cb_cr_width = obj_surface->orig_width / 4;
15101567
obj_surface->cb_cr_height = obj_surface->orig_height;
15111568
obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1512-
1569+
if (tiling)
1570+
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch,128),VA_STATUS_ERROR_INVALID_PARAMETER);
1571+
else
1572+
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch,i965->codec_info->min_linear_wpitch),VA_STATUS_ERROR_INVALID_PARAMETER);
15131573
break;
15141574

15151575
case VA_FOURCC_422H:
@@ -1522,19 +1582,24 @@ i965_suface_external_memory(VADriverContextP ctx,
15221582
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
15231583
obj_surface->cb_cr_height = obj_surface->orig_height;
15241584
obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1585+
if (tiling)
1586+
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch,128),VA_STATUS_ERROR_INVALID_PARAMETER);
1587+
else
1588+
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch,i965->codec_info->min_linear_wpitch),VA_STATUS_ERROR_INVALID_PARAMETER);
15251589

15261590
break;
15271591

15281592
case VA_FOURCC_YV16:
1529-
assert(memory_attibute->num_planes == 3);
1530-
assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
1593+
ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
1594+
ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
15311595

15321596
obj_surface->subsampling = SUBSAMPLE_YUV422H;
15331597
obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
15341598
obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
15351599
obj_surface->cb_cr_width = obj_surface->orig_width / 2;
15361600
obj_surface->cb_cr_height = obj_surface->orig_height;
15371601
obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1602+
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch,i965->codec_info->min_linear_wpitch),VA_STATUS_ERROR_INVALID_PARAMETER);
15381603

15391604
break;
15401605

@@ -1548,6 +1613,10 @@ i965_suface_external_memory(VADriverContextP ctx,
15481613
obj_surface->cb_cr_width = obj_surface->orig_width;
15491614
obj_surface->cb_cr_height = obj_surface->orig_height / 2;
15501615
obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1616+
if (tiling)
1617+
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch,128),VA_STATUS_ERROR_INVALID_PARAMETER);
1618+
else
1619+
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch,i965->codec_info->min_linear_wpitch),VA_STATUS_ERROR_INVALID_PARAMETER);
15511620

15521621
break;
15531622

@@ -1561,41 +1630,20 @@ i965_suface_external_memory(VADriverContextP ctx,
15611630
obj_surface->cb_cr_width = obj_surface->orig_width;
15621631
obj_surface->cb_cr_height = obj_surface->orig_height;
15631632
obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
1633+
if (tiling)
1634+
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch,128),VA_STATUS_ERROR_INVALID_PARAMETER);
1635+
else
1636+
ASSERT_RET(IS_ALIGNED(obj_surface->cb_cr_pitch,i965->codec_info->min_linear_wpitch),VA_STATUS_ERROR_INVALID_PARAMETER);
15641637

15651638
break;
15661639

15671640
default:
1568-
15691641
return VA_STATUS_ERROR_INVALID_PARAMETER;
15701642
}
15711643

1572-
if (external_memory_type == I965_SURFACE_MEM_GEM_FLINK)
1573-
obj_surface->bo = drm_intel_bo_gem_create_from_name(i965->intel.bufmgr,
1574-
"gem flinked vaapi surface",
1575-
memory_attibute->buffers[index]);
1576-
else if (external_memory_type == I965_SURFACE_MEM_DRM_PRIME)
1577-
obj_surface->bo = drm_intel_bo_gem_create_from_prime(i965->intel.bufmgr,
1578-
memory_attibute->buffers[index],
1579-
obj_surface->size);
1580-
1581-
if (!obj_surface->bo)
1582-
return VA_STATUS_ERROR_INVALID_PARAMETER;
1583-
15841644
return VA_STATUS_SUCCESS;
15851645
}
15861646

1587-
/* byte-per-pixel of the first plane */
1588-
static int
1589-
bpp_1stplane_by_fourcc(unsigned int fourcc)
1590-
{
1591-
const i965_fourcc_info *info = get_fourcc_info(fourcc);
1592-
1593-
if (info && (info->flag & I_S))
1594-
return info->bpp[0] / 8;
1595-
else
1596-
return 0;
1597-
}
1598-
15991647
static VAStatus
16001648
i965_CreateSurfaces2(
16011649
VADriverContextP ctx,

0 commit comments

Comments
 (0)