1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2016 The Khronos Group Inc.
6 *
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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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.
18 *
19 *//*!
20 * \file
21 * \brief Clipping tests utilities
22 *//*--------------------------------------------------------------------*/
23
24 #include "vktClippingUtil.hpp"
25 #include "vkTypeUtil.hpp"
26
27 namespace vkt
28 {
29 namespace clipping
30 {
31 using namespace vk;
32
makeBufferCreateInfo(const VkDeviceSize bufferSize,const VkBufferUsageFlags usage)33 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize bufferSize,
34 const VkBufferUsageFlags usage)
35 {
36 const VkBufferCreateInfo bufferCreateInfo =
37 {
38 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
39 DE_NULL, // const void* pNext;
40 (VkBufferCreateFlags)0, // VkBufferCreateFlags flags;
41 bufferSize, // VkDeviceSize size;
42 usage, // VkBufferUsageFlags usage;
43 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
44 0u, // deUint32 queueFamilyIndexCount;
45 DE_NULL, // const deUint32* pQueueFamilyIndices;
46 };
47 return bufferCreateInfo;
48 }
49
makeBufferMemoryBarrier(const VkAccessFlags srcAccessMask,const VkAccessFlags dstAccessMask,const VkBuffer buffer,const VkDeviceSize offset,const VkDeviceSize bufferSizeBytes)50 VkBufferMemoryBarrier makeBufferMemoryBarrier (const VkAccessFlags srcAccessMask,
51 const VkAccessFlags dstAccessMask,
52 const VkBuffer buffer,
53 const VkDeviceSize offset,
54 const VkDeviceSize bufferSizeBytes)
55 {
56 const VkBufferMemoryBarrier barrier =
57 {
58 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
59 DE_NULL, // const void* pNext;
60 srcAccessMask, // VkAccessFlags srcAccessMask;
61 dstAccessMask, // VkAccessFlags dstAccessMask;
62 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
63 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
64 buffer, // VkBuffer buffer;
65 offset, // VkDeviceSize offset;
66 bufferSizeBytes, // VkDeviceSize size;
67 };
68 return barrier;
69 }
70
makeImageMemoryBarrier(const VkAccessFlags srcAccessMask,const VkAccessFlags dstAccessMask,const VkImageLayout oldLayout,const VkImageLayout newLayout,const VkImage image,const VkImageSubresourceRange subresourceRange)71 VkImageMemoryBarrier makeImageMemoryBarrier (const VkAccessFlags srcAccessMask,
72 const VkAccessFlags dstAccessMask,
73 const VkImageLayout oldLayout,
74 const VkImageLayout newLayout,
75 const VkImage image,
76 const VkImageSubresourceRange subresourceRange)
77 {
78 const VkImageMemoryBarrier barrier =
79 {
80 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
81 DE_NULL, // const void* pNext;
82 srcAccessMask, // VkAccessFlags outputMask;
83 dstAccessMask, // VkAccessFlags inputMask;
84 oldLayout, // VkImageLayout oldLayout;
85 newLayout, // VkImageLayout newLayout;
86 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
87 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
88 image, // VkImage image;
89 subresourceRange, // VkImageSubresourceRange subresourceRange;
90 };
91 return barrier;
92 }
93
makeCommandPool(const DeviceInterface & vk,const VkDevice device,const deUint32 queueFamilyIndex)94 Move<VkCommandPool> makeCommandPool (const DeviceInterface& vk, const VkDevice device, const deUint32 queueFamilyIndex)
95 {
96 const VkCommandPoolCreateInfo info =
97 {
98 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
99 DE_NULL, // const void* pNext;
100 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
101 queueFamilyIndex, // deUint32 queueFamilyIndex;
102 };
103 return createCommandPool(vk, device, &info);
104 }
105
makeCommandBuffer(const DeviceInterface & vk,const VkDevice device,const VkCommandPool commandPool)106 Move<VkCommandBuffer> makeCommandBuffer (const DeviceInterface& vk, const VkDevice device, const VkCommandPool commandPool)
107 {
108 const VkCommandBufferAllocateInfo info =
109 {
110 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
111 DE_NULL, // const void* pNext;
112 commandPool, // VkCommandPool commandPool;
113 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
114 1u, // deUint32 commandBufferCount;
115 };
116 return allocateCommandBuffer(vk, device, &info);
117 }
118
makeDescriptorSet(const DeviceInterface & vk,const VkDevice device,const VkDescriptorPool descriptorPool,const VkDescriptorSetLayout setLayout)119 Move<VkDescriptorSet> makeDescriptorSet (const DeviceInterface& vk,
120 const VkDevice device,
121 const VkDescriptorPool descriptorPool,
122 const VkDescriptorSetLayout setLayout)
123 {
124 const VkDescriptorSetAllocateInfo info =
125 {
126 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType;
127 DE_NULL, // const void* pNext;
128 descriptorPool, // VkDescriptorPool descriptorPool;
129 1u, // deUint32 descriptorSetCount;
130 &setLayout, // const VkDescriptorSetLayout* pSetLayouts;
131 };
132 return allocateDescriptorSet(vk, device, &info);
133 }
134
makePipelineLayout(const DeviceInterface & vk,const VkDevice device,const VkDescriptorSetLayout descriptorSetLayout)135 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
136 const VkDevice device,
137 const VkDescriptorSetLayout descriptorSetLayout)
138 {
139 const VkPipelineLayoutCreateInfo info =
140 {
141 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
142 DE_NULL, // const void* pNext;
143 (VkPipelineLayoutCreateFlags)0, // VkPipelineLayoutCreateFlags flags;
144 1u, // deUint32 setLayoutCount;
145 &descriptorSetLayout, // const VkDescriptorSetLayout* pSetLayouts;
146 0u, // deUint32 pushConstantRangeCount;
147 DE_NULL, // const VkPushConstantRange* pPushConstantRanges;
148 };
149 return createPipelineLayout(vk, device, &info);
150 }
151
makePipelineLayoutWithoutDescriptors(const DeviceInterface & vk,const VkDevice device)152 Move<VkPipelineLayout> makePipelineLayoutWithoutDescriptors (const DeviceInterface& vk,
153 const VkDevice device)
154 {
155 const VkPipelineLayoutCreateInfo info =
156 {
157 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
158 DE_NULL, // const void* pNext;
159 (VkPipelineLayoutCreateFlags)0, // VkPipelineLayoutCreateFlags flags;
160 0u, // deUint32 setLayoutCount;
161 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts;
162 0u, // deUint32 pushConstantRangeCount;
163 DE_NULL, // const VkPushConstantRange* pPushConstantRanges;
164 };
165 return createPipelineLayout(vk, device, &info);
166 }
167
makeImageView(const DeviceInterface & vk,const VkDevice device,const VkImage image,const VkImageViewType viewType,const VkFormat format,const VkImageSubresourceRange subresourceRange)168 Move<VkImageView> makeImageView (const DeviceInterface& vk,
169 const VkDevice device,
170 const VkImage image,
171 const VkImageViewType viewType,
172 const VkFormat format,
173 const VkImageSubresourceRange subresourceRange)
174 {
175 const VkImageViewCreateInfo imageViewParams =
176 {
177 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
178 DE_NULL, // const void* pNext;
179 (VkImageViewCreateFlags)0, // VkImageViewCreateFlags flags;
180 image, // VkImage image;
181 viewType, // VkImageViewType viewType;
182 format, // VkFormat format;
183 makeComponentMappingRGBA(), // VkComponentMapping components;
184 subresourceRange, // VkImageSubresourceRange subresourceRange;
185 };
186 return createImageView(vk, device, &imageViewParams);
187 }
188
makeBufferImageCopy(const VkImageSubresourceLayers subresourceLayers,const VkExtent3D extent)189 VkBufferImageCopy makeBufferImageCopy (const VkImageSubresourceLayers subresourceLayers,
190 const VkExtent3D extent)
191 {
192 const VkBufferImageCopy copyParams =
193 {
194 0ull, // VkDeviceSize bufferOffset;
195 0u, // deUint32 bufferRowLength;
196 0u, // deUint32 bufferImageHeight;
197 subresourceLayers, // VkImageSubresourceLayers imageSubresource;
198 makeOffset3D(0, 0, 0), // VkOffset3D imageOffset;
199 extent, // VkExtent3D imageExtent;
200 };
201 return copyParams;
202 }
203
beginCommandBuffer(const DeviceInterface & vk,const VkCommandBuffer commandBuffer)204 void beginCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
205 {
206 const VkCommandBufferBeginInfo info =
207 {
208 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
209 DE_NULL, // const void* pNext;
210 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
211 DE_NULL, // const VkCommandBufferInheritanceInfo* pInheritanceInfo;
212 };
213 VK_CHECK(vk.beginCommandBuffer(commandBuffer, &info));
214 }
215
endCommandBuffer(const DeviceInterface & vk,const VkCommandBuffer commandBuffer)216 void endCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
217 {
218 VK_CHECK(vk.endCommandBuffer(commandBuffer));
219 }
220
submitCommandsAndWait(const DeviceInterface & vk,const VkDevice device,const VkQueue queue,const VkCommandBuffer commandBuffer)221 void submitCommandsAndWait (const DeviceInterface& vk,
222 const VkDevice device,
223 const VkQueue queue,
224 const VkCommandBuffer commandBuffer)
225 {
226 const VkFenceCreateInfo fenceInfo =
227 {
228 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
229 DE_NULL, // const void* pNext;
230 (VkFenceCreateFlags)0, // VkFenceCreateFlags flags;
231 };
232 const Unique<VkFence> fence(createFence(vk, device, &fenceInfo));
233
234 const VkSubmitInfo submitInfo =
235 {
236 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
237 DE_NULL, // const void* pNext;
238 0u, // uint32_t waitSemaphoreCount;
239 DE_NULL, // const VkSemaphore* pWaitSemaphores;
240 DE_NULL, // const VkPipelineStageFlags* pWaitDstStageMask;
241 1u, // uint32_t commandBufferCount;
242 &commandBuffer, // const VkCommandBuffer* pCommandBuffers;
243 0u, // uint32_t signalSemaphoreCount;
244 DE_NULL, // const VkSemaphore* pSignalSemaphores;
245 };
246 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
247 VK_CHECK(vk.waitForFences(device, 1u, &fence.get(), DE_TRUE, ~0ull));
248 }
249
requireFeatures(const InstanceInterface & vki,const VkPhysicalDevice physDevice,const FeatureFlags flags)250 void requireFeatures (const InstanceInterface& vki, const VkPhysicalDevice physDevice, const FeatureFlags flags)
251 {
252 const VkPhysicalDeviceFeatures features = getPhysicalDeviceFeatures(vki, physDevice);
253
254 if (((flags & FEATURE_TESSELLATION_SHADER) != 0) && !features.tessellationShader)
255 throw tcu::NotSupportedError("Tessellation shader not supported");
256
257 if (((flags & FEATURE_GEOMETRY_SHADER) != 0) && !features.geometryShader)
258 throw tcu::NotSupportedError("Geometry shader not supported");
259
260 if (((flags & FEATURE_SHADER_FLOAT_64) != 0) && !features.shaderFloat64)
261 throw tcu::NotSupportedError("Double-precision floats not supported");
262
263 if (((flags & FEATURE_VERTEX_PIPELINE_STORES_AND_ATOMICS) != 0) && !features.vertexPipelineStoresAndAtomics)
264 throw tcu::NotSupportedError("SSBO and image writes not supported in vertex pipeline");
265
266 if (((flags & FEATURE_FRAGMENT_STORES_AND_ATOMICS) != 0) && !features.fragmentStoresAndAtomics)
267 throw tcu::NotSupportedError("SSBO and image writes not supported in fragment shader");
268
269 if (((flags & FEATURE_SHADER_TESSELLATION_AND_GEOMETRY_POINT_SIZE) != 0) && !features.shaderTessellationAndGeometryPointSize)
270 throw tcu::NotSupportedError("Tessellation and geometry shaders don't support PointSize built-in");
271
272 if (((flags & FEATURE_DEPTH_CLAMP) != 0) && !features.depthClamp)
273 throw tcu::NotSupportedError("Depth clamp not supported");
274
275 if (((flags & FEATURE_LARGE_POINTS) != 0) && !features.largePoints)
276 throw tcu::NotSupportedError("Large points not supported");
277
278 if (((flags & FEATURE_WIDE_LINES) != 0) && !features.wideLines)
279 throw tcu::NotSupportedError("Wide lines not supported");
280
281 if (((flags & FEATURE_SHADER_CLIP_DISTANCE) != 0) && !features.shaderClipDistance)
282 throw tcu::NotSupportedError("Shader ClipDistance not supported");
283
284 if (((flags & FEATURE_SHADER_CULL_DISTANCE) != 0) && !features.shaderCullDistance)
285 throw tcu::NotSupportedError("Shader CullDistance not supported");
286 }
287
getPrimitiveTopologyShortName(const VkPrimitiveTopology topology)288 std::string getPrimitiveTopologyShortName (const VkPrimitiveTopology topology)
289 {
290 std::string name(getPrimitiveTopologyName(topology));
291 return de::toLower(name.substr(22));
292 }
293
294 } // clipping
295 } // vkt
296