xref: /aosp_15_r20/external/deqp/external/vulkancts/framework/vulkan/vkDebugReportUtil.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _VKDEBUGREPORTUTIL_HPP
2 #define _VKDEBUGREPORTUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan CTS Framework
5  * --------------------
6  *
7  * Copyright (c) 2016 Google Inc.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief VK_EXT_debug_report utilities
24  *//*--------------------------------------------------------------------*/
25 
26 #include "vkDefs.hpp"
27 #include "vkRef.hpp"
28 #include "deAppendList.hpp"
29 
30 #include <ostream>
31 
32 namespace vk
33 {
34 
35 #ifndef CTS_USES_VULKANSC
36 
37 struct DebugReportMessage
38 {
39     VkDebugReportFlagsEXT flags;
40     VkDebugReportObjectTypeEXT objectType;
41     uint64_t object;
42     size_t location;
43     int32_t messageCode;
44     std::string layerPrefix;
45     std::string message;
46 
DebugReportMessagevk::DebugReportMessage47     DebugReportMessage(void)
48         : flags(0)
49         , objectType((VkDebugReportObjectTypeEXT)0)
50         , object(0)
51         , location(0)
52         , messageCode(0)
53     {
54     }
55 
DebugReportMessagevk::DebugReportMessage56     DebugReportMessage(VkDebugReportFlagsEXT flags_, VkDebugReportObjectTypeEXT objectType_, uint64_t object_,
57                        size_t location_, int32_t messageCode_, const std::string &layerPrefix_,
58                        const std::string &message_)
59         : flags(flags_)
60         , objectType(objectType_)
61         , object(object_)
62         , location(location_)
63         , messageCode(messageCode_)
64         , layerPrefix(layerPrefix_)
65         , message(message_)
66     {
67     }
68 
isErrorvk::DebugReportMessage69     bool isError() const
70     {
71         static const vk::VkDebugReportFlagsEXT errorFlags = vk::VK_DEBUG_REPORT_ERROR_BIT_EXT;
72         return ((flags & errorFlags) != 0u);
73     }
74 
shouldBeLoggedvk::DebugReportMessage75     bool shouldBeLogged() const
76     {
77         // \note We are not logging INFORMATION and DEBUG messages
78         static const vk::VkDebugReportFlagsEXT otherFlags =
79             vk::VK_DEBUG_REPORT_WARNING_BIT_EXT | vk::VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT;
80         return (isError() || ((flags & otherFlags) != 0u));
81     }
82 };
83 
84 std::ostream &operator<<(std::ostream &str, const DebugReportMessage &message);
85 
86 class DebugReportRecorder
87 {
88 public:
89     using MessageList = de::AppendList<DebugReportMessage>;
90 
91     DebugReportRecorder(bool printValidationErrors);
92     ~DebugReportRecorder(void);
93 
getMessages(void)94     MessageList &getMessages(void)
95     {
96         return m_messages;
97     }
clearMessages(void)98     void clearMessages(void)
99     {
100         m_messages.clear();
101     }
errorPrinting(void) const102     bool errorPrinting(void) const
103     {
104         return m_print_errors;
105     }
106 
107     VkDebugReportCallbackCreateInfoEXT makeCreateInfo(void);
108     Move<VkDebugReportCallbackEXT> createCallback(const InstanceInterface &vki, VkInstance instance);
109 
110 private:
111     MessageList m_messages;
112     const bool m_print_errors;
113 };
114 
115 #endif // CTS_USES_VULKANSC
116 
117 bool isDebugReportSupported(const PlatformInterface &vkp);
118 
119 } // namespace vk
120 
121 #endif // _VKDEBUGREPORTUTIL_HPP
122