1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2016 The Khronos Group Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 * \file vktPipelineMultisampleTestsUtil.cpp
21 * \brief Multisample Tests Utility Classes
22 *//*--------------------------------------------------------------------*/
24 #include "vktPipelineMultisampleTestsUtil.hpp"
25 #include "vkQueryUtil.hpp"
26 #include "vkTypeUtil.hpp"
27 #include "tcuTextureUtil.hpp"
40 tcu::UVec3 getShaderGridSize (const ImageType imageType, const tcu::UVec3& imageSize, const deUint32 mipLevel)
42 const deUint32 mipLevelX = std::max(imageSize.x() >> mipLevel, 1u);
43 const deUint32 mipLevelY = std::max(imageSize.y() >> mipLevel, 1u);
44 const deUint32 mipLevelZ = std::max(imageSize.z() >> mipLevel, 1u);
49 return tcu::UVec3(mipLevelX, 1u, 1u);
51 case IMAGE_TYPE_BUFFER:
52 return tcu::UVec3(imageSize.x(), 1u, 1u);
54 case IMAGE_TYPE_1D_ARRAY:
55 return tcu::UVec3(mipLevelX, imageSize.z(), 1u);
58 return tcu::UVec3(mipLevelX, mipLevelY, 1u);
60 case IMAGE_TYPE_2D_ARRAY:
61 return tcu::UVec3(mipLevelX, mipLevelY, imageSize.z());
64 return tcu::UVec3(mipLevelX, mipLevelY, mipLevelZ);
67 return tcu::UVec3(mipLevelX, mipLevelY, 6u);
69 case IMAGE_TYPE_CUBE_ARRAY:
70 return tcu::UVec3(mipLevelX, mipLevelY, 6u * imageSize.z());
73 DE_FATAL("Unknown image type");
74 return tcu::UVec3(1u, 1u, 1u);
78 tcu::UVec3 getLayerSize (const ImageType imageType, const tcu::UVec3& imageSize)
83 case IMAGE_TYPE_1D_ARRAY:
84 case IMAGE_TYPE_BUFFER:
85 return tcu::UVec3(imageSize.x(), 1u, 1u);
88 case IMAGE_TYPE_2D_ARRAY:
90 case IMAGE_TYPE_CUBE_ARRAY:
91 return tcu::UVec3(imageSize.x(), imageSize.y(), 1u);
94 return tcu::UVec3(imageSize.x(), imageSize.y(), imageSize.z());
97 DE_FATAL("Unknown image type");
98 return tcu::UVec3(1u, 1u, 1u);
102 deUint32 getNumLayers (const ImageType imageType, const tcu::UVec3& imageSize)
109 case IMAGE_TYPE_BUFFER:
112 case IMAGE_TYPE_1D_ARRAY:
113 case IMAGE_TYPE_2D_ARRAY:
114 return imageSize.z();
116 case IMAGE_TYPE_CUBE:
119 case IMAGE_TYPE_CUBE_ARRAY:
120 return imageSize.z() * 6u;
123 DE_FATAL("Unknown image type");
128 deUint32 getNumPixels (const ImageType imageType, const tcu::UVec3& imageSize)
130 const tcu::UVec3 gridSize = getShaderGridSize(imageType, imageSize);
132 return gridSize.x() * gridSize.y() * gridSize.z();
135 deUint32 getDimensions (const ImageType imageType)
140 case IMAGE_TYPE_BUFFER:
143 case IMAGE_TYPE_1D_ARRAY:
147 case IMAGE_TYPE_2D_ARRAY:
148 case IMAGE_TYPE_CUBE:
149 case IMAGE_TYPE_CUBE_ARRAY:
154 DE_FATAL("Unknown image type");
159 deUint32 getLayerDimensions (const ImageType imageType)
164 case IMAGE_TYPE_BUFFER:
165 case IMAGE_TYPE_1D_ARRAY:
169 case IMAGE_TYPE_2D_ARRAY:
170 case IMAGE_TYPE_CUBE:
171 case IMAGE_TYPE_CUBE_ARRAY:
178 DE_FATAL("Unknown image type");
183 VkImageType mapImageType (const ImageType imageType)
188 case IMAGE_TYPE_1D_ARRAY:
189 case IMAGE_TYPE_BUFFER:
190 return VK_IMAGE_TYPE_1D;
193 case IMAGE_TYPE_2D_ARRAY:
194 case IMAGE_TYPE_CUBE:
195 case IMAGE_TYPE_CUBE_ARRAY:
196 return VK_IMAGE_TYPE_2D;
199 return VK_IMAGE_TYPE_3D;
203 return VK_IMAGE_TYPE_LAST;
207 VkImageViewType mapImageViewType (const ImageType imageType)
211 case IMAGE_TYPE_1D: return VK_IMAGE_VIEW_TYPE_1D;
212 case IMAGE_TYPE_1D_ARRAY: return VK_IMAGE_VIEW_TYPE_1D_ARRAY;
213 case IMAGE_TYPE_2D: return VK_IMAGE_VIEW_TYPE_2D;
214 case IMAGE_TYPE_2D_ARRAY: return VK_IMAGE_VIEW_TYPE_2D_ARRAY;
215 case IMAGE_TYPE_3D: return VK_IMAGE_VIEW_TYPE_3D;
216 case IMAGE_TYPE_CUBE: return VK_IMAGE_VIEW_TYPE_CUBE;
217 case IMAGE_TYPE_CUBE_ARRAY: return VK_IMAGE_VIEW_TYPE_CUBE_ARRAY;
221 return VK_IMAGE_VIEW_TYPE_LAST;
225 std::string getImageTypeName (const ImageType imageType)
229 case IMAGE_TYPE_1D: return "1d";
230 case IMAGE_TYPE_1D_ARRAY: return "1d_array";
231 case IMAGE_TYPE_2D: return "2d";
232 case IMAGE_TYPE_2D_ARRAY: return "2d_array";
233 case IMAGE_TYPE_3D: return "3d";
234 case IMAGE_TYPE_CUBE: return "cube";
235 case IMAGE_TYPE_CUBE_ARRAY: return "cube_array";
236 case IMAGE_TYPE_BUFFER: return "buffer";
244 std::string getShaderImageType (const tcu::TextureFormat& format, const ImageType imageType)
246 std::string formatPart = tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER ? "u" :
247 tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER ? "i" : "";
249 std::string imageTypePart;
252 case IMAGE_TYPE_1D: imageTypePart = "1D"; break;
253 case IMAGE_TYPE_1D_ARRAY: imageTypePart = "1DArray"; break;
254 case IMAGE_TYPE_2D: imageTypePart = "2D"; break;
255 case IMAGE_TYPE_2D_ARRAY: imageTypePart = "2DArray"; break;
256 case IMAGE_TYPE_3D: imageTypePart = "3D"; break;
257 case IMAGE_TYPE_CUBE: imageTypePart = "Cube"; break;
258 case IMAGE_TYPE_CUBE_ARRAY: imageTypePart = "CubeArray"; break;
259 case IMAGE_TYPE_BUFFER: imageTypePart = "Buffer"; break;
265 return formatPart + "image" + imageTypePart;
269 std::string getShaderImageDataType (const tcu::TextureFormat& format)
271 switch (tcu::getTextureChannelClass(format.type))
273 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
275 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
277 case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
285 std::string getShaderImageFormatQualifier (const tcu::TextureFormat& format)
287 const char* orderPart;
288 const char* typePart;
290 switch (format.order)
292 case tcu::TextureFormat::R: orderPart = "r"; break;
293 case tcu::TextureFormat::RG: orderPart = "rg"; break;
294 case tcu::TextureFormat::RGB: orderPart = "rgb"; break;
295 case tcu::TextureFormat::RGBA: orderPart = "rgba"; break;
304 case tcu::TextureFormat::FLOAT: typePart = "32f"; break;
305 case tcu::TextureFormat::HALF_FLOAT: typePart = "16f"; break;
307 case tcu::TextureFormat::UNSIGNED_INT32: typePart = "32ui"; break;
308 case tcu::TextureFormat::UNSIGNED_INT16: typePart = "16ui"; break;
309 case tcu::TextureFormat::UNSIGNED_INT8: typePart = "8ui"; break;
311 case tcu::TextureFormat::SIGNED_INT32: typePart = "32i"; break;
312 case tcu::TextureFormat::SIGNED_INT16: typePart = "16i"; break;
313 case tcu::TextureFormat::SIGNED_INT8: typePart = "8i"; break;
315 case tcu::TextureFormat::UNORM_INT16: typePart = "16"; break;
316 case tcu::TextureFormat::UNORM_INT8: typePart = "8"; break;
318 case tcu::TextureFormat::SNORM_INT16: typePart = "16_snorm"; break;
319 case tcu::TextureFormat::SNORM_INT8: typePart = "8_snorm"; break;
326 return std::string() + orderPart + typePart;
329 std::string getShaderImageCoordinates (const ImageType imageType,
330 const std::string& x,
331 const std::string& xy,
332 const std::string& xyz)
337 case IMAGE_TYPE_BUFFER:
340 case IMAGE_TYPE_1D_ARRAY:
344 case IMAGE_TYPE_2D_ARRAY:
346 case IMAGE_TYPE_CUBE:
347 case IMAGE_TYPE_CUBE_ARRAY:
356 VkExtent3D mipLevelExtents (const VkExtent3D& baseExtents, const deUint32 mipLevel)
360 result.width = std::max(baseExtents.width >> mipLevel, 1u);
361 result.height = std::max(baseExtents.height >> mipLevel, 1u);
362 result.depth = std::max(baseExtents.depth >> mipLevel, 1u);
367 deUint32 getImageMaxMipLevels (const VkImageFormatProperties& imageFormatProperties, const VkExtent3D& extent)
369 const deUint32 widestEdge = std::max(std::max(extent.width, extent.height), extent.depth);
371 return std::min(static_cast<deUint32>(deFloatLog2(static_cast<float>(widestEdge))) + 1u, imageFormatProperties.maxMipLevels);
374 deUint32 getImageMipLevelSizeInBytes (const VkExtent3D& baseExtents, const deUint32 layersCount, const tcu::TextureFormat& format, const deUint32 mipmapLevel)
376 const VkExtent3D extents = mipLevelExtents(baseExtents, mipmapLevel);
378 return extents.width * extents.height * extents.depth * layersCount * tcu::getPixelSize(format);
381 deUint32 getImageSizeInBytes (const VkExtent3D& baseExtents, const deUint32 layersCount, const tcu::TextureFormat& format, const deUint32 mipmapLevelsCount)
383 deUint32 imageSizeInBytes = 0;
384 for (deUint32 mipmapLevel = 0; mipmapLevel < mipmapLevelsCount; ++mipmapLevel)
386 imageSizeInBytes += getImageMipLevelSizeInBytes(baseExtents, layersCount, format, mipmapLevel);
389 return imageSizeInBytes;
392 void requireFeatures (const InstanceInterface& instanceInterface, const VkPhysicalDevice physicalDevice, const FeatureFlags flags)
394 const VkPhysicalDeviceFeatures features = getPhysicalDeviceFeatures(instanceInterface, physicalDevice);
396 if (((flags & FEATURE_TESSELLATION_SHADER) != 0) && !features.tessellationShader)
397 throw tcu::NotSupportedError("Tessellation shader not supported");
399 if (((flags & FEATURE_GEOMETRY_SHADER) != 0) && !features.geometryShader)
400 throw tcu::NotSupportedError("Geometry shader not supported");
402 if (((flags & FEATURE_SHADER_FLOAT_64) != 0) && !features.shaderFloat64)
403 throw tcu::NotSupportedError("Double-precision floats not supported");
405 if (((flags & FEATURE_VERTEX_PIPELINE_STORES_AND_ATOMICS) != 0) && !features.vertexPipelineStoresAndAtomics)
406 throw tcu::NotSupportedError("SSBO and image writes not supported in vertex pipeline");
408 if (((flags & FEATURE_FRAGMENT_STORES_AND_ATOMICS) != 0) && !features.fragmentStoresAndAtomics)
409 throw tcu::NotSupportedError("SSBO and image writes not supported in fragment shader");
411 if (((flags & FEATURE_SHADER_TESSELLATION_AND_GEOMETRY_POINT_SIZE) != 0) && !features.shaderTessellationAndGeometryPointSize)
412 throw tcu::NotSupportedError("Tessellation and geometry shaders don't support PointSize built-in");