1 #ifndef _VKTCOMPUTETESTSUTIL_HPP
2 #define _VKTCOMPUTETESTSUTIL_HPP
3 /*------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
6 *
7 * Copyright (c) 2016 The Khronos Group Inc.
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 *//*!
22 * \file
23 * \brief Compute tests utility classes
24 *//*--------------------------------------------------------------------*/
25
26 #include "vkDefs.hpp"
27 #include "vkMemUtil.hpp"
28 #include "vkRef.hpp"
29 #include "vkRefUtil.hpp"
30 #include "vkPrograms.hpp"
31 #include "vkTypeUtil.hpp"
32 #include "vkImageUtil.hpp"
33
34 namespace vkt
35 {
36 namespace compute
37 {
38
39 class Buffer
40 {
41 public:
42 Buffer (const vk::DeviceInterface& vk,
43 const vk::VkDevice device,
44 vk::Allocator& allocator,
45 const vk::VkBufferCreateInfo& bufferCreateInfo,
46 const vk::MemoryRequirement memoryRequirement);
47
get(void) const48 const vk::VkBuffer& get (void) const { return *m_buffer; }
operator *(void) const49 const vk::VkBuffer& operator* (void) const { return get(); }
getAllocation(void) const50 vk::Allocation& getAllocation (void) const { return *m_allocation; }
51
52 private:
53 de::MovePtr<vk::Allocation> m_allocation;
54 vk::Move<vk::VkBuffer> m_buffer;
55
56 Buffer (const Buffer&); // "deleted"
57 Buffer& operator= (const Buffer&);
58 };
59
60 class Image
61 {
62 public:
63 Image (const vk::DeviceInterface& vk,
64 const vk::VkDevice device,
65 vk::Allocator& allocator,
66 const vk::VkImageCreateInfo& imageCreateInfo,
67 const vk::MemoryRequirement memoryRequirement);
68
get(void) const69 const vk::VkImage& get (void) const { return *m_image; }
operator *(void) const70 const vk::VkImage& operator* (void) const { return get(); }
getAllocation(void) const71 vk::Allocation& getAllocation (void) const { return *m_allocation; }
72
73 private:
74 de::MovePtr<vk::Allocation> m_allocation;
75 vk::Move<vk::VkImage> m_image;
76
77 Image (const Image&); // "deleted"
78 Image& operator= (const Image&);
79 };
80
81 vk::Move<vk::VkCommandPool> makeCommandPool (const vk::DeviceInterface& vk,
82 const vk::VkDevice device,
83 const deUint32 queueFamilyIndex);
84
85 vk::Move<vk::VkCommandBuffer> makeCommandBuffer (const vk::DeviceInterface& vk,
86 const vk::VkDevice device,
87 const vk::VkCommandPool commandPool);
88
89 vk::Move<vk::VkPipelineLayout> makePipelineLayout (const vk::DeviceInterface& vk,
90 const vk::VkDevice device);
91
92 vk::Move<vk::VkPipelineLayout> makePipelineLayout (const vk::DeviceInterface& vk,
93 const vk::VkDevice device,
94 const vk::VkDescriptorSetLayout descriptorSetLayout);
95
96 vk::Move<vk::VkPipeline> makeComputePipeline (const vk::DeviceInterface& vk,
97 const vk::VkDevice device,
98 const vk::VkPipelineLayout pipelineLayout,
99 const vk::VkShaderModule shaderModule);
100
101 vk::Move<vk::VkBufferView> makeBufferView (const vk::DeviceInterface& vk,
102 const vk::VkDevice device,
103 const vk::VkBuffer buffer,
104 const vk::VkFormat format,
105 const vk::VkDeviceSize offset,
106 const vk::VkDeviceSize size);
107
108 vk::Move<vk::VkImageView> makeImageView (const vk::DeviceInterface& vk,
109 const vk::VkDevice device,
110 const vk::VkImage image,
111 const vk::VkImageViewType imageViewType,
112 const vk::VkFormat format,
113 const vk::VkImageSubresourceRange subresourceRange);
114
115 vk::Move<vk::VkDescriptorSet> makeDescriptorSet (const vk::DeviceInterface& vk,
116 const vk::VkDevice device,
117 const vk::VkDescriptorPool descriptorPool,
118 const vk::VkDescriptorSetLayout setLayout);
119
120 vk::VkBufferCreateInfo makeBufferCreateInfo (const vk::VkDeviceSize bufferSize,
121 const vk::VkBufferUsageFlags usage);
122
123 vk::VkBufferImageCopy makeBufferImageCopy (const vk::VkExtent3D extent,
124 const deUint32 arraySize);
125
126 vk::VkBufferMemoryBarrier makeBufferMemoryBarrier (const vk::VkAccessFlags srcAccessMask,
127 const vk::VkAccessFlags dstAccessMask,
128 const vk::VkBuffer buffer,
129 const vk::VkDeviceSize offset,
130 const vk::VkDeviceSize bufferSizeBytes);
131
132 vk::VkImageMemoryBarrier makeImageMemoryBarrier (const vk::VkAccessFlags srcAccessMask,
133 const vk::VkAccessFlags dstAccessMask,
134 const vk::VkImageLayout oldLayout,
135 const vk::VkImageLayout newLayout,
136 const vk::VkImage image,
137 const vk::VkImageSubresourceRange subresourceRange);
138
139 void beginCommandBuffer (const vk::DeviceInterface& vk,
140 const vk::VkCommandBuffer cmdBuffer);
141
142 void endCommandBuffer (const vk::DeviceInterface& vk,
143 const vk::VkCommandBuffer cmdBuffer);
144
145 void submitCommandsAndWait (const vk::DeviceInterface& vk,
146 const vk::VkDevice device,
147 const vk::VkQueue queue,
148 const vk::VkCommandBuffer cmdBuffer);
149
makeExtent3D(const tcu::IVec3 & vec)150 inline vk::VkExtent3D makeExtent3D (const tcu::IVec3& vec)
151 {
152 return vk::makeExtent3D(vec.x(), vec.y(), vec.z());
153 }
154
getImageSizeBytes(const tcu::IVec3 & imageSize,const vk::VkFormat format)155 inline vk::VkDeviceSize getImageSizeBytes (const tcu::IVec3& imageSize, const vk::VkFormat format)
156 {
157 return tcu::getPixelSize(vk::mapVkFormat(format)) * imageSize.x() * imageSize.y() * imageSize.z();
158 }
159
160 } // compute
161 } // vkt
162
163 #endif // _VKTCOMPUTETESTSUTIL_HPP
164