OSDN Git Service

vulkan: use Logger in the generated code
authorChia-I Wu <olv@google.com>
Wed, 4 May 2016 08:37:23 +0000 (16:37 +0800)
committerChia-I Wu <olv@google.com>
Fri, 6 May 2016 01:43:58 +0000 (09:43 +0800)
Except for INIT_PROC, where ALOGE is still used for layer/HAL bugs.

Bug: 28120066
Change-Id: Icd9ce99b6bfb77816b11c05f6c8b197a6782b7cd

vulkan/libvulkan/api_gen.cpp
vulkan/libvulkan/code-generator.tmpl
vulkan/libvulkan/driver_gen.cpp

index fe4136f..155a599 100644 (file)
@@ -51,56 +51,56 @@ namespace {
 
 // clang-format off
 
-VKAPI_ATTR void disabledDestroySurfaceKHR(VkInstance, VkSurfaceKHR, const VkAllocationCallbacks*) {
-    ALOGE("VK_KHR_surface not enabled. vkDestroySurfaceKHR not executed.");
+VKAPI_ATTR void disabledDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR, const VkAllocationCallbacks*) {
+    driver::Logger(instance).Err(instance, "VK_KHR_surface not enabled. Exported vkDestroySurfaceKHR not executed.");
 }
 
-VKAPI_ATTR VkResult disabledGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice, uint32_t, VkSurfaceKHR, VkBool32*) {
-    ALOGE("VK_KHR_surface not enabled. vkGetPhysicalDeviceSurfaceSupportKHR not executed.");
+VKAPI_ATTR VkResult disabledGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, uint32_t, VkSurfaceKHR, VkBool32*) {
+    driver::Logger(physicalDevice).Err(physicalDevice, "VK_KHR_surface not enabled. Exported vkGetPhysicalDeviceSurfaceSupportKHR not executed.");
     return VK_SUCCESS;
 }
 
-VKAPI_ATTR VkResult disabledGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice, VkSurfaceKHR, VkSurfaceCapabilitiesKHR*) {
-    ALOGE("VK_KHR_surface not enabled. vkGetPhysicalDeviceSurfaceCapabilitiesKHR not executed.");
+VKAPI_ATTR VkResult disabledGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR, VkSurfaceCapabilitiesKHR*) {
+    driver::Logger(physicalDevice).Err(physicalDevice, "VK_KHR_surface not enabled. Exported vkGetPhysicalDeviceSurfaceCapabilitiesKHR not executed.");
     return VK_SUCCESS;
 }
 
-VKAPI_ATTR VkResult disabledGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice, VkSurfaceKHR, uint32_t*, VkSurfaceFormatKHR*) {
-    ALOGE("VK_KHR_surface not enabled. vkGetPhysicalDeviceSurfaceFormatsKHR not executed.");
+VKAPI_ATTR VkResult disabledGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR, uint32_t*, VkSurfaceFormatKHR*) {
+    driver::Logger(physicalDevice).Err(physicalDevice, "VK_KHR_surface not enabled. Exported vkGetPhysicalDeviceSurfaceFormatsKHR not executed.");
     return VK_SUCCESS;
 }
 
-VKAPI_ATTR VkResult disabledGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice, VkSurfaceKHR, uint32_t*, VkPresentModeKHR*) {
-    ALOGE("VK_KHR_surface not enabled. vkGetPhysicalDeviceSurfacePresentModesKHR not executed.");
+VKAPI_ATTR VkResult disabledGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR, uint32_t*, VkPresentModeKHR*) {
+    driver::Logger(physicalDevice).Err(physicalDevice, "VK_KHR_surface not enabled. Exported vkGetPhysicalDeviceSurfacePresentModesKHR not executed.");
     return VK_SUCCESS;
 }
 
-VKAPI_ATTR VkResult disabledCreateSwapchainKHR(VkDevice, const VkSwapchainCreateInfoKHR*, const VkAllocationCallbacks*, VkSwapchainKHR*) {
-    ALOGE("VK_KHR_swapchain not enabled. vkCreateSwapchainKHR not executed.");
+VKAPI_ATTR VkResult disabledCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR*, const VkAllocationCallbacks*, VkSwapchainKHR*) {
+    driver::Logger(device).Err(device, "VK_KHR_swapchain not enabled. Exported vkCreateSwapchainKHR not executed.");
     return VK_SUCCESS;
 }
 
