<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Dec 6, 2016 at 3:05 AM, Lionel Landwerlin <span dir="ltr"><<a href="mailto:llandwerlin@gmail.com" target="_blank">llandwerlin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Signed-off-by: Lionel Landwerlin <<a href="mailto:lionel.g.landwerlin@intel.com">lionel.g.landwerlin@intel.com</a><wbr>><br>
---<br>
 src/intel/<a href="http://Makefile.isl.am" rel="noreferrer" target="_blank">Makefile.isl.am</a>                          |  10 +-<br>
 src/intel/isl/isl.c                                |  25 +++<br>
 src/intel/isl/isl.h                                |   8 +<br>
 src/intel/isl/tests/.gitignore                     |   1 +<br>
 .../tests/isl_surf_get_image_<wbr>depth_pitch_test.c    | 248 +++++++++++++++++++++<br>
 5 files changed, 291 insertions(+), 1 deletion(-)<br>
 create mode 100644 src/intel/isl/tests/isl_surf_<wbr>get_image_depth_pitch_test.c<br>
<br>
diff --git a/src/intel/<a href="http://Makefile.isl.am" rel="noreferrer" target="_blank">Makefile.isl.am</a> b/src/intel/<a href="http://Makefile.isl.am" rel="noreferrer" target="_blank">Makefile.isl.am</a><br>
index 5a317f522b..eb788f4a13 100644<br>
--- a/src/intel/<a href="http://Makefile.isl.am" rel="noreferrer" target="_blank">Makefile.isl.am</a><br>
+++ b/src/intel/<a href="http://Makefile.isl.am" rel="noreferrer" target="_blank">Makefile.isl.am</a><br>
@@ -67,10 +67,18 @@ isl/isl_format_layout.c: isl/gen_format_layout.py \<br>
 #  Tests<br>
 # ------------------------------<wbr>------------------------------<wbr>----------------<br>
<br>
-check_PROGRAMS += isl/tests/isl_surf_get_image_<wbr>offset_test<br>
+check_PROGRAMS += \<br>
+       isl/tests/isl_surf_get_image_<wbr>depth_pitch_test \<br>
+       isl/tests/isl_surf_get_image_<wbr>offset_test<br>
<br>
 TESTS += $(check_PROGRAMS)<br>
<br>
+isl_tests_isl_surf_get_image_<wbr>depth_pitch_test_LDADD = \<br>
+       common/<a href="http://libintel_common.la" rel="noreferrer" target="_blank">libintel_common.la</a> \<br>
+       isl/<a href="http://libisl.la" rel="noreferrer" target="_blank">libisl.la</a> \<br>
+       $(top_builddir)/src/mesa/<wbr>drivers/dri/i965/<a href="http://libi965_compiler.la" rel="noreferrer" target="_blank">libi965_<wbr>compiler.la</a> \<br>
+       -lm<br>
+<br>
 isl_tests_isl_surf_get_image_<wbr>offset_test_LDADD = \<br>
        common/<a href="http://libintel_common.la" rel="noreferrer" target="_blank">libintel_common.la</a> \<br>
        isl/<a href="http://libisl.la" rel="noreferrer" target="_blank">libisl.la</a> \<br>
diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c<br>
index 82ab68dc65..8c3aed92ac 100644<br>
--- a/src/intel/isl/isl.c<br>
+++ b/src/intel/isl/isl.c<br>
@@ -1874,3 +1874,28 @@ isl_surf_get_depth_format(<wbr>const struct isl_device *dev,<br>
       return 5; /* D16_UNORM */<br>
    }<br>
 }<br>
