misc: Make DEBUG_MARKER entrypoints a device extension with separate dispatch

Right now only DrawState and ParamChecker implement this extension.
diff --git a/include/vkDbg.h b/include/vkDbg.h
deleted file mode 100644
index 9e5fb6e..0000000
--- a/include/vkDbg.h
+++ /dev/null
@@ -1,141 +0,0 @@
-#ifndef __VKDBG_H__
-#define __VKDBG_H__
-
-#include <vulkan.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif // __cplusplus
-
-typedef enum VkValidationLevel_
-{
-    VK_VALIDATION_LEVEL_0                                   = 0x00000000,
-    VK_VALIDATION_LEVEL_1                                   = 0x00000001,
-    VK_VALIDATION_LEVEL_2                                   = 0x00000002,
-    VK_VALIDATION_LEVEL_3                                   = 0x00000003,
-    VK_VALIDATION_LEVEL_4                                   = 0x00000004,
-
-    VK_VALIDATION_LEVEL_BEGIN_RANGE                         = VK_VALIDATION_LEVEL_0,
-    VK_VALIDATION_LEVEL_END_RANGE                           = VK_VALIDATION_LEVEL_4,
-    VK_NUM_VALIDATION_LEVEL                                 = (VK_VALIDATION_LEVEL_END_RANGE - VK_VALIDATION_LEVEL_BEGIN_RANGE + 1),
-
-    VK_MAX_ENUM(VkValidationLevel)
-} VkValidationLevel;
-
-typedef enum _VK_DBG_MSG_TYPE
-{
-    VK_DBG_REPORT_INFO_BIT      = 0x0,
-    VK_DBG_REPORT_ERROR_BIT        = 0x1,
-    VK_DBG_MSG_WARNING      = 0x2,
-    VK_DBG_MSG_PERF_WARNING = 0x3,
-
-    VK_DBG_MSG_TYPE_BEGIN_RANGE = VK_DBG_REPORT_INFO_BIT,
-    VK_DBG_MSG_TYPE_END_RANGE   = VK_DBG_MSG_PERF_WARNING,
-    VK_NUM_DBG_MSG_TYPE         = (VK_DBG_MSG_TYPE_END_RANGE - VK_DBG_MSG_TYPE_BEGIN_RANGE + 1),
-} VK_DBG_MSG_TYPE;
-
-typedef enum _VK_DBG_MSG_FILTER
-{
-    VK_DBG_MSG_FILTER_NONE     = 0x0,
-    VK_DBG_MSG_FILTER_REPEATED = 0x1,
-    VK_DBG_MSG_FILTER_ALL      = 0x2,
-
-    VK_DBG_MSG_FILTER_BEGIN_RANGE = VK_DBG_MSG_FILTER_NONE,
-    VK_DBG_MSG_FILTER_END_RANGE   = VK_DBG_MSG_FILTER_ALL,
-    VK_NUM_DBG_MSG_FILTER         = (VK_DBG_MSG_FILTER_END_RANGE - VK_DBG_MSG_FILTER_BEGIN_RANGE + 1),
-} VK_DBG_MSG_FILTER;
-
-typedef enum _VK_DBG_GLOBAL_OPTION
-{
-    VK_DBG_OPTION_DEBUG_ECHO_ENABLE = 0x0,
-    VK_DBG_OPTION_BREAK_ON_ERROR    = 0x1,
-    VK_DBG_OPTION_BREAK_ON_WARNING  = 0x2,
-
-    VK_DBG_GLOBAL_OPTION_BEGIN_RANGE = VK_DBG_OPTION_DEBUG_ECHO_ENABLE,
-    VK_DBG_GLOBAL_OPTION_END_RANGE   = VK_DBG_OPTION_BREAK_ON_WARNING,
-    VK_NUM_DBG_GLOBAL_OPTION         = (VK_DBG_GLOBAL_OPTION_END_RANGE - VK_DBG_GLOBAL_OPTION_BEGIN_RANGE + 1),
-} VK_DBG_GLOBAL_OPTION;
-
-typedef enum _VK_DBG_DEVICE_OPTION
-{
-    VK_DBG_OPTION_DISABLE_PIPELINE_LOADS      = 0x0,
-    VK_DBG_OPTION_FORCE_OBJECT_MEMORY_REQS    = 0x1,
-    VK_DBG_OPTION_FORCE_LARGE_IMAGE_ALIGNMENT = 0x2,
-
-    VK_DBG_DEVICE_OPTION_BEGIN_RANGE = VK_DBG_OPTION_DISABLE_PIPELINE_LOADS,
-    VK_DBG_DEVICE_OPTION_END_RANGE   = VK_DBG_OPTION_FORCE_LARGE_IMAGE_ALIGNMENT,
-    VK_NUM_DBG_DEVICE_OPTION         = (VK_DBG_DEVICE_OPTION_END_RANGE - VK_DBG_DEVICE_OPTION_BEGIN_RANGE + 1),
-} VK_DBG_DEVICE_OPTION;
-
-typedef void (VKAPI *VK_DBG_MSG_CALLBACK_FUNCTION)(
-    VK_DBG_MSG_TYPE      msgType,
-    VkValidationLevel    validationLevel,
-    VkObject             srcObject,
-    size_t               location,
-    int32_t              msgCode,
-    const char*          pMsg,
-    void*                pUserData);
-
-// Debug functions
-typedef VkResult (VKAPI *PFN_vkDbgSetValidationLevel)(VkDevice device, VkValidationLevel validationLevel);
-typedef VkResult (VKAPI *PFN_vkDbgRegisterMsgCallback)(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData);
-typedef VkResult (VKAPI *PFN_vkDbgUnregisterMsgCallback)(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback);
-typedef VkResult (VKAPI *PFN_vkDbgSetMessageFilter)(VkDevice device, int32_t msgCode, VK_DBG_MSG_FILTER filter);
-typedef VkResult (VKAPI *PFN_vkDbgSetObjectTag)(VkDevice device, VkObject object, size_t tagSize, const void* pTag);
-typedef VkResult (VKAPI *PFN_vkDbgSetGlobalOption)(VkInstance instance, VK_DBG_GLOBAL_OPTION dbgOption, size_t dataSize, const void* pData);
-typedef VkResult (VKAPI *PFN_vkDbgSetDeviceOption)(VkDevice device, VK_DBG_DEVICE_OPTION dbgOption, size_t dataSize, const void* pData);
-typedef void (VKAPI *PFN_vkCmdDbgMarkerBegin)(VkCmdBuffer cmdBuffer, const char* pMarker);
-typedef void (VKAPI *PFN_vkCmdDbgMarkerEnd)(VkCmdBuffer cmdBuffer);
-
-#ifdef VK_PROTOTYPES
-VkResult VKAPI vkDbgSetValidationLevel(
-    VkDevice           device,
-    VkValidationLevel validationLevel);
-
-VkResult VKAPI vkDbgRegisterMsgCallback(
-    VkInstance                  instance,
-    VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback,
-    void*                         pUserData);
-
-VkResult VKAPI vkDbgUnregisterMsgCallback(
-    VkInstance                  instance,
-    VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback);
-
-VkResult VKAPI vkDbgSetMessageFilter(
-    VkDevice         device,
-    int32_t            msgCode,
-    VK_DBG_MSG_FILTER filter);
-
-VkResult VKAPI vkDbgSetObjectTag(
-    VkDevice        device,
-    VkObject        object,
-    size_t          tagSize,
-    const void*     pTag);
-
-VkResult VKAPI vkDbgSetGlobalOption(
-    VkInstance          instance,
-    VK_DBG_GLOBAL_OPTION dbgOption,
-    size_t                dataSize,
-    const void*           pData);
-
-VkResult VKAPI vkDbgSetDeviceOption(
-    VkDevice            device,
-    VK_DBG_DEVICE_OPTION dbgOption,
-    size_t                dataSize,
-    const void*           pData);
-
-void VKAPI vkCmdDbgMarkerBegin(
-    VkCmdBuffer  cmdBuffer,
-    const char*     pMarker);
-
-void VKAPI vkCmdDbgMarkerEnd(
-    VkCmdBuffer  cmdBuffer);
-
-#endif // VK_PROTOTYPES
-
-#ifdef __cplusplus
-}; // extern "C"
-#endif // __cplusplus
-
-#endif // __VKDBG_H__
diff --git a/include/vkLayer.h b/include/vkLayer.h
index 883cca1..468d435 100644
--- a/include/vkLayer.h
+++ b/include/vkLayer.h
@@ -132,9 +132,6 @@
     PFN_vkCreateRenderPass CreateRenderPass;
     PFN_vkCmdBeginRenderPass CmdBeginRenderPass;
     PFN_vkCmdEndRenderPass CmdEndRenderPass;
