• 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 Image
70 {
71 public:
72 									Image			(const vk::DeviceInterface&		vk,
73 													 const vk::VkDevice				device,
74 													 vk::Allocator&					allocator,
75 													 const vk::VkImageCreateInfo&	imageCreateInfo,
76 													 const vk::MemoryRequirement	memoryRequirement);
~Image(void)77 	virtual							~Image			(void)		 {}
78 
get(void) const79 	const vk::VkImage&				get				(void) const { return *m_image; }
operator *(void) const80 	const vk::VkImage&				operator*		(void) const { return get(); }
81 
getSemaphore(void) const82 	virtual vk::VkSemaphore			getSemaphore	(void) const { return DE_NULL; }
83 
84 									Image			(const Image&) = delete;
85 	Image&							operator=		(const Image&) = delete;
86 
87 protected:
88 	using AllocationsVec = std::vector<de::SharedPtr<vk::Allocation>>;
89 
90 									Image			(void);
91 
92 	AllocationsVec					m_allocations;
93 	vk::Move<vk::VkImage>			m_image;
94 };
95 
96 #ifndef CTS_USES_VULKANSC
97 class SparseImage : public Image
98 {
99 public:
100 									SparseImage		(const vk::DeviceInterface&		vkd,
101 													 vk::VkDevice					device,
102 													 vk::VkPhysicalDevice			physicalDevice,
103 													 const vk::InstanceInterface&	vki,
104 													 const vk::VkImageCreateInfo&	createInfo,
105 													 const vk::VkQueue				sparseQueue,
106 													 vk::Allocator&					allocator,
107 													 const tcu::TextureFormat&		format);
108 
getSemaphore(void) const109 	virtual vk::VkSemaphore			getSemaphore	(void) const { return m_semaphore.get(); }
110 
111 									SparseImage		(const SparseImage&) = delete;
112 	SparseImage&					operator=		(const SparseImage&) = delete;
113 
114 protected:
115 	vk::Move<vk::VkSemaphore>		m_semaphore;
116 };
117 #endif // CTS_USES_VULKANSC
118 
119 tcu::UVec3				getShaderGridSize	(const ImageType imageType, const tcu::UVec3& imageSize);	//!< Size used for addresing image in a shader
120 tcu::UVec3				getLayerSize		(const ImageType imageType, const tcu::UVec3& imageSize);	//!< Size of a single layer
121 deUint32				getNumLayers		(const ImageType imageType, const tcu::UVec3& imageSize);	//!< Number of array layers (for array and cube types)
122 deUint32				getNumPixels		(const ImageType imageType, const tcu::UVec3& imageSize);	//!< Number of texels in an image
123 deUint32				getDimensions		(const ImageType imageType);								//!< Coordinate dimension used for addressing (e.g. 3 (x,y,z) for 2d array)
124 deUint32				getLayerDimensions	(const ImageType imageType);								//!< Coordinate dimension used for addressing a single layer (e.g. 2 (x,y) for 2d array)
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::VkBufferImageCopy				makeBufferImageCopy				(const vk::VkExtent3D						extent,
142 																	 const deUint32								arraySize);
143 
144 vk::VkImageViewUsageCreateInfo		makeImageViewUsageCreateInfo	(const vk::VkImageUsageFlags				imageUsageFlags);
145 
146 vk::VkSamplerCreateInfo				makeSamplerCreateInfo			();
147 
getImageSizeBytes(const tcu::IVec3 & imageSize,const vk::VkFormat format)148 inline vk::VkDeviceSize getImageSizeBytes (const tcu::IVec3& imageSize, const vk::VkFormat format)
149 {
150 	return tcu::getPixelSize(vk::mapVkFormat(format)) * imageSize.x() * imageSize.y() * imageSize.z();
151 }
152 
153 tcu::UVec3			getCompressedImageResolutionInBlocks	(const vk::VkFormat format, const tcu::UVec3& size);
154 tcu::UVec3			getCompressedImageResolutionBlockCeil	(const vk::VkFormat format, const tcu::UVec3& size);
155 vk::VkDeviceSize	getCompressedImageSizeInBytes			(const vk::VkFormat format, const tcu::UVec3& size);
156 vk::VkDeviceSize	getUncompressedImageSizeInBytes			(const vk::VkFormat format, const tcu::UVec3& size);
157 
158 std::string	getFormatShortString (const vk::VkFormat format);
159 
160 std::vector<tcu::Vec4> createFullscreenQuad (void);
161 
162 vk::VkBufferImageCopy makeBufferImageCopy (const deUint32 imageWidth, const deUint32 imageHeight, const deUint32 mipLevel = 0u, const deUint32 layer = 0u);
163 vk::VkBufferImageCopy makeBufferImageCopy (const deUint32 imageWidth, const deUint32 imageHeight, const deUint32 mipLevel, const deUint32 layer, const deUint32 bufferRowLength, const deUint32 bufferImageHeight);
164 
165 void beginRenderPass (const vk::DeviceInterface&	vk,
166 					  const vk::VkCommandBuffer		commandBuffer,
167 					  const vk::VkRenderPass		renderPass,
168 					  const vk::VkFramebuffer		framebuffer,
169 					  const vk::VkExtent2D&			renderSize);
170 
171 } // image
172 } // vkt
173 
174 #endif // _VKTIMAGETESTSUTIL_HPP
175