Add initial Vulkan image utilities.
authorMika Isojärvi <misojarvi@google.com>
Fri, 7 Aug 2015 22:42:02 +0000 (15:42 -0700)
committerMika Isojärvi <misojarvi@google.com>
Mon, 17 Aug 2015 22:38:43 +0000 (15:38 -0700)
Change-Id: Ic33903b8c8717d8f0d36d192be5d20bb43df6dae

external/vulkancts/framework/vulkan/CMakeLists.txt
external/vulkancts/framework/vulkan/vkImageUtil.cpp [new file with mode: 0644]
external/vulkancts/framework/vulkan/vkImageUtil.hpp [new file with mode: 0644]

index c39a07f..b4e27ea 100644 (file)
@@ -29,6 +29,8 @@ set(VKUTIL_SRCS
        vkBinaryRegistry.hpp
        vkNullDriver.cpp
        vkNullDriver.hpp
+       vkImageUtil.cpp
+       vkImageUtil.hpp
        )
 
 set(VKUTIL_LIBS
diff --git a/external/vulkancts/framework/vulkan/vkImageUtil.cpp b/external/vulkancts/framework/vulkan/vkImageUtil.cpp
new file mode 100644 (file)
index 0000000..c05645d
--- /dev/null
@@ -0,0 +1,233 @@
+/*-------------------------------------------------------------------------
+ * Vulkan CTS Framework
+ * --------------------
+ *
+ * Copyright (c) 2015 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 Confidential Information as defined by the
+ * Khronos Membership Agreement until designated non-confidential by
+ * Khronos, at which point this condition clause shall be removed.
+ *
+ * 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 Image utilities.
+ *//*--------------------------------------------------------------------*/
+
+#include "vkImageUtil.hpp"
+
+namespace vk
+{
+
+using tcu::TextureFormat;
+
+VkFormat mapTextureFormat (const tcu::TextureFormat& format)
+{
+       DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELORDER_LAST < (1<<16));
+       DE_STATIC_ASSERT(tcu::TextureFormat::CHANNELTYPE_LAST < (1<<16));
+
+#define PACK_FMT(ORDER, TYPE) ((int(ORDER) << 16) | int(TYPE))
+#define FMT_CASE(ORDER, TYPE) PACK_FMT(tcu::TextureFormat::ORDER, tcu::TextureFormat::TYPE)
+
+       switch (PACK_FMT(format.order, format.type))
+       {
+               case FMT_CASE(RGB, UNORM_SHORT_565):                            return VK_FORMAT_R5G6B5_UNORM;
+               case FMT_CASE(RGBA, UNORM_SHORT_5551):                          return VK_FORMAT_R5G5B5A1_UNORM;
+
+               case FMT_CASE(R, UNORM_INT8):                                           return VK_FORMAT_R8_UNORM;
+               case FMT_CASE(R, SNORM_INT8):                                           return VK_FORMAT_R8_SNORM;
+               case FMT_CASE(R, UNSIGNED_INT8):                                        return VK_FORMAT_R8_UINT;
+               case FMT_CASE(R, SIGNED_INT8):                                          return VK_FORMAT_R8_SINT;
+               case FMT_CASE(sR, UNORM_INT8):                                          return VK_FORMAT_R8_SRGB;
+
+               case FMT_CASE(RG, UNORM_INT8):                                          return VK_FORMAT_R8G8_UNORM;
+               case FMT_CASE(RG, SNORM_INT8):                                          return VK_FORMAT_R8G8_SNORM;
+               case FMT_CASE(RG, UNSIGNED_INT8):                                       return VK_FORMAT_R8G8_UINT;
+               case FMT_CASE(RG, SIGNED_INT8):                                         return VK_FORMAT_R8G8_SINT;
+               case FMT_CASE(sRG, SIGNED_INT8):                                        return VK_FORMAT_R8G8_SRGB;
+
+               case FMT_CASE(RGB, UNORM_INT8):                                         return VK_FORMAT_R8G8B8_UNORM;
+               case FMT_CASE(RGB, SNORM_INT8):                                         return VK_FORMAT_R8G8B8_SNORM;
+               case FMT_CASE(RGB, UNSIGNED_INT8):                                      return VK_FORMAT_R8G8B8_UINT;
+               case FMT_CASE(RGB, SIGNED_INT8):                                        return VK_FORMAT_R8G8B8_SINT;
+               case FMT_CASE(sRGB, SNORM_INT8):                                        return VK_FORMAT_R8G8B8_SRGB;
+
+               case FMT_CASE(RGBA, UNORM_INT8):                                        return VK_FORMAT_R8G8B8A8_UNORM;
+               case FMT_CASE(RGBA, SNORM_INT8):                                        return VK_FORMAT_R8G8B8A8_SNORM;
+               case FMT_CASE(RGBA, UNSIGNED_INT8):                                     return VK_FORMAT_R8G8B8A8_UINT;
+               case FMT_CASE(RGBA, SIGNED_INT8):                                       return VK_FORMAT_R8G8B8A8_SINT;
+               case FMT_CASE(sRGBA, SNORM_INT8):                                       return VK_FORMAT_R8G8B8A8_SRGB;
+
+               case FMT_CASE(RGBA, UNORM_INT_1010102_REV):                     return VK_FORMAT_R10G10B10A2_UNORM;
+               case FMT_CASE(RGBA, UNSIGNED_INT_1010102_REV):          return VK_FORMAT_R10G10B10A2_UINT;
+
+               case FMT_CASE(R, UNORM_INT16):                                          return VK_FORMAT_R16_UNORM;
+               case FMT_CASE(R, SNORM_INT16):                                          return VK_FORMAT_R16_SNORM;
+               case FMT_CASE(R, UNSIGNED_INT16):                                       return VK_FORMAT_R16_UINT;
+               case FMT_CASE(R, SIGNED_INT16):                                         return VK_FORMAT_R16_SINT;
+               case FMT_CASE(R, HALF_FLOAT):                                           return VK_FORMAT_R16_SFLOAT;
+
+               case FMT_CASE(RG, UNORM_INT16):                                         return VK_FORMAT_R16G16_UNORM;
+               case FMT_CASE(RG, SNORM_INT16):                                         return VK_FORMAT_R16G16_SNORM;
+               case FMT_CASE(RG, UNSIGNED_INT16):                                      return VK_FORMAT_R16G16_UINT;
+               case FMT_CASE(RG, SIGNED_INT16):                                        return VK_FORMAT_R16G16_SINT;
+               case FMT_CASE(RG, HALF_FLOAT):                                          return VK_FORMAT_R16G16_SFLOAT;
+
+               case FMT_CASE(RGB, UNORM_INT16):                                        return VK_FORMAT_R16G16B16_UNORM;
+               case FMT_CASE(RGB, SNORM_INT16):                                        return VK_FORMAT_R16G16B16_SNORM;
+               case FMT_CASE(RGB, UNSIGNED_INT16):                                     return VK_FORMAT_R16G16B16_UINT;
+               case FMT_CASE(RGB, SIGNED_INT16):                                       return VK_FORMAT_R16G16B16_SINT;
+               case FMT_CASE(RGB, HALF_FLOAT):                                         return VK_FORMAT_R16G16B16_SFLOAT;
+
+               case FMT_CASE(RGBA, UNORM_INT16):                                       return VK_FORMAT_R16G16B16A16_UNORM;
+               case FMT_CASE(RGBA, SNORM_INT16):                                       return VK_FORMAT_R16G16B16A16_SNORM;
+               case FMT_CASE(RGBA, UNSIGNED_INT16):                            return VK_FORMAT_R16G16B16A16_UINT;
+               case FMT_CASE(RGBA, SIGNED_INT16):                                      return VK_FORMAT_R16G16B16A16_SINT;
+               case FMT_CASE(RGBA, HALF_FLOAT):                                        return VK_FORMAT_R16G16B16A16_SFLOAT;
+
+               case FMT_CASE(R, UNSIGNED_INT32):                                       return VK_FORMAT_R32_UINT;
+               case FMT_CASE(R, SIGNED_INT32):                                         return VK_FORMAT_R32_SINT;
+               case FMT_CASE(R, FLOAT):                                                        return VK_FORMAT_R32_SFLOAT;
+
+               case FMT_CASE(RG, UNSIGNED_INT32):                                      return VK_FORMAT_R32G32_UINT;
+               case FMT_CASE(RG, SIGNED_INT32):                                        return VK_FORMAT_R32G32_SINT;
+               case FMT_CASE(RG, FLOAT):                                                       return VK_FORMAT_R32G32_SFLOAT;
+
+               case FMT_CASE(RGB, UNSIGNED_INT32):                                     return VK_FORMAT_R32G32B32_UINT;
+               case FMT_CASE(RGB, SIGNED_INT32):                                       return VK_FORMAT_R32G32B32_SINT;
+               case FMT_CASE(RGB, FLOAT):                                                      return VK_FORMAT_R32G32B32_SFLOAT;
+
+               case FMT_CASE(RGBA, UNSIGNED_INT32):                            return VK_FORMAT_R32G32B32A32_UINT;
+               case FMT_CASE(RGBA, SIGNED_INT32):                                      return VK_FORMAT_R32G32B32A32_SINT;
+               case FMT_CASE(RGBA, FLOAT):                                                     return VK_FORMAT_R32G32B32A32_SFLOAT;
+
+               case FMT_CASE(RGB, UNSIGNED_INT_11F_11F_10F_REV):       return VK_FORMAT_R11G11B10_UFLOAT;
+               case FMT_CASE(RGB, UNSIGNED_INT_999_E5_REV):            return VK_FORMAT_R9G9B9E5_UFLOAT;
+
+               case FMT_CASE(D, UNORM_INT16):                                          return VK_FORMAT_D16_UNORM;
+               case FMT_CASE(D, UNORM_INT24):                                          return VK_FORMAT_D24_UNORM;
+               case FMT_CASE(D, FLOAT):                                                        return VK_FORMAT_D32_SFLOAT;
+
+               case FMT_CASE(S, UNSIGNED_INT8):                                        return VK_FORMAT_S8_UINT;
+               case FMT_CASE(DS, FLOAT_UNSIGNED_INT_24_8_REV):         return VK_FORMAT_D24_UNORM_S8_UINT;
+
+               case FMT_CASE(BGRA, UNORM_SHORT_4444):                          return VK_FORMAT_B4G4R4A4_UNORM;
+               case FMT_CASE(BGRA, UNORM_SHORT_5551):                          return VK_FORMAT_B5G5R5A1_UNORM;
+               default:
+                       TCU_THROW(InternalError, "Unknown texture format");
+       }
+
+#undef PACK_FMT
+#undef FMT_CASE
+}
+
+tcu::TextureFormat mapVkFormat (VkFormat format)
+{
+       switch (format)
+       {
+               case VK_FORMAT_R5G6B5_UNORM:            return TextureFormat(TextureFormat::RGB,        TextureFormat::UNORM_SHORT_565);
+               case VK_FORMAT_R5G5B5A1_UNORM:          return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_SHORT_5551);
+
+               case VK_FORMAT_R8_UNORM:                        return TextureFormat(TextureFormat::R,          TextureFormat::UNORM_INT8);
+               case VK_FORMAT_R8_SNORM:                        return TextureFormat(TextureFormat::R,          TextureFormat::SNORM_INT8);
+               case VK_FORMAT_R8_UINT:                         return TextureFormat(TextureFormat::R,          TextureFormat::UNSIGNED_INT8);
+               case VK_FORMAT_R8_SINT:                         return TextureFormat(TextureFormat::R,          TextureFormat::SIGNED_INT8);
+               case VK_FORMAT_R8_SRGB:                         return TextureFormat(TextureFormat::sR,         TextureFormat::UNORM_INT8);
+
+               case VK_FORMAT_R8G8_UNORM:                      return TextureFormat(TextureFormat::RG,         TextureFormat::UNORM_INT8);
+               case VK_FORMAT_R8G8_SNORM:                      return TextureFormat(TextureFormat::RG,         TextureFormat::SNORM_INT8);
+               case VK_FORMAT_R8G8_UINT:                       return TextureFormat(TextureFormat::RG,         TextureFormat::UNSIGNED_INT8);
+               case VK_FORMAT_R8G8_SINT:                       return TextureFormat(TextureFormat::RG,         TextureFormat::SIGNED_INT8);
+               case VK_FORMAT_R8G8_SRGB:                       return TextureFormat(TextureFormat::sRG,        TextureFormat::SIGNED_INT8);
+
+               case VK_FORMAT_R8G8B8_UNORM:            return TextureFormat(TextureFormat::RGB,        TextureFormat::UNORM_INT8);
+               case VK_FORMAT_R8G8B8_SNORM:            return TextureFormat(TextureFormat::RGB,        TextureFormat::SNORM_INT8);
+               case VK_FORMAT_R8G8B8_UINT:                     return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT8);
+               case VK_FORMAT_R8G8B8_SINT:                     return TextureFormat(TextureFormat::RGB,        TextureFormat::SIGNED_INT8);
+               case VK_FORMAT_R8G8B8_SRGB:                     return TextureFormat(TextureFormat::sRGB,       TextureFormat::SNORM_INT8);
+
+               case VK_FORMAT_R8G8B8A8_UNORM:          return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_INT8);
+               case VK_FORMAT_R8G8B8A8_SNORM:          return TextureFormat(TextureFormat::RGBA,       TextureFormat::SNORM_INT8);
+               case VK_FORMAT_R8G8B8A8_UINT:           return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT8);
+               case VK_FORMAT_R8G8B8A8_SINT:           return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT8);
+               case VK_FORMAT_R8G8B8A8_SRGB:           return TextureFormat(TextureFormat::sRGBA,      TextureFormat::SNORM_INT8);
+
+               case VK_FORMAT_R10G10B10A2_UNORM:       return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_INT_1010102_REV);
+               case VK_FORMAT_R10G10B10A2_UINT:        return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT_1010102_REV);
+
+               case VK_FORMAT_R16_UNORM:                       return TextureFormat(TextureFormat::R,          TextureFormat::UNORM_INT16);
+               case VK_FORMAT_R16_SNORM:                       return TextureFormat(TextureFormat::R,          TextureFormat::SNORM_INT16);
+               case VK_FORMAT_R16_UINT:                        return TextureFormat(TextureFormat::R,          TextureFormat::UNSIGNED_INT16);
+               case VK_FORMAT_R16_SINT:                        return TextureFormat(TextureFormat::R,          TextureFormat::SIGNED_INT16);
+               case VK_FORMAT_R16_SFLOAT:                      return TextureFormat(TextureFormat::R,          TextureFormat::HALF_FLOAT);
+
+               case VK_FORMAT_R16G16_UNORM:            return TextureFormat(TextureFormat::RG,         TextureFormat::UNORM_INT16);
+               case VK_FORMAT_R16G16_SNORM:            return TextureFormat(TextureFormat::RG,         TextureFormat::SNORM_INT16);
+               case VK_FORMAT_R16G16_UINT:                     return TextureFormat(TextureFormat::RG,         TextureFormat::UNSIGNED_INT16);
+               case VK_FORMAT_R16G16_SINT:                     return TextureFormat(TextureFormat::RG,         TextureFormat::SIGNED_INT16);
+               case VK_FORMAT_R16G16_SFLOAT:           return TextureFormat(TextureFormat::RG,         TextureFormat::HALF_FLOAT);
+
+               case VK_FORMAT_R16G16B16_UNORM:         return TextureFormat(TextureFormat::RGB,        TextureFormat::UNORM_INT16);
+               case VK_FORMAT_R16G16B16_SNORM:         return TextureFormat(TextureFormat::RGB,        TextureFormat::SNORM_INT16);
+               case VK_FORMAT_R16G16B16_UINT:          return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT16);
+               case VK_FORMAT_R16G16B16_SINT:          return TextureFormat(TextureFormat::RGB,        TextureFormat::SIGNED_INT16);
+               case VK_FORMAT_R16G16B16_SFLOAT:        return TextureFormat(TextureFormat::RGB,        TextureFormat::HALF_FLOAT);
+
+               case VK_FORMAT_R16G16B16A16_UNORM:      return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNORM_INT16);
+               case VK_FORMAT_R16G16B16A16_SNORM:      return TextureFormat(TextureFormat::RGBA,       TextureFormat::SNORM_INT16);
+               case VK_FORMAT_R16G16B16A16_UINT:       return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT16);
+               case VK_FORMAT_R16G16B16A16_SINT:       return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT16);
+               case VK_FORMAT_R16G16B16A16_SFLOAT:     return TextureFormat(TextureFormat::RGBA,       TextureFormat::HALF_FLOAT);
+
+               case VK_FORMAT_R32_UINT:                        return TextureFormat(TextureFormat::R,          TextureFormat::UNSIGNED_INT32);
+               case VK_FORMAT_R32_SINT:                        return TextureFormat(TextureFormat::R,          TextureFormat::SIGNED_INT32);
+               case VK_FORMAT_R32_SFLOAT:                      return TextureFormat(TextureFormat::R,          TextureFormat::FLOAT);
+
+               case VK_FORMAT_R32G32_UINT:                     return TextureFormat(TextureFormat::RG,         TextureFormat::UNSIGNED_INT32);
+               case VK_FORMAT_R32G32_SINT:                     return TextureFormat(TextureFormat::RG,         TextureFormat::SIGNED_INT32);
+               case VK_FORMAT_R32G32_SFLOAT:           return TextureFormat(TextureFormat::RG,         TextureFormat::FLOAT);
+
+               case VK_FORMAT_R32G32B32_UINT:          return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT32);
+               case VK_FORMAT_R32G32B32_SINT:          return TextureFormat(TextureFormat::RGB,        TextureFormat::SIGNED_INT32);
+               case VK_FORMAT_R32G32B32_SFLOAT:        return TextureFormat(TextureFormat::RGB,        TextureFormat::FLOAT);
+
+               case VK_FORMAT_R32G32B32A32_UINT:       return TextureFormat(TextureFormat::RGBA,       TextureFormat::UNSIGNED_INT32);
+               case VK_FORMAT_R32G32B32A32_SINT:       return TextureFormat(TextureFormat::RGBA,       TextureFormat::SIGNED_INT32);
+               case VK_FORMAT_R32G32B32A32_SFLOAT:     return TextureFormat(TextureFormat::RGBA,       TextureFormat::FLOAT);
+
+               case VK_FORMAT_R11G11B10_UFLOAT:        return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT_11F_11F_10F_REV);
+               case VK_FORMAT_R9G9B9E5_UFLOAT:         return TextureFormat(TextureFormat::RGB,        TextureFormat::UNSIGNED_INT_999_E5_REV);
+
+               case VK_FORMAT_D16_UNORM:                       return TextureFormat(TextureFormat::D,          TextureFormat::UNORM_INT16);
+               case VK_FORMAT_D24_UNORM:                       return TextureFormat(TextureFormat::D,          TextureFormat::UNORM_INT24);
+               case VK_FORMAT_D32_SFLOAT:                      return TextureFormat(TextureFormat::D,          TextureFormat::FLOAT);
+
+               case VK_FORMAT_S8_UINT:                         return TextureFormat(TextureFormat::S,          TextureFormat::UNSIGNED_INT8);
+               case VK_FORMAT_D24_UNORM_S8_UINT:       return TextureFormat(TextureFormat::DS,         TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV);
+
+               case VK_FORMAT_B4G4R4A4_UNORM:          return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNORM_SHORT_4444);
+               case VK_FORMAT_B5G5R5A1_UNORM:          return TextureFormat(TextureFormat::BGRA,       TextureFormat::UNORM_SHORT_5551);
+               default:
+                       TCU_THROW(InternalError, "Unknown image format");
+       }
+}
+
+} // vk
diff --git a/external/vulkancts/framework/vulkan/vkImageUtil.hpp b/external/vulkancts/framework/vulkan/vkImageUtil.hpp
new file mode 100644 (file)
index 0000000..3916765
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef _VKIMAGEUTIL_HPP
+#define _VKIMAGEUTIL_HPP
+/*-------------------------------------------------------------------------
+ * Vulkan CTS Framework
+ * --------------------
+ *
+ * Copyright (c) 2015 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 Confidential Information as defined by the
+ * Khronos Membership Agreement until designated non-confidential by
+ * Khronos, at which point this condition clause shall be removed.
+ *
+ * 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 Image utilities.
+ *//*--------------------------------------------------------------------*/
+
+#include "vkDefs.hpp"
+
+#include "tcuTexture.hpp"
+
+namespace vk
+{
+
+VkFormat                       mapTextureFormat        (const tcu::TextureFormat& format);
+tcu::TextureFormat     mapVkFormat                     (VkFormat format);
+
+} // vk
+
+#endif // _VKIMAGEUTIL_HPP