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