Add utilities for VK_EXT_debug_report
authorPyry Haulos <phaulos@google.com>
Tue, 29 Mar 2016 00:33:23 +0000 (17:33 -0700)
committerPyry Haulos <phaulos@google.com>
Wed, 30 Mar 2016 02:13:41 +0000 (19:13 -0700)
Change-Id: Ia884b2dd6688b15d71fa2df4029afe5d3023fa04

Android.mk
external/vulkancts/framework/vulkan/CMakeLists.txt
external/vulkancts/framework/vulkan/vkBasicTypes.inl
external/vulkancts/framework/vulkan/vkDebugReportUtil.cpp [new file with mode: 0644]
external/vulkancts/framework/vulkan/vkDebugReportUtil.hpp [new file with mode: 0644]
external/vulkancts/gen_framework.py

index 41f58c9..7356d16 100644 (file)
@@ -801,6 +801,7 @@ LOCAL_SRC_FILES := \
        external/vulkancts/modules/vulkan/wsi/vktWsiSwapchainTests.cpp \
        external/vulkancts/modules/vulkan/wsi/vktWsiTests.cpp \
        external/vulkancts/framework/vulkan/vkBuilderUtil.cpp \
+       external/vulkancts/framework/vulkan/vkDebugReportUtil.cpp \
        external/vulkancts/framework/vulkan/vkSpirVProgram.cpp \
        external/vulkancts/framework/vulkan/vkPrograms.cpp \
        external/vulkancts/framework/vulkan/vkApiVersion.cpp \
index 133aa57..e286154 100644 (file)
@@ -43,6 +43,8 @@ set(VKUTIL_SRCS
        vkWsiPlatform.hpp
        vkWsiUtil.cpp
        vkWsiUtil.hpp
+       vkDebugReportUtil.cpp
+       vkDebugReportUtil.hpp
        )
 
 set(VKUTIL_LIBS
index b5b9484..5e5db01 100644 (file)
@@ -685,7 +685,7 @@ enum VkColorSpaceKHR
 {
        VK_COLORSPACE_SRGB_NONLINEAR_KHR        = 0,
 
-       VK_COLOR_SPACE_K_H_R_LAST
+       VK_COLOR_SPACE_KHR_LAST
 };
 
 enum VkPresentModeKHR
@@ -695,7 +695,7 @@ enum VkPresentModeKHR
        VK_PRESENT_MODE_FIFO_KHR                        = 2,
        VK_PRESENT_MODE_FIFO_RELAXED_KHR        = 3,
 
-       VK_PRESENT_MODE_K_H_R_LAST
+       VK_PRESENT_MODE_KHR_LAST
 };
 
 enum VkDebugReportObjectTypeEXT
@@ -730,7 +730,7 @@ enum VkDebugReportObjectTypeEXT
        VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT                   = 27,
        VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_EXT                    = 28,
 
-       VK_DEBUG_REPORT_OBJECT_TYPE_E_X_T_LAST
+       VK_DEBUG_REPORT_OBJECT_TYPE_EXT_LAST
 };
 
 enum VkDebugReportErrorEXT
@@ -738,7 +738,7 @@ enum VkDebugReportErrorEXT
        VK_DEBUG_REPORT_ERROR_NONE_EXT                  = 0,
        VK_DEBUG_REPORT_ERROR_CALLBACK_REF_EXT  = 1,
 
-       VK_DEBUG_REPORT_ERROR_E_X_T_LAST
+       VK_DEBUG_REPORT_ERROR_EXT_LAST
 };
 
 enum VkFormatFeatureFlagBits
