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