Expand tests for mutable images
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / image / vktImageTestsUtil.hpp
1 #ifndef _VKTIMAGETESTSUTIL_HPP
2 #define _VKTIMAGETESTSUTIL_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 Image 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 image
37 {
38
39 enum ImageType
40 {
41         IMAGE_TYPE_1D = 0,
42         IMAGE_TYPE_1D_ARRAY,
43         IMAGE_TYPE_2D,
44         IMAGE_TYPE_2D_ARRAY,
45         IMAGE_TYPE_3D,
46         IMAGE_TYPE_CUBE,
47         IMAGE_TYPE_CUBE_ARRAY,
48         IMAGE_TYPE_BUFFER,
49
50         IMAGE_TYPE_LAST
51 };
52
53 vk::VkImageType                 mapImageType                                    (const ImageType imageType);
54 vk::VkImageViewType             mapImageViewType                                (const ImageType imageType);
55 std::string                             getImageTypeName                                (const ImageType imageType);
56 std::string                             getShaderImageType                              (const tcu::TextureFormat& format, const ImageType imageType, const bool multisample = false);
57 std::string                             getShaderImageFormatQualifier   (const tcu::TextureFormat& format);
58 std::string                             getGlslSamplerType                              (const tcu::TextureFormat& format, vk::VkImageViewType type);
59 const char*                             getGlslInputFormatType                  (const vk::VkFormat format);
60 const char*                             getGlslFormatType                               (const vk::VkFormat format);
61
62 class Buffer
63 {
64 public:
65                                                                         Buffer                  (const vk::DeviceInterface&             vk,
66                                                                                                          const vk::VkDevice                             device,
67                                                                                                          vk::Allocator&                                 allocator,
68                                                                                                          const vk::VkBufferCreateInfo&  bufferCreateInfo,
69                                                                                                          const vk::MemoryRequirement    memoryRequirement);
70
71         const vk::VkBuffer&                             get                             (void) const { return *m_buffer; }
72         const vk::VkBuffer&                             operator*               (void) const { return get(); }
73         vk::Allocation&                                 getAllocation   (void) const { return *m_allocation; }
74
75 private:
76         de::MovePtr<vk::Allocation>             m_allocation;
77         vk::Move<vk::VkBuffer>                  m_buffer;
78
79                                                                         Buffer                  (const Buffer&);  // "deleted"
80         Buffer&                                                 operator=               (const Buffer&);
81 };
82
83 class Image
84 {
85 public:
86                                                                         Image                   (const vk::DeviceInterface&             vk,
87                                                                                                          const vk::VkDevice                             device,
88                                                                                                          vk::Allocator&                                 allocator,
89                                                                                                          const vk::VkImageCreateInfo&   imageCreateInfo,
90                                                                                                          const vk::MemoryRequirement    memoryRequirement);
91
92         const vk::VkImage&                              get                             (void) const { return *m_image; }
93         const vk::VkImage&                              operator*               (void) const { return get(); }
94         vk::Allocation&                                 getAllocation   (void) const { return *m_allocation; }
95
96 private:
97         de::MovePtr<vk::Allocation>             m_allocation;
98         vk::Move<vk::VkImage>                   m_image;
99
100                                                                         Image                   (const Image&);  // "deleted"
101         Image&                                                  operator=               (const Image&);
102 };
103
104 deUint32                                getBlockSizeInBytes     (const vk::VkFormat compressedFormat);
105 deUint32                                getBlockWidth           (const vk::VkFormat compressedFormat);
106 deUint32                                getBlockHeight          (const vk::VkFormat compressedFormat);
107 tcu::UVec3                              getShaderGridSize       (const ImageType imageType, const tcu::UVec3& imageSize);       //!< Size used for addresing image in a shader
108 tcu::UVec3                              getLayerSize            (const ImageType imageType, const tcu::UVec3& imageSize);       //!< Size of a single layer
109 deUint32                                getNumLayers            (const ImageType imageType, const tcu::UVec3& imageSize);       //!< Number of array layers (for array and cube types)
110 deUint32                                getNumPixels            (const ImageType imageType, const tcu::UVec3& imageSize);       //!< Number of texels in an image
111 deUint32                                getDimensions           (const ImageType imageType);                                                            //!< Coordinate dimension used for addressing (e.g. 3 (x,y,z) for 2d array)
112 deUint32                                getLayerDimensions      (const ImageType imageType);                                                            //!< Coordinate dimension used for addressing a single layer (e.g. 2 (x,y) for 2d array)
113 std::vector<tcu::UVec3> getMipLevelSizes        (tcu::UVec3 baseSize);
114
115 vk::Move<vk::VkPipelineLayout>  makePipelineLayout                              (const vk::DeviceInterface&                                     vk,
116                                                                                                                                  const vk::VkDevice                                                     device,
117                                                                                                                                  const vk::VkDescriptorSetLayout                        descriptorSetLayout);
118
119 vk::Move<vk::VkPipeline>                makeComputePipeline                             (const vk::DeviceInterface&                                     vk,
120                                                                                                                                  const vk::VkDevice                                                     device,
121                                                                                                                                  const vk::VkPipelineLayout                                     pipelineLayout,
122                                                                                                                                  const vk::VkShaderModule                                       shaderModule);
123
124 vk::Move<vk::VkPipeline>                makeGraphicsPipeline                    (const vk::DeviceInterface&                                     vk,
125                                                                                                                                  const vk::VkDevice                                                     device,
126                                                                                                                                  const vk::VkPipelineLayout                                     pipelineLayout,
127                                                                                                                                  const vk::VkRenderPass                                         renderPass,
128                                                                                                                                  const vk::VkShaderModule                                       vertexModule,
129                                                                                                                                  const vk::VkShaderModule                                       fragmentModule,
130                                                                                                                                  const vk::VkExtent2D                                           renderSize,
131                                                                                                                                  const deUint32                                                         colorAttachmentCount);
132
133 vk::Move<vk::VkRenderPass>              makeRenderPass                                  (const vk::DeviceInterface&                                     vk,
134                                                                                                                                  const vk::VkDevice                                                     device,
135                                                                                                                                  const vk::VkFormat                                                     inputFormat,
136                                                                                                                                  const vk::VkFormat                                                     colorFormat);
137
138 vk::Move<vk::VkRenderPass>              makeRenderPass                                  (const vk::DeviceInterface&                                     vk,
139                                                                                                                                  const vk::VkDevice                                                     device);
140
141 vk::Move<vk::VkBufferView>              makeBufferView                                  (const vk::DeviceInterface&                                     vk,
142                                                                                                                                  const vk::VkDevice                                                     device,
143                                                                                                                                  const vk::VkBuffer                                                     buffer,
144                                                                                                                                  const vk::VkFormat                                                     format,
145                                                                                                                                  const vk::VkDeviceSize                                         offset,
146                                                                                                                                  const vk::VkDeviceSize                                         size);
147
148 vk::Move<vk::VkImageView>               makeImageView                                   (const vk::DeviceInterface&                                     vk,
149                                                                                                                                  const vk::VkDevice                                                     device,
150                                                                                                                                  const vk::VkImage                                                      image,
151                                                                                                                                  const vk::VkImageViewType                                      imageViewType,
152                                                                                                                                  const vk::VkFormat                                                     format,
153                                                                                                                                  const vk::VkImageSubresourceRange                      subresourceRange,
154                                                                                                                                  const vk::VkImageViewUsageCreateInfoKHR*       ImageUsageCreateInfoKHR = DE_NULL);
155
156 vk::Move<vk::VkDescriptorSet>   makeDescriptorSet                               (const vk::DeviceInterface&                                     vk,
157                                                                                                                                  const vk::VkDevice                                                     device,
158                                                                                                                                  const vk::VkDescriptorPool                                     descriptorPool,
159                                                                                                                                  const vk::VkDescriptorSetLayout                        setLayout);
160
161 vk::VkBufferCreateInfo                  makeBufferCreateInfo                    (const vk::VkDeviceSize                                         bufferSize,
162                                                                                                                                  const vk::VkBufferUsageFlags                           usage);
163
164 vk::VkBufferImageCopy                   makeBufferImageCopy                             (const vk::VkExtent3D                                           extent,
165                                                                                                                                  const deUint32                                                         arraySize);
166
167 vk::VkBufferMemoryBarrier               makeBufferMemoryBarrier                 (const vk::VkAccessFlags                                        srcAccessMask,
168                                                                                                                                  const vk::VkAccessFlags                                        dstAccessMask,
169                                                                                                                                  const vk::VkBuffer                                                     buffer,
170                                                                                                                                  const vk::VkDeviceSize                                         offset,
171                                                                                                                                  const vk::VkDeviceSize                                         bufferSizeBytes);
172
173 vk::VkImageMemoryBarrier                makeImageMemoryBarrier                  (const vk::VkAccessFlags                                        srcAccessMask,
174                                                                                                                                  const vk::VkAccessFlags                                        dstAccessMask,
175                                                                                                                                  const vk::VkImageLayout                                        oldLayout,
176                                                                                                                                  const vk::VkImageLayout                                        newLayout,
177                                                                                                                                  const vk::VkImage                                                      image,
178                                                                                                                                  const vk::VkImageSubresourceRange                      subresourceRange);
179
180 vk::VkSamplerCreateInfo                 makeSamplerCreateInfo                   ();
181
182 void                                                    beginCommandBuffer                              (const vk::DeviceInterface&                                     vk,
183                                                                                                                                  const vk::VkCommandBuffer                                      cmdBuffer);
184
185 void                                                    endCommandBuffer                                (const vk::DeviceInterface&                                     vk,
186                                                                                                                                  const vk::VkCommandBuffer                                      cmdBuffer);
187
188 void                                                    submitCommandsAndWait                   (const vk::DeviceInterface&                                     vk,
189                                                                                                                                  const vk::VkDevice                                                     device,
190                                                                                                                                  const vk::VkQueue                                                      queue,
191                                                                                                                                  const vk::VkCommandBuffer                                      cmdBuffer);
192
193 inline vk::VkDeviceSize getImageSizeBytes (const tcu::IVec3& imageSize, const vk::VkFormat format)
194 {
195         return tcu::getPixelSize(vk::mapVkFormat(format)) * imageSize.x() * imageSize.y() * imageSize.z();
196 }
197
198 tcu::UVec3                      getCompressedImageResolutionInBlocks    (const vk::VkFormat format, const tcu::UVec3 size);
199 vk::VkDeviceSize        getCompressedImageSizeInBytes                   (const vk::VkFormat format, const tcu::UVec3& size);
200 vk::VkDeviceSize        getUncompressedImageSizeInBytes                 (const vk::VkFormat format, const tcu::UVec3& size);
201
202 std::string     getFormatShortString (const vk::VkFormat format);
203
204 std::vector<tcu::Vec4> createFullscreenQuad (void);
205
206 vk::VkBufferImageCopy makeBufferImageCopy (const deUint32 imageWidth, const deUint32 imageHeight);
207
208 void beginRenderPass (const vk::DeviceInterface&        vk,
209                                           const vk::VkCommandBuffer             commandBuffer,
210                                           const vk::VkRenderPass                renderPass,
211                                           const vk::VkFramebuffer               framebuffer,
212                                           const vk::VkExtent2D&                 renderSize);
213
214 vk::Move<vk::VkFramebuffer> makeFramebuffer (const vk::DeviceInterface& vk,
215                                                                                          const vk::VkDevice                     device,
216                                                                                          const vk::VkRenderPass         renderPass,
217                                                                                          const deUint32                         attachmentCount,
218                                                                                          const vk::VkImageView*         pAttachments,
219                                                                                          const vk::VkExtent2D&          size,
220                                                                                          const deUint32                         layersCount);
221
222 } // image
223 } // vkt
224
225 #endif // _VKTIMAGETESTSUTIL_HPP