<div dir="auto"><div><div class="gmail_extra"><div class="gmail_quote">On Dec 8, 2016 8:48 AM, "Lionel Landwerlin" <<a href="mailto:llandwerlin@gmail.com">llandwerlin@gmail.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">v2: add lod level argument (Jason)<br>
    return 0 for any lod level > 0 (Jason)<br>
    return 0 for any surface not 3D (Jason)</blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">I'd rather have ISL assert these than just silently return 0.  That way it's clear they make no sense.  We can have a dimension check in the Vulkan driver where it calls this function.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="quoted-text">
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>
</div> src/intel/isl/isl.c                                |  28 +++<br>
 src/intel/isl/isl.h                                |  11 +<br>
 src/intel/isl/tests/.gitignore                     |   1 +<br>
 .../tests/isl_surf_get_image_<wbr>depth_pitch_test.c    | 245 +++++++++++++++++++++<br>
 5 files changed, 294 insertions(+), 1 deletion(-)<br>
<div class="quoted-text"> 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>
</div>index 82ab68dc65..0d61cd7cdc 100644<br>
--- a/src/intel/isl/isl.c<br>
+++ b/src/intel/isl/isl.c<br>
@@ -1874,3 +1874,31 @@ isl_surf_get_depth_format(<wbr>const struct isl_device *dev,<br>
<div class="quoted-text">       return 5; /* D16_UNORM */<br>
    }<br>
 }<br>
+<br>
+uint32_t<br>
+isl_surf_get_depth_pitch(<wbr>const struct isl_device *device,<br></div></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">Could you please put some units on this function?</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="quoted-text">
</div>+                         const struct isl_surf *surf,<br>
+                         uint32_t level)<br>
<div class="quoted-text">+{<br>
+   switch (surf->dim_layout) {<br>
+   case ISL_DIM_LAYOUT_GEN9_1D:<br>
+   case ISL_DIM_LAYOUT_GEN4_2D:<br>
</div>+      return 0;<br></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">This isn't right.  On Sky Lake and above, 3D surfaces have the GEN4_2D layout.  The depth pitch does make sense here and it's equal to the array pitch for all miplevels.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   case ISL_DIM_LAYOUT_GEN4_3D: {<br>
+      if (level > 0)<br>
+         return 0;<br>
+<br>
<div class="quoted-text">+      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>
</div>+      return surf->row_pitch * isl_align(surf->phys_level0_<wbr>sa.h,<br>
+                                         surf->image_alignment_el.h);<br></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">This calculation isn't right.  In both cases, it should simply be the height of lod0 aligned to the surface vertical alignment.  It has nothing to do with tiling so fat as I know.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      }<br>
<div class="quoted-text">+   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>
</div>index 07368f9bcf..7c033f380c 100644<br>
--- a/src/intel/isl/isl.h<br>
+++ b/src/intel/isl/isl.h<br>
@@ -1388,10 +1388,21 @@ isl_surf_get_array_pitch_sa_<wbr>rows(const struct isl_surf *surf)<br>
 static inline uint32_t<br>
 isl_surf_get_array_pitch(const struct isl_surf *surf)<br>
 {<br>
+   if (surf->dim_layout == ISL_DIM_LAYOUT_GEN4_3D)<br>
+      return 0;<br>
    return isl_surf_get_array_pitch_sa_<wbr>rows(surf) * surf->row_pitch;<br>
<div class="quoted-text"> }<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>
</div>+                         const struct isl_surf *surf,<br>
+                         uint32_t level);<br>
<div class="quoted-text">+<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>
</div>index 0000000000..d59ad9b2a9<br>
--- /dev/null<br>
+++ b/src/intel/isl/tests/isl_<wbr>surf_get_image_depth_pitch_<wbr>test.c<br>
@@ -0,0 +1,245 @@<br>
<div class="elided-text">+/*<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>
</div>+      isl_surf_get_depth_pitch(&dev, &surf, 0);<br>
+<br>
+   t_assert(depth_pitch == 0);<br>
+}<br>
+<br>
+static void<br>
<div class="elided-text">+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>
</div>+      isl_surf_get_depth_pitch(&dev, &surf, 0);<br>
<div class="quoted-text">+<br>
+   t_assert(depth_pitch >= 256 * 256 * 4);<br>
</div>+   t_assert(depth_pitch % 4096 == 0);<br>
<div class="elided-text">+}<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>
</div>+      isl_surf_get_depth_pitch(&dev, &surf, 0);<br>
<div class="quoted-text">+<br>
+   t_assert(depth_pitch >= 256 * 256 * 4);<br>
+}<br>
</div><div class="elided-text">+<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>
</div>+      isl_surf_get_depth_pitch(&dev, &surf, 0);<br>
<div class="quoted-text">+<br>
+   t_assert(depth_pitch >= 256 * 256 * 3);<br>
+}<br>
</div><div class="elided-text">+<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>
</div>+      isl_surf_get_depth_pitch(&dev, &surf, 0);<br>
+<br>
+   t_assert(depth_pitch == 0);<br>
+}<br>
+<br>
+static void<br>
<div class="elided-text">+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>
</div>+      isl_surf_get_depth_pitch(&dev, &surf, 0);<br>
+<br>
+   t_assert(depth_pitch == 0);<br>
<div class="elided-text">+}<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>
--<br>
2.11.0<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>
</div></blockquote></div><br></div></div></div>