diff --git a/external/vulkancts/framework/vulkan/vkDebugReportUtil.cpp b/external/vulkancts/framework/vulkan/vkDebugReportUtil.cpp
new file mode 100644 (file)
index 0000000..221045f
--- /dev/null
@@ -0,0 +1,166 @@
+/*-------------------------------------------------------------------------
+ * Vulkan CTS Framework
+ * --------------------
+ *
+ * Copyright (c) 2016 Google Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and/or associated documentation files (the
+ * "Materials"), to deal in the Materials without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Materials, and to
+ * permit persons to whom the Materials are furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice(s) and this permission notice shall be
+ * included in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//*!
+ * \file
+ * \brief VK_EXT_debug_report utilities
+ *//*--------------------------------------------------------------------*/
+
+#include "vkDebugReportUtil.hpp"
+#include "vkRefUtil.hpp"
+#include "deArrayUtil.hpp"
+
+namespace vk
+{
+
+namespace
+{
+
+tcu::Format::Bitfield<32> shortDebugFlagsStr (VkDebugReportFlagsEXT flags)
+{
+       static const tcu::Format::BitDesc       s_bits[] =
+       {
+               tcu::Format::BitDesc(VK_DEBUG_REPORT_INFORMATION_BIT_EXT,                       "INFO"),
+               tcu::Format::BitDesc(VK_DEBUG_REPORT_WARNING_BIT_EXT,                           "WARNING"),
+               tcu::Format::BitDesc(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,       "PERFORMANCE"),
+               tcu::Format::BitDesc(VK_DEBUG_REPORT_ERROR_BIT_EXT,                                     "ERROR"),
+               tcu::Format::BitDesc(VK_DEBUG_REPORT_DEBUG_BIT_EXT,                                     "DEBUG"),
+       };
+
+       return tcu::Format::Bitfield<32>(flags, DE_ARRAY_BEGIN(s_bits), DE_ARRAY_END(s_bits));
+}
+
+const char* getShortObjectTypeName (VkDebugReportObjectTypeEXT objectType)
+{
+       static const char* const s_names[] =
+       {
+               "Unknown",
+               "Instance",
+               "PhysicalDevice",
+               "Device",
+               "Queue",
+               "Semaphore",
+               "CommandBuffer",
+               "Fence",
+               "DeviceMemory",
+               "Buffer",
+               "Image",
+               "Event",
+               "QueryPool",
+               "BufferView",
+               "ImageView",
+               "ShaderModule",
+               "PipelineCache",
+               "PipelineLayout",
+               "RenderPass",
+               "Pipeline",
+               "DescriptorSetLayout",
+               "Sampler",
+               "DescriptorPool",
+               "DescriptorSet",
+               "Framebuffer",
+               "CommandPool",
+               "SurfaceKHR",
+               "SwapchainKHR",
+               "DebugReportCallbackEXT",
+       };
+       return de::getSizedArrayElement<VK_DEBUG_REPORT_OBJECT_TYPE_EXT_LAST>(s_names, objectType);
+}
+
+tcu::Format::Enum<VkDebugReportObjectTypeEXT> shortObjectTypeStr (VkDebugReportObjectTypeEXT objectType)
+{
+       return tcu::Format::Enum<VkDebugReportObjectTypeEXT>(getShortObjectTypeName, objectType);
+}
+
+} // anonymous
+
+std::ostream& operator<< (std::ostream& str, const DebugReportMessage& message)
+{
+       str << shortDebugFlagsStr(message.flags) << ": "
+               << message.message
+               << " (code " << tcu::toHex(message.messageCode);
+
+       if (message.layerPrefix.empty())
+               str << " from " << message.layerPrefix;
+
+       str << " at " << shortObjectTypeStr(message.objectType) << ":" << message.location << ")";
+
+       return str;
+}
+
+namespace
+{
+
+VKAPI_ATTR VkBool32    VKAPI_CALL debugReportCallback (VkDebugReportFlagsEXT           flags,
+                                                                                                       VkDebugReportObjectTypeEXT      objectType,
+                                                                                                       deUint64                                        object,
+                                                                                                       size_t                                          location,
+                                                                                                       deInt32                                         messageCode,
+                                                                                                       const char*                                     pLayerPrefix,
+                                                                                                       const char*                                     pMessage,
+                                                                                                       void*                                           pUserData)
+{
+       DebugReportRecorder::MessageList* const messageList     = reinterpret_cast<DebugReportRecorder::MessageList*>(pUserData);
+
+       messageList->append(DebugReportMessage(flags, objectType, object, location, messageCode, pLayerPrefix, pMessage));
+
+       return VK_TRUE;
+}
+
+Move<VkDebugReportCallbackEXT> createCallback (const InstanceInterface&                                vki,
+                                                                                          VkInstance                                                   instance,
+                                                                                          DebugReportRecorder::MessageList*    messageList)
+{
+       const VkDebugReportFlagsEXT                                     allFlags        = VK_DEBUG_REPORT_INFORMATION_BIT_EXT
+                                                                                                                       | VK_DEBUG_REPORT_WARNING_BIT_EXT
+                                                                                                                       | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT
+                                                                                                                       | VK_DEBUG_REPORT_ERROR_BIT_EXT
+                                                                                                                       | VK_DEBUG_REPORT_DEBUG_BIT_EXT;
+
+       const VkDebugReportCallbackCreateInfoEXT        createInfo      =
+       {
+               VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT,
+               DE_NULL,
+               allFlags,
+               debugReportCallback,
+               messageList
+       };
+
+       return createDebugReportCallbackEXT(vki, instance, &createInfo);
+}
+
+} // anonymous
+
+DebugReportRecorder::DebugReportRecorder (const InstanceInterface& vki, VkInstance instance)
+       : m_messages    (1024)
+       , m_callback    (createCallback(vki, instance, &m_messages))
+{
+}
+
+DebugReportRecorder::~DebugReportRecorder (void)
+{
+}
+
+} // vk
diff --git a/external/vulkancts/framework/vulkan/vkDebugReportUtil.hpp b/external/vulkancts/framework/vulkan/vkDebugReportUtil.hpp
new file mode 100644 (file)
index 0000000..8a184cf
--- /dev/null
@@ -0,0 +1,97 @@
+#ifndef _VKDEBUGREPORTUTIL_HPP
+#define _VKDEBUGREPORTUTIL_HPP
+/*-------------------------------------------------------------------------
+ * Vulkan CTS Framework
+ * --------------------
+ *
+ * Copyright (c) 2016 Google Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and/or associated documentation files (the
+ * "Materials"), to deal in the Materials without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Materials, and to
+ * permit persons to whom the Materials are furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice(s) and this permission notice shall be
+ * included in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+ *
+ *//*!
+ * \file
+ * \brief VK_EXT_debug_report utilities
+ *//*--------------------------------------------------------------------*/
+
+#include "vkDefs.hpp"
+#include "vkRef.hpp"
+#include "deAppendList.hpp"
+
+#include <ostream>
+
+namespace vk
+{
+
+struct DebugReportMessage
+{
+       VkDebugReportFlagsEXT           flags;
+       VkDebugReportObjectTypeEXT      objectType;
+       deUint64                                        object;
+       size_t                                          location;
+       deInt32                                         messageCode;
+       std::string                                     layerPrefix;
+       std::string                                     message;
+
+       DebugReportMessage (void)
+               : flags                 (0)
+               , objectType    ((VkDebugReportObjectTypeEXT)0)
+               , object                (0)
+               , location              (0)
+               , messageCode   (0)
+       {}
+
+       DebugReportMessage (VkDebugReportFlagsEXT               flags_,
+                                               VkDebugReportObjectTypeEXT      objectType_,
+                                               deUint64                                        object_,
+                                               size_t                                          location_,
+                                               deInt32                                         messageCode_,
+                                               const std::string&                      layerPrefix_,
+                                               const std::string&                      message_)
+               : flags                 (flags_)
+               , objectType    (objectType_)
+               , object                (object_)
+               , location              (location_)
+               , messageCode   (messageCode_)
+               , layerPrefix   (layerPrefix_)
+               , message               (message_)
+       {}
+};
+
+std::ostream&  operator<<      (std::ostream& str, const DebugReportMessage& message);
+
+class DebugReportRecorder
+{
+public:
+       typedef de::AppendList<DebugReportMessage>      MessageList;
+
+                                                                                       DebugReportRecorder             (const InstanceInterface& vki, VkInstance instance);
+                                                                                       ~DebugReportRecorder    (void);
+
+       const MessageList&                                              getMessages                             (void) const { return m_messages; }
+       void                                                                    clearMessages                   (void) { m_messages.clear(); }
+
+private:
+       MessageList                                                             m_messages;
+       const Unique<VkDebugReportCallbackEXT>  m_callback;
+};
+
+} // vk
+
+#endif // _VKDEBUGREPORTUTIL_HPP
index 9c667f5..f754081 100644 (file)
@@ -420,7 +420,7 @@ def writeHandleType (api, filename):
 def getEnumValuePrefix (enum):
        prefix = enum.name[0]
        for i in range(1, len(enum.name)):
-               if enum.name[i].isupper():
+               if enum.name[i].isupper() and not enum.name[i-1].isupper():
                        prefix += "_"
                prefix += enum.name[i].upper()
        return prefix