• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _VKTTEXTURETESTUTIL_HPP
2 #define _VKTTEXTURETESTUTIL_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2016 The Khronos Group Inc.
8  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
9  * Copyright (c) 2014 The Android Open Source Project
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  *
23  *//*!
24  * \file
25  * \brief Texture test utilities.
26  *
27  * About coordinates:
28  *  + Quads consist of 2 triangles, rendered using explicit indices.
29  *  + All TextureTestUtil functions and classes expect texture coordinates
30  *    for quads to be specified in order (-1, -1), (-1, 1), (1, -1), (1, 1).
31  *//*--------------------------------------------------------------------*/
32 
33 #include "tcuDefs.hpp"
34 #include "tcuSurface.hpp"
35 
36 #include "vkDefs.hpp"
37 #include "vkTypeUtil.hpp"
38 #include "vktTestCase.hpp"
39 
40 #include "gluShaderProgram.hpp"
41 #include "gluTextureTestUtil.hpp"
42 #include "deSharedPtr.hpp"
43 
44 #include "../pipeline/vktPipelineImageUtil.hpp"
45 
46 namespace vkt
47 {
48 
49 namespace texture
50 {
51 
52 namespace util
53 {
54 
55 enum Program
56 {
57 	PROGRAM_2D_FLOAT = 0,
58 	PROGRAM_2D_INT,
59 	PROGRAM_2D_UINT,
60 	PROGRAM_2D_SHADOW,
61 
62 	PROGRAM_2D_FLOAT_BIAS,
63 	PROGRAM_2D_INT_BIAS,
64 	PROGRAM_2D_UINT_BIAS,
65 	PROGRAM_2D_SHADOW_BIAS,
66 
67 	PROGRAM_1D_FLOAT,
68 	PROGRAM_1D_INT,
69 	PROGRAM_1D_UINT,
70 	PROGRAM_1D_SHADOW,
71 
72 	PROGRAM_1D_FLOAT_BIAS,
73 	PROGRAM_1D_INT_BIAS,
74 	PROGRAM_1D_UINT_BIAS,
75 	PROGRAM_1D_SHADOW_BIAS,
76 
77 	PROGRAM_CUBE_FLOAT,
78 	PROGRAM_CUBE_INT,
79 	PROGRAM_CUBE_UINT,
80 	PROGRAM_CUBE_SHADOW,
81 
82 	PROGRAM_CUBE_FLOAT_BIAS,
83 	PROGRAM_CUBE_INT_BIAS,
84 	PROGRAM_CUBE_UINT_BIAS,
85 	PROGRAM_CUBE_SHADOW_BIAS,
86 
87 	PROGRAM_1D_ARRAY_FLOAT,
88 	PROGRAM_1D_ARRAY_INT,
89 	PROGRAM_1D_ARRAY_UINT,
90 	PROGRAM_1D_ARRAY_SHADOW,
91 
92 	PROGRAM_2D_ARRAY_FLOAT,
93 	PROGRAM_2D_ARRAY_INT,
94 	PROGRAM_2D_ARRAY_UINT,
95 	PROGRAM_2D_ARRAY_SHADOW,
96 
97 	PROGRAM_3D_FLOAT,
98 	PROGRAM_3D_INT,
99 	PROGRAM_3D_UINT,
100 
101 	PROGRAM_3D_FLOAT_BIAS,
102 	PROGRAM_3D_INT_BIAS,
103 	PROGRAM_3D_UINT_BIAS,
104 
105 	PROGRAM_CUBE_ARRAY_FLOAT,
106 	PROGRAM_CUBE_ARRAY_INT,
107 	PROGRAM_CUBE_ARRAY_UINT,
108 	PROGRAM_CUBE_ARRAY_SHADOW,
109 
110 	PROGRAM_BUFFER_FLOAT,
111 	PROGRAM_BUFFER_INT,
112 	PROGRAM_BUFFER_UINT,
113 
114 	PROGRAM_LAST
115 };
116 
117 void initializePrograms (vk::SourceCollections& programCollection, glu::Precision texCoordPrecision, const std::vector<Program>& programs, const char* texCoordSwizzle = DE_NULL, glu::Precision fragOutputPrecision = glu::Precision::PRECISION_MEDIUMP);
118 
119 typedef de::SharedPtr<pipeline::TestTexture>			TestTextureSp;
120 typedef de::SharedPtr<pipeline::TestTexture2D>			TestTexture2DSp;
121 typedef de::SharedPtr<pipeline::TestTextureCube>		TestTextureCubeSp;
122 typedef de::SharedPtr<pipeline::TestTexture2DArray>		TestTexture2DArraySp;
123 typedef de::SharedPtr<pipeline::TestTexture3D>			TestTexture3DSp;
124 typedef de::SharedPtr<pipeline::TestTexture1D>			TestTexture1DSp;
125 typedef de::SharedPtr<pipeline::TestTexture1DArray>		TestTexture1DArraySp;
126 typedef de::SharedPtr<pipeline::TestTextureCubeArray>	TestTextureCubeArraySp;
127 
128 class TextureBinding {
129 public:
130 	enum Type
131 	{
132 		TYPE_NONE = 0,
133 		TYPE_2D,
134 		TYPE_CUBE_MAP,
135 		TYPE_2D_ARRAY,
136 		TYPE_3D,
137 
138 		TYPE_1D,
139 		TYPE_1D_ARRAY,
140 		TYPE_CUBE_ARRAY,
141 
142 		TYPE_LAST
143 	};
144 
145 	enum ImageBackingMode
146 	{
147 		IMAGE_BACKING_MODE_REGULAR = 0,
148 		IMAGE_BACKING_MODE_SPARSE,
149 
150 		IMAGE_BACKING_MODE_LAST
151 	};
152 													TextureBinding				(Context& context);
153 													TextureBinding				(Context& context, const TestTextureSp& textureData, const Type type,
154 																				 const vk::VkImageAspectFlags aspectMask,
155 																				 const ImageBackingMode backingMode				= IMAGE_BACKING_MODE_REGULAR,
156 																				 const vk::VkComponentMapping componentMapping	= vk::makeComponentMappingRGBA());
getImage(void)157 	vk::VkImage										getImage					(void) { return *m_textureImage; }
getImageView(void)158 	vk::VkImageView									getImageView				(void) { return *m_textureImageView; }
getType(void)159 	Type											getType						(void) { return m_type; }
getTestTexture(void)160 	const pipeline::TestTexture&					getTestTexture				(void) { return *m_textureData; }
161 	void											updateTextureViewMipLevels	(deUint32 baseLevel, deUint32 maxLevel);
162 
163 private:
164 													TextureBinding				(const TextureBinding&);	// not allowed!
165 	TextureBinding&									operator=					(const TextureBinding&);	// not allowed!
166 
167 	void											updateTextureData			(const TestTextureSp& textureData, const Type type);
168 
169 	Context&										m_context;
170 	Type											m_type;
171 	ImageBackingMode								m_backingMode;
172 	TestTextureSp									m_textureData;
173 	vk::Move<vk::VkImage>							m_textureImage;
174 	de::MovePtr<vk::Allocation>						m_textureImageMemory;
175 	vk::Move<vk::VkImageView>						m_textureImageView;
176 	std::vector<de::SharedPtr<vk::Allocation> >		m_allocations;
177 	vk::VkImageAspectFlags							m_aspectMask;
178 	vk::VkComponentMapping							m_componentMapping;
179 };
180 
181 void checkTextureSupport (Context& context, const vk::VkFormat imageFormat, const vk::VkComponentMapping& imageComponents,
182 											const vk::VkFormat viewFormat,  const vk::VkComponentMapping& viewComponents);
183 
184 typedef de::SharedPtr<TextureBinding>	TextureBindingSp;
185 
186 class TextureRenderer
187 {
188 public:
189 											TextureRenderer				(Context& context,
190 																		 vk::VkSampleCountFlagBits sampleCount,
191 																		 deUint32 renderWidth,
192 																		 deUint32 renderHeight,
193 																		 vk::VkComponentMapping componentMapping = vk::makeComponentMappingRGBA());
194 
195 											TextureRenderer				(Context& context,
196 																		 vk::VkSampleCountFlagBits sampleCount,
197 																		 deUint32 renderWidth,
198 																		 deUint32 renderHeight,
199 																		 deUint32 renderDepth,
200 																		 vk::VkComponentMapping componentMapping = vk::makeComponentMappingRGBA(),
201 																		 vk::VkImageType imageType = vk::VK_IMAGE_TYPE_2D,
202 																		 vk::VkImageViewType imageViewType = vk::VK_IMAGE_VIEW_TYPE_2D,
203 																		 vk::VkFormat imageFormat = vk::VK_FORMAT_R8G8B8A8_UNORM);
204 
205 											~TextureRenderer			(void);
206 
207 	void									renderQuad					(tcu::Surface& result, int texUnit, const float* texCoord, glu::TextureTestUtil::TextureType texType);
208 	void									renderQuad					(tcu::Surface& result, int texUnit, const float* texCoord, const glu::TextureTestUtil::ReferenceParams& params);
209 	void									renderQuad					(tcu::Surface&									result,
210 																		 const float*									positions,
211 																		 const int										texUnit,
212 																		 const float*									texCoord,
213 																		 const glu::TextureTestUtil::ReferenceParams&	params,
214 																		 const float									maxAnisotropy);
215 
216 	void									renderQuad					(const tcu::PixelBufferAccess& result, int texUnit, const float* texCoord, const glu::TextureTestUtil::ReferenceParams& params);
217 	void									renderQuad					(const tcu::PixelBufferAccess&					result,
218 																		 const float*									positions,
219 																		 const int										texUnit,
220 																		 const float*									texCoord,
221 																		 const glu::TextureTestUtil::ReferenceParams&	params,
222 																		 const float									maxAnisotropy);
223 
224 	void									clearImage					(vk::VkImage image);
225 
226 	void									add2DTexture				(const TestTexture2DSp& texture,
227 																		 const vk::VkImageAspectFlags& aspectMask,
228 																		 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
229 	const pipeline::TestTexture2D&			get2DTexture				(int textureIndex) const;
230 
231 	void									addCubeTexture				(const TestTextureCubeSp& texture,
232 																		 const vk::VkImageAspectFlags& aspectMask,
233 																		 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
234 	const pipeline::TestTextureCube&		getCubeTexture				(int textureIndex) const;
235 
236 	void									add2DArrayTexture			(const TestTexture2DArraySp& texture,
237 																		 const vk::VkImageAspectFlags& aspectMask,
238 																		 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
239 	const pipeline::TestTexture2DArray&		get2DArrayTexture			(int textureIndex) const;
240 
241 	void									add3DTexture				(const TestTexture3DSp& texture,
242 																		 const vk::VkImageAspectFlags& aspectMask,
243 																		 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
244 	const pipeline::TestTexture3D&			get3DTexture				(int textureIndex) const;
245 
246 	void									add1DTexture				(const TestTexture1DSp& texture,
247 																		 const vk::VkImageAspectFlags& aspectMask,
248 																		 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
249 	const pipeline::TestTexture1D&			get1DTexture				(int textureIndex) const;
250 
251 	void									add1DArrayTexture			(const TestTexture1DArraySp& texture,
252 																		 const vk::VkImageAspectFlags& aspectMask,
253 																		 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
254 	const pipeline::TestTexture1DArray&		get1DArrayTexture			(int textureIndex) const;
255 
256 	void									addCubeArrayTexture			(const TestTextureCubeArraySp& texture,
257 																		 const vk::VkImageAspectFlags& aspectMask,
258 																		 TextureBinding::ImageBackingMode backingMode = TextureBinding::IMAGE_BACKING_MODE_REGULAR);
259 	const pipeline::TestTextureCubeArray&	getCubeArrayTexture			(int textureIndex) const;
260 
261 	void									setViewport					(float viewportX, float viewportY, float viewportW, float viewportH);
262 
263 	TextureBinding*							getTextureBinding			(int textureIndex) const;
264 
265 	deUint32								getRenderWidth				(void) const;
266 	deUint32								getRenderHeight				(void) const;
267 
268 protected:
269 											TextureRenderer				(const TextureRenderer& other);
270 	TextureRenderer&						operator=					(const TextureRenderer& other);
271 
272 	Context&								m_context;
273 	tcu::TestLog&							m_log;
274 
275 	const deUint32							m_renderWidth;
276 	const deUint32							m_renderHeight;
277 	const deUint32							m_renderDepth;
278 	const vk::VkSampleCountFlagBits			m_sampleCount;
279 	const deBool							m_multisampling;
280 
281 	const vk::VkFormat						m_imageFormat;
282 	const tcu::TextureFormat				m_textureFormat;
283 
284 	vk::Move<vk::VkImage>					m_image;
285 	de::MovePtr<vk::Allocation>				m_imageMemory;
286 	vk::Move<vk::VkImageView>				m_imageView;
287 
288 	vk::Move<vk::VkImage>					m_resolvedImage;
289 	de::MovePtr<vk::Allocation>				m_resolvedImageMemory;
290 	vk::Move<vk::VkImageView>				m_resolvedImageView;
291 
292 	vk::Move<vk::VkCommandPool>				m_commandPool;
293 	vk::Move<vk::VkRenderPass>				m_renderPass;
294 	vk::Move<vk::VkFramebuffer>				m_frameBuffer;
295 
296 	vk::Move<vk::VkDescriptorPool>			m_descriptorPool;
297 
298 	vk::Move<vk::VkBuffer>					m_uniformBuffer;
299 	de::MovePtr<vk::Allocation>				m_uniformBufferMemory;
300 	const vk::VkDeviceSize					m_uniformBufferSize;
301 
302 	vk::Move<vk::VkBuffer>					m_vertexIndexBuffer;
303 	de::MovePtr<vk::Allocation>				m_vertexIndexBufferMemory;
304 	static const vk::VkDeviceSize			s_vertexIndexBufferSize;
305 	static const deUint16					s_vertexIndices[6];
306 
307 	vk::Move<vk::VkBuffer>					m_resultBuffer;
308 	de::MovePtr<vk::Allocation>				m_resultBufferMemory;
309 	const vk::VkDeviceSize					m_resultBufferSize;
310 
311 	std::vector<TextureBindingSp>			m_textureBindings;
312 
313 	float									m_viewportOffsetX;
314 	float									m_viewportOffsetY;
315 	float									m_viewportWidth;
316 	float									m_viewportHeight;
317 
318 	vk::VkComponentMapping					m_componentMapping;
319 
320 private:
321 	vk::Move<vk::VkDescriptorSet>			makeDescriptorSet			(const vk::VkDescriptorPool descriptorPool, const vk::VkDescriptorSetLayout setLayout) const;
322 	void									addImageTransitionBarrier	(vk::VkCommandBuffer commandBuffer, vk::VkImage image, vk::VkPipelineStageFlags srcStageMask, vk::VkPipelineStageFlags dstStageMask, vk::VkAccessFlags srcAccessMask, vk::VkAccessFlags dstAccessMask, vk::VkImageLayout oldLayout, vk::VkImageLayout newLayout) const;
323 
324 };
325 
326 tcu::Sampler createSampler (tcu::Sampler::WrapMode wrapU, tcu::Sampler::WrapMode wrapV, tcu::Sampler::WrapMode wrapW, tcu::Sampler::FilterMode minFilterMode, tcu::Sampler::FilterMode magFilterMode, bool normalizedCoords = true);
327 tcu::Sampler createSampler (tcu::Sampler::WrapMode wrapU, tcu::Sampler::WrapMode wrapV, tcu::Sampler::FilterMode minFilterMode, tcu::Sampler::FilterMode magFilterMode, bool normalizedCoords = true);
328 tcu::Sampler createSampler (tcu::Sampler::WrapMode wrapU, tcu::Sampler::FilterMode minFilterMode, tcu::Sampler::FilterMode magFilterMode, bool normalizedCoords = true);
329 
330 TestTexture2DSp loadTexture2D (const tcu::Archive& archive, const std::vector<std::string>& filenames);
331 TestTextureCubeSp loadTextureCube (const tcu::Archive& archive, const std::vector<std::string>& filenames);
332 
333 // Add checkTextureSupport() function specialization for your test parameters class/struct if you need to use checkSupport() functionality
334 template <typename T>
checkTextureSupport(Context & context,const T & testParameters)335 void checkTextureSupport (Context& context, const T& testParameters)
336 {
337 	DE_UNREF(context);
338 	DE_UNREF(testParameters);
339 }
340 
341 template <typename INSTANCE_TYPE>
342 class TextureTestCase : public TestCase
343 {
344 public:
TextureTestCase(tcu::TestContext & context,const std::string & name,const std::string & description,const typename INSTANCE_TYPE::ParameterType & testParameters)345 										TextureTestCase	(tcu::TestContext& context, const std::string& name, const std::string& description, const typename INSTANCE_TYPE::ParameterType& testParameters)
346 												: TestCase				(context, name, description)
347 												, m_testsParameters		(testParameters)
348 										{}
349 
createInstance(Context & context) const350 	virtual TestInstance*				createInstance				(Context& context) const
351 										{
352 											return new INSTANCE_TYPE(context, m_testsParameters);
353 										}
354 
initPrograms(vk::SourceCollections & programCollection) const355 	virtual void						initPrograms				(vk::SourceCollections& programCollection) const
356 										{
357 											initializePrograms(programCollection, m_testsParameters.texCoordPrecision, m_testsParameters.programs);
358 										}
359 
checkSupport(Context & context) const360 	virtual void						checkSupport				(Context& context) const
361 										{
362 											checkTextureSupport(context, m_testsParameters);
363 										}
364 
365 
366 protected:
367 	const typename INSTANCE_TYPE::ParameterType m_testsParameters;
368 };
369 
370 struct TextureCommonTestCaseParameters
371 {
372 								TextureCommonTestCaseParameters	(void);
373 
374 	vk::VkSampleCountFlagBits	sampleCount;
375 	glu::Precision				texCoordPrecision;
376 
377 	tcu::Sampler::FilterMode	minFilter;
378 	tcu::Sampler::FilterMode	magFilter;
379 	tcu::Sampler::WrapMode		wrapS;
380 
381 	vk::VkFormat				format;
382 
383 	std::vector<util::Program>	programs;
384 
385 	deBool						unnormal;
386 	vk::VkImageAspectFlags		aspectMask;
387 };
388 
389 struct Texture2DTestCaseParameters : public TextureCommonTestCaseParameters
390 {
391 								Texture2DTestCaseParameters		(void);
392 	tcu::Sampler::WrapMode		wrapT;
393 	int							width;
394 	int							height;
395 	bool						mipmaps;
396 };
397 
398 struct TextureCubeTestCaseParameters : public TextureCommonTestCaseParameters
399 {
400 								TextureCubeTestCaseParameters	(void);
401 	tcu::Sampler::WrapMode		wrapT;
402 	int							size;
403 };
404 
405 struct Texture2DArrayTestCaseParameters : public Texture2DTestCaseParameters
406 {
407 								Texture2DArrayTestCaseParameters(void);
408 	tcu::Sampler::WrapMode		wrapT;
409 	int							numLayers;
410 };
411 
412 struct Texture3DTestCaseParameters : public Texture2DTestCaseParameters
413 {
414 								Texture3DTestCaseParameters		(void);
415 	tcu::Sampler::WrapMode		wrapR;
416 	int							depth;
417 };
418 
419 struct Texture1DTestCaseParameters : public TextureCommonTestCaseParameters
420 {
421 								Texture1DTestCaseParameters		(void);
422 	int							width;
423 };
424 
425 struct Texture1DArrayTestCaseParameters : public Texture1DTestCaseParameters
426 {
427 								Texture1DArrayTestCaseParameters(void);
428 	int							numLayers;
429 };
430 
431 struct TextureCubeArrayTestCaseParameters : public TextureCubeTestCaseParameters
432 {
433 								TextureCubeArrayTestCaseParameters	(void);
434 	int							numLayers;
435 };
436 
437 } // util
438 } // texture
439 } // vkt
440 
441 #endif // _VKTTEXTURETESTUTIL_HPP
442