blob: 7a03d4ab24d55ec3fbb86877e9db5dbbc31dc374 [file] [log] [blame]
Jesse Hall715b86a2016-01-16 16:34:29 -08001/*
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
Chia-I Wu62262232016-03-26 07:06:44 +080020#include <vulkan/vulkan.h>
Jesse Hall715b86a2016-01-16 16:34:29 -080021#include <shared_mutex>
Jesse Hall715b86a2016-01-16 16:34:29 -080022
23namespace vulkan {
Chia-I Wu62262232016-03-26 07:06:44 +080024namespace driver {
Jesse Hall715b86a2016-01-16 16:34:29 -080025
26// clang-format off
Chia-I Wu62262232016-03-26 07:06:44 +080027VKAPI_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);
Jesse Hall715b86a2016-01-16 16:34:29 -080030// clang-format on
31
32class DebugReportCallbackList {
Chia-I Wua0d40aa2016-05-05 12:43:03 +080033 private:
34 // forward declaration
35 struct Node;
36
Jesse Hall715b86a2016-01-16 16:34:29 -080037 public:
38 DebugReportCallbackList()
39 : head_{nullptr, 0, nullptr, nullptr, VK_NULL_HANDLE} {}
40 DebugReportCallbackList(const DebugReportCallbackList&) = delete;
41 DebugReportCallbackList& operator=(const DebugReportCallbackList&) = delete;
42 ~DebugReportCallbackList() = default;
43
Chia-I Wua0d40aa2016-05-05 12:43:03 +080044 Node* AddCallback(const VkDebugReportCallbackCreateInfoEXT& info,
45 VkDebugReportCallbackEXT driver_handle,
46 const VkAllocationCallbacks& allocator);
47 void RemoveCallback(Node* node, const VkAllocationCallbacks& allocator);
48
Jesse Hall715b86a2016-01-16 16:34:29 -080049 void Message(VkDebugReportFlagsEXT flags,
50 VkDebugReportObjectTypeEXT object_type,
51 uint64_t object,
52 size_t location,
53 int32_t message_code,
54 const char* layer_prefix,
55 const char* message);
56
Chia-I Wua0d40aa2016-05-05 12:43:03 +080057 static Node* FromHandle(VkDebugReportCallbackEXT handle) {
58 return reinterpret_cast<Node*>(uintptr_t(handle));
59 }
60
61 static VkDebugReportCallbackEXT GetHandle(const Node* node) {
62 return VkDebugReportCallbackEXT(reinterpret_cast<uintptr_t>(node));
63 }
64
65 static VkDebugReportCallbackEXT GetDriverHandle(const Node* node) {
66 return node->driver_handle;
67 }
68
Jesse Hall715b86a2016-01-16 16:34:29 -080069 private:
70 struct Node {
71 Node* next;
Chia-I Wua0d40aa2016-05-05 12:43:03 +080072
Jesse Hall715b86a2016-01-16 16:34:29 -080073 VkDebugReportFlagsEXT flags;
74 PFN_vkDebugReportCallbackEXT callback;
Chia-I Wua0d40aa2016-05-05 12:43:03 +080075 void* user_data;
76
77 VkDebugReportCallbackEXT driver_handle;
Jesse Hall715b86a2016-01-16 16:34:29 -080078 };
79
80 // TODO(jessehall): replace with std::shared_mutex when available in libc++
81 std::shared_timed_mutex rwmutex_;
82 Node head_;
83};
84
Chia-I Wu62262232016-03-26 07:06:44 +080085} // namespace driver
Jesse Hall715b86a2016-01-16 16:34:29 -080086} // namespace vulkan
87
88#endif // LIBVULKAN_DEBUG_REPORT_H