Merge branch vk-gl-cts/vulkan-cts-1.0.2 into vk-gl-cts/master
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / compute / vktComputeTestsUtil.hpp
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
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
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
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
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::VkBufferView>              makeBufferView                                  (const vk::DeviceInterface&                     vk,
98                                                                                                                                  const vk::VkDevice                                     device,
99                                                                                                                                  const vk::VkBuffer                                     buffer,
100                                                                                                                                  const vk::VkFormat                                     format,
101                                                                                                                                  const vk::VkDeviceSize                         offset,
102                                                                                                                                  const vk::VkDeviceSize                         size);
103
104 vk::Move<vk::VkImageView>               makeImageView                                   (const vk::DeviceInterface&                     vk,
105                                                                                                                                  const vk::VkDevice                                     device,
106                                                                                                                                  const vk::VkImage                                      image,
107                                                                                                                                  const vk::VkImageViewType                      imageViewType,
108                                                                                                                                  const vk::VkFormat                                     format,
109                                                                                                                                  const vk::VkImageSubresourceRange      subresourceRange);
110
111 vk::Move<vk::VkDescriptorSet>   makeDescriptorSet                               (const vk::DeviceInterface&                     vk,
112                                                                                                                                  const vk::VkDevice                                     device,
113                                                                                                                                  const vk::VkDescriptorPool                     descriptorPool,
114                                                                                                                                  const vk::VkDescriptorSetLayout        setLayout);
115
116 vk::VkBufferCreateInfo                  makeBufferCreateInfo                    (const vk::VkDeviceSize                         bufferSize,
117                                                                                                                                  const vk::VkBufferUsageFlags           usage);
118
119 vk::VkBufferImageCopy                   makeBufferImageCopy                             (const vk::VkExtent3D                           extent,
120                                                                                                                                  const deUint32                                         arraySize);
121
122 vk::VkBufferMemoryBarrier               makeBufferMemoryBarrier                 (const vk::VkAccessFlags                        srcAccessMask,
123                                                                                                                                  const vk::VkAccessFlags                        dstAccessMask,
124                                                                                                                                  const vk::VkBuffer                                     buffer,
125                                                                                                                                  const vk::VkDeviceSize                         offset,
126                                                                                                                                  const vk::VkDeviceSize                         bufferSizeBytes);
127
128 vk::VkImageMemoryBarrier                makeImageMemoryBarrier                  (const vk::VkAccessFlags                        srcAccessMask,
129                                                                                                                                  const vk::VkAccessFlags                        dstAccessMask,
130                                                                                                                                  const vk::VkImageLayout                        oldLayout,
131                                                                                                                                  const vk::VkImageLayout                        newLayout,
132                                                                                                                                  const vk::VkImage                                      image,
133                                                                                                                                  const vk::VkImageSubresourceRange      subresourceRange);
134
135 void                                                    beginCommandBuffer                              (const vk::DeviceInterface&                     vk,
136                                                                                                                                  const vk::VkCommandBuffer                      cmdBuffer);
137
138 void                                                    endCommandBuffer                                (const vk::DeviceInterface&                     vk,
139                                                                                                                                  const vk::VkCommandBuffer                      cmdBuffer);
140
141 void                                                    submitCommandsAndWait                   (const vk::DeviceInterface&                     vk,
142                                                                                                                                  const vk::VkDevice                                     device,
143                                                                                                                                  const vk::VkQueue                                      queue,
144                                                                                                                                  const vk::VkCommandBuffer                      cmdBuffer);
145
146 inline vk::VkExtent3D makeExtent3D (const tcu::IVec3& vec)
147 {
148         return vk::makeExtent3D(vec.x(), vec.y(), vec.z());
149 }
150
151 inline vk::VkDeviceSize getImageSizeBytes (const tcu::IVec3& imageSize, const vk::VkFormat format)
152 {
153         return tcu::getPixelSize(vk::mapVkFormat(format)) * imageSize.x() * imageSize.y() * imageSize.z();
154 }
155
156 } // compute
157 } // vkt
158
159 #endif // _VKTCOMPUTETESTSUTIL_HPP