• 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 
78 	enum BindingType
79 	{
80 		BindingSSBO,
81 		BindingImage,
82 		BindingUBO,
83 	};
84 
SSBODatavkt::subgroups::SSBOData85 	SSBOData() :
86 		initializeType	(InitializeNone),
87 		layout			(LayoutStd140),
88 		format			(vk::VK_FORMAT_UNDEFINED),
89 		numElements		(0),
90 		bindingType		(BindingSSBO),
91 		binding			(0u),
92 		stages			((vk::VkShaderStageFlags)0u)
93 	{}
94 
SSBODatavkt::subgroups::SSBOData95 	SSBOData (InputDataInitializeType	initializeType_,
96 			  InputDataLayoutType		layout_,
97 			  vk::VkFormat				format_,
98 			  vk::VkDeviceSize			numElements_,
99 			  BindingType				bindingType_	= BindingSSBO,
100 			  deUint32					binding_		= 0u,
101 			  vk::VkShaderStageFlags	stages_			= static_cast<vk::VkShaderStageFlags>(0u))
102 		: initializeType	(initializeType_)
103 		, layout			(layout_)
104 		, format			(format_)
105 		, numElements		(numElements_)
106 		, bindingType		(bindingType_)
107 		, binding			(binding_)
108 		, stages			(stages_)
109 	{
110 		if (bindingType == BindingUBO)
111 			DE_ASSERT(layout == LayoutStd140);
112 	}
113 
isImagevkt::subgroups::SSBOData114 	bool isImage () const
115 	{
116 		return (bindingType == BindingImage);
117 	}
118 
isUBOvkt::subgroups::SSBOData119 	bool isUBO () const
120 	{
121 		return (bindingType == BindingUBO);
122 	}
123 
124 	InputDataInitializeType		initializeType;
125 	InputDataLayoutType			layout;
126 	vk::VkFormat				format;
127 	vk::VkDeviceSize			numElements;
128 	BindingType					bindingType;
129 	deUint32					binding;
130 	vk::VkShaderStageFlags		stages;
131 };
132 
133 deUint32 getStagesCount (vk::VkShaderStageFlags shaderStages);
134 
135 std::string getSharedMemoryBallotHelper ();
136 
137 std::string getSharedMemoryBallotHelperARB ();
138 
139 deUint32 getSubgroupSize (Context& context);
140 
141 deUint32 maxSupportedSubgroupSize ();
142 
143 std::string getShaderStageName (vk::VkShaderStageFlags stage);
144 
145 std::string getSubgroupFeatureName (vk::VkSubgroupFeatureFlagBits bit);
146 
147 void addNoSubgroupShader (vk::SourceCollections& programCollection);
148 
149 void initStdFrameBufferPrograms (vk::SourceCollections&				programCollection,
150 								 const vk::ShaderBuildOptions&		buildOptions,
151 								 vk::VkShaderStageFlags				shaderStage,
152 								 vk::VkFormat						format,
153 								 bool								gsPointSize,
154 								 const std::string&					extHeader,
155 								 const std::string&					testSrc,
156 								 const std::string&					helperStr,
157 								 const std::vector<std::string>&	declarations	= std::vector<std::string>());
158 
159 void initStdPrograms (vk::SourceCollections&			programCollection,
160 					  const vk::ShaderBuildOptions&		buildOptions,
161 					  vk::VkShaderStageFlags			shaderStage,
162 					  vk::VkFormat						format,
163 					  bool								gsPointSize,
164 					  const std::string&				extHeader,
165 					  const std::string&				testSrc,
166 					  const std::string&				helperStr,
167 					  const std::vector<std::string>&	declarations			= std::vector<std::string>(),
168 					  const bool						avoidHelperInvocations	= false,
169 					  const std::string&				tempRes					= "  uint tempRes;\n");
170 
171 bool isSubgroupSupported (Context& context);
172 
173 bool areSubgroupOperationsSupportedForStage (Context& context, vk::VkShaderStageFlags stage);
174 
175 bool isSubgroupFeatureSupportedForDevice (Context& context, vk::VkSubgroupFeatureFlagBits bit);
176 
177 bool isFragmentSSBOSupportedForDevice (Context& context);
178 
179 bool isVertexSSBOSupportedForDevice (Context& context);
180 
181 bool isFormatSupportedForDevice (Context& context, vk::VkFormat format);
182 
183 bool isInt64SupportedForDevice (Context& context);
184 
185 bool isTessellationAndGeometryPointSizeSupported (Context& context);
186 
187 bool is16BitUBOStorageSupported (Context& context);
188 
189 bool is8BitUBOStorageSupported (Context& context);
190 
191 bool isSubgroupBroadcastDynamicIdSupported (Context& context);
192 
193 std::string getFormatNameForGLSL (vk::VkFormat format);
194 
195 std::string getAdditionalExtensionForFormat (vk::VkFormat format);
196 
197 const std::vector<vk::VkFormat> getAllFormats ();
198 
199 bool isFormatSigned (vk::VkFormat format);
200 bool isFormatUnsigned (vk::VkFormat format);
201 bool isFormatFloat (vk::VkFormat format);
202 bool isFormatBool (vk::VkFormat format);
203 bool isFormat8bitTy (vk::VkFormat format);
204 bool isFormat16BitTy (vk::VkFormat format);
205 
206 void addGeometryShadersFromTemplate (const std::string& glslTemplate, const vk::ShaderBuildOptions& options, vk::GlslSourceCollection& collection);
207 void addGeometryShadersFromTemplate (const std::string& spirvTemplate, const vk::SpirVAsmBuildOptions& options, vk::SpirVAsmCollection& collection);
208 
209 void setVertexShaderFrameBuffer (vk::SourceCollections& programCollection);
210 
211 void setFragmentShaderFrameBuffer (vk::SourceCollections& programCollection);
212 
213 void setFragmentShaderFrameBuffer (vk::SourceCollections& programCollection);
214 
215 void setTesCtrlShaderFrameBuffer (vk::SourceCollections& programCollection);
216 
217 void setTesEvalShaderFrameBuffer (vk::SourceCollections& programCollection);
218 
219 bool check (std::vector<const void*> datas, deUint32 width, deUint32 ref);
220 
221 bool checkComputeOrMesh (std::vector<const void*>	datas,
222 						 const deUint32				numWorkgroups[3],
223 						 const deUint32				localSize[3],
224 						 deUint32					ref);
225 
226 tcu::TestStatus makeTessellationEvaluationFrameBufferTest (Context&						context,
227 														   vk::VkFormat					format,
228 														   const SSBOData*				extraData,
229 														   deUint32						extraDataCount,
230 														   const void*					internalData,
231 														   CheckResult					checkResult,
232 														   const vk::VkShaderStageFlags	shaderStage = vk::VK_SHADER_STAGE_ALL_GRAPHICS);
233 
234 tcu::TestStatus makeGeometryFrameBufferTest (Context&			context,
235 											 vk::VkFormat		format,
236 											 const SSBOData*	extraData,
237 											 deUint32			extraDataCount,
238 											 const void*		internalData,
239 											 CheckResult		checkResult);
240 
241 // Allows using verification functions with or without the optional last boolean argument.
242 // If using a function that does not need the last argument, it will not be passed down to it.
243 class VerificationFunctor
244 {
245 public:
246 	using NoLastArgVariant	= bool(*)(const void*, std::vector<const void*>, deUint32, deUint32);
247 	using AllArgsVariant	= bool(*)(const void*, std::vector<const void*>, deUint32, deUint32, bool);
248 
VerificationFunctor(NoLastArgVariant func)249 	VerificationFunctor (NoLastArgVariant func)
250 		: m_noLastArgFunc{func}, m_allArgsFunc{nullptr}
251 		{}
252 
VerificationFunctor(AllArgsVariant func)253 	VerificationFunctor (AllArgsVariant func)
254 		: m_noLastArgFunc{nullptr}, m_allArgsFunc{func}
255 		{}
256 
operator ()(const void * extraData,std::vector<const void * > datas,deUint32 width,deUint32 subgroupSize,bool multipleCallsPossible) const257 	bool operator() (const void* extraData, std::vector<const void*> datas, deUint32 width, deUint32 subgroupSize, bool multipleCallsPossible) const
258 	{
259 		if (m_allArgsFunc)
260 			return m_allArgsFunc(extraData, datas, width, subgroupSize, multipleCallsPossible);
261 		return m_noLastArgFunc(extraData, datas, width, subgroupSize);
262 	}
263 
264 private:
265 	NoLastArgVariant	m_noLastArgFunc;
266 	AllArgsVariant		m_allArgsFunc;
267 };
268 
269 vk::VkShaderStageFlags getPossibleGraphicsSubgroupStages (Context& context, const vk::VkShaderStageFlags testedStages);
270 
271 tcu::TestStatus allStages (Context&						context,
272 						   vk::VkFormat					format,
273 						   const SSBOData*				extraData,
274 						   deUint32						extraDataCount,
275 						   const void*					internalData,
276 						   const VerificationFunctor&	checkResult,
277 						   const vk::VkShaderStageFlags	shaderStage);
278 
279 tcu::TestStatus makeVertexFrameBufferTest (Context&			context,
280 										   vk::VkFormat		format,
281 										   const SSBOData*	extraData,
282 										   deUint32			extraDataCount,
283 										   const void*		internalData,
284 										   CheckResult		checkResult);
285 
286 tcu::TestStatus makeFragmentFrameBufferTest (Context&				context,
287 											 vk::VkFormat			format,
288 											 const SSBOData*		extraData,
289 											 deUint32				extraDataCount,
290 											 const void*			internalData,
291 											 CheckResultFragment	checkResult);
292 
293 tcu::TestStatus makeComputeTest (Context&				context,
294 								 vk::VkFormat			format,
295 								 const SSBOData*		inputs,
296 								 deUint32				inputsCount,
297 								 const void*			internalData,
298 								 CheckResultCompute		checkResult,
299 								 deUint32				requiredSubgroupSize = 0u,
300 								 const deUint32			pipelineShaderStageCreateFlags = 0u);
301 
302 tcu::TestStatus makeMeshTest (Context&				context,
303 							  vk::VkFormat			format,
304 							  const SSBOData*		inputs,
305 							  deUint32				inputsCount,
306 							  const void*			internalData,
307 							  CheckResultCompute	checkResult,
308 							  deUint32				requiredSubgroupSize = 0u,
309 							  const deUint32		pipelineShaderStageCreateFlags = 0u);
310 
311 /* Functions needed for VK_EXT_subgroup_size_control tests */
312 tcu::TestStatus makeTessellationEvaluationFrameBufferTestRequiredSubgroupSize (Context&							context,
313 																			   vk::VkFormat						format,
314 																			   const SSBOData*					extraData,
315 																			   deUint32							extraDataCount,
316 																			   const void*						internalData,
317 																			   CheckResult						checkResult,
318 																			   const vk::VkShaderStageFlags		shaderStage = vk::VK_SHADER_STAGE_ALL_GRAPHICS,
319 																			   const deUint32					tessShaderStageCreateFlags = 0u,
320 																			   const deUint32					requiredSubgroupSize = 0u);
321 
322 tcu::TestStatus makeGeometryFrameBufferTestRequiredSubgroupSize (Context&			context,
323 																 vk::VkFormat		format,
324 																 const SSBOData*	extraData,
325 																 deUint32			extraDataCount,
326 																 const void*		internalData,
327 																 CheckResult		checkResult,
328 																 const deUint32		geometryShaderStageCreateFlags = 0u,
329 																 const deUint32		requiredSubgroupSize = 0u);
330 
331 tcu::TestStatus allStagesRequiredSubgroupSize (Context&						context,
332 											   vk::VkFormat					format,
333 											   const SSBOData*				extraDatas,
334 											   deUint32						extraDatasCount,
335 											   const void*					internalData,
336 											   const VerificationFunctor&	checkResult,
337 											   const vk::VkShaderStageFlags	shaderStageTested,
338 											   const deUint32				vertexShaderStageCreateFlags,
339 											   const deUint32				tessellationControlShaderStageCreateFlags,
340 											   const deUint32				tessellationEvalShaderStageCreateFlags,
341 											   const deUint32				geometryShaderStageCreateFlags,
342 											   const deUint32				fragmentShaderStageCreateFlags,
343 											   const deUint32				requiredSubgroupSize[5]);
344 
345 tcu::TestStatus makeVertexFrameBufferTestRequiredSubgroupSize (Context&				context,
346 															   vk::VkFormat			format,
347 															   const SSBOData*		extraData,
348 															   deUint32				extraDataCount,
349 															   const void*			internalData,
350 															   CheckResult			checkResult,
351 															   const deUint32		vertexShaderStageCreateFlags = 0u,
352 															   const deUint32		requiredSubgroupSize = 0u);
353 
354 tcu::TestStatus makeFragmentFrameBufferTestRequiredSubgroupSize (Context&				context,
355 																 vk::VkFormat			format,
356 																 const SSBOData*		extraData,
357 																 deUint32				extraDataCount,
358 																 const void*			internalData,
359 																 CheckResultFragment	checkResult,
360 																 const deUint32			fragmentShaderStageCreateFlags = 0u,
361 																 const deUint32			requiredSubgroupSize = 0u);
362 
363 tcu::TestStatus makeComputeTestRequiredSubgroupSize (Context&				context,
364 													 vk::VkFormat			format,
365 													 const SSBOData*		inputs,
366 													 deUint32				inputsCount,
367 													 const void*			internalData,
368 													 CheckResultCompute		checkResult,
369 													 const deUint32			pipelineShaderStageCreateFlags,
370 													 const deUint32			numWorkgroups[3],
371 													 const deBool			isRequiredSubgroupSize,
372 													 const deUint32			subgroupSize,
373 													 const deUint32			localSizesToTest[][3],
374 													 const deUint32			localSizesToTestCount);
375 
376 tcu::TestStatus makeMeshTestRequiredSubgroupSize	(Context&				context,
377 													 vk::VkFormat			format,
378 													 const SSBOData*		inputs,
379 													 deUint32				inputsCount,
380 													 const void*			internalData,
381 													 CheckResultCompute		checkResult,
382 													 const deUint32			pipelineShaderStageCreateFlags,
383 													 const deUint32			numWorkgroups[3],
384 													 const deBool			isRequiredSubgroupSize,
385 													 const deUint32			subgroupSize,
386 													 const deUint32			localSizesToTest[][3],
387 													 const deUint32			localSizesToTestCount);
388 
389 void supportedCheckShader (Context& context, const vk::VkShaderStageFlags shaderStage);
390 
391 const std::vector<vk::VkFormat> getAllRayTracingFormats();
392 
393 void addRayTracingNoSubgroupShader (vk::SourceCollections& programCollection);
394 
395 vk::VkShaderStageFlags getPossibleRayTracingSubgroupStages (Context& context, const vk::VkShaderStageFlags testedStages);
396 
397 tcu::TestStatus allRayTracingStages (Context&						context,
398 									 vk::VkFormat					format,
399 									 const SSBOData*				extraData,
400 									 deUint32						extraDataCount,
401 									 const void*					internalData,
402 									 const VerificationFunctor&		checkResult,
403 									 const vk::VkShaderStageFlags	shaderStage);
404 
405 tcu::TestStatus allRayTracingStagesRequiredSubgroupSize (Context&						context,
406 														 vk::VkFormat					format,
407 														 const SSBOData*				extraDatas,
408 														 deUint32						extraDatasCount,
409 														 const void*					internalData,
410 														 const VerificationFunctor&		checkResult,
411 														 const vk::VkShaderStageFlags	shaderStageTested,
412 														 const deUint32					shaderStageCreateFlags[6],
413 														 const deUint32					requiredSubgroupSize[6]);
414 } // subgroups
415 } // vkt
416 
417 #endif // _VKTSUBGROUPSTESTSUTILS_HPP
418