1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2016 The Khronos Group Inc.
6 * Copyright (c) 2016 The Android Open Source Project
7 *
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
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
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.
19 *
20 *//*!
21 * \file
22 * \brief Image load/store utilities
23 *//*--------------------------------------------------------------------*/
24
25 #include "deMath.h"
26 #include "tcuTextureUtil.hpp"
27 #include "vktImageLoadStoreUtil.hpp"
28 #include "vkQueryUtil.hpp"
29
30 using namespace vk;
31
32 namespace vkt
33 {
34 namespace image
35 {
36
computeStoreColorScale(const vk::VkFormat format,const tcu::IVec3 imageSize)37 float computeStoreColorScale(const vk::VkFormat format, const tcu::IVec3 imageSize)
38 {
39 const int maxImageDimension = de::max(imageSize.x(), de::max(imageSize.y(), imageSize.z()));
40 const float div = static_cast<float>(maxImageDimension - 1);
41
42 if (isUnormFormat(format))
43 return 1.0f / div;
44 else if (isSnormFormat(format))
45 return 2.0f / div;
46 else
47 return 1.0f;
48 }
49
getImageTypeForSingleLayer(const ImageType imageType)50 ImageType getImageTypeForSingleLayer(const ImageType imageType)
51 {
52 switch (imageType)
53 {
54 case IMAGE_TYPE_1D:
55 case IMAGE_TYPE_1D_ARRAY:
56 return IMAGE_TYPE_1D;
57
58 case IMAGE_TYPE_2D:
59 case IMAGE_TYPE_2D_ARRAY:
60 case IMAGE_TYPE_CUBE:
61 case IMAGE_TYPE_CUBE_ARRAY:
62 // A single layer for cube is a 2d face
63 return IMAGE_TYPE_2D;
64
65 case IMAGE_TYPE_3D:
66 return IMAGE_TYPE_3D;
67
68 case IMAGE_TYPE_BUFFER:
69 return IMAGE_TYPE_BUFFER;
70
71 default:
72 DE_FATAL("Internal test error");
73 return IMAGE_TYPE_LAST;
74 }
75 }
76
makeImageCreateInfo(const Texture & texture,const VkFormat format,const VkImageUsageFlags usage,const VkImageCreateFlags flags,const VkImageTiling tiling)77 VkImageCreateInfo makeImageCreateInfo(const Texture &texture, const VkFormat format, const VkImageUsageFlags usage,
78 const VkImageCreateFlags flags, const VkImageTiling tiling)
79 {
80 const VkSampleCountFlagBits samples = static_cast<VkSampleCountFlagBits>(
81 texture.numSamples()); // integer and bit mask are aligned, so we can cast like this
82
83 const VkImageCreateInfo imageParams = {
84 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
85 DE_NULL, // const void* pNext;
86 (isCube(texture) ? (VkImageCreateFlags)VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : 0u) |
87 flags, // VkImageCreateFlags flags;
88 mapImageType(texture.type()), // VkImageType imageType;
89 format, // VkFormat format;
90 makeExtent3D(texture.layerSize()), // VkExtent3D extent;
91 1u, // uint32_t mipLevels;
92 (uint32_t)texture.numLayers(), // uint32_t arrayLayers;
93 samples, // VkSampleCountFlagBits samples;
94 tiling, // VkImageTiling tiling;
95 usage, // VkImageUsageFlags usage;
96 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
97 0u, // uint32_t queueFamilyIndexCount;
98 DE_NULL, // const uint32_t* pQueueFamilyIndices;
99 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
100 };
101 return imageParams;
102 }
103
104 //! Minimum chunk size is determined by the offset alignment requirements.
getOptimalUniformBufferChunkSize(const InstanceInterface & vki,const VkPhysicalDevice physDevice,VkDeviceSize minimumRequiredChunkSizeBytes)105 VkDeviceSize getOptimalUniformBufferChunkSize(const InstanceInterface &vki, const VkPhysicalDevice physDevice,
106 VkDeviceSize minimumRequiredChunkSizeBytes)
107 {
108 const VkPhysicalDeviceProperties properties = getPhysicalDeviceProperties(vki, physDevice);
109 const VkDeviceSize alignment = properties.limits.minUniformBufferOffsetAlignment;
110
111 if (minimumRequiredChunkSizeBytes > alignment)
112 return alignment + (minimumRequiredChunkSizeBytes / alignment) * alignment;
113 else
114 return alignment;
115 }
116
isRepresentableIntegerValue(tcu::Vector<int64_t,4> value,tcu::TextureFormat format)117 bool isRepresentableIntegerValue(tcu::Vector<int64_t, 4> value, tcu::TextureFormat format)
118 {
119 const tcu::IVec4 formatBitDepths = tcu::getTextureFormatBitDepth(format);
120 const uint32_t numChannels = getNumUsedChannels(mapTextureFormat(format));
121
122 switch (tcu::getTextureChannelClass(format.type))
123 {
124 case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
125 {
126 for (uint32_t compNdx = 0; compNdx < numChannels; compNdx++)
127 {
128 if (deFloorToInt32(log2((double)value[compNdx]) + 1) > formatBitDepths[compNdx])
129 return false;
130 }
131
132 break;
133 }
134
135 case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
136 {
137 for (uint32_t compNdx = 0; compNdx < numChannels; compNdx++)
138 {
139 if ((deFloorToInt32(log2((double)deAbs64(value[compNdx])) + 1) + 1) > formatBitDepths[compNdx])
140 return false;
141 }
142
143 break;
144 }
145
146 default:
147 DE_ASSERT(isIntegerFormat(mapTextureFormat(format)));
148 }
149
150 return true;
151 }
152
153 } // namespace image
154 } // namespace vkt
155