mesa/src/vulkan/wsi/wsi_common_private.h

306 lines
12 KiB
C
Raw Permalink Normal View History

/*
* Copyright © 2017 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef WSI_COMMON_PRIVATE_H
#define WSI_COMMON_PRIVATE_H
#include "wsi_common.h"
#include "vulkan/runtime/vk_object.h"
#include "vulkan/runtime/vk_sync.h"
struct wsi_image;
struct wsi_swapchain;
#define WSI_DEBUG_BUFFER (1ull << 0)
#define WSI_DEBUG_SW (1ull << 1)
#define WSI_DEBUG_NOSHM (1ull << 2)
#define WSI_DEBUG_LINEAR (1ull << 3)
extern uint64_t WSI_DEBUG;
struct wsi_image_info {
VkImageCreateInfo create;
struct wsi_image_create_info wsi;
VkExternalMemoryImageCreateInfo ext_mem;
VkImageFormatListCreateInfo format_list;
VkImageDrmFormatModifierListCreateInfoEXT drm_mod_list;
bool prime_use_linear_modifier;
/* Not really part of VkImageCreateInfo but needed to figure out the
* number of planes we need to bind.
*/
uint32_t modifier_prop_count;
struct VkDrmFormatModifierPropertiesEXT *modifier_props;
/* For buffer blit images, the linear stride in bytes */
uint32_t linear_stride;
/* For buffer blit images, the size of the buffer in bytes */
uint32_t linear_size;
uint32_t (*select_image_memory_type)(const struct wsi_device *wsi,
uint32_t type_bits);
uint32_t (*select_buffer_memory_type)(const struct wsi_device *wsi,
uint32_t type_bits);
uint8_t *(*alloc_shm)(struct wsi_image *image, unsigned size);
VkResult (*create_mem)(const struct wsi_swapchain *chain,
const struct wsi_image_info *info,
struct wsi_image *image);
VkResult (*finish_create)(const struct wsi_swapchain *chain,
const struct wsi_image_info *info,
struct wsi_image *image);
};
struct wsi_image {
VkImage image;
VkDeviceMemory memory;
struct {
VkBuffer buffer;
VkDeviceMemory memory;
VkCommandBuffer *blit_cmd_buffers;
} buffer;
#ifndef _WIN32
uint64_t drm_modifier;
#endif
int num_planes;
uint32_t sizes[4];
uint32_t offsets[4];
uint32_t row_pitches[4];
#ifndef _WIN32
int dma_buf_fd;
#endif
void *cpu_map;
};
struct wsi_swapchain {
struct vk_object_base base;
const struct wsi_device *wsi;
VkDevice device;
VkAllocationCallbacks alloc;
VkFence* fences;
VkSemaphore* buffer_blit_semaphores;
VkPresentModeKHR present_mode;
int signal_dma_buf_from_semaphore;
VkSemaphore dma_buf_semaphore;
struct wsi_image_info image_info;
uint32_t image_count;
bool use_buffer_blit;
/* If the driver wants to use a special queue to execute the buffer blit,
* it'll implement the wsi_device::get_buffer_blit_queue callback.
* The created queue will be stored here and will be used to execute the
* buffer blit instead of using the present queue.
*/
VkQueue buffer_blit_queue;
/* Command pools, one per queue family */
VkCommandPool *cmd_pools;
VkResult (*destroy)(struct wsi_swapchain *swapchain,
const VkAllocationCallbacks *pAllocator);
struct wsi_image *(*get_wsi_image)(struct wsi_swapchain *swapchain,
uint32_t image_index);
VkResult (*acquire_next_image)(struct wsi_swapchain *swap_chain,
const VkAcquireNextImageInfoKHR *info,
uint32_t *image_index);
VkResult (*queue_present)(struct wsi_swapchain *swap_chain,
uint32_t image_index,
const VkPresentRegionKHR *damage);
};
bool
wsi_device_matches_drm_fd(const struct wsi_device *wsi, int drm_fd);
VkResult
wsi_swapchain_init(const struct wsi_device *wsi,
struct wsi_swapchain *chain,
VkDevice device,
const VkSwapchainCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
bool use_buffer_blit);
enum VkPresentModeKHR
wsi_swapchain_get_present_mode(struct wsi_device *wsi,
const VkSwapchainCreateInfoKHR *pCreateInfo);
void wsi_swapchain_finish(struct wsi_swapchain *chain);
uint32_t
wsi_select_memory_type(const struct wsi_device *wsi,
VkMemoryPropertyFlags req_flags,
VkMemoryPropertyFlags deny_flags,
uint32_t type_bits);
uint32_t
wsi_select_device_memory_type(const struct wsi_device *wsi,
uint32_t type_bits);
VkResult
wsi_configure_native_image(const struct wsi_swapchain *chain,
const VkSwapchainCreateInfoKHR *pCreateInfo,
uint32_t num_modifier_lists,
const uint32_t *num_modifiers,
const uint64_t *const *modifiers,
struct wsi_image_info *info);
VkResult
wsi_configure_prime_image(UNUSED const struct wsi_swapchain *chain,
const VkSwapchainCreateInfoKHR *pCreateInfo,
bool use_modifier,
struct wsi_image_info *info);
VkResult
wsi_configure_cpu_image(const struct wsi_swapchain *chain,
const VkSwapchainCreateInfoKHR *pCreateInfo,
uint8_t *(alloc_shm)(struct wsi_image *image,
unsigned size),
struct wsi_image_info *info);
VkResult
wsi_create_buffer_image_mem(const struct wsi_swapchain *chain,
const struct wsi_image_info *info,
struct wsi_image *image,
VkExternalMemoryHandleTypeFlags handle_types,
bool implicit_sync);
VkResult
wsi_finish_create_buffer_image(const struct wsi_swapchain *chain,
const struct wsi_image_info *info,
struct wsi_image *image);
VkResult
wsi_configure_buffer_image(UNUSED const struct wsi_swapchain *chain,
const VkSwapchainCreateInfoKHR *pCreateInfo,
uint32_t stride_align, uint32_t size_align,
struct wsi_image_info *info);
VkResult
wsi_configure_image(const struct wsi_swapchain *chain,
const VkSwapchainCreateInfoKHR *pCreateInfo,
VkExternalMemoryHandleTypeFlags handle_types,
struct wsi_image_info *info);
void
wsi_destroy_image_info(const struct wsi_swapchain *chain,
struct wsi_image_info *info);
VkResult
wsi_create_image(const struct wsi_swapchain *chain,
const struct wsi_image_info *info,
struct wsi_image *image);
void
wsi_image_init(struct wsi_image *image);
void
wsi_destroy_image(const struct wsi_swapchain *chain,
struct wsi_image *image);
#ifdef HAVE_LIBDRM
VkResult
wsi_prepare_signal_dma_buf_from_semaphore(struct wsi_swapchain *chain,
const struct wsi_image *image);
VkResult
wsi_signal_dma_buf_from_semaphore(const struct wsi_swapchain *chain,
const struct wsi_image *image);
VkResult
wsi_create_sync_for_dma_buf_wait(const struct wsi_swapchain *chain,
const struct wsi_image *image,
enum vk_sync_features sync_features,
struct vk_sync **sync_out);
#endif
struct wsi_interface {
VkResult (*get_support)(VkIcdSurfaceBase *surface,
struct wsi_device *wsi_device,
uint32_t queueFamilyIndex,
VkBool32* pSupported);
VkResult (*get_capabilities2)(VkIcdSurfaceBase *surface,
struct wsi_device *wsi_device,
const void *info_next,
VkSurfaceCapabilities2KHR* pSurfaceCapabilities);
VkResult (*get_formats)(VkIcdSurfaceBase *surface,
struct wsi_device *wsi_device,
uint32_t* pSurfaceFormatCount,
VkSurfaceFormatKHR* pSurfaceFormats);
VkResult (*get_formats2)(VkIcdSurfaceBase *surface,
struct wsi_device *wsi_device,
const void *info_next,
uint32_t* pSurfaceFormatCount,
VkSurfaceFormat2KHR* pSurfaceFormats);
VkResult (*get_present_modes)(VkIcdSurfaceBase *surface,
uint32_t* pPresentModeCount,
VkPresentModeKHR* pPresentModes);
VkResult (*get_present_rectangles)(VkIcdSurfaceBase *surface,
struct wsi_device *wsi_device,
uint32_t* pRectCount,
VkRect2D* pRects);
VkResult (*create_swapchain)(VkIcdSurfaceBase *surface,
VkDevice device,
struct wsi_device *wsi_device,
const VkSwapchainCreateInfoKHR* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
struct wsi_swapchain **swapchain);
};
VkResult wsi_x11_init_wsi(struct wsi_device *wsi_device,
const VkAllocationCallbacks *alloc,
const struct driOptionCache *dri_options);
void wsi_x11_finish_wsi(struct wsi_device *wsi_device,
const VkAllocationCallbacks *alloc);
VkResult wsi_wl_init_wsi(struct wsi_device *wsi_device,
const VkAllocationCallbacks *alloc,
VkPhysicalDevice physical_device);
void wsi_wl_finish_wsi(struct wsi_device *wsi_device,
const VkAllocationCallbacks *alloc);
VkResult wsi_win32_init_wsi(struct wsi_device *wsi_device,
const VkAllocationCallbacks *alloc,
VkPhysicalDevice physical_device);
void wsi_win32_finish_wsi(struct wsi_device *wsi_device,
const VkAllocationCallbacks *alloc);
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@jlekstrand.net> * Simplify addition of VK_USE_PLATFORM_DISPLAY_KHR to vulkan_wsi_args Suggested-by: Eric Engestrom <eric.engestrom@imgtec.com> v3: Add separate 'display_fd' and 'render_fd' arguments to wsi_device_init API. This allows drivers to use different FDs for the different aspects of the device. Use largest mode as display size when no preferred mode. If the display doesn't provide a preferred mode, we'll assume that the largest supported mode is the "physical size" of the device and report that. v4: Make wsi_image_state enumeration values uppercase. Follow more common mesa conventions. Remove 'render_fd' from wsi_device_init API. The wsi_common_display code doesn't use this fd at all, so stop passing it in. This avoids any potential confusion over which fd to use when creating display-relative object handles. Remove call to wsi_create_prime_image which would never have been reached as the necessary condition (use_prime_blit) is never set. whitespace cleanups in wsi_common_display.c Suggested-by: Jason Ekstrand <jason@jlekstrand.net> Add depth/bpp info to available surface formats. Instead of hard-coding depth 24 bpp 32 in the drmModeAddFB call, use the requested format to find suitable values. Destroy kernel buffers and FBs when swapchain is destroyed. We were leaking both of these kernel objects across swapchain destruction. Note that wsi_display_wait_for_event waits for anything to happen. wsi_display_wait_for_event is simply a yield so that the caller can then check to see if the desired state change has occurred. Record swapchain failures in chain for later return. If some asynchronous swapchain activity fails, we need to tell the application eventually. Record the failure in the swapchain and report it at the next acquire_next_image or queue_present call. Fix error returns from wsi_display_setup_connector. If a malloc failed, then the result should be VK_ERROR_OUT_OF_HOST_MEMORY. Otherwise, the associated ioctl failed and we're either VT switched away, or our lease has been revoked, in which case we should return VK_ERROR_OUT_OF_DATE_KHR. Make sure both sides of if/else brace use matches Note that we assume drmModeSetCrtc is synchronous. Add a comment explaining why we can idle any previous displayed image as soon as the mode set returns. Note that EACCES from drmModePageFlip means VT inactive. When vt switched away drmModePageFlip returns EACCES. Poll once a second waiting until we get some other return value back. Clean up after alloc failure in wsi_display_surface_create_swapchain. Destroy any created images, free the swapchain. Remove physical_device from wsi_display_init_wsi. We never need this value, so remove it from the API and from the internal wsi_display structure. Use drmModeAddFB2 in wsi_display_image_init. This takes a drm format instead of depth/bpp, which provides more control over the format of the data. v5: Set the 'currentStackIndex' member of the VkDisplayPlanePropertiesKHR record to zero, instead of indexing across all displays. This value is the stack depth of the plane within an individual display, and as the current code supports only a single plane per display, should be set to zero for all elements Discovered-by: David Mao <David.Mao@amd.com> v6: Remove 'platform_display' bits from the build and use the existing 'platform_drm' instead. v7: Ensure VK_ICD_WSI_PLATFORM_MAX is large enough by setting to VK_ICD_WSI_PLATFORM_DISPLAY + 1 v8: Simplify wsi_device_init failure from wsi_display_init_wsi by using the same pattern as the other wsi layers. Adopt Jason Ekstrand's white space and variable declaration suggestions. Declare variables at first use, eliminate extra whitespace between types and names, add list iterator helpers, switch to lower-case list_ macros. Respond to Jason's April 8 review: * Create a function to convert relative to absolute timeouts to catch overflow issues in one place * use VK_NULL_HANDLE to clear prop->currentDisplay * Get rid of available_present_modes array. * return OUT_OF_DATE_KHR when display_queue_next called after display has been released. * Make errors from mode setting fatal in display_queue_next * Remove duplicate pthread_mutex_init call * Add wsi_init_pthread_cond_monotonic helper function to isolate pthread error handling from wsi_display_init_wsi Suggested-by: Jason Ekstrand <jason.ekstrand@intel.com> v9: Fix vscan handling by using MAX2(vscan, 1) everywhere. Vscan can be zero anywhere, which is treated the same as 1. Suggested-by: Jason Ekstrand <jason.ekstrand@intel.com> v10: Respond to Vulkan CTS failures. 1. Initialize planeReorderPossible in display_properties code 2. Only report connected displays in get_display_plane_supported_displays 3. Return VK_ERROR_OUT_OF_HOST_MEMORY when pthread cond initialization fails. Signed-off-by: Jason Ekstrand <jason.ekstrand@intel.com> 4. 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 <jason.ekstrand@intel.com> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Signed-off-by: Keith Packard <keithp@keithp.com>
2018-02-07 18:31:44 +00:00
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);
void
wsi_display_setup_syncobj_fd(struct wsi_device *wsi_device,
int fd);
VK_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain, base, VkSwapchainKHR,
VK_OBJECT_TYPE_SWAPCHAIN_KHR)
#endif /* WSI_COMMON_PRIVATE_H */