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 
makeExtent3D(const tcu::IVec3 & vec)102 inline VkExtent3D makeExtent3D (const tcu::IVec3& vec)
103 {
104 	return makeExtent3D((deUint32)vec.x(), (deUint32)vec.y(), (deUint32)vec.z());
105 }
106 
makeExtent3D(const tcu::UVec3 & vec)107 inline VkExtent3D makeExtent3D (const tcu::UVec3& vec)
108 {
109 	return makeExtent3D(vec.x(), vec.y(), vec.z());
110 }
111 
makeRect2D(deInt32 x,deInt32 y,deUint32 width,deUint32 height)112 inline VkRect2D makeRect2D (deInt32 x, deInt32 y, deUint32 width, deUint32 height)
113 {
114 	VkRect2D r;
115 	r.offset.x		= x;
116 	r.offset.y		= y;
117 	r.extent.width	= width;
118 	r.extent.height	= height;
119 
120 	return r;
121 }
122 
makeRect2D(const tcu::IVec2 & vec)123 inline VkRect2D makeRect2D(const tcu::IVec2& vec)
124 {
125 	return makeRect2D(0, 0, vec.x(), vec.y());
126 }
127 
makeRect2D(const tcu::IVec3 & vec)128 inline VkRect2D makeRect2D(const tcu::IVec3& vec)
129 {
130 	return makeRect2D(0, 0, vec.x(), vec.y());
131 }
132 
makeRect2D(const tcu::UVec2 & vec)133 inline VkRect2D makeRect2D(const tcu::UVec2& vec)
134 {
135 	return makeRect2D(0, 0, vec.x(), vec.y());
136 }
137 
makeRect2D(const VkExtent3D & extent)138 inline VkRect2D makeRect2D(const VkExtent3D& extent)
139 {
140 	return makeRect2D(0, 0, extent.width, extent.height);
141 }
142 
makeRect2D(const VkExtent2D & extent)143 inline VkRect2D makeRect2D(const VkExtent2D& extent)
144 {
145 	return makeRect2D(0, 0, extent.width, extent.height);
146 }
147 
makeRect2D(const deUint32 width,const deUint32 height)148 inline VkRect2D makeRect2D(const deUint32 width, const deUint32 height)
149 {
150 	return makeRect2D(0, 0, width, height);
151 }
152 
makeViewport(const tcu::IVec2 & vec)153 inline VkViewport makeViewport(const tcu::IVec2& vec)
154 {
155 	return makeViewport(0.0f, 0.0f, (float)vec.x(), (float)vec.y(), 0.0f, 1.0f);
156 }
157 
makeViewport(const tcu::IVec3 & vec)158 inline VkViewport makeViewport(const tcu::IVec3& vec)
159 {
160 	return makeViewport(0.0f, 0.0f, (float)vec.x(), (float)vec.y(), 0.0f, 1.0f);
161 }
162 
makeViewport(const tcu::UVec2 & vec)163 inline VkViewport makeViewport(const tcu::UVec2& vec)
164 {
165 	return makeViewport(0.0f, 0.0f, (float)vec.x(), (float)vec.y(), 0.0f, 1.0f);
166 }
167 
makeViewport(const VkExtent3D & extent)168 inline VkViewport makeViewport(const VkExtent3D& extent)
169 {
170 	return makeViewport(0.0f, 0.0f, (float)extent.width, (float)extent.height, 0.0f, 1.0f);
171 }
172 
makeViewport(const VkExtent2D & extent)173 inline VkViewport makeViewport(const VkExtent2D& extent)
174 {
175 	return makeViewport(0.0f, 0.0f, (float)extent.width, (float)extent.height, 0.0f, 1.0f);
176 }
177 
makeViewport(const deUint32 width,const deUint32 height)178 inline VkViewport makeViewport(const deUint32 width, const deUint32 height)
179 {
180 	return makeViewport(0.0f, 0.0f, (float)width, (float)height, 0.0f, 1.0f);
181 }
182 
183 } // vk
184 
185 #endif // _VKTYPEUTIL_HPP
186