1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 Mobica Ltd.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and/or associated documentation files (the
9 * "Materials"), to deal in the Materials without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Materials, and to
12 * permit persons to whom the Materials are furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice(s) and this permission notice shall be included
16 * in all copies or substantial portions of the Materials.
18 * The Materials are Confidential Information as defined by the
19 * Khronos Membership Agreement until designated non-confidential by Khronos,
20 * at which point this condition clause shall be removed.
22 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
32 * \brief Compute tests utility classes
33 *//*--------------------------------------------------------------------*/
35 #include "vktComputeTestsUtil.hpp"
36 #include "vkQueryUtil.hpp"
37 #include "vkTypeUtil.hpp"
46 Buffer::Buffer (const DeviceInterface& vk,
47 const VkDevice device,
49 const VkBufferCreateInfo& bufferCreateInfo,
50 const MemoryRequirement memoryRequirement)
52 m_buffer = createBuffer(vk, device, &bufferCreateInfo);
53 m_allocation = allocator.allocate(getBufferMemoryRequirements(vk, device, *m_buffer), memoryRequirement);
54 VK_CHECK(vk.bindBufferMemory(device, *m_buffer, m_allocation->getMemory(), m_allocation->getOffset()));
57 Image::Image (const DeviceInterface& vk,
58 const VkDevice device,
60 const VkImageCreateInfo& imageCreateInfo,
61 const MemoryRequirement memoryRequirement)
63 m_image = createImage(vk, device, &imageCreateInfo);
64 m_allocation = allocator.allocate(getImageMemoryRequirements(vk, device, *m_image), memoryRequirement);
65 VK_CHECK(vk.bindImageMemory(device, *m_image, m_allocation->getMemory(), m_allocation->getOffset()));
68 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize bufferSize,
69 const VkBufferUsageFlags usage)
71 const VkBufferCreateInfo bufferCreateInfo =
73 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
74 DE_NULL, // const void* pNext;
75 0u, // VkBufferCreateFlags flags;
76 bufferSize, // VkDeviceSize size;
77 usage, // VkBufferUsageFlags usage;
78 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
79 0u, // deUint32 queueFamilyIndexCount;
80 DE_NULL, // const deUint32* pQueueFamilyIndices;
82 return bufferCreateInfo;
85 VkBufferImageCopy makeBufferImageCopy (const VkExtent3D extent,
86 const deUint32 arraySize)
88 const VkBufferImageCopy copyParams =
90 0ull, // VkDeviceSize bufferOffset;
91 0u, // deUint32 bufferRowLength;
92 0u, // deUint32 bufferImageHeight;
93 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, arraySize), // VkImageSubresourceLayers imageSubresource;
94 makeOffset3D(0, 0, 0), // VkOffset3D imageOffset;
95 extent, // VkExtent3D imageExtent;
100 Move<VkCommandPool> makeCommandPool (const DeviceInterface& vk, const VkDevice device, const deUint32 queueFamilyIndex)
102 const VkCommandPoolCreateInfo commandPoolParams =
104 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
105 DE_NULL, // const void* pNext;
106 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
107 queueFamilyIndex, // deUint32 queueFamilyIndex;
109 return createCommandPool(vk, device, &commandPoolParams);
112 Move<VkCommandBuffer> makeCommandBuffer (const DeviceInterface& vk, const VkDevice device, const VkCommandPool commandPool)
114 const VkCommandBufferAllocateInfo bufferAllocateParams =
116 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
117 DE_NULL, // const void* pNext;
118 commandPool, // VkCommandPool commandPool;
119 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
120 1u, // deUint32 bufferCount;
122 return allocateCommandBuffer(vk, device, &bufferAllocateParams);
125 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
126 const VkDevice device)
128 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
130 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
131 DE_NULL, // const void* pNext;
132 0u, // VkPipelineLayoutCreateFlags flags;
133 0u, // deUint32 setLayoutCount;
134 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts;
135 0u, // deUint32 pushConstantRangeCount;
136 DE_NULL, // const VkPushConstantRange* pPushConstantRanges;
138 return createPipelineLayout(vk, device, &pipelineLayoutParams);
141 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
142 const VkDevice device,
143 const VkDescriptorSetLayout descriptorSetLayout)
145 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
147 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
148 DE_NULL, // const void* pNext;
149 0u, // VkPipelineLayoutCreateFlags flags;
150 1u, // deUint32 setLayoutCount;
151 &descriptorSetLayout, // const VkDescriptorSetLayout* pSetLayouts;
152 0u, // deUint32 pushConstantRangeCount;
153 DE_NULL, // const VkPushConstantRange* pPushConstantRanges;
155 return createPipelineLayout(vk, device, &pipelineLayoutParams);
158 Move<VkPipeline> makeComputePipeline (const DeviceInterface& vk,
159 const VkDevice device,
160 const VkPipelineLayout pipelineLayout,
161 const VkShaderModule shaderModule)
163 const VkPipelineShaderStageCreateInfo pipelineShaderStageParams =
165 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
166 DE_NULL, // const void* pNext;
167 0u, // VkPipelineShaderStageCreateFlags flags;
168 VK_SHADER_STAGE_COMPUTE_BIT, // VkShaderStageFlagBits stage;
169 shaderModule, // VkShaderModule module;
170 "main", // const char* pName;
171 DE_NULL, // const VkSpecializationInfo* pSpecializationInfo;
173 const VkComputePipelineCreateInfo pipelineCreateInfo =
175 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType sType;
176 DE_NULL, // const void* pNext;
177 0u, // VkPipelineCreateFlags flags;
178 pipelineShaderStageParams, // VkPipelineShaderStageCreateInfo stage;
179 pipelineLayout, // VkPipelineLayout layout;
180 DE_NULL, // VkPipeline basePipelineHandle;
181 0, // deInt32 basePipelineIndex;
183 return createComputePipeline(vk, device, DE_NULL , &pipelineCreateInfo);
186 Move<VkBufferView> makeBufferView (const DeviceInterface& vk,
187 const VkDevice vkDevice,
188 const VkBuffer buffer,
189 const VkFormat format,
190 const VkDeviceSize offset,
191 const VkDeviceSize size)
193 const VkBufferViewCreateInfo bufferViewParams =
195 VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO, // VkStructureType sType;
196 DE_NULL, // const void* pNext;
197 0u, // VkBufferViewCreateFlags flags;
198 buffer, // VkBuffer buffer;
199 format, // VkFormat format;
200 offset, // VkDeviceSize offset;
201 size, // VkDeviceSize range;
203 return createBufferView(vk, vkDevice, &bufferViewParams);
206 Move<VkImageView> makeImageView (const DeviceInterface& vk,
207 const VkDevice vkDevice,
209 const VkImageViewType imageViewType,
210 const VkFormat format,
211 const VkImageSubresourceRange subresourceRange)
213 const VkImageViewCreateInfo imageViewParams =
215 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
216 DE_NULL, // const void* pNext;
217 0u, // VkImageViewCreateFlags flags;
218 image, // VkImage image;
219 imageViewType, // VkImageViewType viewType;
220 format, // VkFormat format;
221 makeComponentMappingRGBA(), // VkComponentMapping components;
222 subresourceRange, // VkImageSubresourceRange subresourceRange;
224 return createImageView(vk, vkDevice, &imageViewParams);
227 Move<VkDescriptorSet> makeDescriptorSet (const DeviceInterface& vk,
228 const VkDevice device,
229 const VkDescriptorPool descriptorPool,
230 const VkDescriptorSetLayout setLayout)
232 const VkDescriptorSetAllocateInfo allocateParams =
234 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType;
235 DE_NULL, // const void* pNext;
236 descriptorPool, // VkDescriptorPool descriptorPool;
237 1u, // deUint32 setLayoutCount;
238 &setLayout, // const VkDescriptorSetLayout* pSetLayouts;
240 return allocateDescriptorSet(vk, device, &allocateParams);
243 VkBufferMemoryBarrier makeBufferMemoryBarrier (const VkAccessFlags srcAccessMask,
244 const VkAccessFlags dstAccessMask,
245 const VkBuffer buffer,
246 const VkDeviceSize offset,
247 const VkDeviceSize bufferSizeBytes)
249 const VkBufferMemoryBarrier barrier =
251 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
252 DE_NULL, // const void* pNext;
253 srcAccessMask, // VkAccessFlags srcAccessMask;
254 dstAccessMask, // VkAccessFlags dstAccessMask;
255 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
256 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
257 buffer, // VkBuffer buffer;
258 offset, // VkDeviceSize offset;
259 bufferSizeBytes, // VkDeviceSize size;
264 VkImageMemoryBarrier makeImageMemoryBarrier (const VkAccessFlags srcAccessMask,
265 const VkAccessFlags dstAccessMask,
266 const VkImageLayout oldLayout,
267 const VkImageLayout newLayout,
269 const VkImageSubresourceRange subresourceRange)
271 const VkImageMemoryBarrier barrier =
273 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
274 DE_NULL, // const void* pNext;
275 srcAccessMask, // VkAccessFlags outputMask;
276 dstAccessMask, // VkAccessFlags inputMask;
277 oldLayout, // VkImageLayout oldLayout;
278 newLayout, // VkImageLayout newLayout;
279 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
280 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
281 image, // VkImage image;
282 subresourceRange, // VkImageSubresourceRange subresourceRange;
287 void beginCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
289 const VkCommandBufferBeginInfo commandBufBeginParams =
291 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
292 DE_NULL, // const void* pNext;
293 0u, // VkCommandBufferUsageFlags flags;
294 (const VkCommandBufferInheritanceInfo*)DE_NULL,
296 VK_CHECK(vk.beginCommandBuffer(commandBuffer, &commandBufBeginParams));
299 void endCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
301 VK_CHECK(vk.endCommandBuffer(commandBuffer));
304 void submitCommandsAndWait (const DeviceInterface& vk,
305 const VkDevice device,
307 const VkCommandBuffer commandBuffer)
309 const VkFenceCreateInfo fenceParams =
311 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
312 DE_NULL, // const void* pNext;
313 0u, // VkFenceCreateFlags flags;
315 const Unique<VkFence> fence(createFence(vk, device, &fenceParams));
317 const VkSubmitInfo submitInfo =
319 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
320 DE_NULL, // const void* pNext;
321 0u, // deUint32 waitSemaphoreCount;
322 DE_NULL, // const VkSemaphore* pWaitSemaphores;
323 (const VkPipelineStageFlags*)DE_NULL,
324 1u, // deUint32 commandBufferCount;
325 &commandBuffer, // const VkCommandBuffer* pCommandBuffers;
326 0u, // deUint32 signalSemaphoreCount;
327 DE_NULL, // const VkSemaphore* pSignalSemaphores;
330 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
331 VK_CHECK(vk.waitForFences(device, 1u, &fence.get(), DE_TRUE, ~0ull));