debug_report.h revision 622622377a1ac71a81a88e335f170c4a08835f06
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 <vulkan/vulkan.h>
21#include <shared_mutex>
22
23namespace vulkan {
24namespace driver {
25
26// clang-format off
27VKAPI_ATTR VkResult CreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback);
28VKAPI_ATTR void DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks* pAllocator);
29VKAPI_ATTR void DebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object, size_t location, int32_t messageCode, const char* pLayerPrefix, const char* pMessage);
30// clang-format on
31
32class DebugReportCallbackList {
33   public:
34    DebugReportCallbackList()
35        : head_{nullptr, 0, nullptr, nullptr, VK_NULL_HANDLE} {}
36    DebugReportCallbackList(const DebugReportCallbackList&) = delete;
37    DebugReportCallbackList& operator=(const DebugReportCallbackList&) = delete;
38    ~DebugReportCallbackList() = default;
39
40    VkResult CreateCallback(
41        VkInstance instance,
42        const VkDebugReportCallbackCreateInfoEXT* create_info,
43        const VkAllocationCallbacks* allocator,
44        VkDebugReportCallbackEXT* callback);
45    void DestroyCallback(VkInstance instance,
46                         VkDebugReportCallbackEXT callback,
47                         const VkAllocationCallbacks* allocator);
48    void Message(VkDebugReportFlagsEXT flags,
49                 VkDebugReportObjectTypeEXT object_type,
50                 uint64_t object,
51                 size_t location,
52                 int32_t message_code,
53                 const char* layer_prefix,
54                 const char* message);
55
56   private:
57    struct Node {
58        Node* next;
59        VkDebugReportFlagsEXT flags;
60        PFN_vkDebugReportCallbackEXT callback;
61        void* data;
62        VkDebugReportCallbackEXT driver_callback;
63    };
64
65    // TODO(jessehall): replace with std::shared_mutex when available in libc++
66    std::shared_timed_mutex rwmutex_;
67    Node head_;
68};
69
70}  // namespace driver
71}  // namespace vulkan
72
73#endif  // LIBVULKAN_DEBUG_REPORT_H
74