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 #include "deSharedPtr.hpp" 36 37 namespace vkt 38 { 39 namespace pipeline 40 { 41 42 class TestTexture; 43 44 enum BorderColor 45 { 46 BORDER_COLOR_OPAQUE_BLACK, 47 BORDER_COLOR_OPAQUE_WHITE, 48 BORDER_COLOR_TRANSPARENT_BLACK, 49 50 BORDER_COLOR_COUNT 51 }; 52 53 bool isSupportedSamplableFormat (const vk::InstanceInterface& instanceInterface, 54 vk::VkPhysicalDevice device, 55 vk::VkFormat format); 56 bool isLinearFilteringSupported (const vk::InstanceInterface& instanceInterface, 57 vk::VkPhysicalDevice device, 58 vk::VkFormat format, 59 vk::VkImageTiling tiling); 60 61 bool isMinMaxFilteringSupported (const vk::InstanceInterface& instanceInterface, 62 vk::VkPhysicalDevice device, 63 vk::VkFormat format, 64 vk::VkImageTiling tiling); 65 66 vk::VkBorderColor getFormatBorderColor (BorderColor color, vk::VkFormat format); 67 68 void getLookupScaleBias (vk::VkFormat format, 69 tcu::Vec4& lookupScale, 70 tcu::Vec4& lookupBias); 71 72 /*--------------------------------------------------------------------*//*! 73 * Gets a tcu::TextureLevel initialized with data from a VK color 74 * attachment. 75 * 76 * The VkImage must be non-multisampled and able to be used as a source 77 * operand for transfer operations. 78 *//*--------------------------------------------------------------------*/ 79 de::MovePtr<tcu::TextureLevel> readColorAttachment (const vk::DeviceInterface& vk, 80 vk::VkDevice device, 81 vk::VkQueue queue, 82 deUint32 queueFamilyIndex, 83 vk::Allocator& allocator, 84 vk::VkImage image, 85 vk::VkFormat format, 86 const tcu::UVec2& renderSize); 87 88 89 /*--------------------------------------------------------------------*//*! 90 * Gets a tcu::TextureLevel initialized with data from a VK depth 91 * attachment. 92 * 93 * The VkImage must be non-multisampled and able to be used as a source 94 * operand for transfer operations. 95 *//*--------------------------------------------------------------------*/ 96 de::MovePtr<tcu::TextureLevel> readDepthAttachment (const vk::DeviceInterface& vk, 97 vk::VkDevice device, 98 vk::VkQueue queue, 99 deUint32 queueFamilyIndex, 100 vk::Allocator& allocator, 101 vk::VkImage image, 102 vk::VkFormat format, 103 const tcu::UVec2& renderSize, 104 vk::VkImageLayout currentLayout = vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); 105 106 /*--------------------------------------------------------------------*//*! 107 * Gets a tcu::TextureLevel initialized with data from a VK stencil 108 * attachment. 109 * 110 * The VkImage must be non-multisampled and able to be used as a source 111 * operand for transfer operations. 112 *//*--------------------------------------------------------------------*/ 113 de::MovePtr<tcu::TextureLevel> readStencilAttachment (const vk::DeviceInterface& vk, 114 vk::VkDevice device, 115 vk::VkQueue queue, 116 deUint32 queueFamilyIndex, 117 vk::Allocator& allocator, 118 vk::VkImage image, 119 vk::VkFormat format, 120 const tcu::UVec2& renderSize, 121 vk::VkImageLayout currentLayout = vk::VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); 122 123 124 /*--------------------------------------------------------------------*//*! 125 * Uploads data from a test texture to a destination VK image. 126 * 127 * The VkImage must be non-multisampled and able to be used as a 128 * destination operand for transfer operations. 129 *//*--------------------------------------------------------------------*/ 130 void uploadTestTexture (const vk::DeviceInterface& vk, 131 vk::VkDevice device, 132 vk::VkQueue queue, 133 deUint32 queueFamilyIndex, 134 vk::Allocator& allocator, 135 const TestTexture& testTexture, 136 vk::VkImage destImage); 137 138 /*--------------------------------------------------------------------*//*! 139 * Uploads data from a test texture to a destination VK image using sparse 140 * binding. 141 * 142 * The VkImage must be non-multisampled and able to be used as a 143 * destination operand for transfer operations. 144 *//*--------------------------------------------------------------------*/ 145 void uploadTestTextureSparse (const vk::DeviceInterface& vk, 146 vk::VkDevice device, 147 const vk::VkPhysicalDevice physicalDevice, 148 const vk::InstanceInterface& instance, 149 const vk::VkImageCreateInfo& imageCreateInfo, 150 vk::VkQueue universalQueue, 151 deUint32 universalQueueFamilyIndex, 152 vk::VkQueue sparseQueue, 153 vk::Allocator& allocator, 154 std::vector<de::SharedPtr<vk::Allocation> >& allocations, 155 const TestTexture& srcTexture, 156 vk::VkImage destImage); 157 158 class TestTexture 159 { 160 public: 161 TestTexture (const tcu::TextureFormat& format, int width, int height, int depth); 162 TestTexture (const tcu::CompressedTexFormat& format, int width, int height, int depth); 163 virtual ~TestTexture (void); 164 165 virtual int getNumLevels (void) const = 0; 166 virtual deUint32 getSize (void) const; getArraySize(void) const167 virtual int getArraySize (void) const { return 1; } 168 isCompressed(void) const169 virtual bool isCompressed (void) const { return !m_compressedLevels.empty(); } 170 virtual deUint32 getCompressedSize (void) const; 171 172 virtual tcu::PixelBufferAccess getLevel (int level, int layer) = 0; 173 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const = 0; 174 175 virtual tcu::CompressedTexture& getCompressedLevel (int level, int layer); 176 virtual const tcu::CompressedTexture& getCompressedLevel (int level, int layer) const; 177 178 virtual std::vector<vk::VkBufferImageCopy> getBufferCopyRegions (void) const; 179 virtual void write (deUint8* destPtr) const; 180 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const = 0; 181 182 virtual const tcu::TextureFormat& getTextureFormat (void) const = 0; 183 virtual tcu::UVec3 getTextureDimension (void) const = 0; 184 185 protected: 186 void populateLevels (const std::vector<tcu::PixelBufferAccess>& levels); 187 void populateCompressedLevels (tcu::CompressedTexFormat format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels); 188 189 static void fillWithGradient (const tcu::PixelBufferAccess& levelAccess); 190 191 void copyToTexture (TestTexture&) const; 192 193 protected: 194 std::vector<tcu::CompressedTexture*> m_compressedLevels; 195 }; 196 197 class TestTexture1D : public TestTexture 198 { 199 private: 200 tcu::Texture1D m_texture; 201 202 public: 203 TestTexture1D (const tcu::TextureFormat& format, int width); 204 TestTexture1D (const tcu::CompressedTexFormat& format, int width); 205 virtual ~TestTexture1D (void); 206 207 virtual int getNumLevels (void) const; 208 virtual tcu::PixelBufferAccess getLevel (int level, int layer); 209 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const; 210 virtual const tcu::Texture1D& getTexture (void) const; 211 virtual tcu::Texture1D& getTexture (void); getTextureFormat(void) const212 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); } getTextureDimension(void) const213 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getWidth(), 1, 1); } 214 215 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const; 216 }; 217 218 class TestTexture1DArray : public TestTexture 219 { 220 private: 221 tcu::Texture1DArray m_texture; 222 223 public: 224 TestTexture1DArray (const tcu::TextureFormat& format, int width, int arraySize); 225 TestTexture1DArray (const tcu::CompressedTexFormat& format, int width, int arraySize); 226 virtual ~TestTexture1DArray (void); 227 228 virtual int getNumLevels (void) const; 229 virtual tcu::PixelBufferAccess getLevel (int level, int layer); 230 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const; 231 virtual const tcu::Texture1DArray& getTexture (void) const; 232 virtual tcu::Texture1DArray& getTexture (void); 233 virtual int getArraySize (void) const; getTextureFormat(void) const234 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); } getTextureDimension(void) const235 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getWidth(), 1, 1); } 236 237 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const; 238 }; 239 240 class TestTexture2D : public TestTexture 241 { 242 private: 243 tcu::Texture2D m_texture; 244 245 public: 246 TestTexture2D (const tcu::TextureFormat& format, int width, int height); 247 TestTexture2D (const tcu::TextureFormat& format, int width, int height, int miplevels); 248 TestTexture2D (const tcu::CompressedTexFormat& format, int width, int height); 249 virtual ~TestTexture2D (void); 250 251 virtual int getNumLevels (void) const; 252 virtual tcu::PixelBufferAccess getLevel (int level, int layer); 253 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const; 254 virtual const tcu::Texture2D& getTexture (void) const; 255 virtual tcu::Texture2D& getTexture (void); getTextureFormat(void) const256 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); } getTextureDimension(void) const257 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1); } 258 259 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const; 260 }; 261 262 class TestTexture2DArray : public TestTexture 263 { 264 private: 265 tcu::Texture2DArray m_texture; 266 267 public: 268 TestTexture2DArray (const tcu::TextureFormat& format, int width, int height, int arraySize); 269 TestTexture2DArray (const tcu::CompressedTexFormat& format, int width, int height, int arraySize); 270 virtual ~TestTexture2DArray (void); 271 272 virtual int getNumLevels (void) const; 273 virtual tcu::PixelBufferAccess getLevel (int level, int layer); 274 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const; 275 virtual const tcu::Texture2DArray& getTexture (void) const; 276 virtual tcu::Texture2DArray& getTexture (void); 277 virtual int getArraySize (void) const; getTextureFormat(void) const278 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); } getTextureDimension(void) const279 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1); } 280 281 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const; 282 }; 283 284 class TestTexture3D : public TestTexture 285 { 286 private: 287 tcu::Texture3D m_texture; 288 289 public: 290 TestTexture3D (const tcu::TextureFormat& format, int width, int height, int depth); 291 TestTexture3D (const tcu::CompressedTexFormat& format, int width, int height, int depth); 292 virtual ~TestTexture3D (void); 293 294 virtual int getNumLevels (void) const; 295 virtual tcu::PixelBufferAccess getLevel (int level, int layer); 296 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const; 297 virtual const tcu::Texture3D& getTexture (void) const; 298 virtual tcu::Texture3D& getTexture (void); getTextureFormat(void) const299 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); } getTextureDimension(void) const300 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), m_texture.getDepth()); } 301 302 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const; 303 }; 304 305 class TestTextureCube : public TestTexture 306 { 307 private: 308 tcu::TextureCube m_texture; 309 310 public: 311 TestTextureCube (const tcu::TextureFormat& format, int size); 312 TestTextureCube (const tcu::CompressedTexFormat& format, int size); 313 virtual ~TestTextureCube (void); 314 315 virtual int getNumLevels (void) const; 316 virtual tcu::PixelBufferAccess getLevel (int level, int layer); 317 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const; 318 virtual int getArraySize (void) const; 319 virtual const tcu::TextureCube& getTexture (void) const; 320 virtual tcu::TextureCube& getTexture (void); getTextureFormat(void) const321 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); } getTextureDimension(void) const322 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1); } 323 324 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const; 325 }; 326 327 class TestTextureCubeArray: public TestTexture 328 { 329 private: 330 tcu::TextureCubeArray m_texture; 331 332 public: 333 TestTextureCubeArray (const tcu::TextureFormat& format, int size, int arraySize); 334 TestTextureCubeArray (const tcu::CompressedTexFormat& format, int size, int arraySize); 335 virtual ~TestTextureCubeArray (void); 336 337 virtual int getNumLevels (void) const; 338 virtual tcu::PixelBufferAccess getLevel (int level, int layer); 339 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const; 340 virtual int getArraySize (void) const; 341 virtual const tcu::TextureCubeArray& getTexture (void) const; 342 virtual tcu::TextureCubeArray& getTexture (void); getTextureFormat(void) const343 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); } getTextureDimension(void) const344 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1); } 345 346 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const; 347 }; 348 349 } // pipeline 350 } // vkt 351 352 #endif // _VKTPIPELINEIMAGEUTIL_HPP 353