loader: Remove extension enable checks
authorMark Young <marky@lunarg.com>
Fri, 9 Sep 2016 00:36:32 +0000 (18:36 -0600)
committerMark Young <marky@lunarg.com>
Fri, 9 Sep 2016 00:36:32 +0000 (18:36 -0600)
Apparently, the intent of Vulkan is to have the loader do no
run-time checking in each of the functions as to whether or not
the extension is enabled.  This should only be done in the
validation layers.

This resolves the crash Jeff was seeing in the Nvidia driver when
using the new extension.

Change-Id: Ic90db0bde062d6b2511954abb8677f9f20bb4285

loader/extensions.c
loader/extensions.h
loader/loader.c
loader/loader.h
loader/wsi.c
loader/wsi.h

index 4749e20..fd7e0ec 100644 (file)
 #include "extensions.h"
 #include <vulkan/vk_icd.h>
 
-// Definitions for EXT_debug_marker extension
-
-VKAPI_ATTR VkResult VKAPI_CALL vkDebugMarkerSetObjectTagEXT(
-    VkDevice device, VkDebugMarkerObjectTagInfoEXT *pTagInfo) {
-    struct loader_dev_dispatch_table *disp = loader_get_dev_dispatch(device);
-    if (0 == disp->enabled_known_extensions.ext_debug_marker ||
-        NULL == disp->core_dispatch.DebugMarkerSetObjectTagEXT) {
-        return VK_ERROR_EXTENSION_NOT_PRESENT;
-    } else {
-        return disp->core_dispatch.DebugMarkerSetObjectTagEXT(device, pTagInfo);
-    }
-}
-
-VKAPI_ATTR VkResult VKAPI_CALL vkDebugMarkerSetObjectNameEXT(
-    VkDevice device, VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
-    struct loader_dev_dispatch_table *disp = loader_get_dev_dispatch(device);
-    if (0 == disp->enabled_known_extensions.ext_debug_marker ||
-        NULL == disp->core_dispatch.DebugMarkerSetObjectNameEXT) {
-        return VK_ERROR_EXTENSION_NOT_PRESENT;
-    } else {
-        return disp->core_dispatch.DebugMarkerSetObjectNameEXT(device,
-                                                               pNameInfo);
-    }
-}
-
-VKAPI_ATTR void VKAPI_CALL vkCmdDebugMarkerBeginEXT(
-    VkCommandBuffer commandBuffer, VkDebugMarkerMarkerInfoEXT *pMarkerInfo) {
-    struct loader_dev_dispatch_table *disp =
-        loader_get_dev_dispatch(commandBuffer);
-    if (1 == disp->enabled_known_extensions.ext_debug_marker &&
-        NULL != disp->core_dispatch.CmdDebugMarkerBeginEXT) {
-        disp->core_dispatch.CmdDebugMarkerBeginEXT(commandBuffer, pMarkerInfo);
-    }
-}
-
-VKAPI_ATTR void VKAPI_CALL
-vkCmdDebugMarkerEndEXT(VkCommandBuffer commandBuffer) {
-    struct loader_dev_dispatch_table *disp =
-        loader_get_dev_dispatch(commandBuffer);
-    if (1 == disp->enabled_known_extensions.ext_debug_marker &&
-        NULL != disp->core_dispatch.CmdDebugMarkerEndEXT) {
-        disp->core_dispatch.CmdDebugMarkerEndEXT(commandBuffer);
-    }
-}
-
-VKAPI_ATTR void VKAPI_CALL vkCmdDebugMarkerInsertEXT(
-    VkCommandBuffer commandBuffer, VkDebugMarkerMarkerInfoEXT *pMarkerInfo) {
-    struct loader_dev_dispatch_table *disp =
-        loader_get_dev_dispatch(commandBuffer);
-    if (1 == disp->enabled_known_extensions.ext_debug_marker &&
-        NULL != disp->core_dispatch.CmdDebugMarkerInsertEXT) {
-        disp->core_dispatch.CmdDebugMarkerInsertEXT(commandBuffer, pMarkerInfo);
-    }
-}
-
 // Definitions for the VK_NV_external_memory_capabilities extension
 
 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
