loader: Address Jon Ashburn's review comments.
It took a few commits (squashed down into 1) to get it correct. Includes:
Use loader_heap_{alloc|free}().
Try to deal correctly with initializing the vkCreate*SurfaceKHR()'s.
diff --git a/include/vulkan/vk_layer.h b/include/vulkan/vk_layer.h
index a75f02a..85d141f 100644
--- a/include/vulkan/vk_layer.h
+++ b/include/vulkan/vk_layer.h
@@ -173,6 +173,21 @@
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR GetPhysicalDeviceSurfaceCapabilitiesKHR;
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR;
PFN_vkGetPhysicalDeviceSurfacePresentModesKHR GetPhysicalDeviceSurfacePresentModesKHR;
+#ifdef VK_USE_PLATFORM_MIR_KHR
+ PFN_vkCreateMirSurfaceKHR CreateMirSurfaceKHR;
+#endif
+#ifdef VK_USE_PLATFORM_WAYLAND_KHR
+ PFN_vkCreateWaylandSurfaceKHR CreateWaylandSurfaceKHR;
+#endif
+#ifdef VK_USE_PLATFORM_WIN32_KHR
+ PFN_vkCreateWin32SurfaceKHR CreateWin32SurfaceKHR;
+#endif
+#ifdef VK_USE_PLATFORM_XCB_KHR
+ PFN_vkCreateXcbSurfaceKHR CreateXcbSurfaceKHR;
+#endif
+#ifdef VK_USE_PLATFORM_XLIB_KHR
+ PFN_vkCreateXlibSurfaceKHR CreateXlibSurfaceKHR;
+#endif
PFN_vkDbgCreateMsgCallback DbgCreateMsgCallback;
PFN_vkDbgDestroyMsgCallback DbgDestroyMsgCallback;
} VkLayerInstanceDispatchTable;
diff --git a/loader/loader.c b/loader/loader.c
index eb47149..2b8c2db 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -111,6 +111,21 @@
.GetPhysicalDeviceSurfaceCapabilitiesKHR = loader_GetPhysicalDeviceSurfaceCapabilitiesKHR,
.GetPhysicalDeviceSurfaceFormatsKHR = loader_GetPhysicalDeviceSurfaceFormatsKHR,
.GetPhysicalDeviceSurfacePresentModesKHR = loader_GetPhysicalDeviceSurfacePresentModesKHR,
+#ifdef VK_USE_PLATFORM_MIR_KHR
+ .CreateMirSurfaceKHR = vkCreateMirSurfaceKHR,
+#endif
+#ifdef VK_USE_PLATFORM_WAYLAND_KHR
+ .CreateWaylandSurfaceKHR = vkCreateWaylandSurfaceKHR,
+#endif
+#ifdef VK_USE_PLATFORM_WIN32_KHR
+ .CreateWin32SurfaceKHR = vkCreateWin32SurfaceKHR,
+#endif
+#ifdef VK_USE_PLATFORM_XCB_KHR
+ .CreateXcbSurfaceKHR = vkCreateXcbSurfaceKHR,
+#endif
+#ifdef VK_USE_PLATFORM_XLIB_KHR
+ .CreateXlibSurfaceKHR = vkCreateXlibSurfaceKHR,
+#endif
.DbgCreateMsgCallback = loader_DbgCreateMsgCallback,
.DbgDestroyMsgCallback = loader_DbgDestroyMsgCallback,
};
diff --git a/loader/loader.h b/loader/loader.h
index c83faa9..86f3e22 100644
--- a/loader/loader.h
+++ b/loader/loader.h
@@ -226,7 +226,6 @@
bool wsi_xcb_surface_enabled;
bool wsi_xlib_surface_enabled;
#endif // _WIN32
- bool wsi_swapchain_enabled;
};
/* per enumerated PhysicalDevice structure */
diff --git a/loader/table_ops.h b/loader/table_ops.h
index f307781..b5327eb 100644
--- a/loader/table_ops.h
+++ b/loader/table_ops.h
@@ -469,6 +469,21 @@
table->GetPhysicalDeviceSurfaceCapabilitiesKHR = (PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR) gpa(inst, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR");
table->GetPhysicalDeviceSurfaceFormatsKHR = (PFN_vkGetPhysicalDeviceSurfaceFormatsKHR) gpa(inst, "vkGetPhysicalDeviceSurfaceFormatsKHR");
table->GetPhysicalDeviceSurfacePresentModesKHR = (PFN_vkGetPhysicalDeviceSurfacePresentModesKHR) gpa(inst, "vkGetPhysicalDeviceSurfacePresentModesKHR");
+#ifdef VK_USE_PLATFORM_MIR_KHR
+ table->CreateMirSurfaceKHR = (PFN_vkCreateMirSurfaceKHR) gpa(inst, "vkCreateMirSurfaceKHR");
+#endif
+#ifdef VK_USE_PLATFORM_WAYLAND_KHR
+ table->CreateWaylandSurfaceKHR = (PFN_vkCreateWaylandSurfaceKHR) gpa(inst, "vkCreateWaylandSurfaceKHR");
+#endif
+#ifdef VK_USE_PLATFORM_WIN32_KHR
+ table->CreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR) gpa(inst, "vkCreateWin32SurfaceKHR");
+#endif
+#ifdef VK_USE_PLATFORM_XCB_KHR
+ table->CreateXcbSurfaceKHR = (PFN_vkCreateXcbSurfaceKHR) gpa(inst, "vkCreateXcbSurfaceKHR");
+#endif
+#ifdef VK_USE_PLATFORM_XLIB_KHR
+ table->CreateXlibSurfaceKHR = (PFN_vkCreateXlibSurfaceKHR) gpa(inst, "vkCreateXlibSurfaceKHR");
+#endif
}
static inline void *loader_lookup_instance_dispatch_table(
@@ -513,6 +528,26 @@
return (void *) table->GetPhysicalDeviceSurfaceFormatsKHR;
if (!strcmp(name, "GetPhysicalDeviceSurfacePresentModesKHR"))
return (void *) table->GetPhysicalDeviceSurfacePresentModesKHR;
+#ifdef VK_USE_PLATFORM_MIR_KHR
+ if (!strcmp(name, "CreateMirSurfaceKHR"))
+ return (void *) table->CreateMirSurfaceKHR;
+#endif
+#ifdef VK_USE_PLATFORM_WAYLAND_KHR
+ if (!strcmp(name, "CreateWaylandSurfaceKHR"))
+ return (void *) table->CreateWaylandSurfaceKHR;
+#endif
+#ifdef VK_USE_PLATFORM_WIN32_KHR
+ if (!strcmp(name, "CreateWin32SurfaceKHR"))
+ return (void *) table->CreateWin32SurfaceKHR;
+#endif
+#ifdef VK_USE_PLATFORM_XCB_KHR
+ if (!strcmp(name, "CreateXcbSurfaceKHR"))
+ return (void *) table->CreateXcbSurfaceKHR;
+#endif
+#ifdef VK_USE_PLATFORM_XLIB_KHR
+ if (!strcmp(name, "CreateXlibSurfaceKHR"))
+ return (void *) table->CreateXlibSurfaceKHR;
+#endif
if (!strcmp(name, "DbgCreateMsgCallback"))
return (void *) table->DbgCreateMsgCallback;
if (!strcmp(name, "DbgDestroyMsgCallback"))
diff --git a/loader/wsi.c b/loader/wsi.c
index 311b91d..c1cbc32 100644
--- a/loader/wsi.c
+++ b/loader/wsi.c
@@ -123,14 +123,13 @@
{
ptr_instance->wsi_surface_enabled = false;
#ifdef _WIN32
- ptr_instance->wsi_surface_enabled = true;
+ ptr_instance->wsi_win32_surface_enabled = true;
#else // _WIN32
ptr_instance->wsi_mir_surface_enabled = false;
ptr_instance->wsi_wayland_surface_enabled = false;
ptr_instance->wsi_xcb_surface_enabled = false;
ptr_instance->wsi_xlib_surface_enabled = false;
#endif // _WIN32
- ptr_instance->wsi_swapchain_enabled = false;
for (uint32_t i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_SURFACE_EXTENSION_NAME) == 0) {
@@ -140,7 +139,7 @@
#ifdef _WIN32
#ifdef VK_USE_PLATFORM_WIN32_KHR
if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_WIN32_SURFACE_EXTENSION_NAME) == 0) {
- ptr_instance->wsi_surface_enabled = true;
+ ptr_instance->wsi_win32_surface_enabled = true;
continue;
}
#endif/ VK_USE_PLATFORM_WIN32_KHR
@@ -188,11 +187,9 @@
VkSurfaceKHR surface,
const VkAllocationCallbacks* pAllocator)
{
- if (pAllocator) {
- pAllocator->pfnFree(pAllocator->pUserData, surface);
- } else {
- free(surface);
- }
+ struct loader_instance *ptr_instance = loader_get_instance(instance);
+
+ loader_heap_free(ptr_instance, surface);
}
/*
@@ -481,17 +478,12 @@
const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface)
{
+ struct loader_instance *ptr_instance = loader_get_instance(instance);
VkIcdSurfaceWin32 *pIcdSurface = NULL;
- if (pAllocator) {
- pIcdSurface = (VkIcdSurfaceWin32 *) pAllocator->pfnAllocation(
- pAllocator->pUserData,
- sizeof(VkIcdSurfaceWin32),
- sizeof(VkSurfaceKHR),
- VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
- } else {
- pIcdSurface = (VkIcdSurfaceWin32 *) malloc(sizeof(VkIcdSurfaceWin32));
- }
+ pIcdSurface = loader_heap_alloc(ptr_instance,
+ sizeof(VkIcdSurfaceWin32),
+ VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (pIcdSurface == NULL) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
@@ -525,17 +517,12 @@
const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface)
{
+ struct loader_instance *ptr_instance = loader_get_instance(instance);
VkIcdSurfaceMir *pIcdSurface = NULL;
- if (pAllocator) {
- pIcdSurface = (VkIcdSurfaceMir *) pAllocator->pfnAllocation(
- pAllocator->pUserData,
- sizeof(VkIcdSurfaceMir),
- sizeof(VkSurfaceKHR),
- VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
- } else {
- pIcdSurface = (VkIcdSurfaceMir *) malloc(sizeof(VkIcdSurfaceMir));
- }
+ pIcdSurface = loader_heap_alloc(ptr_instance,
+ sizeof(VkIcdSurfaceMir),
+ VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (pIcdSurface == NULL) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
@@ -567,17 +554,12 @@
const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface)
{
+ struct loader_instance *ptr_instance = loader_get_instance(instance);
VkIcdSurfaceWayland *pIcdSurface = NULL;
- if (pAllocator) {
- pIcdSurface = (VkIcdSurfaceWayland *) pAllocator->pfnAllocation(
- pAllocator->pUserData,
- sizeof(VkIcdSurfaceWayland),
- sizeof(VkSurfaceKHR),
- VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
- } else {
- pIcdSurface = (VkIcdSurfaceWayland *) malloc(sizeof(VkIcdSurfaceWayland));
- }
+ pIcdSurface = loader_heap_alloc(ptr_instance,
+ sizeof(VkIcdSurfaceWayland),
+ VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (pIcdSurface == NULL) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
@@ -609,17 +591,12 @@
const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface)
{
+ struct loader_instance *ptr_instance = loader_get_instance(instance);
VkIcdSurfaceXcb *pIcdSurface = NULL;
- if (pAllocator) {
- pIcdSurface = (VkIcdSurfaceXcb *) pAllocator->pfnAllocation(
- pAllocator->pUserData,
- sizeof(VkIcdSurfaceXcb),
- sizeof(VkSurfaceKHR),
- VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
- } else {
- pIcdSurface = (VkIcdSurfaceXcb *) malloc(sizeof(VkIcdSurfaceXcb));
- }
+ pIcdSurface = loader_heap_alloc(ptr_instance,
+ sizeof(VkIcdSurfaceXcb),
+ VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (pIcdSurface == NULL) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
@@ -651,17 +628,12 @@
const VkAllocationCallbacks* pAllocator,
VkSurfaceKHR* pSurface)
{
+ struct loader_instance *ptr_instance = loader_get_instance(instance);
VkIcdSurfaceXlib *pIcdSurface = NULL;
- if (pAllocator) {
- pIcdSurface = (VkIcdSurfaceXlib *) pAllocator->pfnAllocation(
- pAllocator->pUserData,
- sizeof(VkIcdSurfaceXlib),
- sizeof(VkSurfaceKHR),
- VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
- } else {
- pIcdSurface = (VkIcdSurfaceXlib *) malloc(sizeof(VkIcdSurfaceXlib));
- }
+ pIcdSurface = loader_heap_alloc(ptr_instance,
+ sizeof(VkIcdSurfaceXlib),
+ VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (pIcdSurface == NULL) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}