<div dir="ltr">Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 4, 2017 at 5:09 PM, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On modern systems with 4GB apertures, the size in bytes is 4294967296,<br>
or (1ull << 32).  The kernel gives us the aperture size as a __u64,<br>
which works out great.<br>
<br>
Unfortunately, libdrm "helpfully" returns the data as a size_t, which<br>
on 32-bit systems means it truncates the aperture size to 0 bytes.<br>
We've happily reported this value as 0 MB of video memory via<br>
GLX_MESA_query_renderer since it was originally exposed.<br>
<br>
This patch bypasses libdrm and calls the ioctl ourselves so we can<br>
use a proper uint64_t, avoiding the 32-bit integer overflow.  We now<br>
report a proper video memory size on 32-bit systems.<br>
---<br>
 src/mesa/drivers/dri/i965/<wbr>intel_screen.c | 16 ++++++++++++----<br>
 1 file changed, 12 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>intel_screen.c b/src/mesa/drivers/dri/i965/<wbr>intel_screen.c<br>
index 811a9c5a867..f94e8a77c10 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>intel_screen.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>intel_screen.c<br>
@@ -950,6 +950,17 @@ static const __DRIimageExtension intelImageExtension = {<br>
     .createImageWithModifiers           = intel_create_image_with_<wbr>modifiers,<br>
 };<br>
<br>
+static uint64_t<br>
+get_aperture_size(int fd)<br>
+{<br>
+   struct drm_i915_gem_get_aperture aperture;<br>
+<br>
+   if (drmIoctl(fd, DRM_IOCTL_I915_GEM_GET_<wbr>APERTURE, &aperture) != 0)<br>
+      return 0;<br>
+<br>
+   return aperture.aper_size;<br>
+}<br>
+<br>
 static int<br>
 brw_query_renderer_integer(__<wbr>DRIscreen *dri_screen,<br>
                            int param, unsigned int *value)<br>
@@ -972,10 +983,7 @@ brw_query_renderer_integer(__<wbr>DRIscreen *dri_screen,<br>
        * assume that there's some fragmentation, and we start doing extra<br>
        * flushing, etc.  That's the big cliff apps will care about.<br>
        */<br>
-      size_t aper_size;<br>
-      size_t mappable_size;<br>
-<br>
-      drm_intel_get_aperture_sizes(<wbr>dri_screen->fd, &mappable_size, &aper_size);<br>
+      uint64_t aper_size = get_aperture_size(dri_screen-><wbr>fd);<br>
<br>
       const unsigned gpu_mappable_megabytes =<br>
          (aper_size / (1024 * 1024)) * 3 / 4;<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.12.1<br>
<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>
</font></span></blockquote></div><br></div></div></div>