[1/7] vulkan: Add VK_EXT_display_surface_counter [v4]
diff mbox

Message ID 20180615025256.10657-2-keithp@keithp.com
State New
Headers show

Commit Message

Keith Packard June 15, 2018, 2:52 a.m. UTC
This extension is required to support EXT_display_control as it offers
a way to query whether the vblank counter is supported.

v2: Thanks to kisak

    Fix spelling of VkSurfaceCapabilities2EXT in wsi_common_wayland.c,
    it was using ext instead of EXT.

    Fix spelling of VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_EXT

v3: Fix wayland WSI, regularize spelling

    Misspelled 'surface' in get_capabilities2ext
    Remove extra _ from get_capabilities_2ext in a couple of places

v4: Adopt Jason Ekstrand's coding conventions

    Declare variables at first use, eliminate extra whitespace
    between types and names. Wrap lines to 80 columns.

    Suggested-by: Jason Ekstrand <jason.ekstrand@intel.com>

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 src/vulkan/wsi/wsi_common.c         | 12 ++++++++++++
 src/vulkan/wsi/wsi_common.h         |  6 ++++++
 src/vulkan/wsi/wsi_common_display.c | 27 +++++++++++++++++++++++++++
 src/vulkan/wsi/wsi_common_private.h |  3 +++
 src/vulkan/wsi/wsi_common_wayland.c | 27 +++++++++++++++++++++++++++
 src/vulkan/wsi/wsi_common_x11.c     | 27 +++++++++++++++++++++++++++
 6 files changed, 102 insertions(+)

Comments

Jason Ekstrand June 16, 2018, 6:22 p.m. UTC | #1
On Thu, Jun 14, 2018 at 7:52 PM, Keith Packard <keithp@keithp.com> wrote:

> This extension is required to support EXT_display_control as it offers
> a way to query whether the vblank counter is supported.
>
> v2: Thanks to kisak
>
>     Fix spelling of VkSurfaceCapabilities2EXT in wsi_common_wayland.c,
>     it was using ext instead of EXT.
>
>     Fix spelling of VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_EXT
>
> v3: Fix wayland WSI, regularize spelling
>
>     Misspelled 'surface' in get_capabilities2ext
>     Remove extra _ from get_capabilities_2ext in a couple of places
>
> v4: Adopt Jason Ekstrand's coding conventions
>
>     Declare variables at first use, eliminate extra whitespace
>     between types and names. Wrap lines to 80 columns.
>
>     Suggested-by: Jason Ekstrand <jason.ekstrand@intel.com>
>
> Signed-off-by: Keith Packard <keithp@keithp.com>
> ---
>  src/vulkan/wsi/wsi_common.c         | 12 ++++++++++++
>  src/vulkan/wsi/wsi_common.h         |  6 ++++++
>  src/vulkan/wsi/wsi_common_display.c | 27 +++++++++++++++++++++++++++
>  src/vulkan/wsi/wsi_common_private.h |  3 +++
>  src/vulkan/wsi/wsi_common_wayland.c | 27 +++++++++++++++++++++++++++
>  src/vulkan/wsi/wsi_common_x11.c     | 27 +++++++++++++++++++++++++++
>  6 files changed, 102 insertions(+)
>
> diff --git a/src/vulkan/wsi/wsi_common_private.h
> b/src/vulkan/wsi/wsi_common_private.h
> index 3d502b9fc9d..b97d2d8ba06 100644
> --- a/src/vulkan/wsi/wsi_common_private.h
> +++ b/src/vulkan/wsi/wsi_common_private.h
> @@ -109,6 +109,9 @@ struct wsi_interface {
>     VkResult (*get_capabilities2)(VkIcdSurfaceBase *surface,
>                                   const void *info_next,
>                                   VkSurfaceCapabilities2KHR*
> pSurfaceCapabilities);
> +   VkResult (*get_capabilities2ext)(VkIcdSurfaceBase *surface,
> +                                    VkSurfaceCapabilities2EXT*
> +                                    pSurfaceCapabilities);
>

I really don't like adding a third get_capabilities hook.  An alternative
way to do this would be to add a pseud-extension which allows you do get he
extra bit of data with a chain-in on vkGetSurfaceCapabilities2KHR.  I sent
two patches which do just that.  If you like them, I'm happy do do the
reabase for you if you'd like.

--Jason
Keith Packard June 16, 2018, 6:55 p.m. UTC | #2
Jason Ekstrand <jason@jlekstrand.net> writes:

> I really don't like adding a third get_capabilities hook.

Yeah, but this new function takes a different struct parameter which has
a different (but not strict superset) of contents from either of the
existing functions. Annoying.

> An alternative way to do this would be to add a pseud-extension which
> allows you do get he extra bit of data with a chain-in on
> vkGetSurfaceCapabilities2KHR.  I sent two patches which do just that.
> If you like them, I'm happy do do the reabase for you if you'd like.

I'll review that when I have some time Monday.

Patch
diff mbox

diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c
index 142c5d8fe58..91d0b72e1ba 100644
--- a/src/vulkan/wsi/wsi_common.c
+++ b/src/vulkan/wsi/wsi_common.c
@@ -710,6 +710,18 @@  wsi_common_get_surface_capabilities2(struct wsi_device *wsi_device,
                                    pSurfaceCapabilities);
 }
 
