vk/wsi: Move to a clallback system for the entire WSI implementation
We do this for two reasons: First, because it allows us to simplify WSI and compiling in/out support for a particular platform is as simple as calling or not calling the platform-specific init function. Second, the implementation gives us a place for a given chunk of the WSI to stash stuff in the instance.
This commit is contained in:
parent
06d8fd5881
commit
348cb29a20
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -23,6 +23,19 @@
|
|||
|
||||
#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,
|
||||
|
@ -30,14 +43,23 @@ anv_GetPhysicalDeviceSurfaceSupportWSI(
|
|||
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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue