From 54d0daa4819338c5b94b6dd80a8693eb6046d09f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 7 Feb 2018 10:31:44 -0800 Subject: anv: Add KHR_display extension to anv [v7] This adds support for the KHR_display extension to the anv Vulkan driver. The driver now attempts to open the master DRM node when the KHR_display extension is requested so that the common winsys code can perform the necessary operations. v2: Make sure primary fd is usable When KHR_display is selected, we try to open the primary node instead of the render node in case the user wants to use KHR_display for presentation. However, if we're actually going to end up using RandR leases, then we don't care if the resulting fd can't be used for display, but the kernel also prevents us from using it for drawing when someone else has master. v3: Simplify addition of VK_USE_PLATFORM_DISPLAY_KHR to vulkan_wsi_args Suggested-by: Eric Engestrom v4: Adapt primary node usage to new wsi_device_init API v5: Adopt Jason Ekstrand's coding conventions Declare variables at first use, eliminate extra whitespace between types and names. Wrap lines to 80 columns. Remove spurious MM_PER_PIXEL define Suggested-by: Jason Ekstrand v6: Open DRM master before initializing WSI layer. The DRM master FD is passed to the WSI layer during initialization, so we need to open the device slightly earlier in the function. Close DRM master in device_finish. Use anv_gem_get_param to detect working master_fd instead of directly using the ioctl. Suggested-by: Jason Ekstrand v7: Add vkCreateDisplayModeKHR. This doesn't actually create new modes, it only looks to see if the requested parameters matches an existing mode and returns that. Suggested-by: Jason Ekstrand Signed-off-by: Keith Packard Reviewed-by: Jason Ekstrand --- src/intel/vulkan/anv_device.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/intel/vulkan/anv_device.c') diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 294a145c1a8..b3d30675b1e 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -274,6 +274,7 @@ anv_physical_device_init_uuids(struct anv_physical_device *device) static VkResult anv_physical_device_init(struct anv_physical_device *device, struct anv_instance *instance, + const char *primary_path, const char *path) { VkResult result; @@ -440,6 +441,20 @@ anv_physical_device_init(struct anv_physical_device *device, if (result != VK_SUCCESS) goto fail; + if (instance->enabled_extensions.KHR_display) { + master_fd = open(primary_path, O_RDWR | O_CLOEXEC); + if (master_fd >= 0) { + /* prod the device with a GETPARAM call which will fail if + * we don't have permission to even render on this device + */ + if (anv_gem_get_param(master_fd, I915_PARAM_CHIPSET_ID) == 0) { + close(master_fd); + master_fd = -1; + } + } + } + device->master_fd = master_fd; + result = anv_init_wsi(device); if (result != VK_SUCCESS) { ralloc_free(device->compiler); @@ -449,8 +464,9 @@ anv_physical_device_init(struct anv_physical_device *device, anv_physical_device_get_supported_extensions(device, &device->supported_extensions); + device->local_fd = fd; - device->master_fd = master_fd; + return VK_SUCCESS; fail: @@ -466,6 +482,8 @@ anv_physical_device_finish(struct anv_physical_device *device) anv_finish_wsi(device); ralloc_free(device->compiler); close(device->local_fd); + if (device->master_fd >= 0) + close(device->master_fd); } static void * @@ -639,6 +657,7 @@ anv_enumerate_devices(struct anv_instance *instance) result = anv_physical_device_init(&instance->physicalDevice, instance, + devices[i]->nodes[DRM_NODE_PRIMARY], devices[i]->nodes[DRM_NODE_RENDER]); if (result != VK_ERROR_INCOMPATIBLE_DRIVER) break; -- cgit v1.2.3