diff options
author | Kristian Høgsberg Kristensen <[email protected]> | 2015-07-21 13:09:25 -0700 |
---|---|---|
committer | Kristian Høgsberg Kristensen <[email protected]> | 2015-08-10 17:18:55 -0700 |
commit | 9564dd37a00f642d2637ffa15c2f27fb8992aa50 (patch) | |
tree | 6fb869f4604f6c6c6fe1fb1e2c5d9766d477909a /src/vulkan | |
parent | 8605ee60e086ceb936000d3942a902239105637d (diff) |
vk: Query aperture size up front in anv_physical_device_init()
We already query the device in various ways here and we can just also
get the aperture size. This avoids keeping an extra drm fd open
during the life time of the driver.
Also, we need to use explicit 64 bit types for the aperture size, not
size_t.
Diffstat (limited to 'src/vulkan')
-rw-r--r-- | src/vulkan/anv_device.c | 43 | ||||
-rw-r--r-- | src/vulkan/anv_gem.c | 4 | ||||
-rw-r--r-- | src/vulkan/anv_private.h | 4 |
3 files changed, 21 insertions, 30 deletions
diff --git a/src/vulkan/anv_device.c b/src/vulkan/anv_device.c index 0c05c33f626..7eed78c660e 100644 --- a/src/vulkan/anv_device.c +++ b/src/vulkan/anv_device.c @@ -41,20 +41,15 @@ anv_env_get_int(const char *name) return strtol(val, NULL, 0); } -static void -anv_physical_device_finish(struct anv_physical_device *device) -{ - if (device->fd >= 0) - close(device->fd); -} - static VkResult anv_physical_device_init(struct anv_physical_device *device, struct anv_instance *instance, const char *path) { - device->fd = open(path, O_RDWR | O_CLOEXEC); - if (device->fd < 0) + int fd; + + fd = open(path, O_RDWR | O_CLOEXEC); + if (fd < 0) return vk_error(VK_ERROR_UNAVAILABLE); device->instance = instance; @@ -66,7 +61,7 @@ anv_physical_device_init(struct anv_physical_device *device, /* INTEL_DEVID_OVERRIDE implies INTEL_NO_HW. */ device->no_hw = true; } else { - device->chipset_id = anv_gem_get_param(device->fd, I915_PARAM_CHIPSET_ID); + device->chipset_id = anv_gem_get_param(fd, I915_PARAM_CHIPSET_ID); } if (!device->chipset_id) goto fail; @@ -76,22 +71,27 @@ anv_physical_device_init(struct anv_physical_device *device, if (!device->info) goto fail; - if (!anv_gem_get_param(device->fd, I915_PARAM_HAS_WAIT_TIMEOUT)) + if (anv_gem_get_aperture(fd, &device->aperture_size) == -1) + goto fail; + + if (!anv_gem_get_param(fd, I915_PARAM_HAS_WAIT_TIMEOUT)) goto fail; - if (!anv_gem_get_param(device->fd, I915_PARAM_HAS_EXECBUF2)) + if (!anv_gem_get_param(fd, I915_PARAM_HAS_EXECBUF2)) goto fail; - if (!anv_gem_get_param(device->fd, I915_PARAM_HAS_LLC)) + if (!anv_gem_get_param(fd, I915_PARAM_HAS_LLC)) goto fail; - if (!anv_gem_get_param(device->fd, I915_PARAM_HAS_EXEC_CONSTANTS)) + if (!anv_gem_get_param(fd, I915_PARAM_HAS_EXEC_CONSTANTS)) goto fail; + close(fd); + return VK_SUCCESS; fail: - anv_physical_device_finish(device); + close(fd); return vk_error(VK_ERROR_UNAVAILABLE); } @@ -154,10 +154,6 @@ VkResult anv_DestroyInstance( { ANV_FROM_HANDLE(anv_instance, instance, _instance); - if (instance->physicalDeviceCount > 0) { - anv_physical_device_finish(&instance->physicalDevice); - } - VG(VALGRIND_DESTROY_MEMPOOL(instance)); instance->pfnFree(instance->pAllocUserData, instance); @@ -456,17 +452,12 @@ VkResult anv_GetPhysicalDeviceMemoryProperties( VkPhysicalDeviceMemoryProperties* pMemoryProperties) { ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice); - - size_t aperture_size; - size_t heap_size; - - if (anv_gem_get_aperture(physical_device, &aperture_size) == -1) - return vk_error(VK_ERROR_UNAVAILABLE); + VkDeviceSize heap_size; /* Reserve some wiggle room for the driver by exposing only 75% of the * aperture to the heap. */ - heap_size = 3 * aperture_size / 4; + heap_size = 3 * physical_device->aperture_size / 4; /* The property flags below are valid only for llc platforms. */ pMemoryProperties->memoryTypeCount = 1; diff --git a/src/vulkan/anv_gem.c b/src/vulkan/anv_gem.c index 4ce857e2a5f..01671d2ea50 100644 --- a/src/vulkan/anv_gem.c +++ b/src/vulkan/anv_gem.c @@ -230,13 +230,13 @@ anv_gem_destroy_context(struct anv_device *device, int context) } int -anv_gem_get_aperture(struct anv_physical_device *physical_dev, uint64_t *size) +anv_gem_get_aperture(int fd, uint64_t *size) { struct drm_i915_gem_get_aperture aperture; int ret; VG_CLEAR(aperture); - ret = anv_ioctl(physical_dev->fd, DRM_IOCTL_I915_GEM_GET_APERTURE, &aperture); + ret = anv_ioctl(fd, DRM_IOCTL_I915_GEM_GET_APERTURE, &aperture); if (ret == -1) return -1; diff --git a/src/vulkan/anv_private.h b/src/vulkan/anv_private.h index 48edc6c95ed..d53f63d5d27 100644 --- a/src/vulkan/anv_private.h +++ b/src/vulkan/anv_private.h @@ -339,7 +339,7 @@ struct anv_physical_device { const char * path; const char * name; const struct brw_device_info * info; - int fd; + uint64_t aperture_size; }; struct anv_instance { @@ -444,7 +444,7 @@ int anv_gem_set_tiling(struct anv_device *device, int gem_handle, int anv_gem_create_context(struct anv_device *device); int anv_gem_destroy_context(struct anv_device *device, int context); int anv_gem_get_param(int fd, uint32_t param); -int anv_gem_get_aperture(struct anv_physical_device *physical_dev, uint64_t *size); +int anv_gem_get_aperture(int fd, uint64_t *size); int anv_gem_handle_to_fd(struct anv_device *device, int gem_handle); int anv_gem_fd_to_handle(struct anv_device *device, int fd); int anv_gem_userptr(struct anv_device *device, void *mem, size_t size); |