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"
35 #include "deSharedPtr.hpp"
46 BORDER_COLOR_OPAQUE_BLACK,
47 BORDER_COLOR_OPAQUE_WHITE,
48 BORDER_COLOR_TRANSPARENT_BLACK,
53 bool isSupportedSamplableFormat (const vk::InstanceInterface& instanceInterface,
54 vk::VkPhysicalDevice device,
56 bool isLinearFilteringSupported (const vk::InstanceInterface& instanceInterface,
57 vk::VkPhysicalDevice device,
59 vk::VkImageTiling tiling);
61 vk::VkBorderColor getFormatBorderColor (BorderColor color, vk::VkFormat format);
63 void getLookupScaleBias (vk::VkFormat format,
64 tcu::Vec4& lookupScale,
65 tcu::Vec4& lookupBias);
67 /*--------------------------------------------------------------------*//*!
68 * Gets a tcu::TextureLevel initialized with data from a VK color
71 * The VkImage must be non-multisampled and able to be used as a source
72 * operand for transfer operations.
73 *//*--------------------------------------------------------------------*/
74 de::MovePtr<tcu::TextureLevel> readColorAttachment (const vk::DeviceInterface& vk,
77 deUint32 queueFamilyIndex,
78 vk::Allocator& allocator,
81 const tcu::UVec2& renderSize);
83 /*--------------------------------------------------------------------*//*!
84 * Uploads data from a test texture to a destination VK image.
86 * The VkImage must be non-multisampled and able to be used as a
87 * destination operand for transfer operations.
88 *//*--------------------------------------------------------------------*/
89 void uploadTestTexture (const vk::DeviceInterface& vk,
92 deUint32 queueFamilyIndex,
93 vk::Allocator& allocator,
94 const TestTexture& testTexture,
95 vk::VkImage destImage);
97 /*--------------------------------------------------------------------*//*!
98 * Uploads data from a test texture to a destination VK image using sparse
101 * The VkImage must be non-multisampled and able to be used as a
102 * destination operand for transfer operations.
103 *//*--------------------------------------------------------------------*/
104 void uploadTestTextureSparse (const vk::DeviceInterface& vk,
106 const vk::VkPhysicalDevice physicalDevice,
107 const vk::InstanceInterface& instance,
108 const vk::VkImageCreateInfo& imageCreateInfo,
110 deUint32 queueFamilyIndex,
111 vk::Allocator& allocator,
112 std::vector<de::SharedPtr<vk::Allocation> >& allocations,
113 const TestTexture& srcTexture,
114 vk::VkImage destImage);
118 /*--------------------------------------------------------------------*//*!
119 * Allocates memory for a sparse image and handles the memory binding.
120 *//*--------------------------------------------------------------------*/
121 void allocateAndBindSparseImage (const vk::DeviceInterface& vk,
123 const vk::VkPhysicalDevice physicalDevice,
124 const vk::InstanceInterface& instance,
125 const vk::VkImageCreateInfo& imageCreateInfo,
126 const vk::VkSemaphore& signalSemaphore,
128 vk::Allocator& allocator,
129 std::vector<de::SharedPtr<vk::Allocation> >& allocations,
130 tcu::TextureFormat format,
131 vk::VkImage destImage);
136 TestTexture (const tcu::TextureFormat& format, int width, int height, int depth);
137 TestTexture (const tcu::CompressedTexFormat& format, int width, int height, int depth);
138 virtual ~TestTexture (void);
140 virtual int getNumLevels (void) const = 0;
141 virtual deUint32 getSize (void) const;
142 virtual int getArraySize (void) const { return 1; }
144 virtual bool isCompressed (void) const { return !m_compressedLevels.empty(); }
145 virtual deUint32 getCompressedSize (void) const;
147 virtual tcu::PixelBufferAccess getLevel (int level, int layer) = 0;
148 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const = 0;
150 virtual tcu::CompressedTexture& getCompressedLevel (int level, int layer);
151 virtual const tcu::CompressedTexture& getCompressedLevel (int level, int layer) const;
153 virtual std::vector<vk::VkBufferImageCopy> getBufferCopyRegions (void) const;
154 virtual void write (deUint8* destPtr) const;
155 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const = 0;
157 virtual const tcu::TextureFormat& getTextureFormat (void) const = 0;
158 virtual tcu::UVec3 getTextureDimension (void) const = 0;
161 void populateLevels (const std::vector<tcu::PixelBufferAccess>& levels);
162 void populateCompressedLevels (tcu::CompressedTexFormat format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels);
164 static void fillWithGradient (const tcu::PixelBufferAccess& levelAccess);
166 void copyToTexture (TestTexture&) const;
169 std::vector<tcu::CompressedTexture*> m_compressedLevels;
172 class TestTexture1D : public TestTexture
175 tcu::Texture1D m_texture;
178 TestTexture1D (const tcu::TextureFormat& format, int width);
179 TestTexture1D (const tcu::CompressedTexFormat& format, int width);
180 virtual ~TestTexture1D (void);
182 virtual int getNumLevels (void) const;
183 virtual tcu::PixelBufferAccess getLevel (int level, int layer);
184 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const;
185 virtual const tcu::Texture1D& getTexture (void) const;
186 virtual tcu::Texture1D& getTexture (void);
187 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); }
188 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getWidth(), 1, 1); }
190 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const;
193 class TestTexture1DArray : public TestTexture
196 tcu::Texture1DArray m_texture;
199 TestTexture1DArray (const tcu::TextureFormat& format, int width, int arraySize);
200 TestTexture1DArray (const tcu::CompressedTexFormat& format, int width, int arraySize);
201 virtual ~TestTexture1DArray (void);
203 virtual int getNumLevels (void) const;
204 virtual tcu::PixelBufferAccess getLevel (int level, int layer);
205 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const;
206 virtual const tcu::Texture1DArray& getTexture (void) const;
207 virtual tcu::Texture1DArray& getTexture (void);
208 virtual int getArraySize (void) const;
209 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); }
210 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getWidth(), 1, 1); }
212 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const;
215 class TestTexture2D : public TestTexture
218 tcu::Texture2D m_texture;
221 TestTexture2D (const tcu::TextureFormat& format, int width, int height);
222 TestTexture2D (const tcu::CompressedTexFormat& format, int width, int height);
223 virtual ~TestTexture2D (void);
225 virtual int getNumLevels (void) const;
226 virtual tcu::PixelBufferAccess getLevel (int level, int layer);
227 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const;
228 virtual const tcu::Texture2D& getTexture (void) const;
229 virtual tcu::Texture2D& getTexture (void);
230 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); }
231 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1); }
233 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const;
236 class TestTexture2DArray : public TestTexture
239 tcu::Texture2DArray m_texture;
242 TestTexture2DArray (const tcu::TextureFormat& format, int width, int height, int arraySize);
243 TestTexture2DArray (const tcu::CompressedTexFormat& format, int width, int height, int arraySize);
244 virtual ~TestTexture2DArray (void);
246 virtual int getNumLevels (void) const;
247 virtual tcu::PixelBufferAccess getLevel (int level, int layer);
248 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const;
249 virtual const tcu::Texture2DArray& getTexture (void) const;
250 virtual tcu::Texture2DArray& getTexture (void);
251 virtual int getArraySize (void) const;
252 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); }
253 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), 1); }
255 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const;
258 class TestTexture3D : public TestTexture
261 tcu::Texture3D m_texture;
264 TestTexture3D (const tcu::TextureFormat& format, int width, int height, int depth);
265 TestTexture3D (const tcu::CompressedTexFormat& format, int width, int height, int depth);
266 virtual ~TestTexture3D (void);
268 virtual int getNumLevels (void) const;
269 virtual tcu::PixelBufferAccess getLevel (int level, int layer);
270 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const;
271 virtual const tcu::Texture3D& getTexture (void) const;
272 virtual tcu::Texture3D& getTexture (void);
273 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); }
274 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getWidth(), m_texture.getHeight(), m_texture.getDepth()); }
276 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const;
279 class TestTextureCube : public TestTexture
282 tcu::TextureCube m_texture;
285 TestTextureCube (const tcu::TextureFormat& format, int size);
286 TestTextureCube (const tcu::CompressedTexFormat& format, int size);
287 virtual ~TestTextureCube (void);
289 virtual int getNumLevels (void) const;
290 virtual tcu::PixelBufferAccess getLevel (int level, int layer);
291 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const;
292 virtual int getArraySize (void) const;
293 virtual const tcu::TextureCube& getTexture (void) const;
294 virtual tcu::TextureCube& getTexture (void);
295 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); }
296 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1); }
298 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const;
301 class TestTextureCubeArray: public TestTexture
304 tcu::TextureCubeArray m_texture;
307 TestTextureCubeArray (const tcu::TextureFormat& format, int size, int arraySize);
308 TestTextureCubeArray (const tcu::CompressedTexFormat& format, int size, int arraySize);
309 virtual ~TestTextureCubeArray (void);
311 virtual int getNumLevels (void) const;
312 virtual tcu::PixelBufferAccess getLevel (int level, int layer);
313 virtual const tcu::ConstPixelBufferAccess getLevel (int level, int layer) const;
314 virtual int getArraySize (void) const;
315 virtual const tcu::TextureCubeArray& getTexture (void) const;
316 virtual tcu::TextureCubeArray& getTexture (void);
317 virtual const tcu::TextureFormat& getTextureFormat (void) const { return m_texture.getFormat(); }
318 virtual tcu::UVec3 getTextureDimension (void) const { return tcu::UVec3(m_texture.getSize(), m_texture.getSize(), 1); }
320 virtual de::MovePtr<TestTexture> copy (const tcu::TextureFormat) const;
326 #endif // _VKTPIPELINEIMAGEUTIL_HPP