-    PFN_vkDbgSetObjectTag DbgSetObjectTag;
-    PFN_vkCmdDbgMarkerBegin CmdDbgMarkerBegin;
-    PFN_vkCmdDbgMarkerEnd CmdDbgMarkerEnd;
     PFN_vkCreateSwapChainWSI CreateSwapChainWSI;
     PFN_vkDestroySwapChainWSI DestroySwapChainWSI;
     PFN_vkGetSwapChainInfoWSI GetSwapChainInfoWSI;
@@ -144,7 +141,6 @@
     PFN_vkDbgStringCallback DbgStringCallback;
     PFN_vkDbgStdioCallback DbgStdioCallback;
     PFN_vkDbgBreakCallback DbgBreakCallback;
-    PFN_vkDbgSetObjectName DbgSetObjectName;
 } VkLayerDispatchTable;
 
 typedef struct VkLayerInstanceDispatchTable_
diff --git a/include/vk_debug_marker_layer.h b/include/vk_debug_marker_layer.h
new file mode 100644
index 0000000..7c4ebc9
--- /dev/null
+++ b/include/vk_debug_marker_layer.h
@@ -0,0 +1,46 @@
+//
+// File: vk_debug_marker_lunarg.h
+//
+/*
+** Copyright (c) 2015 The Khronos Group Inc.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a
+** copy of this software and/or associated documentation files (the
+** "Materials"), to deal in the Materials without restriction, including
+** without limitation the rights to use, copy, modify, merge, publish,
+** distribute, sublicense, and/or sell copies of the Materials, and to
+** permit persons to whom the Materials are furnished to do so, subject to
+** the following conditions:
+**
+** The above copyright notice and this permission notice shall be included
+** in all copies or substantial portions of the Materials.
+**
+** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+**
+** Authors:
+**   Jon Ashburn <jon@lunarg.com>
+**   Courtney Goeltzenleuchter <courtney@lunarg.com>
+*/
+
+#pragma once
+
+#include "vulkan.h"
+#include "vk_debug_marker_lunarg.h"
+#include "vkLayer.h"
+
+
+typedef struct VkLayerDebugMarkerDispatchTable_
+{
+
+    PFN_vkCmdDbgMarkerBegin CmdDbgMarkerBegin;
+    PFN_vkCmdDbgMarkerEnd CmdDbgMarkerEnd;
+    PFN_vkDbgSetObjectTag DbgSetObjectTag;
+    PFN_vkDbgSetObjectName DbgSetObjectName;
+    bool ext_enabled;
+} VkLayerDebugMarkerDispatchTable;
diff --git a/layers/draw_state.cpp b/layers/draw_state.cpp
index 61f8804..54f6813 100644
--- a/layers/draw_state.cpp
+++ b/layers/draw_state.cpp
@@ -40,6 +40,7 @@
 #include "vk_struct_size_helper.h"
 #include "draw_state.h"
 #include "layers_config.h"
