• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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				getFormatPrefix					(const tcu::TextureFormat& format);
57 std::string				getShaderImageType				(const tcu::TextureFormat& format, const ImageType imageType, const bool multisample = false);
58 std::string				getShaderImageFormatQualifier	(const tcu::TextureFormat& format);
59 std::string				getGlslSamplerType				(const tcu::TextureFormat& format, vk::VkImageViewType type);
60 const char*				getGlslInputFormatType			(const vk::VkFormat format);
61 const char*				getGlslFormatType				(const vk::VkFormat format);
62 const char*				getGlslAttachmentType			(const vk::VkFormat format);
63 const char*				getGlslInputAttachmentType		(const vk::VkFormat format);
64 bool					isPackedType					(const vk::VkFormat format);
65 bool					isComponentSwizzled				(const vk::VkFormat format);
66 int						getNumUsedChannels				(const vk::VkFormat format);
67 bool					isFormatImageLoadStoreCapable	(const vk::VkFormat format);
68 
69 class Buffer
70 {
71 public:
72 									Buffer			(const vk::DeviceInterface&		vk,
73 													 const vk::VkDevice				device,
74 													 vk::Allocator&					allocator,
75 													 const vk::VkBufferCreateInfo&	bufferCreateInfo,
76 													 const vk::MemoryRequirement	memoryRequirement);
77 
get(void) const78 	const vk::VkBuffer&				get				(void) const { return *m_buffer; }
operator *(void) const79 	const vk::VkBuffer&				operator*		(void) const { return get(); }
getAllocation(void) const80 	vk::Allocation&					getAllocation	(void) const { return *m_allocation; }
81 
82 private:
83 	de::MovePtr<vk::Allocation>		m_allocation;
84 	vk::Move<vk::VkBuffer>			m_buffer;
85 
86 									Buffer			(const Buffer&);  // "deleted"
87 	Buffer&							operator=		(const Buffer&);
88 };
89 
90 class Image
91 {
92 public:
93 									Image			(const vk::DeviceInterface&		vk,
94 													 const vk::VkDevice				device,
95 													 vk::Allocator&					allocator,
96 													 const vk::VkImageCreateInfo&	imageCreateInfo,
97 													 const vk::MemoryRequirement	memoryRequirement);
~Image(void)98 	virtual							~Image			(void)		 {}
99 
get(void) const100 	const vk::VkImage&				get				(void) const { return *m_image; }
operator *(void) const101 	const vk::VkImage&				operator*		(void) const { return get(); }
102 
getSemaphore(void) const103 	virtual vk::VkSemaphore			getSemaphore	(void) const { return DE_NULL; }
104 
105 									Image			(const Image&) = delete;
106 	Image&							operator=		(const Image&) = delete;
107 
108 protected:
109 	using AllocationsVec = std::vector<de::SharedPtr<vk::Allocation>>;
110 
111 									Image			(void);
112 
113 	AllocationsVec					m_allocations;
114 	vk::Move<vk::VkImage>			m_image;
115 };
116 
117 class SparseImage : public Image
118 {
119 public:
120 									SparseImage		(const vk::DeviceInterface&		vkd,
121 													 vk::VkDevice					device,
122 													 vk::VkPhysicalDevice			physicalDevice,
123 													 const vk::InstanceInterface&	vki,
124 													 const vk::VkImageCreateInfo&	createInfo,
125 													 const vk::VkQueue				sparseQueue,
126 													 vk::Allocator&					allocator,
127 													 const tcu::TextureFormat&		format);
128 
getSemaphore(void) const129 	virtual vk::VkSemaphore			getSemaphore	(void) const { return m_semaphore.get(); }
130 
131 									SparseImage		(const SparseImage&) = delete;
132 	SparseImage&					operator=		(const SparseImage&) = delete;
133 
134 protected:
135 	vk::Move<vk::VkSemaphore>		m_semaphore;
136 };
137 
138 tcu::UVec3				getShaderGridSize	(const ImageType imageType, const tcu::UVec3& imageSize);	//!< Size used for addresing image in a shader
139 tcu::UVec3				getLayerSize		(const ImageType imageType, const tcu::UVec3& imageSize);	//!< Size of a single layer
140 deUint32				getNumLayers		(const ImageType imageType, const tcu::UVec3& imageSize);	//!< Number of array layers (for array and cube types)
141 deUint32				getNumPixels		(const ImageType imageType, const tcu::UVec3& imageSize);	//!< Number of texels in an image
142 deUint32				getDimensions		(const ImageType imageType);								//!< Coordinate dimension used for addressing (e.g. 3 (x,y,z) for 2d array)
143 deUint32				getLayerDimensions	(const ImageType imageType);								//!< Coordinate dimension used for addressing a single layer (e.g. 2 (x,y) for 2d array)
144 
145 vk::Move<vk::VkPipeline>			makeComputePipeline				(const vk::DeviceInterface&					vk,
146 																	 const vk::VkDevice							device,
147 																	 const vk::VkPipelineLayout					pipelineLayout,
148 																	 const vk::VkShaderModule					shaderModule);
149 
150 vk::Move<vk::VkPipeline>			makeGraphicsPipeline			(const vk::DeviceInterface&					vk,
151 																	 const vk::VkDevice							device,
152 																	 const vk::VkPipelineLayout					pipelineLayout,
153 																	 const vk::VkRenderPass						renderPass,
154 																	 const vk::VkShaderModule					vertexModule,
155 																	 const vk::VkShaderModule					fragmentModule,
156 																	 const vk::VkExtent2D						renderSize,
157 																	 const deUint32								colorAttachmentCount,
158 																	 const bool									dynamicSize = false);
159 
160 vk::Move<vk::VkRenderPass>			makeRenderPass					(const vk::DeviceInterface&					vk,
161 																	 const vk::VkDevice							device,
162 																	 const vk::VkFormat							inputFormat,
163 																	 const vk::VkFormat							colorFormat);
164 
165 vk::VkBufferImageCopy				makeBufferImageCopy				(const vk::VkExtent3D						extent,
166 																	 const deUint32								arraySize);
167 
168 vk::VkImageViewUsageCreateInfo		makeImageViewUsageCreateInfo	(const vk::VkImageUsageFlags				imageUsageFlags);
169 
170 vk::VkSamplerCreateInfo				makeSamplerCreateInfo			();
171 
getImageSizeBytes(const tcu::IVec3 & imageSize,const vk::VkFormat format)172 inline vk::VkDeviceSize getImageSizeBytes (const tcu::IVec3& imageSize, const vk::VkFormat format)
173 {
174 	return tcu::getPixelSize(vk::mapVkFormat(format)) * imageSize.x() * imageSize.y() * imageSize.z();
175 }
176 
177 tcu::UVec3			getCompressedImageResolutionInBlocks	(const vk::VkFormat format, const tcu::UVec3& size);
178 tcu::UVec3			getCompressedImageResolutionBlockCeil	(const vk::VkFormat format, const tcu::UVec3& size);
179 vk::VkDeviceSize	getCompressedImageSizeInBytes			(const vk::VkFormat format, const tcu::UVec3& size);
180 vk::VkDeviceSize	getUncompressedImageSizeInBytes			(const vk::VkFormat format, const tcu::UVec3& size);
181 
182 std::string	getFormatShortString (const vk::VkFormat format);
183 
184 std::vector<tcu::Vec4> createFullscreenQuad (void);
185 
186 vk::VkBufferImageCopy makeBufferImageCopy (const deUint32 imageWidth, const deUint32 imageHeight, const deUint32 mipLevel = 0u, const deUint32 layer = 0u);
187 vk::VkBufferImageCopy makeBufferImageCopy (const deUint32 imageWidth, const deUint32 imageHeight, const deUint32 mipLevel, const deUint32 layer, const deUint32 bufferRowLength, const deUint32 bufferImageHeight);
188 
189 void beginRenderPass (const vk::DeviceInterface&	vk,
190 					  const vk::VkCommandBuffer		commandBuffer,
191 					  const vk::VkRenderPass		renderPass,
192 					  const vk::VkFramebuffer		framebuffer,
193 					  const vk::VkExtent2D&			renderSize);
194 
195 } // image
196 } // vkt
197 
198 #endif // _VKTIMAGETESTSUTIL_HPP
199