iris: Report the same video memory settings as i965.
authorKenneth Graunke <kenneth@whitecape.org>
Wed, 8 May 2019 19:37:32 +0000 (12:37 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Wed, 8 May 2019 19:43:08 +0000 (12:43 -0700)
This just copy and pastes Ian's code from i965.

src/gallium/drivers/iris/iris_screen.c
src/gallium/drivers/iris/iris_screen.h

index 30d32b2ed431d32085b42d7c0446942bbdfecb2e..b42c359d833a371df91161ff94f276ec82da049e 100644 (file)
@@ -93,6 +93,14 @@ iris_get_name(struct pipe_screen *pscreen)
    return buf;
 }
 
+static uint64_t
+get_aperture_size(int fd)
+{
+   struct drm_i915_gem_get_aperture aperture = {};
+   drm_ioctl(fd, DRM_IOCTL_I915_GEM_GET_APERTURE, &aperture);
+   return aperture.aper_size;
+}
+
 static int
 iris_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
 {
@@ -250,8 +258,28 @@ iris_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
       return 0x8086;
    case PIPE_CAP_DEVICE_ID:
       return screen->pci_id;
-   case PIPE_CAP_VIDEO_MEMORY:
-      return INT_MAX; // XXX: bogus
+   case PIPE_CAP_VIDEO_MEMORY: {
+      /* 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.
+       */
+      const unsigned gpu_mappable_megabytes =
+         (screen->aperture_bytes * 3 / 4) / (1024 * 1024);
+
+      const long system_memory_pages = sysconf(_SC_PHYS_PAGES);
+      const long system_page_size = sysconf(_SC_PAGE_SIZE);
+
+      if (system_memory_pages <= 0 || system_page_size <= 0)
+         return -1;
+
+      const uint64_t system_memory_bytes =
+         (uint64_t) system_memory_pages * (uint64_t) system_page_size;
+
+      const unsigned system_memory_megabytes =
+         (unsigned) (system_memory_bytes / (1024 * 1024));
+
+      return MIN2(system_memory_megabytes, gpu_mappable_megabytes);
+   }
    case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
    case PIPE_CAP_MAX_VARYINGS:
       return 32;
@@ -575,6 +603,8 @@ iris_screen_create(int fd, const struct pipe_screen_config *config)
    screen->devinfo.timestamp_frequency =
       iris_getparam_integer(screen, I915_PARAM_CS_TIMESTAMP_FREQUENCY);
 
+   screen->aperture_bytes = get_aperture_size(fd);
+
    if (getenv("INTEL_NO_HW") != NULL)
       screen->no_hw = true;
 
index a8f33dc32368676e80c4db97dfd32451c3028308..270597a46d0d647f43ddceea7de4155503b6e419 100644 (file)
@@ -68,6 +68,8 @@ struct iris_screen {
 
    unsigned subslice_total;
 
+   uint64_t aperture_bytes;
+
    struct gen_device_info devinfo;
    struct isl_device isl_dev;
    struct iris_bufmgr *bufmgr;