1 #ifndef _VKTYPEUTIL_HPP
2 #define _VKTYPEUTIL_HPP
3 /*-------------------------------------------------------------------------
4 * Vulkan CTS Framework
5 * --------------------
6 *
7 * Copyright (c) 2015 Google Inc.
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 *//*!
22 * \file
23 * \brief Utilities for creating commonly used composite types.
24 *//*--------------------------------------------------------------------*/
25
26 #include "vkDefs.hpp"
27 #include "tcuVector.hpp"
28
29 namespace vk
30 {
31
32 #include "vkTypeUtil.inl"
33
makeClearValueColorF32(float r,float g,float b,float a)34 inline VkClearValue makeClearValueColorF32 (float r, float g, float b, float a)
35 {
36 VkClearValue v;
37 v.color.float32[0] = r;
38 v.color.float32[1] = g;
39 v.color.float32[2] = b;
40 v.color.float32[3] = a;
41 return v;
42 }
43
makeClearValueColorVec4(tcu::Vec4 vec)44 inline VkClearValue makeClearValueColorVec4 (tcu::Vec4 vec)
45 {
46 return makeClearValueColorF32(vec.x(), vec.y(), vec.z(), vec.w());
47 }
48
makeClearValueColorU32(deUint32 r,deUint32 g,deUint32 b,deUint32 a)49 inline VkClearValue makeClearValueColorU32 (deUint32 r, deUint32 g, deUint32 b, deUint32 a)
50 {
51 VkClearValue v;
52 v.color.uint32[0] = r;
53 v.color.uint32[1] = g;
54 v.color.uint32[2] = b;
55 v.color.uint32[3] = a;
56 return v;
57 }
58
makeClearValueColorI32(deInt32 r,deInt32 g,deInt32 b,deInt32 a)59 inline VkClearValue makeClearValueColorI32 (deInt32 r, deInt32 g, deInt32 b, deInt32 a)
60 {
61 VkClearValue v;
62 v.color.int32[0] = r;
63 v.color.int32[1] = g;
64 v.color.int32[2] = b;
65 v.color.int32[3] = a;
66 return v;
67 }
68
makeClearValueColor(const tcu::Vec4 & color)69 inline VkClearValue makeClearValueColor (const tcu::Vec4& color)
70 {
71 VkClearValue v;
72 v.color.float32[0] = color[0];
73 v.color.float32[1] = color[1];
74 v.color.float32[2] = color[2];
75 v.color.float32[3] = color[3];
76 return v;
77 }
78
makeClearValueDepthStencil(float depth,deUint32 stencil)79 inline VkClearValue makeClearValueDepthStencil (float depth, deUint32 stencil)
80 {
81 VkClearValue v;
82 v.depthStencil.depth = depth;
83 v.depthStencil.stencil = stencil;
84 return v;
85 }
86
makeClearValue(VkClearColorValue color)87 inline VkClearValue makeClearValue (VkClearColorValue color)
88 {
89 VkClearValue v;
90 v.color = color;
91 return v;
92 }
93
makeComponentMappingRGBA(void)94 inline VkComponentMapping makeComponentMappingRGBA (void)
95 {
96 return makeComponentMapping(VK_COMPONENT_SWIZZLE_R,
97 VK_COMPONENT_SWIZZLE_G,
98 VK_COMPONENT_SWIZZLE_B,
99 VK_COMPONENT_SWIZZLE_A);
100 }
101
makeComponentMappingIdentity(void)102 inline VkComponentMapping makeComponentMappingIdentity (void)
103 {
104 return makeComponentMapping(VK_COMPONENT_SWIZZLE_IDENTITY,
105 VK_COMPONENT_SWIZZLE_IDENTITY,
106 VK_COMPONENT_SWIZZLE_IDENTITY,
107 VK_COMPONENT_SWIZZLE_IDENTITY);
108 }
109
makeExtent3D(const tcu::IVec3 & vec)110 inline VkExtent3D makeExtent3D (const tcu::IVec3& vec)
111 {
112 return makeExtent3D((deUint32)vec.x(), (deUint32)vec.y(), (deUint32)vec.z());
113 }
114
makeExtent3D(const tcu::UVec3 & vec)115 inline VkExtent3D makeExtent3D (const tcu::UVec3& vec)
116 {
117 return makeExtent3D(vec.x(), vec.y(), vec.z());
118 }
119
makeRect2D(deInt32 x,deInt32 y,deUint32 width,deUint32 height)120 inline VkRect2D makeRect2D (deInt32 x, deInt32 y, deUint32 width, deUint32 height)
121 {
122 VkRect2D r;
123 r.offset.x = x;
124 r.offset.y = y;
125 r.extent.width = width;
126 r.extent.height = height;
127
128 return r;
129 }
130
makeRect2D(const tcu::IVec2 & vec)131 inline VkRect2D makeRect2D(const tcu::IVec2& vec)
132 {
133 return makeRect2D(0, 0, vec.x(), vec.y());
134 }
135
makeRect2D(const tcu::IVec3 & vec)136 inline VkRect2D makeRect2D(const tcu::IVec3& vec)
137 {
138 return makeRect2D(0, 0, vec.x(), vec.y());
139 }
140
makeRect2D(const tcu::UVec2 & vec)141 inline VkRect2D makeRect2D(const tcu::UVec2& vec)
142 {
143 return makeRect2D(0, 0, vec.x(), vec.y());
144 }
145
makeRect2D(const VkExtent3D & extent)146 inline VkRect2D makeRect2D(const VkExtent3D& extent)
147 {
148 return makeRect2D(0, 0, extent.width, extent.height);
149 }
150
makeRect2D(const VkExtent2D & extent)151 inline VkRect2D makeRect2D(const VkExtent2D& extent)
152 {
153 return makeRect2D(0, 0, extent.width, extent.height);
154 }
155
makeRect2D(const deUint32 width,const deUint32 height)156 inline VkRect2D makeRect2D(const deUint32 width, const deUint32 height)
157 {
158 return makeRect2D(0, 0, width, height);
159 }
160
makeViewport(const tcu::IVec2 & vec)161 inline VkViewport makeViewport(const tcu::IVec2& vec)
162 {
163 return makeViewport(0.0f, 0.0f, (float)vec.x(), (float)vec.y(), 0.0f, 1.0f);
164 }
165
makeViewport(const tcu::IVec3 & vec)166 inline VkViewport makeViewport(const tcu::IVec3& vec)
167 {
168 return makeViewport(0.0f, 0.0f, (float)vec.x(), (float)vec.y(), 0.0f, 1.0f);
169 }
170
makeViewport(const tcu::UVec2 & vec)171 inline VkViewport makeViewport(const tcu::UVec2& vec)
172 {
173 return makeViewport(0.0f, 0.0f, (float)vec.x(), (float)vec.y(), 0.0f, 1.0f);
174 }
175
makeViewport(const VkExtent3D & extent)176 inline VkViewport makeViewport(const VkExtent3D& extent)
177 {
178 return makeViewport(0.0f, 0.0f, (float)extent.width, (float)extent.height, 0.0f, 1.0f);
179 }
180
makeViewport(const VkExtent2D & extent)181 inline VkViewport makeViewport(const VkExtent2D& extent)
182 {
183 return makeViewport(0.0f, 0.0f, (float)extent.width, (float)extent.height, 0.0f, 1.0f);
184 }
185
makeViewport(const deUint32 width,const deUint32 height)186 inline VkViewport makeViewport(const deUint32 width, const deUint32 height)
187 {
188 return makeViewport(0.0f, 0.0f, (float)width, (float)height, 0.0f, 1.0f);
189 }
190
makeSemaphoreSubmitInfo(VkSemaphore semaphore,VkPipelineStageFlags2KHR stageMask,uint64_t value=0,uint32_t deviceIndex=0)191 inline VkSemaphoreSubmitInfoKHR makeSemaphoreSubmitInfo (VkSemaphore semaphore, VkPipelineStageFlags2KHR stageMask, uint64_t value = 0, uint32_t deviceIndex = 0)
192 {
193 return VkSemaphoreSubmitInfoKHR
194 {
195 VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO_KHR, // VkStructureType sType;
196 DE_NULL, // const void* pNext;
197 semaphore, // VkSemaphore semaphore;
198 value, // uint64_t value;
199 stageMask, // VkPipelineStageFlags2KHR stageMask;
200 deviceIndex, // uint32_t deviceIndex;
201 };
202 }
203
primitiveTopologyCastToList(const VkPrimitiveTopology primitiveTopology)204 inline VkPrimitiveTopology primitiveTopologyCastToList (const VkPrimitiveTopology primitiveTopology)
205 {
206 DE_STATIC_ASSERT(static_cast<deUint64>(VK_PRIMITIVE_TOPOLOGY_PATCH_LIST) + 1 == static_cast<deUint64>(VK_PRIMITIVE_TOPOLOGY_LAST));
207
208 switch (primitiveTopology)
209 {
210 case VK_PRIMITIVE_TOPOLOGY_POINT_LIST: return VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
211 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
212 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
213 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
214 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
215 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
216 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
217 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY: return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
218 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
219 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY: return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
220 case VK_PRIMITIVE_TOPOLOGY_PATCH_LIST: return VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
221 default: TCU_THROW(InternalError, "Unknown primitive topology.");
222 }
223 }
224
isPrimitiveTopologyPoint(const VkPrimitiveTopology primitiveTopology)225 inline bool isPrimitiveTopologyPoint (const VkPrimitiveTopology primitiveTopology)
226 {
227 return primitiveTopologyCastToList(primitiveTopology) == VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
228 }
229
isPrimitiveTopologyLine(const VkPrimitiveTopology primitiveTopology)230 inline bool isPrimitiveTopologyLine (const VkPrimitiveTopology primitiveTopology)
231 {
232 return primitiveTopologyCastToList(primitiveTopology) == VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
233 }
234
isPrimitiveTopologyTriangle(const VkPrimitiveTopology primitiveTopology)235 inline bool isPrimitiveTopologyTriangle (const VkPrimitiveTopology primitiveTopology)
236 {
237 return primitiveTopologyCastToList(primitiveTopology) == VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
238 }
239
isPrimitiveTopologyPatch(const VkPrimitiveTopology primitiveTopology)240 inline bool isPrimitiveTopologyPatch (const VkPrimitiveTopology primitiveTopology)
241 {
242 return primitiveTopologyCastToList(primitiveTopology) == VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
243 }
244
isAllInStage(const VkShaderStageFlags shaderStageFlags,const VkShaderStageFlags stageMask)245 inline bool isAllInStage (const VkShaderStageFlags shaderStageFlags, const VkShaderStageFlags stageMask)
246 {
247 return (shaderStageFlags & stageMask) != 0 && ((shaderStageFlags & ~stageMask) == 0);
248 }
249
isAllComputeStages(const VkShaderStageFlags shaderStageFlags)250 inline bool isAllComputeStages (const VkShaderStageFlags shaderStageFlags)
251 {
252 return isAllInStage(shaderStageFlags, VK_SHADER_STAGE_COMPUTE_BIT);
253 }
254
isAllGraphicsStages(const VkShaderStageFlags shaderStageFlags)255 inline bool isAllGraphicsStages (const VkShaderStageFlags shaderStageFlags)
256 {
257 return isAllInStage(shaderStageFlags, VK_SHADER_STAGE_ALL_GRAPHICS);
258 }
259
260 #ifndef CTS_USES_VULKANSC
isAllRayTracingStages(const VkShaderStageFlags shaderStageFlags)261 inline bool isAllRayTracingStages (const VkShaderStageFlags shaderStageFlags)
262 {
263 const VkShaderStageFlags rayTracingStageFlags = VK_SHADER_STAGE_RAYGEN_BIT_KHR
264 | VK_SHADER_STAGE_ANY_HIT_BIT_KHR
265 | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR
266 | VK_SHADER_STAGE_MISS_BIT_KHR
267 | VK_SHADER_STAGE_INTERSECTION_BIT_KHR
268 | VK_SHADER_STAGE_CALLABLE_BIT_KHR;
269
270 return isAllInStage(shaderStageFlags, rayTracingStageFlags);
271 }
272
isAllMeshShadingStages(const VkShaderStageFlags shaderStageFlags)273 inline bool isAllMeshShadingStages (const VkShaderStageFlags shaderStageFlags)
274 {
275 const VkShaderStageFlags meshStages = (VK_SHADER_STAGE_MESH_BIT_EXT | VK_SHADER_STAGE_TASK_BIT_EXT);
276 return isAllInStage(shaderStageFlags, meshStages);
277 }
278
279 #endif // CTS_USES_VULKANSC
280 } // vk
281
282 #endif // _VKTYPEUTIL_HPP
283