+#include "vk_debug_marker_layer.h"
 // The following is #included again to catch certain OS-specific functions
 // being used:
 #include "loader_platform.h"
@@ -59,6 +60,7 @@
 unordered_map<VkFramebuffer, VkFramebufferCreateInfo*> frameBufferMap;
 
 static std::unordered_map<void *, VkLayerDispatchTable *> tableMap;
+static std::unordered_map<void *, VkLayerDebugMarkerDispatchTable *> tableDebugMarkerMap;
 static std::unordered_map<void *, VkLayerInstanceDispatchTable *> tableInstanceMap;
 
 static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
@@ -1443,6 +1445,7 @@
 static VkLayerDispatchTable * initDeviceTable(const VkBaseLayerObject *devw)
 {
     VkLayerDispatchTable *pTable;
+    VkLayerDebugMarkerDispatchTable *pDebugMarkerTable;
 
     assert(devw);
     VkLayerDispatchTable **ppDisp = (VkLayerDispatchTable **) (devw->baseObject);
@@ -1452,12 +1455,21 @@
     {
         pTable =  new VkLayerDispatchTable;
         tableMap[(void *) *ppDisp] = pTable;
+        pDebugMarkerTable = new VkLayerDebugMarkerDispatchTable;
+        tableDebugMarkerMap[(void *) *ppDisp] = pDebugMarkerTable;
     } else
     {
         return it->second;
     }
 
-    layer_initialize_dispatch_table(pTable, (PFN_vkGetDeviceProcAddr) devw->pGPA, (VkDevice) devw->nextObject);
+    VkDevice device = (VkDevice) devw->nextObject;
+    layer_initialize_dispatch_table(pTable, (PFN_vkGetDeviceProcAddr) devw->pGPA, device);
+
+    pDebugMarkerTable->CmdDbgMarkerBegin = (PFN_vkCmdDbgMarkerBegin) devw->pGPA(device, "vkCmdDbgMarkerBegin");
+    pDebugMarkerTable->CmdDbgMarkerEnd = (PFN_vkCmdDbgMarkerEnd) devw->pGPA(device, "vkCmdDbgMarkerEnd");
+    pDebugMarkerTable->DbgSetObjectTag = (PFN_vkDbgSetObjectTag) devw->pGPA(device, "vkDbgSetObjectTag");
+    pDebugMarkerTable->DbgSetObjectName = (PFN_vkDbgSetObjectName) devw->pGPA(device, "vkDbgSetObjectName");
+    pDebugMarkerTable->ext_enabled = false;
 
     return pTable;
 }
