1 #ifndef _VKTPIPELINEIMAGEUTIL_HPP
2 #define _VKTPIPELINEIMAGEUTIL_HPP
3 /*------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
7 * Copyright (c) 2015 The Khronos Group Inc.
8 * Copyright (c) 2015 Imagination Technologies Ltd.
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 * \brief Utilities for images.
25 *//*--------------------------------------------------------------------*/
27 #include "tcuDefs.hpp"
30 #include "vkPlatform.hpp"
31 #include "vkMemUtil.hpp"
33 #include "tcuTexture.hpp"
34 #include "tcuCompressedTexture.hpp"
45 BORDER_COLOR_OPAQUE_BLACK,
46 BORDER_COLOR_OPAQUE_WHITE,
47 BORDER_COLOR_TRANSPARENT_BLACK,
52 bool isSupportedSamplableFormat (const vk::InstanceInterface& instanceInterface,
53 vk::VkPhysicalDevice device,
55 bool isLinearFilteringSupported (const vk::InstanceInterface& instanceInterface,
56 vk::VkPhysicalDevice device,
58 vk::VkImageTiling tiling);
60 vk::VkBorderColor getFormatBorderColor (BorderColor color, vk::VkFormat format);
62 void getLookupScaleBias (vk::VkFormat format,
63 tcu::Vec4& lookupScale,
64 tcu::Vec4& lookupBias);
66 /*--------------------------------------------------------------------*//*!
67 * Gets a tcu::TextureLevel initialized with data from a VK color
70 * The VkImage must be non-multisampled and able to be used as a source
71 * operand for transfer operations.
72 *//*--------------------------------------------------------------------*/
73 de::MovePtr<tcu::TextureLevel> readColorAttachment (const vk::DeviceInterface& vk,
76 deUint32 queueFamilyIndex,
77 vk::Allocator& allocator,
80 const tcu::UVec2& renderSize);
82 /*--------------------------------------------------------------------*//*!
83 * Uploads data from a test texture to a destination VK image.
85 * The VkImage must be non-multisampled and able to be used as a
86 * destination operand for transfer operations.
87 *//*--------------------------------------------------------------------*/
88 void uploadTestTexture (const vk::DeviceInterface& vk,
91 deUint32 queueFamilyIndex,
92 vk::Allocator& allocator,
93 const TestTexture& testTexture,
94 vk::VkImage destImage);
99 TestTexture (const tcu::TextureFormat& format, int width, int height, int depth);
100 TestTexture (const tcu::CompressedTexFormat& format, int width, int height, int depth);
101 virtual ~TestTexture (void);
103 virtual int getNumLevels (void) const = 0;
104 virtual deUint32 getSize (void) const;
105 virtual int getArraySize (void) const { return 1; }
107 virtual bool isCompressed (void) const { return !m_compressedLevels.empty(); }
108 virtual deUint32 getCompressedSize (void) const;
110 virtual tcu::PixelBufferAccess getLevel (int level, int layer) = 0;
111 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const = 0;
113 virtual tcu::CompressedTexture& getCompressedLevel (int level, int layer);
114 virtual const tcu::CompressedTexture& getCompressedLevel (int level, int layer) const;
116 virtual std::vector<vk::VkBufferImageCopy> getBufferCopyRegions (void) const;
117 virtual void write (deUint8* destPtr) const;
118 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const = 0;
120 virtual const tcu::TextureFormat& getTextureFormat (void) const = 0;
121 virtual tcu::UVec3 getTextureDimension (void) const = 0;
124 void populateLevels (const std::vector<tcu::PixelBufferAccess>& levels);
125 void populateCompressedLevels (tcu::CompressedTexFormat format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels);
127 static void fillWithGradient (const tcu::PixelBufferAccess& levelAccess);
129 void copyToTexture (TestTexture&) const;
132 std::vector<tcu::CompressedTexture*> m_compressedLevels;
135 class TestTexture1D : public TestTexture
138 tcu::Texture1D m_texture;
141 TestTexture1D (const tcu::TextureFormat& format, int width);
142 TestTexture1D (const tcu::CompressedTexFormat& format, int width);
143 virtual ~TestTexture1D (void);
145 virtual int getNumLevels (void) const;
146 virtual tcu::PixelBufferAccess getLevel (int level, int layer);
147 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const;
148 virtual const tcu::Texture1D& getTexture (void) const;
149 virtual tcu::Texture1D& getTexture (void);
150 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); }
151 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getWidth(), 1, 1); }
153 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const;
156 class TestTexture1DArray : public TestTexture
159 tcu::Texture1DArray m_texture;
162 TestTexture1DArray (const tcu::TextureFormat& format, int width, int arraySize);
163 TestTexture1DArray (const tcu::CompressedTexFormat& format, int width, int arraySize);
164 virtual ~TestTexture1DArray (void);
166 virtual int getNumLevels (void) const;
167 virtual tcu::PixelBufferAccess getLevel (int level, int layer);
168 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const;
169 virtual const tcu::Texture1DArray& getTexture (void) const;
170 virtual tcu::Texture1DArray& getTexture (void);
171 virtual int getArraySize (void) const;
172 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); }
173 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getWidth(), 1, 1); }
175 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const;
178 class TestTexture2D : public TestTexture
181 tcu::Texture2D m_texture;
184 TestTexture2D (const tcu::TextureFormat& format, int width, int height);
185 TestTexture2D (const tcu::CompressedTexFormat& format, int width, int height);
186 virtual ~TestTexture2D (void);
188 virtual int getNumLevels (void) const;
189 virtual tcu::PixelBufferAccess getLevel (int level, int layer);
190 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const;
191 virtual const tcu::Texture2D& getTexture (void) const;
192 virtual tcu::Texture2D& getTexture (void);
193 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); }
194 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1); }
196 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const;
199 class TestTexture2DArray : public TestTexture
202 tcu::Texture2DArray m_texture;
205 TestTexture2DArray (const tcu::TextureFormat& format, int width, int height, int arraySize);
206 TestTexture2DArray (const tcu::CompressedTexFormat& format, int width, int height, int arraySize);
207 virtual ~TestTexture2DArray (void);
209 virtual int getNumLevels (void) const;
210 virtual tcu::PixelBufferAccess getLevel (int level, int layer);
211 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const;
212 virtual const tcu::Texture2DArray& getTexture (void) const;
213 virtual tcu::Texture2DArray& getTexture (void);
214 virtual int getArraySize (void) const;
215 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); }
216 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1); }
218 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const;
221 class TestTexture3D : public TestTexture
224 tcu::Texture3D m_texture;
227 TestTexture3D (const tcu::TextureFormat& format, int width, int height, int depth);
228 TestTexture3D (const tcu::CompressedTexFormat& format, int width, int height, int depth);
229 virtual ~TestTexture3D (void);
231 virtual int getNumLevels (void) const;
232 virtual tcu::PixelBufferAccess getLevel (int level, int layer);
233 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const;
234 virtual const tcu::Texture3D& getTexture (void) const;
235 virtual tcu::Texture3D& getTexture (void);
236 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); }
237 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), m_texture.getDepth()); }
239 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const;
242 class TestTextureCube : public TestTexture
245 tcu::TextureCube m_texture;
248 TestTextureCube (const tcu::TextureFormat& format, int size);
249 TestTextureCube (const tcu::CompressedTexFormat& format, int size);
250 virtual ~TestTextureCube (void);
252 virtual int getNumLevels (void) const;
253 virtual tcu::PixelBufferAccess getLevel (int level, int layer);
254 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const;
255 virtual int getArraySize (void) const;
256 virtual const tcu::TextureCube& getTexture (void) const;
257 virtual tcu::TextureCube& getTexture (void);
258 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); }
259 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1); }
261 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const;
264 class TestTextureCubeArray: public TestTexture
267 tcu::TextureCubeArray m_texture;
270 TestTextureCubeArray (const tcu::TextureFormat& format, int size, int arraySize);
271 TestTextureCubeArray (const tcu::CompressedTexFormat& format, int size, int arraySize);
272 virtual ~TestTextureCubeArray (void);
274 virtual int getNumLevels (void) const;
275 virtual tcu::PixelBufferAccess getLevel (int level, int layer);
276 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const;
277 virtual int getArraySize (void) const;
278 virtual const tcu::TextureCubeArray& getTexture (void) const;
279 virtual tcu::TextureCubeArray& getTexture (void);
280 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); }
281 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1); }
283 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const;
289 #endif // _VKTPIPELINEIMAGEUTIL_HPP