1 #ifndef _VKTTEXTURETESTUTIL_HPP
2 #define _VKTTEXTURETESTUTIL_HPP
3 /*------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
6 *
7 * Copyright (c) 2016 The Khronos Group Inc.
8 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
9 * Copyright (c) 2014 The Android Open Source Project
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 *
23 *//*!
24 * \file
25 * \brief Texture test utilities.
26 *
27 * About coordinates:
28 * + Quads consist of 2 triangles, rendered using explicit indices.
29 * + All TextureTestUtil functions and classes expect texture coordinates
30 * for quads to be specified in order (-1, -1), (-1, 1), (1, -1), (1, 1).
31 *//*--------------------------------------------------------------------*/
32
33 #include "tcuDefs.hpp"
34 #include "tcuSurface.hpp"
35
36 #include "vkDefs.hpp"
37 #include "vkTypeUtil.hpp"
38 #include "vktTestCase.hpp"
39
40 #include "gluShaderProgram.hpp"
41 #include "gluTextureTestUtil.hpp"
42 #include "deSharedPtr.hpp"
43
44 #include "../pipeline/vktPipelineImageUtil.hpp"
45
46 namespace vkt
47 {
48
49 namespace texture
50 {
51
52 namespace util
53 {
54
55 enum Program
56 {
57 PROGRAM_2D_FLOAT = 0,
58 PROGRAM_2D_INT,
59 PROGRAM_2D_UINT,
60 PROGRAM_2D_FETCH_LOD,
61 PROGRAM_2D_SHADOW,
62
63 PROGRAM_2D_FLOAT_BIAS,
64 PROGRAM_2D_INT_BIAS,
65 PROGRAM_2D_UINT_BIAS,
66 PROGRAM_2D_SHADOW_BIAS,
67
68 PROGRAM_1D_FLOAT,
69 PROGRAM_1D_INT,
70 PROGRAM_1D_UINT,
71 PROGRAM_1D_SHADOW,
72
73 PROGRAM_1D_FLOAT_BIAS,
74 PROGRAM_1D_INT_BIAS,
75 PROGRAM_1D_UINT_BIAS,
76 PROGRAM_1D_SHADOW_BIAS,
77
78 PROGRAM_CUBE_FLOAT,
79 PROGRAM_CUBE_INT,
80 PROGRAM_CUBE_UINT,
81 PROGRAM_CUBE_SHADOW,
82
83 PROGRAM_CUBE_FLOAT_BIAS,
84 PROGRAM_CUBE_INT_BIAS,
85 PROGRAM_CUBE_UINT_BIAS,
86 PROGRAM_CUBE_SHADOW_BIAS,
87
88 PROGRAM_1D_ARRAY_FLOAT,
89 PROGRAM_1D_ARRAY_INT,
90 PROGRAM_1D_ARRAY_UINT,
91 PROGRAM_1D_ARRAY_SHADOW,
92
93 PROGRAM_2D_ARRAY_FLOAT,
94 PROGRAM_2D_ARRAY_INT,
95 PROGRAM_2D_ARRAY_UINT,
96 PROGRAM_2D_ARRAY_SHADOW,
97
98 PROGRAM_3D_FLOAT,
99 PROGRAM_3D_INT,
100 PROGRAM_3D_UINT,
101 PROGRAM_3D_FETCH_LOD,
102
103 PROGRAM_3D_FLOAT_BIAS,
104 PROGRAM_3D_INT_BIAS,
105 PROGRAM_3D_UINT_BIAS,
106
107 PROGRAM_CUBE_ARRAY_FLOAT,
108 PROGRAM_CUBE_ARRAY_INT,
109 PROGRAM_CUBE_ARRAY_UINT,
110 PROGRAM_CUBE_ARRAY_SHADOW,
111
112 PROGRAM_BUFFER_FLOAT,
113 PROGRAM_BUFFER_INT,
114 PROGRAM_BUFFER_UINT,
115
116 PROGRAM_LAST
117 };
118
119 void initializePrograms (vk::SourceCollections& programCollection, glu::Precision texCoordPrecision, const std::vector<Program>& programs, const char* texCoordSwizzle = DE_NULL, glu::Precision fragOutputPrecision = glu::Precision::PRECISION_MEDIUMP);
120
121 typedef de::SharedPtr<pipeline::TestTexture> TestTextureSp;
122 typedef de::SharedPtr<pipeline::TestTexture2D> TestTexture2DSp;
123 typedef de::SharedPtr<pipeline::TestTextureCube> TestTextureCubeSp;
124 typedef de::SharedPtr<pipeline::TestTexture2DArray> TestTexture2DArraySp;
125 typedef de::SharedPtr<pipeline::TestTexture3D> TestTexture3DSp;
126 typedef de::SharedPtr<pipeline::TestTexture1D> TestTexture1DSp;
127 typedef de::SharedPtr<pipeline::TestTexture1DArray> TestTexture1DArraySp;
128 typedef de::SharedPtr<pipeline::TestTextureCubeArray> TestTextureCubeArraySp;
129
130 class TextureBinding {
131 public:
132 enum Type
133 {
134 TYPE_NONE = 0,
135 TYPE_2D,
136 TYPE_CUBE_MAP,
137 TYPE_2D_ARRAY,
138 TYPE_3D,
139
140 TYPE_1D,
141 TYPE_1D_ARRAY,
142 TYPE_CUBE_ARRAY,
143
144 TYPE_LAST
145 };
146
147 enum ImageBackingMode
148 {
149 IMAGE_BACKING_MODE_REGULAR = 0,
150 IMAGE_BACKING_MODE_SPARSE,
151
152 IMAGE_BACKING_MODE_LAST
153 };
154 TextureBinding (Context& context);
155 TextureBinding (Context& context, vk::VkDevice device, vk::Allocator& allocator, const TestTextureSp& textureData, const Type type,
156 const vk::VkImageAspectFlags aspectMask,
157 const ImageBackingMode backingMode = IMAGE_BACKING_MODE_REGULAR,
158 const vk::VkComponentMapping componentMapping = vk::makeComponentMappingRGBA());
getImage(void)159 vk::VkImage getImage (void) { return *m_textureImage; }
getImageView(void)160 vk::VkImageView getImageView (void) { return *m_textureImageView; }
getType(void)161 Type getType (void) { return m_type; }
getTestTexture(void)162 const pipeline::TestTexture& getTestTexture (void) { return *m_textureData; }
163 void updateTextureViewMipLevels (deUint32 baseLevel, deUint32 maxLevel, float imageViewMinLod = 0.0f);
164
165 private:
166 TextureBinding (const TextureBinding&); // not allowed!
167 TextureBinding& operator= (const TextureBinding&); // not allowed!
168
169 void updateTextureData (const TestTextureSp& textureData, const Type type);
170
171 Context& m_context;
172 vk::VkDevice m_device;
173 vk::Allocator& m_allocator;
174 Type m_type;
175 ImageBackingMode m_backingMode;
176 TestTextureSp m_textureData;
177 vk::Move<vk::VkImage> m_textureImage;
178 de::MovePtr<vk::Allocation> m_textureImageMemory;
179 vk::Move<vk::VkImageView> m_textureImageView;
180 std::vector<de::SharedPtr<vk::Allocation> > m_allocations;
181 vk::VkImageAspectFlags m_aspectMask;
182 vk::VkComponentMapping m_componentMapping;
183 };
184
185 void checkTextureSupport (Context& context, const vk::VkFormat imageFormat, const vk::VkComponentMapping& imageComponents,
186 const vk::VkFormat viewFormat, const vk::VkComponentMapping& viewComponents);
187
188 typedef de::SharedPtr<TextureBinding> TextureBindingSp;
189
190 class TextureRenderer
191 {
192 public:
193 TextureRenderer (Context& context,
194 vk::VkSampleCountFlagBits sampleCount,
195 deUint32 renderWidth,
196 deUint32 renderHeight,
197 vk::VkComponentMapping componentMapping = vk::makeComponentMappingRGBA(),
198 bool requireRobustness2 = false,
199 bool requireImageViewMinLod = false);
200
201 TextureRenderer (Context& context,
202 vk::VkSampleCountFlagBits sampleCount,
203 deUint32 renderWidth,
204 deUint32 renderHeight,
205 deUint32 renderDepth,
206 vk::VkComponentMapping componentMapping = vk::makeComponentMappingRGBA(),
207 vk::VkImageType imageType = vk::VK_IMAGE_TYPE_2D,
208 vk::VkImageViewType imageViewType = vk::VK_IMAGE_VIEW_TYPE_2D,
209 vk::VkFormat imageFormat = vk::VK_FORMAT_R8G8B8A8_UNORM,
210 bool requireRobustness2 = false,
211 bool requireImageViewMinLod = false);
212
213 ~TextureRenderer (void);
214
215 void renderQuad (tcu::Surface& result, int texUnit, const float* texCoord, glu::TextureTestUtil::TextureType texType);
216 void renderQuad (tcu::Surface& result, int texUnit, const float* texCoord, const glu::TextureTestUtil::ReferenceParams& params);
217 void renderQuad (tcu::Surface& result,
218 const float* positions,
219 const int texUnit,
220 const float* texCoord,
221 const glu::TextureTestUtil::ReferenceParams& params,
222 const float maxAnisotropy);
223
224 void renderQuad (const tcu::PixelBufferAccess& result, int texUnit, const float* texCoord, const glu::TextureTestUtil::ReferenceParams& params);
225 void renderQuad (const tcu::PixelBufferAccess& result,
226 const float* positions,
227 const int texUnit,
228 const float* texCoord,
229 const glu::TextureTestUtil::ReferenceParams& params,
230 const float maxAnisotropy);
231
232 void clearImage (vk::VkImage image);
233
234 void add2DTexture (const TestTexture2DSp& texture,
235 const vk::VkImageAspectFlags& aspectMask,
236 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
237 const pipeline::TestTexture2D& get2DTexture (int textureIndex) const;
238
239 void addCubeTexture (const TestTextureCubeSp& texture,
240 const vk::VkImageAspectFlags& aspectMask,
241 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
242 const pipeline::TestTextureCube& getCubeTexture (int textureIndex) const;
243
244 void add2DArrayTexture (const TestTexture2DArraySp& texture,
245 const vk::VkImageAspectFlags& aspectMask,
246 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
247 const pipeline::TestTexture2DArray& get2DArrayTexture (int textureIndex) const;
248
249 void add3DTexture (const TestTexture3DSp& texture,
250 const vk::VkImageAspectFlags& aspectMask,
251 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
252 const pipeline::TestTexture3D& get3DTexture (int textureIndex) const;
253
254 void add1DTexture (const TestTexture1DSp& texture,
255 const vk::VkImageAspectFlags& aspectMask,
256 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
257 const pipeline::TestTexture1D& get1DTexture (int textureIndex) const;
258
259 void add1DArrayTexture (const TestTexture1DArraySp& texture,
260 const vk::VkImageAspectFlags& aspectMask,
261 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
262 const pipeline::TestTexture1DArray& get1DArrayTexture (int textureIndex) const;
263
264 void addCubeArrayTexture (const TestTextureCubeArraySp& texture,
265 const vk::VkImageAspectFlags& aspectMask,
266 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
267 const pipeline::TestTextureCubeArray& getCubeArrayTexture (int textureIndex) const;
268
269 void setViewport (float viewportX, float viewportY, float viewportW, float viewportH);
270
271 TextureBinding* getTextureBinding (int textureIndex) const;
272
273 deUint32 getRenderWidth (void) const;
274 deUint32 getRenderHeight (void) const;
275
276 protected:
277 TextureRenderer (const TextureRenderer& other);
278 TextureRenderer& operator= (const TextureRenderer& other);
279
280 Context& m_context;
281 vk::Move<vk::VkDevice> m_customDevice;
282 de::MovePtr<vk::Allocator> m_allocator;
283 tcu::TestLog& m_log;
284
285 const deUint32 m_renderWidth;
286 const deUint32 m_renderHeight;
287 const deUint32 m_renderDepth;
288 const vk::VkSampleCountFlagBits m_sampleCount;
289 const deBool m_multisampling;
290
291 const vk::VkFormat m_imageFormat;
292 const tcu::TextureFormat m_textureFormat;
293
294 vk::Move<vk::VkImage> m_image;
295 de::MovePtr<vk::Allocation> m_imageMemory;
296 vk::Move<vk::VkImageView> m_imageView;
297
298 vk::Move<vk::VkImage> m_resolvedImage;
299 de::MovePtr<vk::Allocation> m_resolvedImageMemory;
300 vk::Move<vk::VkImageView> m_resolvedImageView;
301
302 vk::Move<vk::VkCommandPool> m_commandPool;
303 vk::Move<vk::VkRenderPass> m_renderPass;
304 vk::Move<vk::VkFramebuffer> m_frameBuffer;
305
306 vk::Move<vk::VkDescriptorPool> m_descriptorPool;
307 vk::Move<vk::VkDescriptorSet> m_descriptorSet[2];
308 vk::Move<vk::VkDescriptorSetLayout> m_descriptorSetLayout[2];
309 vk::Move<vk::VkPipelineLayout> m_pipelineLayout;
310
311 vk::Move<vk::VkBuffer> m_uniformBuffer;
312 de::MovePtr<vk::Allocation> m_uniformBufferMemory;
313 const vk::VkDeviceSize m_uniformBufferSize;
314
315 vk::Move<vk::VkBuffer> m_vertexIndexBuffer;
316 de::MovePtr<vk::Allocation> m_vertexIndexBufferMemory;
317 static const vk::VkDeviceSize s_vertexIndexBufferSize;
318 static const deUint16 s_vertexIndices[6];
319
320 vk::Move<vk::VkBuffer> m_resultBuffer;
321 de::MovePtr<vk::Allocation> m_resultBufferMemory;
322 const vk::VkDeviceSize m_resultBufferSize;
323
324 std::vector<TextureBindingSp> m_textureBindings;
325
326 float m_viewportOffsetX;
327 float m_viewportOffsetY;
328 float m_viewportWidth;
329 float m_viewportHeight;
330
331 vk::VkComponentMapping m_componentMapping;
332
333 bool m_requireRobustness2;
334 bool m_requireImageViewMinLod;
335
336 private:
337 vk::Move<vk::VkDescriptorSet> makeDescriptorSet (const vk::VkDescriptorPool descriptorPool, const vk::VkDescriptorSetLayout setLayout) const;
338 void addImageTransitionBarrier (vk::VkCommandBuffer commandBuffer, vk::VkImage image, vk::VkPipelineStageFlags srcStageMask, vk::VkPipelineStageFlags dstStageMask, vk::VkAccessFlags srcAccessMask, vk::VkAccessFlags dstAccessMask, vk::VkImageLayout oldLayout, vk::VkImageLayout newLayout) const;
339
340 vk::VkDevice getDevice (void) const;
341 };
342
343 tcu::Sampler createSampler (tcu::Sampler::WrapMode wrapU, tcu::Sampler::WrapMode wrapV, tcu::Sampler::WrapMode wrapW, tcu::Sampler::FilterMode minFilterMode, tcu::Sampler::FilterMode magFilterMode, bool normalizedCoords = true);
344 tcu::Sampler createSampler (tcu::Sampler::WrapMode wrapU, tcu::Sampler::WrapMode wrapV, tcu::Sampler::FilterMode minFilterMode, tcu::Sampler::FilterMode magFilterMode, bool normalizedCoords = true);
345 tcu::Sampler createSampler (tcu::Sampler::WrapMode wrapU, tcu::Sampler::FilterMode minFilterMode, tcu::Sampler::FilterMode magFilterMode, bool normalizedCoords = true);
346
347 TestTexture2DSp loadTexture2D (const tcu::Archive& archive, const std::vector<std::string>& filenames);
348 TestTextureCubeSp loadTextureCube (const tcu::Archive& archive, const std::vector<std::string>& filenames);
349
350 // Add checkTextureSupport() function specialization for your test parameters class/struct if you need to use checkSupport() functionality
351 template <typename T>
checkTextureSupport(Context & context,const T & testParameters)352 void checkTextureSupport (Context& context, const T& testParameters)
353 {
354 DE_UNREF(context);
355 DE_UNREF(testParameters);
356 }
357
358 template <typename INSTANCE_TYPE>
359 class TextureTestCase : public TestCase
360 {
361 public:
TextureTestCase(tcu::TestContext & context,const std::string & name,const std::string & description,const typename INSTANCE_TYPE::ParameterType & testParameters)362 TextureTestCase (tcu::TestContext& context, const std::string& name, const std::string& description, const typename INSTANCE_TYPE::ParameterType& testParameters)
363 : TestCase (context, name, description)
364 , m_testsParameters (testParameters)
365 {}
366
createInstance(Context & context) const367 virtual TestInstance* createInstance (Context& context) const
368 {
369 return new INSTANCE_TYPE(context, m_testsParameters);
370 }
371
initPrograms(vk::SourceCollections & programCollection) const372 virtual void initPrograms (vk::SourceCollections& programCollection) const
373 {
374 initializePrograms(programCollection, m_testsParameters.texCoordPrecision, m_testsParameters.programs);
375 }
376
checkSupport(Context & context) const377 virtual void checkSupport (Context& context) const
378 {
379 checkTextureSupport(context, m_testsParameters);
380 }
381
382
383 protected:
384 const typename INSTANCE_TYPE::ParameterType m_testsParameters;
385 };
386
387 struct TextureCommonTestCaseParameters
388 {
389 TextureCommonTestCaseParameters (void);
390
391 enum TestType
392 {
393 TEST_NORMAL = 0,
394 TEST_IMAGE_VIEW_MINLOD,
395 TEST_IMAGE_VIEW_MINLOD_INT_TEX_COORD,
396 TEST_IMAGE_VIEW_MINLOD_INT_TEX_COORD_BASELEVEL
397 };
398
399 vk::VkSampleCountFlagBits sampleCount;
400 glu::Precision texCoordPrecision;
401
402 tcu::Sampler::FilterMode minFilter;
403 tcu::Sampler::FilterMode magFilter;
404 tcu::Sampler::WrapMode wrapS;
405
406 vk::VkFormat format;
407
408 std::vector<util::Program> programs;
409
410 deBool unnormal;
411 vk::VkImageAspectFlags aspectMask;
412
413 TestType testType;
414 };
415
416 struct Texture2DTestCaseParameters : public TextureCommonTestCaseParameters
417 {
418 Texture2DTestCaseParameters (void);
419 tcu::Sampler::WrapMode wrapT;
420 int width;
421 int height;
422 bool mipmaps;
423 };
424
425 struct TextureCubeTestCaseParameters : public TextureCommonTestCaseParameters
426 {
427 TextureCubeTestCaseParameters (void);
428 tcu::Sampler::WrapMode wrapT;
429 int size;
430 deBool seamless;
431 };
432
433 struct Texture2DArrayTestCaseParameters : public Texture2DTestCaseParameters
434 {
435 Texture2DArrayTestCaseParameters(void);
436 tcu::Sampler::WrapMode wrapT;
437 int numLayers;
438 };
439
440 struct Texture3DTestCaseParameters : public Texture2DTestCaseParameters
441 {
442 Texture3DTestCaseParameters (void);
443 tcu::Sampler::WrapMode wrapR;
444 int depth;
445 };
446
447 struct Texture1DTestCaseParameters : public TextureCommonTestCaseParameters
448 {
449 Texture1DTestCaseParameters (void);
450 int width;
451 };
452
453 struct Texture1DArrayTestCaseParameters : public Texture1DTestCaseParameters
454 {
455 Texture1DArrayTestCaseParameters(void);
456 int numLayers;
457 };
458
459 struct TextureCubeArrayTestCaseParameters : public TextureCubeTestCaseParameters
460 {
461 TextureCubeArrayTestCaseParameters (void);
462 int numLayers;
463 };
464
465 struct TextureCubeFilteringTestCaseParameters : public TextureCubeTestCaseParameters
466 {
467 TextureCubeFilteringTestCaseParameters (void);
468 bool onlySampleFaceInterior;
469 };
470
471 } // util
472 } // texture
473 } // vkt
474
475 #endif // _VKTTEXTURETESTUTIL_HPP
476