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
34namespace vkt
35{
36namespace compute
37{
38
39class Buffer
40{
41public:
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
48	const vk::VkBuffer&				get				(void) const { return *m_buffer; }
49	const vk::VkBuffer&				operator*		(void) const { return get(); }
50	vk::Allocation&					getAllocation	(void) const { return *m_allocation; }
51
52private:
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
60class Image
61{
62public:
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
69	const vk::VkImage&				get				(void) const { return *m_image; }
70	const vk::VkImage&				operator*		(void) const { return get(); }
71	vk::Allocation&					getAllocation	(void) const { return *m_allocation; }
72
73private:
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
81vk::Move<vk::VkCommandPool>			makeCommandPool				(const vk::DeviceInterface&			vk,
82																 const vk::VkDevice					device,
83																 const deUint32						queueFamilyIndex);
84
85vk::Move<vk::VkCommandBuffer>		makeCommandBuffer			(const vk::DeviceInterface&			vk,
86																 const vk::VkDevice					device,
87																 const vk::VkCommandPool			commandPool);
88
89vk::Move<vk::VkPipelineLayout>	makePipelineLayout				(const vk::DeviceInterface&			vk,
90																 const vk::VkDevice					device);
91
92vk::Move<vk::VkPipelineLayout>	makePipelineLayout				(const vk::DeviceInterface&			vk,
93																 const vk::VkDevice					device,
94																 const vk::VkDescriptorSetLayout	descriptorSetLayout);
95
96vk::Move<vk::VkPipeline>		makeComputePipeline				(const vk::DeviceInterface&			vk,
97																 const vk::VkDevice					device,
98																 const vk::VkPipelineLayout			pipelineLayout,
99																 const vk::VkShaderModule			shaderModule);
100
101vk::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
108vk::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
115vk::Move<vk::VkDescriptorSet>	makeDescriptorSet				(const vk::DeviceInterface&			vk,
116																 const vk::VkDevice					device,
117																 const vk::VkDescriptorPool			descriptorPool,
118																 const vk::VkDescriptorSetLayout	setLayout);
119
120vk::VkBufferCreateInfo			makeBufferCreateInfo			(const vk::VkDeviceSize				bufferSize,
121																 const vk::VkBufferUsageFlags		usage);
122
123vk::VkBufferImageCopy			makeBufferImageCopy				(const vk::VkExtent3D				extent,
124																 const deUint32						arraySize);
125
126vk::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
132vk::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
139void							beginCommandBuffer				(const vk::DeviceInterface&			vk,
140																 const vk::VkCommandBuffer			cmdBuffer);
141
142void							endCommandBuffer				(const vk::DeviceInterface&			vk,
143																 const vk::VkCommandBuffer			cmdBuffer);
144
145void							submitCommandsAndWait			(const vk::DeviceInterface&			vk,
146																 const vk::VkDevice					device,
147																 const vk::VkQueue					queue,
148																 const vk::VkCommandBuffer			cmdBuffer);
149
150inline vk::VkExtent3D makeExtent3D (const tcu::IVec3& vec)
151{
152	return vk::makeExtent3D(vec.x(), vec.y(), vec.z());
153}
154
155inline 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