<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div class="">Looks good.</div>
<div class=""><br class="">
</div>
Reviewed-By: George Kyriazis <<a href="mailto:george.kyriazis@intel.com" class="">george.kyriazis@intel.com</a>>
<div class=""><br class="">
</div>
<div class="">
<div>
<blockquote type="cite" class="">
<div class="">On Nov 30, 2017, at 11:51 AM, Bruce Cherniak <<a href="mailto:bruce.cherniak@intel.com" class="">bruce.cherniak@intel.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">This patch fixes piglit tex3d-maxsize by correcting 4 things:<br class="">
<br class="">
The total_size calculation was using 32-bit math, therefore a >4GB<br class="">
allocation request overflowed and was not returning false (unsupported).<br class="">
<br class="">
Changed AlignedMalloc arguments from "unsigned int" to size_t, to handle<br class="">
<blockquote type="cite" class="">4GB allocations.<br class="">
</blockquote>
<br class="">
Added error checking on texture allocations to fail gracefully.<br class="">
<br class="">
Finally, temporarily decreased supported max texture size from 4GB to 2GB.<br class="">
The gallivm texture-sampler needs some additional work to correctly handle<br class="">
larger than 2GB textures (offsets to LLVMBuildGEP are signed).<br class="">
<br class="">
I'm working on a follow-on patch to allow up to 4GB textures, as this is<br class="">
useful in HPC visualization applications.<br class="">
<br class="">
Fixes piglit tex3d-maxsize.<br class="">
<br class="">
v2: Updated patch description to clarify ">4GB".<br class="">
---<br class="">
src/gallium/drivers/swr/rasterizer/common/os.h |  2 +-<br class="">
src/gallium/drivers/swr/swr_screen.cpp         | 12 +++++++++---<br class="">
2 files changed, 10 insertions(+), 4 deletions(-)<br class="">
<br class="">
diff --git a/src/gallium/drivers/swr/rasterizer/common/os.h b/src/gallium/drivers/swr/rasterizer/common/os.h<br class="">
index 4ed6b88e45..358cb33b6e 100644<br class="">
--- a/src/gallium/drivers/swr/rasterizer/common/os.h<br class="">
+++ b/src/gallium/drivers/swr/rasterizer/common/os.h<br class="">
@@ -210,7 +210,7 @@ unsigned char _BitScanReverse(unsigned int *Index, unsigned int Mask)<br class="">
}<br class="">
<br class="">
inline<br class="">
-void *AlignedMalloc(unsigned int size, unsigned int alignment)<br class="">
+void *AlignedMalloc(size_t size, size_t alignment)<br class="">
{<br class="">
    void *ret;<br class="">
    if (posix_memalign(&ret, alignment, size))<br class="">
diff --git a/src/gallium/drivers/swr/swr_screen.cpp b/src/gallium/drivers/swr/swr_screen.cpp<br class="">
index 3f2433e65a..71a07ebe8d 100644<br class="">
--- a/src/gallium/drivers/swr/swr_screen.cpp<br class="">
+++ b/src/gallium/drivers/swr/swr_screen.cpp<br class="">
@@ -50,7 +50,7 @@<br class="">
 * Max texture sizes<br class="">
 * XXX Check max texture size values against core and sampler.<br class="">
 */<br class="">
-#define SWR_MAX_TEXTURE_SIZE (4 * 1024 * 1024 * 1024ULL) /* 4GB */<br class="">
+#define SWR_MAX_TEXTURE_SIZE (2 * 1024 * 1024 * 1024ULL) /* 2GB */<br class="">
#define SWR_MAX_TEXTURE_2D_LEVELS 14  /* 8K x 8K for now */<br class="">
#define SWR_MAX_TEXTURE_3D_LEVELS 12  /* 2K x 2K x 2K for now */<br class="">
#define SWR_MAX_TEXTURE_CUBE_LEVELS 14  /* 8K x 8K for now */<br class="">
@@ -821,13 +821,15 @@ swr_texture_layout(struct swr_screen *screen,<br class="">
         ComputeSurfaceOffset<false>(0, 0, 0, 0, 0, level, &res->swr);<br class="">
   }<br class="">
<br class="">
-   size_t total_size = res->swr.depth * res->swr.qpitch * res->swr.pitch *<br class="">
-                       res->swr.numSamples;<br class="">
+   size_t total_size = (uint64_t)res->swr.depth * res->swr.qpitch *<br class="">
+                                 res->swr.pitch * res->swr.numSamples;<br class="">
   if (total_size > SWR_MAX_TEXTURE_SIZE)<br class="">
      return false;<br class="">
<br class="">
   if (allocate) {<br class="">
      res->swr.xpBaseAddress = (gfxptr_t)AlignedMalloc(total_size, 64);<br class="">
+      if (!res->swr.xpBaseAddress)<br class="">
+         return false;<br class="">
<br class="">
      if (res->has_depth && res->has_stencil) {<br class="">
         res->secondary = res->swr;<br class="">
@@ -843,6 +845,10 @@ swr_texture_layout(struct swr_screen *screen,<br class="">
                      res->secondary.pitch * res->secondary.numSamples;<br class="">
<br class="">
         res->secondary.xpBaseAddress = (gfxptr_t) AlignedMalloc(total_size, 64);<br class="">
+         if (!res->secondary.xpBaseAddress) {<br class="">
+            AlignedFree((void *)res->swr.xpBaseAddress);<br class="">
+            return false;<br class="">
+         }<br class="">
      }<br class="">
   }<br class="">
<br class="">
-- <br class="">
2.11.0<br class="">
<br class="">
_______________________________________________<br class="">
mesa-dev mailing list<br class="">
<a href="mailto:mesa-dev@lists.freedesktop.org" class="">mesa-dev@lists.freedesktop.org</a><br class="">
https://lists.freedesktop.org/mailman/listinfo/mesa-dev<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>