[Mesa-dev] [PATCH v2] anv, radv: Add support for VK_KHR_get_display_properties2
Jason Ekstrand
jason at jlekstrand.net
Wed Jun 20 15:07:20 UTC 2018
Cc: Keith Packard <keithp at keithp.com>
---
src/amd/vulkan/radv_extensions.py | 1 +
src/amd/vulkan/radv_wsi_display.c | 57 +++++++++
src/intel/vulkan/anv_extensions.py | 1 +
src/intel/vulkan/anv_wsi_display.c | 56 +++++++++
src/vulkan/wsi/wsi_common_display.c | 175 +++++++++++++++++++++++++---
src/vulkan/wsi/wsi_common_display.h | 27 +++++
6 files changed, 301 insertions(+), 16 deletions(-)
diff --git a/src/amd/vulkan/radv_extensions.py b/src/amd/vulkan/radv_extensions.py
index 65ce7349016..5eb63a7d5dc 100644
--- a/src/amd/vulkan/radv_extensions.py
+++ b/src/amd/vulkan/radv_extensions.py
@@ -66,6 +66,7 @@ EXTENSIONS = [
Extension('VK_KHR_external_semaphore', 1, 'device->rad_info.has_syncobj'),
Extension('VK_KHR_external_semaphore_capabilities', 1, True),
Extension('VK_KHR_external_semaphore_fd', 1, 'device->rad_info.has_syncobj'),
+ Extension('VK_KHR_get_display_properties2', 1, 'VK_USE_PLATFORM_DISPLAY_KHR'),
Extension('VK_KHR_get_memory_requirements2', 1, True),
Extension('VK_KHR_get_physical_device_properties2', 1, True),
Extension('VK_KHR_get_surface_capabilities2', 1, 'RADV_HAS_SURFACE'),
diff --git a/src/amd/vulkan/radv_wsi_display.c b/src/amd/vulkan/radv_wsi_display.c
index 84431019dbb..764180ec7b5 100644
--- a/src/amd/vulkan/radv_wsi_display.c
+++ b/src/amd/vulkan/radv_wsi_display.c
@@ -56,6 +56,20 @@ radv_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physical_device,
properties);
}
+VkResult
+radv_GetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physical_device,
+ uint32_t *property_count,
+ VkDisplayProperties2KHR *properties)
+{
+ RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
+
+ return wsi_display_get_physical_device_display_properties2(
+ physical_device,
+ &pdevice->wsi_device,
+ property_count,
+ properties);
+}
+
VkResult
radv_GetPhysicalDeviceDisplayPlanePropertiesKHR(
VkPhysicalDevice physical_device,
@@ -71,6 +85,21 @@ radv_GetPhysicalDeviceDisplayPlanePropertiesKHR(
properties);
}
+VkResult
+radv_GetPhysicalDeviceDisplayPlaneProperties2KHR(
+ VkPhysicalDevice physical_device,
+ uint32_t *property_count,
+ VkDisplayPlaneProperties2KHR *properties)
+{
+ RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
+
+ return wsi_display_get_physical_device_display_plane_properties2(
+ physical_device,
+ &pdevice->wsi_device,
+ property_count,
+ properties);
+}
+
VkResult
radv_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physical_device,
uint32_t plane_index,
@@ -103,6 +132,21 @@ radv_GetDisplayModePropertiesKHR(VkPhysicalDevice physical_device,
properties);
}
+VkResult
+radv_GetDisplayModeProperties2KHR(VkPhysicalDevice physical_device,
+ VkDisplayKHR display,
+ uint32_t *property_count,
+ VkDisplayModeProperties2KHR *properties)
+{
+ RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
+
+ return wsi_display_get_display_mode_properties2(physical_device,
+ &pdevice->wsi_device,
+ display,
+ property_count,
+ properties);
+}
+
VkResult
radv_CreateDisplayModeKHR(VkPhysicalDevice physical_device,
VkDisplayKHR display,
@@ -135,6 +179,19 @@ radv_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physical_device,
capabilities);
}
+VkResult
+radv_GetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physical_device,
+ const VkDisplayPlaneInfo2KHR *pDisplayPlaneInfo,
+ VkDisplayPlaneCapabilities2KHR *capabilities)
+{
+ RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
+
+ return wsi_get_display_plane_capabilities2(physical_device,
+ &pdevice->wsi_device,
+ pDisplayPlaneInfo,
+ capabilities);
+}
+
VkResult
radv_CreateDisplayPlaneSurfaceKHR(
VkInstance _instance,
diff --git a/src/intel/vulkan/anv_extensions.py b/src/intel/vulkan/anv_extensions.py
index 2bba4ee4d2b..e3e996ad136 100644
--- a/src/intel/vulkan/anv_extensions.py
+++ b/src/intel/vulkan/anv_extensions.py
@@ -88,6 +88,7 @@ EXTENSIONS = [
Extension('VK_KHR_external_semaphore', 1, True),
Extension('VK_KHR_external_semaphore_capabilities', 1, True),
Extension('VK_KHR_external_semaphore_fd', 1, True),
+ Extension('VK_KHR_get_display_properties2', 1, 'VK_USE_PLATFORM_DISPLAY_KHR'),
Extension('VK_KHR_get_memory_requirements2', 1, True),
Extension('VK_KHR_get_physical_device_properties2', 1, True),
Extension('VK_KHR_get_surface_capabilities2', 1, 'ANV_HAS_SURFACE'),
diff --git a/src/intel/vulkan/anv_wsi_display.c b/src/intel/vulkan/anv_wsi_display.c
index ed679e85e13..c8892a88606 100644
--- a/src/intel/vulkan/anv_wsi_display.c
+++ b/src/intel/vulkan/anv_wsi_display.c
@@ -40,6 +40,19 @@ anv_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physical_device,
properties);
}
+VkResult
+anv_GetPhysicalDeviceDisplayProperties2KHR(
+ VkPhysicalDevice physicalDevice,
+ uint32_t* pPropertyCount,
+ VkDisplayProperties2KHR* pProperties)
+{
+ ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
+
+ return wsi_display_get_physical_device_display_properties2(
+ physicalDevice, &pdevice->wsi_device,
+ pPropertyCount, pProperties);
+}
+
VkResult
anv_GetPhysicalDeviceDisplayPlanePropertiesKHR(
VkPhysicalDevice physical_device,
@@ -53,6 +66,19 @@ anv_GetPhysicalDeviceDisplayPlanePropertiesKHR(
property_count, properties);
}
+VkResult
+anv_GetPhysicalDeviceDisplayPlaneProperties2KHR(
+ VkPhysicalDevice physicalDevice,
+ uint32_t* pPropertyCount,
+ VkDisplayPlaneProperties2KHR* pProperties)
+{
+ ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
+
+ return wsi_display_get_physical_device_display_plane_properties2(
+ physicalDevice, &pdevice->wsi_device,
+ pPropertyCount, pProperties);
+}
+
VkResult
anv_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physical_device,
uint32_t plane_index,
@@ -84,6 +110,22 @@ anv_GetDisplayModePropertiesKHR(VkPhysicalDevice physical_device,
properties);
}
+VkResult
+anv_GetDisplayModeProperties2KHR(
+ VkPhysicalDevice physicalDevice,
+ VkDisplayKHR display,
+ uint32_t* pPropertyCount,
+ VkDisplayModeProperties2KHR* pProperties)
+{
+ ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
+
+ return wsi_display_get_display_mode_properties2(physicalDevice,
+ &pdevice->wsi_device,
+ display,
+ pPropertyCount,
+ pProperties);
+}
+
VkResult
anv_CreateDisplayModeKHR(VkPhysicalDevice physical_device,
VkDisplayKHR display,
@@ -116,6 +158,20 @@ anv_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physical_device,
capabilities);
}
+VkResult
+anv_GetDisplayPlaneCapabilities2KHR(
+ VkPhysicalDevice physicalDevice,
+ const VkDisplayPlaneInfo2KHR* pDisplayPlaneInfo,
+ VkDisplayPlaneCapabilities2KHR* pCapabilities)
+{
+ ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
+
+ return wsi_get_display_plane_capabilities2(physicalDevice,
+ &pdevice->wsi_device,
+ pDisplayPlaneInfo,
+ pCapabilities);
+}
+
VkResult
anv_CreateDisplayPlaneSurfaceKHR(
VkInstance _instance,
diff --git a/src/vulkan/wsi/wsi_common_display.c b/src/vulkan/wsi/wsi_common_display.c
index 4f52e8087a6..670bb7fba91 100644
--- a/src/vulkan/wsi/wsi_common_display.c
+++ b/src/vulkan/wsi/wsi_common_display.c
@@ -341,8 +341,11 @@ mode_size(struct wsi_display_mode *mode)
static void
wsi_display_fill_in_display_properties(struct wsi_device *wsi_device,
struct wsi_display_connector *connector,
- VkDisplayPropertiesKHR *properties)
+ VkDisplayProperties2KHR *properties2)
{
+ assert(properties2->sType == VK_STRUCTURE_TYPE_DISPLAY_PROPERTIES_2_KHR);
+ VkDisplayPropertiesKHR *properties = &properties2->displayProperties;
+
properties->display = wsi_display_connector_to_handle(connector);
properties->displayName = connector->name;
@@ -401,6 +404,50 @@ wsi_display_get_physical_device_display_properties(
struct wsi_display *wsi =
(struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLATFORM_DISPLAY];
+ if (properties == NULL) {
+ return wsi_display_get_physical_device_display_properties2(
+ physical_device, wsi_device, property_count, NULL);
+ } else {
+ /* If we're actually returning properties, allocate a temporary array of
+ * VkDisplayProperties2KHR structs, call properties2 to fill them out,
+ * and then copy them to the client. This seems a bit expensive but
+ * wsi_display_get_physical_device_display_properties2() calls
+ * drmModeGetResources() which does an ioctl and then a bunch of
+ * allocations so this should get lost in the noise.
+ */
+ VkDisplayProperties2KHR *props2 =
+ vk_zalloc(wsi->alloc, sizeof(*props2) * *property_count, 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ if (props2 == NULL)
+ return VK_ERROR_OUT_OF_HOST_MEMORY;
+
+ for (uint32_t i = 0; i < *property_count; i++)
+ props2[i].sType = VK_STRUCTURE_TYPE_DISPLAY_PROPERTIES_2_KHR;
+
+ VkResult result = wsi_display_get_physical_device_display_properties2(
+ physical_device, wsi_device, property_count, props2);
+
+ if (result == VK_SUCCESS || result == VK_INCOMPLETE) {
+ for (uint32_t i = 0; i < *property_count; i++)
+ properties[i] = props2[i].displayProperties;
+ }
+
+ vk_free(wsi->alloc, props2);
+
+ return result;
+ }
+}
+
+VkResult
+wsi_display_get_physical_device_display_properties2(
+ VkPhysicalDevice physical_device,
+ struct wsi_device *wsi_device,
+ uint32_t *property_count,
+ VkDisplayProperties2KHR *properties)
+{
+ struct wsi_display *wsi =
+ (struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLATFORM_DISPLAY];
+
if (wsi->fd < 0)
goto bail;
@@ -443,6 +490,24 @@ bail:
/*
* Implement vkGetPhysicalDeviceDisplayPlanePropertiesKHR (VK_KHR_display
*/
+static void
+wsi_display_fill_in_display_plane_properties(
+ struct wsi_device *wsi_device,
+ struct wsi_display_connector *connector,
+ VkDisplayPlaneProperties2KHR *properties)
+{
+ assert(properties->sType == VK_STRUCTURE_TYPE_DISPLAY_PLANE_PROPERTIES_2_KHR);
+ VkDisplayPlanePropertiesKHR *prop = &properties->displayPlaneProperties;
+
+ if (connector && connector->active) {
+ prop->currentDisplay = wsi_display_connector_to_handle(connector);
+ prop->currentStackIndex = 0;
+ } else {
+ prop->currentDisplay = VK_NULL_HANDLE;
+ prop->currentStackIndex = 0;
+ }
+}
+
VkResult
wsi_display_get_physical_device_display_plane_properties(
VkPhysicalDevice physical_device,
@@ -457,13 +522,33 @@ wsi_display_get_physical_device_display_plane_properties(
wsi_for_each_connector(connector, wsi) {
vk_outarray_append(&conn, prop) {
- if (connector && connector->active) {
- prop->currentDisplay = wsi_display_connector_to_handle(connector);
- prop->currentStackIndex = 0;
- } else {
- prop->currentDisplay = VK_NULL_HANDLE;
- prop->currentStackIndex = 0;
- }
+ VkDisplayPlaneProperties2KHR prop2 = {
+ .sType = VK_STRUCTURE_TYPE_DISPLAY_PLANE_PROPERTIES_2_KHR,
+ };
+ wsi_display_fill_in_display_plane_properties(wsi_device, connector,
+ &prop2);
+ *prop = prop2.displayPlaneProperties;
+ }
+ }
+ return vk_outarray_status(&conn);
+}
+
+VkResult
+wsi_display_get_physical_device_display_plane_properties2(
+ VkPhysicalDevice physical_device,
+ struct wsi_device *wsi_device,
+ uint32_t *property_count,
+ VkDisplayPlaneProperties2KHR *properties)
+{
+ struct wsi_display *wsi =
+ (struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLATFORM_DISPLAY];
+
+ VK_OUTARRAY_MAKE(conn, properties, property_count);
+
+ wsi_for_each_connector(connector, wsi) {
+ vk_outarray_append(&conn, prop) {
+ wsi_display_fill_in_display_plane_properties(wsi_device, connector,
+ prop);
}
}
return vk_outarray_status(&conn);
@@ -503,6 +588,22 @@ wsi_display_get_display_plane_supported_displays(
* Implement vkGetDisplayModePropertiesKHR (VK_KHR_display)
*/
+static void
+wsi_display_fill_in_display_mode_properties(
+ struct wsi_device *wsi_device,
+ struct wsi_display_mode *display_mode,
+ VkDisplayModeProperties2KHR *properties)
+{
+ assert(properties->sType = VK_STRUCTURE_TYPE_DISPLAY_MODE_PROPERTIES_2_KHR);
+ VkDisplayModePropertiesKHR *prop = &properties->displayModeProperties;
+
+ prop->displayMode = wsi_display_mode_to_handle(display_mode);
+ prop->parameters.visibleRegion.width = display_mode->hdisplay;
+ prop->parameters.visibleRegion.height = display_mode->vdisplay;
+ prop->parameters.refreshRate =
+ (uint32_t) (wsi_display_mode_refresh(display_mode) * 1000 + 0.5);
+}
+
VkResult
wsi_display_get_display_mode_properties(VkPhysicalDevice physical_device,
struct wsi_device *wsi_device,
@@ -516,14 +617,40 @@ wsi_display_get_display_mode_properties(VkPhysicalDevice physical_device,
VK_OUTARRAY_MAKE(conn, properties, property_count);
wsi_for_each_display_mode(display_mode, connector) {
- if (display_mode->valid) {
- vk_outarray_append(&conn, prop) {
- prop->displayMode = wsi_display_mode_to_handle(display_mode);
- prop->parameters.visibleRegion.width = display_mode->hdisplay;
- prop->parameters.visibleRegion.height = display_mode->vdisplay;
- prop->parameters.refreshRate =
- (uint32_t) (wsi_display_mode_refresh(display_mode) * 1000 + 0.5);
- }
+ if (!display_mode->valid)
+ continue;
+
+ vk_outarray_append(&conn, prop) {
+ VkDisplayModeProperties2KHR prop2 = {
+ .sType = VK_STRUCTURE_TYPE_DISPLAY_MODE_PROPERTIES_2_KHR,
+ };
+ wsi_display_fill_in_display_mode_properties(wsi_device,
+ display_mode, &prop2);
+ *prop = prop2.displayModeProperties;
+ }
+ }
+ return vk_outarray_status(&conn);
+}
+
+VkResult
+wsi_display_get_display_mode_properties2(VkPhysicalDevice physical_device,
+ struct wsi_device *wsi_device,
+ VkDisplayKHR display,
+ uint32_t *property_count,
+ VkDisplayModeProperties2KHR *properties)
+{
+ struct wsi_display_connector *connector =
+ wsi_display_connector_from_handle(display);
+
+ VK_OUTARRAY_MAKE(conn, properties, property_count);
+
+ wsi_for_each_display_mode(display_mode, connector) {
+ if (!display_mode->valid)
+ continue;
+
+ vk_outarray_append(&conn, prop) {
+ wsi_display_fill_in_display_mode_properties(wsi_device,
+ display_mode, prop);
}
}
return vk_outarray_status(&conn);
@@ -604,6 +731,22 @@ wsi_get_display_plane_capabilities(VkPhysicalDevice physical_device,
return VK_SUCCESS;
}
+VkResult
+wsi_get_display_plane_capabilities2(
+ VkPhysicalDevice physical_device,
+ struct wsi_device *wsi_device,
+ const VkDisplayPlaneInfo2KHR *pDisplayPlaneInfo,
+ VkDisplayPlaneCapabilities2KHR *capabilities)
+{
+ assert(capabilities->sType =
+ VK_STRUCTURE_TYPE_DISPLAY_PLANE_CAPABILITIES_2_KHR);
+
+ return wsi_get_display_plane_capabilities(physical_device, wsi_device,
+ pDisplayPlaneInfo->mode,
+ pDisplayPlaneInfo->planeIndex,
+ &capabilities->capabilities);
+}
+
VkResult
wsi_create_display_surface(VkInstance instance,
const VkAllocationCallbacks *allocator,
diff --git a/src/vulkan/wsi/wsi_common_display.h b/src/vulkan/wsi/wsi_common_display.h
index eaa0ba727b0..e4df4b1dc9f 100644
--- a/src/vulkan/wsi/wsi_common_display.h
+++ b/src/vulkan/wsi/wsi_common_display.h
@@ -39,6 +39,13 @@ wsi_display_get_physical_device_display_properties(
uint32_t *property_count,
VkDisplayPropertiesKHR *properties);
+VkResult
+wsi_display_get_physical_device_display_properties2(
+ VkPhysicalDevice physical_device,
+ struct wsi_device *wsi_device,
+ uint32_t *pPropertyCount,
+ VkDisplayProperties2KHR *pProperties);
+
VkResult
wsi_display_get_physical_device_display_plane_properties(
VkPhysicalDevice physical_device,
@@ -46,6 +53,13 @@ wsi_display_get_physical_device_display_plane_properties(
uint32_t *property_count,
VkDisplayPlanePropertiesKHR *properties);
+VkResult
+wsi_display_get_physical_device_display_plane_properties2(
+ VkPhysicalDevice physical_device,
+ struct wsi_device *wsi_device,
+ uint32_t *property_count,
+ VkDisplayPlaneProperties2KHR *properties);
+
VkResult
wsi_display_get_display_plane_supported_displays(
VkPhysicalDevice physical_device,
@@ -61,6 +75,13 @@ wsi_display_get_display_mode_properties(VkPhysicalDevice physical_device,
uint32_t *property_count,
VkDisplayModePropertiesKHR *properties);
+VkResult
+wsi_display_get_display_mode_properties2(VkPhysicalDevice physical_device,
+ struct wsi_device *wsi_device,
+ VkDisplayKHR display,
+ uint32_t *property_count,
+ VkDisplayModeProperties2KHR *properties);
+
VkResult
wsi_display_create_display_mode(VkPhysicalDevice physical_device,
struct wsi_device *wsi_device,
@@ -76,6 +97,12 @@ wsi_get_display_plane_capabilities(VkPhysicalDevice physical_device,
uint32_t plane_index,
VkDisplayPlaneCapabilitiesKHR *capabilities);
+VkResult
+wsi_get_display_plane_capabilities2(VkPhysicalDevice physical_device,
+ struct wsi_device *wsi_device,
+ const VkDisplayPlaneInfo2KHR *pDisplayPlaneInfo,
+ VkDisplayPlaneCapabilities2KHR *capabilities);
+
VkResult
wsi_create_display_surface(VkInstance instance,
const VkAllocationCallbacks *pAllocator,
--
2.17.1
More information about the mesa-dev
mailing list