[Mesa-dev] [PATCH 01/53] i965: Fix GLX_MESA_query_renderer video memory on 32-bit.
Jason Ekstrand
jason at jlekstrand.net
Wed Apr 5 02:48:11 UTC 2017
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
On Tue, Apr 4, 2017 at 5:09 PM, Kenneth Graunke <kenneth at whitecape.org>
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;
> +
> + return aperture.aper_size;
> +}
> +
> static int
> brw_query_renderer_integer(__DRIscreen *dri_screen,
> int param, unsigned int *value)
> @@ -972,10 +983,7 @@ brw_query_renderer_integer(__DRIscreen *dri_screen,
> * assume that there's some fragmentation, and we start doing extra
> * flushing, etc. That's the big cliff apps will care about.
> */
> - size_t aper_size;
> - size_t mappable_size;
> -
> - drm_intel_get_aperture_sizes(dri_screen->fd, &mappable_size,
> &aper_size);
> + uint64_t aper_size = get_aperture_size(dri_screen->fd);
>
> const unsigned gpu_mappable_megabytes =
> (aper_size / (1024 * 1024)) * 3 / 4;
> --
> 2.12.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170404/41cc65fc/attachment.html>
More information about the mesa-dev
mailing list