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 Object creation utilities
22 *//*--------------------------------------------------------------------*/
24 #include "vktFragmentOperationsMakeUtil.hpp"
25 #include "vkTypeUtil.hpp"
26 #include "vkPrograms.hpp"
27 #include "vkQueryUtil.hpp"
32 namespace FragmentOperations
37 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize bufferSize,
38 const VkBufferUsageFlags usage)
40 const VkBufferCreateInfo bufferCreateInfo =
42 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
43 DE_NULL, // const void* pNext;
44 (VkBufferCreateFlags)0, // VkBufferCreateFlags flags;
45 bufferSize, // VkDeviceSize size;
46 usage, // VkBufferUsageFlags usage;
47 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
48 0u, // deUint32 queueFamilyIndexCount;
49 DE_NULL, // const deUint32* pQueueFamilyIndices;
51 return bufferCreateInfo;
54 VkBufferMemoryBarrier makeBufferMemoryBarrier (const VkAccessFlags srcAccessMask,
55 const VkAccessFlags dstAccessMask,
56 const VkBuffer buffer,
57 const VkDeviceSize offset,
58 const VkDeviceSize bufferSizeBytes)
60 const VkBufferMemoryBarrier barrier =
62 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
63 DE_NULL, // const void* pNext;
64 srcAccessMask, // VkAccessFlags srcAccessMask;
65 dstAccessMask, // VkAccessFlags dstAccessMask;
66 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
67 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
68 buffer, // VkBuffer buffer;
69 offset, // VkDeviceSize offset;
70 bufferSizeBytes, // VkDeviceSize size;
75 VkImageMemoryBarrier makeImageMemoryBarrier (const VkAccessFlags srcAccessMask,
76 const VkAccessFlags dstAccessMask,
77 const VkImageLayout oldLayout,
78 const VkImageLayout newLayout,
80 const VkImageSubresourceRange subresourceRange)
82 const VkImageMemoryBarrier barrier =
84 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
85 DE_NULL, // const void* pNext;
86 srcAccessMask, // VkAccessFlags outputMask;
87 dstAccessMask, // VkAccessFlags inputMask;
88 oldLayout, // VkImageLayout oldLayout;
89 newLayout, // VkImageLayout newLayout;
90 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
91 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
92 image, // VkImage image;
93 subresourceRange, // VkImageSubresourceRange subresourceRange;
98 Move<VkDescriptorSet> makeDescriptorSet (const DeviceInterface& vk,
99 const VkDevice device,
100 const VkDescriptorPool descriptorPool,
101 const VkDescriptorSetLayout setLayout)
103 const VkDescriptorSetAllocateInfo info =
105 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType;
106 DE_NULL, // const void* pNext;
107 descriptorPool, // VkDescriptorPool descriptorPool;
108 1u, // deUint32 descriptorSetCount;
109 &setLayout, // const VkDescriptorSetLayout* pSetLayouts;
111 return allocateDescriptorSet(vk, device, &info);
114 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
115 const VkDevice device)
117 const VkPipelineLayoutCreateInfo info =
119 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
120 DE_NULL, // const void* pNext;
121 (VkPipelineLayoutCreateFlags)0, // 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, &info);
130 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
131 const VkDevice device,
132 const VkDescriptorSetLayout descriptorSetLayout)
134 const VkPipelineLayoutCreateInfo info =
136 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
137 DE_NULL, // const void* pNext;
138 (VkPipelineLayoutCreateFlags)0, // 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, &info);
147 Move<VkPipeline> makeComputePipeline (const DeviceInterface& vk,
148 const VkDevice device,
149 const VkPipelineLayout pipelineLayout,
150 const VkShaderModule shaderModule,
151 const VkSpecializationInfo* specInfo)
153 const VkPipelineShaderStageCreateInfo shaderStageInfo =
155 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
156 DE_NULL, // const void* pNext;
157 (VkPipelineShaderStageCreateFlags)0, // VkPipelineShaderStageCreateFlags flags;
158 VK_SHADER_STAGE_COMPUTE_BIT, // VkShaderStageFlagBits stage;
159 shaderModule, // VkShaderModule module;
160 "main", // const char* pName;
161 specInfo, // const VkSpecializationInfo* pSpecializationInfo;
163 const VkComputePipelineCreateInfo pipelineInfo =
165 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType sType;
166 DE_NULL, // const void* pNext;
167 (VkPipelineCreateFlags)0, // VkPipelineCreateFlags flags;
168 shaderStageInfo, // VkPipelineShaderStageCreateInfo stage;
169 pipelineLayout, // VkPipelineLayout layout;
170 DE_NULL, // VkPipeline basePipelineHandle;
171 0, // deInt32 basePipelineIndex;
173 return createComputePipeline(vk, device, DE_NULL , &pipelineInfo);
176 Move<VkImageView> makeImageView (const DeviceInterface& vk,
177 const VkDevice vkDevice,
179 const VkImageViewType viewType,
180 const VkFormat format,
181 const VkImageSubresourceRange subresourceRange)
183 const VkImageViewCreateInfo imageViewParams =
185 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
186 DE_NULL, // const void* pNext;
187 (VkImageViewCreateFlags)0, // VkImageViewCreateFlags flags;
188 image, // VkImage image;
189 viewType, // VkImageViewType viewType;
190 format, // VkFormat format;
191 makeComponentMappingRGBA(), // VkComponentMapping components;
192 subresourceRange, // VkImageSubresourceRange subresourceRange;
194 return createImageView(vk, vkDevice, &imageViewParams);
197 void beginCommandBuffer (const DeviceInterface& vk, const VkCommandBuffer commandBuffer)
199 const VkCommandBufferBeginInfo info =
201 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
202 DE_NULL, // const void* pNext;
203 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
204 DE_NULL, // const VkCommandBufferInheritanceInfo* pInheritanceInfo;
206 VK_CHECK(vk.beginCommandBuffer(commandBuffer, &info));
209 void submitCommandsAndWait (const DeviceInterface& vk,
210 const VkDevice device,
212 const VkCommandBuffer commandBuffer)
214 const Unique<VkFence> fence(createFence(vk, device));
216 const VkSubmitInfo submitInfo =
218 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
219 DE_NULL, // const void* pNext;
220 0u, // uint32_t waitSemaphoreCount;
221 DE_NULL, // const VkSemaphore* pWaitSemaphores;
222 DE_NULL, // const VkPipelineStageFlags* pWaitDstStageMask;
223 1u, // uint32_t commandBufferCount;
224 &commandBuffer, // const VkCommandBuffer* pCommandBuffers;
225 0u, // uint32_t signalSemaphoreCount;
226 DE_NULL, // const VkSemaphore* pSignalSemaphores;
228 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
229 VK_CHECK(vk.waitForFences(device, 1u, &fence.get(), DE_TRUE, ~0ull));
232 Move<VkFramebuffer> makeFramebuffer (const DeviceInterface& vk,
233 const VkDevice device,
234 const VkRenderPass renderPass,
235 const deUint32 attachmentCount,
236 const VkImageView* pAttachments,
237 const deUint32 width,
238 const deUint32 height,
239 const deUint32 layers)
241 const VkFramebufferCreateInfo framebufferInfo = {
242 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
243 DE_NULL, // const void* pNext;
244 (VkFramebufferCreateFlags)0, // VkFramebufferCreateFlags flags;
245 renderPass, // VkRenderPass renderPass;
246 attachmentCount, // uint32_t attachmentCount;
247 pAttachments, // const VkImageView* pAttachments;
248 width, // uint32_t width;
249 height, // uint32_t height;
250 layers, // uint32_t layers;
253 return createFramebuffer(vk, device, &framebufferInfo);
256 MovePtr<Allocation> bindImage (const DeviceInterface& vk, const VkDevice device, Allocator& allocator, const VkImage image, const MemoryRequirement requirement)
258 MovePtr<Allocation> alloc = allocator.allocate(getImageMemoryRequirements(vk, device, image), requirement);
259 VK_CHECK(vk.bindImageMemory(device, image, alloc->getMemory(), alloc->getOffset()));
263 MovePtr<Allocation> bindBuffer (const DeviceInterface& vk, const VkDevice device, Allocator& allocator, const VkBuffer buffer, const MemoryRequirement requirement)
265 MovePtr<Allocation> alloc(allocator.allocate(getBufferMemoryRequirements(vk, device, buffer), requirement));
266 VK_CHECK(vk.bindBufferMemory(device, buffer, alloc->getMemory(), alloc->getOffset()));
270 } // FragmentOperations