@@ -90,27 +35,16 @@ vkGetPhysicalDeviceExternalImageFormatPropertiesNV(
     VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags,
     VkExternalMemoryHandleTypeFlagsNV externalHandleType,
     VkExternalImageFormatPropertiesNV *pExternalImageFormatProperties) {
-
     const VkLayerInstanceDispatchTable *disp;
     struct loader_physical_device_tramp *phys_dev =
         (struct loader_physical_device_tramp *)physicalDevice;
-    struct loader_instance *inst = phys_dev->this_instance;
     VkPhysicalDevice unwrapped_phys_dev =
         loader_unwrap_physical_device(physicalDevice);
     disp = loader_get_instance_dispatch(physicalDevice);
 
-    if (0 == inst->enabled_known_extensions.nv_external_memory_capabilities ||
-        NULL == disp->GetPhysicalDeviceExternalImageFormatPropertiesNV) {
-        loader_log(
-            inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0,
-            "vkGetPhysicalDeviceExternalImageFormatPropertiesNV called without"
-            " NV_external_memory_capabilities extension being enabled");
-        return VK_ERROR_EXTENSION_NOT_PRESENT;
-    } else {
-        return disp->GetPhysicalDeviceExternalImageFormatPropertiesNV(
-            unwrapped_phys_dev, format, type, tiling, usage, flags,
-            externalHandleType, pExternalImageFormatProperties);
-    }
+    return disp->GetPhysicalDeviceExternalImageFormatPropertiesNV(
+        unwrapped_phys_dev, format, type, tiling, usage, flags,
+        externalHandleType, pExternalImageFormatProperties);
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL
@@ -152,28 +86,19 @@ VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndirectCountAMD(
     VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
     VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
     uint32_t stride) {
-    struct loader_dev_dispatch_table *disp =
-        loader_get_dev_dispatch(commandBuffer);
-    if (1 == disp->enabled_known_extensions.amd_draw_indirect_count &&
-        NULL != disp->core_dispatch.CmdDrawIndirectCountAMD) {
-        disp->core_dispatch.CmdDrawIndirectCountAMD(
-            commandBuffer, buffer, offset, countBuffer, countBufferOffset,
-            maxDrawCount, stride);
-    }
+    const VkLayerDispatchTable *disp = loader_get_dispatch(commandBuffer);
+    disp->CmdDrawIndirectCountAMD(commandBuffer, buffer, offset, countBuffer,
+                                  countBufferOffset, maxDrawCount, stride);
 }
 
 VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirectCountAMD(
     VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
     VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
     uint32_t stride) {
-    struct loader_dev_dispatch_table *disp =
-        loader_get_dev_dispatch(commandBuffer);
-    if (1 == disp->enabled_known_extensions.amd_draw_indirect_count &&
-        NULL != disp->core_dispatch.CmdDrawIndexedIndirectCountAMD) {
-        disp->core_dispatch.CmdDrawIndexedIndirectCountAMD(
-            commandBuffer, buffer, offset, countBuffer, countBufferOffset,
-            maxDrawCount, stride);
-    }
+    const VkLayerDispatchTable *disp = loader_get_dispatch(commandBuffer);
+    disp->CmdDrawIndexedIndirectCountAMD(commandBuffer, buffer, offset,
+                                         countBuffer, countBufferOffset,
+                                         maxDrawCount, stride);
 }
 
 #ifdef VK_USE_PLATFORM_WIN32_KHR
@@ -183,14 +108,8 @@ VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirectCountAMD(
 VKAPI_ATTR VkResult VKAPI_CALL vkGetMemoryWin32HandleNV(
     VkDevice device, VkDeviceMemory memory,
     VkExternalMemoryHandleTypeFlagsNV handleType, HANDLE *pHandle) {
-    struct loader_dev_dispatch_table *disp = loader_get_dev_dispatch(device);
-    if (0 == disp->enabled_known_extensions.nv_external_memory_win32 ||
-        NULL == disp->core_dispatch.GetMemoryWin32HandleNV) {
-        return VK_ERROR_EXTENSION_NOT_PRESENT;
-    } else {
-        return disp->core_dispatch.GetMemoryWin32HandleNV(device, memory,
-                                                          handleType, pHandle);
-    }
+    const VkLayerDispatchTable *disp = loader_get_dispatch(device);
+    return disp->GetMemoryWin32HandleNV(device, memory, handleType, pHandle);
 }
 
 #endif // VK_USE_PLATFORM_WIN32_KHR
@@ -201,29 +120,6 @@ bool extension_instance_gpa(struct loader_instance *ptr_instance,
                             const char *name, void **addr) {
     *addr = NULL;
 
-    // Functions for the EXT_debug_marker extension
-
-    if (!strcmp("vkDebugMarkerSetObjectTagEXT", name)) {
-        *addr = (void *)vkDebugMarkerSetObjectTagEXT;
-        return true;
-    }
-    if (!strcmp("vkDebugMarkerSetObjectNameEXT", name)) {
-        *addr = (void *)vkDebugMarkerSetObjectNameEXT;
-        return true;
-    }
-    if (!strcmp("vkCmdDebugMarkerBeginEXT", name)) {
-        *addr = (void *)vkCmdDebugMarkerBeginEXT;
-        return true;
-    }
-    if (!strcmp("vkCmdDebugMarkerEndEXT", name)) {
-        *addr = (void *)vkCmdDebugMarkerEndEXT;
-        return true;
-    }
-    if (!strcmp("vkCmdDebugMarkerInsertEXT", name)) {
-        *addr = (void *)vkCmdDebugMarkerInsertEXT;
-        return true;
-    }
-
     // Functions for the VK_NV_external_memory_capabilities extension
 
     if (!strcmp("vkGetPhysicalDeviceExternalImageFormatPropertiesNV", name)) {
@@ -234,29 +130,6 @@ bool extension_instance_gpa(struct loader_instance *ptr_instance,
         return true;
     }
 
-    // Functions for the VK_AMD_draw_indirect_count extension
-
-    if (!strcmp("vkCmdDrawIndirectCountAMD", name)) {
-        *addr = (void *)vkCmdDrawIndirectCountAMD;
-        return true;
-    }
-
-    if (!strcmp("vkCmdDrawIndexedIndirectCountAMD", name)) {
-        *addr = (void *)vkCmdDrawIndexedIndirectCountAMD;
-        return true;
-    }
-
-#ifdef VK_USE_PLATFORM_WIN32_KHR
-
-    // Functions for the VK_NV_external_memory_win32 extension
-
-    if (!strcmp("vkGetMemoryWin32HandleNV", name)) {
-        *addr = (void *)vkGetMemoryWin32HandleNV;
-        return true;
-    }
-
-#endif // VK_USE_PLATFORM_WIN32_KHR
-
     return false;
 }
 
@@ -273,34 +146,3 @@ void extensions_create_instance(struct loader_instance *ptr_instance,
         }
     }
 }
-
-void extensions_create_device(struct loader_device *dev,
-                              const VkDeviceCreateInfo *pCreateInfo) {
-    dev->loader_dispatch.enabled_known_extensions.ext_debug_marker = 0;
-    dev->loader_dispatch.enabled_known_extensions.amd_draw_indirect_count = 0;
-    dev->loader_dispatch.enabled_known_extensions.nv_external_memory_win32 = 0;
-
-    for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
-        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
-                   VK_EXT_DEBUG_MARKER_EXTENSION_NAME) == 0) {
-            dev->loader_dispatch.enabled_known_extensions.ext_debug_marker = 1;
-            return;
-        }
-
-        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
-                   VK_AMD_EXTENSION_DRAW_INDIRECT_COUNT_EXTENSION_NAME) == 0) {
-            dev->loader_dispatch.enabled_known_extensions
-                .amd_draw_indirect_count = 1;
-            return;
-        }
-
-#ifdef VK_USE_PLATFORM_WIN32_KHR
-        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
-                   VK_NV_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME) == 0) {
-            dev->loader_dispatch.enabled_known_extensions
-                .nv_external_memory_win32 = 1;
-            return;
-        }
-#endif // VK_USE_PLATFORM_WIN32_KHR
-    }
-}
index c84fd86..651d5f5 100644 (file)
@@ -28,9 +28,6 @@ bool extension_instance_gpa(struct loader_instance *ptr_instance,
 void extensions_create_instance(struct loader_instance *ptr_instance,
                                 const VkInstanceCreateInfo *pCreateInfo);
 
-void extensions_create_device(struct loader_device *dev,
-                              const VkDeviceCreateInfo *pCreateInfo);
-
 // Definitions for the VK_NV_external_memory_capabilities extension
 
 VKAPI_ATTR VkResult VKAPI_CALL
index 5a347db..92afbe1 100644 (file)
@@ -4324,9 +4324,6 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDevice(
         }
     }
 
