Home | History | Annotate | Download | only in wsi
      1 /*
      2  * Copyright  2015 Intel Corporation
      3  *
      4  * Permission is hereby granted, free of charge, to any person obtaining a
      5  * copy of this software and associated documentation files (the "Software"),
      6  * to deal in the Software without restriction, including without limitation
      7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8  * and/or sell copies of the Software, and to permit persons to whom the
      9  * Software is furnished to do so, subject to the following conditions:
     10  *
     11  * The above copyright notice and this permission notice (including the next
     12  * paragraph) shall be included in all copies or substantial portions of the
     13  * Software.
     14  *
     15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     21  * IN THE SOFTWARE.
     22  */
     23 #ifndef WSI_COMMON_H
     24 #define WSI_COMMON_H
     25 
     26 #include <stdint.h>
     27 #include <stdbool.h>
     28 
     29 #include "vk_alloc.h"
     30 #include <vulkan/vulkan.h>
     31 #include <vulkan/vk_icd.h>
     32 
     33 /* This is guaranteed to not collide with anything because it's in the
     34  * VK_KHR_swapchain namespace but not actually used by the extension.
     35  */
     36 #define VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA (VkStructureType)1000001002
     37 #define VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA (VkStructureType)1000001003
     38 
     39 struct wsi_image_create_info {
     40     VkStructureType sType;
     41     const void *pNext;
     42     bool scanout;
     43 };
     44 
     45 struct wsi_memory_allocate_info {
     46     VkStructureType sType;
     47     const void *pNext;
     48     bool implicit_sync;
     49 };
     50 
     51 struct wsi_interface;
     52 
     53 #define VK_ICD_WSI_PLATFORM_MAX 5
     54 
     55 struct wsi_device {
     56    VkPhysicalDeviceMemoryProperties memory_props;
     57    uint32_t queue_family_count;
     58 
     59 #define WSI_CB(cb) PFN_vk##cb cb
     60    WSI_CB(AllocateMemory);
     61    WSI_CB(AllocateCommandBuffers);
     62    WSI_CB(BindBufferMemory);
     63    WSI_CB(BindImageMemory);
     64    WSI_CB(BeginCommandBuffer);
     65    WSI_CB(CmdCopyImageToBuffer);
     66    WSI_CB(CreateBuffer);
     67    WSI_CB(CreateCommandPool);
     68    WSI_CB(CreateFence);
     69    WSI_CB(CreateImage);
     70    WSI_CB(DestroyBuffer);
     71    WSI_CB(DestroyCommandPool);
     72    WSI_CB(DestroyFence);
     73    WSI_CB(DestroyImage);
     74    WSI_CB(EndCommandBuffer);
     75    WSI_CB(FreeMemory);
     76    WSI_CB(FreeCommandBuffers);
     77    WSI_CB(GetBufferMemoryRequirements);
     78    WSI_CB(GetImageMemoryRequirements);
     79    WSI_CB(GetImageSubresourceLayout);
     80    WSI_CB(GetMemoryFdKHR);
     81    WSI_CB(GetPhysicalDeviceFormatProperties);
     82    WSI_CB(ResetFences);
     83    WSI_CB(QueueSubmit);
     84    WSI_CB(WaitForFences);
     85 #undef WSI_CB
     86 
     87     struct wsi_interface *                  wsi[VK_ICD_WSI_PLATFORM_MAX];
     88 };
     89 
     90 typedef PFN_vkVoidFunction (VKAPI_PTR *WSI_FN_GetPhysicalDeviceProcAddr)(VkPhysicalDevice physicalDevice, const char* pName);
     91 
     92 VkResult
     93 wsi_device_init(struct wsi_device *wsi,
     94                 VkPhysicalDevice pdevice,
     95                 WSI_FN_GetPhysicalDeviceProcAddr proc_addr,
     96                 const VkAllocationCallbacks *alloc);
     97 
     98 void
     99 wsi_device_finish(struct wsi_device *wsi,
    100                   const VkAllocationCallbacks *alloc);
    101 
    102 #define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType)             \
    103                                                                            \
    104    static inline __VkIcdType *                                             \
    105    __VkIcdType ## _from_handle(__VkType _handle)                           \
    106    {                                                                       \
    107       return (__VkIcdType *)(uintptr_t) _handle;                           \
    108    }                                                                       \
    109                                                                            \
    110    static inline __VkType                                                  \
    111    __VkIcdType ## _to_handle(__VkIcdType *_obj)                            \
    112    {                                                                       \
    113       return (__VkType)(uintptr_t) _obj;                                   \
    114    }
    115 
    116 #define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
    117    __VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
    118 
    119 ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase, VkSurfaceKHR)
    120 
    121 VkResult
    122 wsi_common_get_surface_support(struct wsi_device *wsi_device,
    123                                int local_fd,
    124                                uint32_t queueFamilyIndex,
    125                                VkSurfaceKHR surface,
    126                                const VkAllocationCallbacks *alloc,
    127                                VkBool32* pSupported);
    128 
    129 VkResult
    130 wsi_common_get_surface_capabilities(struct wsi_device *wsi_device,
    131                                     VkSurfaceKHR surface,
    132                                     VkSurfaceCapabilitiesKHR *pSurfaceCapabilities);
    133 
    134 VkResult
    135 wsi_common_get_surface_capabilities2(struct wsi_device *wsi_device,
    136                                      const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
    137                                      VkSurfaceCapabilities2KHR *pSurfaceCapabilities);
    138 
    139 VkResult
    140 wsi_common_get_surface_formats(struct wsi_device *wsi_device,
    141                                VkSurfaceKHR surface,
    142                                uint32_t *pSurfaceFormatCount,
    143                                VkSurfaceFormatKHR *pSurfaceFormats);
    144 
    145 VkResult
    146 wsi_common_get_surface_formats2(struct wsi_device *wsi_device,
    147                                 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
    148                                 uint32_t *pSurfaceFormatCount,
    149                                 VkSurfaceFormat2KHR *pSurfaceFormats);
    150 
    151 VkResult
    152 wsi_common_get_surface_present_modes(struct wsi_device *wsi_device,
    153                                      VkSurfaceKHR surface,
    154                                      uint32_t *pPresentModeCount,
    155                                      VkPresentModeKHR *pPresentModes);
    156 
    157 VkResult
    158 wsi_common_get_images(VkSwapchainKHR _swapchain,
    159                       uint32_t *pSwapchainImageCount,
    160                       VkImage *pSwapchainImages);
    161 
    162 VkResult
    163 wsi_common_acquire_next_image(const struct wsi_device *wsi,
    164                               VkDevice device,
    165                               VkSwapchainKHR swapchain,
    166                               uint64_t timeout,
    167                               VkSemaphore semaphore,
    168                               uint32_t *pImageIndex);
    169 
    170 VkResult
    171 wsi_common_create_swapchain(struct wsi_device *wsi,
    172                             VkDevice device,
    173                             int fd,
    174                             const VkSwapchainCreateInfoKHR *pCreateInfo,
    175                             const VkAllocationCallbacks *pAllocator,
    176                             VkSwapchainKHR *pSwapchain);
    177 void
    178 wsi_common_destroy_swapchain(VkDevice device,
    179                              VkSwapchainKHR swapchain,
    180                              const VkAllocationCallbacks *pAllocator);
    181 
    182 VkResult
    183 wsi_common_queue_present(const struct wsi_device *wsi,
    184                          VkDevice device_h,
    185                          VkQueue queue_h,
    186                          int queue_family_index,
    187                          const VkPresentInfoKHR *pPresentInfo);
    188 
    189 #endif
    190