aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Ashburn <jon@lunarg.com>2016-01-20 08:52:40 -0700
committerJon Ashburn <jon@lunarg.com>2016-01-20 18:05:49 -0700
commitfb031e72f092194aeccf6e39adbf0e83ff91768b (patch)
treefec9d1dbe7fad663e5b04b96a64992d25cf8409e
parent2679f18983e093f1852f592c68ecf93283adf366 (diff)
downloadusermoji-fb031e72f092194aeccf6e39adbf0e83ff91768b.tar.xz
layers: Fix screenshot to intercept CreateInstance so it canbe on instance chain
-rw-r--r--layers/screenshot.cpp43
1 files changed, 37 insertions, 6 deletions
diff --git a/layers/screenshot.cpp b/layers/screenshot.cpp
index 32312897..cc192b87 100644
--- a/layers/screenshot.cpp
+++ b/layers/screenshot.cpp
@@ -22,6 +22,7 @@
*
* Author: Cody Northrop <cody@lunarg.com>
* Author: David Pinedo <david@lunarg.com>
+ * Author: Jon Ashburn <jon@lunarg.com>
*/
#include <inttypes.h>
@@ -52,6 +53,8 @@ struct devExts {
};
static std::unordered_map<void *, struct devExts> deviceExtMap;
static device_table_map screenshot_device_table_map;
+//TODO convert over to the new interface using locally defiend maps
+//static instance_table_map screenshot_instance_table_map;
static int globalLockInitialized = 0;
static loader_platform_thread_mutex globalLock;
@@ -383,6 +386,36 @@ static void writePPM( const char *filename, VkImage image1)
pTableDevice->FreeCommandBuffers(device, deviceMap[device]->commandPool, 1, &commandBuffer);
}
+VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(
+ const VkInstanceCreateInfo* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkInstance* pInstance)
+{
+ VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
+
+ assert(chain_info->u.pLayerInfo);
+ PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
+ assert(fpGetInstanceProcAddr);
+ PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(*pInstance, "vkCreateInstance");
+ if (fpCreateInstance == NULL) {
+ return VK_ERROR_INITIALIZATION_FAILED;
+ }
+
+ // Advance the link info for the next element on the chain
+ chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
+
+ VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
+ if (result != VK_SUCCESS)
+ return result;
+
+ initInstanceTable(*pInstance, fpGetInstanceProcAddr);
+
+ init_screenshot();
+
+ return result;
+}
+
+//TODO hook DestroyInstance to cleanup
static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
{
@@ -426,7 +459,6 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(
initDeviceTable(*pDevice, fpGetDeviceProcAddr, screenshot_device_table_map);
- init_screenshot();
createDeviceRegisterExtensions(pCreateInfo, *pDevice);
// Create a mapping from a device to a physicalDevice
if (deviceMap[*pDevice] == NULL)
@@ -758,13 +790,10 @@ VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(
VkDevice dev,
const char *funcName)
{
- if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
+ if (!strcmp(funcName, "vkGetDeviceProcAddr"))
return (PFN_vkVoidFunction)vkGetDeviceProcAddr;
- }
-
if (!strcmp(funcName, "vkGetDeviceQueue"))
return (PFN_vkVoidFunction) vkGetDeviceQueue;
-
if (!strcmp(funcName, "vkCreateCommandPool"))
return (PFN_vkVoidFunction) vkCreateCommandPool;
@@ -791,8 +820,11 @@ VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(
VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
{
+
if (!strcmp("vkGetInstanceProcAddr", funcName))
return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
+ if (!strcmp(funcName, "vkCreateInstance"))
+ return (PFN_vkVoidFunction) vkCreateInstance;
if (!strcmp(funcName, "vkCreateDevice"))
return (PFN_vkVoidFunction) vkCreateDevice;
if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
@@ -803,7 +835,6 @@ VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(V
if (instance == VK_NULL_HANDLE) {
return NULL;
}
-
VkLayerInstanceDispatchTable* pTable = instance_dispatch_table(instance);
if (pTable->GetInstanceProcAddr == NULL)
return NULL;