diff options
Diffstat (limited to 'src/vulkan')
-rw-r--r-- | src/vulkan/anv_device.c | 4 | ||||
-rw-r--r-- | src/vulkan/anv_private.h | 5 | ||||
-rw-r--r-- | src/vulkan/anv_wsi.c | 54 | ||||
-rw-r--r-- | src/vulkan/anv_wsi.h | 25 | ||||
-rw-r--r-- | src/vulkan/anv_wsi_x11.c | 55 |
5 files changed, 110 insertions, 33 deletions
diff --git a/src/vulkan/anv_device.c b/src/vulkan/anv_device.c index 0df1bbeda3c..c1758de537c 100644 --- a/src/vulkan/anv_device.c +++ b/src/vulkan/anv_device.c @@ -139,6 +139,8 @@ VkResult anv_CreateInstance( VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false)); + anv_init_wsi(instance); + *pInstance = anv_instance_to_handle(instance); return VK_SUCCESS; @@ -149,6 +151,8 @@ VkResult anv_DestroyInstance( { ANV_FROM_HANDLE(anv_instance, instance, _instance); + anv_finish_wsi(instance); + VG(VALGRIND_DESTROY_MEMPOOL(instance)); _mesa_locale_fini(); diff --git a/src/vulkan/anv_private.h b/src/vulkan/anv_private.h index 8be2aa2bee1..0c7d5e8a536 100644 --- a/src/vulkan/anv_private.h +++ b/src/vulkan/anv_private.h @@ -343,8 +343,13 @@ struct anv_instance { 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; diff --git a/src/vulkan/anv_wsi.c b/src/vulkan/anv_wsi.c index 404c905d419..24379337a5e 100644 --- a/src/vulkan/anv_wsi.c +++ b/src/vulkan/anv_wsi.c @@ -24,20 +24,42 @@ #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, uint32_t queueFamilyIndex, 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 @@ -55,13 +77,13 @@ anv_GetSurfaceInfoWSI( 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 @@ -79,14 +101,12 @@ anv_CreateSwapChainWSI( 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); diff --git a/src/vulkan/anv_wsi.h b/src/vulkan/anv_wsi.h index 3a5fba13a56..3ee3fcee56d 100644 --- a/src/vulkan/anv_wsi.h +++ b/src/vulkan/anv_wsi.h @@ -42,10 +42,21 @@ struct anv_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); diff --git a/src/vulkan/anv_wsi_x11.c b/src/vulkan/anv_wsi_x11.c index 54260f56ad9..212c01be0b9 100644 --- a/src/vulkan/anv_wsi_x11.c +++ b/src/vulkan/anv_wsi_x11.c @@ -37,11 +37,22 @@ static const VkSurfacePresentModePropertiesWSI present_modes[] = { { 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); @@ -192,10 +203,11 @@ x11_destroy_swap_chain(struct anv_swap_chain *chain) 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; @@ -335,3 +347,28 @@ anv_x11_create_swap_chain(struct anv_device *device, 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]); +} |