1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2018 Google Inc.
6 * Copyright (c) 2018 The Khronos Group Inc.
7 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
8 * Copyright (c) 2014 The Android Open Source Project
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 Texture swizzle tests.
25 *//*--------------------------------------------------------------------*/
26
27 #include "vktTextureSwizzleTests.hpp"
28
29 #include "vkImageUtil.hpp"
30 #include "vktTestGroupUtil.hpp"
31 #include "vktTextureTestUtil.hpp"
32
33 namespace vkt
34 {
35 namespace texture
36 {
37 namespace
38 {
39
40 using namespace vk;
41 using namespace glu::TextureTestUtil;
42 using namespace texture::util;
43
44 using std::string;
45 using std::vector;
46 using tcu::TestLog;
47
isDefaultComponentMapping(VkComponentMapping mapping)48 bool isDefaultComponentMapping (VkComponentMapping mapping)
49 {
50 if ((mapping.r == VK_COMPONENT_SWIZZLE_R || mapping.r == VK_COMPONENT_SWIZZLE_IDENTITY) &&
51 (mapping.g == VK_COMPONENT_SWIZZLE_G || mapping.g == VK_COMPONENT_SWIZZLE_IDENTITY) &&
52 (mapping.b == VK_COMPONENT_SWIZZLE_B || mapping.b == VK_COMPONENT_SWIZZLE_IDENTITY) &&
53 (mapping.a == VK_COMPONENT_SWIZZLE_A || mapping.a == VK_COMPONENT_SWIZZLE_IDENTITY))
54 return true;
55 else
56 return false;
57 }
58
59 template <typename INSTANCE_TYPE>
60 class SwizzleTestCase : public TextureTestCase<INSTANCE_TYPE>
61 {
62 public:
SwizzleTestCase(tcu::TestContext & context,const std::string & name,const std::string & description,const typename INSTANCE_TYPE::ParameterType & testParameters)63 SwizzleTestCase (tcu::TestContext& context, const std::string& name, const std::string& description, const typename INSTANCE_TYPE::ParameterType& testParameters)
64 : TextureTestCase<INSTANCE_TYPE> (context, name, description, testParameters)
65 {}
66
initPrograms(vk::SourceCollections & programCollection) const67 virtual void initPrograms (vk::SourceCollections& programCollection) const
68 {
69 initializePrograms(programCollection,
70 this->m_testsParameters.texCoordPrecision,
71 this->m_testsParameters.programs,
72 this->m_testsParameters.texCoordSwizzle);
73 }
74 };
75
76 struct Swizzle2DTestParameters : public Texture2DTestCaseParameters
77 {
78 Swizzle2DTestParameters (void);
79 TextureBinding::ImageBackingMode backingMode;
80 vk::VkComponentMapping componentMapping;
81 const char* texCoordSwizzle;
82 const deUint8* texCoordMapping;
83 };
84
Swizzle2DTestParameters(void)85 Swizzle2DTestParameters::Swizzle2DTestParameters (void)
86 : backingMode (TextureBinding::IMAGE_BACKING_MODE_LAST)
87 , componentMapping (makeComponentMappingRGBA())
88 , texCoordSwizzle (DE_NULL)
89 , texCoordMapping (DE_NULL)
90 {
91 }
92
93 class Swizzle2DTestInstance : public TestInstance
94 {
95 public:
96 typedef Swizzle2DTestParameters ParameterType;
97
98 Swizzle2DTestInstance (Context& context,
99 const ParameterType& testParameters);
100 tcu::TestStatus iterate (void);
101
102 private:
103 Swizzle2DTestInstance (const Swizzle2DTestInstance& other);
104 Swizzle2DTestInstance& operator= (const Swizzle2DTestInstance& other);
105
106 const ParameterType& m_testParameters;
107 const tcu::TextureFormat m_format;
108 const tcu::CompressedTexFormat m_compressedFormat;
109 TestTexture2DSp m_texture;
110 TextureRenderer m_renderer;
111 };
112
Swizzle2DTestInstance(Context & context,const ParameterType & testParameters)113 Swizzle2DTestInstance::Swizzle2DTestInstance (Context& context,
114 const ParameterType& testParameters)
115 : TestInstance (context)
116 , m_testParameters (testParameters)
117 , m_format (isCompressedFormat(m_testParameters.format)
118 ? tcu::TextureFormat() // Unused
119 : mapVkFormat(testParameters.format))
120 , m_compressedFormat (isCompressedFormat(m_testParameters.format)
121 ? mapVkCompressedFormat(testParameters.format)
122 : tcu::CompressedTexFormat()) // Unused
123 , m_texture (TestTexture2DSp(isCompressedFormat(m_testParameters.format)
124 ? new pipeline::TestTexture2D(m_compressedFormat, testParameters.width, testParameters.height)
125 : new pipeline::TestTexture2D(m_format, testParameters.width, testParameters.height)))
126 , m_renderer (context, testParameters.sampleCount, testParameters.width, testParameters.height, testParameters.componentMapping)
127 {
128 m_renderer.add2DTexture(m_texture, testParameters.aspectMask, testParameters.backingMode);
129 }
130
iterate(void)131 tcu::TestStatus Swizzle2DTestInstance::iterate (void)
132 {
133 tcu::TestLog& log = m_context.getTestContext().getLog();
134 const pipeline::TestTexture2D& texture = m_renderer.get2DTexture(0);
135 const tcu::TextureFormat textureFormat = texture.getTextureFormat();
136 const float lookupScale = tcu::getTextureFormatInfo(textureFormat).lookupScale[0];
137 const float lookupBias = tcu::getTextureFormatInfo(textureFormat).lookupBias[0];
138
139 ReferenceParams sampleParams (TEXTURETYPE_2D);
140 tcu::Surface rendered (m_renderer.getRenderWidth(), m_renderer.getRenderHeight());
141 vector<float> texCoord;
142
143 // Params for reference
144 sampleParams.sampler = util::createSampler(m_testParameters.wrapS, m_testParameters.wrapT, m_testParameters.minFilter, m_testParameters.magFilter);
145 sampleParams.samplerType = isCompressedFormat(m_testParameters.format) ? SAMPLERTYPE_FLOAT : getSamplerType(m_format);
146 sampleParams.lodMode = LODMODE_EXACT;
147 sampleParams.colorBias = tcu::Vec4(lookupBias);
148 sampleParams.colorScale = tcu::Vec4(lookupScale);
149
150 if (sampleParams.colorBias != tcu::Vec4(0.0f))
151 sampleParams.flags = RenderParams::USE_BIAS;
152
153 log << TestLog::Message << "Compare reference value = " << sampleParams.ref << TestLog::EndMessage;
154 log << TestLog::Message << "Lookup scale = " << lookupScale << TestLog::EndMessage;
155 log << TestLog::Message << "Lookup bias = " << lookupBias << TestLog::EndMessage;
156
157 computeQuadTexCoord2D(texCoord, tcu::Vec2(0.0f, 0.0f), tcu::Vec2(1.0f, 1.0f));
158 m_renderer.renderQuad(rendered, 0, &texCoord[0], sampleParams);
159
160 const tcu::IVec4 formatBitDepth = getTextureFormatBitDepth(vk::mapVkFormat(VK_FORMAT_R8G8B8A8_UNORM));
161 const tcu::PixelFormat pixelFormat (formatBitDepth[0], formatBitDepth[1], formatBitDepth[2], formatBitDepth[3]);
162 tcu::Surface referenceFrame (m_renderer.getRenderWidth(), m_renderer.getRenderHeight());
163
164 // Render reference (based on sampleTextureNonProjected in gluTextureTestUtil.cpp)
165 {
166 std::vector<tcu::ConstPixelBufferAccess> storage;
167 const tcu::Texture2DView src = getEffectiveTextureView(m_texture->getTexture(), storage, sampleParams.sampler);
168 const tcu::SurfaceAccess dst = tcu::SurfaceAccess(referenceFrame, pixelFormat);
169
170 const tcu::IVec2 dstSize = tcu::IVec2(dst.getWidth(), dst.getHeight());
171 const tcu::IVec2 srcSize = tcu::IVec2(src.getWidth(), src.getHeight());
172
173 const float lodBias = (sampleParams.flags & ReferenceParams::USE_BIAS) ? sampleParams.bias : 0.0f;
174 const tcu::Vec4 sq = tcu::Vec4(texCoord[0+0], texCoord[2+0], texCoord[4+0], texCoord[6+0]);
175 const tcu::Vec4 tq = tcu::Vec4(texCoord[0+1], texCoord[2+1], texCoord[4+1], texCoord[6+1]);
176
177 tcu::Vec3 tri[2][2] =
178 {
179 { sq.swizzle(0, 1, 2), sq.swizzle(3, 2, 1) },
180 { tq.swizzle(0, 1, 2), tq.swizzle(3, 2, 1) }
181 };
182
183 // Swizzle texture coordinates
184 if (m_testParameters.texCoordMapping)
185 {
186 const tcu::Vec3 swz[2][2] =
187 {
188 { tri[m_testParameters.texCoordMapping[0]][0], tri[m_testParameters.texCoordMapping[0]][1] },
189 { tri[m_testParameters.texCoordMapping[1]][0], tri[m_testParameters.texCoordMapping[1]][1] }
190 };
191
192 memcpy(tri, swz, sizeof(tri));
193 }
194
195 // Coordinates and lod per triangle
196 const tcu::Vec3 triS[2] = { tri[0][0], tri[0][1] };
197 const tcu::Vec3 triT[2] = { tri[1][0], tri[1][1] };
198 const float triLod[2] = { de::clamp(computeNonProjectedTriLod(sampleParams.lodMode, dstSize, srcSize, triS[0], triT[0]) + lodBias, sampleParams.minLod, sampleParams.maxLod),
199 de::clamp(computeNonProjectedTriLod(sampleParams.lodMode, dstSize, srcSize, triS[1], triT[1]) + lodBias, sampleParams.minLod, sampleParams.maxLod) };
200
201 for (int y = 0; y < dstSize.y(); y++)
202 for (int x = 0; x < dstSize.x(); x++)
203 {
204 const float yf = ((float)y + 0.5f) / (float)dstSize.y();
205 const float xf = ((float)x + 0.5f) / (float)dstSize.x();
206
207 const int triNdx = xf + yf >= 1.0f ? 1 : 0; // Top left fill rule
208 const float triX = triNdx ? 1.0f-xf : xf;
209 const float triY = triNdx ? 1.0f-yf : yf;
210
211 const float s = triangleInterpolate(triS[triNdx].x(), triS[triNdx].y(), triS[triNdx].z(), triX, triY);
212 const float t = triangleInterpolate(triT[triNdx].x(), triT[triNdx].y(), triT[triNdx].z(), triX, triY);
213 const float lod = triLod[triNdx];
214
215 dst.setPixel(src.sample(sampleParams.sampler, s, t, lod) * sampleParams.colorScale + sampleParams.colorBias, x, y);
216 }
217 }
218
219 // Reference component mapping swizzle
220 if (!isDefaultComponentMapping(m_testParameters.componentMapping))
221 {
222 tcu::Surface swzSurface = referenceFrame;
223 const tcu::IVec4 bitDepth = getTextureFormatBitDepth(isCompressedFormat(m_testParameters.format)
224 ? getUncompressedFormat(m_compressedFormat)
225 : m_format);
226 const deUint8 one = deUint8(255.0f * (lookupScale + lookupBias));
227 const deUint8 zero = deUint8(255.0f * lookupBias);
228
229 const VkComponentSwizzle swizzle[] =
230 {
231 m_testParameters.componentMapping.r,
232 m_testParameters.componentMapping.g,
233 m_testParameters.componentMapping.b,
234 m_testParameters.componentMapping.a
235 };
236
237 log << TestLog::Message << "Format bit depth = " << bitDepth << TestLog::EndMessage;
238 log << TestLog::Message << "One = " << int(one) << TestLog::EndMessage;
239 log << TestLog::Message << "Zero = " << int(zero) << TestLog::EndMessage;
240
241 for (int y = 0; y < m_testParameters.height; y++)
242 for (int x = 0; x < m_testParameters.width; x++)
243 {
244 const tcu::RGBA original = referenceFrame.getPixel(x, y);
245 tcu::IVec4 swizzled = original.toIVec();
246
247 for (int ndx = 0; ndx < 4; ndx++)
248 {
249 switch (swizzle[ndx])
250 {
251 case VK_COMPONENT_SWIZZLE_ZERO:
252 swizzled[ndx] = zero;
253 break;
254 case VK_COMPONENT_SWIZZLE_ONE:
255 swizzled[ndx] = one;
256 break;
257 case VK_COMPONENT_SWIZZLE_R:
258 swizzled[ndx] = bitDepth[0] ? original.getRed() : zero;
259 break;
260 case VK_COMPONENT_SWIZZLE_G:
261 swizzled[ndx] = bitDepth[1] ? original.getGreen() : zero;
262 break;
263 case VK_COMPONENT_SWIZZLE_B:
264 swizzled[ndx] = bitDepth[2] ? original.getBlue() : zero;
265 break;
266 case VK_COMPONENT_SWIZZLE_A:
267 swizzled[ndx] = bitDepth[3] ? original.getAlpha() : one;
268 break;
269 default:
270 DE_ASSERT(swizzle[ndx] == VK_COMPONENT_SWIZZLE_IDENTITY);
271 }
272 }
273
274 swzSurface.setPixel(x, y, tcu::RGBA(swizzled.x(), swizzled.y(), swizzled.z(), swizzled.w()));
275 }
276
277 referenceFrame = swzSurface;
278 }
279
280 // Compare and log
281 const tcu::RGBA threshold = pixelFormat.getColorThreshold() + tcu::RGBA(2, 2, 2, 2);
282 const bool isOk = compareImages(log, referenceFrame, rendered, threshold);
283
284 return isOk ? tcu::TestStatus::pass("Pass") : tcu::TestStatus::fail("Image verification failed");
285 }
286
287 } // anonymous
288
populateTextureSwizzleTests(tcu::TestCaseGroup * textureSwizzleTests)289 void populateTextureSwizzleTests (tcu::TestCaseGroup* textureSwizzleTests)
290 {
291 tcu::TestContext& testCtx = textureSwizzleTests->getTestContext();
292
293 static const struct{
294 const VkFormat format;
295 const Program program;
296 } formats2D[] =
297 {
298 { VK_FORMAT_R4G4_UNORM_PACK8, PROGRAM_2D_FLOAT },
299 { VK_FORMAT_R4G4B4A4_UNORM_PACK16, PROGRAM_2D_FLOAT },
300 { VK_FORMAT_R5G6B5_UNORM_PACK16, PROGRAM_2D_FLOAT },
301 { VK_FORMAT_R5G5B5A1_UNORM_PACK16, PROGRAM_2D_FLOAT },
302 { VK_FORMAT_R8_UNORM, PROGRAM_2D_FLOAT },
303 { VK_FORMAT_R8_SNORM, PROGRAM_2D_FLOAT_BIAS },
304 { VK_FORMAT_R8_USCALED, PROGRAM_2D_UINT },
305 { VK_FORMAT_R8_SSCALED, PROGRAM_2D_INT_BIAS },
306 { VK_FORMAT_R8_UINT, PROGRAM_2D_UINT },
307 { VK_FORMAT_R8_SINT, PROGRAM_2D_INT_BIAS },
308 { VK_FORMAT_R8_SRGB, PROGRAM_2D_FLOAT },
309 { VK_FORMAT_R8G8_UNORM, PROGRAM_2D_FLOAT },
310 { VK_FORMAT_R8G8_SNORM, PROGRAM_2D_FLOAT_BIAS },
311 { VK_FORMAT_R8G8_USCALED, PROGRAM_2D_UINT },
312 { VK_FORMAT_R8G8_SSCALED, PROGRAM_2D_INT_BIAS },
313 { VK_FORMAT_R8G8_UINT, PROGRAM_2D_UINT },
314 { VK_FORMAT_R8G8_SINT, PROGRAM_2D_INT_BIAS },
315 { VK_FORMAT_R8G8_SRGB, PROGRAM_2D_FLOAT },
316 { VK_FORMAT_R8G8B8_UNORM, PROGRAM_2D_FLOAT },
317 { VK_FORMAT_R8G8B8_SNORM, PROGRAM_2D_FLOAT_BIAS },
318 { VK_FORMAT_R8G8B8_USCALED, PROGRAM_2D_UINT },
319 { VK_FORMAT_R8G8B8_SSCALED, PROGRAM_2D_INT_BIAS },
320 { VK_FORMAT_R8G8B8_UINT, PROGRAM_2D_UINT },
321 { VK_FORMAT_R8G8B8_SINT, PROGRAM_2D_INT_BIAS },
322 { VK_FORMAT_R8G8B8_SRGB, PROGRAM_2D_FLOAT },
323 { VK_FORMAT_R8G8B8A8_UNORM, PROGRAM_2D_FLOAT },
324 { VK_FORMAT_R8G8B8A8_SNORM, PROGRAM_2D_FLOAT_BIAS },
325 { VK_FORMAT_R8G8B8A8_USCALED, PROGRAM_2D_UINT },
326 { VK_FORMAT_R8G8B8A8_SSCALED, PROGRAM_2D_INT_BIAS },
327 { VK_FORMAT_R8G8B8A8_UINT, PROGRAM_2D_UINT },
328 { VK_FORMAT_R8G8B8A8_SINT, PROGRAM_2D_INT_BIAS },
329 { VK_FORMAT_R8G8B8A8_SRGB, PROGRAM_2D_FLOAT },
330 { VK_FORMAT_A2R10G10B10_UNORM_PACK32, PROGRAM_2D_FLOAT },
331 { VK_FORMAT_A2R10G10B10_UINT_PACK32, PROGRAM_2D_UINT },
332 { VK_FORMAT_A2B10G10R10_USCALED_PACK32, PROGRAM_2D_UINT },
333 { VK_FORMAT_R16_UNORM, PROGRAM_2D_FLOAT },
334 { VK_FORMAT_R16_SNORM, PROGRAM_2D_FLOAT_BIAS },
335 { VK_FORMAT_R16_USCALED, PROGRAM_2D_UINT },
336 { VK_FORMAT_R16_SSCALED, PROGRAM_2D_INT_BIAS },
337 { VK_FORMAT_R16_UINT, PROGRAM_2D_UINT },
338 { VK_FORMAT_R16_SINT, PROGRAM_2D_INT_BIAS },
339 { VK_FORMAT_R16_SFLOAT, PROGRAM_2D_FLOAT_BIAS },
340 { VK_FORMAT_R16G16_UNORM, PROGRAM_2D_FLOAT },
341 { VK_FORMAT_R16G16_SNORM, PROGRAM_2D_FLOAT_BIAS },
342 { VK_FORMAT_R16G16_USCALED, PROGRAM_2D_UINT },
343 { VK_FORMAT_R16G16_SSCALED, PROGRAM_2D_INT_BIAS },
344 { VK_FORMAT_R16G16_UINT, PROGRAM_2D_UINT },
345 { VK_FORMAT_R16G16_SINT, PROGRAM_2D_INT_BIAS },
346 { VK_FORMAT_R16G16_SFLOAT, PROGRAM_2D_FLOAT_BIAS },
347 { VK_FORMAT_R16G16B16_UNORM, PROGRAM_2D_FLOAT },
348 { VK_FORMAT_R16G16B16_SNORM, PROGRAM_2D_FLOAT_BIAS },
349 { VK_FORMAT_R16G16B16_USCALED, PROGRAM_2D_UINT },
350 { VK_FORMAT_R16G16B16_SSCALED, PROGRAM_2D_INT_BIAS },
351 { VK_FORMAT_R16G16B16_UINT, PROGRAM_2D_UINT },
352 { VK_FORMAT_R16G16B16_SINT, PROGRAM_2D_INT_BIAS },
353 { VK_FORMAT_R16G16B16_SFLOAT, PROGRAM_2D_FLOAT_BIAS },
354 { VK_FORMAT_R16G16B16A16_UNORM, PROGRAM_2D_FLOAT },
355 { VK_FORMAT_R16G16B16A16_SNORM, PROGRAM_2D_FLOAT_BIAS },
356 { VK_FORMAT_R16G16B16A16_USCALED, PROGRAM_2D_UINT },
357 { VK_FORMAT_R16G16B16A16_SSCALED, PROGRAM_2D_INT_BIAS },
358 { VK_FORMAT_R16G16B16A16_UINT, PROGRAM_2D_UINT },
359 { VK_FORMAT_R16G16B16A16_SINT, PROGRAM_2D_INT_BIAS },
360 { VK_FORMAT_R16G16B16A16_SFLOAT, PROGRAM_2D_FLOAT_BIAS },
361 { VK_FORMAT_R32_UINT, PROGRAM_2D_UINT },
362 { VK_FORMAT_R32_SINT, PROGRAM_2D_INT_BIAS },
363 { VK_FORMAT_R32_SFLOAT, PROGRAM_2D_FLOAT_BIAS },
364 { VK_FORMAT_R32G32_UINT, PROGRAM_2D_UINT },
365 { VK_FORMAT_R32G32_SINT, PROGRAM_2D_INT_BIAS },
366 { VK_FORMAT_R32G32_SFLOAT, PROGRAM_2D_FLOAT_BIAS },
367 { VK_FORMAT_R32G32B32_UINT, PROGRAM_2D_UINT },
368 { VK_FORMAT_R32G32B32_SINT, PROGRAM_2D_INT_BIAS },
369 { VK_FORMAT_R32G32B32_SFLOAT, PROGRAM_2D_FLOAT_BIAS },
370 { VK_FORMAT_R32G32B32A32_UINT, PROGRAM_2D_UINT },
371 { VK_FORMAT_R32G32B32A32_SINT, PROGRAM_2D_INT_BIAS },
372 { VK_FORMAT_R32G32B32A32_SFLOAT, PROGRAM_2D_FLOAT_BIAS },
373 { VK_FORMAT_B10G11R11_UFLOAT_PACK32, PROGRAM_2D_FLOAT },
374 { VK_FORMAT_E5B9G9R9_UFLOAT_PACK32, PROGRAM_2D_FLOAT },
375 { VK_FORMAT_B4G4R4A4_UNORM_PACK16, PROGRAM_2D_FLOAT },
376 { VK_FORMAT_B5G5R5A1_UNORM_PACK16, PROGRAM_2D_FLOAT },
377 { VK_FORMAT_A4R4G4B4_UNORM_PACK16_EXT, PROGRAM_2D_FLOAT },
378 { VK_FORMAT_A4B4G4R4_UNORM_PACK16_EXT, PROGRAM_2D_FLOAT },
379
380 // Compressed formats
381 { VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, PROGRAM_2D_FLOAT },
382 { VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK, PROGRAM_2D_FLOAT },
383 { VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK, PROGRAM_2D_FLOAT },
384 { VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK, PROGRAM_2D_FLOAT },
385 { VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, PROGRAM_2D_FLOAT },
386 { VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK, PROGRAM_2D_FLOAT },
387 { VK_FORMAT_EAC_R11_UNORM_BLOCK, PROGRAM_2D_FLOAT },
388 { VK_FORMAT_EAC_R11_SNORM_BLOCK, PROGRAM_2D_FLOAT_BIAS },
389 { VK_FORMAT_EAC_R11G11_UNORM_BLOCK, PROGRAM_2D_FLOAT },
390 { VK_FORMAT_EAC_R11G11_SNORM_BLOCK, PROGRAM_2D_FLOAT_BIAS },
391 { VK_FORMAT_ASTC_4x4_UNORM_BLOCK, PROGRAM_2D_FLOAT_BIAS },
392 { VK_FORMAT_ASTC_4x4_SRGB_BLOCK, PROGRAM_2D_FLOAT },
393 { VK_FORMAT_ASTC_5x4_UNORM_BLOCK, PROGRAM_2D_FLOAT_BIAS },
394 { VK_FORMAT_ASTC_5x4_SRGB_BLOCK, PROGRAM_2D_FLOAT },
395 { VK_FORMAT_ASTC_5x5_UNORM_BLOCK, PROGRAM_2D_FLOAT_BIAS },
396 { VK_FORMAT_ASTC_5x5_SRGB_BLOCK, PROGRAM_2D_FLOAT },
397 { VK_FORMAT_ASTC_6x5_UNORM_BLOCK, PROGRAM_2D_FLOAT_BIAS },
398 { VK_FORMAT_ASTC_6x5_SRGB_BLOCK, PROGRAM_2D_FLOAT },
399 { VK_FORMAT_ASTC_6x6_UNORM_BLOCK, PROGRAM_2D_FLOAT_BIAS },
400 { VK_FORMAT_ASTC_6x6_SRGB_BLOCK, PROGRAM_2D_FLOAT },
401 { VK_FORMAT_ASTC_8x5_UNORM_BLOCK, PROGRAM_2D_FLOAT_BIAS },
402 { VK_FORMAT_ASTC_8x5_SRGB_BLOCK, PROGRAM_2D_FLOAT },
403 { VK_FORMAT_ASTC_8x6_UNORM_BLOCK, PROGRAM_2D_FLOAT_BIAS },
404 { VK_FORMAT_ASTC_8x6_SRGB_BLOCK, PROGRAM_2D_FLOAT },
405 { VK_FORMAT_ASTC_8x8_UNORM_BLOCK, PROGRAM_2D_FLOAT_BIAS },
406 { VK_FORMAT_ASTC_8x8_SRGB_BLOCK, PROGRAM_2D_FLOAT },
407 { VK_FORMAT_ASTC_10x5_UNORM_BLOCK, PROGRAM_2D_FLOAT_BIAS },
408 { VK_FORMAT_ASTC_10x5_SRGB_BLOCK, PROGRAM_2D_FLOAT },
409 { VK_FORMAT_ASTC_10x6_UNORM_BLOCK, PROGRAM_2D_FLOAT_BIAS },
410 { VK_FORMAT_ASTC_10x6_SRGB_BLOCK, PROGRAM_2D_FLOAT },
411 { VK_FORMAT_ASTC_10x8_UNORM_BLOCK, PROGRAM_2D_FLOAT_BIAS },
412 { VK_FORMAT_ASTC_10x8_SRGB_BLOCK, PROGRAM_2D_FLOAT },
413 { VK_FORMAT_ASTC_10x10_UNORM_BLOCK, PROGRAM_2D_FLOAT_BIAS },
414 { VK_FORMAT_ASTC_10x10_SRGB_BLOCK, PROGRAM_2D_FLOAT },
415 { VK_FORMAT_ASTC_12x10_UNORM_BLOCK, PROGRAM_2D_FLOAT_BIAS },
416 { VK_FORMAT_ASTC_12x10_SRGB_BLOCK, PROGRAM_2D_FLOAT },
417 { VK_FORMAT_ASTC_12x12_UNORM_BLOCK, PROGRAM_2D_FLOAT_BIAS },
418 { VK_FORMAT_ASTC_12x12_SRGB_BLOCK, PROGRAM_2D_FLOAT }
419 };
420
421 static const struct {
422 const char* name;
423 const deUint32 width;
424 const deUint32 height;
425 } sizes2D[] =
426 {
427 { "pot", 128, 64, },
428 { "npot", 51, 65 },
429 };
430
431 static const struct {
432 const char* name;
433 const TextureBinding::ImageBackingMode backingMode;
434 } backingModes[] =
435 {
436 { "", TextureBinding::IMAGE_BACKING_MODE_REGULAR },
437 #ifndef CTS_USES_VULKANSC
438 { "_sparse", TextureBinding::IMAGE_BACKING_MODE_SPARSE }
439 #endif // CTS_USES_VULKANSC
440 };
441
442 static const struct {
443 const char* name;
444 const VkComponentMapping componentMapping;
445 } componentMappings[] =
446 {
447 { "zzzz", {VK_COMPONENT_SWIZZLE_ZERO, VK_COMPONENT_SWIZZLE_ZERO, VK_COMPONENT_SWIZZLE_ZERO, VK_COMPONENT_SWIZZLE_ZERO} },
448 { "oooo", {VK_COMPONENT_SWIZZLE_ONE, VK_COMPONENT_SWIZZLE_ONE, VK_COMPONENT_SWIZZLE_ONE, VK_COMPONENT_SWIZZLE_ONE} },
449 { "rrrr", {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_R} },
450 { "gggg", {VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_G} },
451 { "bbbb", {VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_B} },
452 { "aaaa", {VK_COMPONENT_SWIZZLE_A, VK_COMPONENT_SWIZZLE_A, VK_COMPONENT_SWIZZLE_A, VK_COMPONENT_SWIZZLE_A} },
453 { "rgba", {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A} },
454 { "iiii", {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY} },
455 { "abgr", {VK_COMPONENT_SWIZZLE_A, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_R} },
456 };
457
458 static const struct {
459 const char* swizzle;
460 const deUint8 mapping[2];
461 } texCoordSwizzles2d[] =
462 {
463 { "yx", { 1, 0 } },
464 { "xx", { 0, 0 } },
465 { "yy", { 1, 1 } }
466 };
467
468 de::MovePtr<tcu::TestCaseGroup> groupCompMap (new tcu::TestCaseGroup(testCtx, "component_mapping", "Component mapping swizzles"));
469 de::MovePtr<tcu::TestCaseGroup> groupTexCoord (new tcu::TestCaseGroup(testCtx, "texture_coordinate", "Texture coordinate swizzles"));
470
471 // 2D Component mapping swizzles
472 for (int sizeNdx = 0; sizeNdx < DE_LENGTH_OF_ARRAY(sizes2D); sizeNdx++)
473 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats2D); formatNdx++)
474 for (int backingNdx = 0; backingNdx < DE_LENGTH_OF_ARRAY(backingModes); backingNdx++)
475 for (int mappingNdx = 0; mappingNdx < DE_LENGTH_OF_ARRAY(componentMappings); mappingNdx++)
476 {
477 const string formatStr = de::toString(getFormatStr(formats2D[formatNdx].format));
478 const string caseDesc = formatStr + ", TEXTURETYPE_2D";
479 const string caseName = de::toLower(formatStr.substr(10)) + "_2d"
480 + "_" + sizes2D[sizeNdx].name
481 + backingModes[backingNdx].name
482 + "_" + componentMappings[mappingNdx].name;
483
484 Swizzle2DTestParameters testParameters;
485 testParameters.format = formats2D[formatNdx].format;
486 testParameters.backingMode = backingModes[backingNdx].backingMode;
487 testParameters.componentMapping = componentMappings[mappingNdx].componentMapping;
488 testParameters.width = sizes2D[sizeNdx].width;
489 testParameters.height = sizes2D[sizeNdx].height;
490 testParameters.minFilter = tcu::Sampler::NEAREST;
491 testParameters.magFilter = tcu::Sampler::NEAREST;
492 testParameters.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
493 testParameters.programs.push_back(formats2D[formatNdx].program);
494
495 groupCompMap->addChild(new SwizzleTestCase<Swizzle2DTestInstance>(testCtx, caseName.c_str(), caseDesc.c_str(), testParameters));
496 }
497
498 // 2D Texture coordinate swizzles
499 for (int sizeNdx = 0; sizeNdx < DE_LENGTH_OF_ARRAY(sizes2D); sizeNdx++)
500 for (int formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats2D); formatNdx++)
501 for (int backingNdx = 0; backingNdx < DE_LENGTH_OF_ARRAY(backingModes); backingNdx++)
502 for (int swizzleNdx = 0; swizzleNdx < DE_LENGTH_OF_ARRAY(texCoordSwizzles2d); swizzleNdx++)
503 {
504 const string formatStr = de::toString(getFormatStr(formats2D[formatNdx].format));
505 const string caseDesc = formatStr + ", TEXTURETYPE_2D";
506 const string caseName = de::toLower(formatStr.substr(10)) + "_2d"
507 + "_" + sizes2D[sizeNdx].name
508 + backingModes[backingNdx].name
509 + "_" + texCoordSwizzles2d[swizzleNdx].swizzle;
510
511 Swizzle2DTestParameters testParameters;
512 testParameters.format = formats2D[formatNdx].format;
513 testParameters.backingMode = backingModes[backingNdx].backingMode;
514 testParameters.componentMapping = makeComponentMappingRGBA();
515 testParameters.texCoordSwizzle = texCoordSwizzles2d[swizzleNdx].swizzle;
516 testParameters.texCoordMapping = texCoordSwizzles2d[swizzleNdx].mapping;
517 testParameters.width = sizes2D[sizeNdx].width;
518 testParameters.height = sizes2D[sizeNdx].height;
519 testParameters.minFilter = tcu::Sampler::NEAREST;
520 testParameters.magFilter = tcu::Sampler::NEAREST;
521 testParameters.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
522 testParameters.programs.push_back(formats2D[formatNdx].program);
523
524 groupTexCoord->addChild(new SwizzleTestCase<Swizzle2DTestInstance>(testCtx, caseName.c_str(), caseDesc.c_str(), testParameters));
525 }
526
527 textureSwizzleTests->addChild(groupCompMap.release());
528 textureSwizzleTests->addChild(groupTexCoord.release());
529 }
530
createTextureSwizzleTests(tcu::TestContext & testCtx)531 tcu::TestCaseGroup* createTextureSwizzleTests (tcu::TestContext& testCtx)
532 {
533 return createTestGroup(testCtx, "swizzle", "Texture swizzle tests.", populateTextureSwizzleTests);
534 }
535
536 } // texture
537 } // vkt
538