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 "vktPipelineMakeUtil.hpp"
25 #include "vkTypeUtil.hpp"
26 #include "vkPrograms.hpp"
27 #include "vkRefUtil.hpp"
28 #include "vkQueryUtil.hpp"
29 #include <vector>
30
31 namespace vkt
32 {
33 namespace pipeline
34 {
35 using namespace vk;
36 using de::MovePtr;
37
Buffer(const vk::DeviceInterface & vk,const vk::VkDevice device,vk::Allocator & allocator,const vk::VkBufferCreateInfo & bufferCreateInfo,const vk::MemoryRequirement memoryRequirement)38 Buffer::Buffer (const vk::DeviceInterface& vk,
39 const vk::VkDevice device,
40 vk::Allocator& allocator,
41 const vk::VkBufferCreateInfo& bufferCreateInfo,
42 const vk::MemoryRequirement memoryRequirement)
43 : m_buffer (createBuffer(vk, device, &bufferCreateInfo))
44 , m_allocation (bindBuffer(vk, device, allocator, *m_buffer, memoryRequirement))
45 {
46 }
47
Image(const vk::DeviceInterface & vk,const vk::VkDevice device,vk::Allocator & allocator,const vk::VkImageCreateInfo & imageCreateInfo,const vk::MemoryRequirement memoryRequirement)48 Image::Image (const vk::DeviceInterface& vk,
49 const vk::VkDevice device,
50 vk::Allocator& allocator,
51 const vk::VkImageCreateInfo& imageCreateInfo,
52 const vk::MemoryRequirement memoryRequirement)
53 : m_image (createImage(vk, device, &imageCreateInfo))
54 , m_allocation (bindImage(vk, device, allocator, *m_image, memoryRequirement))
55 {
56 }
57
makeCommandBuffer(const DeviceInterface & vk,const VkDevice device,const VkCommandPool commandPool)58 Move<VkCommandBuffer> makeCommandBuffer (const DeviceInterface& vk, const VkDevice device, const VkCommandPool commandPool)
59 {
60 return allocateCommandBuffer(vk, device, commandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
61 }
62
makeComputePipeline(const DeviceInterface & vk,const VkDevice device,const VkPipelineLayout pipelineLayout,const VkShaderModule shaderModule,const VkSpecializationInfo * specInfo)63 Move<VkPipeline> makeComputePipeline (const DeviceInterface& vk,
64 const VkDevice device,
65 const VkPipelineLayout pipelineLayout,
66 const VkShaderModule shaderModule,
67 const VkSpecializationInfo* specInfo)
68 {
69 const VkPipelineShaderStageCreateInfo shaderStageInfo =
70 {
71 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
72 DE_NULL, // const void* pNext;
73 (VkPipelineShaderStageCreateFlags)0, // VkPipelineShaderStageCreateFlags flags;
74 VK_SHADER_STAGE_COMPUTE_BIT, // VkShaderStageFlagBits stage;
75 shaderModule, // VkShaderModule module;
76 "main", // const char* pName;
77 specInfo, // const VkSpecializationInfo* pSpecializationInfo;
78 };
79 const VkComputePipelineCreateInfo pipelineInfo =
80 {
81 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType sType;
82 DE_NULL, // const void* pNext;
83 (VkPipelineCreateFlags)0, // VkPipelineCreateFlags flags;
84 shaderStageInfo, // VkPipelineShaderStageCreateInfo stage;
85 pipelineLayout, // VkPipelineLayout layout;
86 DE_NULL, // VkPipeline basePipelineHandle;
87 0, // deInt32 basePipelineIndex;
88 };
89 return createComputePipeline(vk, device, DE_NULL , &pipelineInfo);
90 }
91
bindImageDedicated(const InstanceInterface & vki,const DeviceInterface & vkd,const VkPhysicalDevice physDevice,const VkDevice device,const VkImage image,const MemoryRequirement requirement)92 MovePtr<Allocation> bindImageDedicated (const InstanceInterface& vki, const DeviceInterface& vkd, const VkPhysicalDevice physDevice, const VkDevice device, const VkImage image, const MemoryRequirement requirement)
93 {
94 MovePtr<Allocation> alloc(allocateDedicated(vki, vkd, physDevice, device, image, requirement));
95 VK_CHECK(vkd.bindImageMemory(device, image, alloc->getMemory(), alloc->getOffset()));
96 return alloc;
97 }
98
bindBufferDedicated(const InstanceInterface & vki,const DeviceInterface & vkd,const VkPhysicalDevice physDevice,const VkDevice device,const VkBuffer buffer,const MemoryRequirement requirement)99 MovePtr<Allocation> bindBufferDedicated (const InstanceInterface& vki, const DeviceInterface& vkd, const VkPhysicalDevice physDevice, const VkDevice device, const VkBuffer buffer, const MemoryRequirement requirement)
100 {
101 MovePtr<Allocation> alloc(allocateDedicated(vki, vkd, physDevice, device, buffer, requirement));
102 VK_CHECK(vkd.bindBufferMemory(device, buffer, alloc->getMemory(), alloc->getOffset()));
103 return alloc;
104 }
105
106 } // pipeline
107 } // vkt
108