• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2015 The Khronos Group Inc.
6  * Copyright (c) 2015 Imagination Technologies Ltd.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *//*!
21  * \file
22  * \brief Image Tests
23  *//*--------------------------------------------------------------------*/
24 
25 #include "vktPipelineImageTests.hpp"
26 #include "vktPipelineImageSamplingInstance.hpp"
27 #include "vktPipelineImageUtil.hpp"
28 #include "vktPipelineVertexUtil.hpp"
29 #include "vktTestCase.hpp"
30 #include "vkImageUtil.hpp"
31 #include "vkPrograms.hpp"
32 #include "tcuTextureUtil.hpp"
33 #include "deStringUtil.hpp"
34 
35 #include <sstream>
36 #include <vector>
37 
38 namespace vkt
39 {
40 namespace pipeline
41 {
42 
43 using namespace vk;
44 using de::MovePtr;
45 
46 namespace
47 {
48 
49 class ImageTest : public vkt::TestCase
50 {
51 public:
52 							ImageTest							(tcu::TestContext&	testContext,
53 																 const char*		name,
54 																 const char*		description,
55 
56 																 AllocationKind		allocationKind,
57 																 VkDescriptorType	samplingType,
58 																 VkImageViewType	imageViewType,
59 																 VkFormat			imageFormat,
60 																 const tcu::IVec3&	imageSize,
61 																 int				imageCount,
62 																 int				arraySize);
63 
64 	ImageSamplingInstanceParams	getImageSamplingInstanceParams	(AllocationKind		allocationKind,
65 																 VkDescriptorType	samplingType,
66 																 VkImageViewType	imageViewType,
67 																 VkFormat			imageFormat,
68 																 const tcu::IVec3&	imageSize,
69 																 int				imageCount,
70 																 int				arraySize) const;
71 
72 	virtual void			initPrograms						(SourceCollections& sourceCollections) const;
73 	virtual void			checkSupport						(Context& context) const;
74 	virtual TestInstance*	createInstance						(Context& context) const;
75 	static std::string		getGlslSamplerType					(const tcu::TextureFormat& format, VkImageViewType type);
76 	static std::string		getGlslTextureType					(const tcu::TextureFormat& format, VkImageViewType type);
77 	static std::string		getGlslSamplerDecl					(int imageCount);
78 	static std::string		getGlslTextureDecl					(int imageCount);
79 	static std::string		getGlslFragColorDecl				(int imageCount);
80 	static std::string		getGlslSampler						(const tcu::TextureFormat&	format,
81 																 VkImageViewType			type,
82 																 VkDescriptorType			samplingType,
83 																 int						imageCount);
84 
85 private:
86 	AllocationKind			m_allocationKind;
87 	VkDescriptorType		m_samplingType;
88 	VkImageViewType			m_imageViewType;
89 	VkFormat				m_imageFormat;
90 	tcu::IVec3				m_imageSize;
91 	int						m_imageCount;
92 	int						m_arraySize;
93 };
94 
ImageTest(tcu::TestContext & testContext,const char * name,const char * description,AllocationKind allocationKind,VkDescriptorType samplingType,VkImageViewType imageViewType,VkFormat imageFormat,const tcu::IVec3 & imageSize,int imageCount,int arraySize)95 ImageTest::ImageTest (tcu::TestContext&	testContext,
96 					  const char*		name,
97 					  const char*		description,
98 					  AllocationKind	allocationKind,
99 					  VkDescriptorType	samplingType,
100 					  VkImageViewType	imageViewType,
101 					  VkFormat			imageFormat,
102 					  const tcu::IVec3&	imageSize,
103 					  int				imageCount,
104 					  int				arraySize)
105 
106 	: vkt::TestCase		(testContext, name, description)
107 	, m_allocationKind	(allocationKind)
108 	, m_samplingType	(samplingType)
109 	, m_imageViewType	(imageViewType)
110 	, m_imageFormat		(imageFormat)
111 	, m_imageSize		(imageSize)
112 	, m_imageCount		(imageCount)
113 	, m_arraySize		(arraySize)
114 {
115 }
116 
checkSupport(Context & context) const117 void ImageTest::checkSupport (Context& context) const
118 {
119 	// Using a loop to index into an array of images requires shaderSampledImageArrayDynamicIndexing
120 	if (m_imageCount > 1)
121 		context.requireDeviceCoreFeature(DEVICE_CORE_FEATURE_SHADER_SAMPLED_IMAGE_ARRAY_DYNAMIC_INDEXING);
122 
123 	checkSupportImageSamplingInstance(context, getImageSamplingInstanceParams(m_allocationKind, m_samplingType, m_imageViewType, m_imageFormat, m_imageSize, m_imageCount, m_arraySize));
124 }
125 
getImageSamplingInstanceParams(AllocationKind allocationKind,VkDescriptorType samplingType,VkImageViewType imageViewType,VkFormat imageFormat,const tcu::IVec3 & imageSize,int imageCount,int arraySize) const126 ImageSamplingInstanceParams ImageTest::getImageSamplingInstanceParams (AllocationKind		allocationKind,
127 																	   VkDescriptorType		samplingType,
128 																	   VkImageViewType		imageViewType,
129 																	   VkFormat				imageFormat,
130 																	   const tcu::IVec3&	imageSize,
131 																	   int					imageCount,
132 																	   int					arraySize) const
133 {
134 	tcu::UVec2 renderSize;
135 
136 	if (imageViewType == VK_IMAGE_VIEW_TYPE_1D || imageViewType == VK_IMAGE_VIEW_TYPE_2D)
137 	{
138 		renderSize = tcu::UVec2((deUint32)imageSize.x(), (deUint32)imageSize.y());
139 	}
140 	else
141 	{
142 		// Draw a 3x2 grid of texture layers
143 		renderSize = tcu::UVec2((deUint32)imageSize.x() * 3, (deUint32)imageSize.y() * 2);
144 	}
145 
146 	const bool						separateStencilUsage	= false;
147 	const std::vector<Vertex4Tex4>	vertices				= createTestQuadMosaic(imageViewType);
148 	const VkComponentMapping		componentMapping		= { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
149 	const VkImageSubresourceRange	subresourceRange		=
150 	{
151 		VK_IMAGE_ASPECT_COLOR_BIT,
152 		0u,
153 		(deUint32)deLog2Floor32(deMax32(imageSize.x(), deMax32(imageSize.y(), imageSize.z()))) + 1,
154 		0u,
155 		(deUint32)arraySize,
156 	};
157 
158 	const VkSamplerCreateInfo samplerParams =
159 	{
160 		VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,								// VkStructureType			sType;
161 		DE_NULL,															// const void*				pNext;
162 		0u,																	// VkSamplerCreateFlags		flags;
163 		VK_FILTER_NEAREST,													// VkFilter					magFilter;
164 		VK_FILTER_NEAREST,													// VkFilter					minFilter;
165 		VK_SAMPLER_MIPMAP_MODE_NEAREST,										// VkSamplerMipmapMode		mipmapMode;
166 		VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,								// VkSamplerAddressMode		addressModeU;
167 		VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,								// VkSamplerAddressMode		addressModeV;
168 		VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,								// VkSamplerAddressMode		addressModeW;
169 		0.0f,																// float					mipLodBias;
170 		VK_FALSE,															// VkBool32					anisotropyEnable;
171 		1.0f,																// float					maxAnisotropy;
172 		false,																// VkBool32					compareEnable;
173 		VK_COMPARE_OP_NEVER,												// VkCompareOp				compareOp;
174 		0.0f,																// float					minLod;
175 		(float)(subresourceRange.levelCount - 1),							// float					maxLod;
176 		getFormatBorderColor(BORDER_COLOR_TRANSPARENT_BLACK, imageFormat),	// VkBorderColor			borderColor;
177 		false																// VkBool32					unnormalizedCoordinates;
178 	};
179 
180 	return ImageSamplingInstanceParams(renderSize, imageViewType, imageFormat, imageSize, arraySize, componentMapping, subresourceRange, samplerParams, 0.0f, vertices, separateStencilUsage, samplingType, imageCount, allocationKind);
181 }
182 
initPrograms(SourceCollections & sourceCollections) const183 void ImageTest::initPrograms (SourceCollections& sourceCollections) const
184 {
185 	std::ostringstream				vertexSrc;
186 	std::ostringstream				fragmentSrc;
187 	const char*						texCoordSwizzle	= DE_NULL;
188 	const tcu::TextureFormat		format			= (isCompressedFormat(m_imageFormat)) ? tcu::getUncompressedFormat(mapVkCompressedFormat(m_imageFormat))
189 																						  : mapVkFormat(m_imageFormat);
190 
191 	tcu::Vec4						lookupScale;
192 	tcu::Vec4						lookupBias;
193 
194 	getLookupScaleBias(m_imageFormat, lookupScale, lookupBias);
195 
196 	switch (m_imageViewType)
197 	{
198 		case VK_IMAGE_VIEW_TYPE_1D:
199 			texCoordSwizzle = "x";
200 			break;
201 		case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
202 		case VK_IMAGE_VIEW_TYPE_2D:
203 			texCoordSwizzle = "xy";
204 			break;
205 		case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
206 		case VK_IMAGE_VIEW_TYPE_3D:
207 		case VK_IMAGE_VIEW_TYPE_CUBE:
208 			texCoordSwizzle = "xyz";
209 			break;
210 		case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
211 			texCoordSwizzle = "xyzw";
212 			break;
213 		default:
214 			DE_ASSERT(false);
215 			break;
216 	}
217 
218 	vertexSrc << "#version 440\n"
219 			  << "layout(location = 0) in vec4 position;\n"
220 			  << "layout(location = 1) in vec4 texCoords;\n"
221 			  << "layout(location = 0) out highp vec4 vtxTexCoords;\n"
222 			  << "out gl_PerVertex {\n"
223 			  << "	vec4 gl_Position;\n"
224 			  << "};\n"
225 			  << "void main (void)\n"
226 			  << "{\n"
227 			  << "	gl_Position = position;\n"
228 			  << "	vtxTexCoords = texCoords;\n"
229 			  << "}\n";
230 
231 	fragmentSrc << "#version 440\n";
232 	switch (m_samplingType)
233 	{
234 		case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
235 			fragmentSrc
236 				<< "layout(set = 0, binding = 0) uniform highp sampler texSampler;\n"
237 				<< "layout(set = 0, binding = 1) uniform highp " << getGlslTextureType(format, m_imageViewType) << " " << getGlslTextureDecl(m_imageCount) << ";\n";
238 			break;
239 		case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
240 		default:
241 			fragmentSrc
242 				<< "layout(set = 0, binding = 0) uniform highp " << getGlslSamplerType(format, m_imageViewType) << " " << getGlslSamplerDecl(m_imageCount) << ";\n";
243 	}
244 	fragmentSrc << "layout(location = 0) in highp vec4 vtxTexCoords;\n"
245 				<< "layout(location = 0) out highp vec4 " << getGlslFragColorDecl(m_imageCount) << ";\n"
246 				<< "void main (void)\n"
247 				<< "{\n";
248 	if (m_imageCount > 1)
249 		fragmentSrc
250 				<< "	for (uint i = 0; i < " << m_imageCount << "; ++i)\n"
251 				<< "		fragColors[i] = (texture(" << getGlslSampler(format, m_imageViewType, m_samplingType, m_imageCount) << ", vtxTexCoords." << texCoordSwizzle << std::scientific << ") * vec4" << lookupScale << ") + vec4" << lookupBias << "; \n";
252 	else
253 		fragmentSrc
254 				<< "	fragColor = (texture(" << getGlslSampler(format, m_imageViewType, m_samplingType, m_imageCount) << ", vtxTexCoords." << texCoordSwizzle << std::scientific << ") * vec4" << lookupScale << ") + vec4" << lookupBias << "; \n";
255 	fragmentSrc << "}\n";
256 
257 	sourceCollections.glslSources.add("tex_vert") << glu::VertexSource(vertexSrc.str());
258 	sourceCollections.glslSources.add("tex_frag") << glu::FragmentSource(fragmentSrc.str());
259 }
260 
createInstance(Context & context) const261 TestInstance* ImageTest::createInstance (Context& context) const
262 {
263 	return new ImageSamplingInstance(context, getImageSamplingInstanceParams(m_allocationKind, m_samplingType, m_imageViewType, m_imageFormat, m_imageSize, m_imageCount, m_arraySize));
264 }
265 
getGlslSamplerType(const tcu::TextureFormat & format,VkImageViewType type)266 std::string ImageTest::getGlslSamplerType (const tcu::TextureFormat& format, VkImageViewType type)
267 {
268 	std::ostringstream samplerType;
269 
270 	if (tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER)
271 		samplerType << "u";
272 	else if (tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER)
273 		samplerType << "i";
274 
275 	switch (type)
276 	{
277 		case VK_IMAGE_VIEW_TYPE_1D:
278 			samplerType << "sampler1D";
279 			break;
280 
281 		case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
282 			samplerType << "sampler1DArray";
283 			break;
284 
285 		case VK_IMAGE_VIEW_TYPE_2D:
286 			samplerType << "sampler2D";
287 			break;
288 
289 		case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
290 			samplerType << "sampler2DArray";
291 			break;
292 
293 		case VK_IMAGE_VIEW_TYPE_3D:
294 			samplerType << "sampler3D";
295 			break;
296 
297 		case VK_IMAGE_VIEW_TYPE_CUBE:
298 			samplerType << "samplerCube";
299 			break;
300 
301 		case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
302 			samplerType << "samplerCubeArray";
303 			break;
304 
305 		default:
306 			DE_FATAL("Unknown image view type");
307 			break;
308 	}
309 
310 	return samplerType.str();
311 }
312 
getGlslTextureType(const tcu::TextureFormat & format,VkImageViewType type)313 std::string ImageTest::getGlslTextureType (const tcu::TextureFormat& format, VkImageViewType type)
314 {
315 	std::ostringstream textureType;
316 
317 	if (tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER)
318 		textureType << "u";
319 	else if (tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER)
320 		textureType << "i";
321 
322 	switch (type)
323 	{
324 		case VK_IMAGE_VIEW_TYPE_1D:
325 			textureType << "texture1D";
326 			break;
327 
328 		case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
329 			textureType << "texture1DArray";
330 			break;
331 
332 		case VK_IMAGE_VIEW_TYPE_2D:
333 			textureType << "texture2D";
334 			break;
335 
336 		case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
337 			textureType << "texture2DArray";
338 			break;
339 
340 		case VK_IMAGE_VIEW_TYPE_3D:
341 			textureType << "texture3D";
342 			break;
343 
344 		case VK_IMAGE_VIEW_TYPE_CUBE:
345 			textureType << "textureCube";
346 			break;
347 
348 		case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
349 			textureType << "textureCubeArray";
350 			break;
351 
352 		default:
353 			DE_FATAL("Unknown image view type");
354 	}
355 
356 	return textureType.str();
357 }
358 
getGlslSamplerDecl(int imageCount)359 std::string ImageTest::getGlslSamplerDecl (int imageCount)
360 {
361 	std::ostringstream samplerArray;
362 	samplerArray << "texSamplers[" << imageCount << "]";
363 
364 	return imageCount > 1 ? samplerArray.str() : "texSampler";
365 }
366 
getGlslTextureDecl(int imageCount)367 std::string ImageTest::getGlslTextureDecl (int imageCount)
368 {
369 	std::ostringstream textureArray;
370 	textureArray << "texImages[" << imageCount << "]";
371 
372 	return imageCount > 1 ? textureArray.str() : "texImage";
373 }
374 
getGlslFragColorDecl(int imageCount)375 std::string ImageTest::getGlslFragColorDecl (int imageCount)
376 {
377 	std::ostringstream samplerArray;
378 	samplerArray << "fragColors[" << imageCount << "]";
379 
380 	return imageCount > 1 ? samplerArray.str() : "fragColor";
381 }
382 
getGlslSampler(const tcu::TextureFormat & format,VkImageViewType type,VkDescriptorType samplingType,int imageCount)383 std::string ImageTest::getGlslSampler (const tcu::TextureFormat& format, VkImageViewType type, VkDescriptorType samplingType, int imageCount)
384 {
385 	std::string texSampler	= imageCount > 1 ? "texSamplers[i]" : "texSampler";
386 	std::string texImage	= imageCount > 1 ? "texImages[i]" : "texImage";
387 
388 	switch (samplingType)
389 	{
390 		case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
391 			return getGlslSamplerType(format, type) + "(" + texImage + ", texSampler)";
392 		case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
393 		default:
394 			return texSampler;
395 	}
396 }
397 
getFormatCaseName(const VkFormat format)398 std::string getFormatCaseName (const VkFormat format)
399 {
400 	const std::string	fullName	= getFormatName(format);
401 
402 	DE_ASSERT(de::beginsWith(fullName, "VK_FORMAT_"));
403 
404 	return de::toLower(fullName.substr(10));
405 }
406 
getSizeName(VkImageViewType viewType,const tcu::IVec3 & size,int arraySize)407 std::string getSizeName (VkImageViewType viewType, const tcu::IVec3& size, int arraySize)
408 {
409 	std::ostringstream	caseName;
410 
411 	switch (viewType)
412 	{
413 		case VK_IMAGE_VIEW_TYPE_1D:
414 		case VK_IMAGE_VIEW_TYPE_2D:
415 		case VK_IMAGE_VIEW_TYPE_CUBE:
416 			caseName << size.x() << "x" << size.y();
417 			break;
418 
419 		case VK_IMAGE_VIEW_TYPE_3D:
420 			caseName << size.x() << "x" << size.y() << "x" << size.z();
421 			break;
422 
423 		case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
424 		case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
425 		case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
426 			caseName << size.x() << "x" << size.y() << "_array_of_" << arraySize;
427 			break;
428 
429 		default:
430 			DE_ASSERT(false);
431 			break;
432 	}
433 
434 	return caseName.str();
435 }
436 
createImageSizeTests(tcu::TestContext & testCtx,AllocationKind allocationKind,VkDescriptorType samplingType,VkImageViewType imageViewType,VkFormat imageFormat,int imageCount)437 de::MovePtr<tcu::TestCaseGroup> createImageSizeTests (tcu::TestContext& testCtx, AllocationKind allocationKind, VkDescriptorType samplingType, VkImageViewType imageViewType, VkFormat imageFormat, int imageCount)
438 {
439 	using tcu::IVec3;
440 
441 	std::vector<IVec3>					imageSizes;
442 	std::vector<int>					arraySizes;
443 	de::MovePtr<tcu::TestCaseGroup>		imageSizeTests	(new tcu::TestCaseGroup(testCtx, "size", ""));
444 
445 	// Select image imageSizes
446 	switch (imageViewType)
447 	{
448 		case VK_IMAGE_VIEW_TYPE_1D:
449 		case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
450 			// POT
451 			if (imageCount == 1)
452 			{
453 				imageSizes.push_back(IVec3(1, 1, 1));
454 				imageSizes.push_back(IVec3(2, 1, 1));
455 				imageSizes.push_back(IVec3(32, 1, 1));
456 				imageSizes.push_back(IVec3(128, 1, 1));
457 			}
458 			imageSizes.push_back(IVec3(512, 1, 1));
459 
460 			// NPOT
461 			if (imageCount == 1)
462 			{
463 				imageSizes.push_back(IVec3(3, 1, 1));
464 				imageSizes.push_back(IVec3(13, 1, 1));
465 				imageSizes.push_back(IVec3(127, 1, 1));
466 			}
467 			imageSizes.push_back(IVec3(443, 1, 1));
468 			break;
469 
470 		case VK_IMAGE_VIEW_TYPE_2D:
471 		case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
472 			if (imageCount == 1)
473 			{
474 				// POT
475 				imageSizes.push_back(IVec3(1, 1, 1));
476 				imageSizes.push_back(IVec3(2, 2, 1));
477 				imageSizes.push_back(IVec3(32, 32, 1));
478 
479 				// NPOT
480 				imageSizes.push_back(IVec3(3, 3, 1));
481 				imageSizes.push_back(IVec3(13, 13, 1));
482 			}
483 
484 			// POT rectangular
485 			if (imageCount == 1)
486 				imageSizes.push_back(IVec3(8, 16, 1));
487 			imageSizes.push_back(IVec3(32, 16, 1));
488 
489 			// NPOT rectangular
490 			imageSizes.push_back(IVec3(13, 23, 1));
491 			if (imageCount == 1)
492 				imageSizes.push_back(IVec3(23, 8, 1));
493 			break;
494 
495 		case VK_IMAGE_VIEW_TYPE_3D:
496 			// POT cube
497 			if (imageCount == 1)
498 			{
499 				imageSizes.push_back(IVec3(1, 1, 1));
500 				imageSizes.push_back(IVec3(2, 2, 2));
501 			}
502 			imageSizes.push_back(IVec3(16, 16, 16));
503 
504 			// NPOT cube
505 			if (imageCount == 1)
506 			{
507 				imageSizes.push_back(IVec3(3, 3, 3));
508 				imageSizes.push_back(IVec3(5, 5, 5));
509 			}
510 			imageSizes.push_back(IVec3(11, 11, 11));
511 
512 			// POT non-cube
513 			if (imageCount == 1)
514 				imageSizes.push_back(IVec3(32, 16, 8));
515 			imageSizes.push_back(IVec3(8, 16, 32));
516 
517 			// NPOT non-cube
518 			imageSizes.push_back(IVec3(17, 11, 5));
519 			if (imageCount == 1)
520 				imageSizes.push_back(IVec3(5, 11, 17));
521 			break;
522 
523 		case VK_IMAGE_VIEW_TYPE_CUBE:
524 		case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
525 			// POT
526 			imageSizes.push_back(IVec3(32, 32, 1));
527 
528 			// NPOT
529 			imageSizes.push_back(IVec3(13, 13, 1));
530 			break;
531 
532 		default:
533 			DE_ASSERT(false);
534 			break;
535 	}
536 
537 	// Select array sizes
538 	switch (imageViewType)
539 	{
540 		case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
541 		case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
542 			if (imageCount == 1)
543 				arraySizes.push_back(3);
544 			arraySizes.push_back(6);
545 			break;
546 
547 		case VK_IMAGE_VIEW_TYPE_CUBE:
548 			arraySizes.push_back(6);
549 			break;
550 
551 		case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
552 			if (imageCount == 1)
553 				arraySizes.push_back(6);
554 			arraySizes.push_back(6 * 6);
555 			break;
556 
557 		default:
558 			arraySizes.push_back(1);
559 			break;
560 	}
561 
562 	for (size_t sizeNdx = 0; sizeNdx < imageSizes.size(); sizeNdx++)
563 	{
564 		for (size_t arraySizeNdx = 0; arraySizeNdx < arraySizes.size(); arraySizeNdx++)
565 		{
566 			imageSizeTests->addChild(new ImageTest(testCtx,
567 												   getSizeName(imageViewType, imageSizes[sizeNdx], arraySizes[arraySizeNdx]).c_str(),
568 												   "",
569 												   allocationKind,
570 												   samplingType,
571 												   imageViewType,
572 												   imageFormat,
573 												   imageSizes[sizeNdx],
574 												   imageCount,
575 												   arraySizes[arraySizeNdx]));
576 		}
577 	}
578 
579 	return imageSizeTests;
580 }
581 
createImageCountTests(tcu::TestCaseGroup * parentGroup,tcu::TestContext & testCtx,AllocationKind allocationKind,VkDescriptorType samplingType,VkImageViewType imageViewType,VkFormat imageFormat)582 void createImageCountTests (tcu::TestCaseGroup* parentGroup, tcu::TestContext& testCtx, AllocationKind allocationKind, VkDescriptorType samplingType, VkImageViewType imageViewType, VkFormat imageFormat)
583 {
584 	const int		coreImageCounts[]					= { 1, 4, 8 };
585 	const int		dedicatedAllocationImageCounts[]	= { 1 };
586 	const int*		imageCounts							= (allocationKind == ALLOCATION_KIND_DEDICATED)
587 														  ? dedicatedAllocationImageCounts
588 														  : coreImageCounts;
589 	const size_t	imageCountsLength					= (allocationKind == ALLOCATION_KIND_DEDICATED)
590 														  ? DE_LENGTH_OF_ARRAY(dedicatedAllocationImageCounts)
591 														  : DE_LENGTH_OF_ARRAY(coreImageCounts);
592 
593 	for (size_t countNdx = 0; countNdx < imageCountsLength; countNdx++)
594 	{
595 		std::ostringstream	caseName;
596 		caseName << "count_" << imageCounts[countNdx];
597 		de::MovePtr<tcu::TestCaseGroup>	countGroup(new tcu::TestCaseGroup(testCtx, caseName.str().c_str(), ""));
598 		de::MovePtr<tcu::TestCaseGroup> sizeTests = createImageSizeTests(testCtx, allocationKind, samplingType, imageViewType, imageFormat, imageCounts[countNdx]);
599 
600 		countGroup->addChild(sizeTests.release());
601 		parentGroup->addChild(countGroup.release());
602 	}
603 }
604 
createImageFormatTests(tcu::TestContext & testCtx,AllocationKind allocationKind,VkDescriptorType samplingType,VkImageViewType imageViewType)605 de::MovePtr<tcu::TestCaseGroup> createImageFormatTests (tcu::TestContext& testCtx, AllocationKind allocationKind, VkDescriptorType samplingType, VkImageViewType imageViewType)
606 {
607 	// All supported dEQP formats that are not intended for depth or stencil.
608 	const VkFormat coreFormats[]					=
609 	{
610 		VK_FORMAT_R4G4_UNORM_PACK8,
611 		VK_FORMAT_R4G4B4A4_UNORM_PACK16,
612 		VK_FORMAT_R5G6B5_UNORM_PACK16,
613 		VK_FORMAT_R5G5B5A1_UNORM_PACK16,
614 		VK_FORMAT_R8_UNORM,
615 		VK_FORMAT_R8_SNORM,
616 		VK_FORMAT_R8_USCALED,
617 		VK_FORMAT_R8_SSCALED,
618 		VK_FORMAT_R8_UINT,
619 		VK_FORMAT_R8_SINT,
620 		VK_FORMAT_R8_SRGB,
621 		VK_FORMAT_R8G8_UNORM,
622 		VK_FORMAT_R8G8_SNORM,
623 		VK_FORMAT_R8G8_USCALED,
624 		VK_FORMAT_R8G8_SSCALED,
625 		VK_FORMAT_R8G8_UINT,
626 		VK_FORMAT_R8G8_SINT,
627 		VK_FORMAT_R8G8_SRGB,
628 		VK_FORMAT_R8G8B8_UNORM,
629 		VK_FORMAT_R8G8B8_SNORM,
630 		VK_FORMAT_R8G8B8_USCALED,
631 		VK_FORMAT_R8G8B8_SSCALED,
632 		VK_FORMAT_R8G8B8_UINT,
633 		VK_FORMAT_R8G8B8_SINT,
634 		VK_FORMAT_R8G8B8_SRGB,
635 		VK_FORMAT_R8G8B8A8_UNORM,
636 		VK_FORMAT_R8G8B8A8_SNORM,
637 		VK_FORMAT_R8G8B8A8_USCALED,
638 		VK_FORMAT_R8G8B8A8_SSCALED,
639 		VK_FORMAT_R8G8B8A8_UINT,
640 		VK_FORMAT_R8G8B8A8_SINT,
641 		VK_FORMAT_R8G8B8A8_SRGB,
642 		VK_FORMAT_A2R10G10B10_UNORM_PACK32,
643 		VK_FORMAT_A2R10G10B10_UINT_PACK32,
644 		VK_FORMAT_A2R10G10B10_USCALED_PACK32,
645 		VK_FORMAT_A2B10G10R10_UNORM_PACK32,
646 		VK_FORMAT_A2B10G10R10_UINT_PACK32,
647 		VK_FORMAT_A1R5G5B5_UNORM_PACK16,
648 		VK_FORMAT_R16_UNORM,
649 		VK_FORMAT_R16_SNORM,
650 		VK_FORMAT_R16_USCALED,
651 		VK_FORMAT_R16_SSCALED,
652 		VK_FORMAT_R16_UINT,
653 		VK_FORMAT_R16_SINT,
654 		VK_FORMAT_R16_SFLOAT,
655 		VK_FORMAT_R16G16_UNORM,
656 		VK_FORMAT_R16G16_SNORM,
657 		VK_FORMAT_R16G16_USCALED,
658 		VK_FORMAT_R16G16_SSCALED,
659 		VK_FORMAT_R16G16_UINT,
660 		VK_FORMAT_R16G16_SINT,
661 		VK_FORMAT_R16G16_SFLOAT,
662 		VK_FORMAT_R16G16B16_UNORM,
663 		VK_FORMAT_R16G16B16_SNORM,
664 		VK_FORMAT_R16G16B16_USCALED,
665 		VK_FORMAT_R16G16B16_SSCALED,
666 		VK_FORMAT_R16G16B16_UINT,
667 		VK_FORMAT_R16G16B16_SINT,
668 		VK_FORMAT_R16G16B16_SFLOAT,
669 		VK_FORMAT_R16G16B16A16_UNORM,
670 		VK_FORMAT_R16G16B16A16_SNORM,
671 		VK_FORMAT_R16G16B16A16_USCALED,
672 		VK_FORMAT_R16G16B16A16_SSCALED,
673 		VK_FORMAT_R16G16B16A16_UINT,
674 		VK_FORMAT_R16G16B16A16_SINT,
675 		VK_FORMAT_R16G16B16A16_SFLOAT,
676 		VK_FORMAT_R32_UINT,
677 		VK_FORMAT_R32_SINT,
678 		VK_FORMAT_R32_SFLOAT,
679 		VK_FORMAT_R32G32_UINT,
680 		VK_FORMAT_R32G32_SINT,
681 		VK_FORMAT_R32G32_SFLOAT,
682 		VK_FORMAT_R32G32B32_UINT,
683 		VK_FORMAT_R32G32B32_SINT,
684 		VK_FORMAT_R32G32B32_SFLOAT,
685 		VK_FORMAT_R32G32B32A32_UINT,
686 		VK_FORMAT_R32G32B32A32_SINT,
687 		VK_FORMAT_R32G32B32A32_SFLOAT,
688 		VK_FORMAT_B10G11R11_UFLOAT_PACK32,
689 		VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
690 		VK_FORMAT_B4G4R4A4_UNORM_PACK16,
691 		VK_FORMAT_B5G5R5A1_UNORM_PACK16,
692 		VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT,
693 		VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT,
694 
695 		// Compressed formats
696 		VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
697 		VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
698 		VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
699 		VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
700 		VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
701 		VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
702 		VK_FORMAT_EAC_R11_UNORM_BLOCK,
703 		VK_FORMAT_EAC_R11_SNORM_BLOCK,
704 		VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
705 		VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
706 		VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
707 		VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
708 		VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
709 		VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
710 		VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
711 		VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
712 		VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
713 		VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
714 		VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
715 		VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
716 		VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
717 		VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
718 		VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
719 		VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
720 		VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
721 		VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
722 		VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
723 		VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
724 		VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
725 		VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
726 		VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
727 		VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
728 		VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
729 		VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
730 		VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
731 		VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
732 		VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
733 		VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
734 	};
735 	// Formats to test with dedicated allocation
736 	const VkFormat	dedicatedAllocationFormats[]	=
737 	{
738 		VK_FORMAT_R8G8B8A8_UNORM,
739 		VK_FORMAT_R16_SFLOAT,
740 	};
741 	const VkFormat*	formats							= (allocationKind == ALLOCATION_KIND_DEDICATED)
742 													  ? dedicatedAllocationFormats
743 													  : coreFormats;
744 	const size_t	formatsLength					= (allocationKind == ALLOCATION_KIND_DEDICATED)
745 													  ? DE_LENGTH_OF_ARRAY(dedicatedAllocationFormats)
746 													  : DE_LENGTH_OF_ARRAY(coreFormats);
747 
748 	de::MovePtr<tcu::TestCaseGroup>	imageFormatTests(new tcu::TestCaseGroup(testCtx, "format", "Tests samplable formats"));
749 
750 	for (size_t formatNdx = 0; formatNdx < formatsLength; formatNdx++)
751 	{
752 		const VkFormat	format = formats[formatNdx];
753 
754 		if (isCompressedFormat(format))
755 		{
756 			// Do not use compressed formats with 1D and 1D array textures.
757 			if (imageViewType == VK_IMAGE_VIEW_TYPE_1D || imageViewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY)
758 				break;
759 		}
760 
761 		de::MovePtr<tcu::TestCaseGroup>	formatGroup(new tcu::TestCaseGroup(testCtx,
762 			getFormatCaseName(format).c_str(),
763 			(std::string("Samples a texture of format ") + getFormatName(format)).c_str()));
764 		createImageCountTests(formatGroup.get(), testCtx, allocationKind, samplingType, imageViewType, format);
765 
766 		imageFormatTests->addChild(formatGroup.release());
767 	}
768 
769 	return imageFormatTests;
770 }
771 
createImageViewTypeTests(tcu::TestContext & testCtx,AllocationKind allocationKind,VkDescriptorType samplingType)772 de::MovePtr<tcu::TestCaseGroup> createImageViewTypeTests (tcu::TestContext& testCtx, AllocationKind allocationKind, VkDescriptorType samplingType)
773 {
774 	const struct
775 	{
776 		VkImageViewType		type;
777 		const char*			name;
778 	}
779 	imageViewTypes[] =
780 	{
781 		{ VK_IMAGE_VIEW_TYPE_1D,			"1d" },
782 		{ VK_IMAGE_VIEW_TYPE_1D_ARRAY,		"1d_array" },
783 		{ VK_IMAGE_VIEW_TYPE_2D,			"2d" },
784 		{ VK_IMAGE_VIEW_TYPE_2D_ARRAY,		"2d_array" },
785 		{ VK_IMAGE_VIEW_TYPE_3D,			"3d" },
786 		{ VK_IMAGE_VIEW_TYPE_CUBE,			"cube" },
787 		{ VK_IMAGE_VIEW_TYPE_CUBE_ARRAY,	"cube_array" }
788 	};
789 
790 	de::MovePtr<tcu::TestCaseGroup> imageViewTypeTests(new tcu::TestCaseGroup(testCtx, "view_type", ""));
791 
792 	for (int viewTypeNdx = 0; viewTypeNdx < DE_LENGTH_OF_ARRAY(imageViewTypes); viewTypeNdx++)
793 	{
794 		const VkImageViewType			viewType = imageViewTypes[viewTypeNdx].type;
795 		de::MovePtr<tcu::TestCaseGroup>	viewTypeGroup(new tcu::TestCaseGroup(testCtx, imageViewTypes[viewTypeNdx].name, (std::string("Uses a ") + imageViewTypes[viewTypeNdx].name + " view").c_str()));
796 		de::MovePtr<tcu::TestCaseGroup>	formatTests = createImageFormatTests(testCtx, allocationKind, samplingType, viewType);
797 
798 		viewTypeGroup->addChild(formatTests.release());
799 		imageViewTypeTests->addChild(viewTypeGroup.release());
800 	}
801 
802 	return imageViewTypeTests;
803 }
804 
createImageSamplingTypeTests(tcu::TestContext & testCtx,AllocationKind allocationKind)805 de::MovePtr<tcu::TestCaseGroup> createImageSamplingTypeTests (tcu::TestContext& testCtx, AllocationKind allocationKind)
806 {
807 	VkDescriptorType samplingTypes[] =
808 	{
809 		VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
810 		VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
811 	};
812 
813 	de::MovePtr<tcu::TestCaseGroup> imageSamplingTypeTests(new tcu::TestCaseGroup(testCtx, "sampling_type", ""));
814 
815 	for (int smpTypeNdx = 0; smpTypeNdx < DE_LENGTH_OF_ARRAY(samplingTypes); smpTypeNdx++)
816 	{
817 		const char* smpTypeName = samplingTypes[smpTypeNdx] == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER ? "combined" : "separate";
818 		de::MovePtr<tcu::TestCaseGroup>	samplingTypeGroup(new tcu::TestCaseGroup(testCtx, smpTypeName, (std::string("Uses a ") + smpTypeName + " sampler").c_str()));
819 		de::MovePtr<tcu::TestCaseGroup>	viewTypeTests = createImageViewTypeTests(testCtx, allocationKind, samplingTypes[smpTypeNdx]);
820 
821 		samplingTypeGroup->addChild(viewTypeTests.release());
822 		imageSamplingTypeTests->addChild(samplingTypeGroup.release());
823 	}
824 
825 	return imageSamplingTypeTests;
826 }
827 
createSuballocationTests(tcu::TestContext & testCtx)828 de::MovePtr<tcu::TestCaseGroup> createSuballocationTests(tcu::TestContext& testCtx)
829 {
830 	de::MovePtr<tcu::TestCaseGroup>	suballocationTestsGroup(new tcu::TestCaseGroup(testCtx, "suballocation", "Suballocation Image Tests"));
831 	de::MovePtr<tcu::TestCaseGroup>	samplingTypeTests = createImageSamplingTypeTests(testCtx, ALLOCATION_KIND_SUBALLOCATED);
832 
833 	suballocationTestsGroup->addChild(samplingTypeTests.release());
834 
835 	return suballocationTestsGroup;
836 }
837 
createDedicatedAllocationTests(tcu::TestContext & testCtx)838 de::MovePtr<tcu::TestCaseGroup> createDedicatedAllocationTests(tcu::TestContext& testCtx)
839 {
840 	de::MovePtr<tcu::TestCaseGroup>	dedicatedAllocationTestsGroup(new tcu::TestCaseGroup(testCtx, "dedicated_allocation", "Image Tests For Dedicated Allocation"));
841 	de::MovePtr<tcu::TestCaseGroup>	samplingTypeTests = createImageSamplingTypeTests(testCtx, ALLOCATION_KIND_DEDICATED);
842 
843 	dedicatedAllocationTestsGroup->addChild(samplingTypeTests.release());
844 
845 	return dedicatedAllocationTestsGroup;
846 }
847 } // anonymous
848 
createImageTests(tcu::TestContext & testCtx)849 tcu::TestCaseGroup* createImageTests (tcu::TestContext& testCtx)
850 {
851 	de::MovePtr<tcu::TestCaseGroup> imageTests(new tcu::TestCaseGroup(testCtx, "image", "Image tests"));
852 	de::MovePtr<tcu::TestCaseGroup> imageSuballocationTests = createSuballocationTests(testCtx);
853 	de::MovePtr<tcu::TestCaseGroup> imageDedicatedAllocationTests = createDedicatedAllocationTests(testCtx);
854 
855 	imageTests->addChild(imageSuballocationTests.release());
856 	imageTests->addChild(imageDedicatedAllocationTests.release());
857 
858 	return imageTests.release();
859 }
860 
861 } // pipeline
862 } // vkt
863