Commit da997ebe authored by Keith Packard's avatar Keith Packard
Browse files

vulkan: Add KHR_display extension using DRM [v10]

This adds support for the KHR_display extension support to the vulkan
WSI layer. Driver support will be added separately.

v2:
	* fix double ;; in wsi_common_display.c

	* Move mode list from wsi_display to wsi_display_connector

	* Fix scope for wsi_display_mode andwsi_display_connector
          allocs

	* Switch all allocations to vk_zalloc instead of vk_alloc.

	* Fix DRM failure in
          wsi_display_get_physical_device_display_properties

	  When DRM fails, or when we don't have a master fd
	  (presumably due to application errors), just return 0
	  properties from this function, which is at least a valid
	  response.

	* Use vk_outarray for all property queries

	  This is a bit less error-prone than open-coding the same
	  stuff.

	* Remove VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR from surface caps

	  Until we have multi-plane support, we shouldn't pretend to
	  have any multi-plane semantics, even if undefined.

	Suggested-by: Jason Ekstrand <jason@...
parent ef794570
......@@ -225,6 +225,7 @@ radv_physical_device_init(struct radv_physical_device *device,
VkResult result;
drmVersionPtr version;
int fd;
int master_fd = -1;
fd = open(path, O_RDWR | O_CLOEXEC);
if (fd < 0) {
......@@ -247,6 +248,8 @@ radv_physical_device_init(struct radv_physical_device *device,
if (strcmp(version->name, "amdgpu")) {
drmFreeVersion(version);
if (master_fd != -1)
close(master_fd);
close(fd);
if (instance->debug_flags & RADV_DEBUG_STARTUP)
......@@ -271,6 +274,7 @@ radv_physical_device_init(struct radv_physical_device *device,
goto fail;
}
device->master_fd = master_fd;
device->local_fd = fd;
device->ws->query_info(device->ws, &device->rad_info);
......@@ -349,6 +353,8 @@ radv_physical_device_init(struct radv_physical_device *device,
fail:
close(fd);
if (master_fd != -1)
close(master_fd);
return result;
}
......@@ -359,6 +365,8 @@ radv_physical_device_finish(struct radv_physical_device *device)
device->ws->destroy(device->ws);
disk_cache_destroy(device->disk_cache);
close(device->local_fd);
if (device->master_fd != -1)
close(device->master_fd);
}
static void *
......
......@@ -285,6 +285,7 @@ struct radv_physical_device {
uint8_t cache_uuid[VK_UUID_SIZE];
int local_fd;
int master_fd;
struct wsi_device wsi_device;
bool has_rbplus; /* if RB+ register exist */
......
......@@ -41,7 +41,8 @@ radv_init_wsi(struct radv_physical_device *physical_device)
return wsi_device_init(&physical_device->wsi_device,
radv_physical_device_to_handle(physical_device),
radv_wsi_proc_addr,
&physical_device->instance->alloc);
&physical_device->instance->alloc,
physical_device->master_fd);
}
void
......
......@@ -278,6 +278,7 @@ anv_physical_device_init(struct anv_physical_device *device,
{
VkResult result;
int fd;
int master_fd = -1;
brw_process_intel_debug_variable();
......@@ -449,10 +450,13 @@ anv_physical_device_init(struct anv_physical_device *device,
&device->supported_extensions);
device->local_fd = fd;
device->master_fd = master_fd;
return VK_SUCCESS;
fail:
close(fd);
if (master_fd != -1)
close(master_fd);
return result;
}
......
......@@ -876,6 +876,7 @@ struct anv_physical_device {
struct wsi_device wsi_device;
int local_fd;
int master_fd;
};
struct anv_instance {
......
......@@ -48,7 +48,8 @@ anv_init_wsi(struct anv_physical_device *physical_device)
result = wsi_device_init(&physical_device->wsi_device,
anv_physical_device_to_handle(physical_device),
anv_wsi_proc_addr,
&physical_device->instance->alloc);
&physical_device->instance->alloc,
physical_device->master_fd);
if (result != VK_SUCCESS)
return result;
......
......@@ -54,6 +54,13 @@ AM_CPPFLAGS += \
VULKAN_WSI_SOURCES += $(VULKAN_WSI_X11_FILES)
endif
if HAVE_PLATFORM_DRM
AM_CPPFLAGS += \
-DVK_USE_PLATFORM_DISPLAY_KHR
VULKAN_WSI_SOURCES += $(VULKAN_WSI_DISPLAY_FILES)
endif
CLEANFILES = \
$(VULKAN_UTIL_GENERATED_FILES) \
$(VULKAN_WSI_WAYLAND_GENERATED_FILES)
......
......@@ -19,6 +19,10 @@ VULKAN_WSI_X11_FILES := \
wsi/wsi_common_x11.c \
wsi/wsi_common_x11.h
VULKAN_WSI_DISPLAY_FILES := \
wsi/wsi_common_display.c \
wsi/wsi_common_display.h
VULKAN_UTIL_FILES := \
util/vk_alloc.h \
util/vk_debug_report.c \
......
......@@ -59,6 +59,14 @@ if with_platform_wayland
]
endif
if with_platform_drm
vulkan_wsi_args += '-DVK_USE_PLATFORM_DISPLAY_KHR'
files_vulkan_wsi += files(
'wsi_common_display.c',
'wsi_common_display.h',
)
endif
libvulkan_wsi = static_library(
'vulkan_wsi',
files_vulkan_wsi,
......
......@@ -32,7 +32,8 @@ VkResult
wsi_device_init(struct wsi_device *wsi,
VkPhysicalDevice pdevice,
WSI_FN_GetPhysicalDeviceProcAddr proc_addr,
const VkAllocationCallbacks *alloc)
const VkAllocationCallbacks *alloc,
int display_fd)
{
VkResult result;
......@@ -91,6 +92,12 @@ wsi_device_init(struct wsi_device *wsi,
goto fail;
#endif
#ifdef VK_USE_PLATFORM_DISPLAY_KHR
result = wsi_display_init_wsi(wsi, alloc, display_fd);
if (result != VK_SUCCESS)
goto fail;
#endif
return VK_SUCCESS;
fail:
......@@ -102,6 +109,9 @@ void
wsi_device_finish(struct wsi_device *wsi,
const VkAllocationCallbacks *alloc)
{
#ifdef VK_USE_PLATFORM_DISPLAY_KHR
wsi_display_finish_wsi(wsi, alloc);
#endif
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
wsi_wl_finish_wsi(wsi, alloc);
#endif
......
......@@ -68,7 +68,7 @@ struct wsi_format_modifier_properties_list {
struct wsi_interface;
#define VK_ICD_WSI_PLATFORM_MAX 5
#define VK_ICD_WSI_PLATFORM_MAX (VK_ICD_WSI_PLATFORM_DISPLAY + 1)
struct wsi_device {
VkPhysicalDevice pdevice;
......@@ -116,7 +116,8 @@ VkResult
wsi_device_init(struct wsi_device *wsi,
VkPhysicalDevice pdevice,
WSI_FN_GetPhysicalDeviceProcAddr proc_addr,
const VkAllocationCallbacks *alloc);
const VkAllocationCallbacks *alloc,
int display_fd);
void
wsi_device_finish(struct wsi_device *wsi,
......
This diff is collapsed.
/*
* Copyright © 2017 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#ifndef WSI_COMMON_DISPLAY_H
#define WSI_COMMON_DISPLAY_H
#include "wsi_common.h"
#include <xf86drm.h>
#include <xf86drmMode.h>
#define typed_memcpy(dest, src, count) ({ \
STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
memcpy((dest), (src), (count) * sizeof(*(src))); \
})
VkResult
wsi_display_get_physical_device_display_properties(
VkPhysicalDevice physical_device,
struct wsi_device *wsi_device,
uint32_t *property_count,
VkDisplayPropertiesKHR *properties);
VkResult
wsi_display_get_physical_device_display_plane_properties(
VkPhysicalDevice physical_device,
struct wsi_device *wsi_device,
uint32_t *property_count,
VkDisplayPlanePropertiesKHR *properties);
VkResult
wsi_display_get_display_plane_supported_displays(
VkPhysicalDevice physical_device,
struct wsi_device *wsi_device,
uint32_t plane_index,
uint32_t *display_count,
VkDisplayKHR *displays);
VkResult
wsi_display_get_display_mode_properties(VkPhysicalDevice physical_device,
struct wsi_device *wsi_device,
VkDisplayKHR display,
uint32_t *property_count,
VkDisplayModePropertiesKHR *properties);
VkResult
wsi_display_create_display_mode(VkPhysicalDevice physical_device,
struct wsi_device *wsi_device,
VkDisplayKHR display,
const VkDisplayModeCreateInfoKHR *create_info,
const VkAllocationCallbacks *allocator,
VkDisplayModeKHR *mode);
VkResult
wsi_get_display_plane_capabilities(VkPhysicalDevice physical_device,
struct wsi_device *wsi_device,
VkDisplayModeKHR mode_khr,
uint32_t plane_index,
VkDisplayPlaneCapabilitiesKHR *capabilities);
VkResult
wsi_create_display_surface(VkInstance instance,
const VkAllocationCallbacks *pAllocator,
const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
VkSurfaceKHR *pSurface);
#endif
......@@ -141,6 +141,15 @@ void wsi_wl_finish_wsi(struct wsi_device *wsi_device,
const VkAllocationCallbacks *alloc);
VkResult
wsi_display_init_wsi(struct wsi_device *wsi_device,
const VkAllocationCallbacks *alloc,
int display_fd);
void
wsi_display_finish_wsi(struct wsi_device *wsi_device,
const VkAllocationCallbacks *alloc);
#define WSI_DEFINE_NONDISP_HANDLE_CASTS(__wsi_type, __VkType) \
\
static inline struct __wsi_type * \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment