<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 27, 2018 at 6:13 AM, Pohjolainen, Topi <span dir="ltr"><<a href="mailto:topi.pohjolainen@gmail.com" target="_blank">topi.pohjolainen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Thu, Feb 22, 2018 at 11:06:48PM -0800, Jason Ekstrand wrote:<br>
> The tile size calculations use a clever bit of math to make them short<br>
> and simple. We add unit tests to assert that they identically match the<br>
> tables in the PRM.<br>
> ---<br>
> src/intel/<a href="http://Makefile.isl.am" rel="noreferrer" target="_blank">Makefile.isl.am</a> | 9 +-<br>
> src/intel/isl/isl.c | 56 ++++++++++-<br>
> src/intel/isl/meson.build | 11 ++<br>
> src/intel/isl/tests/isl_tile_<wbr>std_y_test.c | 160 ++++++++++++++++++++++++++++++<br>
> 4 files changed, 230 insertions(+), 6 deletions(-)<br>
> create mode 100644 src/intel/isl/tests/isl_tile_<wbr>std_y_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 9525f9e..a498f2f 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>
> @@ -75,7 +75,9 @@ 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>offset_test \<br>
> + isl/tests/isl_tile_std_y_test<br>
><br>
> TESTS += $(check_PROGRAMS)<br>
><br>
> @@ -84,6 +86,11 @@ isl_tests_isl_surf_get_image_<wbr>offset_test_LDADD = \<br>
> isl/<a href="http://libisl.la" rel="noreferrer" target="_blank">libisl.la</a> \<br>
> -lm<br>
><br>
> +isl_tests_isl_tile_std_y_<wbr>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>
> + -lm<br>
> +<br>
> # ------------------------------<wbr>------------------------------<wbr>----------------<br>
><br>
> EXTRA_DIST += \<br>
> diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c<br>
> index aa56a3c..fcbe2ad 100644<br>
> --- a/src/intel/isl/isl.c<br>
> +++ b/src/intel/isl/isl.c<br>
> @@ -217,13 +217,59 @@ isl_tiling_get_info(enum isl_tiling tiling,<br>
> case ISL_TILING_Yf:<br>
> case ISL_TILING_Ys: {<br>
> bool is_Ys = tiling == ISL_TILING_Ys;<br>
> + assert(format_bpb >= 8);<br>
><br>
> - assert(bs > 0);<br>
> - unsigned width = 1 << (6 + (ffs(bs) / 2) + (2 * is_Ys));<br>
> - unsigned height = 1 << (6 - (ffs(bs) / 2) + (2 * is_Ys));<br>
> + switch (dim) {<br>
> + case ISL_SURF_DIM_1D:<br>
> + /* See the Skylake BSpec > Memory Views > Common Surface Formats ><br>
> + * Surface Layout and Tiling > 1D Surfaces > 1D Alignment<br>
> + * Requirements.<br>
<br>
</div></div>I wonder if I'm looking the right version, under "Memory Views" there is no<br>
section called "Common Surface Formats" - but under "Memory Data Formats"<br>
there is such. Only there the "1D Surfaces > 1D Alignment" section is pretty<br>
limited - it only says:<br></blockquote><div><br></div><div>This is the problem with citing the bspec: it changes. If you follow that path in the PRMs, you should get to a useful section.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
1D surfaces are not tiled, but laid out linearly in memory.<br>
<br>
Tiled Resource Mode Bits per Element Horizontal Alignment<br>
TRMODE_NONE Any 64<br>
<span class=""><br>
> + */<br>
> + logical_el = (struct isl_extent4d) {<br>
> + .w = 1 << (12 - (ffs(format_bpb) - 4) + (4 * is_Ys)),<br>
> + .h = 1,<br>
> + .d = 1,<br>
> + .a = 1,<br>
> + };<br>
> + break;<br>
> +<br>
> + case ISL_SURF_DIM_2D:<br>
> + /* See the Skylake BSpec > Memory Views > Common Surface Formats ><br>
> + * Surface Layout and Tiling > 2D Surfaces > 2D/CUBE Alignment<br>
> + * Requirements.<br>
> + */<br>
> + logical_el = (struct isl_extent4d) {<br>
> + .w = 1 << (6 - ((ffs(format_bpb) - 4) / 2) + (2 * is_Ys)),<br>
> + .h = 1 << (6 - ((ffs(format_bpb) - 3) / 2) + (2 * is_Ys)),<br>
> + .d = 1,<br>
> + .a = 1,<br>
> + };<br>
<br>
</span>In case of section "2D/CUBE Alignment" I'm having similar problem - there is<br>
only a simple table. The equations above, however, suggest that there is more<br>
to it.<br><div><div class="h5"></div></div></blockquote><div><br></div><div>There are tables in the PRM. For tile size calculations, there are these fairly simple (Ha!) closed-form calculations. The unit tests below contain the actual tables and test that the calculations above match exactly.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
> +<br>
> + if (is_Ys && samples > 1) {<br>
> + logical_el.w >>= (ffs(samples) - 0) / 2;<br>
> + logical_el.h >>= (ffs(samples) - 1) / 2;<br>
> + logical_el.a = samples;<br>
> + }<br>
> + break;<br>
> +<br>
> + case ISL_SURF_DIM_3D:<br>
> + /* See the Skylake BSpec > Memory Views > Common Surface Formats ><br>
> + * Surface Layout and Tiling > 3D Surfaces > 3D Alignment<br>
> + * Requirements.<br>
> + */<br>
> + logical_el = (struct isl_extent4d) {<br>
> + .w = 1 << (4 - ((ffs(format_bpb) - 2) / 3) + (2 * is_Ys)),<br>
> + .h = 1 << (4 - ((ffs(format_bpb) - 4) / 3) + (1 * is_Ys)),<br>
> + .d = 1 << (4 - ((ffs(format_bpb) - 3) / 3) + (1 * is_Ys)),<br>
> + .a = 1,<br>
> + };<br>
> + break;<br>
> + }<br>
> +<br>
> + uint32_t tile_size_B = is_Ys ? (1 << 16) : (1 << 12);<br>
><br>
> - logical_el = isl_extent4d(width / bs, height, 1, 1);<br>
> - phys_B = isl_extent2d(width, height);<br>
> + phys_B.w = logical_el.width * bs;<br>
> + phys_B.h = tile_size_B / phys_B.w;<br>
> break;<br>
> }<br>
><br>
> diff --git a/src/intel/isl/meson.build b/src/intel/isl/meson.build<br>
> index 36b8b8f..ad0d5cc 100644<br>
> --- a/src/intel/isl/meson.build<br>
> +++ b/src/intel/isl/meson.build<br>
> @@ -98,4 +98,15 @@ if with_tests<br>
> link_with : [libisl, libintel_common],<br>
> )<br>
> )<br>
> +<br>
> + test(<br>
> + 'isl_tile_std_y',<br>
> + executable(<br>
> + 'isl_tile_std_y_test',<br>
> + 'tests/isl_tile_std_y_test.c',<br>
> + dependencies : dep_m,<br>
> + include_directories : [inc_common, inc_intel],<br>
> + link_with : [libisl, libintel_common],<br>
> + )<br>
> + )<br>
> endif<br>
> diff --git a/src/intel/isl/tests/isl_<wbr>tile_std_y_test.c b/src/intel/isl/tests/isl_<wbr>tile_std_y_test.c<br>
> new file mode 100644<br>
> index 0000000..25053c6<br>
> --- /dev/null<br>
> +++ b/src/intel/isl/tests/isl_<wbr>tile_std_y_test.c<br>
> @@ -0,0 +1,160 @@<br>
> +/*<br>
> + * Copyright 2018 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 "isl/isl.h"<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>
> +assert_tile_size(enum isl_tiling tiling, enum isl_surf_dim dim,<br>
> + uint32_t bpb, uint32_t samples,<br>
> + uint32_t w, uint32_t h, uint32_t d, uint32_t a)<br>
> +{<br>
> + struct isl_tile_info tile_info;<br>
> + isl_tiling_get_info(tiling, dim, bpb, samples, &tile_info);<br>
> +<br>
> + /* Sanity */<br>
> + t_assert(tile_info.tiling == tiling);<br>
> + t_assert(tile_info.format_bpb == bpb);<br>
> +<br>
> + t_assert(tile_info.logical_<wbr>extent_el.w == w);<br>
> + t_assert(tile_info.logical_<wbr>extent_el.h == h);<br>
> + t_assert(tile_info.logical_<wbr>extent_el.d == d);<br>
> + t_assert(tile_info.logical_<wbr>extent_el.a == a);<br>
> +<br>
> + uint32_t tile_size = (tiling == ISL_TILING_Ys) ? 64 * 1024 : 4 * 1024;<br>
> +<br>
> + assert(tile_size == tile_info.phys_extent_B.w *<br>
> + tile_info.phys_extent_B.h);<br>
> +<br>
> + assert(tile_size == tile_info.logical_extent_el.w *<br>
> + tile_info.logical_extent_el.h *<br>
> + tile_info.logical_extent_el.d *<br>
> + tile_info.logical_extent_el.a *<br>
> + bpb / 8);<br>
> +}<br>
> +<br>
> +static void<br>
> +test_1d_tile_dimensions()<br>
> +{<br>
> +#define ASSERT_1D(tiling, bpb, alignment) \<br>
> + assert_tile_size(tiling, ISL_SURF_DIM_1D, bpb, 1, alignment, 1, 1, 1)<br>
> +<br>
> + ASSERT_1D(ISL_TILING_Ys, 128, 4096);<br>
> + ASSERT_1D(ISL_TILING_Ys, 64, 8192);<br>
> + ASSERT_1D(ISL_TILING_Ys, 32, 16384);<br>
> + ASSERT_1D(ISL_TILING_Ys, 16, 32768);<br>
> + ASSERT_1D(ISL_TILING_Ys, 8, 65536);<br>
> +<br>
> + ASSERT_1D(ISL_TILING_Yf, 128, 256);<br>
> + ASSERT_1D(ISL_TILING_Yf, 64, 512);<br>
> + ASSERT_1D(ISL_TILING_Yf, 32, 1024);<br>
> + ASSERT_1D(ISL_TILING_Yf, 16, 2048);<br>
> + ASSERT_1D(ISL_TILING_Yf, 8, 4096);<br>
> +<br>
> +#undef ASSERT_1D<br>
> +}<br>
> +<br>
> +static void<br>
> +assert_2d_tile_size(enum isl_tiling tiling, uint32_t bpb,<br>
> + uint32_t halign, uint32_t valign)<br>
> +{<br>
> +#define ASSERT_2D(tiling, bpb, samples, w, h, a) \<br>
> + assert_tile_size(tiling, ISL_SURF_DIM_2D, bpb, samples, w, h, 1, a)<br>
> +<br>
> + /* Single sampled */<br>
> + ASSERT_2D(tiling, bpb, 1, halign, valign, 1);<br>
> +<br>
> + /* Multisampled */<br>
> + if (tiling == ISL_TILING_Ys) {<br>
> + ASSERT_2D(tiling, bpb, 2, halign / 2, valign / 1, 2);<br>
> + ASSERT_2D(tiling, bpb, 4, halign / 2, valign / 2, 4);<br>
> + ASSERT_2D(tiling, bpb, 8, halign / 4, valign / 2, 8);<br>
> + ASSERT_2D(tiling, bpb, 16, halign / 4, valign / 4, 16);<br>
> + } else {<br>
> + ASSERT_2D(tiling, bpb, 2, halign, valign, 1);<br>
> + ASSERT_2D(tiling, bpb, 4, halign, valign, 1);<br>
> + ASSERT_2D(tiling, bpb, 8, halign, valign, 1);<br>
> + ASSERT_2D(tiling, bpb, 16, halign, valign, 1);<br>
> + }<br>
> +<br>
> +#undef ASSERT_2D<br>
> +}<br>
> +<br>
> +static void<br>
> +test_2d_tile_dimensions()<br>
> +{<br>
> + assert_2d_tile_size(ISL_<wbr>TILING_Ys, 128, 64, 64);<br>
> + assert_2d_tile_size(ISL_<wbr>TILING_Ys, 64, 128, 64);<br>
> + assert_2d_tile_size(ISL_<wbr>TILING_Ys, 32, 128, 128);<br>
> + assert_2d_tile_size(ISL_<wbr>TILING_Ys, 16, 256, 128);<br>
> + assert_2d_tile_size(ISL_<wbr>TILING_Ys, 8, 256, 256);<br>
> +<br>
> + assert_2d_tile_size(ISL_<wbr>TILING_Yf, 128, 16, 16);<br>
> + assert_2d_tile_size(ISL_<wbr>TILING_Yf, 64, 32, 16);<br>
> + assert_2d_tile_size(ISL_<wbr>TILING_Yf, 32, 32, 32);<br>
> + assert_2d_tile_size(ISL_<wbr>TILING_Yf, 16, 64, 32);<br>
> + assert_2d_tile_size(ISL_<wbr>TILING_Yf, 8, 64, 64);<br>
> +}<br>
> +<br>
> +static void<br>
> +test_3d_tile_dimensions()<br>
> +{<br>
> +#define ASSERT_3D(tiling, bpb, halign, valign, dalign) \<br>
> + assert_tile_size(tiling, ISL_SURF_DIM_3D, bpb, 1, halign, valign, dalign, 1)<br>
> +<br>
> + ASSERT_3D(ISL_TILING_Ys, 128, 16, 16, 16);<br>
> + ASSERT_3D(ISL_TILING_Ys, 64, 32, 16, 16);<br>
> + ASSERT_3D(ISL_TILING_Ys, 32, 32, 32, 16);<br>
> + ASSERT_3D(ISL_TILING_Ys, 16, 32, 32, 32);<br>
> + ASSERT_3D(ISL_TILING_Ys, 8, 64, 32, 32);<br>
> +<br>
> + ASSERT_3D(ISL_TILING_Yf, 128, 4, 8, 8);<br>
> + ASSERT_3D(ISL_TILING_Yf, 64, 8, 8, 8);<br>
> + ASSERT_3D(ISL_TILING_Yf, 32, 8, 16, 8);<br>
> + ASSERT_3D(ISL_TILING_Yf, 16, 8, 16, 16);<br>
> + ASSERT_3D(ISL_TILING_Yf, 8, 16, 16, 16);<br>
> +<br>
> +#undef ASSERT_3D<br>
> +}<br>
> +<br>
> +int main(void)<br>
> +{<br>
> + test_1d_tile_dimensions();<br>
> + test_2d_tile_dimensions();<br>
> + test_3d_tile_dimensions();<br>
> +<br>
> + return 0;<br>
> +}<br>
> --<br>
> 2.5.0.400.gff86faf<br>
><br>
</div></div>> ______________________________<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>
</blockquote></div><br></div></div>