@@ -1523,11 +1535,27 @@
     return res;
 }
 
+static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
+{
+    uint32_t i, ext_idx;
+    VkLayerDebugMarkerDispatchTable *pDisp =  *(VkLayerDebugMarkerDispatchTable **) device;
+    VkLayerDebugMarkerDispatchTable *pTable = tableDebugMarkerMap[pDisp];
+
+    for (i = 0; i < pCreateInfo->extensionCount; i++) {
+        if (strcmp(pCreateInfo->pEnabledExtensions[i].name, DEBUG_MARKER_EXTENSION_NAME) == 0) {
+            /* Found a matching extension name, mark it enabled */
+            pTable->ext_enabled = true;
+        }
+
+    }
+}
+
 VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
 {
     VkLayerInstanceDispatchTable **ppDisp = (VkLayerInstanceDispatchTable **) gpu;
     VkLayerInstanceDispatchTable* pInstTable = tableInstanceMap[*ppDisp];
     VkResult result = pInstTable->CreateDevice(gpu, pCreateInfo, pDevice);
+    createDeviceRegisterExtensions(pCreateInfo, *pDevice);
     return result;
 }
 
@@ -1568,6 +1596,7 @@
     }
 };
 
+//TODO add DEBUG_MARKER to device extension list
 VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
         VkExtensionInfoType infoType,
         uint32_t extensionIndex,
@@ -2788,7 +2817,14 @@
 VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
 {
     GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
-    if (pCB) {
+    VkLayerDebugMarkerDispatchTable *pDisp =  *(VkLayerDebugMarkerDispatchTable **) cmdBuffer;
+    VkLayerDebugMarkerDispatchTable *pTable = tableDebugMarkerMap[pDisp];
+    if (!pTable->ext_enabled) {
+        char str[1024];
+        sprintf(str, "Attempt to use CmdDbgMarkerBegin but extension disabled!");
+        layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS", str);
+    }
+    else if (pCB) {
         updateCBTracking(cmdBuffer);
         addCmd(pCB, CMD_DBGMARKERBEGIN);
     }
@@ -2797,15 +2833,20 @@
         sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
         layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
     }
-    VkLayerDispatchTable *pDisp =  *(VkLayerDispatchTable **) cmdBuffer;
-    VkLayerDispatchTable *pTable = tableMap[pDisp];
     pTable->CmdDbgMarkerBegin(cmdBuffer, pMarker);
 }
 
 VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
 {
     GLOBAL_CB_NODE* pCB = getCBNode(cmdBuffer);
-    if (pCB) {
+    VkLayerDebugMarkerDispatchTable *pDisp =  *(VkLayerDebugMarkerDispatchTable **) cmdBuffer;
+    VkLayerDebugMarkerDispatchTable *pTable = tableDebugMarkerMap[pDisp];
+    if (!pTable->ext_enabled) {
+        char str[1024];
+        sprintf(str, "Attempt to use CmdDbgMarkerEnd but extension disabled!");
+        layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_EXTENSION, "DS", str);
+    }
+    else if (pCB) {
         updateCBTracking(cmdBuffer);
         addCmd(pCB, CMD_DBGMARKEREND);
     }
@@ -2814,8 +2855,6 @@
         sprintf(str, "Attempt to use CmdBuffer %p that doesn't exist!", (void*)cmdBuffer);
         layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, DRAWSTATE_INVALID_CMD_BUFFER, "DS", str);
     }
