};
static const vk_entry_t entry_points[] = {
- VK_ENTRY_POINT(DestroySurfaceKHR, INSTANCE),
VK_ENTRY_POINT(EnumerateInstanceExtensionProperties, INSTANCE),
VK_ENTRY_POINT(EnumerateDeviceExtensionProperties, INSTANCE),
VK_ENTRY_POINT(GetPhysicalDeviceSurfaceSupportKHR, INSTANCE),
VK_ENTRY_POINT(GetDisplayModePropertiesKHR, INSTANCE),
VK_ENTRY_POINT(CreateDisplayModeKHR, INSTANCE),
VK_ENTRY_POINT(GetDisplayPlaneCapabilitiesKHR, INSTANCE),
- VK_ENTRY_POINT(CreateDisplayPlaneSurfaceKHR, INSTANCE),
VK_ENTRY_POINT(CreateSharedSwapchainsKHR, DEVICE),
- VK_ENTRY_POINT(CreateWaylandSurfaceKHR,INSTANCE),
VK_ENTRY_POINT(GetPhysicalDeviceWaylandPresentationSupportKHR,INSTANCE),
VK_ENTRY_POINT(GetInstanceProcAddr, INSTANCE),
VK_ENTRY_POINT(GetDeviceProcAddr, DEVICE),
#include "wsi.h"
#include <string.h>
-VKAPI_ATTR void VKAPI_CALL
-vk_DestroySurfaceKHR(VkInstance instance,
- VkSurfaceKHR surface,
- const VkAllocationCallbacks *allocator)
-{
- vk_surface_t *sfc = (vk_surface_t *)surface;
-
- if (sfc->tpl.surface)
- tpl_object_unreference((tpl_object_t *)sfc->tpl.surface);
- if (sfc->tpl.display)
- tpl_object_unreference((tpl_object_t *)sfc->tpl.display);
-
- vk_free(&sfc->allocator, sfc);
-}
-
-VKAPI_ATTR VkResult VKAPI_CALL
-vk_CreateWaylandSurfaceKHR(VkInstance instance,
- const VkWaylandSurfaceCreateInfoKHR *info,
- const VkAllocationCallbacks *allocator,
- VkSurfaceKHR *surface)
-{
- vk_surface_t *sfc;
-
- allocator = vk_get_allocator(instance, allocator);
-
- sfc = vk_alloc(allocator, sizeof(vk_surface_t), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
- VK_CHECK(sfc, return VK_ERROR_OUT_OF_HOST_MEMORY, "vk_alloc() failed.\n");
-
- memset(sfc, 0x00, sizeof(vk_surface_t));
-
- sfc->allocator = *allocator;
- sfc->platform.base.platform = VK_ICD_WSI_PLATFORM_WAYLAND;
- sfc->platform.wayland.display = info->display;
- sfc->platform.wayland.surface = info->surface;
-
- sfc->tpl.display = tpl_display_create(TPL_BACKEND_WAYLAND_VULKAN_WSI, info->display);
- VK_CHECK(sfc->tpl.display, goto error, "tpl_display_create() failed.\n");
-
- sfc->tpl.surface = tpl_surface_create(sfc->tpl.display, info->surface, TPL_SURFACE_TYPE_WINDOW,
- TBM_FORMAT_ARGB8888);
- VK_CHECK(sfc->tpl.surface, goto error, "tpl_surface_create() failed.\n");
-
- *surface = (VkSurfaceKHR)sfc;
- return VK_SUCCESS;
-
-error:
- vk_DestroySurfaceKHR(instance, (VkSurfaceKHR)sfc, allocator);
- return VK_ERROR_INITIALIZATION_FAILED;
-}
-
VKAPI_ATTR VkBool32 VKAPI_CALL
vk_GetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice pdev,
uint32_t queue_family_index,
}
VKAPI_ATTR VkResult VKAPI_CALL
-vk_CreateDisplayPlaneSurfaceKHR(VkInstance instance,
- const VkDisplaySurfaceCreateInfoKHR *info,
- const VkAllocationCallbacks *allocator,
- VkSurfaceKHR *surface)
-{
- vk_surface_t *sfc;
-
- allocator = vk_get_allocator(instance, allocator);
-
- sfc = vk_alloc(allocator, sizeof(vk_surface_t), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
- VK_CHECK(sfc, return VK_ERROR_OUT_OF_HOST_MEMORY, "vk_alloc() failed.\n");
-
- sfc->allocator = *allocator;
- sfc->platform.base.platform = VK_ICD_WSI_PLATFORM_DISPLAY;
- sfc->platform.display.displayMode = info->displayMode;
- sfc->platform.display.planeIndex = info->planeIndex;
- sfc->platform.display.planeStackIndex = info->planeStackIndex;
- sfc->platform.display.transform = info->transform;
- sfc->platform.display.globalAlpha = info->globalAlpha;
- sfc->platform.display.alphaMode = info->alphaMode;
- sfc->platform.display.imageExtent = info->imageExtent;
-
- *surface = (VkSurfaceKHR)sfc;
-
- /* TODO: */
-
- return VK_SUCCESS;
-}
-
-VKAPI_ATTR VkResult VKAPI_CALL
vk_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice pdev,
uint32_t queue_family_index,
VkSurfaceKHR surface,
VkSurfaceKHR surface,
VkSurfaceCapabilitiesKHR *caps)
{
- int min, max;
- tpl_result_t res;
- vk_surface_t *sfc = (vk_surface_t *)surface;
+ VkIcdSurfaceWayland *sfc = (VkIcdSurfaceWayland *)surface;
+ tpl_display_t *display;
+ VK_CHECK(sfc->base.platform == VK_ICD_WSI_PLATFORM_WAYLAND, return VK_ERROR_DEVICE_LOST,
+ "Not supported platform surface.\n");
+
+ display = tpl_display_get(sfc->display);
+ VK_CHECK(display, return VK_ERROR_DEVICE_LOST, "tpl_display_get() failed.\n");
+
+#if 0
res = tpl_surface_query_supported_buffer_count(sfc->tpl.surface, &min, &max);
VK_CHECK(res == TPL_ERROR_NONE, return VK_ERROR_DEVICE_LOST,
"tpl_surface_query_supported_buffer_count() failed.\n");
+#endif
+
+ /* TODO: Hard-coded. */
+ caps->minImageCount = 3;
+ caps->maxImageCount = 3;
- caps->minImageCount = min;
- caps->maxImageCount = max;
caps->currentExtent.width = -1;
caps->currentExtent.height = -1;
+
caps->minImageExtent.width = 1;
caps->minImageExtent.height = 1;
+
caps->maxImageExtent.width = INT16_MAX;
caps->maxImageExtent.height = INT16_MAX;
+
caps->maxImageArrayLayers = 1;
+
caps->supportedTransforms = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
caps->currentTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
caps->supportedCompositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR |
VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR;
+
caps->supportedUsageFlags = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT |
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
+ if (display)
+ tpl_object_unreference((tpl_object_t *)display);
+
return VK_SUCCESS;
}
const VkAllocationCallbacks *allocator,
VkSwapchainKHR *swapchain)
{
- vk_swapchain_t *chain;
- vk_surface_t *sfc = (vk_surface_t *)info->surface;
- tbm_format format;
- tpl_result_t res;
+ vk_swapchain_t *chain;
+ tbm_format format;
+ tpl_result_t res;
+ VkIcdSurfaceWayland *surface = (VkIcdSurfaceWayland *)info->surface;
+
+ VK_ASSERT(surface->base.platform == VK_ICD_WSI_PLATFORM_WAYLAND);
switch (info->imageFormat) {
case VK_FORMAT_R8G8B8_SRGB:
format = TBM_FORMAT_ARGB8888;
break;
default:
- format = TBM_FORMAT_ARGB8888;
+ return VK_ERROR_SURFACE_LOST_KHR;
}
allocator = vk_get_allocator(device, allocator);
memset(chain, 0x00, sizeof(vk_swapchain_t));
- res = tpl_surface_create_swapchain(sfc->tpl.surface, format, info->imageExtent.width,
- info->imageExtent.height, info->minImageCount);
- VK_CHECK(res == TPL_ERROR_NONE, goto error, "tpl_surface_create_swapchain() failed.\n");
-
chain->allocator = *allocator;
- chain->surface = sfc;
+ chain->surface = info->surface;
+
+ /* Don't check NULL for display and window. There might be default ones for some systems. */
+
+ chain->tpl_display = tpl_display_get(surface->display);
+ VK_CHECK(chain->tpl_display, goto error, "tpl_display_get() failed.\n");
+
+ chain->tpl_surface = tpl_surface_create(chain->tpl_display, surface->surface,
+ TPL_SURFACE_TYPE_WINDOW, format);
+ VK_CHECK(chain->tpl_surface, goto error, "tpl_surface_create() failed.\n");
+
+ res = tpl_surface_create_swapchain(chain->tpl_surface, format,
+ info->imageExtent.width, info->imageExtent.height,
+ info->minImageCount);
+ VK_CHECK(res == TPL_ERROR_NONE, goto error, "tpl_surface_create_swapchain() failed.\n");
*swapchain = (VkSwapchainKHR)chain;
return VK_SUCCESS;
error:
+ if (chain->tpl_display)
+ tpl_object_unreference((tpl_object_t *)chain->tpl_display);
+
+ if (chain->tpl_surface)
+ tpl_object_unreference((tpl_object_t *)chain->tpl_surface);
+
vk_free(allocator, chain);
return VK_ERROR_DEVICE_LOST;
}
{
vk_swapchain_t *chain = (vk_swapchain_t *)swapchain;
- tpl_surface_destroy_swapchain(chain->surface->tpl.surface);
+ tpl_surface_destroy_swapchain(chain->tpl_surface);
free(chain->buffers);
+ if (chain->tpl_display)
+ tpl_object_unreference((tpl_object_t *)chain->tpl_display);
+
+ if (chain->tpl_surface)
+ tpl_object_unreference((tpl_object_t *)chain->tpl_surface);
+
vk_free(&chain->allocator, chain);
}
tpl_result_t res;
int buffer_count;
- res = tpl_surface_get_swapchain_buffers(chain->surface->tpl.surface,
- &chain->buffers, &buffer_count);
+ res = tpl_surface_get_swapchain_buffers(chain->tpl_surface, &chain->buffers, &buffer_count);
VK_CHECK(res == TPL_ERROR_NONE, return VK_ERROR_SURFACE_LOST_KHR,
"tpl_surface_get_swapchain_buffers() failed\n.");
chain->buffer_count = buffer_count;
tbm_surface_h next;
vk_swapchain_t *chain = (vk_swapchain_t *)swapchain;
- next = tpl_surface_dequeue_buffer(chain->surface->tpl.surface);
+ next = tpl_surface_dequeue_buffer(chain->tpl_surface);
VK_CHECK(next, return VK_ERROR_SURFACE_LOST_KHR, "tpl_surface_dequeue_buffers() failed\n.");
for (i = 0; i < chain->buffer_count; i++) {
tpl_result_t res;
vk_swapchain_t *chain = (vk_swapchain_t *)info->pSwapchains[i];
- res = tpl_surface_enqueue_buffer(chain->surface->tpl.surface,
+ res = tpl_surface_enqueue_buffer(chain->tpl_surface,
chain->buffers[info->pImageIndices[i]]);
if (info->pResults != NULL)
typedef struct vk_surface vk_surface_t;
typedef struct vk_swapchain vk_swapchain_t;
-struct vk_surface {
- union {
- VkIcdSurfaceBase base;
- VkIcdSurfaceDisplay display;
- VkIcdSurfaceWayland wayland;
- } platform;
-
- VkAllocationCallbacks allocator;
-
- struct {
- tpl_display_t *display;
- tpl_surface_t *surface;
- } tpl;
-};
-
struct vk_swapchain {
- VkAllocationCallbacks allocator;
- vk_surface_t *surface;
+ VkAllocationCallbacks allocator;
+ VkSurfaceKHR surface;
+
+ tpl_display_t *tpl_display;
+ tpl_surface_t *tpl_surface;
- tbm_surface_h *buffers;
- uint32_t buffer_count;
+ uint32_t buffer_count;
+ tbm_surface_h *buffers;
};
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_free(const VkAllocationCallbacks *allocator, void *mem);
/* Entry point proto types. */
-VKAPI_ATTR void VKAPI_CALL
-vk_DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
- const VkAllocationCallbacks *allocator);
-
VKAPI_ATTR VkResult VKAPI_CALL
vk_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice pdev, uint32_t queue_family_index,
VkSurfaceKHR surface, VkBool32 *supported);
uint32_t plane_index, VkDisplayPlaneCapabilitiesKHR *caps);
VKAPI_ATTR VkResult VKAPI_CALL
-vk_CreateDisplayPlaneSurfaceKHR(VkInstance instance, const VkDisplaySurfaceCreateInfoKHR *info,
- const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface);
-
-VKAPI_ATTR VkResult VKAPI_CALL
vk_CreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchain_count,
const VkSwapchainCreateInfoKHR *infos,
const VkAllocationCallbacks *allocator, VkSwapchainKHR *swapchains);
-VKAPI_ATTR VkResult VKAPI_CALL
-vk_CreateWaylandSurfaceKHR(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *info,
- const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface);
-
VKAPI_ATTR VkBool32 VKAPI_CALL
vk_GetPhysicalDeviceWaylandPresentationSupportKHR(VkPhysicalDevice pdev,
uint32_t queue_family_index,