Merge branch '259-fix-arm-gcc-issue' into 'vulkan-cts-1.0'
[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  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and/or associated documentation files (the
11  * "Materials"), to deal in the Materials without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Materials, and to
14  * permit persons to whom the Materials are furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice(s) and this permission notice shall be included
18  * in all copies or substantial portions of the Materials.
19  *
20  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
27  *
28  *//*!
29  * \file
30  * \brief Compute tests utility classes
31  *//*--------------------------------------------------------------------*/
32
33 #include "vkDefs.hpp"
34 #include "vkMemUtil.hpp"
35 #include "vkRef.hpp"
36 #include "vkRefUtil.hpp"
37 #include "vkPrograms.hpp"
38 #include "vkTypeUtil.hpp"
39 #include "vkImageUtil.hpp"
40
41 namespace vkt
42 {
43 namespace compute
44 {
45
46 class Buffer
47 {
48 public:
49                                                                         Buffer                  (const vk::DeviceInterface&             vk,
50                                                                                                          const vk::VkDevice                             device,
51                                                                                                          vk::Allocator&                                 allocator,
52                                                                                                          const vk::VkBufferCreateInfo&  bufferCreateInfo,
53                                                                                                          const vk::MemoryRequirement    memoryRequirement);
54
55         const vk::VkBuffer&                             get                             (void) const { return *m_buffer; }
56         const vk::VkBuffer&                             operator*               (void) const { return get(); }
57         vk::Allocation&                                 getAllocation   (void) const { return *m_allocation; }
58
59 private:
60         de::MovePtr<vk::Allocation>             m_allocation;
61         vk::Move<vk::VkBuffer>                  m_buffer;
62
63                                                                         Buffer                  (const Buffer&);  // "deleted"
64         Buffer&                                                 operator=               (const Buffer&);
65 };
66
67 class Image
68 {
69 public:
70                                                                         Image                   (const vk::DeviceInterface&             vk,
71                                                                                                          const vk::VkDevice                             device,
72                                                                                                          vk::Allocator&                                 allocator,
73                                                                                                          const vk::VkImageCreateInfo&   imageCreateInfo,
74                                                                                                          const vk::MemoryRequirement    memoryRequirement);
75
76         const vk::VkImage&                              get                             (void) const { return *m_image; }
77         const vk::VkImage&                              operator*               (void) const { return get(); }
78         vk::Allocation&                                 getAllocation   (void) const { return *m_allocation; }
79
80 private:
81         de::MovePtr<vk::Allocation>             m_allocation;
82         vk::Move<vk::VkImage>                   m_image;
83
84                                                                         Image                   (const Image&);  // "deleted"
85         Image&                                                  operator=               (const Image&);
86 };
87
88 vk::Move<vk::VkCommandPool>                     makeCommandPool                         (const vk::DeviceInterface&                     vk,
89                                                                                                                                  const vk::VkDevice                                     device,
90                                                                                                                                  const deUint32                                         queueFamilyIndex);
91
92 vk::Move<vk::VkCommandBuffer>           makeCommandBuffer                       (const vk::DeviceInterface&                     vk,
93                                                                                                                                  const vk::VkDevice                                     device,
94                                                                                                                                  const vk::VkCommandPool                        commandPool);
95
96 vk::Move<vk::VkPipelineLayout>  makePipelineLayout                              (const vk::DeviceInterface&                     vk,
97                                                                                                                                  const vk::VkDevice                                     device);
98
99 vk::Move<vk::VkPipelineLayout>  makePipelineLayout                              (const vk::DeviceInterface&                     vk,
100                                                                                                                                  const vk::VkDevice                                     device,
101                                                                                                                                  const vk::VkDescriptorSetLayout        descriptorSetLayout);
102
103 vk::Move<vk::VkPipeline>                makeComputePipeline                             (const vk::DeviceInterface&                     vk,
104                                                                                                                                  const vk::VkDevice                                     device,
105                                                                                                                                  const vk::VkPipelineLayout                     pipelineLayout,
106                                                                                                                                  const vk::VkShaderModule                       shaderModule);
107
108 vk::Move<vk::VkBufferView>              makeBufferView                                  (const vk::DeviceInterface&                     vk,
109                                                                                                                                  const vk::VkDevice                                     device,
110                                                                                                                                  const vk::VkBuffer                                     buffer,
111                                                                                                                                  const vk::VkFormat                                     format,
112                                                                                                                                  const vk::VkDeviceSize                         offset,
113                                                                                                                                  const vk::VkDeviceSize                         size);
114
115 vk::Move<vk::VkImageView>               makeImageView                                   (const vk::DeviceInterface&                     vk,
116                                                                                                                                  const vk::VkDevice                                     device,
117                                                                                                                                  const vk::VkImage                                      image,
118                                                                                                                                  const vk::VkImageViewType                      imageViewType,
119                                                                                                                                  const vk::VkFormat                                     format,
120                                                                                                                                  const vk::VkImageSubresourceRange      subresourceRange);
121
122 vk::Move<vk::VkDescriptorSet>   makeDescriptorSet                               (const vk::DeviceInterface&                     vk,
123                                                                                                                                  const vk::VkDevice                                     device,
124                                                                                                                                  const vk::VkDescriptorPool                     descriptorPool,
125                                                                                                                                  const vk::VkDescriptorSetLayout        setLayout);
126
127 vk::VkBufferCreateInfo                  makeBufferCreateInfo                    (const vk::VkDeviceSize                         bufferSize,
128                                                                                                                                  const vk::VkBufferUsageFlags           usage);
129
130 vk::VkBufferImageCopy                   makeBufferImageCopy                             (const vk::VkExtent3D                           extent,
131                                                                                                                                  const deUint32                                         arraySize);
132
133 vk::VkBufferMemoryBarrier               makeBufferMemoryBarrier                 (const vk::VkAccessFlags                        srcAccessMask,
134                                                                                                                                  const vk::VkAccessFlags                        dstAccessMask,
135                                                                                                                                  const vk::VkBuffer                                     buffer,
136                                                                                                                                  const vk::VkDeviceSize                         offset,
137                                                                                                                                  const vk::VkDeviceSize                         bufferSizeBytes);
138
139 vk::VkImageMemoryBarrier                makeImageMemoryBarrier                  (const vk::VkAccessFlags                        srcAccessMask,
140                                                                                                                                  const vk::VkAccessFlags                        dstAccessMask,
141                                                                                                                                  const vk::VkImageLayout                        oldLayout,
142                                                                                                                                  const vk::VkImageLayout                        newLayout,
143                                                                                                                                  const vk::VkImage                                      image,
144                                                                                                                                  const vk::VkImageSubresourceRange      subresourceRange);
145
146 void                                                    beginCommandBuffer                              (const vk::DeviceInterface&                     vk,
147                                                                                                                                  const vk::VkCommandBuffer                      cmdBuffer);
148
149 void                                                    endCommandBuffer                                (const vk::DeviceInterface&                     vk,
150                                                                                                                                  const vk::VkCommandBuffer                      cmdBuffer);
151
152 void                                                    submitCommandsAndWait                   (const vk::DeviceInterface&                     vk,
153                                                                                                                                  const vk::VkDevice                                     device,
154                                                                                                                                  const vk::VkQueue                                      queue,
155                                                                                                                                  const vk::VkCommandBuffer                      cmdBuffer);
156
157 inline vk::VkExtent3D makeExtent3D (const tcu::IVec3& vec)
158 {
159         return vk::makeExtent3D(vec.x(), vec.y(), vec.z());
160 }
161
162 inline vk::VkDeviceSize getImageSizeBytes (const tcu::IVec3& imageSize, const vk::VkFormat format)
163 {
164         return tcu::getPixelSize(vk::mapVkFormat(format)) * imageSize.x() * imageSize.y() * imageSize.z();
165 }
166
167 } // compute
168 } // vkt
169
170 #endif // _VKTCOMPUTETESTSUTIL_HPP