+VkResult
+wsi_common_get_surface_capabilities2ext(
+   struct wsi_device *wsi_device,
+   VkSurfaceKHR _surface,
+   VkSurfaceCapabilities2EXT *pSurfaceCapabilities)
+{
+   ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
+   struct wsi_interface *iface = wsi_device->wsi[surface->platform];
+
+   return iface->get_capabilities2ext(surface, pSurfaceCapabilities);
+}
+
 VkResult
 wsi_common_get_surface_formats(struct wsi_device *wsi_device,
                                VkSurfaceKHR _surface,
diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h
index 61b1de59d7f..054aad23c1c 100644
--- a/src/vulkan/wsi/wsi_common.h
+++ b/src/vulkan/wsi/wsi_common.h
@@ -178,6 +178,12 @@  wsi_common_get_surface_present_modes(struct wsi_device *wsi_device,
                                      uint32_t *pPresentModeCount,
                                      VkPresentModeKHR *pPresentModes);
 
+VkResult
+wsi_common_get_surface_capabilities2ext(
+   struct wsi_device *wsi_device,
+   VkSurfaceKHR surface,
+   VkSurfaceCapabilities2EXT *pSurfaceCapabilities);
+
 VkResult
 wsi_common_get_images(VkSwapchainKHR _swapchain,
                       uint32_t *pSwapchainImageCount,
diff --git a/src/vulkan/wsi/wsi_common_display.c b/src/vulkan/wsi/wsi_common_display.c
index e140e71c518..504f7741d73 100644
--- a/src/vulkan/wsi/wsi_common_display.c
+++ b/src/vulkan/wsi/wsi_common_display.c
@@ -641,6 +641,32 @@  wsi_display_surface_get_capabilities2(VkIcdSurfaceBase *icd_surface,
                                                &caps->surfaceCapabilities);
 }
 
+static VkResult
+wsi_display_surface_get_capabilities2ext(VkIcdSurfaceBase *icd_surface,
+                                          VkSurfaceCapabilities2EXT *caps)
+{
+   VkSurfaceCapabilitiesKHR     khr_caps;
+   VkResult                     ret;
+
+   assert(caps->sType == VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_EXT);
+   ret = wsi_display_surface_get_capabilities(icd_surface, &khr_caps);
+   if (ret)
+      return ret;
+
+   caps->minImageCount = khr_caps.minImageCount;
+   caps->maxImageCount = khr_caps.maxImageCount;
+   caps->currentExtent = khr_caps.currentExtent;
+   caps->minImageExtent = khr_caps.minImageExtent;
+   caps->maxImageExtent = khr_caps.maxImageExtent;
+   caps->maxImageArrayLayers = khr_caps.maxImageArrayLayers;
+   caps->supportedTransforms = khr_caps.supportedTransforms;
+   caps->currentTransform = khr_caps.currentTransform;
+   caps->supportedCompositeAlpha = khr_caps.supportedCompositeAlpha;
+   caps->supportedUsageFlags = khr_caps.supportedUsageFlags;
+   caps->supportedSurfaceCounters = 0;
+   return ret;
+}
+
 static const struct {
    VkFormat     format;
    uint32_t     drm_format;
@@ -1393,6 +1419,7 @@  wsi_display_init_wsi(struct wsi_device *wsi_device,
    wsi->base.get_support = wsi_display_surface_get_support;
    wsi->base.get_capabilities = wsi_display_surface_get_capabilities;
    wsi->base.get_capabilities2 = wsi_display_surface_get_capabilities2;
+   wsi->base.get_capabilities2ext = wsi_display_surface_get_capabilities2ext;
    wsi->base.get_formats = wsi_display_surface_get_formats;
    wsi->base.get_formats2 = wsi_display_surface_get_formats2;
    wsi->base.get_present_modes = wsi_display_surface_get_present_modes;
diff --git a/src/vulkan/wsi/wsi_common_private.h b/src/vulkan/wsi/wsi_common_private.h
index 3d502b9fc9d..b97d2d8ba06 100644
--- a/src/vulkan/wsi/wsi_common_private.h
+++ b/src/vulkan/wsi/wsi_common_private.h
@@ -109,6 +109,9 @@  struct wsi_interface {
    VkResult (*get_capabilities2)(VkIcdSurfaceBase *surface,
                                  const void *info_next,
                                  VkSurfaceCapabilities2KHR* pSurfaceCapabilities);
+   VkResult (*get_capabilities2ext)(VkIcdSurfaceBase *surface,
+                                    VkSurfaceCapabilities2EXT*
+                                    pSurfaceCapabilities);
    VkResult (*get_formats)(VkIcdSurfaceBase *surface,
                            struct wsi_device *wsi_device,
                            uint32_t* pSurfaceFormatCount,
diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c
index ec38a4e578f..908d8676e2a 100644
--- a/src/vulkan/wsi/wsi_common_wayland.c
+++ b/src/vulkan/wsi/wsi_common_wayland.c
@@ -524,6 +524,32 @@  wsi_wl_surface_get_capabilities2(VkIcdSurfaceBase *surface,
    return wsi_wl_surface_get_capabilities(surface, &caps->surfaceCapabilities);
 }
 
+static VkResult
+wsi_wl_surface_get_capabilities2ext(VkIcdSurfaceBase *surface,
+                                    VkSurfaceCapabilities2EXT* caps)
+{
+   VkSurfaceCapabilitiesKHR     khr_caps;
+   VkResult                     ret;
+
+   assert(caps->sType == VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_EXT);
+   ret = wsi_wl_surface_get_capabilities(surface, &khr_caps);
+   if (ret)
+      return ret;
+
+   caps->minImageCount = khr_caps.minImageCount;
+   caps->maxImageCount = khr_caps.maxImageCount;
+   caps->currentExtent = khr_caps.currentExtent;
+   caps->minImageExtent = khr_caps.minImageExtent;
+   caps->maxImageExtent = khr_caps.maxImageExtent;
+   caps->maxImageArrayLayers = khr_caps.maxImageArrayLayers;
+   caps->supportedTransforms = khr_caps.supportedTransforms;
+   caps->currentTransform = khr_caps.currentTransform;
+   caps->supportedCompositeAlpha = khr_caps.supportedCompositeAlpha;
+   caps->supportedUsageFlags = khr_caps.supportedUsageFlags;
+   caps->supportedSurfaceCounters = 0;
+   return ret;
+}
+
 static VkResult
 wsi_wl_surface_get_formats(VkIcdSurfaceBase *icd_surface,
 			   struct wsi_device *wsi_device,
@@ -1012,6 +1038,7 @@  wsi_wl_init_wsi(struct wsi_device *wsi_device,
    wsi->base.get_support = wsi_wl_surface_get_support;
    wsi->base.get_capabilities = wsi_wl_surface_get_capabilities;
    wsi->base.get_capabilities2 = wsi_wl_surface_get_capabilities2;
+   wsi->base.get_capabilities2ext = wsi_wl_surface_get_capabilities2ext;
    wsi->base.get_formats = wsi_wl_surface_get_formats;
    wsi->base.get_formats2 = wsi_wl_surface_get_formats2;
    wsi->base.get_present_modes = wsi_wl_surface_get_present_modes;
diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c
index 20d7cf5a2c8..129e30913c3 100644
--- a/src/vulkan/wsi/wsi_common_x11.c
+++ b/src/vulkan/wsi/wsi_common_x11.c
@@ -547,6 +547,32 @@  x11_surface_get_capabilities2(VkIcdSurfaceBase *icd_surface,
    return x11_surface_get_capabilities(icd_surface, &caps->surfaceCapabilities);
 }
 
+static VkResult
+x11_surface_get_capabilities2ext(VkIcdSurfaceBase *icd_surface,
+                                 VkSurfaceCapabilities2EXT *caps)
+{
+   VkSurfaceCapabilitiesKHR     khr_caps;
+   VkResult                     ret;
+
+   assert(caps->sType == VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_EXT);
+   ret = x11_surface_get_capabilities(icd_surface, &khr_caps);
+   if (ret)
+      return ret;
+
+   caps->minImageCount = khr_caps.minImageCount;
+   caps->maxImageCount = khr_caps.maxImageCount;
+   caps->currentExtent = khr_caps.currentExtent;
+   caps->minImageExtent = khr_caps.minImageExtent;
+   caps->maxImageExtent = khr_caps.maxImageExtent;
+   caps->maxImageArrayLayers = khr_caps.maxImageArrayLayers;
+   caps->supportedTransforms = khr_caps.supportedTransforms;
+   caps->currentTransform = khr_caps.currentTransform;
+   caps->supportedCompositeAlpha = khr_caps.supportedCompositeAlpha;
+   caps->supportedUsageFlags = khr_caps.supportedUsageFlags;
+   caps->supportedSurfaceCounters = 0;
+   return ret;
+}
+
 static VkResult
 x11_surface_get_formats(VkIcdSurfaceBase *surface,
                         struct wsi_device *wsi_device,
@@ -1471,6 +1497,7 @@  wsi_x11_init_wsi(struct wsi_device *wsi_device,
    wsi->base.get_support = x11_surface_get_support;
    wsi->base.get_capabilities = x11_surface_get_capabilities;
    wsi->base.get_capabilities2 = x11_surface_get_capabilities2;
+   wsi->base.get_capabilities2ext = x11_surface_get_capabilities2ext;
    wsi->base.get_formats = x11_surface_get_formats;
    wsi->base.get_formats2 = x11_surface_get_formats2;
    wsi->base.get_present_modes = x11_surface_get_present_modes;