From fb1350c76f1525e6bd320cef62d55aff19ec3f05 Mon Sep 17 00:00:00 2001
From: Nanley Chery <nanley.g.chery@intel.com>
Date: Thu, 23 May 2019 13:44:52 -0700
Subject: intel: Add and use helpers for level0 extent

Prepare for a bug fix by adding and using helpers which convert
isl_surf::logical_level0_px and isl_surf::phys_level0_sa to units of
surface elements.

v2:
- Update iris (Ken).
- Update anv.

Cc: <mesa-stable@lists.freedesktop.org>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
---
 src/intel/isl/isl.h | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

(limited to 'src/intel/isl')

diff --git a/src/intel/isl/isl.h b/src/intel/isl/isl.h
index 0218f05d175..162301e4bf6 100644
--- a/src/intel/isl/isl.h
+++ b/src/intel/isl/isl.h
@@ -1885,6 +1885,38 @@ isl_surf_get_image_alignment_sa(const struct isl_surf *surf)
                        fmtl->bd * surf->image_alignment_el.d);
 }
 
+/**
+ * Logical extent of level 0 in units of surface elements.
+ */
+static inline struct isl_extent4d
+isl_surf_get_logical_level0_el(const struct isl_surf *surf)
+{
+   const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
+
+   return isl_extent4d(DIV_ROUND_UP(surf->logical_level0_px.w, fmtl->bw),
+                       DIV_ROUND_UP(surf->logical_level0_px.h, fmtl->bh),
+                       DIV_ROUND_UP(surf->logical_level0_px.d, fmtl->bd),
+                       surf->logical_level0_px.a);
+}
+
+/**
+ * Physical extent of level 0 in units of surface elements.
+ */
+static inline struct isl_extent4d
+isl_surf_get_phys_level0_el(const struct isl_surf *surf)
+{
+   const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
+
+   assert(surf->phys_level0_sa.w % fmtl->bw == 0);
+   assert(surf->phys_level0_sa.h % fmtl->bh == 0);
+   assert(surf->phys_level0_sa.d % fmtl->bd == 0);
+
+   return isl_extent4d(surf->phys_level0_sa.w / fmtl->bw,
+                       surf->phys_level0_sa.h / fmtl->bh,
+                       surf->phys_level0_sa.d / fmtl->bd,
+                       surf->phys_level0_sa.a);
+}
+
 /**
  * Pitch between vertically adjacent surface elements, in bytes.
  */
-- 
cgit v1.2.3