-    VkLayerDispatchTable *pDisp =  *(VkLayerDispatchTable **) cmdBuffer;
-    VkLayerDispatchTable *pTable = tableMap[pDisp];
     pTable->CmdDbgMarkerEnd(cmdBuffer);
 }
 
diff --git a/layers/draw_state.h b/layers/draw_state.h
index d56f2db..73dfc14 100644
--- a/layers/draw_state.h
+++ b/layers/draw_state.h
@@ -51,6 +51,7 @@
     DRAWSTATE_RASTER_NOT_BOUND,                 // Draw submitted with no raster state object bound
     DRAWSTATE_COLOR_BLEND_NOT_BOUND,            // Draw submitted with no color blend state object bound when color write enabled
     DRAWSTATE_DEPTH_STENCIL_NOT_BOUND,          // Draw submitted with no depth-stencil state object bound when depth write enabled
+    DRAWSTATE_INVALID_EXTENSION
 } DRAW_STATE_ERROR;
 
 typedef enum _DRAW_TYPE
diff --git a/layers/param_checker.cpp b/layers/param_checker.cpp
index 3f5af68..c45b743 100644
--- a/layers/param_checker.cpp
+++ b/layers/param_checker.cpp
@@ -32,6 +32,7 @@
 
 #include "loader_platform.h"
 #include "vkLayer.h"
+#include "vk_debug_marker_layer.h"
 #include "layers_config.h"
 #include "vk_enum_validate_helper.h"
 #include "vk_struct_validate_helper.h"
@@ -41,6 +42,7 @@
 #include "layers_msg.h"
 
 static VkLayerDispatchTable nextTable;
+static VkLayerDebugMarkerDispatchTable nextDebugMarkerTable;
 static VkLayerInstanceDispatchTable nextInstanceTable;
 static VkBaseLayerObject *pCurObj;
 static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(initOnce);
@@ -53,9 +55,15 @@
 static void initDeviceTable(void)
 {
     PFN_vkGetDeviceProcAddr fpNextGPA;
+    VkDevice device = (VkDevice) pCurObj->nextObject;
     fpNextGPA = (PFN_vkGetDeviceProcAddr) pCurObj->pGPA;
     assert(fpNextGPA);
-    layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkDevice) pCurObj->nextObject);
+    layer_initialize_dispatch_table(&nextTable, fpNextGPA, device);
+
+    nextDebugMarkerTable.CmdDbgMarkerBegin = (PFN_vkCmdDbgMarkerBegin) fpNextGPA(device, "vkCmdDbgMarkerBegin");
+    nextDebugMarkerTable.CmdDbgMarkerEnd = (PFN_vkCmdDbgMarkerEnd) fpNextGPA(device, "vkCmdDbgMarkerEnd");
+    nextDebugMarkerTable.DbgSetObjectTag = (PFN_vkDbgSetObjectTag) fpNextGPA(device, "vkDbgSetObjectTag");
+    nextDebugMarkerTable.DbgSetObjectName = (PFN_vkDbgSetObjectName) fpNextGPA(device, "vkDbgSetObjectName");
 }
 
 static void initInstanceTable(void)
@@ -224,6 +232,21 @@
 
 }
 
