VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
+ anv_init_wsi(instance);
+
*pInstance = anv_instance_to_handle(instance);
return VK_SUCCESS;
{
ANV_FROM_HANDLE(anv_instance, instance, _instance);
+ anv_finish_wsi(instance);
+
VG(VALGRIND_DESTROY_MEMPOOL(instance));
_mesa_locale_fini();
uint32_t apiVersion;
uint32_t physicalDeviceCount;
struct anv_physical_device physicalDevice;
+
+ struct anv_wsi_implementation * wsi_impl[VK_PLATFORM_NUM_WSI];
};
+VkResult anv_init_wsi(struct anv_instance *instance);
+void anv_finish_wsi(struct anv_instance *instance);
+
struct anv_meta_state {
struct {
VkPipeline pipeline;
#include "anv_wsi.h"
+VkResult
+anv_init_wsi(struct anv_instance *instance)
+{
+ memset(instance->wsi_impl, 0, sizeof(instance->wsi_impl));
+ return anv_x11_init_wsi(instance);
+}
+
+void
+anv_finish_wsi(struct anv_instance *instance)
+{
+ anv_x11_finish_wsi(instance);
+}
+
VkResult
anv_GetPhysicalDeviceSurfaceSupportWSI(
VkPhysicalDevice physicalDevice,
const VkSurfaceDescriptionWSI* pSurfaceDescription,
VkBool32* pSupported)
{
+ ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
+
assert(pSurfaceDescription->sType ==
VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI);
VkSurfaceDescriptionWindowWSI *window = (void *)pSurfaceDescription;
- *pSupported = window->platform == VK_PLATFORM_XCB_WSI;
+ struct anv_wsi_implementation *impl =
+ physical_device->instance->wsi_impl[window->platform];
- return VK_SUCCESS;
+ if (impl) {
+ return impl->get_window_supported(impl, physical_device,
+ window, pSupported);
+ } else {
+ *pSupported = false;
+ return VK_SUCCESS;
+ }
}
VkResult
VkSurfaceDescriptionWindowWSI *window =
(VkSurfaceDescriptionWindowWSI *)pSurfaceDescription;
- switch (window->platform) {
- case VK_PLATFORM_XCB_WSI:
- return anv_x11_get_surface_info(device, window, infoType,
- pDataSize, pData);
- default:
- return vk_error(VK_ERROR_INVALID_VALUE);
- }
+ struct anv_wsi_implementation *impl =
+ device->instance->wsi_impl[window->platform];
+
+ assert(impl);
+
+ return impl->get_surface_info(impl, device, window, infoType,
+ pDataSize, pData);
}
VkResult
VkSurfaceDescriptionWindowWSI *window =
(VkSurfaceDescriptionWindowWSI *)pCreateInfo->pSurfaceDescription;
- switch (window->platform) {
- case VK_PLATFORM_XCB_WSI:
- result = anv_x11_create_swap_chain(device, pCreateInfo,
- (void *)&swap_chain);
- break;
- default:
- return vk_error(VK_ERROR_INVALID_VALUE);
- }
+ struct anv_wsi_implementation *impl =
+ device->instance->wsi_impl[window->platform];
+
+ assert(impl);
+
+ result = impl->create_swap_chain(impl, device, pCreateInfo, &swap_chain);
if (result == VK_SUCCESS)
*pSwapChain = anv_swap_chain_to_handle(swap_chain);
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_swap_chain, VkSwapChainWSI)
-VkResult anv_x11_get_surface_info(struct anv_device *device,
- VkSurfaceDescriptionWindowWSI *window,
- VkSurfaceInfoTypeWSI infoType,
- size_t* pDataSize, void* pData);
-VkResult anv_x11_create_swap_chain(struct anv_device *device,
- const VkSwapChainCreateInfoWSI *pCreateInfo,
- struct anv_swap_chain **swap_chain);
+struct anv_wsi_implementation {
+ VkResult (*get_window_supported)(struct anv_wsi_implementation *impl,
+ struct anv_physical_device *physical_device,
+ const VkSurfaceDescriptionWindowWSI *window,
+ VkBool32 *pSupported);
+ VkResult (*get_surface_info)(struct anv_wsi_implementation *impl,
+ struct anv_device *device,
+ VkSurfaceDescriptionWindowWSI *window,
+ VkSurfaceInfoTypeWSI infoType,
+ size_t* pDataSize, void* pData);
+ VkResult (*create_swap_chain)(struct anv_wsi_implementation *impl,
+ struct anv_device *device,
+ const VkSwapChainCreateInfoWSI *pCreateInfo,
+ struct anv_swap_chain **swap_chain);
+};
+
+VkResult anv_x11_init_wsi(struct anv_instance *instance);
+void anv_x11_finish_wsi(struct anv_instance *instance);
{ VK_PRESENT_MODE_MAILBOX_WSI },
};
-VkResult
-anv_x11_get_surface_info(struct anv_device *device,
- VkSurfaceDescriptionWindowWSI *window,
- VkSurfaceInfoTypeWSI infoType,
- size_t* pDataSize, void* pData)
+static VkResult
+x11_get_window_supported(struct anv_wsi_implementation *impl,
+ struct anv_physical_device *physical_device,
+ const VkSurfaceDescriptionWindowWSI *window,
+ VkBool32 *pSupported)
+{
+ *pSupported = true;
+ stub_return(VK_SUCCESS);
+}
+
+static VkResult
+x11_get_surface_info(struct anv_wsi_implementation *impl,
+ struct anv_device *device,
+ VkSurfaceDescriptionWindowWSI *window,
+ VkSurfaceInfoTypeWSI infoType,
+ size_t* pDataSize, void* pData)
{
if (pDataSize == NULL)
return vk_error(VK_ERROR_INVALID_POINTER);
return VK_SUCCESS;
}
-VkResult
-anv_x11_create_swap_chain(struct anv_device *device,
- const VkSwapChainCreateInfoWSI *pCreateInfo,
- struct anv_swap_chain **swap_chain_out)
+static VkResult
+x11_create_swap_chain(struct anv_wsi_implementation *impl,
+ struct anv_device *device,
+ const VkSwapChainCreateInfoWSI *pCreateInfo,
+ struct anv_swap_chain **swap_chain_out)
{
struct x11_swap_chain *chain;
xcb_void_cookie_t cookie;
fail:
return result;
}
+
+VkResult
+anv_x11_init_wsi(struct anv_instance *instance)
+{
+ struct anv_wsi_implementation *impl;
+
+ impl = anv_instance_alloc(instance, sizeof(*impl), 8,
+ VK_SYSTEM_ALLOC_TYPE_INTERNAL);
+ if (!impl)
+ return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+
+ impl->get_window_supported = x11_get_window_supported;
+ impl->get_surface_info = x11_get_surface_info;
+ impl->create_swap_chain = x11_create_swap_chain;
+
+ instance->wsi_impl[VK_PLATFORM_XCB_WSI] = impl;
+
+ return VK_SUCCESS;
+}
+
+void
+anv_x11_finish_wsi(struct anv_instance *instance)
+{
+ anv_instance_free(instance, instance->wsi_impl[VK_PLATFORM_XCB_WSI]);
+}