@@ -1361,6 +1361,18 @@ i965_destroy_surface(struct object_heap *heap, struct object_base *obj)
1361
1361
object_heap_free (heap , obj );
1362
1362
}
1363
1363
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
+
1364
1376
static VAStatus
1365
1377
i965_surface_native_memory (VADriverContextP ctx ,
1366
1378
struct object_surface * obj_surface ,
@@ -1392,7 +1404,22 @@ i965_suface_external_memory(VADriverContextP ctx,
1392
1404
int index )
1393
1405
{
1394
1406
struct i965_driver_data * i965 = i965_driver_data (ctx );
1407
+ unsigned int tiling ,swizzle ;
1395
1408
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 );
1396
1423
if (!memory_attibute ||
1397
1424
!memory_attibute -> buffers ||
1398
1425
index > memory_attibute -> num_buffers )
@@ -1404,15 +1431,33 @@ i965_suface_external_memory(VADriverContextP ctx,
1404
1431
1405
1432
obj_surface -> fourcc = memory_attibute -> pixel_format ;
1406
1433
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 );
1408
1437
1409
1438
if (memory_attibute -> num_planes == 1 )
1410
1439
obj_surface -> height = memory_attibute -> data_size / obj_surface -> width ;
1411
1440
else
1412
1441
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
+ }
1413
1452
1414
1453
obj_surface -> x_cb_offset = 0 ; /* X offset is always 0 */
1415
1454
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 ;
1416
1461
1417
1462
switch (obj_surface -> fourcc ) {
1418
1463
case VA_FOURCC_NV12 :
@@ -1426,6 +1471,10 @@ i965_suface_external_memory(VADriverContextP ctx,
1426
1471
obj_surface -> cb_cr_width = obj_surface -> orig_width / 2 ;
1427
1472
obj_surface -> cb_cr_height = obj_surface -> orig_height / 2 ;
1428
1473
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 );
1429
1478
1430
1479
break ;
1431
1480
@@ -1440,7 +1489,11 @@ i965_suface_external_memory(VADriverContextP ctx,
1440
1489
obj_surface -> cb_cr_width = obj_surface -> orig_width / 2 ;
1441
1490
obj_surface -> cb_cr_height = obj_surface -> orig_height / 2 ;
1442
1491
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
+
1444
1497
break ;
1445
1498
1446
1499
case VA_FOURCC_I420 :
@@ -1456,6 +1509,10 @@ i965_suface_external_memory(VADriverContextP ctx,
1456
1509
obj_surface -> cb_cr_width = obj_surface -> orig_width / 2 ;
1457
1510
obj_surface -> cb_cr_height = obj_surface -> orig_height / 2 ;
1458
1511
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 );
1459
1516
1460
1517
break ;
1461
1518
@@ -1489,7 +1546,7 @@ i965_suface_external_memory(VADriverContextP ctx,
1489
1546
1490
1547
case VA_FOURCC_Y800 : /* monochrome surface */
1491
1548
ASSERT_RET (memory_attibute -> num_planes == 1 , VA_STATUS_ERROR_INVALID_PARAMETER );
1492
-
1549
+
1493
1550
obj_surface -> subsampling = SUBSAMPLE_YUV400 ;
1494
1551
obj_surface -> y_cb_offset = 0 ;
1495
1552
obj_surface -> y_cr_offset = 0 ;
@@ -1509,7 +1566,10 @@ i965_suface_external_memory(VADriverContextP ctx,
1509
1566
obj_surface -> cb_cr_width = obj_surface -> orig_width / 4 ;
1510
1567
obj_surface -> cb_cr_height = obj_surface -> orig_height ;
1511
1568
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 );
1513
1573
break ;
1514
1574
1515
1575
case VA_FOURCC_422H :
@@ -1522,19 +1582,24 @@ i965_suface_external_memory(VADriverContextP ctx,
1522
1582
obj_surface -> cb_cr_width = obj_surface -> orig_width / 2 ;
1523
1583
obj_surface -> cb_cr_height = obj_surface -> orig_height ;
1524
1584
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 );
1525
1589
1526
1590
break ;
1527
1591
1528
1592
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 );
1531
1595
1532
1596
obj_surface -> subsampling = SUBSAMPLE_YUV422H ;
1533
1597
obj_surface -> y_cr_offset = memory_attibute -> offsets [1 ] / obj_surface -> width ;
1534
1598
obj_surface -> y_cb_offset = memory_attibute -> offsets [2 ] / obj_surface -> width ;
1535
1599
obj_surface -> cb_cr_width = obj_surface -> orig_width / 2 ;
1536
1600
obj_surface -> cb_cr_height = obj_surface -> orig_height ;
1537
1601
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 );
1538
1603
1539
1604
break ;
1540
1605
@@ -1548,6 +1613,10 @@ i965_suface_external_memory(VADriverContextP ctx,
1548
1613
obj_surface -> cb_cr_width = obj_surface -> orig_width ;
1549
1614
obj_surface -> cb_cr_height = obj_surface -> orig_height / 2 ;
1550
1615
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 );
1551
1620
1552
1621
break ;
1553
1622
@@ -1561,41 +1630,20 @@ i965_suface_external_memory(VADriverContextP ctx,
1561
1630
obj_surface -> cb_cr_width = obj_surface -> orig_width ;
1562
1631
obj_surface -> cb_cr_height = obj_surface -> orig_height ;
1563
1632
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 );
1564
1637
1565
1638
break ;
1566
1639
1567
1640
default :
1568
-
1569
1641
return VA_STATUS_ERROR_INVALID_PARAMETER ;
1570
1642
}
1571
1643
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
-
1584
1644
return VA_STATUS_SUCCESS ;
1585
1645
}
1586
1646
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
-
1599
1647
static VAStatus
1600
1648
i965_CreateSurfaces2 (
1601
1649
VADriverContextP ctx ,
0 commit comments