vk/device: Add member anv_physical_device::fd
authorChad Versace <chad.versace@intel.com>
Thu, 9 Jul 2015 23:31:39 +0000 (16:31 -0700)
committerChad Versace <chad.versace@intel.com>
Sat, 11 Jul 2015 00:35:52 +0000 (17:35 -0700)
During anv_physical_device_init(), we opend the DRM device to do some
queries, then promptly closed it. Now we keep it open for the lifetime
of the anv_physical_device so that we can query it some more during
vkGetPhysicalDevice*Properties() [which will happen in follow-up
commits].

src/vulkan/device.c
src/vulkan/private.h

index 0856bcec4004545241245a921b83054fecd496f3..c5079dfebd9ec3d1b3a5c379746fc243ffdcf8bc 100644 (file)
@@ -44,7 +44,8 @@ anv_env_get_int(const char *name)
 static void
 anv_physical_device_finish(struct anv_physical_device *device)
 {
-   /* Nothing to do */
+   if (device->fd >= 0)
+      close(device->fd);
 }
 
 static VkResult
@@ -52,10 +53,8 @@ anv_physical_device_init(struct anv_physical_device *device,
                          struct anv_instance *instance,
                          const char *path)
 {
-   int fd;
-   
-   fd = open(path, O_RDWR | O_CLOEXEC);
-   if (fd < 0)
+   device->fd = open(path, O_RDWR | O_CLOEXEC);
+   if (device->fd < 0)
       return vk_error(VK_ERROR_UNAVAILABLE);
 
    device->instance = instance;
@@ -67,7 +66,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(fd, I915_PARAM_CHIPSET_ID);
+      device->chipset_id = anv_gem_get_param(device->fd, I915_PARAM_CHIPSET_ID);
    }
    if (!device->chipset_id)
       goto fail;
@@ -77,25 +76,22 @@ anv_physical_device_init(struct anv_physical_device *device,
    if (!device->info)
       goto fail;
    
-   if (!anv_gem_get_param(fd, I915_PARAM_HAS_WAIT_TIMEOUT))
+   if (!anv_gem_get_param(device->fd, I915_PARAM_HAS_WAIT_TIMEOUT))
       goto fail;
 
-   if (!anv_gem_get_param(fd, I915_PARAM_HAS_EXECBUF2))
+   if (!anv_gem_get_param(device->fd, I915_PARAM_HAS_EXECBUF2))
       goto fail;
 
-   if (!anv_gem_get_param(fd, I915_PARAM_HAS_LLC))
+   if (!anv_gem_get_param(device->fd, I915_PARAM_HAS_LLC))
       goto fail;
 
-   if (!anv_gem_get_param(fd, I915_PARAM_HAS_EXEC_CONSTANTS))
+   if (!anv_gem_get_param(device->fd, I915_PARAM_HAS_EXEC_CONSTANTS))
       goto fail;
-
-   close(fd);
    
    return VK_SUCCESS;
    
- fail:
-   close(fd);
-
+fail:
+   anv_physical_device_finish(device);
    return vk_error(VK_ERROR_UNAVAILABLE);
 }
 
@@ -528,6 +524,8 @@ VkResult anv_CreateDevice(
    parse_debug_flags(device);
 
    device->instance = physical_device->instance;
+
+   /* XXX(chadv): Can we dup() physicalDevice->fd here? */
    device->fd = open(physical_device->path, O_RDWR | O_CLOEXEC);
    if (device->fd == -1)
       goto fail_device;
index ea846bfc06e7bc38eef35070ea683adec4e0ed95..b4f7e3f7a45232f3e7f7ef16a48040afed91e9b5 100644 (file)
@@ -343,6 +343,7 @@ struct anv_physical_device {
     const char *                                path;
     const char *                                name;
     const struct brw_device_info *              info;
+    int                                         fd;
 };
 
 struct anv_instance {