-VKAPI_ATTR void disabledDestroySwapchainKHR(VkDevice, VkSwapchainKHR, const VkAllocationCallbacks*) {
-    ALOGE("VK_KHR_swapchain not enabled. vkDestroySwapchainKHR not executed.");
+VKAPI_ATTR void disabledDestroySwapchainKHR(VkDevice device, VkSwapchainKHR, const VkAllocationCallbacks*) {
+    driver::Logger(device).Err(device, "VK_KHR_swapchain not enabled. Exported vkDestroySwapchainKHR not executed.");
 }
 
-VKAPI_ATTR VkResult disabledGetSwapchainImagesKHR(VkDevice, VkSwapchainKHR, uint32_t*, VkImage*) {
-    ALOGE("VK_KHR_swapchain not enabled. vkGetSwapchainImagesKHR not executed.");
+VKAPI_ATTR VkResult disabledGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR, uint32_t*, VkImage*) {
+    driver::Logger(device).Err(device, "VK_KHR_swapchain not enabled. Exported vkGetSwapchainImagesKHR not executed.");
     return VK_SUCCESS;
 }
 
-VKAPI_ATTR VkResult disabledAcquireNextImageKHR(VkDevice, VkSwapchainKHR, uint64_t, VkSemaphore, VkFence, uint32_t*) {
-    ALOGE("VK_KHR_swapchain not enabled. vkAcquireNextImageKHR not executed.");
+VKAPI_ATTR VkResult disabledAcquireNextImageKHR(VkDevice device, VkSwapchainKHR, uint64_t, VkSemaphore, VkFence, uint32_t*) {
+    driver::Logger(device).Err(device, "VK_KHR_swapchain not enabled. Exported vkAcquireNextImageKHR not executed.");
     return VK_SUCCESS;
 }
 
-VKAPI_ATTR VkResult disabledQueuePresentKHR(VkQueue, const VkPresentInfoKHR*) {
-    ALOGE("VK_KHR_swapchain not enabled. vkQueuePresentKHR not executed.");
+VKAPI_ATTR VkResult disabledQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR*) {
+    driver::Logger(queue).Err(queue, "VK_KHR_swapchain not enabled. Exported vkQueuePresentKHR not executed.");
     return VK_SUCCESS;
 }
 
-VKAPI_ATTR VkResult disabledCreateAndroidSurfaceKHR(VkInstance, const VkAndroidSurfaceCreateInfoKHR*, const VkAllocationCallbacks*, VkSurfaceKHR*) {
-    ALOGE("VK_KHR_android_surface not enabled. vkCreateAndroidSurfaceKHR not executed.");
+VKAPI_ATTR VkResult disabledCreateAndroidSurfaceKHR(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR*, const VkAllocationCallbacks*, VkSurfaceKHR*) {
+    driver::Logger(instance).Err(instance, "VK_KHR_android_surface not enabled. Exported vkCreateAndroidSurfaceKHR not executed.");
     return VK_SUCCESS;
 }
 
@@ -304,7 +304,7 @@ VKAPI_ATTR VkResult vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pP
 __attribute__((visibility("default")))
 VKAPI_ATTR PFN_vkVoidFunction vkGetDeviceProcAddr(VkDevice device, const char* pName) {
     if (device == VK_NULL_HANDLE) {
-        ALOGE("vkGetDeviceProcAddr called with invalid device");
+        ALOGE("invalid vkGetDeviceProcAddr(VK_NULL_HANDLE, ...) call");
         return nullptr;
     }
 
@@ -342,7 +342,9 @@ VKAPI_ATTR PFN_vkVoidFunction vkGetDeviceProcAddr(VkDevice device, const char* p
         std::binary_search(
             known_non_device_names, known_non_device_names + count, pName,
             [](const char* a, const char* b) { return (strcmp(a, b) < 0); })) {
-        ALOGE("vkGetDeviceProcAddr called with %s", (pName) ? pName : "(null)");
+        vulkan::driver::Logger(device).Err(
+            device, "invalid vkGetDeviceProcAddr(%p, \"%s\") call", device,
+            (pName) ? pName : "(null)");
         return nullptr;
     }
     // clang-format off
@@ -356,12 +358,12 @@ VKAPI_ATTR PFN_vkVoidFunction vkGetDeviceProcAddr(VkDevice device, const char* p
 __attribute__((visibility("default")))
 VKAPI_ATTR PFN_vkVoidFunction vkGetInstanceProcAddr(VkInstance instance, const char* pName) {
     // global functions
-    if (!instance) {
+    if (instance == VK_NULL_HANDLE) {
         if (strcmp(pName, "vkCreateInstance") == 0) return reinterpret_cast<PFN_vkVoidFunction>(vulkan::api::CreateInstance);
         if (strcmp(pName, "vkEnumerateInstanceLayerProperties") == 0) return reinterpret_cast<PFN_vkVoidFunction>(vulkan::api::EnumerateInstanceLayerProperties);
         if (strcmp(pName, "vkEnumerateInstanceExtensionProperties") == 0) return reinterpret_cast<PFN_vkVoidFunction>(vulkan::api::EnumerateInstanceExtensionProperties);
 
-        ALOGE("vkGetInstanceProcAddr called with %s without instance",  pName);
+        ALOGE("invalid vkGetInstanceProcAddr(VK_NULL_HANDLE, \"%s\") call", pName);
         return nullptr;
     }
 
@@ -510,8 +512,11 @@ VKAPI_ATTR PFN_vkVoidFunction vkGetInstanceProcAddr(VkInstance instance, const c
         hooks, hooks + count, pName,
         [](const Hook& h, const char* n) { return strcmp(h.name, n) < 0; });
     if (hook < hooks + count && strcmp(hook->name, pName) == 0) {
-        if (!hook->proc)
-            ALOGE("vkGetInstanceProcAddr called with %s with instance", pName);
+        if (!hook->proc) {
+            vulkan::driver::Logger(instance).Err(
+                instance, "invalid vkGetInstanceProcAddr(%p, \"%s\") call",
+                instance, pName);
+        }
         return hook->proc;
     }
     // clang-format off
index 3968371..1f70549 100644 (file)
@@ -482,10 +482,16 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
     {{$ext_name := index $ext.Arguments 0}}
 
     {{$base := (Macro "BaseName" $)}}
-    {{$unnamed_params := (ForEach $.CallParameters "ParameterType" | JoinWith ", ")}}
 
-    VKAPI_ATTR {{Node "Type" $.Return}} disabled{{$base}}({{$unnamed_params}}) {
-      ALOGE("{{$ext_name}} not enabled. {{$.Name}} not executed.");
+    {{$p0 := (index $.CallParameters 0)}}
+    {{$ptail := (Tail 1 $.CallParameters)}}
+
+    {{$first_type := (Macro "Parameter" $p0)}}
+    {{$tail_types := (ForEach $ptail "ParameterType" | JoinWith ", ")}}
+
+    VKAPI_ATTR {{Node "Type" $.Return}} disabled{{$base}}({{$first_type}}, {{$tail_types}}) {
+      driver::Logger({{$p0.Name}}).Err({{$p0.Name}}, §
+        "{{$ext_name}} not enabled. Exported {{$.Name}} not executed.");
       {{if not (IsVoid $.Return.Type)}}return VK_SUCCESS;{{end}}
     }
     ¶
@@ -502,7 +508,7 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
   {{AssertType $ "API"}}
 
   // global functions
-  if (!instance) {
+  if (instance == VK_NULL_HANDLE) {
     {{range $f := AllCommands $}}
       {{if (Macro "IsGloballyDispatched" $f)}}
         if (strcmp(pName, "{{$f.Name}}") == 0) return §
@@ -511,7 +517,7 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
       {{end}}
     {{end}}
     ¶
-    ALOGE("vkGetInstanceProcAddr called with %s without instance",  pName);
+    ALOGE("invalid vkGetInstanceProcAddr(VK_NULL_HANDLE, \"%s\") call", pName);
     return nullptr;
   }
   ¶
@@ -549,8 +555,11 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
     hooks, hooks + count, pName,
     [](const Hook& h, const char* n) { return strcmp(h.name, n) < 0; });
   if (hook <  hooks + count && strcmp(hook->name, pName) == 0) {
-    if (!hook->proc)
-      ALOGE("vkGetInstanceProcAddr called with %s with instance",  pName);
+    if (!hook->proc) {
+      vulkan::driver::Logger(instance).Err(
+        instance, "invalid vkGetInstanceProcAddr(%p, \"%s\") call",
+        instance, pName);
+    }
     return hook->proc;
   }
   // clang-format off
@@ -567,7 +576,7 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
   {{AssertType $ "API"}}
 
   if (device == VK_NULL_HANDLE) {
-    ALOGE("vkGetDeviceProcAddr called with invalid device");
+    ALOGE("invalid vkGetDeviceProcAddr(VK_NULL_HANDLE, ...) call");
     return nullptr;
   }
   ¶
@@ -587,7 +596,9 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
       std::binary_search(
         known_non_device_names, known_non_device_names + count, pName,
         [](const char* a, const char* b) { return (strcmp(a, b) < 0); })) {
-    ALOGE("vkGetDeviceProcAddr called with %s", (pName) ? pName : "(null)");
+    vulkan::driver::Logger(device).Err(§
+      device, "invalid vkGetDeviceProcAddr(%p, \"%s\") call", device,§
+      (pName) ? pName : "(null)");
     return nullptr;
   }
   // clang-format off
@@ -775,7 +786,6 @@ VK_KHR_swapchain
     {{$ext_name := index $ext.Arguments 0}}
 
     {{$base := (Macro "BaseName" $)}}
-    {{$unnamed_params := (ForEach $.CallParameters "ParameterType" | JoinWith ", ")}}
 
     VKAPI_ATTR {{Node "Type" $.Return}} checked{{$base}}({{Macro "Parameters" $}}) {
       {{$p0 := index $.CallParameters 0}}
@@ -785,7 +795,7 @@ VK_KHR_swapchain
         {{if not (IsVoid $.Return.Type)}}return §{{end}}
         {{$base}}({{Macro "Arguments" $}});
       } else {
-        ALOGE("{{$ext_name}} not enabled. {{$.Name}} not executed.");
+        Logger({{$p0.Name}}).Err({{$p0.Name}}, "{{$ext_name}} not enabled. {{$.Name}} not executed.");
         {{if not (IsVoid $.Return.Type)}}return VK_SUCCESS;{{end}}
       }
     }
index 5bd2159..29351a1 100644 (file)
@@ -33,7 +33,7 @@ VKAPI_ATTR VkResult checkedCreateSwapchainKHR(VkDevice device, const VkSwapchain
     if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
         return CreateSwapchainKHR(device, pCreateInfo, pAllocator, pSwapchain);
     } else {
-        ALOGE("VK_KHR_swapchain not enabled. vkCreateSwapchainKHR not executed.");
+        Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkCreateSwapchainKHR not executed.");
         return VK_SUCCESS;
     }
 }
@@ -42,7 +42,7 @@ VKAPI_ATTR void checkedDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapc
     if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
         DestroySwapchainKHR(device, swapchain, pAllocator);
     } else {
-        ALOGE("VK_KHR_swapchain not enabled. vkDestroySwapchainKHR not executed.");
+        Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkDestroySwapchainKHR not executed.");
     }
 }
 
@@ -50,7 +50,7 @@ VKAPI_ATTR VkResult checkedGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR
     if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
         return GetSwapchainImagesKHR(device, swapchain, pSwapchainImageCount, pSwapchainImages);
     } else {
-        ALOGE("VK_KHR_swapchain not enabled. vkGetSwapchainImagesKHR not executed.");
+        Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkGetSwapchainImagesKHR not executed.");
         return VK_SUCCESS;
     }
 }
@@ -59,7 +59,7 @@ VKAPI_ATTR VkResult checkedAcquireNextImageKHR(VkDevice device, VkSwapchainKHR s
     if (GetData(device).hook_extensions[ProcHook::KHR_swapchain]) {
         return AcquireNextImageKHR(device, swapchain, timeout, semaphore, fence, pImageIndex);
     } else {
-        ALOGE("VK_KHR_swapchain not enabled. vkAcquireNextImageKHR not executed.");
+        Logger(device).Err(device, "VK_KHR_swapchain not enabled. vkAcquireNextImageKHR not executed.");
         return VK_SUCCESS;
     }
 }
@@ -68,7 +68,7 @@ VKAPI_ATTR VkResult checkedQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR
     if (GetData(queue).hook_extensions[ProcHook::KHR_swapchain]) {
         return QueuePresentKHR(queue, pPresentInfo);
     } else {
-        ALOGE("VK_KHR_swapchain not enabled. vkQueuePresentKHR not executed.");
+        Logger(queue).Err(queue, "VK_KHR_swapchain not enabled. vkQueuePresentKHR not executed.");
         return VK_SUCCESS;
     }
 }