+static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
+{
+    uint32_t i, ext_idx;
+    VkLayerDebugMarkerDispatchTable *pDisp =  *(VkLayerDebugMarkerDispatchTable **) device;
+    VkLayerDebugMarkerDispatchTable *pTable = &nextDebugMarkerTable;
+
+    for (i = 0; i < pCreateInfo->extensionCount; i++) {
+        if (strcmp(pCreateInfo->pEnabledExtensions[i].name, DEBUG_MARKER_EXTENSION_NAME) == 0) {
+            /* Found a matching extension name, mark it enabled */
+            pTable->ext_enabled = true;
+        }
+
+    }
+}
+
 void PostCreateDevice(VkResult result, const VkDeviceCreateInfo *pCreateInfo, VkDevice* pDevice)
 {
     if(result != VK_SUCCESS)
@@ -235,6 +258,7 @@
     }
 
     enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->pEnabledExtensions);
+    createDeviceRegisterExtensions(pCreateInfo, *pDevice);
 
     if(pDevice == nullptr)
     {
@@ -311,6 +335,7 @@
                                                size_t*  pDataSize,
                                                void*    pData)
 {
+    //TODO add DEBUG_MARKER to extension list
     VkResult result = nextInstanceTable.GetPhysicalDeviceExtensionInfo(gpu, infoType, extensionIndex, pDataSize, pData);
     return result;
 }
@@ -1828,14 +1853,46 @@
 
 VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
 {
-
-    nextTable.CmdDbgMarkerBegin(cmdBuffer, pMarker);
+    //VkLayerDebugMarkerDispatchTable *pDisp =  *(VkLayerDebugMarkerDispatchTable **) cmdBuffer;
+    VkLayerDebugMarkerDispatchTable *pTable = &nextDebugMarkerTable;
+    if (!pTable->ext_enabled) {
+        char const str[] = "Attempt to use CmdDbgMarkerBegin but extension disabled!";
+        layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, 1, "PARAMCHECK", str);
+    }
+    nextDebugMarkerTable.CmdDbgMarkerBegin(cmdBuffer, pMarker);
 }
 
 VK_LAYER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
 {
+    //VkLayerDebugMarkerDispatchTable *pDisp =  *(VkLayerDebugMarkerDispatchTable **) cmdBuffer;
+    VkLayerDebugMarkerDispatchTable *pTable = &nextDebugMarkerTable;
+    if (!pTable->ext_enabled) {
+        char const str[] = "Attempt to use CmdDbgMarkerEnd but extension disabled!";
+        layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, 1, "PARAMCHECK", str);
+    }
+    nextDebugMarkerTable.CmdDbgMarkerEnd(cmdBuffer);
+}
 
-    nextTable.CmdDbgMarkerEnd(cmdBuffer);
+VkResult VKAPI vkDbgSetObjectTag(VkDevice device, VkObjectType  objType, VkObject object, size_t tagSize, const void* pTag)
+{
+    //VkLayerDebugMarkerDispatchTable *pDisp =  *(VkLayerDebugMarkerDispatchTable **) cmdBuffer;
+    VkLayerDebugMarkerDispatchTable *pTable = &nextDebugMarkerTable;
+    if (!pTable->ext_enabled) {
+        char const str[] = "Attempt to use DbgSetObjectTag but extension disabled!";
+        layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, 1, "PARAMCHECK", str);
+    }
+    nextDebugMarkerTable.DbgSetObjectTag(device, objType, object, tagSize, pTag);
+}
+
+VkResult VKAPI vkDbgSetObjectName(VkDevice device, VkObjectType  objType, VkObject object, size_t nameSize, const char* pName)
+{
+    //VkLayerDebugMarkerDispatchTable *pDisp =  *(VkLayerDebugMarkerDispatchTable **) cmdBuffer;
+    VkLayerDebugMarkerDispatchTable *pTable = &nextDebugMarkerTable;
+    if (!pTable->ext_enabled) {
+        char const str[] = "Attempt to use DbgSetObjectName but extension disabled!";
+        layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, NULL, 0, 1, "PARAMCHECK", str);
+    }
+    nextDebugMarkerTable.DbgSetObjectName(device, objType, object, nameSize, pName);
 }
 
 VK_LAYER_EXPORT VkResult VKAPI vkGetDisplayInfoWSI(VkDisplayWSI display, VkDisplayInfoTypeWSI infoType, size_t* pDataSize, void* pData)
