[Mesa-dev] [PATCH] i965: Fix GLX_MESA_query_renderer video memory on 32-bit.

Chris Wilson chris at chris-wilson.co.uk
Thu Mar 30 23:38:14 UTC 2017


On Thu, Mar 30, 2017 at 04:28:19PM -0700, Kenneth Graunke wrote:
> On modern systems with 4GB apertures, the size in bytes is 4294967296,
> or (1ull << 32).  The kernel gives us the aperture size as a __u64,
> which works out great.
> 
> Unfortunately, libdrm "helpfully" returns the data as a size_t, which
> on 32-bit systems means it truncates the aperture size to 0 bytes.
> We've happily reported this value as 0 MB of video memory via
> GLX_MESA_query_renderer since it was originally exposed.
> 
> This patch bypasses libdrm and calls the ioctl ourselves so we can
> use a proper uint64_t, avoiding the 32-bit integer overflow.  We now
> report a proper video memory size on 32-bit systems.
> ---
>  src/mesa/drivers/dri/i965/intel_screen.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
> index 811a9c5a867..f94e8a77c10 100644
> --- a/src/mesa/drivers/dri/i965/intel_screen.c
> +++ b/src/mesa/drivers/dri/i965/intel_screen.c
> @@ -950,6 +950,17 @@ static const __DRIimageExtension intelImageExtension = {
>      .createImageWithModifiers           = intel_create_image_with_modifiers,
>  };
>  
> +static uint64_t
> +get_aperture_size(int fd)
> +{
> +   struct drm_i915_gem_get_aperture aperture;
> +
> +   if (drmIoctl(fd, DRM_IOCTL_I915_GEM_GET_APERTURE, &aperture) != 0)
> +      return 0;

The aperture is nothing to do with the video memory limits... You want
to query the context for the size of the GTT, e.g.
https://patchwork.freedesktop.org/patch/62189/

i.e.
static uint64_t get_gtt_size(int fd)
{
   struct drm_i915_gem_context_param p;
   size_t mappable_size, aper_size;

   memset(&p, 0, sizeof(p));
   p.param = I915_CONTEXT_PARAM_GTT_SIZE;
   if (drmIoctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0)
      return p.value;

   /* do sometheing useful for old kernels */

   drm_intel_get_aperture_sizes(fd, &mappable_size, &aper_size);

   return aper_size;
}

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the mesa-dev mailing list