[Mesa-dev] [PATCH 08/18] i965: Wire up initial support for DRI_RENDERER_QUERY extension

Kenneth Graunke kenneth at whitecape.org
Thu Nov 7 13:29:08 PST 2013


On 10/11/2013 03:10 PM, Ian Romanick wrote:
> From: Ian Romanick <ian.d.romanick at intel.com>
> 
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> ---
>  src/mesa/drivers/dri/i965/intel_screen.c | 81 ++++++++++++++++++++++++++++++++
>  1 file changed, 81 insertions(+)
> 
> diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
> index b6b4275..e8a0323 100644
> --- a/src/mesa/drivers/dri/i965/intel_screen.c
> +++ b/src/mesa/drivers/dri/i965/intel_screen.c
> @@ -27,6 +27,7 @@
>  
>  #include <errno.h>
>  #include <time.h>
> +#include <sys/sysinfo.h>
>  #include "main/glheader.h"
>  #include "main/context.h"
>  #include "main/framebuffer.h"
> @@ -835,10 +836,90 @@ static struct __DRIimageExtensionRec intelImageExtension = {
>      .createImageFromDmaBufs             = intel_create_image_from_dma_bufs
>  };
>  
> +static int
> +brw_query_renderer_integer(__DRIscreen *psp, int param, int *value)
> +{
> +   const struct intel_screen *const intelScreen =
> +      (struct intel_screen *) psp->driverPrivate;
> +
> +   switch (param) {
> +   case __DRI2_RENDERER_VENDOR_ID:
> +      value[0] = 0x8086;
> +      return 0;
> +   case __DRI2_RENDERER_DEVICE_ID:
> +      value[0] = intelScreen->deviceID;
> +      return 0;
> +   case __DRI2_RENDERER_ACCELERATED:
> +      value[0] = 1;
> +      return 0;
> +   case __DRI2_RENDERER_VIDEO_MEMORY: {
> +      struct sysinfo info;
> +      uint64_t system_memory_bytes;
> +      unsigned system_memory_megabytes;
> +
> +      /* Once a batch uses more than 75% of the maximum mappable size, we
> +       * assume that there's some fragmentation, and we start doing extra
> +       * flushing, etc.  That's the big cliff apps will care about.
> +       *
> +       * Can only map 2G onto the GPU through the GTT.
> +       */
> +      const unsigned gpu_mappable_megabytes = 2 * 1024 * 3 / 4;
> +
> +      if (sysinfo(&info) < 0)
> +         return -1;

This is Linux-specific, so it won't work on BSD or Solaris.  I think you
could also do:

uint64_t system_memory_bytes =
   sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGE_SIZE);

(I found this suggestion on StackOverflow:)
http://stackoverflow.com/questions/2513505/how-to-get-available-memory-c-g

According to the man page, sysconf(3) conforms to POSIX.1-2001.  A bit
of searching shows that it's available on Solaris and Mac OS X.

The 3/4 GTT suggestion sounds reasonably sane, but I'd like to hear
Eric's opinion on the matter.

--Ken


More information about the mesa-dev mailing list