Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 12cb94a8 authored by Chia-I Wu's avatar Chia-I Wu Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'vk-debug-report' into nyc-dev

* changes:
  vulkan: improve vulkan::driver logcat messages
  vulkan: use Logger in vulkan::api
  vulkan: use Logger in the generated code
  vulkan: add DebugReportLogger
  vulkan: make debug report callbacks available in DeviceData
  vulkan: avoid duplicated app messages
  vulkan: constify DebugReportCallbackList::Message
  vulkan: refactor DebugReportCallbackList
parents df98fb95 e201c3f7
Loading
Loading
Loading
Loading
+20 −15
Original line number Original line Diff line number Diff line
@@ -394,7 +394,9 @@ class LayerChain {
                                              uint32_t& count);
                                              uint32_t& count);


   private:
   private:
    LayerChain(bool is_instance, const VkAllocationCallbacks& allocator);
    LayerChain(bool is_instance,
               const driver::DebugReportLogger& logger,
               const VkAllocationCallbacks& allocator);
    ~LayerChain();
    ~LayerChain();


    VkResult ActivateLayers(const char* const* layer_names,
    VkResult ActivateLayers(const char* const* layer_names,
@@ -455,6 +457,7 @@ class LayerChain {
                        void* user_data);
                        void* user_data);


    const bool is_instance_;
    const bool is_instance_;
    const driver::DebugReportLogger& logger_;
    const VkAllocationCallbacks& allocator_;
    const VkAllocationCallbacks& allocator_;


    OverrideLayerNames override_layers_;
    OverrideLayerNames override_layers_;
@@ -476,8 +479,11 @@ class LayerChain {
    std::bitset<driver::ProcHook::EXTENSION_COUNT> enabled_extensions_;
    std::bitset<driver::ProcHook::EXTENSION_COUNT> enabled_extensions_;
};
};


LayerChain::LayerChain(bool is_instance, const VkAllocationCallbacks& allocator)
LayerChain::LayerChain(bool is_instance,
                       const driver::DebugReportLogger& logger,
                       const VkAllocationCallbacks& allocator)
    : is_instance_(is_instance),
    : is_instance_(is_instance),
      logger_(logger),
      allocator_(allocator),
      allocator_(allocator),
      override_layers_(is_instance, allocator),
      override_layers_(is_instance, allocator),
      override_extensions_(is_instance, allocator),
      override_extensions_(is_instance, allocator),
@@ -562,12 +568,9 @@ VkResult LayerChain::ActivateLayers(VkPhysicalDevice physical_dev,
        }
        }


        if (!exact_match) {
        if (!exact_match) {
            ALOGW("Device layers");
            logger_.Warn(physical_dev,
            for (uint32_t i = 0; i < layer_count; i++)
                         "Device layers disagree with instance layers and are "
                ALOGW("  %s", layer_names[i]);
                         "overridden by instance layers");
            ALOGW(
                "disagree with instance layers and are overridden by "
                "instance layers");
        }
        }
    }
    }


