@@ -1280,7 +1280,6 @@ svga3dsurface_get_pixel_offset(SVGA3dSurfaceFormat format,
12801280 return offset ;
12811281}
12821282
1283-
12841283static inline u32
12851284svga3dsurface_get_image_offset (SVGA3dSurfaceFormat format ,
12861285 surf_size_struct baseLevelSize ,
@@ -1375,4 +1374,236 @@ svga3dsurface_is_screen_target_format(SVGA3dSurfaceFormat format)
13751374 return svga3dsurface_is_dx_screen_target_format (format );
13761375}
13771376
1377+ /**
1378+ * struct svga3dsurface_mip - Mimpmap level information
1379+ * @bytes: Bytes required in the backing store of this mipmap level.
1380+ * @img_stride: Byte stride per image.
1381+ * @row_stride: Byte stride per block row.
1382+ * @size: The size of the mipmap.
1383+ */
1384+ struct svga3dsurface_mip {
1385+ size_t bytes ;
1386+ size_t img_stride ;
1387+ size_t row_stride ;
1388+ struct drm_vmw_size size ;
1389+
1390+ };
1391+
1392+ /**
1393+ * struct svga3dsurface_cache - Cached surface information
1394+ * @desc: Pointer to the surface descriptor
1395+ * @mip: Array of mipmap level information. Valid size is @num_mip_levels.
1396+ * @mip_chain_bytes: Bytes required in the backing store for the whole chain
1397+ * of mip levels.
1398+ * @sheet_bytes: Bytes required in the backing store for a sheet
1399+ * representing a single sample.
1400+ * @num_mip_levels: Valid size of the @mip array. Number of mipmap levels in
1401+ * a chain.
1402+ * @num_layers: Number of slices in an array texture or number of faces in
1403+ * a cubemap texture.
1404+ */
1405+ struct svga3dsurface_cache {
1406+ const struct svga3d_surface_desc * desc ;
1407+ struct svga3dsurface_mip mip [DRM_VMW_MAX_MIP_LEVELS ];
1408+ size_t mip_chain_bytes ;
1409+ size_t sheet_bytes ;
1410+ u32 num_mip_levels ;
1411+ u32 num_layers ;
1412+ };
1413+
1414+ /**
1415+ * struct svga3dsurface_loc - Surface location
1416+ * @sub_resource: Surface subresource. Defined as layer * num_mip_levels +
1417+ * mip_level.
1418+ * @x: X coordinate.
1419+ * @y: Y coordinate.
1420+ * @z: Z coordinate.
1421+ */
1422+ struct svga3dsurface_loc {
1423+ u32 sub_resource ;
1424+ u32 x , y , z ;
1425+ };
1426+
1427+ /**
1428+ * svga3dsurface_subres - Compute the subresource from layer and mipmap.
1429+ * @cache: Surface layout data.
1430+ * @mip_level: The mipmap level.
1431+ * @layer: The surface layer (face or array slice).
1432+ *
1433+ * Return: The subresource.
1434+ */
1435+ static inline u32 svga3dsurface_subres (const struct svga3dsurface_cache * cache ,
1436+ u32 mip_level , u32 layer )
1437+ {
1438+ return cache -> num_mip_levels * layer + mip_level ;
1439+ }
1440+
1441+ /**
1442+ * svga3dsurface_setup_cache - Build a surface cache entry
1443+ * @size: The surface base level dimensions.
1444+ * @format: The surface format.
1445+ * @num_mip_levels: Number of mipmap levels.
1446+ * @num_layers: Number of layers.
1447+ * @cache: Pointer to a struct svga3dsurface_cach object to be filled in.
1448+ *
1449+ * Return: Zero on success, -EINVAL on invalid surface layout.
1450+ */
1451+ static inline int svga3dsurface_setup_cache (const struct drm_vmw_size * size ,
1452+ SVGA3dSurfaceFormat format ,
1453+ u32 num_mip_levels ,
1454+ u32 num_layers ,
1455+ u32 num_samples ,
1456+ struct svga3dsurface_cache * cache )
1457+ {
1458+ const struct svga3d_surface_desc * desc ;
1459+ u32 i ;
1460+
1461+ memset (cache , 0 , sizeof (* cache ));
1462+ cache -> desc = desc = svga3dsurface_get_desc (format );
1463+ cache -> num_mip_levels = num_mip_levels ;
1464+ cache -> num_layers = num_layers ;
1465+ for (i = 0 ; i < cache -> num_mip_levels ; i ++ ) {
1466+ struct svga3dsurface_mip * mip = & cache -> mip [i ];
1467+
1468+ mip -> size = svga3dsurface_get_mip_size (* size , i );
1469+ mip -> bytes = svga3dsurface_get_image_buffer_size
1470+ (desc , & mip -> size , 0 );
1471+ mip -> row_stride =
1472+ __KERNEL_DIV_ROUND_UP (mip -> size .width ,
1473+ desc -> block_size .width ) *
1474+ desc -> bytes_per_block * num_samples ;
1475+ if (!mip -> row_stride )
1476+ goto invalid_dim ;
1477+
1478+ mip -> img_stride =
1479+ __KERNEL_DIV_ROUND_UP (mip -> size .height ,
1480+ desc -> block_size .height ) *
1481+ mip -> row_stride ;
1482+ if (!mip -> img_stride )
1483+ goto invalid_dim ;
1484+
1485+ cache -> mip_chain_bytes += mip -> bytes ;
1486+ }
1487+ cache -> sheet_bytes = cache -> mip_chain_bytes * num_layers ;
1488+ if (!cache -> sheet_bytes )
1489+ goto invalid_dim ;
1490+
1491+ return 0 ;
1492+
1493+ invalid_dim :
1494+ VMW_DEBUG_USER ("Invalid surface layout for dirty tracking.\n" );
1495+ return - EINVAL ;
1496+ }
1497+
1498+ /**
1499+ * svga3dsurface_get_loc - Get a surface location from an offset into the
1500+ * backing store
1501+ * @cache: Surface layout data.
1502+ * @loc: Pointer to a struct svga3dsurface_loc to be filled in.
1503+ * @offset: Offset into the surface backing store.
1504+ */
1505+ static inline void
1506+ svga3dsurface_get_loc (const struct svga3dsurface_cache * cache ,
1507+ struct svga3dsurface_loc * loc ,
1508+ size_t offset )
1509+ {
1510+ const struct svga3dsurface_mip * mip = & cache -> mip [0 ];
1511+ const struct svga3d_surface_desc * desc = cache -> desc ;
1512+ u32 layer ;
1513+ int i ;
1514+
1515+ if (offset >= cache -> sheet_bytes )
1516+ offset %= cache -> sheet_bytes ;
1517+
1518+ layer = offset / cache -> mip_chain_bytes ;
1519+ offset -= layer * cache -> mip_chain_bytes ;
1520+ for (i = 0 ; i < cache -> num_mip_levels ; ++ i , ++ mip ) {
1521+ if (mip -> bytes > offset )
1522+ break ;
1523+ offset -= mip -> bytes ;
1524+ }
1525+
1526+ loc -> sub_resource = svga3dsurface_subres (cache , i , layer );
1527+ loc -> z = offset / mip -> img_stride ;
1528+ offset -= loc -> z * mip -> img_stride ;
1529+ loc -> z *= desc -> block_size .depth ;
1530+ loc -> y = offset / mip -> row_stride ;
1531+ offset -= loc -> y * mip -> row_stride ;
1532+ loc -> y *= desc -> block_size .height ;
1533+ loc -> x = offset / desc -> bytes_per_block ;
1534+ loc -> x *= desc -> block_size .width ;
1535+ }
1536+
1537+ /**
1538+ * svga3dsurface_inc_loc - Clamp increment a surface location with one block
1539+ * size
1540+ * in each dimension.
1541+ * @loc: Pointer to a struct svga3dsurface_loc to be incremented.
1542+ *
1543+ * When computing the size of a range as size = end - start, the range does not
1544+ * include the end element. However a location representing the last byte
1545+ * of a touched region in the backing store *is* included in the range.
1546+ * This function modifies such a location to match the end definition
1547+ * given as start + size which is the one used in a SVGA3dBox.
1548+ */
1549+ static inline void
1550+ svga3dsurface_inc_loc (const struct svga3dsurface_cache * cache ,
1551+ struct svga3dsurface_loc * loc )
1552+ {
1553+ const struct svga3d_surface_desc * desc = cache -> desc ;
1554+ u32 mip = loc -> sub_resource % cache -> num_mip_levels ;
1555+ const struct drm_vmw_size * size = & cache -> mip [mip ].size ;
1556+
1557+ loc -> sub_resource ++ ;
1558+ loc -> x += desc -> block_size .width ;
1559+ if (loc -> x > size -> width )
1560+ loc -> x = size -> width ;
1561+ loc -> y += desc -> block_size .height ;
1562+ if (loc -> y > size -> height )
1563+ loc -> y = size -> height ;
1564+ loc -> z += desc -> block_size .depth ;
1565+ if (loc -> z > size -> depth )
1566+ loc -> z = size -> depth ;
1567+ }
1568+
1569+ /**
1570+ * svga3dsurface_min_loc - The start location in a subresource
1571+ * @cache: Surface layout data.
1572+ * @sub_resource: The subresource.
1573+ * @loc: Pointer to a struct svga3dsurface_loc to be filled in.
1574+ */
1575+ static inline void
1576+ svga3dsurface_min_loc (const struct svga3dsurface_cache * cache ,
1577+ u32 sub_resource ,
1578+ struct svga3dsurface_loc * loc )
1579+ {
1580+ loc -> sub_resource = sub_resource ;
1581+ loc -> x = loc -> y = loc -> z = 0 ;
1582+ }
1583+
1584+ /**
1585+ * svga3dsurface_min_loc - The end location in a subresource
1586+ * @cache: Surface layout data.
1587+ * @sub_resource: The subresource.
1588+ * @loc: Pointer to a struct svga3dsurface_loc to be filled in.
1589+ *
1590+ * Following the end definition given in svga3dsurface_inc_loc(),
1591+ * Compute the end location of a surface subresource.
1592+ */
1593+ static inline void
1594+ svga3dsurface_max_loc (const struct svga3dsurface_cache * cache ,
1595+ u32 sub_resource ,
1596+ struct svga3dsurface_loc * loc )
1597+ {
1598+ const struct drm_vmw_size * size ;
1599+ u32 mip ;
1600+
1601+ loc -> sub_resource = sub_resource + 1 ;
1602+ mip = sub_resource % cache -> num_mip_levels ;
1603+ size = & cache -> mip [mip ].size ;
1604+ loc -> x = size -> width ;
1605+ loc -> y = size -> height ;
1606+ loc -> z = size -> depth ;
1607+ }
1608+
13781609#endif /* _SVGA3D_SURFACEDEFS_H_ */
0 commit comments