1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Imagination Technologies Ltd.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and/or associated documentation files (the
10 * "Materials"), to deal in the Materials without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Materials, and to
13 * permit persons to whom the Materials are furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice(s) and this permission notice shall be included
17 * in all copies or substantial portions of the Materials.
19 * The Materials are Confidential Information as defined by the
20 * Khronos Membership Agreement until designated non-confidential by Khronos,
21 * at which point this condition clause shall be removed.
23 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
33 * \brief Sampler Tests
34 *//*--------------------------------------------------------------------*/
36 #include "vktPipelineSamplerTests.hpp"
37 #include "vktPipelineImageSamplingInstance.hpp"
38 #include "vktPipelineImageUtil.hpp"
39 #include "vktPipelineVertexUtil.hpp"
40 #include "vktTestCase.hpp"
41 #include "vkImageUtil.hpp"
42 #include "vkPrograms.hpp"
43 #include "tcuPlatform.hpp"
44 #include "tcuTextureUtil.hpp"
45 #include "deStringUtil.hpp"
63 class SamplerTest : public vkt::TestCase
66 SamplerTest (tcu::TestContext& testContext,
68 const char* description,
69 VkImageViewType imageViewType,
73 virtual ~SamplerTest (void) {}
75 virtual void initPrograms (SourceCollections& sourceCollections) const;
76 virtual TestInstance* createInstance (Context& context) const;
77 virtual tcu::IVec2 getRenderSize (VkImageViewType viewType) const;
78 virtual std::vector<Vertex4Tex4> createVertices (void) const;
79 virtual VkSamplerCreateInfo getSamplerCreateInfo (void) const;
81 static std::string getGlslSamplerType (const tcu::TextureFormat& format, VkImageViewType type);
82 static tcu::IVec3 getImageSize (VkImageViewType viewType, int size);
83 static int getArraySize (VkImageViewType viewType);
86 VkImageViewType m_imageViewType;
87 VkFormat m_imageFormat;
89 VkImageViewCreateInfo m_imageViewParams;
90 VkSamplerCreateInfo m_samplerParams;
94 class SamplerMagFilterTest : public SamplerTest
97 SamplerMagFilterTest (tcu::TestContext& testContext,
99 const char* description,
100 VkImageViewType imageViewType,
101 VkFormat imageFormat,
103 virtual ~SamplerMagFilterTest (void) {}
104 virtual VkSamplerCreateInfo getSamplerCreateInfo (void) const;
107 VkFilter m_magFilter;
110 class SamplerMinFilterTest : public SamplerTest
113 SamplerMinFilterTest (tcu::TestContext& testContext,
115 const char* description,
116 VkImageViewType imageViewType,
117 VkFormat imageFormat,
119 virtual ~SamplerMinFilterTest (void) {}
120 virtual VkSamplerCreateInfo getSamplerCreateInfo (void) const;
123 VkFilter m_minFilter;
126 class SamplerLodTest : public SamplerTest
129 SamplerLodTest (tcu::TestContext& testContext,
131 const char* description,
132 VkImageViewType imageViewType,
133 VkFormat imageFormat,
134 VkSamplerMipmapMode mipmapMode,
139 virtual ~SamplerLodTest (void) {}
140 virtual VkSamplerCreateInfo getSamplerCreateInfo (void) const;
143 VkSamplerMipmapMode m_mipmapMode;
149 class SamplerAddressModesTest : public SamplerTest
152 SamplerAddressModesTest (tcu::TestContext& testContext,
154 const char* description,
155 VkImageViewType imageViewType,
156 VkFormat imageFormat,
157 VkSamplerAddressMode addressU,
158 VkSamplerAddressMode addressV,
159 VkSamplerAddressMode addressW,
160 VkBorderColor borderColor);
161 virtual ~SamplerAddressModesTest (void) {}
162 virtual tcu::IVec2 getRenderSize (VkImageViewType viewType) const;
163 virtual std::vector<Vertex4Tex4> createVertices (void) const;
164 virtual VkSamplerCreateInfo getSamplerCreateInfo (void) const;
167 VkSamplerAddressMode m_addressU;
168 VkSamplerAddressMode m_addressV;
169 VkSamplerAddressMode m_addressW;
170 VkBorderColor m_borderColor;
176 SamplerTest::SamplerTest (tcu::TestContext& testContext,
178 const char* description,
179 VkImageViewType imageViewType,
180 VkFormat imageFormat,
183 : vkt::TestCase (testContext, name, description)
184 , m_imageViewType (imageViewType)
185 , m_imageFormat (imageFormat)
186 , m_imageSize (imageSize)
187 , m_samplerLod (samplerLod)
191 void SamplerTest::initPrograms (SourceCollections& sourceCollections) const
193 std::ostringstream vertexSrc;
194 std::ostringstream fragmentSrc;
195 const char* texCoordSwizzle = DE_NULL;
196 tcu::TextureFormat format = (isCompressedFormat(m_imageFormat)) ? tcu::getUncompressedFormat(mapVkCompressedFormat(m_imageFormat))
197 : mapVkFormat(m_imageFormat);
198 const tcu::TextureFormatInfo formatInfo = tcu::getTextureFormatInfo(format);
200 switch (m_imageViewType)
202 case VK_IMAGE_VIEW_TYPE_1D:
203 texCoordSwizzle = "x";
205 case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
206 case VK_IMAGE_VIEW_TYPE_2D:
207 texCoordSwizzle = "xy";
209 case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
210 case VK_IMAGE_VIEW_TYPE_3D:
211 case VK_IMAGE_VIEW_TYPE_CUBE:
212 texCoordSwizzle = "xyz";
214 case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
215 texCoordSwizzle = "xyzw";
222 vertexSrc << "#version 440\n"
223 << "layout(location = 0) in vec4 position;\n"
224 << "layout(location = 1) in vec4 texCoords;\n"
225 << "layout(location = 0) out highp vec4 vtxTexCoords;\n"
226 << "out gl_PerVertex {\n"
227 << " vec4 gl_Position;\n"
229 << "void main (void)\n"
231 << " gl_Position = position;\n"
232 << " vtxTexCoords = texCoords;\n"
235 fragmentSrc << "#version 440\n"
236 << "layout(set = 0, binding = 0) uniform highp " << getGlslSamplerType(format, m_imageViewType) << " texSampler;\n"
237 << "layout(location = 0) in highp vec4 vtxTexCoords;\n"
238 << "layout(location = 0) out highp vec4 fragColor;\n"
239 << "void main (void)\n"
243 if (m_samplerLod > 0.0f)
244 fragmentSrc << "textureLod(texSampler, vtxTexCoords." << texCoordSwizzle << ", " << std::fixed << m_samplerLod << ")";
246 fragmentSrc << "texture(texSampler, vtxTexCoords." << texCoordSwizzle << ")" << std::fixed;
248 fragmentSrc << " * vec4" << std::scientific << formatInfo.lookupScale << " + vec4" << formatInfo.lookupBias << ";\n"
251 sourceCollections.glslSources.add("tex_vert") << glu::VertexSource(vertexSrc.str());
252 sourceCollections.glslSources.add("tex_frag") << glu::FragmentSource(fragmentSrc.str());
255 TestInstance* SamplerTest::createInstance (Context& context) const
257 const tcu::IVec2 renderSize = getRenderSize(m_imageViewType);
258 const std::vector<Vertex4Tex4> vertices = createVertices();
259 const VkSamplerCreateInfo samplerParams = getSamplerCreateInfo();
260 const VkComponentMapping componentMapping = getFormatComponentMapping(m_imageFormat);
261 const VkImageSubresourceRange subresourceRange =
263 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
264 0u, // deUint32 baseMipLevel;
265 (deUint32)deLog2Floor32(m_imageSize) + 1, // deUint32 mipLevels;
266 0u, // deUint32 baseArrayLayer;
267 (deUint32)SamplerTest::getArraySize(m_imageViewType) // deUint32 arraySize;
272 return new ImageSamplingInstance(context, renderSize, m_imageViewType, m_imageFormat,
273 getImageSize(m_imageViewType, m_imageSize),
274 getArraySize(m_imageViewType),
275 componentMapping, subresourceRange,
276 samplerParams, m_samplerLod,vertices);
279 tcu::IVec2 SamplerTest::getRenderSize (VkImageViewType viewType) const
281 if (viewType == VK_IMAGE_VIEW_TYPE_1D || viewType == VK_IMAGE_VIEW_TYPE_2D)
283 return tcu::IVec2(16, 16);
287 return tcu::IVec2(16 * 3, 16 * 2);
291 std::vector<Vertex4Tex4> SamplerTest::createVertices (void) const
293 std::vector<Vertex4Tex4> vertices = createTestQuadMosaic(m_imageViewType);
294 // Adjust texture coordinate to avoid doing NEAREST filtering exactly on texel boundaries.
295 // TODO: Would be nice to base this on number of texels and subtexel precision. But this
297 for (unsigned int i = 0; i < vertices.size(); ++i) {
298 vertices[i].texCoord += tcu::Vec4(0.001f, 0.001f, 0.001f, 0.0f);
303 VkSamplerCreateInfo SamplerTest::getSamplerCreateInfo (void) const
305 const VkSamplerCreateInfo defaultSamplerParams =
307 VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, // VkStructureType sType;
308 DE_NULL, // const void* pNext;
309 0u, // VkSamplerCreateFlags flags;
310 VK_FILTER_NEAREST, // VkFilter magFilter;
311 VK_FILTER_NEAREST, // VkFilter minFilter;
312 VK_SAMPLER_MIPMAP_MODE_BASE, // VkSamplerMipmapMode mipmapMode;
313 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // VkSamplerAddressMode addressModeU;
314 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // VkSamplerAddressMode addressModeV;
315 VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // VkSamplerAddressMode addressModeW;
316 0.0f, // float mipLodBias;
317 1.0f, // float maxAnisotropy;
318 false, // VkBool32 compareEnable;
319 VK_COMPARE_OP_NEVER, // VkCompareOp compareOp;
320 0.0f, // float minLod;
321 (float)deLog2Floor32(m_imageSize) + 1, // float maxLod;
322 getFormatBorderColor(BORDER_COLOR_TRANSPARENT_BLACK, m_imageFormat), // VkBorderColor borderColor;
323 false // VkBool32 unnormalizedCoordinates;
326 return defaultSamplerParams;
329 std::string SamplerTest::getGlslSamplerType (const tcu::TextureFormat& format, VkImageViewType type)
331 std::ostringstream samplerType;
333 if (tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER)
335 else if (tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER)
340 case VK_IMAGE_VIEW_TYPE_1D:
341 samplerType << "sampler1D";
344 case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
345 samplerType << "sampler1DArray";
348 case VK_IMAGE_VIEW_TYPE_2D:
349 samplerType << "sampler2D";
352 case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
353 samplerType << "sampler2DArray";
356 case VK_IMAGE_VIEW_TYPE_3D:
357 samplerType << "sampler3D";
360 case VK_IMAGE_VIEW_TYPE_CUBE:
361 samplerType << "samplerCube";
364 case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
365 samplerType << "samplerCubeArray";
369 DE_FATAL("Unknown image view type");
373 return samplerType.str();
376 tcu::IVec3 SamplerTest::getImageSize (VkImageViewType viewType, int size)
380 case VK_IMAGE_VIEW_TYPE_1D:
381 case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
382 return tcu::IVec3(size, 1, 1);
384 case VK_IMAGE_VIEW_TYPE_3D:
385 return tcu::IVec3(size, size, 4);
391 return tcu::IVec3(size, size, 1);
394 int SamplerTest::getArraySize (VkImageViewType viewType)
398 case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
399 case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
400 case VK_IMAGE_VIEW_TYPE_CUBE:
403 case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
414 // SamplerMagFilterTest
416 SamplerMagFilterTest::SamplerMagFilterTest (tcu::TestContext& testContext,
418 const char* description,
419 VkImageViewType imageViewType,
420 VkFormat imageFormat,
422 : SamplerTest (testContext, name, description, imageViewType, imageFormat, 8, 0.0f)
423 , m_magFilter (magFilter)
427 VkSamplerCreateInfo SamplerMagFilterTest::getSamplerCreateInfo (void) const
429 VkSamplerCreateInfo samplerParams = SamplerTest::getSamplerCreateInfo();
430 samplerParams.magFilter = m_magFilter;
432 return samplerParams;
436 // SamplerMinFilterTest
438 SamplerMinFilterTest::SamplerMinFilterTest (tcu::TestContext& testContext,
440 const char* description,
441 VkImageViewType imageViewType,
442 VkFormat imageFormat,
444 : SamplerTest (testContext, name, description, imageViewType, imageFormat, 32, 0.0f)
445 , m_minFilter (minFilter)
449 VkSamplerCreateInfo SamplerMinFilterTest::getSamplerCreateInfo (void) const
451 VkSamplerCreateInfo samplerParams = SamplerTest::getSamplerCreateInfo();
452 samplerParams.minFilter = m_minFilter;
453 // set minLod to epsilon, to force use of the minFilter
454 samplerParams.minLod = 0.01f;
456 return samplerParams;
462 SamplerLodTest::SamplerLodTest (tcu::TestContext& testContext,
464 const char* description,
465 VkImageViewType imageViewType,
466 VkFormat imageFormat,
467 VkSamplerMipmapMode mipmapMode,
472 : SamplerTest (testContext, name, description, imageViewType, imageFormat, 32, samplerLod)
473 , m_mipmapMode (mipmapMode)
476 , m_mipLodBias (mipLodBias)
480 VkSamplerCreateInfo SamplerLodTest::getSamplerCreateInfo (void) const
482 VkSamplerCreateInfo samplerParams = SamplerTest::getSamplerCreateInfo();
484 samplerParams.mipmapMode = m_mipmapMode;
485 samplerParams.minLod = m_minLod;
486 samplerParams.maxLod = m_maxLod;
487 samplerParams.mipLodBias = m_mipLodBias;
489 return samplerParams;
493 // SamplerAddressModesTest
495 SamplerAddressModesTest::SamplerAddressModesTest (tcu::TestContext& testContext,
497 const char* description,
498 VkImageViewType imageViewType,
499 VkFormat imageFormat,
500 VkSamplerAddressMode addressU,
501 VkSamplerAddressMode addressV,
502 VkSamplerAddressMode addressW,
503 VkBorderColor borderColor)
504 : SamplerTest (testContext, name, description, imageViewType, imageFormat, 8, 0.0f)
505 , m_addressU (addressU)
506 , m_addressV (addressV)
507 , m_addressW (addressW)
508 , m_borderColor (borderColor)
512 tcu::IVec2 SamplerAddressModesTest::getRenderSize (VkImageViewType viewType) const
514 return 4 * SamplerTest::getRenderSize(viewType);
517 std::vector<Vertex4Tex4> SamplerAddressModesTest::createVertices (void) const
519 std::vector<Vertex4Tex4> vertices = SamplerTest::createVertices();
521 switch (m_imageViewType)
523 case VK_IMAGE_VIEW_TYPE_1D: case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
524 for (size_t vertexNdx = 0; vertexNdx < vertices.size(); vertexNdx++)
525 vertices[vertexNdx].texCoord.x() = (vertices[vertexNdx].texCoord.x() - 0.5f) * 4.0f;
529 case VK_IMAGE_VIEW_TYPE_2D:
530 case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
531 for (size_t vertexNdx = 0; vertexNdx < vertices.size(); vertexNdx++)
532 vertices[vertexNdx].texCoord.xy() = (vertices[vertexNdx].texCoord.swizzle(0, 1) - tcu::Vec2(0.5f)) * 4.0f;
536 case VK_IMAGE_VIEW_TYPE_3D:
537 for (size_t vertexNdx = 0; vertexNdx < vertices.size(); vertexNdx++)
538 vertices[vertexNdx].texCoord.xyz() = (vertices[vertexNdx].texCoord.swizzle(0, 1, 2) - tcu::Vec3(0.5f)) * 4.0f;
542 case VK_IMAGE_VIEW_TYPE_CUBE:
543 case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
553 VkSamplerCreateInfo SamplerAddressModesTest::getSamplerCreateInfo (void) const
555 VkSamplerCreateInfo samplerParams = SamplerTest::getSamplerCreateInfo();
556 samplerParams.addressModeU = m_addressU;
557 samplerParams.addressModeV = m_addressV;
558 samplerParams.addressModeW = m_addressW;
559 samplerParams.borderColor = m_borderColor;
561 return samplerParams;
565 // Utilities to create test nodes
567 std::string getFormatCaseName (const VkFormat format)
569 const std::string fullName = getFormatName(format);
571 DE_ASSERT(de::beginsWith(fullName, "VK_FORMAT_"));
573 return de::toLower(fullName.substr(10));
576 MovePtr<tcu::TestCaseGroup> createSamplerMagFilterTests (tcu::TestContext& testCtx, VkImageViewType imageViewType, VkFormat imageFormat)
578 MovePtr<tcu::TestCaseGroup> samplerMagFilterTests (new tcu::TestCaseGroup(testCtx, "mag_filter", "Tests for magnification filter"));
580 if (isCompressedFormat(imageFormat) || (!isIntFormat(imageFormat) && !isUintFormat(imageFormat)))
581 samplerMagFilterTests->addChild(new SamplerMagFilterTest(testCtx, "linear", "Magnifies image using VK_TEX_FILTER_LINEAR", imageViewType, imageFormat, VK_FILTER_LINEAR));
582 samplerMagFilterTests->addChild(new SamplerMagFilterTest(testCtx, "nearest", "Magnifies image using VK_TEX_FILTER_NEAREST", imageViewType, imageFormat, VK_FILTER_NEAREST));
584 return samplerMagFilterTests;
587 MovePtr<tcu::TestCaseGroup> createSamplerMinFilterTests (tcu::TestContext& testCtx, VkImageViewType imageViewType, VkFormat imageFormat)
589 MovePtr<tcu::TestCaseGroup> samplerMinFilterTests (new tcu::TestCaseGroup(testCtx, "min_filter", "Tests for minification filter"));
591 if (isCompressedFormat(imageFormat) || (!isIntFormat(imageFormat) && !isUintFormat(imageFormat)))
592 samplerMinFilterTests->addChild(new SamplerMinFilterTest(testCtx, "linear", "Minifies image using VK_TEX_FILTER_LINEAR", imageViewType, imageFormat, VK_FILTER_LINEAR));
593 samplerMinFilterTests->addChild(new SamplerMinFilterTest(testCtx, "nearest", "Minifies image using VK_TEX_FILTER_NEAREST", imageViewType, imageFormat, VK_FILTER_NEAREST));
595 return samplerMinFilterTests;
598 MovePtr<tcu::TestCaseGroup> createSamplerLodTests (tcu::TestContext& testCtx, VkImageViewType imageViewType, VkFormat imageFormat, VkSamplerMipmapMode mipmapMode)
600 struct TestCaseConfig
603 const char* description;
610 TestCaseConfig testCaseConfigs [] =
612 { "equal_min_3_max_3", "minLod = 3, maxLod = 3, mipLodBias = 0, lod = 0", 3.0f, 3.0f, 0.0f, 0.0f },
613 { "select_min_1", "minLod = 1, maxLod = 5, mipLodBias = 0, lod = 0", 1.0f, 5.0f, 0.0f, 0.0f },
614 { "select_max_4", "minLod = 0, maxLod = 4, mipLodBias = 0, lod = 5", 0.0f, 4.0f, 0.0f, 5.0f },
615 { "select_bias_2_1", "minLod = 0, maxLod = 2.1, mipLodBias = 5.0, lod = 0", 0.0f, 2.1f, 5.0f, 0.0f },
616 { "select_bias_2_5", "minLod = 0, maxLod = 5, mipLodBias = 2.5, lod = 0", 0.0f, 5.0f, 2.5f, 0.00001f },
617 { "select_bias_3_1", "minLod = 0, maxLod = 5, mipLodBias = -0.9, lod = 4.0", 0.0f, 5.0f, -0.9f, 4.0f },
618 { "select_bias_3_7", "minLod = 0, maxLod = 5, mipLodBias = 3.0, lod = 0.7", 0.0f, 5.0f, 3.0f, 0.7f },
621 MovePtr<tcu::TestCaseGroup> samplerLodTests (new tcu::TestCaseGroup(testCtx, "lod", "Tests for sampler LOD"));
623 for (int configNdx = 0; configNdx < DE_LENGTH_OF_ARRAY(testCaseConfigs); configNdx++)
625 const TestCaseConfig& config = testCaseConfigs[configNdx];
627 samplerLodTests->addChild(new SamplerLodTest(testCtx, config.name, config.description, imageViewType, imageFormat, mipmapMode, config.minLod, config.maxLod, config.mipLodBias, config.lod));
630 return samplerLodTests;
633 MovePtr<tcu::TestCaseGroup> createSamplerMipmapTests (tcu::TestContext& testCtx, VkImageViewType imageViewType, VkFormat imageFormat)
635 MovePtr<tcu::TestCaseGroup> samplerMipmapTests (new tcu::TestCaseGroup(testCtx, "mipmap", "Tests for mipmap modes"));
637 // Mipmap mode: nearest
638 MovePtr<tcu::TestCaseGroup> mipmapNearestTests (new tcu::TestCaseGroup(testCtx, "nearest", "Uses VK_TEX_MIPMAP_MODE_NEAREST"));
639 mipmapNearestTests->addChild(createSamplerLodTests(testCtx, imageViewType, imageFormat, VK_SAMPLER_MIPMAP_MODE_NEAREST).release());
640 samplerMipmapTests->addChild(mipmapNearestTests.release());
642 // Mipmap mode: linear
643 if (isCompressedFormat(imageFormat) || (!isIntFormat(imageFormat) && !isUintFormat(imageFormat)))
645 MovePtr<tcu::TestCaseGroup> mipmapLinearTests(new tcu::TestCaseGroup(testCtx, "linear", "Uses VK_TEX_MIPMAP_MODE_LINEAR"));
646 mipmapLinearTests->addChild(createSamplerLodTests(testCtx, imageViewType, imageFormat, VK_SAMPLER_MIPMAP_MODE_LINEAR).release());
647 samplerMipmapTests->addChild(mipmapLinearTests.release());
650 return samplerMipmapTests;
653 std::string getAddressModesCaseName (VkSamplerAddressMode u, VkSamplerAddressMode v, VkSamplerAddressMode w, BorderColor border)
655 static const char* borderColorNames[BORDER_COLOR_COUNT] =
662 std::ostringstream caseName;
664 if (u == v && v == w)
666 const std::string fullName = getSamplerAddressModeName(u);
667 DE_ASSERT(de::beginsWith(fullName, "VK_SAMPLER_ADDRESS_"));
670 caseName << de::toLower(fullName.substr(19));
672 if (u == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)
674 caseName << "_" << borderColorNames[border];
679 const std::string fullNameU = getSamplerAddressModeName(u);
680 const std::string fullNameV = getSamplerAddressModeName(v);
681 const std::string fullNameW = getSamplerAddressModeName(w);
683 DE_ASSERT(de::beginsWith(fullNameU, "VK_SAMPLER_ADDRESS_"));
684 DE_ASSERT(de::beginsWith(fullNameV, "VK_SAMPLER_ADDRESS_"));
685 DE_ASSERT(de::beginsWith(fullNameW, "VK_SAMPLER_ADDRESS_"));
688 << "_" << de::toLower(fullNameU.substr(19))
689 << "_" << de::toLower(fullNameV.substr(19))
690 << "_" << de::toLower(fullNameW.substr(19));
693 return caseName.str();
696 MovePtr<tcu::TestCaseGroup> createSamplerAddressModesTests (tcu::TestContext& testCtx, VkImageViewType imageViewType, VkFormat imageFormat)
698 struct TestCaseConfig
700 VkSamplerAddressMode u;
701 VkSamplerAddressMode v;
702 VkSamplerAddressMode w;
706 const TestCaseConfig testCaseConfigs[] =
708 // All address modes equal
709 { VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, BORDER_COLOR_TRANSPARENT_BLACK },
710 { VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_REPEAT, BORDER_COLOR_TRANSPARENT_BLACK },
711 { VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, BORDER_COLOR_TRANSPARENT_BLACK },
712 { VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, BORDER_COLOR_TRANSPARENT_BLACK },
714 // All address modes equal using border color
715 { VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, BORDER_COLOR_TRANSPARENT_BLACK },
716 { VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, BORDER_COLOR_OPAQUE_BLACK },
717 { VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, BORDER_COLOR_OPAQUE_WHITE },
719 // Pairwise combinations of address modes not covered by previous tests
720 { VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_REPEAT, BORDER_COLOR_OPAQUE_WHITE},
721 { VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, BORDER_COLOR_OPAQUE_WHITE },
722 { VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, BORDER_COLOR_OPAQUE_WHITE },
723 { VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, BORDER_COLOR_OPAQUE_WHITE },
724 { VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, BORDER_COLOR_OPAQUE_WHITE },
725 { VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, BORDER_COLOR_OPAQUE_WHITE },
726 { VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, VK_SAMPLER_ADDRESS_MODE_REPEAT, BORDER_COLOR_OPAQUE_WHITE },
727 { VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, BORDER_COLOR_OPAQUE_WHITE },
728 { VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, BORDER_COLOR_OPAQUE_WHITE },
729 { VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, BORDER_COLOR_OPAQUE_WHITE },
730 { VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, BORDER_COLOR_OPAQUE_WHITE },
731 { VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, BORDER_COLOR_OPAQUE_WHITE },
732 { VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_REPEAT, BORDER_COLOR_OPAQUE_WHITE },
733 { VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, BORDER_COLOR_OPAQUE_WHITE },
734 { VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, BORDER_COLOR_OPAQUE_WHITE },
735 { VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, BORDER_COLOR_OPAQUE_WHITE },
736 { VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, BORDER_COLOR_OPAQUE_WHITE },
737 { VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, BORDER_COLOR_OPAQUE_WHITE },
738 { VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, VK_SAMPLER_ADDRESS_MODE_REPEAT, BORDER_COLOR_OPAQUE_WHITE },
739 { VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, BORDER_COLOR_OPAQUE_WHITE },
740 { VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, BORDER_COLOR_OPAQUE_WHITE },
741 { VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, BORDER_COLOR_OPAQUE_WHITE },
744 MovePtr<tcu::TestCaseGroup> samplerAddressModesTests (new tcu::TestCaseGroup(testCtx, "address_modes", "Tests for address modes"));
746 for (int configNdx = 0; configNdx < DE_LENGTH_OF_ARRAY(testCaseConfigs); configNdx++)
748 const TestCaseConfig& config = testCaseConfigs[configNdx];
750 samplerAddressModesTests->addChild(new SamplerAddressModesTest(testCtx,
751 getAddressModesCaseName(config.u, config.v, config.w, config.border).c_str(),
755 config.u, config.v, config.w,
756 getFormatBorderColor(config.border, imageFormat)));
759 return samplerAddressModesTests;
764 tcu::TestCaseGroup* createSamplerTests (tcu::TestContext& testCtx)
768 VkImageViewType type;
773 { VK_IMAGE_VIEW_TYPE_1D, "1d" },
774 { VK_IMAGE_VIEW_TYPE_1D_ARRAY, "1d_array" },
775 { VK_IMAGE_VIEW_TYPE_2D, "2d" },
776 { VK_IMAGE_VIEW_TYPE_2D_ARRAY, "2d_array" },
777 { VK_IMAGE_VIEW_TYPE_3D, "3d" },
778 { VK_IMAGE_VIEW_TYPE_CUBE, "cube" },
779 { VK_IMAGE_VIEW_TYPE_CUBE_ARRAY, "cube_array" }
782 const VkFormat formats[] =
785 VK_FORMAT_R4G4_UNORM_PACK8,
786 VK_FORMAT_R4G4B4A4_UNORM_PACK16,
787 VK_FORMAT_R5G6B5_UNORM_PACK16,
788 VK_FORMAT_R5G5B5A1_UNORM_PACK16,
789 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
790 VK_FORMAT_A2R10G10B10_UINT_PACK32,
791 VK_FORMAT_B10G11R11_UFLOAT_PACK32,
792 VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
793 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
794 VK_FORMAT_B5G5R5A1_UNORM_PACK16,
796 // Pairwise combinations of 8-bit channel formats, UNORM/SNORM/SINT/UINT/SRGB type x 1-to-4 channels x RGBA/BGRA order
798 VK_FORMAT_R8G8B8_UINT,
799 VK_FORMAT_B8G8R8A8_SINT,
800 VK_FORMAT_R8G8_UNORM,
801 VK_FORMAT_B8G8R8_SNORM,
802 VK_FORMAT_R8G8B8A8_SNORM,
805 VK_FORMAT_R8G8B8A8_SRGB,
806 VK_FORMAT_R8G8B8A8_UNORM,
807 VK_FORMAT_B8G8R8A8_UNORM,
808 VK_FORMAT_B8G8R8_SRGB,
811 VK_FORMAT_R8G8B8A8_UINT,
814 VK_FORMAT_B8G8R8_SINT,
815 VK_FORMAT_R8G8_SNORM,
816 VK_FORMAT_B8G8R8_UNORM,
819 // Pairwise combinations of 16/32-bit channel formats x SINT/UINT/SFLOAT type x 1-to-4 channels
820 VK_FORMAT_R32G32_SFLOAT,
821 VK_FORMAT_R32G32B32_UINT,
822 VK_FORMAT_R16G16B16A16_SFLOAT,
823 VK_FORMAT_R16G16_UINT,
824 VK_FORMAT_R32G32B32A32_SINT,
825 VK_FORMAT_R16G16B16_SINT,
826 VK_FORMAT_R16_SFLOAT,
829 VK_FORMAT_R16G16B16_SFLOAT,
830 VK_FORMAT_R16G16_SINT,
833 VK_FORMAT_R8G8B8A8_SSCALED,
834 VK_FORMAT_A2R10G10B10_USCALED_PACK32,
836 // Compressed formats
837 VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
838 VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
839 VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
840 VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
841 VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
842 VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
843 VK_FORMAT_EAC_R11_UNORM_BLOCK,
844 VK_FORMAT_EAC_R11_SNORM_BLOCK,
845 VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
846 VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
847 VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
848 VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
849 VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
850 VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
851 VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
852 VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
853 VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
854 VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
855 VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
856 VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
859 de::MovePtr<tcu::TestCaseGroup> samplerTests (new tcu::TestCaseGroup(testCtx, "sampler", "Sampler tests"));
860 de::MovePtr<tcu::TestCaseGroup> viewTypeTests (new tcu::TestCaseGroup(testCtx, "view_type", ""));
862 for (int viewTypeNdx = 0; viewTypeNdx < DE_LENGTH_OF_ARRAY(imageViewTypes); viewTypeNdx++)
864 const VkImageViewType viewType = imageViewTypes[viewTypeNdx].type;
865 de::MovePtr<tcu::TestCaseGroup> viewTypeGroup (new tcu::TestCaseGroup(testCtx, imageViewTypes[viewTypeNdx].name, (std::string("Uses a ") + imageViewTypes[viewTypeNdx].name + " view").c_str()));
866 de::MovePtr<tcu::TestCaseGroup> formatTests (new tcu::TestCaseGroup(testCtx, "format", "Tests samplable formats"));
868 for (size_t formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); formatNdx++)
870 const VkFormat format = formats[formatNdx];
871 const bool isCompressed = isCompressedFormat(format);
875 // Do not use compressed formats with 1D and 1D array textures.
876 if (viewType == VK_IMAGE_VIEW_TYPE_1D || viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY)
879 // 3D ASTC textures are not supported.
880 if (tcu::isAstcFormat(mapVkCompressedFormat(format)) && viewType == VK_IMAGE_VIEW_TYPE_3D)
884 de::MovePtr<tcu::TestCaseGroup> formatGroup (new tcu::TestCaseGroup(testCtx,
885 getFormatCaseName(format).c_str(),
886 (std::string("Samples a texture of format ") + getFormatName(format)).c_str()));
890 // Do not include minFilter tests with compressed formats.
891 // Randomly generated compressed textures are too noisy and will derive in false positives.
892 de::MovePtr<tcu::TestCaseGroup> minFilterTests = createSamplerMinFilterTests(testCtx, viewType, format);
893 formatGroup->addChild(minFilterTests.release());
896 de::MovePtr<tcu::TestCaseGroup> magFilterTests = createSamplerMagFilterTests(testCtx, viewType, format);
897 de::MovePtr<tcu::TestCaseGroup> mipmapTests = createSamplerMipmapTests(testCtx, viewType, format);
899 formatGroup->addChild(magFilterTests.release());
900 formatGroup->addChild(mipmapTests.release());
902 if (viewType != VK_IMAGE_VIEW_TYPE_CUBE && viewType != VK_IMAGE_VIEW_TYPE_CUBE_ARRAY)
904 de::MovePtr<tcu::TestCaseGroup> addressModesTests = createSamplerAddressModesTests(testCtx, viewType, format);
905 formatGroup->addChild(addressModesTests.release());
908 formatTests->addChild(formatGroup.release());
911 viewTypeGroup->addChild(formatTests.release());
912 viewTypeTests->addChild(viewTypeGroup.release());
915 samplerTests->addChild(viewTypeTests.release());
917 return samplerTests.release();