-    wsi_create_device(dev, pCreateInfo);
-    extensions_create_device(dev, pCreateInfo);
-
     // TODO: Why does fpCreateDevice behave differently than
     // this_icd->CreateDevice?
     //    VkResult res = fpCreateDevice(phys_dev->phys_dev, &localCreateInfo,
index 651d507..19d28e1 100644 (file)
@@ -158,20 +158,9 @@ struct loader_dev_ext_dispatch_table {
     PFN_vkDevExt dev_ext[MAX_NUM_DEV_EXTS];
 };
 
-union loader_device_extension_enables {
-    struct {
-        uint8_t khr_display_swapchain       : 1;
-        uint8_t ext_debug_marker            : 1;
-        uint8_t amd_draw_indirect_count     : 1;
-        uint8_t nv_external_memory_win32    : 1;
-    };
-    uint64_t padding[4];
-};
-
 struct loader_dev_dispatch_table {
     VkLayerDispatchTable core_dispatch;
     struct loader_dev_ext_dispatch_table ext_dispatch;
-    union loader_device_extension_enables enabled_known_extensions;
 };
 
 // per CreateDevice structure
index 13d3004..a74cdb4 100644 (file)
@@ -158,20 +158,6 @@ void wsi_create_instance(struct loader_instance *ptr_instance,
     }
 }
 
