1 #ifndef _VKTPIPELINEMULTISAMPLEBASE_HPP
2 #define _VKTPIPELINEMULTISAMPLEBASE_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 vktPipelineMultisampleBase.hpp
23  * \brief Multisample Tests Base Classes
24  *//*--------------------------------------------------------------------*/
25 
26 #include "vktPipelineMultisampleTestsUtil.hpp"
27 #include "vktTestCase.hpp"
28 #include "tcuVector.hpp"
29 
30 namespace vkt
31 {
32 namespace pipeline
33 {
34 namespace multisample
35 {
36 
37 struct ImageMSParams
38 {
ImageMSParamsvkt::pipeline::multisample::ImageMSParams39 	ImageMSParams(const vk::VkSampleCountFlagBits samples, const tcu::UVec3& size) : numSamples(samples), imageSize(size) {}
40 
41 	vk::VkSampleCountFlagBits	numSamples;
42 	tcu::UVec3					imageSize;
43 };
44 
45 class MultisampleCaseBase : public TestCase
46 {
47 public:
MultisampleCaseBase(tcu::TestContext & testCtx,const std::string & name,const ImageMSParams & imageMSParams)48 	MultisampleCaseBase	(tcu::TestContext&		testCtx,
49 						 const std::string&		name,
50 						 const ImageMSParams&	imageMSParams)
51 		: TestCase(testCtx, name, "")
52 		, m_imageMSParams(imageMSParams)
53 	{}
54 
55 protected:
56 	const ImageMSParams m_imageMSParams;
57 };
58 
59 typedef MultisampleCaseBase* (*MultisampleCaseFuncPtr)(tcu::TestContext& testCtx, const std::string& name, const ImageMSParams& imageMSParams);
60 
61 class MultisampleInstanceBase : public TestInstance
62 {
63 public:
MultisampleInstanceBase(Context & context,const ImageMSParams & imageMSParams)64 								MultisampleInstanceBase		(Context&							context,
65 															 const ImageMSParams&				imageMSParams)
66 		: TestInstance		(context)
67 		, m_imageMSParams	(imageMSParams)
68 		, m_imageType		(IMAGE_TYPE_2D)
69 		, m_imageFormat		(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8))
70 	{}
71 
72 	typedef std::vector<vk::VkVertexInputAttributeDescription> VertexAttribDescVec;
73 
74 	struct VertexDataDesc
75 	{
76 		vk::VkPrimitiveTopology	primitiveTopology;
77 		deUint32				verticesCount;
78 		deUint32				dataStride;
79 		vk::VkDeviceSize		dataSize;
80 		VertexAttribDescVec		vertexAttribDescVec;
81 	};
82 
83 protected:
84 
85 	void					validateImageSize			(const vk::InstanceInterface&	instance,
86 														 const vk::VkPhysicalDevice		physicalDevice,
87 														 const ImageType				imageType,
88 														 const tcu::UVec3&				imageSize) const;
89 
90 	void					validateImageFeatureFlags	(const vk::InstanceInterface&	instance,
91 														 const vk::VkPhysicalDevice		physicalDevice,
92 														 const vk::VkFormat				format,
93 														 const vk::VkFormatFeatureFlags	featureFlags) const;
94 
95 	void					validateImageInfo			(const vk::InstanceInterface&	instance,
96 														 const vk::VkPhysicalDevice		physicalDevice,
97 														 const vk::VkImageCreateInfo&	imageInfo) const;
98 
99 	virtual VertexDataDesc	getVertexDataDescripton		(void) const = 0;
100 
101 	virtual void			uploadVertexData			(const vk::Allocation&			vertexBufferAllocation,
102 														 const VertexDataDesc&			vertexDataDescripton) const = 0;
103 protected:
104 	const ImageMSParams			m_imageMSParams;
105 	const ImageType				m_imageType;
106 	const tcu::TextureFormat	m_imageFormat;
107 };
108 
109 } // multisample
110 
111 template <class CaseClass>
makeMSGroup(tcu::TestContext & testCtx,const std::string groupName,const tcu::UVec3 imageSizes[],const deUint32 imageSizesElemCount,const vk::VkSampleCountFlagBits imageSamples[],const deUint32 imageSamplesElemCount)112 tcu::TestCaseGroup* makeMSGroup	(tcu::TestContext&							testCtx,
113 								 const std::string							groupName,
114 								 const tcu::UVec3							imageSizes[],
115 								 const deUint32								imageSizesElemCount,
116 								 const vk::VkSampleCountFlagBits			imageSamples[],
117 								 const deUint32								imageSamplesElemCount)
118 {
119 	de::MovePtr<tcu::TestCaseGroup> caseGroup(new tcu::TestCaseGroup(testCtx, groupName.c_str(), ""));
120 
121 	for (deUint32 imageSizeNdx = 0u; imageSizeNdx < imageSizesElemCount; ++imageSizeNdx)
122 	{
123 		const tcu::UVec3	imageSize = imageSizes[imageSizeNdx];
124 		std::ostringstream	imageSizeStream;
125 
126 		imageSizeStream << imageSize.x() << "_" << imageSize.y() << "_" << imageSize.z();
127 
128 		de::MovePtr<tcu::TestCaseGroup> sizeGroup(new tcu::TestCaseGroup(testCtx, imageSizeStream.str().c_str(), ""));
129 
130 		for (deUint32 imageSamplesNdx = 0u; imageSamplesNdx < imageSamplesElemCount; ++imageSamplesNdx)
131 		{
132 			const vk::VkSampleCountFlagBits		samples = imageSamples[imageSamplesNdx];
133 			const multisample::ImageMSParams	imageMSParams = multisample::ImageMSParams(samples, imageSize);
134 
135 			sizeGroup->addChild(CaseClass::createCase(testCtx, "samples_" + de::toString(samples), imageMSParams));
136 		}
137 
138 		caseGroup->addChild(sizeGroup.release());
139 	}
140 	return caseGroup.release();
141 }
142 
143 } // pipeline
144 } // vkt
145 
146 #endif // _VKTPIPELINEMULTISAMPLEBASE_HPP
147