1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2016 The Khronos Group Inc.
6 * Copyright (c) 2016 The Android Open Source Project
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 * \brief Image load/store utilities
23 *//*--------------------------------------------------------------------*/
26 #include "tcuTextureUtil.hpp"
27 #include "vktImageLoadStoreUtil.hpp"
28 #include "vkQueryUtil.hpp"
37 float computeStoreColorScale (const vk::VkFormat format, const tcu::IVec3 imageSize)
39 const int maxImageDimension = de::max(imageSize.x(), de::max(imageSize.y(), imageSize.z()));
40 const float div = static_cast<float>(maxImageDimension - 1);
42 if (isUnormFormat(format))
44 else if (isSnormFormat(format))
50 ImageType getImageTypeForSingleLayer (const ImageType imageType)
55 case IMAGE_TYPE_1D_ARRAY:
59 case IMAGE_TYPE_2D_ARRAY:
61 case IMAGE_TYPE_CUBE_ARRAY:
62 // A single layer for cube is a 2d face
68 case IMAGE_TYPE_BUFFER:
69 return IMAGE_TYPE_BUFFER;
72 DE_FATAL("Internal test error");
73 return IMAGE_TYPE_LAST;
77 VkImageCreateInfo makeImageCreateInfo (const Texture& texture, const VkFormat format, const VkImageUsageFlags usage, const VkImageCreateFlags flags, const VkImageTiling tiling)
79 const VkSampleCountFlagBits samples = static_cast<VkSampleCountFlagBits>(texture.numSamples()); // integer and bit mask are aligned, so we can cast like this
81 const VkImageCreateInfo imageParams =
83 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
84 DE_NULL, // const void* pNext;
85 (isCube(texture) ? (VkImageCreateFlags)VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : 0u) | flags, // VkImageCreateFlags flags;
86 mapImageType(texture.type()), // VkImageType imageType;
87 format, // VkFormat format;
88 makeExtent3D(texture.layerSize()), // VkExtent3D extent;
89 1u, // deUint32 mipLevels;
90 (deUint32)texture.numLayers(), // deUint32 arrayLayers;
91 samples, // VkSampleCountFlagBits samples;
92 tiling, // VkImageTiling tiling;
93 usage, // VkImageUsageFlags usage;
94 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
95 0u, // deUint32 queueFamilyIndexCount;
96 DE_NULL, // const deUint32* pQueueFamilyIndices;
97 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
103 //! Minimum chunk size is determined by the offset alignment requirements.
104 VkDeviceSize getOptimalUniformBufferChunkSize (const InstanceInterface& vki, const VkPhysicalDevice physDevice, VkDeviceSize minimumRequiredChunkSizeBytes)
106 const VkPhysicalDeviceProperties properties = getPhysicalDeviceProperties(vki, physDevice);
107 const VkDeviceSize alignment = properties.limits.minUniformBufferOffsetAlignment;
109 if (minimumRequiredChunkSizeBytes > alignment)
110 return alignment + (minimumRequiredChunkSizeBytes / alignment) * alignment;
115 bool isRepresentableIntegerValue (tcu::Vector<deInt64, 4> value, tcu::TextureFormat format)
117 const tcu::IVec4 formatBitDepths = tcu::getTextureFormatBitDepth(format);
118 const deUint32 numChannels = getNumUsedChannels(mapTextureFormat(format));
120 switch (tcu::getTextureChannelClass(format.type))
122 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
124 for (deUint32 compNdx = 0; compNdx < numChannels; compNdx++)
126 if (deFloorToInt32(log2((double)value[compNdx]) + 1) > formatBitDepths[compNdx])
133 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
135 for (deUint32 compNdx = 0; compNdx < numChannels; compNdx++)
137 if ((deFloorToInt32(log2((double)deAbs64(value[compNdx])) + 1) + 1) > formatBitDepths[compNdx])
145 DE_ASSERT(isIntegerFormat(mapTextureFormat(format)));