+<br>
+uint32_t<br>
+isl_surf_get_depth_pitch(<wbr>const struct isl_device *device,<br>
+                         const struct isl_surf *surf)<br>
+{<br>
+   switch (surf->dim_layout) {<br>
+   case ISL_DIM_LAYOUT_GEN9_1D:<br>
+   case ISL_DIM_LAYOUT_GEN4_2D:<br>
+      return isl_surf_get_array_pitch(surf)<wbr>;<br>
+   case ISL_DIM_LAYOUT_GEN4_3D: {<br>
+      if (surf->tiling == ISL_TILING_LINEAR)<br>
+         return surf->row_pitch * surf->phys_level0_sa.h;<br>
+<br>
+      struct isl_tile_info tile_info;<br>
+      isl_surf_get_tile_info(device, surf, &tile_info);<br>
+<br>
+      return isl_align(surf->row_pitch * surf->phys_level0_sa.h,<br>
+                       tile_info.phys_extent_B.width *<br>
+                       tile_info.phys_extent_B.<wbr>height);<br>
+      }<br></blockquote><div><br></div><div>Sorry, but this still isn't correct :/  What you really want is to align it to the surf->image_align_el.h<br><br></div><div>What is the motivation for this query?  To claim to have a useful depth pitch is 80% a lie on Broadwell and earlier so I'd prefer to not encourage apps with one.  At the very least, this function should take a LOD and assert that it's 0 for GEN4_3D surfaces so that users of ISL don't think that it returns a useful value on older hardware.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   default:<br>
+      unreachable("bad isl_dim_layout");<br>
+      break;<br>
+   }<br>
+}<br>
diff --git a/src/intel/isl/isl.h b/src/intel/isl/isl.h<br>
index 07368f9bcf..3ec76fabc9 100644<br>
--- a/src/intel/isl/isl.h<br>
+++ b/src/intel/isl/isl.h<br>
@@ -1392,6 +1392,14 @@ isl_surf_get_array_pitch(const struct isl_surf *surf)<br>
 }<br>
