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 Compute tests utility classes
22 *//*--------------------------------------------------------------------*/
24 #include "vktComputeTestsUtil.hpp"
25 #include "vkQueryUtil.hpp"
26 #include "vkTypeUtil.hpp"
35 Buffer::Buffer (const DeviceInterface& vk,
36 const VkDevice device,
38 const VkBufferCreateInfo& bufferCreateInfo,
39 const MemoryRequirement memoryRequirement)
41 m_buffer = createBuffer(vk, device, &bufferCreateInfo);
42 m_allocation = allocator.allocate(getBufferMemoryRequirements(vk, device, *m_buffer), memoryRequirement);
43 VK_CHECK(vk.bindBufferMemory(device, *m_buffer, m_allocation->getMemory(), m_allocation->getOffset()));
46 Image::Image (const DeviceInterface& vk,
47 const VkDevice device,
49 const VkImageCreateInfo& imageCreateInfo,
50 const MemoryRequirement memoryRequirement)
52 m_image = createImage(vk, device, &imageCreateInfo);
53 m_allocation = allocator.allocate(getImageMemoryRequirements(vk, device, *m_image), memoryRequirement);
54 VK_CHECK(vk.bindImageMemory(device, *m_image, m_allocation->getMemory(), m_allocation->getOffset()));
57 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize bufferSize,
58 const VkBufferUsageFlags usage)
60 const VkBufferCreateInfo bufferCreateInfo =
62 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
63 DE_NULL, // const void* pNext;
64 0u, // VkBufferCreateFlags flags;
65 bufferSize, // VkDeviceSize size;
66 usage, // VkBufferUsageFlags usage;
67 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
68 0u, // deUint32 queueFamilyIndexCount;
69 DE_NULL, // const deUint32* pQueueFamilyIndices;
71 return bufferCreateInfo;
74 VkBufferImageCopy makeBufferImageCopy (const VkExtent3D extent,
75 const deUint32 arraySize)
77 const VkBufferImageCopy copyParams =
79 0ull, // VkDeviceSize bufferOffset;
80 0u, // deUint32 bufferRowLength;
81 0u, // deUint32 bufferImageHeight;
82 makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, arraySize), // VkImageSubresourceLayers imageSubresource;
83 makeOffset3D(0, 0, 0), // VkOffset3D imageOffset;
84 extent, // VkExtent3D imageExtent;
89 Move<VkCommandPool> makeCommandPool (const DeviceInterface& vk, const VkDevice device, const deUint32 queueFamilyIndex)
91 const VkCommandPoolCreateInfo commandPoolParams =
93 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
94 DE_NULL, // const void* pNext;
95 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags;
96 queueFamilyIndex, // deUint32 queueFamilyIndex;
98 return createCommandPool(vk, device, &commandPoolParams);
101 Move<VkCommandBuffer> makeCommandBuffer (const DeviceInterface& vk, const VkDevice device, const VkCommandPool commandPool)
103 const VkCommandBufferAllocateInfo bufferAllocateParams =
105 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
106 DE_NULL, // const void* pNext;
107 commandPool, // VkCommandPool commandPool;
108 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
109 1u, // deUint32 bufferCount;
111 return allocateCommandBuffer(vk, device, &bufferAllocateParams);
114 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
115 const VkDevice device)
117 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
119 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
120 DE_NULL, // const void* pNext;
121 0u, // VkPipelineLayoutCreateFlags flags;
122 0u, // deUint32 setLayoutCount;
123 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts;
124 0u, // deUint32 pushConstantRangeCount;
125 DE_NULL, // const VkPushConstantRange* pPushConstantRanges;
127 return createPipelineLayout(vk, device, &pipelineLayoutParams);
130 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
131 const VkDevice device,
132 const VkDescriptorSetLayout descriptorSetLayout)
134 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
136 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
137 DE_NULL, // const void* pNext;
138 0u, // VkPipelineLayoutCreateFlags flags;
139 1u, // deUint32 setLayoutCount;
140 &descriptorSetLayout, // const VkDescriptorSetLayout* pSetLayouts;
141 0u, // deUint32 pushConstantRangeCount;
142 DE_NULL, // const VkPushConstantRange* pPushConstantRanges;
144 return createPipelineLayout(vk, device, &pipelineLayoutParams);
147 Move<VkPipeline> makeComputePipeline (const DeviceInterface& vk,
148 const VkDevice device,
149 const VkPipelineLayout pipelineLayout,
150 const VkShaderModule shaderModule)
152 const VkPipelineShaderStageCreateInfo pipelineShaderStageParams =
154 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
155 DE_NULL, // const void* pNext;
156 0u, // VkPipelineShaderStageCreateFlags flags;
157 VK_SHADER_STAGE_COMPUTE_BIT, // VkShaderStageFlagBits stage;
158 shaderModule, // VkShaderModule module;
159 "main", // const char* pName;
160 DE_NULL, // const VkSpecializationInfo* pSpecializationInfo;
162 const VkComputePipelineCreateInfo pipelineCreateInfo =
164 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType sType;
165 DE_NULL, // const void* pNext;
166 0u, // VkPipelineCreateFlags flags;
167 pipelineShaderStageParams, // VkPipelineShaderStageCreateInfo stage;
168 pipelineLayout, // VkPipelineLayout layout;
169 DE_NULL, // VkPipeline basePipelineHandle;
170 0, // deInt32 basePipelineIndex;
172 return createComputePipeline(vk, device, DE_NULL , &pipelineCreateInfo);
175 Move<VkBufferView> makeBufferView (const DeviceInterface& vk,
176 const VkDevice vkDevice,
177 const VkBuffer buffer,
178 const VkFormat format,
179 const VkDeviceSize offset,
180 const VkDeviceSize size)
182 const VkBufferViewCreateInfo bufferViewParams =
184 VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO, // VkStructureType sType;
185 DE_NULL, // const void* pNext;
186 0u, // VkBufferViewCreateFlags flags;
187 buffer, // VkBuffer buffer;
188 format, // VkFormat format;
189 offset, // VkDeviceSize offset;
190 size, // VkDeviceSize range;
192 return createBufferView(vk, vkDevice, &bufferViewParams);
195 Move<VkImageView> makeImageView (const DeviceInterface& vk,
196 const VkDevice vkDevice,
198 const VkImageViewType imageViewType,
199 const VkFormat format,
200 const VkImageSubresourceRange subresourceRange)
202 const VkImageViewCreateInfo imageViewParams =
204 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
205 DE_NULL, // const void* pNext;
206 0u, // VkImageViewCreateFlags flags;
207 image, // VkImage image;
208 imageViewType, // VkImageViewType viewType;
209 format, // VkFormat format;
210 makeComponentMappingRGBA(), // VkComponentMapping components;
211 subresourceRange, // VkImageSubresourceRange subresourceRange;
213 return createImageView(vk, vkDevice, &imageViewParams);
216 Move<VkDescriptorSet> makeDescriptorSet (const DeviceInterface& vk,
217 const VkDevice device,
218 const VkDescriptorPool descriptorPool,
219 const VkDescriptorSetLayout setLayout)
221 const VkDescriptorSetAllocateInfo allocateParams =
223 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType;
224 DE_NULL, // const void* pNext;
225 descriptorPool, // VkDescriptorPool descriptorPool;
226 1u, // deUint32 setLayoutCount;
227 &setLayout, // const VkDescriptorSetLayout* pSetLayouts;
229 return allocateDescriptorSet(vk, device, &allocateParams);
232 VkBufferMemoryBarrier makeBufferMemoryBarrier (const VkAccessFlags srcAccessMask,
233 const VkAccessFlags dstAccessMask,
234 const VkBuffer buffer,
235 const VkDeviceSize offset,
236 const VkDeviceSize bufferSizeBytes)
238 const VkBufferMemoryBarrier barrier =
240 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
241 DE_NULL, // const void* pNext;
242 srcAccessMask, // VkAccessFlags srcAccessMask;
243 dstAccessMask, // VkAccessFlags dstAccessMask;
244 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
245 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
246 buffer, // VkBuffer buffer;
247 offset, // VkDeviceSize offset;
248 bufferSizeBytes, // VkDeviceSize size;
253 VkImageMemoryBarrier makeImageMemoryBarrier (const VkAccessFlags srcAccessMask,
254 const VkAccessFlags dstAccessMask,
255 const VkImageLayout oldLayout,
256 const VkImageLayout newLayout,
258 const VkImageSubresourceRange subresourceRange)
260 const VkImageMemoryBarrier barrier =
262 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
263 DE_NULL, // const void* pNext;
264 srcAccessMask, // VkAccessFlags outputMask;
265 dstAccessMask, // VkAccessFlags inputMask;
266 oldLayout, // VkImageLayout oldLayout;
267 newLayout, // VkImageLayout newLayout;
268 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
269 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
270 image, // VkImage image;
271 subresourceRange, // VkImageSubresourceRange subresourceRange;
276 void beginCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
278 const VkCommandBufferBeginInfo commandBufBeginParams =
280 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
281 DE_NULL, // const void* pNext;
282 0u, // VkCommandBufferUsageFlags flags;
283 (const VkCommandBufferInheritanceInfo*)DE_NULL,
285 VK_CHECK(vk.beginCommandBuffer(commandBuffer, &commandBufBeginParams));
288 void endCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
290 VK_CHECK(vk.endCommandBuffer(commandBuffer));
293 void submitCommandsAndWait (const DeviceInterface& vk,
294 const VkDevice device,
296 const VkCommandBuffer commandBuffer)
298 const VkFenceCreateInfo fenceParams =
300 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
301 DE_NULL, // const void* pNext;
302 0u, // VkFenceCreateFlags flags;
304 const Unique<VkFence> fence(createFence(vk, device, &fenceParams));
306 const VkSubmitInfo submitInfo =
308 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
309 DE_NULL, // const void* pNext;
310 0u, // deUint32 waitSemaphoreCount;
311 DE_NULL, // const VkSemaphore* pWaitSemaphores;
312 (const VkPipelineStageFlags*)DE_NULL,
313 1u, // deUint32 commandBufferCount;
314 &commandBuffer, // const VkCommandBuffer* pCommandBuffers;
315 0u, // deUint32 signalSemaphoreCount;
316 DE_NULL, // const VkSemaphore* pSignalSemaphores;
319 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
320 VK_CHECK(vk.waitForFences(device, 1u, &fence.get(), DE_TRUE, ~0ull));