• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _VKTSUBGROUPSTESTSUTILS_HPP
2 #define _VKTSUBGROUPSTESTSUTILS_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2017 The Khronos Group Inc.
8  * Copyright (c) 2017 Codeplay Software Ltd.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */ /*!
23  * \file
24  * \brief Subgroups tests utility classes
25  */ /*--------------------------------------------------------------------*/
26 
27 #include "vkBuilderUtil.hpp"
28 #include "vkDefs.hpp"
29 #include "vkDeviceUtil.hpp"
30 #include "vkMemUtil.hpp"
31 #include "vkPlatform.hpp"
32 #include "vkPrograms.hpp"
33 #include "vkQueryUtil.hpp"
34 #include "vkRef.hpp"
35 #include "vkRefUtil.hpp"
36 #include "vkStrUtil.hpp"
37 #include "vkTypeUtil.hpp"
38 #include "vktTestCase.hpp"
39 #include "vktTestCaseUtil.hpp"
40 #include "vkRayTracingUtil.hpp"
41 
42 #include "tcuFormatUtil.hpp"
43 #include "tcuTestLog.hpp"
44 #include "tcuVectorUtil.hpp"
45 
46 #include "gluShaderUtil.hpp"
47 
48 #include "deSharedPtr.hpp"
49 #include "deUniquePtr.hpp"
50 
51 #include <string>
52 #include <vector>
53 
54 namespace vkt
55 {
56 namespace subgroups
57 {
58 typedef bool (*CheckResult)(const void* internalData, std::vector<const void*> datas, deUint32 width, deUint32 subgroupSize);
59 typedef bool (*CheckResultFragment)(const void* internalData, std::vector<const void*> datas, deUint32 width, deUint32 height, deUint32 subgroupSize);
60 typedef bool (*CheckResultCompute)(const void* internalData, std::vector<const void*> datas, const deUint32 numWorkgroups[3], const deUint32 localSize[3], deUint32 subgroupSize);
61 
62 // A struct to represent input data to a shader
63 struct SSBOData
64 {
65 	enum InputDataInitializeType
66 	{
67 		InitializeNone = 0,
68 		InitializeNonZero,
69 		InitializeZero,
70 	};
71 	enum InputDataLayoutType
72 	{
73 		LayoutStd140 = 0,
74 		LayoutStd430,
75 		LayoutPacked
76 	};
77 
SSBODatavkt::subgroups::SSBOData78 	SSBOData() :
79 		initializeType	(InitializeNone),
80 		layout			(LayoutStd140),
81 		format			(vk::VK_FORMAT_UNDEFINED),
82 		numElements		(0),
83 		isImage			(false),
84 		binding			(0u),
85 		stages			((vk::VkShaderStageFlags)0u)
86 	{}
87 
SSBODatavkt::subgroups::SSBOData88 	SSBOData (InputDataInitializeType	initializeType_,
89 			  InputDataLayoutType		layout_,
90 			  vk::VkFormat				format_,
91 			  vk::VkDeviceSize			numElements_,
92 			  bool						isImage_	= false,
93 			  deUint32					binding_	= 0u,
94 			  vk::VkShaderStageFlags	stages_		= static_cast<vk::VkShaderStageFlags>(0u))
95 		: initializeType	(initializeType_)
96 		, layout			(layout_)
97 		, format			(format_)
98 		, numElements		(numElements_)
99 		, isImage			(isImage_)
100 		, binding			(binding_)
101 		, stages			(stages_)
102 	{}
103 
104 	InputDataInitializeType		initializeType;
105 	InputDataLayoutType			layout;
106 	vk::VkFormat				format;
107 	vk::VkDeviceSize			numElements;
108 	bool						isImage;
109 	deUint32					binding;
110 	vk::VkShaderStageFlags		stages;
111 };
112 
113 deUint32 getStagesCount (vk::VkShaderStageFlags shaderStages);
114 
115 std::string getSharedMemoryBallotHelper ();
116 
117 std::string getSharedMemoryBallotHelperARB ();
118 
119 deUint32 getSubgroupSize (Context& context);
120 
121 deUint32 maxSupportedSubgroupSize ();
122 
123 std::string getShaderStageName (vk::VkShaderStageFlags stage);
124 
125 std::string getSubgroupFeatureName (vk::VkSubgroupFeatureFlagBits bit);
126 
127 void addNoSubgroupShader (vk::SourceCollections& programCollection);
128 
129 void initStdFrameBufferPrograms (vk::SourceCollections&				programCollection,
130 								 const vk::ShaderBuildOptions&		buildOptions,
131 								 vk::VkShaderStageFlags				shaderStage,
132 								 vk::VkFormat						format,
133 								 bool								gsPointSize,
134 								 const std::string&					extHeader,
135 								 const std::string&					testSrc,
136 								 const std::string&					helperStr,
137 								 const std::vector<std::string>&	declarations	= std::vector<std::string>());
138 
139 void initStdPrograms (vk::SourceCollections&			programCollection,
140 					  const vk::ShaderBuildOptions&		buildOptions,
141 					  vk::VkShaderStageFlags			shaderStage,
142 					  vk::VkFormat						format,
143 					  bool								gsPointSize,
144 					  const std::string&				extHeader,
145 					  const std::string&				testSrc,
146 					  const std::string&				helperStr,
147 					  const std::vector<std::string>&	declarations			= std::vector<std::string>(),
148 					  const bool						avoidHelperInvocations	= false,
149 					  const std::string&				tempRes					= "  uint tempRes;\n");
150 
151 bool isSubgroupSupported (Context& context);
152 
153 bool areSubgroupOperationsSupportedForStage (Context& context, vk::VkShaderStageFlags stage);
154 
155 bool isSubgroupFeatureSupportedForDevice (Context& context, vk::VkSubgroupFeatureFlagBits bit);
156 
157 bool isFragmentSSBOSupportedForDevice (Context& context);
158 
159 bool isVertexSSBOSupportedForDevice (Context& context);
160 
161 bool isFormatSupportedForDevice (Context& context, vk::VkFormat format);
162 
163 bool isInt64SupportedForDevice (Context& context);
164 
165 bool isTessellationAndGeometryPointSizeSupported (Context& context);
166 
167 bool is16BitUBOStorageSupported (Context& context);
168 
169 bool is8BitUBOStorageSupported (Context& context);
170 
171 bool isSubgroupBroadcastDynamicIdSupported (Context& context);
172 
173 std::string getFormatNameForGLSL (vk::VkFormat format);
174 
175 std::string getAdditionalExtensionForFormat (vk::VkFormat format);
176 
177 const std::vector<vk::VkFormat> getAllFormats ();
178 
179 bool isFormatSigned (vk::VkFormat format);
180 bool isFormatUnsigned (vk::VkFormat format);
181 bool isFormatFloat (vk::VkFormat format);
182 bool isFormatBool (vk::VkFormat format);
183 bool isFormat8bitTy (vk::VkFormat format);
184 bool isFormat16BitTy (vk::VkFormat format);
185 
186 void addGeometryShadersFromTemplate (const std::string& glslTemplate, const vk::ShaderBuildOptions& options, vk::GlslSourceCollection& collection);
187 void addGeometryShadersFromTemplate (const std::string& spirvTemplate, const vk::SpirVAsmBuildOptions& options, vk::SpirVAsmCollection& collection);
188 
189 void setVertexShaderFrameBuffer (vk::SourceCollections& programCollection);
190 
191 void setFragmentShaderFrameBuffer (vk::SourceCollections& programCollection);
192 
193 void setFragmentShaderFrameBuffer (vk::SourceCollections& programCollection);
194 
195 void setTesCtrlShaderFrameBuffer (vk::SourceCollections& programCollection);
196 
197 void setTesEvalShaderFrameBuffer (vk::SourceCollections& programCollection);
198 
199 bool check (std::vector<const void*> datas, deUint32 width, deUint32 ref);
200 
201 bool checkCompute (std::vector<const void*>		datas,
202 				   const deUint32				numWorkgroups[3],
203 				   const deUint32				localSize[3],
204 				   deUint32						ref);
205 
206 tcu::TestStatus makeTessellationEvaluationFrameBufferTest (Context&						context,
207 														   vk::VkFormat					format,
208 														   const SSBOData*				extraData,
209 														   deUint32						extraDataCount,
210 														   const void*					internalData,
211 														   CheckResult					checkResult,
212 														   const vk::VkShaderStageFlags	shaderStage = vk::VK_SHADER_STAGE_ALL_GRAPHICS);
213 
214 tcu::TestStatus makeGeometryFrameBufferTest (Context&			context,
215 											 vk::VkFormat		format,
216 											 const SSBOData*	extraData,
217 											 deUint32			extraDataCount,
218 											 const void*		internalData,
219 											 CheckResult		checkResult);
220 
221 // Allows using verification functions with or without the optional last boolean argument.
222 // If using a function that does not need the last argument, it will not be passed down to it.
223 class VerificationFunctor
224 {
225 public:
226 	using NoLastArgVariant	= bool(*)(const void*, std::vector<const void*>, deUint32, deUint32);
227 	using AllArgsVariant	= bool(*)(const void*, std::vector<const void*>, deUint32, deUint32, bool);
228 
VerificationFunctor(NoLastArgVariant func)229 	VerificationFunctor (NoLastArgVariant func)
230 		: m_noLastArgFunc{func}, m_allArgsFunc{nullptr}
231 		{}
232 
VerificationFunctor(AllArgsVariant func)233 	VerificationFunctor (AllArgsVariant func)
234 		: m_noLastArgFunc{nullptr}, m_allArgsFunc{func}
235 		{}
236 
operator ()(const void * extraData,std::vector<const void * > datas,deUint32 width,deUint32 subgroupSize,bool multipleCallsPossible) const237 	bool operator() (const void* extraData, std::vector<const void*> datas, deUint32 width, deUint32 subgroupSize, bool multipleCallsPossible) const
238 	{
239 		if (m_allArgsFunc)
240 			return m_allArgsFunc(extraData, datas, width, subgroupSize, multipleCallsPossible);
241 		return m_noLastArgFunc(extraData, datas, width, subgroupSize);
242 	}
243 
244 private:
245 	NoLastArgVariant	m_noLastArgFunc;
246 	AllArgsVariant		m_allArgsFunc;
247 };
248 
249 vk::VkShaderStageFlags getPossibleGraphicsSubgroupStages (Context& context, const vk::VkShaderStageFlags testedStages);
250 
251 tcu::TestStatus allStages (Context&						context,
252 						   vk::VkFormat					format,
253 						   const SSBOData*				extraData,
254 						   deUint32						extraDataCount,
255 						   const void*					internalData,
256 						   const VerificationFunctor&	checkResult,
257 						   const vk::VkShaderStageFlags	shaderStage);
258 
259 tcu::TestStatus makeVertexFrameBufferTest (Context&			context,
260 										   vk::VkFormat		format,
261 										   const SSBOData*	extraData,
262 										   deUint32			extraDataCount,
263 										   const void*		internalData,
264 										   CheckResult		checkResult);
265 
266 tcu::TestStatus makeFragmentFrameBufferTest (Context&				context,
267 											 vk::VkFormat			format,
268 											 const SSBOData*		extraData,
269 											 deUint32				extraDataCount,
270 											 const void*			internalData,
271 											 CheckResultFragment	checkResult);
272 
273 tcu::TestStatus makeComputeTest (Context&				context,
274 								 vk::VkFormat			format,
275 								 const SSBOData*		inputs,
276 								 deUint32				inputsCount,
277 								 const void*			internalData,
278 								 CheckResultCompute		checkResult,
279 								 deUint32				requiredSubgroupSize = 0u,
280 								 const deUint32			pipelineShaderStageCreateFlags = 0u);
281 
282 /* Functions needed for VK_EXT_subgroup_size_control tests */
283 tcu::TestStatus makeTessellationEvaluationFrameBufferTestRequiredSubgroupSize (Context&							context,
284 																			   vk::VkFormat						format,
285 																			   const SSBOData*					extraData,
286 																			   deUint32							extraDataCount,
287 																			   const void*						internalData,
288 																			   CheckResult						checkResult,
289 																			   const vk::VkShaderStageFlags		shaderStage = vk::VK_SHADER_STAGE_ALL_GRAPHICS,
290 																			   const deUint32					tessShaderStageCreateFlags = 0u,
291 																			   const deUint32					requiredSubgroupSize = 0u);
292 
293 tcu::TestStatus makeGeometryFrameBufferTestRequiredSubgroupSize (Context&			context,
294 																 vk::VkFormat		format,
295 																 const SSBOData*	extraData,
296 																 deUint32			extraDataCount,
297 																 const void*		internalData,
298 																 CheckResult		checkResult,
299 																 const deUint32		geometryShaderStageCreateFlags = 0u,
300 																 const deUint32		requiredSubgroupSize = 0u);
301 
302 tcu::TestStatus allStagesRequiredSubgroupSize (Context&						context,
303 											   vk::VkFormat					format,
304 											   const SSBOData*				extraDatas,
305 											   deUint32						extraDatasCount,
306 											   const void*					internalData,
307 											   const VerificationFunctor&	checkResult,
308 											   const vk::VkShaderStageFlags	shaderStageTested,
309 											   const deUint32				vertexShaderStageCreateFlags,
310 											   const deUint32				tessellationControlShaderStageCreateFlags,
311 											   const deUint32				tessellationEvalShaderStageCreateFlags,
312 											   const deUint32				geometryShaderStageCreateFlags,
313 											   const deUint32				fragmentShaderStageCreateFlags,
314 											   const deUint32				requiredSubgroupSize[5]);
315 
316 tcu::TestStatus makeVertexFrameBufferTestRequiredSubgroupSize (Context&				context,
317 															   vk::VkFormat			format,
318 															   const SSBOData*		extraData,
319 															   deUint32				extraDataCount,
320 															   const void*			internalData,
321 															   CheckResult			checkResult,
322 															   const deUint32		vertexShaderStageCreateFlags = 0u,
323 															   const deUint32		requiredSubgroupSize = 0u);
324 
325 tcu::TestStatus makeFragmentFrameBufferTestRequiredSubgroupSize (Context&				context,
326 																 vk::VkFormat			format,
327 																 const SSBOData*		extraData,
328 																 deUint32				extraDataCount,
329 																 const void*			internalData,
330 																 CheckResultFragment	checkResult,
331 																 const deUint32			fragmentShaderStageCreateFlags = 0u,
332 																 const deUint32			requiredSubgroupSize = 0u);
333 
334 tcu::TestStatus makeComputeTestRequiredSubgroupSize (Context&				context,
335 													 vk::VkFormat			format,
336 													 const SSBOData*		inputs,
337 													 deUint32				inputsCount,
338 													 const void*			internalData,
339 													 CheckResultCompute		checkResult,
340 													 const deUint32			pipelineShaderStageCreateFlags,
341 													 const deUint32			numWorkgroups[3],
342 													 const deBool			isRequiredSubgroupSize,
343 													 const deUint32			subgroupSize,
344 													 const deUint32			localSizesToTest[][3],
345 													 const deUint32			localSizesToTestCount);
346 
347 void supportedCheckShader (Context& context, const vk::VkShaderStageFlags shaderStage);
348 
349 const std::vector<vk::VkFormat> getAllRayTracingFormats();
350 
351 void addRayTracingNoSubgroupShader (vk::SourceCollections& programCollection);
352 
353 vk::VkShaderStageFlags getPossibleRayTracingSubgroupStages (Context& context, const vk::VkShaderStageFlags testedStages);
354 
355 tcu::TestStatus allRayTracingStages (Context&						context,
356 									 vk::VkFormat					format,
357 									 const SSBOData*				extraData,
358 									 deUint32						extraDataCount,
359 									 const void*					internalData,
360 									 const VerificationFunctor&		checkResult,
361 									 const vk::VkShaderStageFlags	shaderStage);
362 
363 tcu::TestStatus allRayTracingStagesRequiredSubgroupSize (Context&						context,
364 														 vk::VkFormat					format,
365 														 const SSBOData*				extraDatas,
366 														 deUint32						extraDatasCount,
367 														 const void*					internalData,
368 														 const VerificationFunctor&		checkResult,
369 														 const vk::VkShaderStageFlags	shaderStageTested,
370 														 const deUint32					shaderStageCreateFlags[6],
371 														 const deUint32					requiredSubgroupSize[6]);
372 } // subgroups
373 } // vkt
374 
375 #endif // _VKTSUBGROUPSTESTSUTILS_HPP
376