-void wsi_create_device(struct loader_device *dev,
-    const VkDeviceCreateInfo *pCreateInfo) {
-    dev->loader_dispatch.enabled_known_extensions.khr_display_swapchain = 0;
-
-    for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
-        if (strcmp(pCreateInfo->ppEnabledExtensionNames[i],
-                   VK_KHR_DISPLAY_SWAPCHAIN_EXTENSION_NAME) == 0) {
-            dev->loader_dispatch.enabled_known_extensions
-                .khr_display_swapchain = 1;
-            return;
-        }
-    }
-}
-
 // Linux WSI surface extensions are not always compiled into the loader. (Assume
 // for Windows the KHR_win32_surface is always compiled into loader). A given
 // Linux build environment might not have the headers required for building one
@@ -1278,14 +1264,9 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSharedSwapchainsKHR(
     VkDevice device, uint32_t swapchainCount,
     const VkSwapchainCreateInfoKHR *pCreateInfos,
     const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchains) {
-    struct loader_dev_dispatch_table *disp = loader_get_dev_dispatch(device);
-    if (0 == disp->enabled_known_extensions.khr_display_swapchain ||
-        NULL == disp->core_dispatch.CreateSharedSwapchainsKHR) {
-        return VK_ERROR_EXTENSION_NOT_PRESENT;
-    } else {
-        return disp->core_dispatch.CreateSharedSwapchainsKHR(
-            device, swapchainCount, pCreateInfos, pAllocator, pSwapchains);
-    }
+    const VkLayerDispatchTable *disp;
+    disp = loader_get_dispatch(device);
+    return disp->CreateSharedSwapchainsKHR(device, swapchainCount, pCreateInfos, pAllocator, pSwapchains);
 }
 
 bool wsi_swapchain_instance_gpa(struct loader_instance *ptr_instance,
index 7409e7d..fa60088 100644 (file)
@@ -27,8 +27,6 @@ bool wsi_swapchain_instance_gpa(struct loader_instance *ptr_instance,
 
 void wsi_create_instance(struct loader_instance *ptr_instance,
                          const VkInstanceCreateInfo *pCreateInfo);
-void wsi_create_device(struct loader_device *dev,
-                       const VkDeviceCreateInfo *pCreateInfo);
 bool wsi_unsupported_instance_extension(const VkExtensionProperties *ext_prop);
 
 VKAPI_ATTR void VKAPI_CALL