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