<div dir="ltr"><div><div>Ken and I had a fairly lengthy conversation about this on IRC today:<br><br><a href="https://people.freedesktop.org/~jekstrand/isl-padding">https://people.freedesktop.org/~jekstrand/isl-padding</a><br><br></div>The conclusion was that we both hate the patch but it's probably safe and it does fix bugs. The thing that really wins me over is that we have historically done none of this padding in the GL driver (except for one bit about cube maps) and seem to have gotten away with it. We have had some underallocation issues in the past but none have them have tracked back to this.<br><br></div>--Jason<br><div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 2, 2017 at 1:35 PM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>The docs contain a bunch of commentary about the need to pad various<br>
surfaces out to multiples of something or other. However, all of those<br>
requirements are about avoiding GTT errors due to missing pages when the<br>
data port or sampler accesses slightly out-of-bounds. However, because<br>
the kernel already fills all the empty space in our GTT with the scratch<br>
page, we never have to worry about faulting due to OOB reads. There are<br>
two caveats to this:<br>
<br>
1) There is some potential for issues with caches here if extra data<br>
ends up in a cache we don't expect due to OOB reads. However,<br>
because we always trash the entire cache whenever we need to move<br>
anything between cache domains, this shouldn't be an issue.<br>
<br>
2) There is a potential issue if a surface gets placed at the very top<br>
of the GTT by the kernel. In this case, the hardware could<br>
potentially end up trying to read past the top of the GTT. If it<br>
nicely wraps around at the 48-bit (or 32-bit) boundary, then this<br>
shouldn't be an issue thanks to the scratch page. If it doesn't,<br>
then we need to come up with something to handle it.<br>
<br>
Up until some of the GL move to ISL, having the padding code in there<br>
just caused us to harmlessly use a bit more memory in Vulkan. However,<br>
now that we're using ISL sizes to validate external dma-buf images,<br>
these padding requirements are causing us to reject otherwise valid<br>
images due to the size of the BO being too small.<br>
<br>
Cc: "17.2" <<a href="mailto:mesa-stable@lists.freedesktop.org" target="_blank">mesa-stable@lists.freedesktop<wbr>.org</a>><br>
Cc: Chad Versace <<a href="mailto:chadversary@chromium.org" target="_blank">chadversary@chromium.org</a>><br>
</span>Tested-by: Tapani Pälli <<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>><br>
Tested-by: Tomasz Figa <<a href="mailto:tfiga@chromium.org" target="_blank">tfiga@chromium.org</a>><br>
<span class="gmail-m_-2544883053933398013im gmail-m_-2544883053933398013HOEnZb">---<br>
src/intel/isl/isl.c | 119 +-----------------------------<wbr>----------------------<br>
1 file changed, 2 insertions(+), 117 deletions(-)<br>
<br>
</span><div class="gmail-m_-2544883053933398013HOEnZb"><div class="gmail-m_-2544883053933398013h5">diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c<br>
index 5e3d279..d3124de 100644<br>
--- a/src/intel/isl/isl.c<br>
+++ b/src/intel/isl/isl.c<br>
@@ -1374,116 +1374,6 @@ isl_calc_row_pitch(const struct isl_device *dev,<br>
return true;<br>
}<br>
<br>
-/**<br>
- * Calculate and apply any padding required for the surface.<br>
- *<br>
- * @param[inout] total_h_el is updated with the new height<br>
- * @param[out] pad_bytes is overwritten with additional padding requirements.<br>
- */<br>
-static void<br>
-isl_apply_surface_padding(con<wbr>st struct isl_device *dev,<br>
- const struct isl_surf_init_info *restrict info,<br>
- const struct isl_tile_info *tile_info,<br>
- uint32_t *total_h_el,<br>
- uint32_t *pad_bytes)<br>
-{<br>
- const struct isl_format_layout *fmtl = isl_format_get_layout(info->fo<wbr>rmat);<br>
-<br>
- *pad_bytes = 0;<br>
-<br>
- /* From the Broadwell PRM >> Volume 5: Memory Views >> Common Surface<br>
- * Formats >> Surface Padding Requirements >> Render Target and Media<br>
- * Surfaces:<br>
- *<br>
- * The data port accesses data (pixels) outside of the surface if they<br>
- * are contained in the same cache request as pixels that are within the<br>
- * surface. These pixels will not be returned by the requesting message,<br>
- * however if these pixels lie outside of defined pages in the GTT,<br>
- * a GTT error will result when the cache request is processed. In<br>
- * order to avoid these GTT errors, “padding” at the bottom of the<br>
- * surface is sometimes necessary.<br>
- *<br>
- * From the Broadwell PRM >> Volume 5: Memory Views >> Common Surface<br>
- * Formats >> Surface Padding Requirements >> Sampling Engine Surfaces:<br>
- *<br>
- * ... Lots of padding requirements, all listed separately below.<br>
- */<br>
-<br>
- /* We can safely ignore the first padding requirement, quoted below,<br>
- * because isl doesn't do buffers.<br>
- *<br>
- * - [pre-BDW] For buffers, which have no inherent “height,” padding<br>
- * requirements are different. A buffer must be padded to the next<br>
- * multiple of 256 array elements, with an additional 16 bytes added<br>
- * beyond that to account for the L1 cache line.<br>
- */<br>
-<br>
- /*<br>
- * - For compressed textures [...], padding at the bottom of the surface<br>
- * is to an even compressed row.<br>
- */<br>
- if (isl_format_is_compressed(info<wbr>->format))<br>
- *total_h_el = isl_align(*total_h_el, 2);<br>
-<br>
- /*<br>
- * - For cube surfaces, an additional two rows of padding are required<br>
- * at the bottom of the surface.<br>
- */<br>
- if (info->usage & ISL_SURF_USAGE_CUBE_BIT)<br>
- *total_h_el += 2;<br>
-<br>
- /*<br>
- * - For packed YUV, 96 bpt, 48 bpt, and 24 bpt surface formats,<br>
- * additional padding is required. These surfaces require an extra row<br>
- * plus 16 bytes of padding at the bottom in addition to the general<br>
- * padding requirements.<br>
- */<br>
- if (isl_format_is_yuv(info->forma<wbr>t) &&<br>
- (fmtl->bpb == 96 || fmtl->bpb == 48|| fmtl->bpb == 24)) {<br>
- *total_h_el += 1;<br>
- *pad_bytes += 16;<br>
- }<br>
-<br>
- /*<br>
- * - For linear surfaces, additional padding of 64 bytes is required at<br>
- * the bottom of the surface. This is in addition to the padding<br>
- * required above.<br>
- */<br>
- if (tile_info->tiling == ISL_TILING_LINEAR)<br>
- *pad_bytes += 64;<br>
-<br>
- /* The below text weakens, not strengthens, the padding requirements for<br>
- * linear surfaces. Therefore we can safely ignore it.<br>
- *<br>
- * - [BDW+] For SURFTYPE_BUFFER, SURFTYPE_1D, and SURFTYPE_2D non-array,<br>
- * non-MSAA, non-mip-mapped surfaces in linear memory, the only<br>
- * padding requirement is to the next aligned 64-byte boundary beyond<br>
- * the end of the surface. The rest of the padding requirements<br>
- * documented above do not apply to these surfaces.<br>
- */<br>
-<br>
- /*<br>
- * - [SKL+] For SURFTYPE_2D and SURFTYPE_3D with linear mode and<br>
- * height % 4 != 0, the surface must be padded with<br>
- * 4-(height % 4)*Surface Pitch # of bytes.<br>
- */<br>
- if (ISL_DEV_GEN(dev) >= 9 &&<br>
- tile_info->tiling == ISL_TILING_LINEAR &&<br>
- (info->dim == ISL_SURF_DIM_2D || info->dim == ISL_SURF_DIM_3D)) {<br>
- *total_h_el = isl_align(*total_h_el, 4);<br>
- }<br>
-<br>
- /*<br>
- * - [SKL+] For SURFTYPE_1D with linear mode, the surface must be padded<br>
- * to 4 times the Surface Pitch # of bytes<br>
- */<br>
- if (ISL_DEV_GEN(dev) >= 9 &&<br>
- tile_info->tiling == ISL_TILING_LINEAR &&<br>
- info->dim == ISL_SURF_DIM_1D) {<br>
- *total_h_el += 4;<br>
- }<br>
-}<br>
-<br>
bool<br>
isl_surf_init_s(const struct isl_device *dev,<br>
struct isl_surf *surf,<br>
@@ -1536,10 +1426,6 @@ isl_surf_init_s(const struct isl_device *dev,<br>
array_pitch_span, &array_pitch_el_rows,<br>
&phys_total_el);<br>
<br>
- uint32_t padded_h_el = phys_total_el.h;<br>
- uint32_t pad_bytes;<br>
- isl_apply_surface_padding(<wbr>dev, info, &tile_info, &padded_h_el, &pad_bytes);<br>
-<br>
uint32_t row_pitch;<br>
if (!isl_calc_row_pitch(dev, info, &tile_info, dim_layout,<br>
&phys_total_el, &row_pitch))<br>
@@ -1548,7 +1434,7 @@ isl_surf_init_s(const struct isl_device *dev,<br>
uint32_t base_alignment;<br>
uint64_t size;<br>
if (tiling == ISL_TILING_LINEAR) {<br>
- size = (uint64_t) row_pitch * padded_h_el + pad_bytes;<br>
+ size = (uint64_t) row_pitch * phys_total_el.h;<br>
<br>
/* From the Broadwell PRM Vol 2d, RENDER_SURFACE_STATE::SurfaceB<wbr>aseAddress:<br>
*<br>
@@ -1569,9 +1455,8 @@ isl_surf_init_s(const struct isl_device *dev,<br>
}<br>
base_alignment = isl_round_up_to_power_of_two(b<wbr>ase_alignment);<br>
} else {<br>
- padded_h_el += isl_align_div_npot(pad_bytes, row_pitch);<br>
const uint32_t total_h_tl =<br>
- isl_align_div(padded_h_el, tile_info.logical_extent_el.he<wbr>ight);<br>
+ isl_align_div(phys_total_el.<wbr>h, tile_info.logical_extent_el.he<wbr>ight);<br>
<br>
size = (uint64_t) total_h_tl * tile_info.phys_extent_B.height * row_pitch;<br>
<br>
</div></div><span class="gmail-m_-2544883053933398013HOEnZb"><font color="#888888">--<br>
2.5.0.400.gff86faf<br>
<br>
</font></span></blockquote></div><br></div></div></div></div></div>