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<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
102 const VkDevice device)
104 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
106 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
107 DE_NULL, // const void* pNext;
108 0u, // VkPipelineLayoutCreateFlags flags;
109 0u, // deUint32 setLayoutCount;
110 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts;
111 0u, // deUint32 pushConstantRangeCount;
112 DE_NULL, // const VkPushConstantRange* pPushConstantRanges;
114 return createPipelineLayout(vk, device, &pipelineLayoutParams);
117 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
118 const VkDevice device,
119 const VkDescriptorSetLayout descriptorSetLayout)
121 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
123 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
124 DE_NULL, // const void* pNext;
125 0u, // VkPipelineLayoutCreateFlags flags;
126 1u, // deUint32 setLayoutCount;
127 &descriptorSetLayout, // const VkDescriptorSetLayout* pSetLayouts;
128 0u, // deUint32 pushConstantRangeCount;
129 DE_NULL, // const VkPushConstantRange* pPushConstantRanges;
131 return createPipelineLayout(vk, device, &pipelineLayoutParams);
134 Move<VkPipeline> makeComputePipeline (const DeviceInterface& vk,
135 const VkDevice device,
136 const VkPipelineLayout pipelineLayout,
137 const VkShaderModule shaderModule)
139 const VkPipelineShaderStageCreateInfo pipelineShaderStageParams =
141 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
142 DE_NULL, // const void* pNext;
143 0u, // VkPipelineShaderStageCreateFlags flags;
144 VK_SHADER_STAGE_COMPUTE_BIT, // VkShaderStageFlagBits stage;
145 shaderModule, // VkShaderModule module;
146 "main", // const char* pName;
147 DE_NULL, // const VkSpecializationInfo* pSpecializationInfo;
149 const VkComputePipelineCreateInfo pipelineCreateInfo =
151 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType sType;
152 DE_NULL, // const void* pNext;
153 0u, // VkPipelineCreateFlags flags;
154 pipelineShaderStageParams, // VkPipelineShaderStageCreateInfo stage;
155 pipelineLayout, // VkPipelineLayout layout;
156 DE_NULL, // VkPipeline basePipelineHandle;
157 0, // deInt32 basePipelineIndex;
159 return createComputePipeline(vk, device, DE_NULL , &pipelineCreateInfo);
162 Move<VkBufferView> makeBufferView (const DeviceInterface& vk,
163 const VkDevice vkDevice,
164 const VkBuffer buffer,
165 const VkFormat format,
166 const VkDeviceSize offset,
167 const VkDeviceSize size)
169 const VkBufferViewCreateInfo bufferViewParams =
171 VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO, // VkStructureType sType;
172 DE_NULL, // const void* pNext;
173 0u, // VkBufferViewCreateFlags flags;
174 buffer, // VkBuffer buffer;
175 format, // VkFormat format;
176 offset, // VkDeviceSize offset;
177 size, // VkDeviceSize range;
179 return createBufferView(vk, vkDevice, &bufferViewParams);
182 Move<VkImageView> makeImageView (const DeviceInterface& vk,
183 const VkDevice vkDevice,
185 const VkImageViewType imageViewType,
186 const VkFormat format,
187 const VkImageSubresourceRange subresourceRange)
189 const VkImageViewCreateInfo imageViewParams =
191 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
192 DE_NULL, // const void* pNext;
193 0u, // VkImageViewCreateFlags flags;
194 image, // VkImage image;
195 imageViewType, // VkImageViewType viewType;
196 format, // VkFormat format;
197 makeComponentMappingRGBA(), // VkComponentMapping components;
198 subresourceRange, // VkImageSubresourceRange subresourceRange;
200 return createImageView(vk, vkDevice, &imageViewParams);
203 Move<VkDescriptorSet> makeDescriptorSet (const DeviceInterface& vk,
204 const VkDevice device,
205 const VkDescriptorPool descriptorPool,
206 const VkDescriptorSetLayout setLayout)
208 const VkDescriptorSetAllocateInfo allocateParams =
210 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType;
211 DE_NULL, // const void* pNext;
212 descriptorPool, // VkDescriptorPool descriptorPool;
213 1u, // deUint32 setLayoutCount;
214 &setLayout, // const VkDescriptorSetLayout* pSetLayouts;
216 return allocateDescriptorSet(vk, device, &allocateParams);
219 VkBufferMemoryBarrier makeBufferMemoryBarrier (const VkAccessFlags srcAccessMask,
220 const VkAccessFlags dstAccessMask,
221 const VkBuffer buffer,
222 const VkDeviceSize offset,
223 const VkDeviceSize bufferSizeBytes)
225 const VkBufferMemoryBarrier barrier =
227 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
228 DE_NULL, // const void* pNext;
229 srcAccessMask, // VkAccessFlags srcAccessMask;
230 dstAccessMask, // VkAccessFlags dstAccessMask;
231 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
232 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
233 buffer, // VkBuffer buffer;
234 offset, // VkDeviceSize offset;
235 bufferSizeBytes, // VkDeviceSize size;
240 VkImageMemoryBarrier makeImageMemoryBarrier (const VkAccessFlags srcAccessMask,
241 const VkAccessFlags dstAccessMask,
242 const VkImageLayout oldLayout,
243 const VkImageLayout newLayout,
245 const VkImageSubresourceRange subresourceRange)
247 const VkImageMemoryBarrier barrier =
249 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
250 DE_NULL, // const void* pNext;
251 srcAccessMask, // VkAccessFlags outputMask;
252 dstAccessMask, // VkAccessFlags inputMask;
253 oldLayout, // VkImageLayout oldLayout;
254 newLayout, // VkImageLayout newLayout;
255 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
256 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
257 image, // VkImage image;
258 subresourceRange, // VkImageSubresourceRange subresourceRange;
263 void beginCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
265 const VkCommandBufferBeginInfo commandBufBeginParams =
267 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
268 DE_NULL, // const void* pNext;
269 0u, // VkCommandBufferUsageFlags flags;
270 (const VkCommandBufferInheritanceInfo*)DE_NULL,
272 VK_CHECK(vk.beginCommandBuffer(commandBuffer, &commandBufBeginParams));
275 void endCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
277 VK_CHECK(vk.endCommandBuffer(commandBuffer));
280 void submitCommandsAndWait (const DeviceInterface& vk,
281 const VkDevice device,
283 const VkCommandBuffer commandBuffer)
285 const Unique<VkFence> fence(createFence(vk, device));
287 const VkSubmitInfo submitInfo =
289 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
290 DE_NULL, // const void* pNext;
291 0u, // deUint32 waitSemaphoreCount;
292 DE_NULL, // const VkSemaphore* pWaitSemaphores;
293 (const VkPipelineStageFlags*)DE_NULL,
294 1u, // deUint32 commandBufferCount;
295 &commandBuffer, // const VkCommandBuffer* pCommandBuffers;
296 0u, // deUint32 signalSemaphoreCount;
297 DE_NULL, // const VkSemaphore* pSignalSemaphores;
300 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
301 VK_CHECK(vk.waitForFences(device, 1u, &fence.get(), DE_TRUE, ~0ull));