<br>
 /**<br>
+ * Pitch between depth slices, in bytes (for 2D images, this should be<br>
+ * equivalent to isl_surf_get_array_pitch()).<br>
+ */<br>
+uint32_t<br>
+isl_surf_get_depth_pitch(<wbr>const struct isl_device *device,<br>
+                         const struct isl_surf *surf);<br>
+<br>
+/**<br>
  * Calculate the offset, in units of surface samples, to a subimage in the<br>
  * surface.<br>
  *<br>
diff --git a/src/intel/isl/tests/.<wbr>gitignore b/src/intel/isl/tests/.<wbr>gitignore<br>
index ba70ecfbee..e90b4a4a97 100644<br>
--- a/src/intel/isl/tests/.<wbr>gitignore<br>
+++ b/src/intel/isl/tests/.<wbr>gitignore<br>
@@ -1 +1,2 @@<br>
+/isl_surf_get_image_depth_<wbr>pitch_test<br>
 /isl_surf_get_image_offset_<wbr>test<br>
diff --git a/src/intel/isl/tests/isl_<wbr>surf_get_image_depth_pitch_<wbr>test.c b/src/intel/isl/tests/isl_<wbr>surf_get_image_depth_pitch_<wbr>test.c<br>
new file mode 100644<br>
index 0000000000..725d1e2b48<br>
--- /dev/null<br>
+++ b/src/intel/isl/tests/isl_<wbr>surf_get_image_depth_pitch_<wbr>test.c<br>
@@ -0,0 +1,248 @@<br>
+/*<br>
+ * Copyright 2016 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
+ * DEALINGS IN THE SOFTWARE.<br>
+ */<br>
+<br>
+#include <assert.h><br>
+#include <stdbool.h><br>
+#include <stdio.h><br>
+#include <stdlib.h><br>
+<br>
+#include "common/gen_device_info.h"<br>
+#include "isl/isl.h"<br>
+#include "isl/isl_priv.h"<br>
+<br>
+#define BDW_GT2_DEVID 0x161a<br>
+<br>
+// An asssert that works regardless of NDEBUG.<br>
+#define t_assert(cond) \<br>
+   do { \<br>
+      if (!(cond)) { \<br>
+         fprintf(stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \<br>
+         abort(); \<br>
+      } \<br>
+   } while (0)<br>
+<br>
+static void<br>
+test_bdw_2d_r8g8b8a8_unorm_<wbr>42x43_levels09_tiley0(void)<br>
+{<br>
+   bool ok;<br>
+<br>
+   struct gen_device_info devinfo;<br>
+   t_assert(gen_get_device_info(<wbr>BDW_GT2_DEVID, &devinfo));<br>
+<br>
+   struct isl_device dev;<br>
+   isl_device_init(&dev, &devinfo, /*bit6_swizzle*/ false);<br>
+<br>
+   struct isl_surf surf;<br>
+   ok = isl_surf_init(&dev, &surf,<br>
+                      .dim = ISL_SURF_DIM_2D,<br>
+                      .format = ISL_FORMAT_R8G8B8A8_UNORM,<br>
+                      .width = 42,<br>
+                      .height = 43,<br>
+                      .depth = 1,<br>
+                      .levels = 9,<br>
+                      .array_len = 1,<br>
+                      .samples = 1,<br>
+                      .usage = ISL_SURF_USAGE_TEXTURE_BIT |<br>
+                               ISL_SURF_USAGE_DISABLE_AUX_<wbr>BIT,<br>
+                      .tiling_flags = ISL_TILING_Y0_BIT);<br>
+   t_assert(ok);<br>
+<br>
+   uint32_t depth_pitch =<br>
+      isl_surf_get_depth_pitch(&dev, &surf);<br>
+<br>
+   t_assert(depth_pitch == isl_surf_get_array_pitch(&<wbr>surf));<br>
+}<br>
+<br>
+static void<br>
+test_bdw_3d_r8g8b8a8_unorm_<wbr>256x256x256_levels09_tiley0(<wbr>void)<br>
+{<br>
+   bool ok;<br>
+<br>
+   struct gen_device_info devinfo;<br>
+   t_assert(gen_get_device_info(<wbr>BDW_GT2_DEVID, &devinfo));<br>
+<br>
+   struct isl_device dev;<br>
+   isl_device_init(&dev, &devinfo, /*bit6_swizzle*/ false);<br>
+<br>
+   struct isl_surf surf;<br>
+   ok = isl_surf_init(&dev, &surf,<br>
+                      .dim = ISL_SURF_DIM_3D,<br>
+                      .format = ISL_FORMAT_R8G8B8A8_UNORM,<br>
+                      .width = 256,<br>
+                      .height = 256,<br>
+                      .depth = 256,<br>
+                      .levels = 9,<br>
+                      .array_len = 1,<br>
+                      .samples = 1,<br>
+                      .usage = ISL_SURF_USAGE_TEXTURE_BIT |<br>
+                               ISL_SURF_USAGE_DISABLE_AUX_<wbr>BIT,<br>
+                      .tiling_flags = ISL_TILING_Y0_BIT);<br>
+   t_assert(ok);<br>
+<br>
+   uint32_t depth_pitch =<br>
+      isl_surf_get_depth_pitch(&dev, &surf);<br>
+<br>
+   t_assert(depth_pitch >= 256 * 256 * 4);<br>
+   t_assert(depth_pitch < isl_surf_get_array_pitch(&<wbr>surf));<br>
+   t_assert(depth_pitch % 4096 == 0);<br>
+}<br>
+<br>
+static void<br>
+test_bdw_3d_r8g8b8a8_unorm_<wbr>256x256x256_levels09_linear(<wbr>void)<br>
+{<br>
+   bool ok;<br>
+<br>
+   struct gen_device_info devinfo;<br>
+   t_assert(gen_get_device_info(<wbr>BDW_GT2_DEVID, &devinfo));<br>
+<br>
+   struct isl_device dev;<br>
+   isl_device_init(&dev, &devinfo, /*bit6_swizzle*/ false);<br>
+<br>
+   struct isl_surf surf;<br>
+   ok = isl_surf_init(&dev, &surf,<br>
+                      .dim = ISL_SURF_DIM_3D,<br>
+                      .format = ISL_FORMAT_R8G8B8A8_UNORM,<br>
+                      .width = 256,<br>
+                      .height = 256,<br>
+                      .depth = 256,<br>
+                      .levels = 1,<br>
+                      .array_len = 1,<br>
+                      .samples = 1,<br>
+                      .usage = ISL_SURF_USAGE_TEXTURE_BIT |<br>
+                               ISL_SURF_USAGE_DISABLE_AUX_<wbr>BIT,<br>
+                      .tiling_flags = ISL_TILING_LINEAR_BIT);<br>
+   t_assert(ok);<br>
+<br>
+   uint32_t depth_pitch =<br>
+      isl_surf_get_depth_pitch(&dev, &surf);<br>
+<br>
+   t_assert(depth_pitch >= 256 * 256 * 4);<br>
+   t_assert(depth_pitch < isl_surf_get_array_pitch(&<wbr>surf));<br>
+}<br>
+<br>
+static void<br>
+test_bdw_3d_r8g8b8_unorm_<wbr>256x256x256_levels09_linear(<wbr>void)<br>
+{<br>
+   bool ok;<br>
+<br>
+   struct gen_device_info devinfo;<br>
+   t_assert(gen_get_device_info(<wbr>BDW_GT2_DEVID, &devinfo));<br>
+<br>
+   struct isl_device dev;<br>
+   isl_device_init(&dev, &devinfo, /*bit6_swizzle*/ false);<br>
+<br>
+   struct isl_surf surf;<br>
+   ok = isl_surf_init(&dev, &surf,<br>
+                      .dim = ISL_SURF_DIM_3D,<br>
+                      .format = ISL_FORMAT_R8G8B8_UNORM,<br>
+                      .width = 256,<br>
+                      .height = 256,<br>
+                      .depth = 256,<br>
+                      .levels = 1,<br>
+                      .array_len = 1,<br>
+                      .samples = 1,<br>
+                      .usage = ISL_SURF_USAGE_TEXTURE_BIT |<br>
+                               ISL_SURF_USAGE_DISABLE_AUX_<wbr>BIT,<br>
+                      .tiling_flags = ISL_TILING_LINEAR_BIT);<br>
+   t_assert(ok);<br>
+<br>
+   uint32_t depth_pitch =<br>
+      isl_surf_get_depth_pitch(&dev, &surf);<br>
+<br>
+   t_assert(depth_pitch >= 256 * 256 * 3);<br>
+   t_assert(depth_pitch < isl_surf_get_array_pitch(&<wbr>surf));<br>
+}<br>
+<br>
+static void<br>
+test_bdw_2d_r8g8b8a8_unorm_<wbr>256x256x256_levels09_linear(<wbr>void)<br>
+{<br>
+   bool ok;<br>
+<br>
+   struct gen_device_info devinfo;<br>
+   t_assert(gen_get_device_info(<wbr>BDW_GT2_DEVID, &devinfo));<br>
+<br>
+   struct isl_device dev;<br>
+   isl_device_init(&dev, &devinfo, /*bit6_swizzle*/ false);<br>
+<br>
+   struct isl_surf surf;<br>
+   ok = isl_surf_init(&dev, &surf,<br>
+                      .dim = ISL_SURF_DIM_2D,<br>
+                      .format = ISL_FORMAT_R8G8B8A8_UNORM,<br>
+                      .width = 256,<br>
+                      .height = 256,<br>
+                      .depth = 1,<br>
+                      .levels = 1,<br>
+                      .array_len = 256,<br>
+                      .samples = 1,<br>
+                      .usage = ISL_SURF_USAGE_TEXTURE_BIT |<br>
+                               ISL_SURF_USAGE_DISABLE_AUX_<wbr>BIT,<br>
+                      .tiling_flags = ISL_TILING_LINEAR_BIT);<br>
+   t_assert(ok);<br>
+<br>
+   uint32_t depth_pitch =<br>
+      isl_surf_get_depth_pitch(&dev, &surf);<br>
+<br>
+   t_assert(depth_pitch == isl_surf_get_array_pitch(&<wbr>surf));<br>
+}<br>
+<br>
+static void<br>
+test_bdw_1d_r8g8b8a8_unorm_<wbr>256_levels09_linear(void)<br>
+{<br>
+   bool ok;<br>
+<br>
+   struct gen_device_info devinfo;<br>
+   t_assert(gen_get_device_info(<wbr>BDW_GT2_DEVID, &devinfo));<br>
+<br>
+   struct isl_device dev;<br>
+   isl_device_init(&dev, &devinfo, /*bit6_swizzle*/ false);<br>
+<br>
+   struct isl_surf surf;<br>
+   ok = isl_surf_init(&dev, &surf,<br>
+                      .dim = ISL_SURF_DIM_1D,<br>
+                      .format = ISL_FORMAT_R8G8B8A8_UNORM,<br>
+                      .width = 256,<br>
+                      .height = 1,<br>
+                      .depth = 1,<br>
+                      .levels = 1,<br>
+                      .array_len = 1,<br>
+                      .samples = 1,<br>
+                      .usage = ISL_SURF_USAGE_TEXTURE_BIT |<br>
+                               ISL_SURF_USAGE_DISABLE_AUX_<wbr>BIT,<br>
+                      .tiling_flags = ISL_TILING_LINEAR_BIT);<br>
+   t_assert(ok);<br>
+<br>
+   uint32_t depth_pitch =<br>
+      isl_surf_get_depth_pitch(&dev, &surf);<br>
+<br>
+   t_assert(depth_pitch == isl_surf_get_array_pitch(&<wbr>surf));<br>
+}<br>
+<br>
+int main(void)<br>
+{<br>
+   test_bdw_2d_r8g8b8a8_unorm_<wbr>42x43_levels09_tiley0();<br>
+   test_bdw_3d_r8g8b8a8_unorm_<wbr>256x256x256_levels09_tiley0();<br>
+   test_bdw_3d_r8g8b8a8_unorm_<wbr>256x256x256_levels09_linear();<br>
+   test_bdw_3d_r8g8b8_unorm_<wbr>256x256x256_levels09_linear();<br>
+   test_bdw_2d_r8g8b8a8_unorm_<wbr>256x256x256_levels09_linear();<br>
+   test_bdw_1d_r8g8b8a8_unorm_<wbr>256_levels09_linear();<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.11.0<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>