layers: Move some fixed code into header files for APIDump and Generic
authorJon Ashburn <jon@lunarg.com>
Thu, 17 Sep 2015 21:28:12 +0000 (15:28 -0600)
committerJon Ashburn <jon@lunarg.com>
Thu, 17 Sep 2015 21:29:28 +0000 (15:29 -0600)
layers/apidump.h
layers/generic.h
vk-layer-generate.py

index 6905fbd8e4ba0bf97900124bc1ef4c4b83c6b030..7eba182a0b759e698c1936ff7ed7ddedcc030d0c 100644 (file)
  * Authors:
  *   Courtney Goeltzenleuchter <courtney@lunarg.com>
  */
+#pragma once
 
-#ifndef GENERIC_H
-#define GENERIC_H
-#include "vkLayer.h"
+#include "vk_layer.h"
 
 /*
  * This file contains static functions for the generated layer Generic
@@ -53,6 +52,50 @@ static const VkLayerProperties layerDevProps[LAYER_DEV_PROPS_ARRAY_SIZE] = {
     }
 };
 
+struct devExts {
+    bool wsi_enabled;
+};
+
+struct instExts {
+    bool wsi_enabled;
+};
+
+static std::unordered_map<void *, struct devExts>     deviceExtMap;
+static std::unordered_map<void *, struct instExts>     instanceExtMap;
+
+static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
+{
+    uint32_t i;
+    VkLayerDispatchTable *pDisp  = device_dispatch_table(device);
+    PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
+    pDisp->GetSurfacePropertiesKHR = (PFN_vkGetSurfacePropertiesKHR) gpa(device, "vkGetSurfacePropertiesKHR");
+    pDisp->GetSurfaceFormatsKHR = (PFN_vkGetSurfaceFormatsKHR) gpa(device, "vkGetSurfaceFormatsKHR");
+    pDisp->GetSurfacePresentModesKHR = (PFN_vkGetSurfacePresentModesKHR) gpa(device, "vkGetSurfacePresentModesKHR");
+    pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
+    pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
+    pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
+    pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
+    pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
 
-#endif // GENERIC_H
+    deviceExtMap[pDisp].wsi_enabled = false;
+    for (i = 0; i < pCreateInfo->extensionCount; i++) {
+        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_DEVICE_SWAPCHAIN_EXTENSION_NAME) == 0)
+            deviceExtMap[pDisp].wsi_enabled = true;
+
+    }
+}
+
+static void createInstanceRegisterExtensions(const VkInstanceCreateInfo* pCreateInfo, VkInstance instance)
+{
+    uint32_t i;
+    VkLayerInstanceDispatchTable *pDisp  = instance_dispatch_table(instance);
+    PFN_vkGetInstanceProcAddr gpa = pDisp->GetInstanceProcAddr;
+    pDisp->GetPhysicalDeviceSurfaceSupportKHR = (PFN_vkGetPhysicalDeviceSurfaceSupportKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceSupportKHR");
+    instanceExtMap[pDisp].wsi_enabled = false;
+    for (i = 0; i < pCreateInfo->extensionCount; i++) {
+        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_SWAPCHAIN_EXTENSION_NAME) == 0)
+            instanceExtMap[pDisp].wsi_enabled = true;
+
+    }
+}
 
index d74d98585e0380ec2544b8569965f7366702710b..793281b8f8401fbaf579bf104aa7a1bd3b816439 100644 (file)
@@ -51,6 +51,49 @@ static const VkLayerProperties deviceLayerProps[] = {
     }
 };
 
+struct devExts {
+    bool wsi_enabled;
+};
+struct instExts {
+    bool wsi_enabled;
+};
+static std::unordered_map<void *, struct devExts>     deviceExtMap;
+static std::unordered_map<void *, struct instExts>    instanceExtMap;
+
+static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
+{
+    uint32_t i;
+    VkLayerDispatchTable *pDisp  = device_dispatch_table(device);
+    PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;
+    pDisp->GetSurfacePropertiesKHR = (PFN_vkGetSurfacePropertiesKHR) gpa(device, "vkGetSurfacePropertiesKHR");
+    pDisp->GetSurfaceFormatsKHR = (PFN_vkGetSurfaceFormatsKHR) gpa(device, "vkGetSurfaceFormatsKHR");
+    pDisp->GetSurfacePresentModesKHR = (PFN_vkGetSurfacePresentModesKHR) gpa(device, "vkGetSurfacePresentModesKHR");
+    pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");
+    pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");
+    pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");
+    pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");
+    pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");
+
+    deviceExtMap[pDisp].wsi_enabled = false;
+    for (i = 0; i < pCreateInfo->extensionCount; i++) {
+        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_DEVICE_SWAPCHAIN_EXTENSION_NAME) == 0)
+            deviceExtMap[pDisp].wsi_enabled = true;
 
+    }
+}
+
+static void createInstanceRegisterExtensions(const VkInstanceCreateInfo* pCreateInfo, VkInstance instance)
+{
+    uint32_t i;
+    VkLayerInstanceDispatchTable *pDisp  = instance_dispatch_table(instance);
+    PFN_vkGetInstanceProcAddr gpa = pDisp->GetInstanceProcAddr;
+    pDisp->GetPhysicalDeviceSurfaceSupportKHR = (PFN_vkGetPhysicalDeviceSurfaceSupportKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceSupportKHR");
+    instanceExtMap[pDisp].wsi_enabled = false;
+    for (i = 0; i < pCreateInfo->extensionCount; i++) {
+        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_SWAPCHAIN_EXTENSION_NAME) == 0)
+            instanceExtMap[pDisp].wsi_enabled = true;
+
+    }
+}
 #endif // GENERIC_H
 
index d4a58a945783373c56750f354ee24c1cf38fc706..7fa0cdeb8440dde3e8bed331de4c2354446646c0 100755 (executable)
@@ -609,48 +609,6 @@ class GenericLayerSubcommand(Subcommand):
         gen_header.append('#define LAYER_EXT_ARRAY_SIZE 1')
         gen_header.append('#define LAYER_DEV_EXT_ARRAY_SIZE 1')
         gen_header.append('static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);')
-        gen_header.append('struct devExts {')
-        gen_header.append('    bool wsi_enabled;')
-        gen_header.append('};')
-        gen_header.append('struct instExts {')
-        gen_header.append('    bool wsi_enabled;')
-        gen_header.append('};')
-        gen_header.append('static std::unordered_map<void *, struct devExts>     deviceExtMap;')
-        gen_header.append('static std::unordered_map<void *, struct instExts>    instanceExtMap;')
-        gen_header.append('')
-        gen_header.append('static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)')
-        gen_header.append('{')
-        gen_header.append('    uint32_t i;')
-        gen_header.append('    VkLayerDispatchTable *pDisp  = device_dispatch_table(device);')
-        gen_header.append('    PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;')
-        gen_header.append('    pDisp->GetSurfacePropertiesKHR = (PFN_vkGetSurfacePropertiesKHR) gpa(device, "vkGetSurfacePropertiesKHR");')
-        gen_header.append('    pDisp->GetSurfaceFormatsKHR = (PFN_vkGetSurfaceFormatsKHR) gpa(device, "vkGetSurfaceFormatsKHR");')
-        gen_header.append('    pDisp->GetSurfacePresentModesKHR = (PFN_vkGetSurfacePresentModesKHR) gpa(device, "vkGetSurfacePresentModesKHR");')
-        gen_header.append('    pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");')
-        gen_header.append('    pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");')
-        gen_header.append('    pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");')
-        gen_header.append('    pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");')
-        gen_header.append('    pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");\n')
-        gen_header.append('    deviceExtMap[pDisp].wsi_enabled = false;')
-        gen_header.append('    for (i = 0; i < pCreateInfo->extensionCount; i++) {')
-        gen_header.append('        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_DEVICE_SWAPCHAIN_EXTENSION_NAME) == 0)')
-        gen_header.append('            deviceExtMap[pDisp].wsi_enabled = true;')
-        gen_header.append('')
-        gen_header.append('    }')
-        gen_header.append('}\n')
-        gen_header.append('static void createInstanceRegisterExtensions(const VkInstanceCreateInfo* pCreateInfo, VkInstance instance)')
-        gen_header.append('{')
-        gen_header.append('    uint32_t i;')
-        gen_header.append('    VkLayerInstanceDispatchTable *pDisp  = instance_dispatch_table(instance);')
-        gen_header.append('    PFN_vkGetInstanceProcAddr gpa = pDisp->GetInstanceProcAddr;')
-        gen_header.append('    pDisp->GetPhysicalDeviceSurfaceSupportKHR = (PFN_vkGetPhysicalDeviceSurfaceSupportKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceSupportKHR");')
-        gen_header.append('    instanceExtMap[pDisp].wsi_enabled = false;')
-        gen_header.append('    for (i = 0; i < pCreateInfo->extensionCount; i++) {')
-        gen_header.append('        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_SWAPCHAIN_EXTENSION_NAME) == 0)')
-        gen_header.append('            instanceExtMap[pDisp].wsi_enabled = true;')
-        gen_header.append('')
-        gen_header.append('    }')
-        gen_header.append('}')
         gen_header.append('')
         return "\n".join(gen_header)
 
@@ -764,6 +722,7 @@ class APIDumpSubcommand(Subcommand):
         header_txt.append('#include "vk_layer_table.h"')
         header_txt.append('#include "vk_layer_extension_utils.h"')
         header_txt.append('#include <unordered_map>')
+        header_txt.append('#include "apidump.h"')
         header_txt.append('')
         header_txt.append('static std::ofstream fileStream;')
         header_txt.append('static std::string fileName = "vk_apidump.txt";')
@@ -827,50 +786,6 @@ class APIDumpSubcommand(Subcommand):
         header_txt.append('    assert(maxTID < MAX_TID);')
         header_txt.append('    return retVal;')
         header_txt.append('}')
-        header_txt.append('struct devExts {')
-        header_txt.append('    bool wsi_enabled;')
-        header_txt.append('};')
-        header_txt.append('')
-        header_txt.append('struct instExts {')
-        header_txt.append('    bool wsi_enabled;')
-        header_txt.append('};')
-        header_txt.append('')
-        header_txt.append('static std::unordered_map<void *, struct devExts>     deviceExtMap;')
-        header_txt.append('static std::unordered_map<void *, struct instExts>     instanceExtMap;')
-        header_txt.append('')
-        header_txt.append('static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)')
-        header_txt.append('{')
-        header_txt.append('    uint32_t i;')
-        header_txt.append('    VkLayerDispatchTable *pDisp  = device_dispatch_table(device);')
-        header_txt.append('    PFN_vkGetDeviceProcAddr gpa = pDisp->GetDeviceProcAddr;')
-        header_txt.append('    pDisp->GetSurfacePropertiesKHR = (PFN_vkGetSurfacePropertiesKHR) gpa(device, "vkGetSurfacePropertiesKHR");')
-        header_txt.append('    pDisp->GetSurfaceFormatsKHR = (PFN_vkGetSurfaceFormatsKHR) gpa(device, "vkGetSurfaceFormatsKHR");')
-        header_txt.append('    pDisp->GetSurfacePresentModesKHR = (PFN_vkGetSurfacePresentModesKHR) gpa(device, "vkGetSurfacePresentModesKHR");')
-        header_txt.append('    pDisp->CreateSwapchainKHR = (PFN_vkCreateSwapchainKHR) gpa(device, "vkCreateSwapchainKHR");')
-        header_txt.append('    pDisp->DestroySwapchainKHR = (PFN_vkDestroySwapchainKHR) gpa(device, "vkDestroySwapchainKHR");')
-        header_txt.append('    pDisp->GetSwapchainImagesKHR = (PFN_vkGetSwapchainImagesKHR) gpa(device, "vkGetSwapchainImagesKHR");')
-        header_txt.append('    pDisp->AcquireNextImageKHR = (PFN_vkAcquireNextImageKHR) gpa(device, "vkAcquireNextImageKHR");')
-        header_txt.append('    pDisp->QueuePresentKHR = (PFN_vkQueuePresentKHR) gpa(device, "vkQueuePresentKHR");\n')
-        header_txt.append('    deviceExtMap[pDisp].wsi_enabled = false;')
-        header_txt.append('    for (i = 0; i < pCreateInfo->extensionCount; i++) {')
-        header_txt.append('        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_DEVICE_SWAPCHAIN_EXTENSION_NAME) == 0)')
-        header_txt.append('            deviceExtMap[pDisp].wsi_enabled = true;')
-        header_txt.append('')
-        header_txt.append('    }')
-        header_txt.append('}\n')
-        header_txt.append('static void createInstanceRegisterExtensions(const VkInstanceCreateInfo* pCreateInfo, VkInstance instance)')
-        header_txt.append('{')
-        header_txt.append('    uint32_t i;')
-        header_txt.append('    VkLayerInstanceDispatchTable *pDisp  = instance_dispatch_table(instance);')
-        header_txt.append('    PFN_vkGetInstanceProcAddr gpa = pDisp->GetInstanceProcAddr;')
-        header_txt.append('    pDisp->GetPhysicalDeviceSurfaceSupportKHR = (PFN_vkGetPhysicalDeviceSurfaceSupportKHR) gpa(instance, "vkGetPhysicalDeviceSurfaceSupportKHR");')
-        header_txt.append('    instanceExtMap[pDisp].wsi_enabled = false;')
-        header_txt.append('    for (i = 0; i < pCreateInfo->extensionCount; i++) {')
-        header_txt.append('        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_KHR_SWAPCHAIN_EXTENSION_NAME) == 0)')
-        header_txt.append('            instanceExtMap[pDisp].wsi_enabled = true;')
-        header_txt.append('')
-        header_txt.append('    }')
-        header_txt.append('}\n')
         header_txt.append('')
         header_txt.append('void interpret_memBarriers(const void* const* ppMemBarriers, uint32_t memBarrierCount)')
         header_txt.append('{')