debug_report.h revision 715b86ac7d0853131b375ff786c87d8d87a762a1
1/*
2 * Copyright 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef LIBVULKAN_DEBUG_REPORT_H
18#define LIBVULKAN_DEBUG_REPORT_H 1
19
20#include <shared_mutex>
21#include <vulkan/vk_ext_debug_report.h>
22
23namespace vulkan {
24
25// clang-format off
26VKAPI_ATTR VkResult CreateDebugReportCallbackEXT_Bottom(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback);
27VKAPI_ATTR void DestroyDebugReportCallbackEXT_Bottom(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks* pAllocator);
28VKAPI_ATTR void DebugReportMessageEXT_Bottom(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object, size_t location, int32_t messageCode, const char* pLayerPrefix, const char* pMessage);
29// clang-format on
30
31class DebugReportCallbackList {
32   public:
33    DebugReportCallbackList()
34        : head_{nullptr, 0, nullptr, nullptr, VK_NULL_HANDLE} {}
35    DebugReportCallbackList(const DebugReportCallbackList&) = delete;
36    DebugReportCallbackList& operator=(const DebugReportCallbackList&) = delete;
37    ~DebugReportCallbackList() = default;
38
39    VkResult CreateCallback(
40        VkInstance instance,
41        const VkDebugReportCallbackCreateInfoEXT* create_info,
42        const VkAllocationCallbacks* allocator,
43        VkDebugReportCallbackEXT* callback);
44    void DestroyCallback(VkInstance instance,
45                         VkDebugReportCallbackEXT callback,
46                         const VkAllocationCallbacks* allocator);
47    void Message(VkDebugReportFlagsEXT flags,
48                 VkDebugReportObjectTypeEXT object_type,
49                 uint64_t object,
50                 size_t location,
51                 int32_t message_code,
52                 const char* layer_prefix,
53                 const char* message);
54
55   private:
56    struct Node {
57        Node* next;
58        VkDebugReportFlagsEXT flags;
59        PFN_vkDebugReportCallbackEXT callback;
60        void* data;
61        VkDebugReportCallbackEXT driver_callback;
62    };
63
64    // TODO(jessehall): replace with std::shared_mutex when available in libc++
65    std::shared_timed_mutex rwmutex_;
66    Node head_;
67};
68
69}  // namespace vulkan
70
71#endif  // LIBVULKAN_DEBUG_REPORT_H
72