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::VkPipelineLayout> makePipelineLayout (const vk::DeviceInterface& vk,
86 const vk::VkDevice device);
87
88 vk::Move<vk::VkPipelineLayout> makePipelineLayout (const vk::DeviceInterface& vk,
89 const vk::VkDevice device,
90 const vk::VkDescriptorSetLayout descriptorSetLayout);
91
92 vk::Move<vk::VkPipeline> makeComputePipeline (const vk::DeviceInterface& vk,
93 const vk::VkDevice device,
94 const vk::VkPipelineLayout pipelineLayout,
95 const vk::VkShaderModule shaderModule);
96
97 vk::Move<vk::VkPipeline> makeComputePipeline (const vk::DeviceInterface& vk,
98 const vk::VkDevice device,
99 const vk::VkPipelineLayout pipelineLayout,
100 const vk::VkPipelineCreateFlags pipelineFlags,
101 const vk::VkShaderModule shaderModule,
102 const vk::VkPipelineShaderStageCreateFlags shaderFlags);
103
104 vk::Move<vk::VkBufferView> makeBufferView (const vk::DeviceInterface& vk,
105 const vk::VkDevice device,
106 const vk::VkBuffer buffer,
107 const vk::VkFormat format,
108 const vk::VkDeviceSize offset,
109 const vk::VkDeviceSize size);
110
111 vk::Move<vk::VkImageView> makeImageView (const vk::DeviceInterface& vk,
112 const vk::VkDevice device,
113 const vk::VkImage image,
114 const vk::VkImageViewType imageViewType,
115 const vk::VkFormat format,
116 const vk::VkImageSubresourceRange subresourceRange);
117
118 vk::Move<vk::VkDescriptorSet> makeDescriptorSet (const vk::DeviceInterface& vk,
119 const vk::VkDevice device,
120 const vk::VkDescriptorPool descriptorPool,
121 const vk::VkDescriptorSetLayout setLayout);
122
123 vk::VkBufferCreateInfo makeBufferCreateInfo (const vk::VkDeviceSize bufferSize,
124 const vk::VkBufferUsageFlags usage);
125
126 vk::VkBufferImageCopy makeBufferImageCopy (const vk::VkExtent3D extent,
127 const deUint32 arraySize);
128
makeExtent3D(const tcu::IVec3 & vec)129 inline vk::VkExtent3D makeExtent3D (const tcu::IVec3& vec)
130 {
131 return vk::makeExtent3D(vec.x(), vec.y(), vec.z());
132 }
133
getImageSizeBytes(const tcu::IVec3 & imageSize,const vk::VkFormat format)134 inline vk::VkDeviceSize getImageSizeBytes (const tcu::IVec3& imageSize, const vk::VkFormat format)
135 {
136 return tcu::getPixelSize(vk::mapVkFormat(format)) * imageSize.x() * imageSize.y() * imageSize.z();
137 }
138
139 } // compute
140 } // vkt
141
142 #endif // _VKTCOMPUTETESTSUTIL_HPP
143