Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 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 | |
Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 20 | #include <vulkan/vulkan.h> |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 21 | #include <shared_mutex> |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 22 | |
| 23 | namespace vulkan { |
Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 24 | namespace driver { |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 25 | |
| 26 | // clang-format off |
Chia-I Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 27 | VKAPI_ATTR VkResult CreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback); |
| 28 | VKAPI_ATTR void DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks* pAllocator); |
| 29 | VKAPI_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 Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 30 | // clang-format on |
| 31 | |
| 32 | class DebugReportCallbackList { |
Chia-I Wu | a0d40aa | 2016-05-05 12:43:03 +0800 | [diff] [blame^] | 33 | private: |
| 34 | // forward declaration |
| 35 | struct Node; |
| 36 | |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 37 | 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 Wu | a0d40aa | 2016-05-05 12:43:03 +0800 | [diff] [blame^] | 44 | Node* AddCallback(const VkDebugReportCallbackCreateInfoEXT& info, |
| 45 | VkDebugReportCallbackEXT driver_handle, |
| 46 | const VkAllocationCallbacks& allocator); |
| 47 | void RemoveCallback(Node* node, const VkAllocationCallbacks& allocator); |
| 48 | |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 49 | 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 Wu | a0d40aa | 2016-05-05 12:43:03 +0800 | [diff] [blame^] | 57 | 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 Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 69 | private: |
| 70 | struct Node { |
| 71 | Node* next; |
Chia-I Wu | a0d40aa | 2016-05-05 12:43:03 +0800 | [diff] [blame^] | 72 | |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 73 | VkDebugReportFlagsEXT flags; |
| 74 | PFN_vkDebugReportCallbackEXT callback; |
Chia-I Wu | a0d40aa | 2016-05-05 12:43:03 +0800 | [diff] [blame^] | 75 | void* user_data; |
| 76 | |
| 77 | VkDebugReportCallbackEXT driver_handle; |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 78 | }; |
| 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 Wu | 6226223 | 2016-03-26 07:06:44 +0800 | [diff] [blame] | 85 | } // namespace driver |
Jesse Hall | 715b86a | 2016-01-16 16:34:29 -0800 | [diff] [blame] | 86 | } // namespace vulkan |
| 87 | |
| 88 | #endif // LIBVULKAN_DEBUG_REPORT_H |