Fix Vulkan null driver
authorPyry Haulos <phaulos@google.com>
Thu, 18 May 2017 22:42:53 +0000 (15:42 -0700)
committerPyry Haulos <phaulos@google.com>
Thu, 18 May 2017 22:42:53 +0000 (15:42 -0700)
Vulkan platform was changed to use vkGetInstanceProcAddr(NULL, pName)
for loading all platform-level functions, except vkGetInstanceProcAddr
itself, in commit bbd3dce44fafaa4b1952b63564022f19b3a65ca3. Null
driver was not adjusted for that change and that resulted calling into
null function pointer early in the initialization code.

Additionally, null driver now advertises HOST_COHERENT memory.

Change-Id: I65c8b37722950de08e337d7df95aa46a0e826c7b

external/vulkancts/framework/vulkan/vkNullDriver.cpp

index eae9a3f..c25f3c3 100644 (file)
@@ -462,11 +462,6 @@ void DescriptorPool::reset (void)
 extern "C"
 {
 
-VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL getInstanceProcAddr (VkInstance instance, const char* pName)
-{
-       return reinterpret_cast<Instance*>(instance)->getProcAddr(pName);
-}
-
 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL getDeviceProcAddr (VkDevice device, const char* pName)
 {
        return reinterpret_cast<Device*>(device)->getProcAddr(pName);
@@ -743,7 +738,9 @@ VKAPI_ATTR void VKAPI_CALL getPhysicalDeviceMemoryProperties (VkPhysicalDevice,
 
        props->memoryTypeCount                          = 1u;
        props->memoryTypes[0].heapIndex         = 0u;
-       props->memoryTypes[0].propertyFlags     = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
+       props->memoryTypes[0].propertyFlags     = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
+                                                                               | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
+                                                                               | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
 
        props->memoryHeapCount                          = 1u;
        props->memoryHeaps[0].size                      = 1ull << 31;
@@ -950,8 +947,35 @@ VKAPI_ATTR VkResult VKAPI_CALL createSharedSwapchainsKHR (VkDevice device, deUin
        return VK_SUCCESS;
 }
 
+// \note getInstanceProcAddr is a little bit special:
+// vkNullDriverImpl.inl needs it to define s_platformFunctions but
+// getInstanceProcAddr() implementation needs other entry points from
+// vkNullDriverImpl.inl.
+VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL getInstanceProcAddr (VkInstance instance, const char* pName);
+
 #include "vkNullDriverImpl.inl"
 
+VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL getInstanceProcAddr (VkInstance instance, const char* pName)
+{
+       if (instance)
+       {
+               return reinterpret_cast<Instance*>(instance)->getProcAddr(pName);
+       }
+       else
+       {
+               const std::string       name    = pName;
+
+               if (name == "vkCreateInstance")
+                       return (PFN_vkVoidFunction)createInstance;
+               else if (name == "vkEnumerateInstanceExtensionProperties")
+                       return (PFN_vkVoidFunction)enumerateInstanceExtensionProperties;
+               else if (name == "vkEnumerateInstanceLayerProperties")
+                       return (PFN_vkVoidFunction)enumerateInstanceLayerProperties;
+               else
+                       return (PFN_vkVoidFunction)DE_NULL;
+       }
+}
+
 } // extern "C"
 
 Instance::Instance (const VkInstanceCreateInfo*)