<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Mon, Nov 19, 2018 at 12:30 PM Pohjolainen, Topi <<a href="mailto:topi.pohjolainen@gmail.com">topi.pohjolainen@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, Oct 12, 2018 at 01:46:56PM -0500, Jason Ekstrand wrote:<br>
> Unfortunately, there is no nice way to calculate miptail offsets in<br>
> closed form.  Instead, we just copy the tables from the PRM directly<br>
> verbatim.<br>
> ---<br>
>  src/intel/isl/isl.c | 217 +++++++++++++++++++++++++++++++++++++++++++-<br>
>  1 file changed, 213 insertions(+), 4 deletions(-)<br>
> <br>
> diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c<br>
> index 3657b11ee00..c86390bf851 100644<br>
> --- a/src/intel/isl/isl.c<br>
> +++ b/src/intel/isl/isl.c<br>
> @@ -863,6 +863,169 @@ isl_calc_phys_level0_extent_sa(const struct isl_device *dev,<br>
>     }<br>
>  }<br>
>  <br>
> +static const uint16_t std_y_1d_miptail_offset_el[] = {<br>
> +/* 128 bpb */<br>
> +   2048,<br>
> +   1024,<br>
> +   512,<br>
> +   256,<br>
> +   128,<br>
> +   64,<br>
> +   48,<br>
> +   32,<br>
> +   28,<br>
> +   24,<br>
> +   20,<br>
> +   16,<br>
> +   12,<br>
> +   8,<br>
> +   4,<br>
> +   0,<br>
> +};<br>
> +<br>
> +static const uint8_t gen9_std_y_2d_miptail_offset_el[][5][2] = {<br>
> +/*   128 bpb    64 bpb    32 bpb    16 bpb      8 bpb     */<br>
> +   { {32,  0}, {64,  0}, {64,  0}, {128,  0}, {128,  0} },<br>
> +   { { 0, 32}, { 0, 32}, { 0, 64}, {  0, 64}, {  0,128} },<br>
> +   { {16,  0}, {32,  0}, {32,  0}, { 64,  0}, { 64,  0} },<br>
> +   { { 0, 16}, { 0, 16}, { 0, 32}, {  0, 32}, {  0, 64} },<br>
> +   { { 8,  0}, {16,  0}, {16,  0}, { 32,  0}, { 32,  0} },<br>
> +   { { 4,  8}, { 8,  8}, { 8, 16}, { 16, 16}, { 16, 32} },<br>
> +   { { 0, 12}, { 0, 12}, { 0, 24}, {  0, 24}, {  0, 48} },<br>
> +   { { 0,  8}, { 0,  8}, { 0, 16}, {  0, 16}, {  0, 32} },<br>
> +   { { 4,  4}, { 8,  4}, { 8,  8}, { 16,  8}, { 16, 16} },<br>
> +   { { 4,  0}, { 8,  0}, { 8,  0}, { 16,  0}, { 16,  0} },<br>
> +   { { 0,  4}, { 0,  4}, { 0,  8}, {  0,  8}, {  0, 16} },<br>
> +   { { 3,  0}, { 6,  0}, { 4,  4}, {  8,  4}, {  0, 12} },<br>
> +   { { 2,  0}, { 4,  0}, { 4,  0}, {  8,  0}, {  0,  8} },<br>
> +   { { 1,  0}, { 2,  0}, { 0,  4}, {  0,  4}, {  0,  4} },<br>
> +   { { 0,  0}, { 0,  0}, { 0,  0}, {  0,  0}, {  0,  0} },<br>
> +};<br>
> +<br>
> +static const uint8_t gen10_std_y_2d_miptail_offset_el[][5][2] = {<br>
> +/*   128 bpb    64 bpb    32 bpb    16 bpb      8 bpb     */<br>
> +   { {32,  0}, {64,  0}, {64,  0}, {128,  0}, {128,   0} },<br>
> +   { { 0, 32}, { 0, 32}, { 0, 64}, {  0, 64}, {  0, 128} },<br>
> +   { {16,  0}, {32,  0}, {32,  0}, { 64,  0}, { 64,   0} },<br>
> +   { { 0, 16}, { 0, 16}, { 0, 32}, {  0, 32}, {  0,  64} },<br>
> +   { { 8,  0}, {16,  0}, {16,  0}, { 32,  0}, { 32,   0} },<br>
> +   { { 4,  8}, { 8,  8}, { 8, 16}, { 16, 16}, { 16,  32} },<br>
> +   { { 0, 12}, { 0, 12}, { 0, 24}, {  0, 24}, {  0,  48} },<br>
> +   { { 0,  8}, { 0,  8}, { 0, 16}, {  0, 16}, {  0,  32} },<br>
> +   { { 4,  4}, { 8,  4}, { 8,  8}, { 16,  8}, { 16,  16} },<br>
> +   { { 4,  0}, { 8,  0}, { 8,  0}, { 16,  0}, { 16,   0} },<br>
> +   { { 0,  4}, { 0,  4}, { 0,  8}, {  0,  8}, {  0,  16} },<br>
> +   { { 0,  0}, { 0,  0}, { 0,  0}, {  0,  0}, {  0,   0} },<br>
> +   { { 1,  0}, { 2,  0}, { 0,  4}, {  0,  4}, {  0,   4} },<br>
> +   { { 2,  0}, { 4,  0}, { 4,  0}, {  8,  0}, {  0,   8} },<br>
> +   { { 3,  0}, { 6,  0}, { 4,  4}, {  8,  4}, {  0,  12} },<br>
> +};<br>
> +<br>
> +static const uint8_t gen9_std_y_3d_miptail_offset_el[][5][3] = {<br>
> +/*    128 bpb     64 bpb      32 bpb        16 bpb        8 bpb      */<br>
> +   { {8, 0, 0}, {16, 0, 0}, {16,  0, 0}, {16,  0,  0}, {32,  0,  0} },<br>
> +   { {0, 8, 0}, { 0, 8, 0}, { 0, 16, 0}, { 0, 16,  0}, { 0, 16,  0} },<br>
> +   { {0, 0, 8}, { 0, 0, 8}, { 0,  0, 8}, { 0,  0, 16}, { 0,  0, 16} },<br>
> +   { {4, 0, 0}, { 8, 0, 0}, { 8,  0, 0}, { 8,  0,  0}, {16,  0,  0} },<br>
> +   { {0, 4, 0}, { 0, 4, 0}, { 0,  8, 0}, { 0,  8,  0}, { 0,  8,  0} },<br>
> +   { {0, 0, 4}, { 0, 0, 4}, { 0,  0, 4}, { 0,  0,  8}, { 0,  0,  8} },<br>
> +   { {3, 0, 0}, { 6, 0, 0}, { 4,  4, 0}, { 0,  4,  4}, { 0,  4,  4} },<br>
> +   { {2, 0, 0}, { 4, 0, 0}, { 0,  4, 0}, { 0,  4,  0}, { 0,  4,  0} },<br>
> +   { {1, 0, 3}, { 2, 0, 3}, { 4,  0, 3}, { 0,  0,  7}, { 0,  0,  7} },<br>
> +   { {1, 0, 2}, { 2, 0, 2}, { 4,  0, 2}, { 0,  0,  6}, { 0,  0,  6} },<br>
> +   { {1, 0, 1}, { 2, 0, 1}, { 4,  0, 1}, { 0,  0,  5}, { 0,  0,  5} },<br>
> +   { {1, 0, 0}, { 2, 0, 0}, { 4,  0, 0}, { 0,  0,  4}, { 0,  0,  4} },<br>
> +   { {0, 0, 3}, { 0, 0, 3}, { 0,  0, 3}, { 0,  0,  3}, { 0,  0,  3} },<br>
> +   { {0, 0, 2}, { 0, 0, 2}, { 0,  0, 2}, { 0,  0,  2}, { 0,  0,  2} },<br>
> +   { {0, 0, 1}, { 0, 0, 1}, { 0,  0, 1}, { 0,  0,  1}, { 0,  0,  1} },<br>
> +   { {0, 0, 0}, { 0, 0, 0}, { 0,  0, 0}, { 0,  0,  0}, { 0,  0,  0} },<br>
> +};<br>
> +<br>
> +static const uint8_t gen10_std_y_3d_miptail_offset_el[][5][3] = {<br>
> +/*    128 bpb     64 bpb      32 bpb        16 bpb        8 bpb      */<br>
> +   { {8, 0, 0}, {16, 0, 0}, {16,  0, 0}, {16,  0,  0}, {32,  0,  0} },<br>
> +   { {0, 8, 0}, { 0, 8, 0}, { 0, 16, 0}, { 0, 16,  0}, { 0, 16,  0} },<br>
> +   { {0, 0, 8}, { 0, 0, 8}, { 0,  0, 8}, { 0,  0, 16}, { 0,  0, 16} },<br>
> +   { {4, 0, 0}, { 8, 0, 0}, { 8,  0, 0}, { 8,  0,  0}, {16,  0,  0} },<br>
> +   { {0, 4, 0}, { 0, 4, 0}, { 0,  8, 0}, { 0,  8,  0}, { 0,  8,  0} },<br>
> +   { {2, 0, 4}, { 4, 0, 4}, { 4,  0, 4}, { 4,  0,  8}, { 8,  0,  8} },<br>
> +   { {0, 2, 4}, { 0, 2, 4}, { 0,  4, 4}, { 0,  4,  8}, { 0,  4,  8} },<br>
> +   { {0, 0, 4}, { 0, 0, 4}, { 0,  0, 4}, { 0,  0,  8}, { 0,  0,  8} },<br>
> +   { {2, 2, 0}, { 4, 2, 0}, { 4,  4, 0}, { 4,  4,  0}, { 8,  4,  0} },<br>
> +   { {2, 0, 0}, { 4, 0, 0}, { 4,  0, 0}, { 4,  0,  0}, { 8,  0,  0} },<br>
> +   { {0, 2, 0}, { 0, 2, 0}, { 0,  4, 0}, { 0,  4,  0}, { 0,  4,  0} },<br>
> +   { {1, 0, 2}, { 2, 0, 2}, { 2,  0, 2}, { 2,  0,  4}, { 4,  0,  4} },<br>
> +   { {0, 0, 2}, { 0, 0, 2}, { 0,  0, 2}, { 0,  0,  4}, { 0,  0,  4} },<br>
> +   { {1, 0, 0}, { 2, 0, 0}, { 2,  0, 0}, { 2,  0,  0}, { 4,  0,  0} },<br>
> +   { {0, 0, 0}, { 0, 0, 0}, { 0,  0, 0}, { 0,  0,  0}, { 0,  0,  0} },<br>
> +<br>
> +};<br>
> +<br>
> +static void<br>
> +isl_get_miptail_level_offset_el(enum isl_tiling tiling,<br>
> +                                enum isl_surf_dim dim,<br>
> +                                uint32_t format_bpb,<br>
> +                                uint32_t samples,<br>
> +                                uint32_t level,<br>
> +                                uint32_t *x_offset_el,<br>
> +                                uint32_t *y_offset_el,<br>
> +                                uint32_t *z_offset_el)<br>
> +{<br>
> +   uint32_t row = level;<br>
> +   uint32_t col = 8 - ffs(format_bpb);<br>
> +<br>
> +   if (tiling == ISL_TILING_GEN9_Yf || tiling == ISL_TILING_GEN10_Yf)<br>
> +      row += 4;<br>
> +<br>
> +   switch (dim) {<br>
> +   case ISL_SURF_DIM_1D:<br>
> +      assert(samples == 1);<br>
> +      /* The 1D case is simple and doesn't need a table. */<br>
> +      *x_offset_el = std_y_1d_miptail_offset_el[row] << col;<br>
> +      *y_offset_el = 0;<br>
> +      *z_offset_el = 0;<br>
> +      break;<br>
> +<br>
> +   case ISL_SURF_DIM_2D:<br>
> +      assert(isl_is_pow2(samples) && samples <= 16);<br>
> +      if (tiling != ISL_TILING_GEN9_Yf)<br>
> +         row += ffs(samples) - 1;<br>
> +<br>
> +      if (tiling == ISL_TILING_GEN10_Yf || tiling == ISL_TILING_GEN10_Ys) {<br>
> +         assert(row < ARRAY_SIZE(gen10_std_y_2d_miptail_offset_el));<br>
> +         assert(col < ARRAY_SIZE(gen10_std_y_2d_miptail_offset_el[0]));<br>
> +         *x_offset_el = gen10_std_y_2d_miptail_offset_el[row][col][0];<br>
> +         *y_offset_el = gen10_std_y_2d_miptail_offset_el[row][col][1];<br>
> +      } else {<br>
> +         assert(tiling == ISL_TILING_GEN9_Yf || tiling == ISL_TILING_GEN9_Ys);<br>
> +         assert(row < ARRAY_SIZE(gen9_std_y_2d_miptail_offset_el));<br>
> +         assert(col < ARRAY_SIZE(gen9_std_y_2d_miptail_offset_el[0]));<br>
> +         *x_offset_el = gen9_std_y_2d_miptail_offset_el[row][col][0];<br>
> +         *y_offset_el = gen9_std_y_2d_miptail_offset_el[row][col][1];<br>
> +      }<br>
> +      *z_offset_el = 0;<br>
> +      break;<br>
> +<br>
> +   case ISL_SURF_DIM_3D:<br>
> +      assert(samples == 1);<br>
> +      if (tiling == ISL_TILING_GEN10_Yf || tiling == ISL_TILING_GEN10_Ys) {<br>
> +         assert(row < ARRAY_SIZE(gen10_std_y_3d_miptail_offset_el));<br>
> +         assert(col < ARRAY_SIZE(gen10_std_y_3d_miptail_offset_el[0]));<br>
> +         *x_offset_el = gen10_std_y_3d_miptail_offset_el[row][col][0];<br>
> +         *y_offset_el = gen10_std_y_3d_miptail_offset_el[row][col][1];<br>
> +         *z_offset_el = gen10_std_y_3d_miptail_offset_el[row][col][2];<br>
> +      } else {<br>
> +         assert(tiling == ISL_TILING_GEN9_Yf || tiling == ISL_TILING_GEN9_Ys);<br>
> +         assert(row < ARRAY_SIZE(gen9_std_y_3d_miptail_offset_el));<br>
> +         assert(col < ARRAY_SIZE(gen9_std_y_3d_miptail_offset_el[0]));<br>
> +         *x_offset_el = gen9_std_y_3d_miptail_offset_el[row][col][0];<br>
> +         *y_offset_el = gen9_std_y_3d_miptail_offset_el[row][col][1];<br>
> +         *z_offset_el = gen9_std_y_3d_miptail_offset_el[row][col][2];<br>
> +      }<br>
> +      break;<br>
> +   }<br>
> +}<br>
> +<br>
>  /**<br>
>   * Calculate the pitch between physical array slices, in units of rows of<br>
>   * surface elements.<br>
> @@ -2050,7 +2213,7 @@ get_image_offset_sa_gen4_2d(const struct isl_surf *surf,<br>
>        *array_offset = 0;<br>
>     }<br>
>  <br>
> -   for (uint32_t l = 0; l < level; ++l) {<br>
> +   for (uint32_t l = 0; l < MIN(level, surf->miptail_start_level); ++l) {<br>
>        if (l == 1) {<br>
>           uint32_t W = isl_minify(W0, l);<br>
>           x += isl_align_npot(W, image_align_sa.w);<br>
> @@ -2062,6 +2225,22 @@ get_image_offset_sa_gen4_2d(const struct isl_surf *surf,<br>
>  <br>
>     *x_offset_sa = x;<br>
>     *y_offset_sa = y;<br>
> +<br>
> +   if (level >= surf->miptail_start_level) {<br>
> +      const struct isl_format_layout *fmtl =<br>
> +         isl_format_get_layout(surf->format);<br>
> +<br>
> +      uint32_t tail_offset_x_el, tail_offset_y_el, tail_offset_z_el;<br>
> +      isl_get_miptail_level_offset_el(surf->tiling, surf->dim,<br>
> +                                      fmtl->bpb, surf->samples,<br>
> +                                      level - surf->miptail_start_level,<br>
> +                                      &tail_offset_x_el,<br>
> +                                      &tail_offset_y_el,<br>
> +                                      &tail_offset_z_el);<br>
> +      *x_offset_sa += tail_offset_x_el * fmtl->bw;<br>
> +      *y_offset_sa += tail_offset_y_el * fmtl->bh;<br>
> +      *z_offset_sa += tail_offset_z_el * fmtl->bd;<br>
> +   }<br>
>  }<br>
>  <br>
>  /**<br>
> @@ -2204,7 +2383,7 @@ get_image_offset_sa_gen9_1d(const struct isl_surf *surf,<br>
>  <br>
>     uint32_t x = 0;<br>
>  <br>
> -   for (uint32_t l = 0; l < level; ++l) {<br>
> +   for (uint32_t l = 0; l < MIN(level, surf->miptail_start_level); ++l) {<br>
>        uint32_t W = isl_minify(W0, l);<br>
>        uint32_t w = isl_align_npot(W, image_align_sa.w);<br>
>  <br>
> @@ -2221,6 +2400,21 @@ get_image_offset_sa_gen9_1d(const struct isl_surf *surf,<br>
>        *y_offset_sa = 0;<br>
>        *array_offset = layer;<br>
>     }<br>
> +<br>
> +   if (level >= surf->miptail_start_level) {<br>
> +      const struct isl_format_layout *fmtl =<br>
> +         isl_format_get_layout(surf->format);<br>
> +<br>
> +      uint32_t tail_offset_x_el, tail_offset_y_el, tail_offset_z_el;<br>
> +      isl_get_miptail_level_offset_el(surf->tiling, surf->dim,<br>
> +                                      fmtl->bpb, surf->samples,<br>
> +                                      level - surf->miptail_start_level,<br>
> +                                      &tail_offset_x_el,<br>
> +                                      &tail_offset_y_el,<br>
> +                                      &tail_offset_z_el);<br>
> +      assert(tail_offset_y_el == 0 && tail_offset_z_el == 0);<br>
> +      *x_offset_sa += tail_offset_x_el * fmtl->bw;<br>
> +   }<br>
>  }<br>
>  <br>
>  /**<br>
> @@ -2375,8 +2569,23 @@ isl_surf_get_image_offset_B_tile_el(const struct isl_surf *surf,<br>
>                                        y_offset_el,<br>
>                                        &z_offset_el,<br>
>                                        &array_offset);<br>
> -   assert(z_offset_el == 0);<br>
> -   assert(array_offset == 0);<br>
> +   if (level >= surf->miptail_start_level) {<br>
> +      /* We can do a byte offset to the first level of a miptail but we cannot<br>
> +       * offset into a miptail.<br>
> +       */<br>
> +      assert(level == surf->miptail_start_level);<br>
> +<br>
> +      /* The byte offset will get us to the miptail page.  The other offsets<br>
> +       * are to the actual level within the miptail.  It is assumed that the<br>
> +       * caller will set up a texture with a miptail and use the hardware to<br>
> +       * handle offseting inside the miptail.<br>
> +       */<br>
> +      *x_offset_el = 0;<br>
> +      *y_offset_el = 0;<br>
<br>
To me it seems that<br>
<br>
         assert(array_offset == 0);<br></blockquote><div><br></div><div>Uh... It should either be zero or returned somewhere so I suspect it should be zero.  Also, that makes me wonder if I should replace the X and Y assignments with asserts.  It's been a long time and I don't remember my reasoning here.  Let me add some asserts and kick it off to Jenkins and see what happens.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
should hold here as well?<br>
<br>
<br>
Otherwise things look to be in order:<br>
<br>
Reviewed-by: Topi Pohjolainen <<a href="mailto:topi.pohjolainen@intel.com" target="_blank">topi.pohjolainen@intel.com</a>><br>
<br>
<br>
> +   } else {<br>
> +      assert(z_offset_el == 0);<br>
> +      assert(array_offset == 0);<br>
> +   }<br>
>  }<br>
>  <br>
>  void<br>
> -- <br>
> 2.19.1<br>
> <br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">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/mailman/listinfo/mesa-dev</a><br>
</blockquote></div></div>