@@ -617,7 +620,7 @@ LayerChain::ActiveLayer* LayerChain::AllocateLayerArray(uint32_t count) const {
VkResult LayerChain::LoadLayer(ActiveLayer& layer, const char* name) {
VkResult LayerChain::LoadLayer(ActiveLayer& layer, const char* name) {
    const Layer* l = FindLayer(name);
    const Layer* l = FindLayer(name);
    if (!l) {
    if (!l) {
        ALOGW("Failed to find layer %s", name);
        logger_.Err(VK_NULL_HANDLE, "Failed to find layer %s", name);
        return VK_ERROR_LAYER_NOT_PRESENT;
        return VK_ERROR_LAYER_NOT_PRESENT;
    }
    }


@@ -882,7 +885,8 @@ VkResult LayerChain::ValidateExtensions(const char* const* extension_names,
    for (uint32_t i = 0; i < extension_count; i++) {
    for (uint32_t i = 0; i < extension_count; i++) {
        const char* name = extension_names[i];
        const char* name = extension_names[i];
        if (!IsLayerExtension(name) && !IsDriverExtension(name)) {
        if (!IsLayerExtension(name) && !IsDriverExtension(name)) {
            ALOGE("Failed to enable missing instance extension %s", name);
            logger_.Err(VK_NULL_HANDLE,
                        "Failed to enable missing instance extension %s", name);
            return VK_ERROR_EXTENSION_NOT_PRESENT;
            return VK_ERROR_EXTENSION_NOT_PRESENT;
        }
        }


@@ -919,7 +923,8 @@ VkResult LayerChain::ValidateExtensions(VkPhysicalDevice physical_dev,
    for (uint32_t i = 0; i < extension_count; i++) {
    for (uint32_t i = 0; i < extension_count; i++) {
        const char* name = extension_names[i];
        const char* name = extension_names[i];
        if (!IsLayerExtension(name) && !IsDriverExtension(name)) {
        if (!IsLayerExtension(name) && !IsDriverExtension(name)) {
            ALOGE("Failed to enable missing device extension %s", name);
            logger_.Err(physical_dev,
                        "Failed to enable missing device extension %s", name);
            return VK_ERROR_EXTENSION_NOT_PRESENT;
            return VK_ERROR_EXTENSION_NOT_PRESENT;
        }
        }


@@ -1036,7 +1041,7 @@ VkBool32 LayerChain::DebugReportCallback(VkDebugReportFlagsEXT flags,
VkResult LayerChain::CreateInstance(const VkInstanceCreateInfo* create_info,
VkResult LayerChain::CreateInstance(const VkInstanceCreateInfo* create_info,
                                    const VkAllocationCallbacks* allocator,
                                    const VkAllocationCallbacks* allocator,
                                    VkInstance* instance_out) {
                                    VkInstance* instance_out) {
    LayerChain chain(true,
    LayerChain chain(true, driver::DebugReportLogger(*create_info),
                     (allocator) ? *allocator : driver::GetDefaultAllocator());
                     (allocator) ? *allocator : driver::GetDefaultAllocator());


    VkResult result = chain.ActivateLayers(create_info->ppEnabledLayerNames,
    VkResult result = chain.ActivateLayers(create_info->ppEnabledLayerNames,
@@ -1061,9 +1066,9 @@ VkResult LayerChain::CreateDevice(VkPhysicalDevice physical_dev,
                                  const VkDeviceCreateInfo* create_info,
                                  const VkDeviceCreateInfo* create_info,
                                  const VkAllocationCallbacks* allocator,
                                  const VkAllocationCallbacks* allocator,
                                  VkDevice* dev_out) {
                                  VkDevice* dev_out) {
    LayerChain chain(false, (allocator)
    LayerChain chain(
                                ? *allocator
        false, driver::Logger(physical_dev),
                                : driver::GetData(physical_dev).allocator);
        (allocator) ? *allocator : driver::GetData(physical_dev).allocator);


    VkResult result = chain.ActivateLayers(
    VkResult result = chain.ActivateLayers(
        physical_dev, create_info->ppEnabledLayerNames,
        physical_dev, create_info->ppEnabledLayerNames,
+33 −28
Original line number Original line Diff line number Diff line
@@ -51,56 +51,56 @@ namespace {


// clang-format off
// clang-format off


VKAPI_ATTR void disabledDestroySurfaceKHR(VkInstance, VkSurfaceKHR, const VkAllocationCallbacks*) {
VKAPI_ATTR void disabledDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR, const VkAllocationCallbacks*) {
    ALOGE("VK_KHR_surface not enabled. vkDestroySurfaceKHR not executed.");
    driver::Logger(instance).Err(instance, "VK_KHR_surface not enabled. Exported vkDestroySurfaceKHR not executed.");
}
}


VKAPI_ATTR VkResult disabledGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice, uint32_t, VkSurfaceKHR, VkBool32*) {
VKAPI_ATTR VkResult disabledGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, uint32_t, VkSurfaceKHR, VkBool32*) {
    ALOGE("VK_KHR_surface not enabled. vkGetPhysicalDeviceSurfaceSupportKHR not executed.");
    driver::Logger(physicalDevice).Err(physicalDevice, "VK_KHR_surface not enabled. Exported vkGetPhysicalDeviceSurfaceSupportKHR not executed.");
    return VK_SUCCESS;
    return VK_SUCCESS;
}
}


VKAPI_ATTR VkResult disabledGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice, VkSurfaceKHR, VkSurfaceCapabilitiesKHR*) {
VKAPI_ATTR VkResult disabledGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR, VkSurfaceCapabilitiesKHR*) {
    ALOGE("VK_KHR_surface not enabled. vkGetPhysicalDeviceSurfaceCapabilitiesKHR not executed.");
    driver::Logger(physicalDevice).Err(physicalDevice, "VK_KHR_surface not enabled. Exported vkGetPhysicalDeviceSurfaceCapabilitiesKHR not executed.");
    return VK_SUCCESS;
    return VK_SUCCESS;
}
}


VKAPI_ATTR VkResult disabledGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice, VkSurfaceKHR, uint32_t*, VkSurfaceFormatKHR*) {
VKAPI_ATTR VkResult disabledGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR, uint32_t*, VkSurfaceFormatKHR*) {
    ALOGE("VK_KHR_surface not enabled. vkGetPhysicalDeviceSurfaceFormatsKHR not executed.");
    driver::Logger(physicalDevice).Err(physicalDevice, "VK_KHR_surface not enabled. Exported vkGetPhysicalDeviceSurfaceFormatsKHR not executed.");
    return VK_SUCCESS;
    return VK_SUCCESS;
}
}


VKAPI_ATTR VkResult disabledGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice, VkSurfaceKHR, uint32_t*, VkPresentModeKHR*) {
VKAPI_ATTR VkResult disabledGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR, uint32_t*, VkPresentModeKHR*) {
    ALOGE("VK_KHR_surface not enabled. vkGetPhysicalDeviceSurfacePresentModesKHR not executed.");
    driver::Logger(physicalDevice).Err(physicalDevice, "VK_KHR_surface not enabled. Exported vkGetPhysicalDeviceSurfacePresentModesKHR not executed.");
    return VK_SUCCESS;
    return VK_SUCCESS;
}
}


VKAPI_ATTR VkResult disabledCreateSwapchainKHR(VkDevice, const VkSwapchainCreateInfoKHR*, const VkAllocationCallbacks*, VkSwapchainKHR*) {
VKAPI_ATTR VkResult disabledCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR*, const VkAllocationCallbacks*, VkSwapchainKHR*) {
    ALOGE("VK_KHR_swapchain not enabled. vkCreateSwapchainKHR not executed.");
    driver::Logger(device).Err(device, "VK_KHR_swapchain not enabled. Exported vkCreateSwapchainKHR not executed.");
    return VK_SUCCESS;
    return VK_SUCCESS;
}
}


VKAPI_ATTR void disabledDestroySwapchainKHR(VkDevice, VkSwapchainKHR, const VkAllocationCallbacks*) {
VKAPI_ATTR void disabledDestroySwapchainKHR(VkDevice device, VkSwapchainKHR, const VkAllocationCallbacks*) {
    ALOGE("VK_KHR_swapchain not enabled. vkDestroySwapchainKHR not executed.");
    driver::Logger(device).Err(device, "VK_KHR_swapchain not enabled. Exported vkDestroySwapchainKHR not executed.");
}
}


VKAPI_ATTR VkResult disabledGetSwapchainImagesKHR(VkDevice, VkSwapchainKHR, uint32_t*, VkImage*) {
VKAPI_ATTR VkResult disabledGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR, uint32_t*, VkImage*) {
    ALOGE("VK_KHR_swapchain not enabled. vkGetSwapchainImagesKHR not executed.");
    driver::Logger(device).Err(device, "VK_KHR_swapchain not enabled. Exported vkGetSwapchainImagesKHR not executed.");
    return VK_SUCCESS;
    return VK_SUCCESS;
}
}


VKAPI_ATTR VkResult disabledAcquireNextImageKHR(VkDevice, VkSwapchainKHR, uint64_t, VkSemaphore, VkFence, uint32_t*) {
VKAPI_ATTR VkResult disabledAcquireNextImageKHR(VkDevice device, VkSwapchainKHR, uint64_t, VkSemaphore, VkFence, uint32_t*) {
    ALOGE("VK_KHR_swapchain not enabled. vkAcquireNextImageKHR not executed.");
    driver::Logger(device).Err(device, "VK_KHR_swapchain not enabled. Exported vkAcquireNextImageKHR not executed.");
    return VK_SUCCESS;
    return VK_SUCCESS;
}
}


VKAPI_ATTR VkResult disabledQueuePresentKHR(VkQueue, const VkPresentInfoKHR*) {
VKAPI_ATTR VkResult disabledQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR*) {
    ALOGE("VK_KHR_swapchain not enabled. vkQueuePresentKHR not executed.");
    driver::Logger(queue).Err(queue, "VK_KHR_swapchain not enabled. Exported vkQueuePresentKHR not executed.");
    return VK_SUCCESS;
    return VK_SUCCESS;
}
}


VKAPI_ATTR VkResult disabledCreateAndroidSurfaceKHR(VkInstance, const VkAndroidSurfaceCreateInfoKHR*, const VkAllocationCallbacks*, VkSurfaceKHR*) {
VKAPI_ATTR VkResult disabledCreateAndroidSurfaceKHR(VkInstance instance, const VkAndroidSurfaceCreateInfoKHR*, const VkAllocationCallbacks*, VkSurfaceKHR*) {
    ALOGE("VK_KHR_android_surface not enabled. vkCreateAndroidSurfaceKHR not executed.");
    driver::Logger(instance).Err(instance, "VK_KHR_android_surface not enabled. Exported vkCreateAndroidSurfaceKHR not executed.");
    return VK_SUCCESS;
    return VK_SUCCESS;
}
}


@@ -304,7 +304,7 @@ VKAPI_ATTR VkResult vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pP
__attribute__((visibility("default")))
__attribute__((visibility("default")))
VKAPI_ATTR PFN_vkVoidFunction vkGetDeviceProcAddr(VkDevice device, const char* pName) {
VKAPI_ATTR PFN_vkVoidFunction vkGetDeviceProcAddr(VkDevice device, const char* pName) {
    if (device == VK_NULL_HANDLE) {
    if (device == VK_NULL_HANDLE) {
        ALOGE("vkGetDeviceProcAddr called with invalid device");
        ALOGE("invalid vkGetDeviceProcAddr(VK_NULL_HANDLE, ...) call");
        return nullptr;
        return nullptr;
    }
    }


@@ -342,7 +342,9 @@ VKAPI_ATTR PFN_vkVoidFunction vkGetDeviceProcAddr(VkDevice device, const char* p
        std::binary_search(
        std::binary_search(
            known_non_device_names, known_non_device_names + count, pName,
            known_non_device_names, known_non_device_names + count, pName,
            [](const char* a, const char* b) { return (strcmp(a, b) < 0); })) {
            [](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;
        return nullptr;
    }
    }
    // clang-format off
    // clang-format off
@@ -356,12 +358,12 @@ VKAPI_ATTR PFN_vkVoidFunction vkGetDeviceProcAddr(VkDevice device, const char* p
__attribute__((visibility("default")))
__attribute__((visibility("default")))
VKAPI_ATTR PFN_vkVoidFunction vkGetInstanceProcAddr(VkInstance instance, const char* pName) {
VKAPI_ATTR PFN_vkVoidFunction vkGetInstanceProcAddr(VkInstance instance, const char* pName) {
    // global functions
    // 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, "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, "vkEnumerateInstanceLayerProperties") == 0) return reinterpret_cast<PFN_vkVoidFunction>(vulkan::api::EnumerateInstanceLayerProperties);
        if (strcmp(pName, "vkEnumerateInstanceExtensionProperties") == 0) return reinterpret_cast<PFN_vkVoidFunction>(vulkan::api::EnumerateInstanceExtensionProperties);
        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;
        return nullptr;
    }
    }


@@ -510,8 +512,11 @@ VKAPI_ATTR PFN_vkVoidFunction vkGetInstanceProcAddr(VkInstance instance, const c
        hooks, hooks + count, pName,
        hooks, hooks + count, pName,
        [](const Hook& h, const char* n) { return strcmp(h.name, n) < 0; });
        [](const Hook& h, const char* n) { return strcmp(h.name, n) < 0; });
    if (hook < hooks + count && strcmp(hook->name, pName) == 0) {
    if (hook < hooks + count && strcmp(hook->name, pName) == 0) {
        if (!hook->proc)
        if (!hook->proc) {
            ALOGE("vkGetInstanceProcAddr called with %s with instance", pName);
            vulkan::driver::Logger(instance).Err(
                instance, "invalid vkGetInstanceProcAddr(%p, \"%s\") call",
                instance, pName);
        }
        return hook->proc;
        return hook->proc;
    }
    }
    // clang-format off
    // clang-format off
+21 −11
Original line number Original line Diff line number Diff line
@@ -482,10 +482,16 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
    {{$ext_name := index $ext.Arguments 0}}
    {{$ext_name := index $ext.Arguments 0}}


    {{$base := (Macro "BaseName" $)}}
    {{$base := (Macro "BaseName" $)}}
    {{$unnamed_params := (ForEach $.CallParameters "ParameterType" | JoinWith ", ")}}


    VKAPI_ATTR {{Node "Type" $.Return}} disabled{{$base}}({{$unnamed_params}}) {
    {{$p0 := (index $.CallParameters 0)}}
      ALOGE("{{$ext_name}} not enabled. {{$.Name}} not executed.");
    {{$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}}
      {{if not (IsVoid $.Return.Type)}}return VK_SUCCESS;{{end}}
    }
    }


@@ -502,7 +508,7 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
  {{AssertType $ "API"}}
  {{AssertType $ "API"}}


  // global functions
  // global functions
  if (!instance) {
  if (instance == VK_NULL_HANDLE) {
    {{range $f := AllCommands $}}
    {{range $f := AllCommands $}}
      {{if (Macro "IsGloballyDispatched" $f)}}
      {{if (Macro "IsGloballyDispatched" $f)}}
        if (strcmp(pName, "{{$f.Name}}") == 0) return §
        if (strcmp(pName, "{{$f.Name}}") == 0) return §
@@ -511,7 +517,7 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
      {{end}}
      {{end}}
    {{end}}
    {{end}}


    ALOGE("vkGetInstanceProcAddr called with %s without instance",  pName);
    ALOGE("invalid vkGetInstanceProcAddr(VK_NULL_HANDLE, \"%s\") call", pName);
    return nullptr;
    return nullptr;
  }
  }


@@ -549,8 +555,11 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
    hooks, hooks + count, pName,
    hooks, hooks + count, pName,
    [](const Hook& h, const char* n) { return strcmp(h.name, n) < 0; });
    [](const Hook& h, const char* n) { return strcmp(h.name, n) < 0; });
  if (hook <  hooks + count && strcmp(hook->name, pName) == 0) {
  if (hook <  hooks + count && strcmp(hook->name, pName) == 0) {
    if (!hook->proc)
    if (!hook->proc) {
      ALOGE("vkGetInstanceProcAddr called with %s with instance",  pName);
      vulkan::driver::Logger(instance).Err(
        instance, "invalid vkGetInstanceProcAddr(%p, \"%s\") call",
        instance, pName);
    }
    return hook->proc;
    return hook->proc;
  }
  }
  // clang-format off
  // clang-format off
@@ -567,7 +576,7 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
  {{AssertType $ "API"}}
  {{AssertType $ "API"}}


  if (device == VK_NULL_HANDLE) {
  if (device == VK_NULL_HANDLE) {
    ALOGE("vkGetDeviceProcAddr called with invalid device");
    ALOGE("invalid vkGetDeviceProcAddr(VK_NULL_HANDLE, ...) call");
    return nullptr;
    return nullptr;
  }
  }


@@ -587,7 +596,9 @@ bool InitDriverTable(VkDevice dev, PFN_vkGetDeviceProcAddr get_proc,
      std::binary_search(
      std::binary_search(
        known_non_device_names, known_non_device_names + count, pName,
        known_non_device_names, known_non_device_names + count, pName,
        [](const char* a, const char* b) { return (strcmp(a, b) < 0); })) {
        [](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;
    return nullptr;
  }
  }
  // clang-format off
  // clang-format off
@@ -775,7 +786,6 @@ VK_KHR_swapchain
    {{$ext_name := index $ext.Arguments 0}}
    {{$ext_name := index $ext.Arguments 0}}


    {{$base := (Macro "BaseName" $)}}
    {{$base := (Macro "BaseName" $)}}
    {{$unnamed_params := (ForEach $.CallParameters "ParameterType" | JoinWith ", ")}}


    VKAPI_ATTR {{Node "Type" $.Return}} checked{{$base}}({{Macro "Parameters" $}}) {
    VKAPI_ATTR {{Node "Type" $.Return}} checked{{$base}}({{Macro "Parameters" $}}) {
      {{$p0 := index $.CallParameters 0}}
      {{$p0 := index $.CallParameters 0}}
@@ -785,7 +795,7 @@ VK_KHR_swapchain
        {{if not (IsVoid $.Return.Type)}}return §{{end}}
        {{if not (IsVoid $.Return.Type)}}return §{{end}}
        {{$base}}({{Macro "Arguments" $}});
        {{$base}}({{Macro "Arguments" $}});
      } else {
      } 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}}
        {{if not (IsVoid $.Return.Type)}}return VK_SUCCESS;{{end}}
      }
      }
    }
    }
+113 −61
Original line number Original line Diff line number Diff line
@@ -19,62 +19,37 @@
namespace vulkan {
namespace vulkan {
namespace driver {
namespace driver {


VkResult DebugReportCallbackList::CreateCallback(
DebugReportCallbackList::Node* DebugReportCallbackList::AddCallback(
    VkInstance instance,
    const VkDebugReportCallbackCreateInfoEXT& info,
    const VkDebugReportCallbackCreateInfoEXT* create_info,
    VkDebugReportCallbackEXT driver_handle,
    const VkAllocationCallbacks* allocator,
    const VkAllocationCallbacks& allocator) {
    VkDebugReportCallbackEXT* callback) {
    void* mem = allocator.pfnAllocation(allocator.pUserData, sizeof(Node),
    VkDebugReportCallbackEXT driver_callback = VK_NULL_HANDLE;
                                        alignof(Node),

    if (GetData(instance).driver.CreateDebugReportCallbackEXT) {
        VkResult result = GetData(instance).driver.CreateDebugReportCallbackEXT(
            instance, create_info, allocator, &driver_callback);
        if (result != VK_SUCCESS)
            return result;
    }

    const VkAllocationCallbacks* alloc =
        allocator ? allocator : &GetData(instance).allocator;
    void* mem =
        alloc->pfnAllocation(alloc->pUserData, sizeof(Node), alignof(Node),
                                        VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
                                        VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (!mem) {
    if (!mem)
        if (GetData(instance).driver.DestroyDebugReportCallbackEXT) {
        return nullptr;
            GetData(instance).driver.DestroyDebugReportCallbackEXT(
                instance, driver_callback, allocator);
        }
        return VK_ERROR_OUT_OF_HOST_MEMORY;
    }


    // initialize and prepend node to the list
    std::lock_guard<decltype(rwmutex_)> lock(rwmutex_);
    std::lock_guard<decltype(rwmutex_)> lock(rwmutex_);
    head_.next =
    head_.next = new (mem) Node{head_.next, info.flags, info.pfnCallback,
        new (mem) Node{head_.next, create_info->flags, create_info->pfnCallback,
                                info.pUserData, driver_handle};
                       create_info->pUserData, driver_callback};

    *callback =
    return head_.next;
        VkDebugReportCallbackEXT(reinterpret_cast<uintptr_t>(head_.next));
    return VK_SUCCESS;
}
}


void DebugReportCallbackList::DestroyCallback(
void DebugReportCallbackList::RemoveCallback(
    VkInstance instance,
    Node* node,
    VkDebugReportCallbackEXT callback,
    const VkAllocationCallbacks& allocator) {
    const VkAllocationCallbacks* allocator) {
    // remove node from the list
    Node* node = reinterpret_cast<Node*>(uintptr_t(callback));
    {
    std::unique_lock<decltype(rwmutex_)> lock(rwmutex_);
        std::lock_guard<decltype(rwmutex_)> lock(rwmutex_);
        Node* prev = &head_;
        Node* prev = &head_;
        while (prev && prev->next != node)
        while (prev && prev->next != node)
            prev = prev->next;
            prev = prev->next;
        prev->next = node->next;
        prev->next = node->next;
    lock.unlock();

    if (GetData(instance).driver.DestroyDebugReportCallbackEXT) {
        GetData(instance).driver.DestroyDebugReportCallbackEXT(
            instance, node->driver_callback, allocator);
    }
    }


    const VkAllocationCallbacks* alloc =
    allocator.pfnFree(allocator.pUserData, node);
        allocator ? allocator : &GetData(instance).allocator;
    alloc->pfnFree(alloc->pUserData, node);
}
}


void DebugReportCallbackList::Message(VkDebugReportFlagsEXT flags,
void DebugReportCallbackList::Message(VkDebugReportFlagsEXT flags,
@@ -83,32 +58,108 @@ void DebugReportCallbackList::Message(VkDebugReportFlagsEXT flags,
                                      size_t location,
                                      size_t location,
                                      int32_t message_code,
                                      int32_t message_code,
                                      const char* layer_prefix,
                                      const char* layer_prefix,
                                      const char* message) {
                                      const char* message) const {
    std::shared_lock<decltype(rwmutex_)> lock(rwmutex_);
    std::shared_lock<decltype(rwmutex_)> lock(rwmutex_);
    Node* node = &head_;
    const Node* node = &head_;
    while ((node = node->next)) {
    while ((node = node->next)) {
        if ((node->flags & flags) != 0) {
        if ((node->flags & flags) != 0) {
            node->callback(flags, object_type, object, location, message_code,
            node->callback(flags, object_type, object, location, message_code,
                           layer_prefix, message, node->data);
                           layer_prefix, message, node->user_data);
        }
    }
}

void DebugReportLogger::Message(VkDebugReportFlagsEXT flags,
                                VkDebugReportObjectTypeEXT object_type,
                                uint64_t object,
                                size_t location,
                                int32_t message_code,
                                const char* layer_prefix,
                                const char* message) const {
    const VkDebugReportCallbackCreateInfoEXT* info =
        reinterpret_cast<const VkDebugReportCallbackCreateInfoEXT*>(
            instance_pnext_);
    while (info) {
        if (info->sType == VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT) {
            info->pfnCallback(flags, object_type, object, location,
                              message_code, layer_prefix, message,
                              info->pUserData);
        }

        info = reinterpret_cast<const VkDebugReportCallbackCreateInfoEXT*>(
            info->pNext);
    }
    }

    if (callbacks_) {
        callbacks_->Message(flags, object_type, object, location, message_code,
                            layer_prefix, message);
    }
    }
}
}


void DebugReportLogger::PrintV(VkDebugReportFlagsEXT flags,
                               VkDebugReportObjectTypeEXT object_type,
                               uint64_t object,
                               const char* format,
                               va_list ap) const {
    char buf[1024];
    int len = vsnprintf(buf, sizeof(buf), format, ap);

    // message truncated
    if (len >= static_cast<int>(sizeof(buf)))
        memcpy(buf + sizeof(buf) - 4, "...", 4);

    Message(flags, object_type, object, 0, 0, LOG_TAG, buf);
}

VkResult CreateDebugReportCallbackEXT(
VkResult CreateDebugReportCallbackEXT(
    VkInstance instance,
    VkInstance instance,
    const VkDebugReportCallbackCreateInfoEXT* create_info,
    const VkDebugReportCallbackCreateInfoEXT* create_info,
    const VkAllocationCallbacks* allocator,
    const VkAllocationCallbacks* allocator,
    VkDebugReportCallbackEXT* callback) {
    VkDebugReportCallbackEXT* callback) {
    return GetData(instance).debug_report_callbacks.CreateCallback(
    const auto& driver = GetData(instance).driver;
        instance, create_info, allocator, callback);
    VkDebugReportCallbackEXT driver_handle = VK_NULL_HANDLE;
    if (driver.CreateDebugReportCallbackEXT) {
        VkResult result = driver.CreateDebugReportCallbackEXT(
            instance, create_info, allocator, &driver_handle);
        if (result != VK_SUCCESS)
            return result;
    }

    auto& callbacks = GetData(instance).debug_report_callbacks;
    auto node = callbacks.AddCallback(
        *create_info, driver_handle,
        (allocator) ? *allocator : GetData(instance).allocator);
    if (!node) {
        if (driver_handle != VK_NULL_HANDLE) {
            driver.DestroyDebugReportCallbackEXT(instance, driver_handle,
                                                 allocator);
        }

        return VK_ERROR_OUT_OF_HOST_MEMORY;
    }

    *callback = callbacks.GetHandle(node);

    return VK_SUCCESS;
}
}


void DestroyDebugReportCallbackEXT(VkInstance instance,
void DestroyDebugReportCallbackEXT(VkInstance instance,
                                   VkDebugReportCallbackEXT callback,
                                   VkDebugReportCallbackEXT callback,
                                   const VkAllocationCallbacks* allocator) {
                                   const VkAllocationCallbacks* allocator) {
    if (callback)
    if (callback == VK_NULL_HANDLE)
        GetData(instance).debug_report_callbacks.DestroyCallback(
        return;
            instance, callback, allocator);

    auto& callbacks = GetData(instance).debug_report_callbacks;
    auto node = callbacks.FromHandle(callback);
    auto driver_handle = callbacks.GetDriverHandle(node);

    callbacks.RemoveCallback(
        node, (allocator) ? *allocator : GetData(instance).allocator);

    if (driver_handle != VK_NULL_HANDLE) {
        GetData(instance).driver.DestroyDebugReportCallbackEXT(
            instance, driver_handle, allocator);
    }
}
}


void DebugReportMessageEXT(VkInstance instance,
void DebugReportMessageEXT(VkInstance instance,
@@ -123,10 +174,11 @@ void DebugReportMessageEXT(VkInstance instance,
        GetData(instance).driver.DebugReportMessageEXT(
        GetData(instance).driver.DebugReportMessageEXT(
            instance, flags, object_type, object, location, message_code,
            instance, flags, object_type, object, location, message_code,
            layer_prefix, message);
            layer_prefix, message);
    } else {
        GetData(instance).debug_report_callbacks.Message(
            flags, object_type, object, location, message_code, layer_prefix,
            message);
    }
    }
    GetData(instance).debug_report_callbacks.Message(flags, object_type, object,
                                                     location, message_code,
                                                     layer_prefix, message);
}
}


}  // namespace driver
}  // namespace driver
+106 −13

File changed.

Preview size limit exceeded, changes collapsed.

Loading