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 #include "vkObjUtil.hpp"
34 
35 namespace vkt
36 {
37 namespace compute
38 {
39 
40 class Buffer
41 {
42 public:
43 									Buffer			(const vk::DeviceInterface&		vk,
44 													 const vk::VkDevice				device,
45 													 vk::Allocator&					allocator,
46 													 const vk::VkBufferCreateInfo&	bufferCreateInfo,
47 													 const vk::MemoryRequirement	memoryRequirement);
48 
get(void) const49 	const vk::VkBuffer&				get				(void) const { return *m_buffer; }
operator *(void) const50 	const vk::VkBuffer&				operator*		(void) const { return get(); }
getAllocation(void) const51 	vk::Allocation&					getAllocation	(void) const { return *m_allocation; }
52 
53 private:
54 	de::MovePtr<vk::Allocation>		m_allocation;
55 	vk::Move<vk::VkBuffer>			m_buffer;
56 
57 									Buffer			(const Buffer&);  // "deleted"
58 	Buffer&							operator=		(const Buffer&);
59 };
60 
61 class Image
62 {
63 public:
64 									Image			(const vk::DeviceInterface&		vk,
65 													 const vk::VkDevice				device,
66 													 vk::Allocator&					allocator,
67 													 const vk::VkImageCreateInfo&	imageCreateInfo,
68 													 const vk::MemoryRequirement	memoryRequirement);
69 
get(void) const70 	const vk::VkImage&				get				(void) const { return *m_image; }
operator *(void) const71 	const vk::VkImage&				operator*		(void) const { return get(); }
getAllocation(void) const72 	vk::Allocation&					getAllocation	(void) const { return *m_allocation; }
73 
74 private:
75 	de::MovePtr<vk::Allocation>		m_allocation;
76 	vk::Move<vk::VkImage>			m_image;
77 
78 									Image			(const Image&);  // "deleted"
79 	Image&							operator=		(const Image&);
80 };
81 
82 vk::Move<vk::VkPipeline>		makeComputePipeline				(const vk::DeviceInterface&					vk,
83 																 const vk::VkDevice							device,
84 																 const vk::VkPipelineLayout					pipelineLayout,
85 																 const vk::VkShaderModule					shaderModule);
86 
87 vk::Move<vk::VkPipeline>		makeComputePipeline				(const vk::DeviceInterface&					vk,
88 																 const vk::VkDevice							device,
89 																 const vk::VkPipelineLayout					pipelineLayout,
90 																 const vk::VkPipelineCreateFlags			pipelineFlags,
91 																 const vk::VkShaderModule					shaderModule,
92 																 const vk::VkPipelineShaderStageCreateFlags	shaderFlags);
93 
94 vk::VkBufferImageCopy			makeBufferImageCopy				(const vk::VkExtent3D						extent,
95 																 const deUint32								arraySize);
96 
makeExtent3D(const tcu::IVec3 & vec)97 inline vk::VkExtent3D makeExtent3D (const tcu::IVec3& vec)
98 {
99 	return vk::makeExtent3D(vec.x(), vec.y(), vec.z());
100 }
101 
getImageSizeBytes(const tcu::IVec3 & imageSize,const vk::VkFormat format)102 inline vk::VkDeviceSize getImageSizeBytes (const tcu::IVec3& imageSize, const vk::VkFormat format)
103 {
104 	return tcu::getPixelSize(vk::mapVkFormat(format)) * imageSize.x() * imageSize.y() * imageSize.z();
105 }
106 
107 } // compute
108 } // vkt
109 
110 #endif // _VKTCOMPUTETESTSUTIL_HPP
111