[igt-dev] [PATCH i-g-t v29 05/32] lib/intel_bufops: extract getting the stride

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Tue Aug 18 14:05:02 UTC 2020


Remove redundant code for getting the stride

v2: Fix using not initialized buf->tiling field
    (reported by Dominik)

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
 lib/intel_bufops.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/lib/intel_bufops.c b/lib/intel_bufops.c
index 35e3c0d2..871a28da 100644
--- a/lib/intel_bufops.c
+++ b/lib/intel_bufops.c
@@ -142,6 +142,16 @@ static inline bool is_tiling_supported(struct buf_ops *bops, uint32_t tiling)
 	return bops->supported_tiles & TILE_DEF(tiling);
 }
 
+static uint32_t get_stride(uint32_t devid, uint32_t tiling)
+{
+	uint32_t stride = 128;
+
+	if (IS_915G(devid) || IS_915GM(devid) || tiling == I915_TILING_X)
+		stride = 512;
+
+	return stride;
+}
+
 static int __gem_get_tiling(int fd, struct drm_i915_gem_get_tiling *arg)
 {
 	int err;
@@ -747,16 +757,9 @@ static void __intel_buf_init(struct buf_ops *bops,
 
 		size = buf->ccs[0].offset + aux_width * aux_height;
 	} else {
-		if (buf->tiling) {
+		if (tiling) {
 			devid =  intel_get_drm_devid(bops->fd);
-
-			if (bops->intel_gen < 3)
-				tile_width = 128;
-			else if (IS_915G(devid) || buf->tiling == I915_TILING_X)
-				tile_width = 512;
-			else
-				tile_width = 128;
-
+			tile_width = get_stride(devid, tiling);
 			buf->surface[0].stride = ALIGN(width * (bpp / 8), tile_width);
 		} else {
 			buf->surface[0].stride = ALIGN(width * (bpp / 8), alignment ?: 2);
@@ -1041,14 +1044,7 @@ static bool probe_hw_tiling(struct buf_ops *bops, uint32_t tiling,
 	bool is_set = false;
 
 	devid =  intel_get_drm_devid(bops->fd);
-
-	if (tiling == I915_TILING_X || IS_915G(devid))
-		stride = 512;
-	else if (tiling == I915_TILING_Y)
-		stride = 128;
-	else
-		return false;
-
+	stride = get_stride(devid, tiling);
 	handle = gem_create(bops->fd, size);
 
 	/* Single shot, if no fences are available we fail immediately */
-- 
2.26.0



More information about the igt-dev mailing list