diff --git a/loader/loader.c b/loader/loader.c
index 0801ab2..08dd8a3 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -887,6 +887,9 @@
         if (strcmp(loader.loaded_layer_lib_list[i].lib_name, ext_prop->lib_name) == 0) {
             /* Have already loaded this library, just increment ref count */
             loader.loaded_layer_lib_list[i].ref_count++;
+            loader_log(VK_DBG_REPORT_INFO_BIT, 0,
+                       "Inserting instance layer %s from library %s",
+                       ext_prop->info.name, ext_prop->lib_name);
             return loader.loaded_layer_lib_list[i].lib_handle;
         }
     }
diff --git a/loader/table_ops.h b/loader/table_ops.h
index 10fadb2..1fb624b 100644
--- a/loader/table_ops.h
+++ b/loader/table_ops.h
@@ -136,9 +136,6 @@
     table->CreateRenderPass = (PFN_vkCreateRenderPass) gpa(dev, "vkCreateRenderPass");
     table->CmdBeginRenderPass = (PFN_vkCmdBeginRenderPass) gpa(dev, "vkCmdBeginRenderPass");
     table->CmdEndRenderPass = (PFN_vkCmdEndRenderPass) gpa(dev, "vkCmdEndRenderPass");
-    table->DbgSetObjectTag = (PFN_vkDbgSetObjectTag) gpa(dev, "vkDbgSetObjectTag");
-    table->CmdDbgMarkerBegin = (PFN_vkCmdDbgMarkerBegin) gpa(dev, "vkCmdDbgMarkerBegin");
-    table->CmdDbgMarkerEnd = (PFN_vkCmdDbgMarkerEnd) gpa(dev, "vkCmdDbgMarkerEnd");
 //TODO move into it's own table
     table->CreateSwapChainWSI = (PFN_vkCreateSwapChainWSI) gpa(dev, "vkCreateSwapChainWSI");
     table->DestroySwapChainWSI = (PFN_vkDestroySwapChainWSI) gpa(dev, "vkDestroySwapChainWSI");
@@ -362,12 +359,6 @@
         return (void *) table->CmdBeginRenderPass;
     if (!strcmp(name, "CmdEndRenderPass"))
         return (void *) table->CmdEndRenderPass;
-    if (!strcmp(name, "DbgSetObjectTag"))
-        return (void *) table->DbgSetObjectTag;
-    if (!strcmp(name, "CmdDbgMarkerBegin"))
-        return (void *) table->CmdDbgMarkerBegin;
-    if (!strcmp(name, "CmdDbgMarkerEnd"))
-        return (void *) table->CmdDbgMarkerEnd;
 //TODO put in it's own table
     if (!strcmp(name, "CreateSwapChainWSI"))
         return (void *) table->CreateSwapChainWSI;
diff --git a/loader/trampoline.c b/loader/trampoline.c
index 2a54345..8503971 100644
--- a/loader/trampoline.c
+++ b/loader/trampoline.c
@@ -1162,34 +1162,3 @@
 
     disp->CmdEndRenderPass(cmdBuffer, renderPass);
 }
-
-LOADER_EXPORT void VKAPI vkCmdDbgMarkerBegin(VkCmdBuffer cmdBuffer, const char* pMarker)
-{
-    const VkLayerDispatchTable *disp;
-
-    disp = loader_get_dispatch(cmdBuffer);
-
-    disp->CmdDbgMarkerBegin(cmdBuffer, pMarker);
-}
-
-LOADER_EXPORT void VKAPI vkCmdDbgMarkerEnd(VkCmdBuffer cmdBuffer)
-{
-    const VkLayerDispatchTable *disp;
-
-    disp = loader_get_dispatch(cmdBuffer);
-
-    disp->CmdDbgMarkerEnd(cmdBuffer);
-}
-
-LOADER_EXPORT VkResult VKAPI vkQueuePresentWSI(VkQueue queue, const VkPresentInfoWSI* pPresentInfo)
-{
-    const VkLayerDispatchTable *disp;
-
-    disp = loader_get_dispatch(queue);
-
-    return disp->QueuePresentWSI(queue, pPresentInfo);
-}
-
-#if defined(WIN32)
-#pragma optimize( "", on )
-#endif