1 #ifndef _VKTPIPELINEIMAGEUTIL_HPP 2 #define _VKTPIPELINEIMAGEUTIL_HPP 3 /*------------------------------------------------------------------------ 4 * Vulkan Conformance Tests 5 * ------------------------ 6 * 7 * Copyright (c) 2015 The Khronos Group Inc. 8 * Copyright (c) 2015 Imagination Technologies Ltd. 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); 11 * you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 * See the License for the specific language governing permissions and 20 * limitations under the License. 21 * 22 *//*! 23 * \file 24 * \brief Utilities for images. 25 *//*--------------------------------------------------------------------*/ 26 27 #include "tcuDefs.hpp" 28 #include "vkDefs.hpp" 29 #include "vkDefs.hpp" 30 #include "vkPlatform.hpp" 31 #include "vkMemUtil.hpp" 32 #include "vkRef.hpp" 33 #include "tcuTexture.hpp" 34 #include "tcuCompressedTexture.hpp" 35 36 namespace vkt 37 { 38 namespace pipeline 39 { 40 41 class TestTexture; 42 43 enum BorderColor 44 { 45 BORDER_COLOR_OPAQUE_BLACK, 46 BORDER_COLOR_OPAQUE_WHITE, 47 BORDER_COLOR_TRANSPARENT_BLACK, 48 49 BORDER_COLOR_COUNT 50 }; 51 52 bool isSupportedSamplableFormat (const vk::InstanceInterface& instanceInterface, 53 vk::VkPhysicalDevice device, 54 vk::VkFormat format); 55 bool isLinearFilteringSupported (const vk::InstanceInterface& instanceInterface, 56 vk::VkPhysicalDevice device, 57 vk::VkFormat format, 58 vk::VkImageTiling tiling); 59 60 vk::VkBorderColor getFormatBorderColor (BorderColor color, vk::VkFormat format); 61 62 /*--------------------------------------------------------------------*//*! 63 * Gets a tcu::TextureLevel initialized with data from a VK color 64 * attachment. 65 * 66 * The VkImage must be non-multisampled and able to be used as a source 67 * operand for transfer operations. 68 *//*--------------------------------------------------------------------*/ 69 de::MovePtr<tcu::TextureLevel> readColorAttachment (const vk::DeviceInterface& vk, 70 vk::VkDevice device, 71 vk::VkQueue queue, 72 deUint32 queueFamilyIndex, 73 vk::Allocator& allocator, 74 vk::VkImage image, 75 vk::VkFormat format, 76 const tcu::UVec2& renderSize); 77 78 /*--------------------------------------------------------------------*//*! 79 * Uploads data from a test texture to a destination VK image. 80 * 81 * The VkImage must be non-multisampled and able to be used as a 82 * destination operand for transfer operations. 83 *//*--------------------------------------------------------------------*/ 84 void uploadTestTexture (const vk::DeviceInterface& vk, 85 vk::VkDevice device, 86 vk::VkQueue queue, 87 deUint32 queueFamilyIndex, 88 vk::Allocator& allocator, 89 const TestTexture& testTexture, 90 vk::VkImage destImage); 91 92 class TestTexture 93 { 94 public: 95 TestTexture (const tcu::TextureFormat& format, int width, int height, int depth); 96 TestTexture (const tcu::CompressedTexFormat& format, int width, int height, int depth); 97 virtual ~TestTexture (void); 98 99 virtual int getNumLevels (void) const = 0; 100 virtual deUint32 getSize (void) const; 101 virtual int getArraySize (void) const { return 1; } 102 103 virtual bool isCompressed (void) const { return !m_compressedLevels.empty(); } 104 virtual deUint32 getCompressedSize (void) const; 105 106 virtual tcu::PixelBufferAccess getLevel (int level, int layer) = 0; 107 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const = 0; 108 109 virtual tcu::CompressedTexture& getCompressedLevel (int level, int layer); 110 virtual const tcu::CompressedTexture& getCompressedLevel (int level, int layer) const; 111 112 virtual std::vector<vk::VkBufferImageCopy> getBufferCopyRegions (void) const; 113 virtual void write (deUint8* destPtr) const; 114 115 protected: 116 void populateLevels (const std::vector<tcu::PixelBufferAccess>& levels); 117 void populateCompressedLevels (tcu::CompressedTexFormat format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels); 118 119 static void fillWithGradient (const tcu::PixelBufferAccess& levelAccess); 120 121 protected: 122 std::vector<tcu::CompressedTexture*> m_compressedLevels; 123 }; 124 125 class TestTexture1D : public TestTexture 126 { 127 private: 128 tcu::Texture1D m_texture; 129 130 public: 131 TestTexture1D (const tcu::TextureFormat& format, int width); 132 TestTexture1D (const tcu::CompressedTexFormat& format, int width); 133 virtual ~TestTexture1D (void); 134 135 virtual int getNumLevels (void) const; 136 virtual tcu::PixelBufferAccess getLevel (int level, int layer); 137 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const; 138 virtual const tcu::Texture1D& getTexture (void) const; 139 }; 140 141 class TestTexture1DArray : public TestTexture 142 { 143 private: 144 tcu::Texture1DArray m_texture; 145 146 public: 147 TestTexture1DArray (const tcu::TextureFormat& format, int width, int arraySize); 148 TestTexture1DArray (const tcu::CompressedTexFormat& format, int width, int arraySize); 149 virtual ~TestTexture1DArray (void); 150 151 virtual int getNumLevels (void) const; 152 virtual tcu::PixelBufferAccess getLevel (int level, int layer); 153 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const; 154 virtual const tcu::Texture1DArray& getTexture (void) const; 155 virtual int getArraySize (void) const; 156 }; 157 158 class TestTexture2D : public TestTexture 159 { 160 private: 161 tcu::Texture2D m_texture; 162 163 public: 164 TestTexture2D (const tcu::TextureFormat& format, int width, int height); 165 TestTexture2D (const tcu::CompressedTexFormat& format, int width, int height); 166 virtual ~TestTexture2D (void); 167 168 virtual int getNumLevels (void) const; 169 virtual tcu::PixelBufferAccess getLevel (int level, int layer); 170 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const; 171 virtual const tcu::Texture2D& getTexture (void) const; 172 }; 173 174 class TestTexture2DArray : public TestTexture 175 { 176 private: 177 tcu::Texture2DArray m_texture; 178 179 public: 180 TestTexture2DArray (const tcu::TextureFormat& format, int width, int height, int arraySize); 181 TestTexture2DArray (const tcu::CompressedTexFormat& format, int width, int height, int arraySize); 182 virtual ~TestTexture2DArray (void); 183 184 virtual int getNumLevels (void) const; 185 virtual tcu::PixelBufferAccess getLevel (int level, int layer); 186 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const; 187 virtual const tcu::Texture2DArray& getTexture (void) const; 188 virtual int getArraySize (void) const; 189 }; 190 191 class TestTexture3D : public TestTexture 192 { 193 private: 194 tcu::Texture3D m_texture; 195 196 public: 197 TestTexture3D (const tcu::TextureFormat& format, int width, int height, int depth); 198 TestTexture3D (const tcu::CompressedTexFormat& format, int width, int height, int depth); 199 virtual ~TestTexture3D (void); 200 201 virtual int getNumLevels (void) const; 202 virtual tcu::PixelBufferAccess getLevel (int level, int layer); 203 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const; 204 virtual const tcu::Texture3D& getTexture (void) const; 205 }; 206 207 class TestTextureCube : public TestTexture 208 { 209 private: 210 tcu::TextureCube m_texture; 211 212 public: 213 TestTextureCube (const tcu::TextureFormat& format, int size); 214 TestTextureCube (const tcu::CompressedTexFormat& format, int size); 215 virtual ~TestTextureCube (void); 216 217 virtual int getNumLevels (void) const; 218 virtual tcu::PixelBufferAccess getLevel (int level, int layer); 219 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const; 220 virtual int getArraySize (void) const; 221 virtual const tcu::TextureCube& getTexture (void) const; 222 }; 223 224 class TestTextureCubeArray: public TestTexture 225 { 226 private: 227 tcu::TextureCubeArray m_texture; 228 229 public: 230 TestTextureCubeArray (const tcu::TextureFormat& format, int size, int arraySize); 231 TestTextureCubeArray (const tcu::CompressedTexFormat& format, int size, int arraySize); 232 virtual ~TestTextureCubeArray (void); 233 234 virtual int getNumLevels (void) const; 235 virtual tcu::PixelBufferAccess getLevel (int level, int layer); 236 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const; 237 virtual int getArraySize (void) const; 238 virtual const tcu::TextureCubeArray& getTexture (void) const; 239 }; 240 241 } // pipeline 242 } // vkt 243 244 #endif // _VKTPIPELINEIMAGEUTIL_HPP 245