1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2016 The Khronos Group Inc.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Clipping tests utilities
22 *//*--------------------------------------------------------------------*/
24 #include "vktClippingUtil.hpp"
25 #include "vkTypeUtil.hpp"
33 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize bufferSize,
34 const VkBufferUsageFlags usage)
36 const VkBufferCreateInfo bufferCreateInfo =
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;
47 return bufferCreateInfo;
50 VkBufferMemoryBarrier makeBufferMemoryBarrier (const VkAccessFlags srcAccessMask,
51 const VkAccessFlags dstAccessMask,
52 const VkBuffer buffer,
53 const VkDeviceSize offset,
54 const VkDeviceSize bufferSizeBytes)
56 const VkBufferMemoryBarrier barrier =
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;
71 VkImageMemoryBarrier makeImageMemoryBarrier (const VkAccessFlags srcAccessMask,
72 const VkAccessFlags dstAccessMask,
73 const VkImageLayout oldLayout,
74 const VkImageLayout newLayout,
76 const VkImageSubresourceRange subresourceRange)
78 const VkImageMemoryBarrier barrier =
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;
94 Move<VkCommandPool> makeCommandPool (const DeviceInterface& vk, const VkDevice device, const deUint32 queueFamilyIndex)
96 const VkCommandPoolCreateInfo info =
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;
103 return createCommandPool(vk, device, &info);
106 Move<VkCommandBuffer> makeCommandBuffer (const DeviceInterface& vk, const VkDevice device, const VkCommandPool commandPool)
108 const VkCommandBufferAllocateInfo info =
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;
116 return allocateCommandBuffer(vk, device, &info);
119 Move<VkDescriptorSet> makeDescriptorSet (const DeviceInterface& vk,
120 const VkDevice device,
121 const VkDescriptorPool descriptorPool,
122 const VkDescriptorSetLayout setLayout)
124 const VkDescriptorSetAllocateInfo info =
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;
132 return allocateDescriptorSet(vk, device, &info);
135 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
136 const VkDevice device,
137 const VkDescriptorSetLayout descriptorSetLayout)
139 const VkPipelineLayoutCreateInfo info =
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;
149 return createPipelineLayout(vk, device, &info);
152 Move<VkPipelineLayout> makePipelineLayoutWithoutDescriptors (const DeviceInterface& vk,
153 const VkDevice device)
155 const VkPipelineLayoutCreateInfo info =
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;
165 return createPipelineLayout(vk, device, &info);
168 Move<VkImageView> makeImageView (const DeviceInterface& vk,
169 const VkDevice device,
171 const VkImageViewType viewType,
172 const VkFormat format,
173 const VkImageSubresourceRange subresourceRange)
175 const VkImageViewCreateInfo imageViewParams =
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;
186 return createImageView(vk, device, &imageViewParams);
189 VkBufferImageCopy makeBufferImageCopy (const VkImageSubresourceLayers subresourceLayers,
190 const VkExtent3D extent)
192 const VkBufferImageCopy copyParams =
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;
204 void beginCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
206 const VkCommandBufferBeginInfo info =
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;
213 VK_CHECK(vk.beginCommandBuffer(commandBuffer, &info));
216 void endCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
218 VK_CHECK(vk.endCommandBuffer(commandBuffer));
221 void submitCommandsAndWait (const DeviceInterface& vk,
222 const VkDevice device,
224 const VkCommandBuffer commandBuffer)
226 const VkFenceCreateInfo fenceInfo =
228 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
229 DE_NULL, // const void* pNext;
230 (VkFenceCreateFlags)0, // VkFenceCreateFlags flags;
232 const Unique<VkFence> fence(createFence(vk, device, &fenceInfo));
234 const VkSubmitInfo submitInfo =
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;
246 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
247 VK_CHECK(vk.waitForFences(device, 1u, &fence.get(), DE_TRUE, ~0ull));
250 void requireFeatures (const InstanceInterface& vki, const VkPhysicalDevice physDevice, const FeatureFlags flags)
252 const VkPhysicalDeviceFeatures features = getPhysicalDeviceFeatures(vki, physDevice);
254 if (((flags & FEATURE_TESSELLATION_SHADER) != 0) && !features.tessellationShader)
255 throw tcu::NotSupportedError("Tessellation shader not supported");
257 if (((flags & FEATURE_GEOMETRY_SHADER) != 0) && !features.geometryShader)
258 throw tcu::NotSupportedError("Geometry shader not supported");
260 if (((flags & FEATURE_SHADER_FLOAT_64) != 0) && !features.shaderFloat64)
261 throw tcu::NotSupportedError("Double-precision floats not supported");
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");
266 if (((flags & FEATURE_FRAGMENT_STORES_AND_ATOMICS) != 0) && !features.fragmentStoresAndAtomics)
267 throw tcu::NotSupportedError("SSBO and image writes not supported in fragment shader");
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");
272 if (((flags & FEATURE_DEPTH_CLAMP) != 0) && !features.depthClamp)
273 throw tcu::NotSupportedError("Depth clamp not supported");
275 if (((flags & FEATURE_LARGE_POINTS) != 0) && !features.largePoints)
276 throw tcu::NotSupportedError("Large points not supported");
278 if (((flags & FEATURE_WIDE_LINES) != 0) && !features.wideLines)
279 throw tcu::NotSupportedError("Wide lines not supported");
281 if (((flags & FEATURE_SHADER_CLIP_DISTANCE) != 0) && !features.shaderClipDistance)
282 throw tcu::NotSupportedError("Shader ClipDistance not supported");
284 if (((flags & FEATURE_SHADER_CULL_DISTANCE) != 0) && !features.shaderCullDistance)
285 throw tcu::NotSupportedError("Shader CullDistance not supported");
288 std::string getPrimitiveTopologyShortName (const VkPrimitiveTopology topology)
290 std::string name(getPrimitiveTopologyName(topology));
291 return de::toLower(name.substr(22));