1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2016 The Khronos Group Inc.
6 *
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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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.
18 *
19 *//*!
20 * \file
21 * \brief Object creation utilities
22 *//*--------------------------------------------------------------------*/
23
24 #include "vktFragmentOperationsMakeUtil.hpp"
25 #include "vkTypeUtil.hpp"
26 #include "vkPrograms.hpp"
27 #include "vkQueryUtil.hpp"
28 #include "vkCmdUtil.hpp"
29 #include <vector>
30
31 namespace vkt
32 {
33 namespace FragmentOperations
34 {
35 using namespace vk;
36 using de::MovePtr;
37
makeBufferCreateInfo(const VkDeviceSize bufferSize,const VkBufferUsageFlags usage)38 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize bufferSize,
39 const VkBufferUsageFlags usage)
40 {
41 const VkBufferCreateInfo bufferCreateInfo =
42 {
43 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
44 DE_NULL, // const void* pNext;
45 (VkBufferCreateFlags)0, // VkBufferCreateFlags flags;
46 bufferSize, // VkDeviceSize size;
47 usage, // VkBufferUsageFlags usage;
48 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
49 0u, // deUint32 queueFamilyIndexCount;
50 DE_NULL, // const deUint32* pQueueFamilyIndices;
51 };
52 return bufferCreateInfo;
53 }
54
makeDescriptorSet(const DeviceInterface & vk,const VkDevice device,const VkDescriptorPool descriptorPool,const VkDescriptorSetLayout setLayout)55 Move<VkDescriptorSet> makeDescriptorSet (const DeviceInterface& vk,
56 const VkDevice device,
57 const VkDescriptorPool descriptorPool,
58 const VkDescriptorSetLayout setLayout)
59 {
60 const VkDescriptorSetAllocateInfo info =
61 {
62 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructureType sType;
63 DE_NULL, // const void* pNext;
64 descriptorPool, // VkDescriptorPool descriptorPool;
65 1u, // deUint32 descriptorSetCount;
66 &setLayout, // const VkDescriptorSetLayout* pSetLayouts;
67 };
68 return allocateDescriptorSet(vk, device, &info);
69 }
70
makePipelineLayout(const DeviceInterface & vk,const VkDevice device)71 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
72 const VkDevice device)
73 {
74 const VkPipelineLayoutCreateInfo info =
75 {
76 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
77 DE_NULL, // const void* pNext;
78 (VkPipelineLayoutCreateFlags)0, // VkPipelineLayoutCreateFlags flags;
79 0u, // deUint32 setLayoutCount;
80 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts;
81 0u, // deUint32 pushConstantRangeCount;
82 DE_NULL, // const VkPushConstantRange* pPushConstantRanges;
83 };
84 return createPipelineLayout(vk, device, &info);
85 }
86
makePipelineLayout(const DeviceInterface & vk,const VkDevice device,const VkDescriptorSetLayout descriptorSetLayout)87 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
88 const VkDevice device,
89 const VkDescriptorSetLayout descriptorSetLayout)
90 {
91 const VkPipelineLayoutCreateInfo info =
92 {
93 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
94 DE_NULL, // const void* pNext;
95 (VkPipelineLayoutCreateFlags)0, // VkPipelineLayoutCreateFlags flags;
96 1u, // deUint32 setLayoutCount;
97 &descriptorSetLayout, // const VkDescriptorSetLayout* pSetLayouts;
98 0u, // deUint32 pushConstantRangeCount;
99 DE_NULL, // const VkPushConstantRange* pPushConstantRanges;
100 };
101 return createPipelineLayout(vk, device, &info);
102 }
103
makeComputePipeline(const DeviceInterface & vk,const VkDevice device,const VkPipelineLayout pipelineLayout,const VkShaderModule shaderModule,const VkSpecializationInfo * specInfo)104 Move<VkPipeline> makeComputePipeline (const DeviceInterface& vk,
105 const VkDevice device,
106 const VkPipelineLayout pipelineLayout,
107 const VkShaderModule shaderModule,
108 const VkSpecializationInfo* specInfo)
109 {
110 const VkPipelineShaderStageCreateInfo shaderStageInfo =
111 {
112 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
113 DE_NULL, // const void* pNext;
114 (VkPipelineShaderStageCreateFlags)0, // VkPipelineShaderStageCreateFlags flags;
115 VK_SHADER_STAGE_COMPUTE_BIT, // VkShaderStageFlagBits stage;
116 shaderModule, // VkShaderModule module;
117 "main", // const char* pName;
118 specInfo, // const VkSpecializationInfo* pSpecializationInfo;
119 };
120 const VkComputePipelineCreateInfo pipelineInfo =
121 {
122 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType sType;
123 DE_NULL, // const void* pNext;
124 (VkPipelineCreateFlags)0, // VkPipelineCreateFlags flags;
125 shaderStageInfo, // VkPipelineShaderStageCreateInfo stage;
126 pipelineLayout, // VkPipelineLayout layout;
127 DE_NULL, // VkPipeline basePipelineHandle;
128 0, // deInt32 basePipelineIndex;
129 };
130 return createComputePipeline(vk, device, DE_NULL , &pipelineInfo);
131 }
132
makeImageView(const DeviceInterface & vk,const VkDevice vkDevice,const VkImage image,const VkImageViewType viewType,const VkFormat format,const VkImageSubresourceRange subresourceRange)133 Move<VkImageView> makeImageView (const DeviceInterface& vk,
134 const VkDevice vkDevice,
135 const VkImage image,
136 const VkImageViewType viewType,
137 const VkFormat format,
138 const VkImageSubresourceRange subresourceRange)
139 {
140 const VkImageViewCreateInfo imageViewParams =
141 {
142 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
143 DE_NULL, // const void* pNext;
144 (VkImageViewCreateFlags)0, // VkImageViewCreateFlags flags;
145 image, // VkImage image;
146 viewType, // VkImageViewType viewType;
147 format, // VkFormat format;
148 makeComponentMappingRGBA(), // VkComponentMapping components;
149 subresourceRange, // VkImageSubresourceRange subresourceRange;
150 };
151 return createImageView(vk, vkDevice, &imageViewParams);
152 }
153
makeFramebuffer(const DeviceInterface & vk,const VkDevice device,const VkRenderPass renderPass,const deUint32 attachmentCount,const VkImageView * pAttachments,const deUint32 width,const deUint32 height,const deUint32 layers)154 Move<VkFramebuffer> makeFramebuffer (const DeviceInterface& vk,
155 const VkDevice device,
156 const VkRenderPass renderPass,
157 const deUint32 attachmentCount,
158 const VkImageView* pAttachments,
159 const deUint32 width,
160 const deUint32 height,
161 const deUint32 layers)
162 {
163 const VkFramebufferCreateInfo framebufferInfo = {
164 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
165 DE_NULL, // const void* pNext;
166 (VkFramebufferCreateFlags)0, // VkFramebufferCreateFlags flags;
167 renderPass, // VkRenderPass renderPass;
168 attachmentCount, // uint32_t attachmentCount;
169 pAttachments, // const VkImageView* pAttachments;
170 width, // uint32_t width;
171 height, // uint32_t height;
172 layers, // uint32_t layers;
173 };
174
175 return createFramebuffer(vk, device, &framebufferInfo);
176 }
177
bindImage(const DeviceInterface & vk,const VkDevice device,Allocator & allocator,const VkImage image,const MemoryRequirement requirement)178 MovePtr<Allocation> bindImage (const DeviceInterface& vk, const VkDevice device, Allocator& allocator, const VkImage image, const MemoryRequirement requirement)
179 {
180 MovePtr<Allocation> alloc = allocator.allocate(getImageMemoryRequirements(vk, device, image), requirement);
181 VK_CHECK(vk.bindImageMemory(device, image, alloc->getMemory(), alloc->getOffset()));
182 return alloc;
183 }
184
bindBuffer(const DeviceInterface & vk,const VkDevice device,Allocator & allocator,const VkBuffer buffer,const MemoryRequirement requirement)185 MovePtr<Allocation> bindBuffer (const DeviceInterface& vk, const VkDevice device, Allocator& allocator, const VkBuffer buffer, const MemoryRequirement requirement)
186 {
187 MovePtr<Allocation> alloc(allocator.allocate(getBufferMemoryRequirements(vk, device, buffer), requirement));
188 VK_CHECK(vk.bindBufferMemory(device, buffer, alloc->getMemory(), alloc->getOffset()));
189 return alloc;
190 }
191
192 } // FragmentOperations
193 } // vkt
194