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 const char* getGlslAttachmentType (const vk::VkFormat format);
62 const char* getGlslInputAttachmentType (const vk::VkFormat format);
63 bool isPackedType (const vk::VkFormat format);
64 bool isComponentSwizzled (const vk::VkFormat format);
65 int getNumUsedChannels (const vk::VkFormat format);
66
67 class Buffer
68 {
69 public:
70 Buffer (const vk::DeviceInterface& vk,
71 const vk::VkDevice device,
72 vk::Allocator& allocator,
73 const vk::VkBufferCreateInfo& bufferCreateInfo,
74 const vk::MemoryRequirement memoryRequirement);
75
get(void) const76 const vk::VkBuffer& get (void) const { return *m_buffer; }
operator *(void) const77 const vk::VkBuffer& operator* (void) const { return get(); }
getAllocation(void) const78 vk::Allocation& getAllocation (void) const { return *m_allocation; }
79
80 private:
81 de::MovePtr<vk::Allocation> m_allocation;
82 vk::Move<vk::VkBuffer> m_buffer;
83
84 Buffer (const Buffer&); // "deleted"
85 Buffer& operator= (const Buffer&);
86 };
87
88 class Image
89 {
90 public:
91 Image (const vk::DeviceInterface& vk,
92 const vk::VkDevice device,
93 vk::Allocator& allocator,
94 const vk::VkImageCreateInfo& imageCreateInfo,
95 const vk::MemoryRequirement memoryRequirement);
96
get(void) const97 const vk::VkImage& get (void) const { return *m_image; }
operator *(void) const98 const vk::VkImage& operator* (void) const { return get(); }
getAllocation(void) const99 vk::Allocation& getAllocation (void) const { return *m_allocation; }
100
101 private:
102 de::MovePtr<vk::Allocation> m_allocation;
103 vk::Move<vk::VkImage> m_image;
104
105 Image (const Image&); // "deleted"
106 Image& operator= (const Image&);
107 };
108
109 deUint32 getBlockSizeInBytes (const vk::VkFormat compressedFormat);
110 deUint32 getBlockWidth (const vk::VkFormat compressedFormat);
111 deUint32 getBlockHeight (const vk::VkFormat compressedFormat);
112 tcu::UVec3 getShaderGridSize (const ImageType imageType, const tcu::UVec3& imageSize); //!< Size used for addresing image in a shader
113 tcu::UVec3 getLayerSize (const ImageType imageType, const tcu::UVec3& imageSize); //!< Size of a single layer
114 deUint32 getNumLayers (const ImageType imageType, const tcu::UVec3& imageSize); //!< Number of array layers (for array and cube types)
115 deUint32 getNumPixels (const ImageType imageType, const tcu::UVec3& imageSize); //!< Number of texels in an image
116 deUint32 getDimensions (const ImageType imageType); //!< Coordinate dimension used for addressing (e.g. 3 (x,y,z) for 2d array)
117 deUint32 getLayerDimensions (const ImageType imageType); //!< Coordinate dimension used for addressing a single layer (e.g. 2 (x,y) for 2d array)
118
119 vk::Move<vk::VkPipelineLayout> makePipelineLayout (const vk::DeviceInterface& vk,
120 const vk::VkDevice device,
121 const vk::VkDescriptorSetLayout descriptorSetLayout);
122
123 vk::Move<vk::VkPipeline> makeComputePipeline (const vk::DeviceInterface& vk,
124 const vk::VkDevice device,
125 const vk::VkPipelineLayout pipelineLayout,
126 const vk::VkShaderModule shaderModule);
127
128 vk::Move<vk::VkPipeline> makeGraphicsPipeline (const vk::DeviceInterface& vk,
129 const vk::VkDevice device,
130 const vk::VkPipelineLayout pipelineLayout,
131 const vk::VkRenderPass renderPass,
132 const vk::VkShaderModule vertexModule,
133 const vk::VkShaderModule fragmentModule,
134 const vk::VkExtent2D renderSize,
135 const deUint32 colorAttachmentCount,
136 const bool dynamicSize = false);
137
138 vk::Move<vk::VkRenderPass> makeRenderPass (const vk::DeviceInterface& vk,
139 const vk::VkDevice device,
140 const vk::VkFormat inputFormat,
141 const vk::VkFormat colorFormat);
142
143 vk::Move<vk::VkRenderPass> makeRenderPass (const vk::DeviceInterface& vk,
144 const vk::VkDevice device);
145
146 vk::Move<vk::VkBufferView> makeBufferView (const vk::DeviceInterface& vk,
147 const vk::VkDevice device,
148 const vk::VkBuffer buffer,
149 const vk::VkFormat format,
150 const vk::VkDeviceSize offset,
151 const vk::VkDeviceSize size);
152
153 vk::Move<vk::VkImageView> makeImageView (const vk::DeviceInterface& vk,
154 const vk::VkDevice device,
155 const vk::VkImage image,
156 const vk::VkImageViewType imageViewType,
157 const vk::VkFormat format,
158 const vk::VkImageSubresourceRange subresourceRange,
159 const vk::VkImageViewUsageCreateInfoKHR* ImageUsageCreateInfoKHR = DE_NULL);
160
161 vk::Move<vk::VkDescriptorSet> makeDescriptorSet (const vk::DeviceInterface& vk,
162 const vk::VkDevice device,
163 const vk::VkDescriptorPool descriptorPool,
164 const vk::VkDescriptorSetLayout setLayout);
165
166 vk::VkBufferCreateInfo makeBufferCreateInfo (const vk::VkDeviceSize bufferSize,
167 const vk::VkBufferUsageFlags usage);
168
169 vk::VkBufferImageCopy makeBufferImageCopy (const vk::VkExtent3D extent,
170 const deUint32 arraySize);
171
172 vk::VkBufferMemoryBarrier makeBufferMemoryBarrier (const vk::VkAccessFlags srcAccessMask,
173 const vk::VkAccessFlags dstAccessMask,
174 const vk::VkBuffer buffer,
175 const vk::VkDeviceSize offset,
176 const vk::VkDeviceSize bufferSizeBytes);
177
178 vk::VkImageMemoryBarrier makeImageMemoryBarrier (const vk::VkAccessFlags srcAccessMask,
179 const vk::VkAccessFlags dstAccessMask,
180 const vk::VkImageLayout oldLayout,
181 const vk::VkImageLayout newLayout,
182 const vk::VkImage image,
183 const vk::VkImageSubresourceRange subresourceRange);
184
185 vk::VkImageViewUsageCreateInfoKHR makeImageViewUsageCreateInfo (const vk::VkImageUsageFlags imageUsageFlags);
186
187 vk::VkSamplerCreateInfo makeSamplerCreateInfo ();
188
189 void beginCommandBuffer (const vk::DeviceInterface& vk,
190 const vk::VkCommandBuffer cmdBuffer);
191
192 void endCommandBuffer (const vk::DeviceInterface& vk,
193 const vk::VkCommandBuffer cmdBuffer);
194
195 void submitCommandsAndWait (const vk::DeviceInterface& vk,
196 const vk::VkDevice device,
197 const vk::VkQueue queue,
198 const vk::VkCommandBuffer cmdBuffer);
199
getImageSizeBytes(const tcu::IVec3 & imageSize,const vk::VkFormat format)200 inline vk::VkDeviceSize getImageSizeBytes (const tcu::IVec3& imageSize, const vk::VkFormat format)
201 {
202 return tcu::getPixelSize(vk::mapVkFormat(format)) * imageSize.x() * imageSize.y() * imageSize.z();
203 }
204
205 tcu::UVec3 getCompressedImageResolutionInBlocks (const vk::VkFormat format, const tcu::UVec3& size);
206 tcu::UVec3 getCompressedImageResolutionBlockCeil (const vk::VkFormat format, const tcu::UVec3& size);
207 vk::VkDeviceSize getCompressedImageSizeInBytes (const vk::VkFormat format, const tcu::UVec3& size);
208 vk::VkDeviceSize getUncompressedImageSizeInBytes (const vk::VkFormat format, const tcu::UVec3& size);
209
210 std::string getFormatShortString (const vk::VkFormat format);
211
212 std::vector<tcu::Vec4> createFullscreenQuad (void);
213
214 vk::VkBufferImageCopy makeBufferImageCopy (const deUint32 imageWidth, const deUint32 imageHeight, const deUint32 mipLevel = 0u, const deUint32 layer = 0u);
215 vk::VkBufferImageCopy makeBufferImageCopy (const deUint32 imageWidth, const deUint32 imageHeight, const deUint32 mipLevel, const deUint32 layer, const deUint32 bufferRowLength, const deUint32 bufferImageHeight);
216
217 void beginRenderPass (const vk::DeviceInterface& vk,
218 const vk::VkCommandBuffer commandBuffer,
219 const vk::VkRenderPass renderPass,
220 const vk::VkFramebuffer framebuffer,
221 const vk::VkExtent2D& renderSize);
222
223 vk::Move<vk::VkFramebuffer> makeFramebuffer (const vk::DeviceInterface& vk,
224 const vk::VkDevice device,
225 const vk::VkRenderPass renderPass,
226 const deUint32 attachmentCount,
227 const vk::VkImageView* pAttachments,
228 const vk::VkExtent2D& size,
229 const deUint32 layersCount);
230
231 vk::VkRect2D makeScissor (const deUint32 width,
232 const deUint32 height);
233
234 } // image
235 } // vkt
236
237 #endif // _VKTIMAGETESTSUTIL_HPP
238