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:
@@ -139,6 +139,8 @@ VkResult anv_CreateInstance(
|
|||||||
|
|
||||||
VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
|
VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
|
||||||
|
|
||||||
|
anv_init_wsi(instance);
|
||||||
|
|
||||||
*pInstance = anv_instance_to_handle(instance);
|
*pInstance = anv_instance_to_handle(instance);
|
||||||
|
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
@@ -149,6 +151,8 @@ VkResult anv_DestroyInstance(
|
|||||||
{
|
{
|
||||||
ANV_FROM_HANDLE(anv_instance, instance, _instance);
|
ANV_FROM_HANDLE(anv_instance, instance, _instance);
|
||||||
|
|
||||||
|
anv_finish_wsi(instance);
|
||||||
|
|
||||||
VG(VALGRIND_DESTROY_MEMPOOL(instance));
|
VG(VALGRIND_DESTROY_MEMPOOL(instance));
|
||||||
|
|
||||||
_mesa_locale_fini();
|
_mesa_locale_fini();
|
||||||
|
@@ -343,8 +343,13 @@ struct anv_instance {
|
|||||||
uint32_t apiVersion;
|
uint32_t apiVersion;
|
||||||
uint32_t physicalDeviceCount;
|
uint32_t physicalDeviceCount;
|
||||||
struct anv_physical_device physicalDevice;
|
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 anv_meta_state {
|
||||||
struct {
|
struct {
|
||||||
VkPipeline pipeline;
|
VkPipeline pipeline;
|
||||||
|
@@ -23,6 +23,19 @@
|
|||||||
|
|
||||||
#include "anv_wsi.h"
|
#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
|
VkResult
|
||||||
anv_GetPhysicalDeviceSurfaceSupportWSI(
|
anv_GetPhysicalDeviceSurfaceSupportWSI(
|
||||||
VkPhysicalDevice physicalDevice,
|
VkPhysicalDevice physicalDevice,
|
||||||
@@ -30,14 +43,23 @@ anv_GetPhysicalDeviceSurfaceSupportWSI(
|
|||||||
const VkSurfaceDescriptionWSI* pSurfaceDescription,
|
const VkSurfaceDescriptionWSI* pSurfaceDescription,
|
||||||
VkBool32* pSupported)
|
VkBool32* pSupported)
|
||||||
{
|
{
|
||||||
|
ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
|
||||||
|
|
||||||
assert(pSurfaceDescription->sType ==
|
assert(pSurfaceDescription->sType ==
|
||||||
VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI);
|
VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI);
|
||||||
|
|
||||||
VkSurfaceDescriptionWindowWSI *window = (void *)pSurfaceDescription;
|
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
|
VkResult
|
||||||
@@ -55,13 +77,13 @@ anv_GetSurfaceInfoWSI(
|
|||||||
VkSurfaceDescriptionWindowWSI *window =
|
VkSurfaceDescriptionWindowWSI *window =
|
||||||
(VkSurfaceDescriptionWindowWSI *)pSurfaceDescription;
|
(VkSurfaceDescriptionWindowWSI *)pSurfaceDescription;
|
||||||
|
|
||||||
switch (window->platform) {
|
struct anv_wsi_implementation *impl =
|
||||||
case VK_PLATFORM_XCB_WSI:
|
device->instance->wsi_impl[window->platform];
|
||||||
return anv_x11_get_surface_info(device, window, infoType,
|
|
||||||
pDataSize, pData);
|
assert(impl);
|
||||||
default:
|
|
||||||
return vk_error(VK_ERROR_INVALID_VALUE);
|
return impl->get_surface_info(impl, device, window, infoType,
|
||||||
}
|
pDataSize, pData);
|
||||||
}
|
}
|
||||||
|
|
||||||
VkResult
|
VkResult
|
||||||
@@ -79,14 +101,12 @@ anv_CreateSwapChainWSI(
|
|||||||
VkSurfaceDescriptionWindowWSI *window =
|
VkSurfaceDescriptionWindowWSI *window =
|
||||||
(VkSurfaceDescriptionWindowWSI *)pCreateInfo->pSurfaceDescription;
|
(VkSurfaceDescriptionWindowWSI *)pCreateInfo->pSurfaceDescription;
|
||||||
|
|
||||||
switch (window->platform) {
|
struct anv_wsi_implementation *impl =
|
||||||
case VK_PLATFORM_XCB_WSI:
|
device->instance->wsi_impl[window->platform];
|
||||||
result = anv_x11_create_swap_chain(device, pCreateInfo,
|
|
||||||
(void *)&swap_chain);
|
assert(impl);
|
||||||
break;
|
|
||||||
default:
|
result = impl->create_swap_chain(impl, device, pCreateInfo, &swap_chain);
|
||||||
return vk_error(VK_ERROR_INVALID_VALUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == VK_SUCCESS)
|
if (result == VK_SUCCESS)
|
||||||
*pSwapChain = anv_swap_chain_to_handle(swap_chain);
|
*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)
|
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_swap_chain, VkSwapChainWSI)
|
||||||
|
|
||||||
VkResult anv_x11_get_surface_info(struct anv_device *device,
|
struct anv_wsi_implementation {
|
||||||
VkSurfaceDescriptionWindowWSI *window,
|
VkResult (*get_window_supported)(struct anv_wsi_implementation *impl,
|
||||||
VkSurfaceInfoTypeWSI infoType,
|
struct anv_physical_device *physical_device,
|
||||||
size_t* pDataSize, void* pData);
|
const VkSurfaceDescriptionWindowWSI *window,
|
||||||
VkResult anv_x11_create_swap_chain(struct anv_device *device,
|
VkBool32 *pSupported);
|
||||||
const VkSwapChainCreateInfoWSI *pCreateInfo,
|
VkResult (*get_surface_info)(struct anv_wsi_implementation *impl,
|
||||||
struct anv_swap_chain **swap_chain);
|
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 },
|
{ VK_PRESENT_MODE_MAILBOX_WSI },
|
||||||
};
|
};
|
||||||
|
|
||||||
VkResult
|
static VkResult
|
||||||
anv_x11_get_surface_info(struct anv_device *device,
|
x11_get_window_supported(struct anv_wsi_implementation *impl,
|
||||||
VkSurfaceDescriptionWindowWSI *window,
|
struct anv_physical_device *physical_device,
|
||||||
VkSurfaceInfoTypeWSI infoType,
|
const VkSurfaceDescriptionWindowWSI *window,
|
||||||
size_t* pDataSize, void* pData)
|
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)
|
if (pDataSize == NULL)
|
||||||
return vk_error(VK_ERROR_INVALID_POINTER);
|
return vk_error(VK_ERROR_INVALID_POINTER);
|
||||||
@@ -192,10 +203,11 @@ x11_destroy_swap_chain(struct anv_swap_chain *chain)
|
|||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkResult
|
static VkResult
|
||||||
anv_x11_create_swap_chain(struct anv_device *device,
|
x11_create_swap_chain(struct anv_wsi_implementation *impl,
|
||||||
const VkSwapChainCreateInfoWSI *pCreateInfo,
|
struct anv_device *device,
|
||||||
struct anv_swap_chain **swap_chain_out)
|
const VkSwapChainCreateInfoWSI *pCreateInfo,
|
||||||
|
struct anv_swap_chain **swap_chain_out)
|
||||||
{
|
{
|
||||||
struct x11_swap_chain *chain;
|
struct x11_swap_chain *chain;
|
||||||
xcb_void_cookie_t cookie;
|
xcb_void_cookie_t cookie;
|
||||||
@@ -335,3 +347,28 @@ anv_x11_create_swap_chain(struct anv_device *device,
|
|||||||
fail:
|
fail:
|
||||||
return result;
|
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]);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user