1 /*-------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2020 The Khronos Group Inc.
6  * Copyright (c) 2020 Valve Corporation.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *//*!
21  * \file
22  * \brief Ray Tracing Data Spill tests
23  *//*--------------------------------------------------------------------*/
24 #include "vktRayTracingDataSpillTests.hpp"
25 #include "vktTestCase.hpp"
26 
27 #include "vkRayTracingUtil.hpp"
28 #include "vkObjUtil.hpp"
29 #include "vkBufferWithMemory.hpp"
30 #include "vkImageWithMemory.hpp"
31 #include "vkBuilderUtil.hpp"
32 #include "vkCmdUtil.hpp"
33 #include "vkTypeUtil.hpp"
34 #include "vkBarrierUtil.hpp"
35 
36 #include "tcuStringTemplate.hpp"
37 #include "tcuFloat.hpp"
38 
39 #include "deUniquePtr.hpp"
40 #include "deSTLUtil.hpp"
41 
42 #include <sstream>
43 #include <string>
44 #include <map>
45 #include <vector>
46 #include <array>
47 #include <utility>
48 
49 using namespace vk;
50 
51 namespace vkt
52 {
53 namespace RayTracing
54 {
55 
56 namespace
57 {
58 
59 // The type of shader call that will be used.
60 enum class CallType
61 {
62 	TRACE_RAY = 0,
63 	EXECUTE_CALLABLE,
64 	REPORT_INTERSECTION,
65 };
66 
67 // The type of data that will be checked.
68 enum class DataType
69 {
70 	// These can be made an array or vector.
71 	INT32 = 0,
72 	UINT32,
73 	INT64,
74 	UINT64,
75 	INT16,
76 	UINT16,
77 	INT8,
78 	UINT8,
79 	FLOAT32,
80 	FLOAT64,
81 	FLOAT16,
82 
83 	// These are standalone, so the vector type should be scalar.
84 	STRUCT,
85 	IMAGE,
86 	SAMPLER,
87 	SAMPLED_IMAGE,
88 	PTR_IMAGE,
89 	PTR_SAMPLER,
90 	PTR_SAMPLED_IMAGE,
91 	PTR_TEXEL,
92 	OP_NULL,
93 	OP_UNDEF,
94 };
95 
96 // The type of vector in use.
97 enum class VectorType
98 {
99 	SCALAR	= 1,
100 	V2		= 2,
101 	V3		= 3,
102 	V4		= 4,
103 	A5		= 5,
104 };
105 
106 struct InputStruct
107 {
108 	deUint32	uintPart;
109 	float		floatPart;
110 };
111 
112 constexpr auto			kImageFormat		= VK_FORMAT_R32_UINT;
113 const auto				kImageExtent		= makeExtent3D(1u, 1u, 1u);
114 
115 // For samplers.
116 const VkImageUsageFlags	kSampledImageUsage	= (VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT);
117 constexpr size_t		kNumImages			= 4u;
118 constexpr size_t		kNumSamplers		= 4u;
119 constexpr size_t		kNumCombined		= 2u;
120 constexpr size_t		kNumAloneImages		= kNumImages - kNumCombined;
121 constexpr size_t		kNumAloneSamplers	= kNumSamplers - kNumCombined;
122 
123 // For storage images.
124 const VkImageUsageFlags	kStorageImageUsage	= (VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_STORAGE_BIT);
125 
126 // For the pipeline interface tests.
127 constexpr size_t		kNumStorageValues	= 6u;
128 constexpr deUint32		kShaderRecordSize	= sizeof(tcu::UVec4);
129 
130 // Get the effective vector length in memory.
getEffectiveVectorLength(VectorType vectorType)131 size_t getEffectiveVectorLength (VectorType vectorType)
132 {
133 	return ((vectorType == VectorType::V3) ? static_cast<size_t>(4) : static_cast<size_t>(vectorType));
134 }
135 
136 // Get the corresponding element size.
getElementSize(DataType dataType, VectorType vectorType)137 VkDeviceSize getElementSize(DataType dataType, VectorType vectorType)
138 {
139 	const size_t	length		= getEffectiveVectorLength(vectorType);
140 	size_t			dataSize	= 0u;
141 
142 	switch (dataType)
143 	{
144 	case DataType::INT32:			dataSize = sizeof(deInt32);			break;
145 	case DataType::UINT32:			dataSize = sizeof(deUint32);		break;
146 	case DataType::INT64:			dataSize = sizeof(deInt64);			break;
147 	case DataType::UINT64:			dataSize = sizeof(deUint64);		break;
148 	case DataType::INT16:			dataSize = sizeof(deInt16);			break;
149 	case DataType::UINT16:			dataSize = sizeof(deUint16);		break;
150 	case DataType::INT8:			dataSize = sizeof(deInt8);			break;
151 	case DataType::UINT8:			dataSize = sizeof(deUint8);			break;
152 	case DataType::FLOAT32:			dataSize = sizeof(tcu::Float32);	break;
153 	case DataType::FLOAT64:			dataSize = sizeof(tcu::Float64);	break;
154 	case DataType::FLOAT16:			dataSize = sizeof(tcu::Float16);	break;
155 	case DataType::STRUCT:			dataSize = sizeof(InputStruct);		break;
156 	case DataType::IMAGE:				// fallthrough.
157 	case DataType::SAMPLER:				// fallthrough.
158 	case DataType::SAMPLED_IMAGE:		// fallthrough.
159 	case DataType::PTR_IMAGE:			// fallthrough.
160 	case DataType::PTR_SAMPLER:			// fallthrough.
161 	case DataType::PTR_SAMPLED_IMAGE:	// fallthrough.
162 									dataSize = sizeof(tcu::Float32);	break;
163 	case DataType::PTR_TEXEL:		dataSize = sizeof(deInt32);			break;
164 	case DataType::OP_NULL:				// fallthrough.
165 	case DataType::OP_UNDEF:			// fallthrough.
166 									dataSize = sizeof(deUint32);		break;
167 	default: DE_ASSERT(false); break;
168 	}
169 
170 	return static_cast<VkDeviceSize>(dataSize * length);
171 }
172 
173 // Proper stage for generating default geometry.
getShaderStageForGeometry(CallType type_)174 VkShaderStageFlagBits getShaderStageForGeometry (CallType type_)
175 {
176 	VkShaderStageFlagBits bits = VK_SHADER_STAGE_FLAG_BITS_MAX_ENUM;
177 
178 	switch (type_)
179 	{
180 	case CallType::TRACE_RAY:			bits = VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR;		break;
181 	case CallType::EXECUTE_CALLABLE:	bits = VK_SHADER_STAGE_CALLABLE_BIT_KHR;		break;
182 	case CallType::REPORT_INTERSECTION:	bits = VK_SHADER_STAGE_INTERSECTION_BIT_KHR;	break;
183 	default: DE_ASSERT(false); break;
184 	}
185 
186 	DE_ASSERT(bits != VK_SHADER_STAGE_FLAG_BITS_MAX_ENUM);
187 	return bits;
188 }
189 
getShaderStages(CallType type_)190 VkShaderStageFlags getShaderStages (CallType type_)
191 {
192 	VkShaderStageFlags flags = VK_SHADER_STAGE_RAYGEN_BIT_KHR;
193 
194 	switch (type_)
195 	{
196 	case CallType::EXECUTE_CALLABLE:
197 		flags |= VK_SHADER_STAGE_CALLABLE_BIT_KHR;
198 		break;
199 	case CallType::TRACE_RAY:
200 		flags |= VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR;
201 		break;
202 	case CallType::REPORT_INTERSECTION:
203 		flags |= VK_SHADER_STAGE_INTERSECTION_BIT_KHR;
204 		flags |= VK_SHADER_STAGE_ANY_HIT_BIT_KHR;
205 		break;
206 	default:
207 		DE_ASSERT(false);
208 		break;
209 	}
210 
211 	return flags;
212 }
213 
214 // Some test types need additional descriptors with samplers, images and combined image samplers.
samplersNeeded(DataType dataType)215 bool samplersNeeded (DataType dataType)
216 {
217 	bool needed = false;
218 
219 	switch (dataType)
220 	{
221 	case DataType::IMAGE:
222 	case DataType::SAMPLER:
223 	case DataType::SAMPLED_IMAGE:
224 	case DataType::PTR_IMAGE:
225 	case DataType::PTR_SAMPLER:
226 	case DataType::PTR_SAMPLED_IMAGE:
227 		needed = true;
228 		break;
229 	default:
230 		break;
231 	}
232 
233 	return needed;
234 }
235 
236 // Some test types need an additional descriptor with a storage image.
storageImageNeeded(DataType dataType)237 bool storageImageNeeded (DataType dataType)
238 {
239 	return (dataType == DataType::PTR_TEXEL);
240 }
241 
242 // Returns two strings:
243 //		.first is an optional GLSL additional type declaration (for structs, basically).
244 //		.second is the value declaration inside the input block.
getGLSLInputValDecl(DataType dataType, VectorType vectorType)245 std::pair<std::string, std::string> getGLSLInputValDecl (DataType dataType, VectorType vectorType)
246 {
247 	using TypePair	= std::pair<DataType, VectorType>;
248 	using TypeMap	= std::map<TypePair, std::string>;
249 
250 	const std::string	varName		= "val";
251 	const auto			dataTypeIdx	= static_cast<int>(dataType);
252 
253 	if (dataTypeIdx >= static_cast<int>(DataType::INT32) && dataTypeIdx <= static_cast<int>(DataType::FLOAT16))
254 	{
255 		// Note: A5 uses the same type as the scalar version. The array suffix will be added below.
256 		const TypeMap map =
257 		{
258 			std::make_pair(std::make_pair(DataType::INT32,		VectorType::SCALAR),	"int32_t"),
259 			std::make_pair(std::make_pair(DataType::INT32,		VectorType::V2),		"i32vec2"),
260 			std::make_pair(std::make_pair(DataType::INT32,		VectorType::V3),		"i32vec3"),
261 			std::make_pair(std::make_pair(DataType::INT32,		VectorType::V4),		"i32vec4"),
262 			std::make_pair(std::make_pair(DataType::INT32,		VectorType::A5),		"int32_t"),
263 			std::make_pair(std::make_pair(DataType::UINT32,		VectorType::SCALAR),	"uint32_t"),
264 			std::make_pair(std::make_pair(DataType::UINT32,		VectorType::V2),		"u32vec2"),
265 			std::make_pair(std::make_pair(DataType::UINT32,		VectorType::V3),		"u32vec3"),
266 			std::make_pair(std::make_pair(DataType::UINT32,		VectorType::V4),		"u32vec4"),
267 			std::make_pair(std::make_pair(DataType::UINT32,		VectorType::A5),		"uint32_t"),
268 			std::make_pair(std::make_pair(DataType::INT64,		VectorType::SCALAR),	"int64_t"),
269 			std::make_pair(std::make_pair(DataType::INT64,		VectorType::V2),		"i64vec2"),
270 			std::make_pair(std::make_pair(DataType::INT64,		VectorType::V3),		"i64vec3"),
271 			std::make_pair(std::make_pair(DataType::INT64,		VectorType::V4),		"i64vec4"),
272 			std::make_pair(std::make_pair(DataType::INT64,		VectorType::A5),		"int64_t"),
273 			std::make_pair(std::make_pair(DataType::UINT64,		VectorType::SCALAR),	"uint64_t"),
274 			std::make_pair(std::make_pair(DataType::UINT64,		VectorType::V2),		"u64vec2"),
275 			std::make_pair(std::make_pair(DataType::UINT64,		VectorType::V3),		"u64vec3"),
276 			std::make_pair(std::make_pair(DataType::UINT64,		VectorType::V4),		"u64vec4"),
277 			std::make_pair(std::make_pair(DataType::UINT64,		VectorType::A5),		"uint64_t"),
278 			std::make_pair(std::make_pair(DataType::INT16,		VectorType::SCALAR),	"int16_t"),
279 			std::make_pair(std::make_pair(DataType::INT16,		VectorType::V2),		"i16vec2"),
280 			std::make_pair(std::make_pair(DataType::INT16,		VectorType::V3),		"i16vec3"),
281 			std::make_pair(std::make_pair(DataType::INT16,		VectorType::V4),		"i16vec4"),
282 			std::make_pair(std::make_pair(DataType::INT16,		VectorType::A5),		"int16_t"),
283 			std::make_pair(std::make_pair(DataType::UINT16,		VectorType::SCALAR),	"uint16_t"),
284 			std::make_pair(std::make_pair(DataType::UINT16,		VectorType::V2),		"u16vec2"),
285 			std::make_pair(std::make_pair(DataType::UINT16,		VectorType::V3),		"u16vec3"),
286 			std::make_pair(std::make_pair(DataType::UINT16,		VectorType::V4),		"u16vec4"),
287 			std::make_pair(std::make_pair(DataType::UINT16,		VectorType::A5),		"uint16_t"),
288 			std::make_pair(std::make_pair(DataType::INT8,		VectorType::SCALAR),	"int8_t"),
289 			std::make_pair(std::make_pair(DataType::INT8,		VectorType::V2),		"i8vec2"),
290 			std::make_pair(std::make_pair(DataType::INT8,		VectorType::V3),		"i8vec3"),
291 			std::make_pair(std::make_pair(DataType::INT8,		VectorType::V4),		"i8vec4"),
292 			std::make_pair(std::make_pair(DataType::INT8,		VectorType::A5),		"int8_t"),
293 			std::make_pair(std::make_pair(DataType::UINT8,		VectorType::SCALAR),	"uint8_t"),
294 			std::make_pair(std::make_pair(DataType::UINT8,		VectorType::V2),		"u8vec2"),
295 			std::make_pair(std::make_pair(DataType::UINT8,		VectorType::V3),		"u8vec3"),
296 			std::make_pair(std::make_pair(DataType::UINT8,		VectorType::V4),		"u8vec4"),
297 			std::make_pair(std::make_pair(DataType::UINT8,		VectorType::A5),		"uint8_t"),
298 			std::make_pair(std::make_pair(DataType::FLOAT32,	VectorType::SCALAR),	"float32_t"),
299 			std::make_pair(std::make_pair(DataType::FLOAT32,	VectorType::V2),		"f32vec2"),
300 			std::make_pair(std::make_pair(DataType::FLOAT32,	VectorType::V3),		"f32vec3"),
301 			std::make_pair(std::make_pair(DataType::FLOAT32,	VectorType::V4),		"f32vec4"),
302 			std::make_pair(std::make_pair(DataType::FLOAT32,	VectorType::A5),		"float32_t"),
303 			std::make_pair(std::make_pair(DataType::FLOAT64,	VectorType::SCALAR),	"float64_t"),
304 			std::make_pair(std::make_pair(DataType::FLOAT64,	VectorType::V2),		"f64vec2"),
305 			std::make_pair(std::make_pair(DataType::FLOAT64,	VectorType::V3),		"f64vec3"),
306 			std::make_pair(std::make_pair(DataType::FLOAT64,	VectorType::V4),		"f64vec4"),
307 			std::make_pair(std::make_pair(DataType::FLOAT64,	VectorType::A5),		"float64_t"),
308 			std::make_pair(std::make_pair(DataType::FLOAT16,	VectorType::SCALAR),	"float16_t"),
309 			std::make_pair(std::make_pair(DataType::FLOAT16,	VectorType::V2),		"f16vec2"),
310 			std::make_pair(std::make_pair(DataType::FLOAT16,	VectorType::V3),		"f16vec3"),
311 			std::make_pair(std::make_pair(DataType::FLOAT16,	VectorType::V4),		"f16vec4"),
312 			std::make_pair(std::make_pair(DataType::FLOAT16,	VectorType::A5),		"float16_t"),
313 		};
314 
315 		const auto key		= std::make_pair(dataType, vectorType);
316 		const auto found	= map.find(key);
317 
318 		DE_ASSERT(found != end(map));
319 
320 		const auto baseType		= found->second;
321 		const std::string decl	= baseType + " " + varName + ((vectorType == VectorType::A5) ? "[5]" : "") + ";";
322 
323 		return std::make_pair(std::string(), decl);
324 	}
325 	else if (dataType == DataType::STRUCT)
326 	{
327 		return std::make_pair(std::string("struct InputStruct { uint val1; float val2; };\n"), std::string("InputStruct val;"));
328 	}
329 	else if (samplersNeeded(dataType))
330 	{
331 		return std::make_pair(std::string(), std::string("float val;"));
332 	}
333 	else if (storageImageNeeded(dataType))
334 	{
335 		return std::make_pair(std::string(), std::string("int val;"));
336 	}
337 	else if (dataType == DataType::OP_NULL || dataType == DataType::OP_UNDEF)
338 	{
339 		return std::make_pair(std::string(), std::string("uint val;"));
340 	}
341 
342 	// Unreachable.
343 	DE_ASSERT(false);
344 	return std::make_pair(std::string(), std::string());
345 }
346 
347 class DataSpillTestCase : public vkt::TestCase
348 {
349 public:
350 	struct TestParams
351 	{
352 		CallType	callType;
353 		DataType	dataType;
354 		VectorType	vectorType;
355 	};
356 
357 							DataSpillTestCase		(tcu::TestContext& testCtx, const std::string& name, const TestParams& testParams);
~DataSpillTestCase(void)358 	virtual					~DataSpillTestCase		(void) {}
359 
360 	virtual void			initPrograms			(vk::SourceCollections& programCollection) const;
361 	virtual TestInstance*	createInstance			(Context& context) const;
362 	virtual void			checkSupport			(Context& context) const;
363 
364 private:
365 	TestParams				m_params;
366 };
367 
368 class DataSpillTestInstance : public vkt::TestInstance
369 {
370 public:
371 	using TestParams = DataSpillTestCase::TestParams;
372 
373 								DataSpillTestInstance	(Context& context, const TestParams& testParams);
~DataSpillTestInstance(void)374 	virtual						~DataSpillTestInstance	(void) {}
375 
376 	virtual tcu::TestStatus		iterate					(void);
377 
378 private:
379 	TestParams					m_params;
380 };
381 
382 
DataSpillTestCase(tcu::TestContext& testCtx, const std::string& name, const TestParams& testParams)383 DataSpillTestCase::DataSpillTestCase (tcu::TestContext& testCtx, const std::string& name, const TestParams& testParams)
384 	: vkt::TestCase	(testCtx, name)
385 	, m_params		(testParams)
386 {
387 	switch (m_params.dataType)
388 	{
389 	case DataType::STRUCT:
390 	case DataType::IMAGE:
391 	case DataType::SAMPLER:
392 	case DataType::SAMPLED_IMAGE:
393 	case DataType::PTR_IMAGE:
394 	case DataType::PTR_SAMPLER:
395 	case DataType::PTR_SAMPLED_IMAGE:
396 	case DataType::PTR_TEXEL:
397 	case DataType::OP_NULL:
398 	case DataType::OP_UNDEF:
399 		DE_ASSERT(m_params.vectorType == VectorType::SCALAR);
400 		break;
401 	default:
402 		break;
403 	}
404 
405 	// The code assumes at most one of these is needed.
406 	DE_ASSERT(!(samplersNeeded(m_params.dataType) && storageImageNeeded(m_params.dataType)));
407 }
408 
createInstance(Context& context) const409 TestInstance* DataSpillTestCase::createInstance (Context& context) const
410 {
411 	return new DataSpillTestInstance(context, m_params);
412 }
413 
DataSpillTestInstance(Context& context, const TestParams& testParams)414 DataSpillTestInstance::DataSpillTestInstance (Context& context, const TestParams& testParams)
415 	: vkt::TestInstance	(context)
416 	, m_params			(testParams)
417 {
418 }
419 
420 // General checks for all tests.
commonCheckSupport(Context& context)421 void commonCheckSupport (Context& context)
422 {
423 	context.requireDeviceFunctionality("VK_KHR_acceleration_structure");
424 	context.requireDeviceFunctionality("VK_KHR_ray_tracing_pipeline");
425 
426 	const auto& rtFeatures = context.getRayTracingPipelineFeatures();
427 	if (!rtFeatures.rayTracingPipeline)
428 		TCU_THROW(NotSupportedError, "Ray Tracing pipelines not supported");
429 
430 	const auto& asFeatures = context.getAccelerationStructureFeatures();
431 	if (!asFeatures.accelerationStructure)
432 		TCU_FAIL("VK_KHR_acceleration_structure supported without accelerationStructure support");
433 
434 }
435 
checkSupport(Context& context) const436 void DataSpillTestCase::checkSupport (Context& context) const
437 {
438 	// General checks first.
439 	commonCheckSupport(context);
440 
441 	const auto& features			= context.getDeviceFeatures();
442 	const auto& featuresStorage16	= context.get16BitStorageFeatures();
443 	const auto& featuresF16I8		= context.getShaderFloat16Int8Features();
444 	const auto& featuresStorage8	= context.get8BitStorageFeatures();
445 
446 	if (m_params.dataType == DataType::INT64 || m_params.dataType == DataType::UINT64)
447 	{
448 		if (!features.shaderInt64)
449 			TCU_THROW(NotSupportedError, "64-bit integers not supported");
450 	}
451 	else if (m_params.dataType == DataType::INT16 || m_params.dataType == DataType::UINT16)
452 	{
453 		context.requireDeviceFunctionality("VK_KHR_16bit_storage");
454 
455 		if (!features.shaderInt16)
456 			TCU_THROW(NotSupportedError, "16-bit integers not supported");
457 
458 		if (!featuresStorage16.storageBuffer16BitAccess)
459 			TCU_THROW(NotSupportedError, "16-bit storage buffer access not supported");
460 	}
461 	else if (m_params.dataType == DataType::INT8 || m_params.dataType == DataType::UINT8)
462 	{
463 		context.requireDeviceFunctionality("VK_KHR_shader_float16_int8");
464 		context.requireDeviceFunctionality("VK_KHR_8bit_storage");
465 
466 		if (!featuresF16I8.shaderInt8)
467 			TCU_THROW(NotSupportedError, "8-bit integers not supported");
468 
469 		if (!featuresStorage8.storageBuffer8BitAccess)
470 			TCU_THROW(NotSupportedError, "8-bit storage buffer access not supported");
471 	}
472 	else if (m_params.dataType == DataType::FLOAT64)
473 	{
474 		if (!features.shaderFloat64)
475 			TCU_THROW(NotSupportedError, "64-bit floats not supported");
476 	}
477 	else if (m_params.dataType == DataType::FLOAT16)
478 	{
479 		context.requireDeviceFunctionality("VK_KHR_shader_float16_int8");
480 		context.requireDeviceFunctionality("VK_KHR_16bit_storage");
481 
482 		if (!featuresF16I8.shaderFloat16)
483 			TCU_THROW(NotSupportedError, "16-bit floats not supported");
484 
485 		if (!featuresStorage16.storageBuffer16BitAccess)
486 			TCU_THROW(NotSupportedError, "16-bit storage buffer access not supported");
487 	}
488 	else if (samplersNeeded(m_params.dataType))
489 	{
490 		context.requireDeviceFunctionality("VK_EXT_descriptor_indexing");
491 		const auto indexingFeatures = context.getDescriptorIndexingFeatures();
492 		if (!indexingFeatures.shaderSampledImageArrayNonUniformIndexing)
493 			TCU_THROW(NotSupportedError, "No support for non-uniform sampled image arrays");
494 	}
495 }
496 
initPrograms(vk::SourceCollections& programCollection) const497 void DataSpillTestCase::initPrograms (vk::SourceCollections& programCollection) const
498 {
499 	const vk::ShaderBuildOptions	buildOptions	(programCollection.usedVulkanVersion, vk::SPIRV_VERSION_1_4, 0u, true);
500 	const vk::SpirVAsmBuildOptions	spvBuildOptions	(programCollection.usedVulkanVersion, vk::SPIRV_VERSION_1_4, true);
501 
502 	std::ostringstream spvTemplateStream;
503 
504 	// This SPIR-V template will be used to generate shaders for different
505 	// stages (raygen, callable, etc). The basic mechanism uses 3 SSBOs: one
506 	// used strictly as an input, one to write the check result, and one to
507 	// verify the shader call has taken place. The latter two SSBOs contain just
508 	// a single uint, but the input SSBO typically contains other type of data
509 	// that will be filled from the test instance with predetermined values. The
510 	// shader will expect this data to have specific values that can be combined
511 	// some way to give an expected result (e.g. by adding the 4 components if
512 	// it's a vec4). This result will be used in the shader call to make sure
513 	// input values are read *before* the call. After the shader call has taken
514 	// place, the shader will attempt to read the input buffer again and verify
515 	// the value is still correct and matches the previous one. If the result
516 	// matches, it will write a confirmation value in the check buffer. In the
517 	// mean time, the callee will write a confirmation value in the callee
518 	// buffer to verify the shader call took place.
519 	//
520 	// Some test variants use samplers, images or sampled images. These need
521 	// additional bindings of different types and the interesting value is
522 	// typically placed in the image instead of the input buffer, while the
523 	// input buffer is used for sampling coordinates instead.
524 	//
525 	// Some important SPIR-V template variables:
526 	//
527 	// - INPUT_BUFFER_VALUE_TYPE will contain the type of input buffer data.
528 	// - CALC_ZERO_FOR_CALLABLE is expected to contain instructions that will
529 	//   calculate a value of zero to be used in the shader call instruction.
530 	//   This value should be derived from the input data.
531 	// - CALL_STATEMENTS will contain the shader call instructions.
532 	// - CALC_EQUAL_STATEMENT is expected to contain instructions that will
533 	//   set %equal to true as a %bool if the before- and after- data match.
534 	//
535 	// - %input_val_ptr contains the pointer to the input value.
536 	// - %input_val_before contains the value read before the call.
537 	// - %input_val_after contains the value read after the call.
538 
539 	spvTemplateStream
540 		<< "                                  OpCapability RayTracingKHR\n"
541 		<< "${EXTRA_CAPABILITIES}"
542 		<< "                                  OpExtension \"SPV_KHR_ray_tracing\"\n"
543 		<< "${EXTRA_EXTENSIONS}"
544 		<< "                                  OpMemoryModel Logical GLSL450\n"
545 		<< "                                  OpEntryPoint ${ENTRY_POINT} %main \"main\" %topLevelAS %calleeBuffer %outputBuffer %inputBuffer${MAIN_INTERFACE_EXTRAS}\n"
546 		<< "${INTERFACE_DECORATIONS}"
547 		<< "                                  OpMemberDecorate %InputBlock 0 Offset 0\n"
548 		<< "                                  OpDecorate %InputBlock Block\n"
549 		<< "                                  OpDecorate %inputBuffer DescriptorSet 0\n"
550 		<< "                                  OpDecorate %inputBuffer Binding 3\n"
551 		<< "                                  OpMemberDecorate %OutputBlock 0 Offset 0\n"
552 		<< "                                  OpDecorate %OutputBlock Block\n"
553 		<< "                                  OpDecorate %outputBuffer DescriptorSet 0\n"
554 		<< "                                  OpDecorate %outputBuffer Binding 2\n"
555 		<< "                                  OpMemberDecorate %CalleeBlock 0 Offset 0\n"
556 		<< "                                  OpDecorate %CalleeBlock Block\n"
557 		<< "                                  OpDecorate %calleeBuffer DescriptorSet 0\n"
558 		<< "                                  OpDecorate %calleeBuffer Binding 1\n"
559 		<< "                                  OpDecorate %topLevelAS DescriptorSet 0\n"
560 		<< "                                  OpDecorate %topLevelAS Binding 0\n"
561 		<< "${EXTRA_BINDINGS}"
562 		<< "                          %void = OpTypeVoid\n"
563 		<< "                     %void_func = OpTypeFunction %void\n"
564 		<< "                           %int = OpTypeInt 32 1\n"
565 		<< "                          %uint = OpTypeInt 32 0\n"
566 		<< "                         %int_0 = OpConstant %int 0\n"
567 		<< "                        %uint_0 = OpConstant %uint 0\n"
568 		<< "                        %uint_1 = OpConstant %uint 1\n"
569 		<< "                        %uint_2 = OpConstant %uint 2\n"
570 		<< "                        %uint_3 = OpConstant %uint 3\n"
571 		<< "                        %uint_4 = OpConstant %uint 4\n"
572 		<< "                        %uint_5 = OpConstant %uint 5\n"
573 		<< "                      %uint_255 = OpConstant %uint 255\n"
574 		<< "                          %bool = OpTypeBool\n"
575 		<< "                         %float = OpTypeFloat 32\n"
576 		<< "                       %float_0 = OpConstant %float 0\n"
577 		<< "                       %float_1 = OpConstant %float 1\n"
578 		<< "                       %float_9 = OpConstant %float 9\n"
579 		<< "                     %float_0_5 = OpConstant %float 0.5\n"
580 		<< "                      %float_n1 = OpConstant %float -1\n"
581 		<< "                       %v3float = OpTypeVector %float 3\n"
582 		<< "                  %origin_const = OpConstantComposite %v3float %float_0_5 %float_0_5 %float_0\n"
583 		<< "               %direction_const = OpConstantComposite %v3float %float_0 %float_0 %float_n1\n"
584 		<< "${EXTRA_TYPES_AND_CONSTANTS}"
585 		<< "                 %data_func_ptr = OpTypePointer Function ${INPUT_BUFFER_VALUE_TYPE}\n"
586 		<< "${INTERFACE_TYPES_AND_VARIABLES}"
587 		<< "                    %InputBlock = OpTypeStruct ${INPUT_BUFFER_VALUE_TYPE}\n"
588 		<< " %_ptr_StorageBuffer_InputBlock = OpTypePointer StorageBuffer %InputBlock\n"
589 		<< "                   %inputBuffer = OpVariable %_ptr_StorageBuffer_InputBlock StorageBuffer\n"
590 		<< "        %data_storagebuffer_ptr = OpTypePointer StorageBuffer ${INPUT_BUFFER_VALUE_TYPE}\n"
591 		<< "                   %OutputBlock = OpTypeStruct %uint\n"
592 		<< "%_ptr_StorageBuffer_OutputBlock = OpTypePointer StorageBuffer %OutputBlock\n"
593 		<< "                  %outputBuffer = OpVariable %_ptr_StorageBuffer_OutputBlock StorageBuffer\n"
594 		<< "       %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint\n"
595 		<< "                   %CalleeBlock = OpTypeStruct %uint\n"
596 		<< "%_ptr_StorageBuffer_CalleeBlock = OpTypePointer StorageBuffer %CalleeBlock\n"
597 		<< "                  %calleeBuffer = OpVariable %_ptr_StorageBuffer_CalleeBlock StorageBuffer\n"
598 		<< "                       %as_type = OpTypeAccelerationStructureKHR\n"
599 		<< "        %as_uniformconstant_ptr = OpTypePointer UniformConstant %as_type\n"
600 		<< "                    %topLevelAS = OpVariable %as_uniformconstant_ptr UniformConstant\n"
601 		<< "${EXTRA_BINDING_VARIABLES}"
602 		<< "                          %main = OpFunction %void None %void_func\n"
603 		<< "                    %main_label = OpLabel\n"
604 		<< "${EXTRA_FUNCTION_VARIABLES}"
605 		<< "                 %input_val_ptr = OpAccessChain %data_storagebuffer_ptr %inputBuffer %int_0\n"
606 		<< "                %output_val_ptr = OpAccessChain %_ptr_StorageBuffer_uint %outputBuffer %int_0\n"
607 		// Note we use Volatile to load the input buffer value before and after the call statements.
608 		<< "              %input_val_before = OpLoad ${INPUT_BUFFER_VALUE_TYPE} %input_val_ptr Volatile\n"
609 		<< "${CALC_ZERO_FOR_CALLABLE}"
610 		<< "${CALL_STATEMENTS}"
611 		<< "               %input_val_after = OpLoad ${INPUT_BUFFER_VALUE_TYPE} %input_val_ptr Volatile\n"
612 		<< "${CALC_EQUAL_STATEMENT}"
613 		<< "                    %output_val = OpSelect %uint %equal %uint_1 %uint_0\n"
614 		<< "                                  OpStore %output_val_ptr %output_val\n"
615 		<< "                                  OpReturn\n"
616 		<< "                                  OpFunctionEnd\n"
617 		;
618 
619 	const tcu::StringTemplate spvTemplate (spvTemplateStream.str());
620 
621 	std::map<std::string, std::string>	subs;
622 	std::string							componentTypeName;
623 	std::string							opEqual;
624 	const int							numComponents		= static_cast<int>(m_params.vectorType);
625 	const auto							isArray				= (numComponents > static_cast<int>(VectorType::V4));
626 	const auto							numComponentsStr	= de::toString(numComponents);
627 
628 	subs["EXTRA_CAPABILITIES"]			= "";
629 	subs["EXTRA_EXTENSIONS"]			= "";
630 	subs["EXTRA_TYPES_AND_CONSTANTS"]	= "";
631 	subs["EXTRA_FUNCTION_VARIABLES"]	= "";
632 	subs["EXTRA_BINDINGS"]				= "";
633 	subs["EXTRA_BINDING_VARIABLES"]		= "";
634 	subs["EXTRA_FUNCTIONS"]				= "";
635 
636 	// Take into account some of these substitutions will be updated after the if-block.
637 
638 	if (m_params.dataType == DataType::INT32)
639 	{
640 		componentTypeName = "int";
641 
642 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%int";
643 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"                        %int_37 = OpConstant %int 37\n";
644 		subs["CALC_ZERO_FOR_CALLABLE"]		=	"                      %zero_int = OpISub %int %input_val_before %int_37\n"
645 												"             %zero_for_callable = OpBitcast %uint %zero_int\n";
646 	}
647 	else if (m_params.dataType == DataType::UINT32)
648 	{
649 		componentTypeName = "uint";
650 
651 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%uint";
652 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"                       %uint_37 = OpConstant %uint 37\n";
653 		subs["CALC_ZERO_FOR_CALLABLE"]		=	"             %zero_for_callable = OpISub %uint %input_val_before %uint_37\n";
654 	}
655 	else if (m_params.dataType == DataType::INT64)
656 	{
657 		componentTypeName = "long";
658 
659 		subs["EXTRA_CAPABILITIES"]			+=	"                                  OpCapability Int64\n";
660 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%long";
661 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"                          %long = OpTypeInt 64 1\n"
662 												"                       %long_37 = OpConstant %long 37\n";
663 		subs["CALC_ZERO_FOR_CALLABLE"]		=	"                     %zero_long = OpISub %long %input_val_before %long_37\n"
664 												"             %zero_for_callable = OpSConvert %uint %zero_long\n";
665 	}
666 	else if (m_params.dataType == DataType::UINT64)
667 	{
668 		componentTypeName = "ulong";
669 
670 		subs["EXTRA_CAPABILITIES"]			+=	"                                  OpCapability Int64\n";
671 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%ulong";
672 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"                         %ulong = OpTypeInt 64 0\n"
673 												"                      %ulong_37 = OpConstant %ulong 37\n";
674 		subs["CALC_ZERO_FOR_CALLABLE"]		=	"                    %zero_ulong = OpISub %ulong %input_val_before %ulong_37\n"
675 												"             %zero_for_callable = OpUConvert %uint %zero_ulong\n";
676 	}
677 	else if (m_params.dataType == DataType::INT16)
678 	{
679 		componentTypeName = "short";
680 
681 		subs["EXTRA_CAPABILITIES"]			+=	"                                  OpCapability Int16\n"
682 												"                                  OpCapability StorageBuffer16BitAccess\n";
683 		subs["EXTRA_EXTENSIONS"]			+=	"                                  OpExtension \"SPV_KHR_16bit_storage\"\n";
684 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%short";
685 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"                         %short = OpTypeInt 16 1\n"
686 												"                      %short_37 = OpConstant %short 37\n";
687 		subs["CALC_ZERO_FOR_CALLABLE"]		=	"                    %zero_short = OpISub %short %input_val_before %short_37\n"
688 												"             %zero_for_callable = OpSConvert %uint %zero_short\n";
689 	}
690 	else if (m_params.dataType == DataType::UINT16)
691 	{
692 		componentTypeName = "ushort";
693 
694 		subs["EXTRA_CAPABILITIES"]			+=	"                                  OpCapability Int16\n"
695 												"                                  OpCapability StorageBuffer16BitAccess\n";
696 		subs["EXTRA_EXTENSIONS"]			+=	"                                  OpExtension \"SPV_KHR_16bit_storage\"\n";
697 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%ushort";
698 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"                        %ushort = OpTypeInt 16 0\n"
699 												"                     %ushort_37 = OpConstant %ushort 37\n";
700 		subs["CALC_ZERO_FOR_CALLABLE"]		=	"                   %zero_ushort = OpISub %ushort %input_val_before %ushort_37\n"
701 												"             %zero_for_callable = OpUConvert %uint %zero_ushort\n";
702 	}
703 	else if (m_params.dataType == DataType::INT8)
704 	{
705 		componentTypeName = "char";
706 
707 		subs["EXTRA_CAPABILITIES"]			+=	"                                  OpCapability Int8\n"
708 												"                                  OpCapability StorageBuffer8BitAccess\n";
709 		subs["EXTRA_EXTENSIONS"]			+=	"                                  OpExtension \"SPV_KHR_8bit_storage\"\n";
710 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%char";
711 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"                          %char = OpTypeInt 8 1\n"
712 												"                       %char_37 = OpConstant %char 37\n";
713 		subs["CALC_ZERO_FOR_CALLABLE"]		=	"                     %zero_char = OpISub %char %input_val_before %char_37\n"
714 												"             %zero_for_callable = OpSConvert %uint %zero_char\n";
715 	}
716 	else if (m_params.dataType == DataType::UINT8)
717 	{
718 		componentTypeName = "uchar";
719 
720 		subs["EXTRA_CAPABILITIES"]			+=	"                                  OpCapability Int8\n"
721 												"                                  OpCapability StorageBuffer8BitAccess\n";
722 		subs["EXTRA_EXTENSIONS"]			+=	"                                  OpExtension \"SPV_KHR_8bit_storage\"\n";
723 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%uchar";
724 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"                         %uchar = OpTypeInt 8 0\n"
725 												"                      %uchar_37 = OpConstant %uchar 37\n";
726 		subs["CALC_ZERO_FOR_CALLABLE"]		=	"                    %zero_uchar = OpISub %uchar %input_val_before %uchar_37\n"
727 												"             %zero_for_callable = OpUConvert %uint %zero_uchar\n";
728 	}
729 	else if (m_params.dataType == DataType::FLOAT32)
730 	{
731 		componentTypeName = "float";
732 
733 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%float";
734 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"                      %float_37 = OpConstant %float 37\n";
735 		subs["CALC_ZERO_FOR_CALLABLE"]		=	"                    %zero_float = OpFSub %float %input_val_before %float_37\n"
736 												"             %zero_for_callable = OpConvertFToU %uint %zero_float\n";
737 	}
738 	else if (m_params.dataType == DataType::FLOAT64)
739 	{
740 		componentTypeName = "double";
741 
742 		subs["EXTRA_CAPABILITIES"]			+=	"                                  OpCapability Float64\n";
743 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%double";
744 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"                        %double = OpTypeFloat 64\n"
745 												"                     %double_37 = OpConstant %double 37\n";
746 		subs["CALC_ZERO_FOR_CALLABLE"]		=	"                   %zero_double = OpFSub %double %input_val_before %double_37\n"
747 												"             %zero_for_callable = OpConvertFToU %uint %zero_double\n";
748 	}
749 	else if (m_params.dataType == DataType::FLOAT16)
750 	{
751 		componentTypeName = "half";
752 
753 		subs["EXTRA_CAPABILITIES"]			+=	"                                  OpCapability Float16\n"
754 												"                                  OpCapability StorageBuffer16BitAccess\n";
755 		subs["EXTRA_EXTENSIONS"]			+=	"                                  OpExtension \"SPV_KHR_16bit_storage\"\n";
756 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%half";
757 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"                          %half = OpTypeFloat 16\n"
758 												"                       %half_37 = OpConstant %half 37\n";
759 		subs["CALC_ZERO_FOR_CALLABLE"]		=	"                     %zero_half = OpFSub %half %input_val_before %half_37\n"
760 												"             %zero_for_callable = OpConvertFToU %uint %zero_half\n";
761 	}
762 	else if (m_params.dataType == DataType::STRUCT)
763 	{
764 		componentTypeName = "InputStruct";
765 
766 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%InputStruct";
767 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"                   %InputStruct = OpTypeStruct %uint %float\n"
768 												"                      %float_37 = OpConstant %float 37\n"
769 												"            %uint_part_ptr_type = OpTypePointer StorageBuffer %uint\n"
770 												"           %float_part_ptr_type = OpTypePointer StorageBuffer %float\n"
771 												"       %uint_part_func_ptr_type = OpTypePointer Function %uint\n"
772 												"      %float_part_func_ptr_type = OpTypePointer Function %float\n"
773 												"    %input_struct_func_ptr_type = OpTypePointer Function %InputStruct\n"
774 												;
775 		subs["INTERFACE_DECORATIONS"]		=	"                                  OpMemberDecorate %InputStruct 0 Offset 0\n"
776 												"                                  OpMemberDecorate %InputStruct 1 Offset 4\n";
777 
778 		// Sum struct members, then substract constant and convert to uint.
779 		subs["CALC_ZERO_FOR_CALLABLE"]		=	"                 %uint_part_ptr = OpAccessChain %uint_part_ptr_type %input_val_ptr %uint_0\n"
780 												"                %float_part_ptr = OpAccessChain %float_part_ptr_type %input_val_ptr %uint_1\n"
781 												"                     %uint_part = OpLoad %uint %uint_part_ptr\n"
782 												"                    %float_part = OpLoad %float %float_part_ptr\n"
783 												"                 %uint_as_float = OpConvertUToF %float %uint_part\n"
784 												"                    %member_sum = OpFAdd %float %float_part %uint_as_float\n"
785 												"                    %zero_float = OpFSub %float %member_sum %float_37\n"
786 												"             %zero_for_callable = OpConvertFToU %uint %zero_float\n"
787 												;
788 	}
789 	else if (samplersNeeded(m_params.dataType))
790 	{
791 		// These tests will use additional bindings as arrays of 2 elements:
792 		// - 1 array of samplers.
793 		// - 1 array of images.
794 		// - 1 array of combined image samplers.
795 		// Input values are typically used as texture coordinates (normally zeros)
796 		// Pixels will contain the expected values instead of them being in the input buffer.
797 
798 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%float";
799 		subs["EXTRA_CAPABILITIES"]			+=	"                                  OpCapability SampledImageArrayNonUniformIndexing\n";
800 		subs["EXTRA_EXTENSIONS"]			+=	"                                  OpExtension \"SPV_EXT_descriptor_indexing\"\n";
801 		subs["MAIN_INTERFACE_EXTRAS"]		+=	" %sampledTexture %textureSampler %combinedImageSampler";
802 		subs["EXTRA_BINDINGS"]				+=	"                                  OpDecorate %sampledTexture DescriptorSet 0\n"
803 												"                                  OpDecorate %sampledTexture Binding 4\n"
804 												"                                  OpDecorate %textureSampler DescriptorSet 0\n"
805 												"                                  OpDecorate %textureSampler Binding 5\n"
806 												"                                  OpDecorate %combinedImageSampler DescriptorSet 0\n"
807 												"                                  OpDecorate %combinedImageSampler Binding 6\n";
808 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"                       %uint_37 = OpConstant %uint 37\n"
809 												"                        %v4uint = OpTypeVector %uint 4\n"
810 												"                       %v2float = OpTypeVector %float 2\n"
811 												"                    %image_type = OpTypeImage %uint 2D 0 0 0 1 Unknown\n"
812 												"              %image_array_type = OpTypeArray %image_type %uint_2\n"
813 												"  %image_array_type_uniform_ptr = OpTypePointer UniformConstant %image_array_type\n"
814 												"        %image_type_uniform_ptr = OpTypePointer UniformConstant %image_type\n"
815 												"                  %sampler_type = OpTypeSampler\n"
816 												"            %sampler_array_type = OpTypeArray %sampler_type %uint_2\n"
817 												"%sampler_array_type_uniform_ptr = OpTypePointer UniformConstant %sampler_array_type\n"
818 												"      %sampler_type_uniform_ptr = OpTypePointer UniformConstant %sampler_type\n"
819 												"            %sampled_image_type = OpTypeSampledImage %image_type\n"
820 												"      %sampled_image_array_type = OpTypeArray %sampled_image_type %uint_2\n"
821 												"%sampled_image_array_type_uniform_ptr = OpTypePointer UniformConstant %sampled_image_array_type\n"
822 												"%sampled_image_type_uniform_ptr = OpTypePointer UniformConstant %sampled_image_type\n"
823 												;
824 		subs["EXTRA_BINDING_VARIABLES"]		+=	"                %sampledTexture = OpVariable %image_array_type_uniform_ptr UniformConstant\n"
825 												"                %textureSampler = OpVariable %sampler_array_type_uniform_ptr UniformConstant\n"
826 												"          %combinedImageSampler = OpVariable %sampled_image_array_type_uniform_ptr UniformConstant\n"
827 												;
828 
829 		if (m_params.dataType == DataType::IMAGE || m_params.dataType == DataType::SAMPLER)
830 		{
831 			// Use the first sampler and sample from the first image.
832 			subs["CALC_ZERO_FOR_CALLABLE"]	+=	"%image_0_ptr = OpAccessChain %image_type_uniform_ptr %sampledTexture %uint_0\n"
833 												"%sampler_0_ptr = OpAccessChain %sampler_type_uniform_ptr %textureSampler %uint_0\n"
834 												"%sampler_0 = OpLoad %sampler_type %sampler_0_ptr\n"
835 												"%image_0 = OpLoad %image_type %image_0_ptr\n"
836 												"%sampled_image_0 = OpSampledImage %sampled_image_type %image_0 %sampler_0\n"
837 												"%texture_coords_0 = OpCompositeConstruct %v2float %input_val_before %input_val_before\n"
838 												"%pixel_vec_0 = OpImageSampleExplicitLod %v4uint %sampled_image_0 %texture_coords_0 Lod|ZeroExtend %float_0\n"
839 												"%pixel_0 = OpCompositeExtract %uint %pixel_vec_0 0\n"
840 												"%zero_for_callable = OpISub %uint %pixel_0 %uint_37\n"
841 												;
842 		}
843 		else if (m_params.dataType == DataType::SAMPLED_IMAGE)
844 		{
845 			// Use the first combined image sampler.
846 			subs["CALC_ZERO_FOR_CALLABLE"]	+=	"%sampled_image_0_ptr = OpAccessChain %sampled_image_type_uniform_ptr %combinedImageSampler %uint_0\n"
847 												"%sampled_image_0 = OpLoad %sampled_image_type %sampled_image_0_ptr\n"
848 												"%texture_coords_0 = OpCompositeConstruct %v2float %input_val_before %input_val_before\n"
849 												"%pixel_vec_0 = OpImageSampleExplicitLod %v4uint %sampled_image_0 %texture_coords_0 Lod|ZeroExtend %float_0\n"
850 												"%pixel_0 = OpCompositeExtract %uint %pixel_vec_0 0\n"
851 												"%zero_for_callable = OpISub %uint %pixel_0 %uint_37\n"
852 												;
853 		}
854 		else if (m_params.dataType == DataType::PTR_IMAGE)
855 		{
856 			// We attempt to create the second pointer before the call.
857 			subs["CALC_ZERO_FOR_CALLABLE"]		+=	"%image_0_ptr = OpAccessChain %image_type_uniform_ptr %sampledTexture %uint_0\n"
858 													"%image_1_ptr = OpAccessChain %image_type_uniform_ptr %sampledTexture %uint_1\n"
859 													"%image_0 = OpLoad %image_type %image_0_ptr\n"
860 													"%sampler_0_ptr = OpAccessChain %sampler_type_uniform_ptr %textureSampler %uint_0\n"
861 													"%sampler_0 = OpLoad %sampler_type %sampler_0_ptr\n"
862 													"%sampled_image_0 = OpSampledImage %sampled_image_type %image_0 %sampler_0\n"
863 													"%texture_coords_0 = OpCompositeConstruct %v2float %input_val_before %input_val_before\n"
864 													"%pixel_vec_0 = OpImageSampleExplicitLod %v4uint %sampled_image_0 %texture_coords_0 Lod|ZeroExtend %float_0\n"
865 													"%pixel_0 = OpCompositeExtract %uint %pixel_vec_0 0\n"
866 													"%zero_for_callable = OpISub %uint %pixel_0 %uint_37\n"
867 													;
868 		}
869 		else if (m_params.dataType == DataType::PTR_SAMPLER)
870 		{
871 			// We attempt to create the second pointer before the call.
872 			subs["CALC_ZERO_FOR_CALLABLE"]		+=	"%sampler_0_ptr = OpAccessChain %sampler_type_uniform_ptr %textureSampler %uint_0\n"
873 													"%sampler_1_ptr = OpAccessChain %sampler_type_uniform_ptr %textureSampler %uint_1\n"
874 													"%sampler_0 = OpLoad %sampler_type %sampler_0_ptr\n"
875 													"%image_0_ptr = OpAccessChain %image_type_uniform_ptr %sampledTexture %uint_0\n"
876 													"%image_0 = OpLoad %image_type %image_0_ptr\n"
877 													"%sampled_image_0 = OpSampledImage %sampled_image_type %image_0 %sampler_0\n"
878 													"%texture_coords_0 = OpCompositeConstruct %v2float %input_val_before %input_val_before\n"
879 													"%pixel_vec_0 = OpImageSampleExplicitLod %v4uint %sampled_image_0 %texture_coords_0 Lod|ZeroExtend %float_0\n"
880 													"%pixel_0 = OpCompositeExtract %uint %pixel_vec_0 0\n"
881 													"%zero_for_callable = OpISub %uint %pixel_0 %uint_37\n"
882 													;
883 		}
884 		else if (m_params.dataType == DataType::PTR_SAMPLED_IMAGE)
885 		{
886 			// We attempt to create the second pointer before the call.
887 			subs["CALC_ZERO_FOR_CALLABLE"]		+=	"%sampled_image_0_ptr = OpAccessChain %sampled_image_type_uniform_ptr %combinedImageSampler %uint_0\n"
888 													"%sampled_image_1_ptr = OpAccessChain %sampled_image_type_uniform_ptr %combinedImageSampler %uint_1\n"
889 													"%sampled_image_0 = OpLoad %sampled_image_type %sampled_image_0_ptr\n"
890 													"%texture_coords_0 = OpCompositeConstruct %v2float %input_val_before %input_val_before\n"
891 													"%pixel_vec_0 = OpImageSampleExplicitLod %v4uint %sampled_image_0 %texture_coords_0 Lod|ZeroExtend %float_0\n"
892 													"%pixel_0 = OpCompositeExtract %uint %pixel_vec_0 0\n"
893 													"%zero_for_callable = OpISub %uint %pixel_0 %uint_37\n"
894 													;
895 		}
896 		else
897 		{
898 			DE_ASSERT(false);
899 		}
900 	}
901 	else if (storageImageNeeded(m_params.dataType))
902 	{
903 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%int";
904 		subs["MAIN_INTERFACE_EXTRAS"]		+=	" %storageImage";
905 		subs["EXTRA_BINDINGS"]				+=	"                                  OpDecorate %storageImage DescriptorSet 0\n"
906 												"                                  OpDecorate %storageImage Binding 4\n"
907 												;
908 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"                       %uint_37 = OpConstant %uint 37\n"
909 												"                         %v2int = OpTypeVector %int 2\n"
910 												"                    %image_type = OpTypeImage %uint 2D 0 0 0 2 R32ui\n"
911 												"        %image_type_uniform_ptr = OpTypePointer UniformConstant %image_type\n"
912 												"                  %uint_img_ptr = OpTypePointer Image %uint\n"
913 												;
914 		subs["EXTRA_BINDING_VARIABLES"]		+=	"                  %storageImage = OpVariable %image_type_uniform_ptr UniformConstant\n"
915 												;
916 
917 		// Load value from the image, expecting it to be 37 and swapping it with 5.
918 		subs["CALC_ZERO_FOR_CALLABLE"]	+=	"%coords = OpCompositeConstruct %v2int %input_val_before %input_val_before\n"
919 											"%texel_ptr = OpImageTexelPointer %uint_img_ptr %storageImage %coords %uint_0\n"
920 											"%texel_value = OpAtomicCompareExchange %uint %texel_ptr %uint_1 %uint_0 %uint_0 %uint_5 %uint_37\n"
921 											"%zero_for_callable = OpISub %uint %texel_value %uint_37\n"
922 											;
923 	}
924 	else if (m_params.dataType == DataType::OP_NULL)
925 	{
926 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%uint";
927 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"                       %uint_37 = OpConstant %uint 37\n"
928 												"                 %constant_null = OpConstantNull %uint\n"
929 												;
930 
931 		// Create a local copy of the null constant global object to work with it.
932 		subs["CALC_ZERO_FOR_CALLABLE"]	+=	"%constant_null_copy = OpCopyObject %uint %constant_null\n"
933 											"%is_37_before = OpIEqual %bool %input_val_before %uint_37\n"
934 											"%zero_for_callable = OpSelect %uint %is_37_before %constant_null_copy %uint_5\n"
935 											;
936 	}
937 	else if (m_params.dataType == DataType::OP_UNDEF)
938 	{
939 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%uint";
940 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"                       %uint_37 = OpConstant %uint 37\n"
941 												;
942 
943 		// Extract an undef value and write it to the output buffer to make sure it's used before the call. The value will be overwritten later.
944 		subs["CALC_ZERO_FOR_CALLABLE"]	+=	"%undef_var = OpUndef %uint\n"
945 											"%undef_val_before = OpCopyObject %uint %undef_var\n"
946 											"OpStore %output_val_ptr %undef_val_before Volatile\n"
947 											"%zero_for_callable = OpISub %uint %uint_37 %input_val_before\n"
948 											;
949 	}
950 	else
951 	{
952 		DE_ASSERT(false);
953 	}
954 
955 	// Comparison statement for data before and after the call.
956 	switch (m_params.dataType)
957 	{
958 	case DataType::INT32:
959 	case DataType::UINT32:
960 	case DataType::INT64:
961 	case DataType::UINT64:
962 	case DataType::INT16:
963 	case DataType::UINT16:
964 	case DataType::INT8:
965 	case DataType::UINT8:
966 		opEqual = "OpIEqual";
967 		break;
968 	case DataType::FLOAT32:
969 	case DataType::FLOAT64:
970 	case DataType::FLOAT16:
971 		opEqual = "OpFOrdEqual";
972 		break;
973 	case DataType::STRUCT:
974 	case DataType::IMAGE:
975 	case DataType::SAMPLER:
976 	case DataType::SAMPLED_IMAGE:
977 	case DataType::PTR_IMAGE:
978 	case DataType::PTR_SAMPLER:
979 	case DataType::PTR_SAMPLED_IMAGE:
980 	case DataType::PTR_TEXEL:
981 	case DataType::OP_NULL:
982 	case DataType::OP_UNDEF:
983 		// These needs special code for the comparison.
984 		opEqual = "INVALID";
985 		break;
986 	default:
987 		DE_ASSERT(false);
988 		break;
989 	}
990 
991 	if (m_params.dataType == DataType::STRUCT)
992 	{
993 		// We need to store the before and after values in a variable in order to be able to access each member individually without accessing the StorageBuffer again.
994 		subs["EXTRA_FUNCTION_VARIABLES"]	=	"         %input_val_func_before = OpVariable %input_struct_func_ptr_type Function\n"
995 												"          %input_val_func_after = OpVariable %input_struct_func_ptr_type Function\n"
996 												;
997 		subs["CALC_EQUAL_STATEMENT"]		=	"                                  OpStore %input_val_func_before %input_val_before\n"
998 												"                                  OpStore %input_val_func_after %input_val_after\n"
999 												"     %uint_part_func_before_ptr = OpAccessChain %uint_part_func_ptr_type %input_val_func_before %uint_0\n"
1000 												"    %float_part_func_before_ptr = OpAccessChain %float_part_func_ptr_type %input_val_func_before %uint_1\n"
1001 												"      %uint_part_func_after_ptr = OpAccessChain %uint_part_func_ptr_type %input_val_func_after %uint_0\n"
1002 												"     %float_part_func_after_ptr = OpAccessChain %float_part_func_ptr_type %input_val_func_after %uint_1\n"
1003 												"              %uint_part_before = OpLoad %uint %uint_part_func_before_ptr\n"
1004 												"             %float_part_before = OpLoad %float %float_part_func_before_ptr\n"
1005 												"               %uint_part_after = OpLoad %uint %uint_part_func_after_ptr\n"
1006 												"              %float_part_after = OpLoad %float %float_part_func_after_ptr\n"
1007 												"                    %uint_equal = OpIEqual %bool %uint_part_before %uint_part_after\n"
1008 												"                   %float_equal = OpFOrdEqual %bool %float_part_before %float_part_after\n"
1009 												"                         %equal = OpLogicalAnd %bool %uint_equal %float_equal\n"
1010 												;
1011 	}
1012 	else if (m_params.dataType == DataType::IMAGE)
1013 	{
1014 		// Use the same image and the second sampler with different coordinates (actually the same).
1015 		subs["CALC_EQUAL_STATEMENT"]	+=	"%sampler_1_ptr = OpAccessChain %sampler_type_uniform_ptr %textureSampler %uint_1\n"
1016 											"%sampler_1 = OpLoad %sampler_type %sampler_1_ptr\n"
1017 											"%sampled_image_1 = OpSampledImage %sampled_image_type %image_0 %sampler_1\n"
1018 											"%texture_coords_1 = OpCompositeConstruct %v2float %input_val_after %input_val_after\n"
1019 											"%pixel_vec_1 = OpImageSampleExplicitLod %v4uint %sampled_image_1 %texture_coords_1 Lod|ZeroExtend %float_0\n"
1020 											"%pixel_1 = OpCompositeExtract %uint %pixel_vec_1 0\n"
1021 											"%equal = OpIEqual %bool %pixel_0 %pixel_1\n"
1022 											;
1023 	}
1024 	else if (m_params.dataType == DataType::SAMPLER)
1025 	{
1026 		// Use the same sampler and sample from the second image with different coordinates (but actually the same).
1027 		subs["CALC_EQUAL_STATEMENT"]	+=	"%image_1_ptr = OpAccessChain %image_type_uniform_ptr %sampledTexture %uint_1\n"
1028 											"%image_1 = OpLoad %image_type %image_1_ptr\n"
1029 											"%sampled_image_1 = OpSampledImage %sampled_image_type %image_1 %sampler_0\n"
1030 											"%texture_coords_1 = OpCompositeConstruct %v2float %input_val_after %input_val_after\n"
1031 											"%pixel_vec_1 = OpImageSampleExplicitLod %v4uint %sampled_image_1 %texture_coords_1 Lod|ZeroExtend %float_0\n"
1032 											"%pixel_1 = OpCompositeExtract %uint %pixel_vec_1 0\n"
1033 											"%equal = OpIEqual %bool %pixel_0 %pixel_1\n"
1034 											;
1035 	}
1036 	else if (m_params.dataType == DataType::SAMPLED_IMAGE)
1037 	{
1038 		// Reuse the same combined image sampler with different coordinates (actually the same).
1039 		subs["CALC_EQUAL_STATEMENT"]	+=	"%texture_coords_1 = OpCompositeConstruct %v2float %input_val_after %input_val_after\n"
1040 											"%pixel_vec_1 = OpImageSampleExplicitLod %v4uint %sampled_image_0 %texture_coords_1 Lod|ZeroExtend %float_0\n"
1041 											"%pixel_1 = OpCompositeExtract %uint %pixel_vec_1 0\n"
1042 											"%equal = OpIEqual %bool %pixel_0 %pixel_1\n"
1043 											;
1044 	}
1045 	else if (m_params.dataType == DataType::PTR_IMAGE)
1046 	{
1047 		// We attempt to use the second pointer only after the call.
1048 		subs["CALC_EQUAL_STATEMENT"]	+=	"%image_1 = OpLoad %image_type %image_1_ptr\n"
1049 											"%sampled_image_1 = OpSampledImage %sampled_image_type %image_1 %sampler_0\n"
1050 											"%texture_coords_1 = OpCompositeConstruct %v2float %input_val_after %input_val_after\n"
1051 											"%pixel_vec_1 = OpImageSampleExplicitLod %v4uint %sampled_image_1 %texture_coords_1 Lod|ZeroExtend %float_0\n"
1052 											"%pixel_1 = OpCompositeExtract %uint %pixel_vec_1 0\n"
1053 											"%equal = OpIEqual %bool %pixel_0 %pixel_1\n"
1054 											;
1055 
1056 	}
1057 	else if (m_params.dataType == DataType::PTR_SAMPLER)
1058 	{
1059 		// We attempt to use the second pointer only after the call.
1060 		subs["CALC_EQUAL_STATEMENT"]	+=	"%sampler_1 = OpLoad %sampler_type %sampler_1_ptr\n"
1061 											"%sampled_image_1 = OpSampledImage %sampled_image_type %image_0 %sampler_1\n"
1062 											"%texture_coords_1 = OpCompositeConstruct %v2float %input_val_after %input_val_after\n"
1063 											"%pixel_vec_1 = OpImageSampleExplicitLod %v4uint %sampled_image_1 %texture_coords_1 Lod|ZeroExtend %float_0\n"
1064 											"%pixel_1 = OpCompositeExtract %uint %pixel_vec_1 0\n"
1065 											"%equal = OpIEqual %bool %pixel_0 %pixel_1\n"
1066 											;
1067 	}
1068 	else if (m_params.dataType == DataType::PTR_SAMPLED_IMAGE)
1069 	{
1070 		// We attempt to use the second pointer only after the call.
1071 		subs["CALC_EQUAL_STATEMENT"]	+=	"%sampled_image_1 = OpLoad %sampled_image_type %sampled_image_1_ptr\n"
1072 											"%texture_coords_1 = OpCompositeConstruct %v2float %input_val_after %input_val_after\n"
1073 											"%pixel_vec_1 = OpImageSampleExplicitLod %v4uint %sampled_image_1 %texture_coords_1 Lod|ZeroExtend %float_0\n"
1074 											"%pixel_1 = OpCompositeExtract %uint %pixel_vec_1 0\n"
1075 											"%equal = OpIEqual %bool %pixel_0 %pixel_1\n"
1076 											;
1077 	}
1078 	else if (m_params.dataType == DataType::PTR_TEXEL)
1079 	{
1080 		// Check value 5 was stored properly.
1081 		subs["CALC_EQUAL_STATEMENT"]	+=	"%stored_val = OpAtomicLoad %uint %texel_ptr %uint_1 %uint_0\n"
1082 											"%equal = OpIEqual %bool %stored_val %uint_5\n"
1083 											;
1084 	}
1085 	else if (m_params.dataType == DataType::OP_NULL)
1086 	{
1087 		// Reuse the null constant after the call.
1088 		subs["CALC_EQUAL_STATEMENT"]	+=	"%is_37_after = OpIEqual %bool %input_val_after %uint_37\n"
1089 											"%writeback_val = OpSelect %uint %is_37_after %constant_null_copy %uint_5\n"
1090 											"OpStore %input_val_ptr %writeback_val Volatile\n"
1091 											"%readback_val = OpLoad %uint %input_val_ptr Volatile\n"
1092 											"%equal = OpIEqual %bool %readback_val %uint_0\n"
1093 											;
1094 	}
1095 	else if (m_params.dataType == DataType::OP_UNDEF)
1096 	{
1097 		// Extract another undef value and write it to the input buffer. It will not be checked later.
1098 		subs["CALC_EQUAL_STATEMENT"]	+=	"%undef_val_after = OpCopyObject %uint %undef_var\n"
1099 											"OpStore %input_val_ptr %undef_val_after Volatile\n"
1100 											"%equal = OpIEqual %bool %input_val_after %input_val_before\n"
1101 											;
1102 	}
1103 	else
1104 	{
1105 		subs["CALC_EQUAL_STATEMENT"]	+=	"                         %equal = " + opEqual + " %bool %input_val_before %input_val_after\n";
1106 	}
1107 
1108 	// Modifications for vectors and arrays.
1109 	if (numComponents > 1)
1110 	{
1111 		const std::string	vectorTypeName		= "v" + numComponentsStr + componentTypeName;
1112 		const std::string	opType				= (isArray ? "OpTypeArray" : "OpTypeVector");
1113 		const std::string	componentCountStr	= (isArray ? ("%uint_" + numComponentsStr) : numComponentsStr);
1114 
1115 		// Some extra types are needed.
1116 		if (!(m_params.dataType == DataType::FLOAT32 && m_params.vectorType == VectorType::V3))
1117 		{
1118 			// Note: v3float is already defined in the shader by default.
1119 			subs["EXTRA_TYPES_AND_CONSTANTS"] += "%" + vectorTypeName + " = " + opType + " %" + componentTypeName + " " + componentCountStr + "\n";
1120 		}
1121 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"%v" + numComponentsStr + "bool = " + opType + " %bool " + componentCountStr + "\n";
1122 		subs["EXTRA_TYPES_AND_CONSTANTS"]	+=	"%comp_ptr = OpTypePointer StorageBuffer %" + componentTypeName + "\n";
1123 
1124 		// The input value in the buffer has a different type.
1125 		subs["INPUT_BUFFER_VALUE_TYPE"]		=	"%" + vectorTypeName;
1126 
1127 		// Overwrite the way we calculate the zero used in the call.
1128 
1129 		// Proper operations for adding, substracting and converting components.
1130 		std::string opAdd;
1131 		std::string opSub;
1132 		std::string opConvert;
1133 
1134 		switch (m_params.dataType)
1135 		{
1136 		case DataType::INT32:
1137 		case DataType::UINT32:
1138 		case DataType::INT64:
1139 		case DataType::UINT64:
1140 		case DataType::INT16:
1141 		case DataType::UINT16:
1142 		case DataType::INT8:
1143 		case DataType::UINT8:
1144 			opAdd = "OpIAdd";
1145 			opSub = "OpISub";
1146 			break;
1147 		case DataType::FLOAT32:
1148 		case DataType::FLOAT64:
1149 		case DataType::FLOAT16:
1150 			opAdd = "OpFAdd";
1151 			opSub = "OpFSub";
1152 			break;
1153 		default:
1154 			DE_ASSERT(false);
1155 			break;
1156 		}
1157 
1158 		switch (m_params.dataType)
1159 		{
1160 		case DataType::UINT32:
1161 			opConvert = "OpCopyObject";
1162 			break;
1163 		case DataType::INT32:
1164 			opConvert = "OpBitcast";
1165 			break;
1166 		case DataType::INT64:
1167 		case DataType::INT16:
1168 		case DataType::INT8:
1169 			opConvert = "OpSConvert";
1170 			break;
1171 		case DataType::UINT64:
1172 		case DataType::UINT16:
1173 		case DataType::UINT8:
1174 			opConvert = "OpUConvert";
1175 			break;
1176 		case DataType::FLOAT32:
1177 		case DataType::FLOAT64:
1178 		case DataType::FLOAT16:
1179 			opConvert = "OpConvertFToU";
1180 			break;
1181 		default:
1182 			DE_ASSERT(false);
1183 			break;
1184 		}
1185 
1186 		std::ostringstream zeroForCallable;
1187 
1188 		// Create pointers to components and load components.
1189 		for (int i = 0; i < numComponents; ++i)
1190 		{
1191 			zeroForCallable
1192 				<< "%component_ptr_" << i << " = OpAccessChain %comp_ptr %input_val_ptr %uint_" << i << "\n"
1193 				<< "%component_" << i << " = OpLoad %" << componentTypeName << " %component_ptr_" << i << "\n"
1194 				;
1195 		}
1196 
1197 		// Sum components together in %total_sum.
1198 		for (int i = 1; i < numComponents; ++i)
1199 		{
1200 			const std::string previous		= ((i == 1) ? "%component_0" : ("%partial_" + de::toString(i-1)));
1201 			const std::string resultName	= ((i == (numComponents - 1)) ? "%total_sum" : ("%partial_" + de::toString(i)));
1202 			zeroForCallable << resultName << " = " << opAdd << " %" << componentTypeName << " %component_" << i << " " << previous << "\n";
1203 		}
1204 
1205 		// Recalculate the zero.
1206 		zeroForCallable
1207 			<< "%zero_" << componentTypeName << " = " << opSub << " %" << componentTypeName << " %total_sum %" << componentTypeName << "_37\n"
1208 			<< "%zero_for_callable = " << opConvert << " %uint %zero_" << componentTypeName << "\n"
1209 			;
1210 
1211 		// Finally replace the zero_for_callable statements with the special version for vectors.
1212 		subs["CALC_ZERO_FOR_CALLABLE"] = zeroForCallable.str();
1213 
1214 		// Rework comparison statements.
1215 		if (isArray)
1216 		{
1217 			// Arrays need to be compared per-component.
1218 			std::ostringstream calcEqual;
1219 
1220 			for (int i = 0; i < numComponents; ++i)
1221 			{
1222 				calcEqual
1223 					<< "%component_after_" << i << " = OpLoad %" << componentTypeName << " %component_ptr_" << i << "\n"
1224 					<< "%equal_" << i << " = " << opEqual << " %bool %component_" << i << " %component_after_" << i << "\n";
1225 				if (i > 0)
1226 					calcEqual << "%and_" << i << " = OpLogicalAnd %bool %equal_" << (i - 1) << " %equal_" << i << "\n";
1227 				if (i == numComponents - 1)
1228 					calcEqual << "%equal = OpCopyObject %bool %and_" << i << "\n";
1229 			}
1230 
1231 			subs["CALC_EQUAL_STATEMENT"] = calcEqual.str();
1232 		}
1233 		else
1234 		{
1235 			// Vectors can be compared using a bool vector and OpAll.
1236 			subs["CALC_EQUAL_STATEMENT"] =	"                  %equal_vector = " + opEqual + " %v" + numComponentsStr + "bool %input_val_before %input_val_after\n";
1237 			subs["CALC_EQUAL_STATEMENT"] +=	"                         %equal = OpAll %bool %equal_vector\n";
1238 		}
1239 	}
1240 
1241 	if (isArray)
1242 	{
1243 		// Arrays need an ArrayStride decoration.
1244 		std::ostringstream interfaceDecorations;
1245 		interfaceDecorations << "OpDecorate %v" << numComponentsStr << componentTypeName << " ArrayStride " << getElementSize(m_params.dataType, VectorType::SCALAR) << "\n";
1246 		subs["INTERFACE_DECORATIONS"] = interfaceDecorations.str();
1247 	}
1248 
1249 	const auto inputBlockDecls = getGLSLInputValDecl(m_params.dataType, m_params.vectorType);
1250 
1251 	std::ostringstream glslBindings;
1252 	glslBindings
1253 		<< inputBlockDecls.first // Additional data types needed.
1254 		<< "layout(set = 0, binding = 0) uniform accelerationStructureEXT topLevelAS;\n"
1255 		<< "layout(set = 0, binding = 1) buffer CalleeBlock { uint val; } calleeBuffer;\n"
1256 		<< "layout(set = 0, binding = 2) buffer OutputBlock { uint val; } outputBuffer;\n"
1257 		<< "layout(set = 0, binding = 3) buffer InputBlock { " << inputBlockDecls.second << " } inputBuffer;\n"
1258 		;
1259 
1260 	if (samplersNeeded(m_params.dataType))
1261 	{
1262 		glslBindings
1263 			<< "layout(set = 0, binding = 4) uniform utexture2D sampledTexture[2];\n"
1264 			<< "layout(set = 0, binding = 5) uniform sampler textureSampler[2];\n"
1265 			<< "layout(set = 0, binding = 6) uniform usampler2D combinedImageSampler[2];\n"
1266 			;
1267 	}
1268 	else if (storageImageNeeded(m_params.dataType))
1269 	{
1270 		glslBindings
1271 			<< "layout(set = 0, binding = 4, r32ui) uniform uimage2D storageImage;\n"
1272 			;
1273 	}
1274 
1275 	const auto glslBindingsStr	=	glslBindings.str();
1276 	const auto glslHeaderStr	=	"#version 460 core\n"
1277 									"#extension GL_EXT_ray_tracing : require\n"
1278 									"#extension GL_EXT_shader_explicit_arithmetic_types : require\n";
1279 
1280 
1281 	if (m_params.callType == CallType::TRACE_RAY)
1282 	{
1283 		subs["ENTRY_POINT"]						=	"RayGenerationKHR";
1284 		subs["MAIN_INTERFACE_EXTRAS"]			+=	" %hitValue";
1285 		subs["INTERFACE_DECORATIONS"]			+=	"                                  OpDecorate %hitValue Location 0\n";
1286 		subs["INTERFACE_TYPES_AND_VARIABLES"]	=	"                   %payload_ptr = OpTypePointer RayPayloadKHR %v3float\n"
1287 													"                      %hitValue = OpVariable %payload_ptr RayPayloadKHR\n";
1288 		subs["CALL_STATEMENTS"]					=	"                      %as_value = OpLoad %as_type %topLevelAS\n"
1289 													"                                  OpTraceRayKHR %as_value %uint_0 %uint_255 %zero_for_callable %zero_for_callable %zero_for_callable %origin_const %float_0 %direction_const %float_9 %hitValue\n";
1290 
1291 		const auto rgen = spvTemplate.specialize(subs);
1292 		programCollection.spirvAsmSources.add("rgen") << rgen << spvBuildOptions;
1293 
1294 		std::stringstream chit;
1295 		chit
1296 			<< glslHeaderStr
1297 			<< "layout(location = 0) rayPayloadInEXT vec3 hitValue;\n"
1298 			<< "hitAttributeEXT vec3 attribs;\n"
1299 			<< glslBindingsStr
1300 			<< "void main()\n"
1301 			<< "{\n"
1302 			<< "    calleeBuffer.val = 1u;\n"
1303 			<< "}\n"
1304 			;
1305 		programCollection.glslSources.add("chit") << glu::ClosestHitSource(updateRayTracingGLSL(chit.str())) << buildOptions;
1306 	}
1307 	else if (m_params.callType == CallType::EXECUTE_CALLABLE)
1308 	{
1309 		subs["ENTRY_POINT"]						=	"RayGenerationKHR";
1310 		subs["MAIN_INTERFACE_EXTRAS"]			+=	" %callableData";
1311 		subs["INTERFACE_DECORATIONS"]			+=	"                                  OpDecorate %callableData Location 0\n";
1312 		subs["INTERFACE_TYPES_AND_VARIABLES"]	=	"             %callable_data_ptr = OpTypePointer CallableDataKHR %float\n"
1313 													"                  %callableData = OpVariable %callable_data_ptr CallableDataKHR\n";
1314 		subs["CALL_STATEMENTS"]					=	"                                  OpExecuteCallableKHR %zero_for_callable %callableData\n";
1315 
1316 		const auto rgen = spvTemplate.specialize(subs);
1317 		programCollection.spirvAsmSources.add("rgen") << rgen << spvBuildOptions;
1318 
1319 		std::ostringstream call;
1320 		call
1321 			<< glslHeaderStr
1322 			<< "layout(location = 0) callableDataInEXT float callableData;\n"
1323 			<< glslBindingsStr
1324 			<< "void main()\n"
1325 			<< "{\n"
1326 			<< "    calleeBuffer.val = 1u;\n"
1327 			<< "}\n"
1328 			;
1329 
1330 		programCollection.glslSources.add("call") << glu::CallableSource(updateRayTracingGLSL(call.str())) << buildOptions;
1331 	}
1332 	else if (m_params.callType == CallType::REPORT_INTERSECTION)
1333 	{
1334 		subs["ENTRY_POINT"]						=	"IntersectionKHR";
1335 		subs["MAIN_INTERFACE_EXTRAS"]			+=	" %attribs";
1336 		subs["INTERFACE_DECORATIONS"]			+=	"";
1337 		subs["INTERFACE_TYPES_AND_VARIABLES"]	=	"             %hit_attribute_ptr = OpTypePointer HitAttributeKHR %v3float\n"
1338 													"                       %attribs = OpVariable %hit_attribute_ptr HitAttributeKHR\n";
1339 		subs["CALL_STATEMENTS"]					=	"              %intersection_ret = OpReportIntersectionKHR %bool %float_1 %zero_for_callable\n";
1340 
1341 		const auto rint = spvTemplate.specialize(subs);
1342 		programCollection.spirvAsmSources.add("rint") << rint << spvBuildOptions;
1343 
1344 		std::ostringstream rgen;
1345 		rgen
1346 			<< glslHeaderStr
1347 			<< "layout(location = 0) rayPayloadEXT vec3 hitValue;\n"
1348 			<< glslBindingsStr
1349 			<< "void main()\n"
1350 			<< "{\n"
1351 			<< "  traceRayEXT(topLevelAS, 0u, 0xFFu, 0, 0, 0, vec3(0.5, 0.5, 0.0), 0.0, vec3(0.0, 0.0, -1.0), 9.0, 0);\n"
1352 			<< "}\n"
1353 			;
1354 		programCollection.glslSources.add("rgen") << glu::RaygenSource(updateRayTracingGLSL(rgen.str())) << buildOptions;
1355 
1356 		std::stringstream ahit;
1357 		ahit
1358 			<< glslHeaderStr
1359 			<< "layout(location = 0) rayPayloadInEXT vec3 hitValue;\n"
1360 			<< "hitAttributeEXT vec3 attribs;\n"
1361 			<< glslBindingsStr
1362 			<< "void main()\n"
1363 			<< "{\n"
1364 			<< "    calleeBuffer.val = 1u;\n"
1365 			<< "}\n"
1366 			;
1367 		programCollection.glslSources.add("ahit") << glu::AnyHitSource(updateRayTracingGLSL(ahit.str())) << buildOptions;
1368 	}
1369 	else
1370 	{
1371 		DE_ASSERT(false);
1372 	}
1373 }
1374 
1375 using v2i32 = tcu::Vector<deInt32, 2>;
1376 using v3i32 = tcu::Vector<deInt32, 3>;
1377 using v4i32 = tcu::Vector<deInt32, 4>;
1378 using a5i32 = std::array<deInt32, 5>;
1379 
1380 using v2u32 = tcu::Vector<deUint32, 2>;
1381 using v3u32 = tcu::Vector<deUint32, 3>;
1382 using v4u32 = tcu::Vector<deUint32, 4>;
1383 using a5u32 = std::array<deUint32, 5>;
1384 
1385 using v2i64 = tcu::Vector<deInt64, 2>;
1386 using v3i64 = tcu::Vector<deInt64, 3>;
1387 using v4i64 = tcu::Vector<deInt64, 4>;
1388 using a5i64 = std::array<deInt64, 5>;
1389 
1390 using v2u64 = tcu::Vector<deUint64, 2>;
1391 using v3u64 = tcu::Vector<deUint64, 3>;
1392 using v4u64 = tcu::Vector<deUint64, 4>;
1393 using a5u64 = std::array<deUint64, 5>;
1394 
1395 using v2i16 = tcu::Vector<deInt16, 2>;
1396 using v3i16 = tcu::Vector<deInt16, 3>;
1397 using v4i16 = tcu::Vector<deInt16, 4>;
1398 using a5i16 = std::array<deInt16, 5>;
1399 
1400 using v2u16 = tcu::Vector<deUint16, 2>;
1401 using v3u16 = tcu::Vector<deUint16, 3>;
1402 using v4u16 = tcu::Vector<deUint16, 4>;
1403 using a5u16 = std::array<deUint16, 5>;
1404 
1405 using v2i8 = tcu::Vector<deInt8, 2>;
1406 using v3i8 = tcu::Vector<deInt8, 3>;
1407 using v4i8 = tcu::Vector<deInt8, 4>;
1408 using a5i8 = std::array<deInt8, 5>;
1409 
1410 using v2u8 = tcu::Vector<deUint8, 2>;
1411 using v3u8 = tcu::Vector<deUint8, 3>;
1412 using v4u8 = tcu::Vector<deUint8, 4>;
1413 using a5u8 = std::array<deUint8, 5>;
1414 
1415 using v2f32 = tcu::Vector<tcu::Float32, 2>;
1416 using v3f32 = tcu::Vector<tcu::Float32, 3>;
1417 using v4f32 = tcu::Vector<tcu::Float32, 4>;
1418 using a5f32 = std::array<tcu::Float32, 5>;
1419 
1420 using v2f64 = tcu::Vector<tcu::Float64, 2>;
1421 using v3f64 = tcu::Vector<tcu::Float64, 3>;
1422 using v4f64 = tcu::Vector<tcu::Float64, 4>;
1423 using a5f64 = std::array<tcu::Float64, 5>;
1424 
1425 using v2f16 = tcu::Vector<tcu::Float16, 2>;
1426 using v3f16 = tcu::Vector<tcu::Float16, 3>;
1427 using v4f16 = tcu::Vector<tcu::Float16, 4>;
1428 using a5f16 = std::array<tcu::Float16, 5>;
1429 
1430 // Scalar types get filled with value 37, matching the value that will be substracted in the shader.
1431 #define GEN_SCALAR_FILL(DATA_TYPE)											\
1432 	do {																	\
1433 		const auto inputBufferValue = static_cast<DATA_TYPE>(37.0);			\
1434 		deMemcpy(bufferPtr, &inputBufferValue, sizeof(inputBufferValue));	\
1435 	} while (0)
1436 
1437 // Vector types get filled with values that add up to 37, matching the value that will be substracted in the shader.
1438 #define GEN_V2_FILL(DATA_TYPE)												\
1439 	do {																	\
1440 		DATA_TYPE inputBufferValue;											\
1441 		inputBufferValue.x() = static_cast<DATA_TYPE::Element>(21.0);		\
1442 		inputBufferValue.y() = static_cast<DATA_TYPE::Element>(16.0);		\
1443 		deMemcpy(bufferPtr, &inputBufferValue, sizeof(inputBufferValue));	\
1444 	} while (0)
1445 
1446 #define GEN_V3_FILL(DATA_TYPE)												\
1447 	do {																	\
1448 		DATA_TYPE inputBufferValue;											\
1449 		inputBufferValue.x() = static_cast<DATA_TYPE::Element>(11.0);		\
1450 		inputBufferValue.y() = static_cast<DATA_TYPE::Element>(19.0);		\
1451 		inputBufferValue.z() = static_cast<DATA_TYPE::Element>(7.0);		\
1452 		deMemcpy(bufferPtr, &inputBufferValue, sizeof(inputBufferValue));	\
1453 	} while (0)
1454 
1455 #define GEN_V4_FILL(DATA_TYPE)												\
1456 	do {																	\
1457 		DATA_TYPE inputBufferValue;											\
1458 		inputBufferValue.x() = static_cast<DATA_TYPE::Element>(9.0);		\
1459 		inputBufferValue.y() = static_cast<DATA_TYPE::Element>(11.0);		\
1460 		inputBufferValue.z() = static_cast<DATA_TYPE::Element>(3.0);		\
1461 		inputBufferValue.w() = static_cast<DATA_TYPE::Element>(14.0);		\
1462 		deMemcpy(bufferPtr, &inputBufferValue, sizeof(inputBufferValue));	\
1463 	} while (0)
1464 
1465 #define GEN_A5_FILL(DATA_TYPE)															\
1466 	do {																				\
1467 		DATA_TYPE inputBufferValue;														\
1468 		inputBufferValue[0] = static_cast<DATA_TYPE::value_type>(13.0);					\
1469 		inputBufferValue[1] = static_cast<DATA_TYPE::value_type>(6.0);					\
1470 		inputBufferValue[2] = static_cast<DATA_TYPE::value_type>(2.0);					\
1471 		inputBufferValue[3] = static_cast<DATA_TYPE::value_type>(5.0);					\
1472 		inputBufferValue[4] = static_cast<DATA_TYPE::value_type>(11.0);					\
1473 		deMemcpy(bufferPtr, inputBufferValue.data(), de::dataSize(inputBufferValue));	\
1474 	} while (0)
1475 
fillInputBuffer(DataType dataType, VectorType vectorType, void* bufferPtr)1476 void fillInputBuffer (DataType dataType, VectorType vectorType, void* bufferPtr)
1477 {
1478 	if (vectorType == VectorType::SCALAR)
1479 	{
1480 		if		(dataType == DataType::INT32)	GEN_SCALAR_FILL(deInt32);
1481 		else if	(dataType == DataType::UINT32)	GEN_SCALAR_FILL(deUint32);
1482 		else if	(dataType == DataType::INT64)	GEN_SCALAR_FILL(deInt64);
1483 		else if	(dataType == DataType::UINT64)	GEN_SCALAR_FILL(deUint64);
1484 		else if	(dataType == DataType::INT16)	GEN_SCALAR_FILL(deInt16);
1485 		else if	(dataType == DataType::UINT16)	GEN_SCALAR_FILL(deUint16);
1486 		else if	(dataType == DataType::INT8)	GEN_SCALAR_FILL(deInt8);
1487 		else if	(dataType == DataType::UINT8)	GEN_SCALAR_FILL(deUint8);
1488 		else if	(dataType == DataType::FLOAT32)	GEN_SCALAR_FILL(tcu::Float32);
1489 		else if	(dataType == DataType::FLOAT64)	GEN_SCALAR_FILL(tcu::Float64);
1490 		else if	(dataType == DataType::FLOAT16)	GEN_SCALAR_FILL(tcu::Float16);
1491 		else if (dataType == DataType::STRUCT)
1492 		{
1493 			InputStruct data = { 12u, 25.0f };
1494 			deMemcpy(bufferPtr, &data, sizeof(data));
1495 		}
1496 		else if (dataType == DataType::OP_NULL)		GEN_SCALAR_FILL(deUint32);
1497 		else if (dataType == DataType::OP_UNDEF)	GEN_SCALAR_FILL(deUint32);
1498 		else
1499 		{
1500 			DE_ASSERT(false);
1501 		}
1502 	}
1503 	else if (vectorType == VectorType::V2)
1504 	{
1505 		if		(dataType == DataType::INT32)	GEN_V2_FILL(v2i32);
1506 		else if	(dataType == DataType::UINT32)	GEN_V2_FILL(v2u32);
1507 		else if	(dataType == DataType::INT64)	GEN_V2_FILL(v2i64);
1508 		else if	(dataType == DataType::UINT64)	GEN_V2_FILL(v2u64);
1509 		else if	(dataType == DataType::INT16)	GEN_V2_FILL(v2i16);
1510 		else if	(dataType == DataType::UINT16)	GEN_V2_FILL(v2u16);
1511 		else if	(dataType == DataType::INT8)	GEN_V2_FILL(v2i8);
1512 		else if	(dataType == DataType::UINT8)	GEN_V2_FILL(v2u8);
1513 		else if	(dataType == DataType::FLOAT32)	GEN_V2_FILL(v2f32);
1514 		else if	(dataType == DataType::FLOAT64)	GEN_V2_FILL(v2f64);
1515 		else if	(dataType == DataType::FLOAT16)	GEN_V2_FILL(v2f16);
1516 		else
1517 		{
1518 			DE_ASSERT(false);
1519 		}
1520 	}
1521 	else if (vectorType == VectorType::V3)
1522 	{
1523 		if		(dataType == DataType::INT32)	GEN_V3_FILL(v3i32);
1524 		else if	(dataType == DataType::UINT32)	GEN_V3_FILL(v3u32);
1525 		else if	(dataType == DataType::INT64)	GEN_V3_FILL(v3i64);
1526 		else if	(dataType == DataType::UINT64)	GEN_V3_FILL(v3u64);
1527 		else if	(dataType == DataType::INT16)	GEN_V3_FILL(v3i16);
1528 		else if	(dataType == DataType::UINT16)	GEN_V3_FILL(v3u16);
1529 		else if	(dataType == DataType::INT8)	GEN_V3_FILL(v3i8);
1530 		else if	(dataType == DataType::UINT8)	GEN_V3_FILL(v3u8);
1531 		else if	(dataType == DataType::FLOAT32)	GEN_V3_FILL(v3f32);
1532 		else if	(dataType == DataType::FLOAT64)	GEN_V3_FILL(v3f64);
1533 		else if	(dataType == DataType::FLOAT16)	GEN_V3_FILL(v3f16);
1534 		else
1535 		{
1536 			DE_ASSERT(false);
1537 		}
1538 	}
1539 	else if (vectorType == VectorType::V4)
1540 	{
1541 		if		(dataType == DataType::INT32)	GEN_V4_FILL(v4i32);
1542 		else if	(dataType == DataType::UINT32)	GEN_V4_FILL(v4u32);
1543 		else if	(dataType == DataType::INT64)	GEN_V4_FILL(v4i64);
1544 		else if	(dataType == DataType::UINT64)	GEN_V4_FILL(v4u64);
1545 		else if	(dataType == DataType::INT16)	GEN_V4_FILL(v4i16);
1546 		else if	(dataType == DataType::UINT16)	GEN_V4_FILL(v4u16);
1547 		else if	(dataType == DataType::INT8)	GEN_V4_FILL(v4i8);
1548 		else if	(dataType == DataType::UINT8)	GEN_V4_FILL(v4u8);
1549 		else if	(dataType == DataType::FLOAT32)	GEN_V4_FILL(v4f32);
1550 		else if	(dataType == DataType::FLOAT64)	GEN_V4_FILL(v4f64);
1551 		else if	(dataType == DataType::FLOAT16)	GEN_V4_FILL(v4f16);
1552 		else
1553 		{
1554 			DE_ASSERT(false);
1555 		}
1556 	}
1557 	else if (vectorType == VectorType::A5)
1558 	{
1559 		if		(dataType == DataType::INT32)	GEN_A5_FILL(a5i32);
1560 		else if	(dataType == DataType::UINT32)	GEN_A5_FILL(a5u32);
1561 		else if	(dataType == DataType::INT64)	GEN_A5_FILL(a5i64);
1562 		else if	(dataType == DataType::UINT64)	GEN_A5_FILL(a5u64);
1563 		else if	(dataType == DataType::INT16)	GEN_A5_FILL(a5i16);
1564 		else if	(dataType == DataType::UINT16)	GEN_A5_FILL(a5u16);
1565 		else if	(dataType == DataType::INT8)	GEN_A5_FILL(a5i8);
1566 		else if	(dataType == DataType::UINT8)	GEN_A5_FILL(a5u8);
1567 		else if	(dataType == DataType::FLOAT32)	GEN_A5_FILL(a5f32);
1568 		else if	(dataType == DataType::FLOAT64)	GEN_A5_FILL(a5f64);
1569 		else if	(dataType == DataType::FLOAT16)	GEN_A5_FILL(a5f16);
1570 		else
1571 		{
1572 			DE_ASSERT(false);
1573 		}
1574 	}
1575 	else
1576 	{
1577 		DE_ASSERT(false);
1578 	}
1579 }
1580 
iterate(void)1581 tcu::TestStatus DataSpillTestInstance::iterate (void)
1582 {
1583 	const auto& vki						= m_context.getInstanceInterface();
1584 	const auto	physicalDevice			= m_context.getPhysicalDevice();
1585 	const auto&	vkd						= m_context.getDeviceInterface();
1586 	const auto	device					= m_context.getDevice();
1587 	const auto	queue					= m_context.getUniversalQueue();
1588 	const auto	familyIndex				= m_context.getUniversalQueueFamilyIndex();
1589 	auto&		alloc					= m_context.getDefaultAllocator();
1590 	const auto	shaderStages			= getShaderStages(m_params.callType);
1591 
1592 	// Command buffer.
1593 	const auto cmdPool		= makeCommandPool(vkd, device, familyIndex);
1594 	const auto cmdBufferPtr	= allocateCommandBuffer(vkd, device, cmdPool.get(), VK_COMMAND_BUFFER_LEVEL_PRIMARY);
1595 	const auto cmdBuffer	= cmdBufferPtr.get();
1596 
1597 	beginCommandBuffer(vkd, cmdBuffer);
1598 
1599 	// Callee, input and output buffers.
1600 	const auto calleeBufferSize	= getElementSize(DataType::UINT32, VectorType::SCALAR);
1601 	const auto outputBufferSize	= getElementSize(DataType::UINT32, VectorType::SCALAR);
1602 	const auto inputBufferSize	= getElementSize(m_params.dataType, m_params.vectorType);
1603 
1604 	const auto calleeBufferInfo	= makeBufferCreateInfo(calleeBufferSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
1605 	const auto outputBufferInfo	= makeBufferCreateInfo(outputBufferSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
1606 	const auto inputBufferInfo	= makeBufferCreateInfo(inputBufferSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
1607 
1608 	BufferWithMemory calleeBuffer	(vkd, device, alloc, calleeBufferInfo, MemoryRequirement::HostVisible);
1609 	BufferWithMemory outputBuffer	(vkd, device, alloc, outputBufferInfo, MemoryRequirement::HostVisible);
1610 	BufferWithMemory inputBuffer	(vkd, device, alloc, inputBufferInfo, MemoryRequirement::HostVisible);
1611 
1612 	// Fill buffers with values.
1613 	auto& calleeBufferAlloc	= calleeBuffer.getAllocation();
1614 	auto* calleeBufferPtr	= calleeBufferAlloc.getHostPtr();
1615 	auto& outputBufferAlloc	= outputBuffer.getAllocation();
1616 	auto* outputBufferPtr	= outputBufferAlloc.getHostPtr();
1617 	auto& inputBufferAlloc	= inputBuffer.getAllocation();
1618 	auto* inputBufferPtr	= inputBufferAlloc.getHostPtr();
1619 
1620 	deMemset(calleeBufferPtr, 0, static_cast<size_t>(calleeBufferSize));
1621 	deMemset(outputBufferPtr, 0, static_cast<size_t>(outputBufferSize));
1622 
1623 	if (samplersNeeded(m_params.dataType) || storageImageNeeded(m_params.dataType))
1624 	{
1625 		// The input buffer for these cases will be filled with zeros (sampling coordinates), and the input textures will contain the interesting input value.
1626 		deMemset(inputBufferPtr, 0, static_cast<size_t>(inputBufferSize));
1627 	}
1628 	else
1629 	{
1630 		// We want to fill the input buffer with values that will be consistently used in the shader to obtain a result of zero.
1631 		fillInputBuffer(m_params.dataType, m_params.vectorType, inputBufferPtr);
1632 	}
1633 
1634 	flushAlloc(vkd, device, calleeBufferAlloc);
1635 	flushAlloc(vkd, device, outputBufferAlloc);
1636 	flushAlloc(vkd, device, inputBufferAlloc);
1637 
1638 	// Acceleration structures.
1639 	de::MovePtr<BottomLevelAccelerationStructure>	bottomLevelAccelerationStructure;
1640 	de::MovePtr<TopLevelAccelerationStructure>		topLevelAccelerationStructure;
1641 
1642 	bottomLevelAccelerationStructure = makeBottomLevelAccelerationStructure();
1643 	bottomLevelAccelerationStructure->setDefaultGeometryData(getShaderStageForGeometry(m_params.callType), VK_GEOMETRY_NO_DUPLICATE_ANY_HIT_INVOCATION_BIT_KHR);
1644 	bottomLevelAccelerationStructure->createAndBuild(vkd, device, cmdBuffer, alloc);
1645 
1646 	topLevelAccelerationStructure = makeTopLevelAccelerationStructure();
1647 	topLevelAccelerationStructure->setInstanceCount(1);
1648 	topLevelAccelerationStructure->addInstance(de::SharedPtr<BottomLevelAccelerationStructure>(bottomLevelAccelerationStructure.release()));
1649 	topLevelAccelerationStructure->createAndBuild(vkd, device, cmdBuffer, alloc);
1650 
1651 	// Get some ray tracing properties.
1652 	deUint32 shaderGroupHandleSize		= 0u;
1653 	deUint32 shaderGroupBaseAlignment	= 1u;
1654 	{
1655 		const auto rayTracingPropertiesKHR	= makeRayTracingProperties(vki, physicalDevice);
1656 		shaderGroupHandleSize				= rayTracingPropertiesKHR->getShaderGroupHandleSize();
1657 		shaderGroupBaseAlignment			= rayTracingPropertiesKHR->getShaderGroupBaseAlignment();
1658 	}
1659 
1660 	// Textures and samplers if needed.
1661 	de::MovePtr<BufferWithMemory>				textureData;
1662 	std::vector<de::MovePtr<ImageWithMemory>>	textures;
1663 	std::vector<Move<VkImageView>>				textureViews;
1664 	std::vector<Move<VkSampler>>				samplers;
1665 
1666 	if (samplersNeeded(m_params.dataType) || storageImageNeeded(m_params.dataType))
1667 	{
1668 		// Create texture data with the expected contents.
1669 		{
1670 			const auto textureDataSize			= static_cast<VkDeviceSize>(sizeof(deUint32));
1671 			const auto textureDataCreateInfo	= makeBufferCreateInfo(textureDataSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
1672 
1673 			textureData = de::MovePtr<BufferWithMemory>(new BufferWithMemory(vkd, device, alloc, textureDataCreateInfo, MemoryRequirement::HostVisible));
1674 			auto& textureDataAlloc = textureData->getAllocation();
1675 			auto* textureDataPtr = textureDataAlloc.getHostPtr();
1676 
1677 			fillInputBuffer(DataType::UINT32, VectorType::SCALAR, textureDataPtr);
1678 			flushAlloc(vkd, device, textureDataAlloc);
1679 		}
1680 
1681 		// Images will be created like this with different usages.
1682 		VkImageCreateInfo imageCreateInfo =
1683 		{
1684 			VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,	//	VkStructureType			sType;
1685 			nullptr,								//	const void*				pNext;
1686 			0u,										//	VkImageCreateFlags		flags;
1687 			VK_IMAGE_TYPE_2D,						//	VkImageType				imageType;
1688 			kImageFormat,							//	VkFormat				format;
1689 			kImageExtent,							//	VkExtent3D				extent;
1690 			1u,										//	deUint32				mipLevels;
1691 			1u,										//	deUint32				arrayLayers;
1692 			VK_SAMPLE_COUNT_1_BIT,					//	VkSampleCountFlagBits	samples;
1693 			VK_IMAGE_TILING_OPTIMAL,				//	VkImageTiling			tiling;
1694 			kSampledImageUsage,						//	VkImageUsageFlags		usage;
1695 			VK_SHARING_MODE_EXCLUSIVE,				//	VkSharingMode			sharingMode;
1696 			0u,										//	deUint32				queueFamilyIndexCount;
1697 			nullptr,								//	const deUint32*			pQueueFamilyIndices;
1698 			VK_IMAGE_LAYOUT_UNDEFINED,				//	VkImageLayout			initialLayout;
1699 		};
1700 
1701 		const auto imageSubresourceRange	= makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
1702 		const auto imageSubresourceLayers	= makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u);
1703 
1704 		if (samplersNeeded(m_params.dataType))
1705 		{
1706 			// All samplers will be created like this.
1707 			const VkSamplerCreateInfo samplerCreateInfo =
1708 			{
1709 				VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,	//	VkStructureType			sType;
1710 				nullptr,								//	const void*				pNext;
1711 				0u,										//	VkSamplerCreateFlags	flags;
1712 				VK_FILTER_NEAREST,						//	VkFilter				magFilter;
1713 				VK_FILTER_NEAREST,						//	VkFilter				minFilter;
1714 				VK_SAMPLER_MIPMAP_MODE_NEAREST,			//	VkSamplerMipmapMode		mipmapMode;
1715 				VK_SAMPLER_ADDRESS_MODE_REPEAT,			//	VkSamplerAddressMode	addressModeU;
1716 				VK_SAMPLER_ADDRESS_MODE_REPEAT,			//	VkSamplerAddressMode	addressModeV;
1717 				VK_SAMPLER_ADDRESS_MODE_REPEAT,			//	VkSamplerAddressMode	addressModeW;
1718 				0.0,									//	float					mipLodBias;
1719 				VK_FALSE,								//	VkBool32				anisotropyEnable;
1720 				1.0f,									//	float					maxAnisotropy;
1721 				VK_FALSE,								//	VkBool32				compareEnable;
1722 				VK_COMPARE_OP_ALWAYS,					//	VkCompareOp				compareOp;
1723 				0.0f,									//	float					minLod;
1724 				1.0f,									//	float					maxLod;
1725 				VK_BORDER_COLOR_INT_OPAQUE_BLACK,		//	VkBorderColor			borderColor;
1726 				VK_FALSE,								//	VkBool32				unnormalizedCoordinates;
1727 			};
1728 
1729 			// Create textures and samplers.
1730 			for (size_t i = 0; i < kNumImages; ++i)
1731 			{
1732 				textures.emplace_back(new ImageWithMemory(vkd, device, alloc, imageCreateInfo, MemoryRequirement::Any));
1733 				textureViews.emplace_back(makeImageView(vkd, device, textures.back()->get(), VK_IMAGE_VIEW_TYPE_2D, kImageFormat, imageSubresourceRange));
1734 			}
1735 
1736 			for (size_t i = 0; i < kNumSamplers; ++i)
1737 				samplers.emplace_back(createSampler(vkd, device, &samplerCreateInfo));
1738 
1739 			// Make sure texture data is available in the transfer stage.
1740 			const auto textureDataBarrier = makeMemoryBarrier(VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT);
1741 			vkd.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 1u, &textureDataBarrier, 0u, nullptr, 0u, nullptr);
1742 
1743 			const auto bufferImageCopy = makeBufferImageCopy(kImageExtent, imageSubresourceLayers);
1744 
1745 			// Fill textures with data and prepare them for the ray tracing pipeline stages.
1746 			for (size_t i = 0; i < kNumImages; ++i)
1747 			{
1748 				const auto texturePreCopyBarrier	= makeImageMemoryBarrier(0u, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, textures[i]->get(), imageSubresourceRange);
1749 				const auto texturePostCopyBarrier	= makeImageMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, textures[i]->get(), imageSubresourceRange);
1750 
1751 				vkd.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, nullptr, 0u, nullptr, 1u, &texturePreCopyBarrier);
1752 				vkd.cmdCopyBufferToImage(cmdBuffer, textureData->get(), textures[i]->get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, &bufferImageCopy);
1753 				vkd.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR, 0u, 0u, nullptr, 0u, nullptr, 1u, &texturePostCopyBarrier);
1754 			}
1755 		}
1756 		else if (storageImageNeeded(m_params.dataType))
1757 		{
1758 			// Image will be used for storage.
1759 			imageCreateInfo.usage = kStorageImageUsage;
1760 
1761 			textures.emplace_back(new ImageWithMemory(vkd, device, alloc, imageCreateInfo, MemoryRequirement::Any));
1762 			textureViews.emplace_back(makeImageView(vkd, device, textures.back()->get(), VK_IMAGE_VIEW_TYPE_2D, kImageFormat, imageSubresourceRange));
1763 
1764 			// Make sure texture data is available in the transfer stage.
1765 			const auto textureDataBarrier = makeMemoryBarrier(VK_ACCESS_HOST_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT);
1766 			vkd.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 1u, &textureDataBarrier, 0u, nullptr, 0u, nullptr);
1767 
1768 			const auto bufferImageCopy			= makeBufferImageCopy(kImageExtent, imageSubresourceLayers);
1769 			const auto texturePreCopyBarrier	= makeImageMemoryBarrier(0u, VK_ACCESS_TRANSFER_WRITE_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, textures.back()->get(), imageSubresourceRange);
1770 			const auto texturePostCopyBarrier	= makeImageMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, (VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL, textures.back()->get(), imageSubresourceRange);
1771 
1772 			// Fill texture with data and prepare them for the ray tracing pipeline stages.
1773 			vkd.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, nullptr, 0u, nullptr, 1u, &texturePreCopyBarrier);
1774 			vkd.cmdCopyBufferToImage(cmdBuffer, textureData->get(), textures.back()->get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, &bufferImageCopy);
1775 			vkd.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR, 0u, 0u, nullptr, 0u, nullptr, 1u, &texturePostCopyBarrier);
1776 		}
1777 		else
1778 		{
1779 			DE_ASSERT(false);
1780 		}
1781 	}
1782 
1783 	// Descriptor set layout.
1784 	DescriptorSetLayoutBuilder dslBuilder;
1785 	dslBuilder.addBinding(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 1u, shaderStages, nullptr);
1786 	dslBuilder.addBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1u, shaderStages, nullptr);	// Callee buffer.
1787 	dslBuilder.addBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1u, shaderStages, nullptr);	// Output buffer.
1788 	dslBuilder.addBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1u, shaderStages, nullptr);	// Input buffer.
1789 	if (samplersNeeded(m_params.dataType))
1790 	{
1791 		dslBuilder.addBinding(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 2u, shaderStages, nullptr);
1792 		dslBuilder.addBinding(VK_DESCRIPTOR_TYPE_SAMPLER, 2u, shaderStages, nullptr);
1793 		dslBuilder.addBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2u, shaderStages, nullptr);
1794 	}
1795 	else if (storageImageNeeded(m_params.dataType))
1796 	{
1797 		dslBuilder.addBinding(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1u, shaderStages, nullptr);
1798 	}
1799 	const auto descriptorSetLayout = dslBuilder.build(vkd, device);
1800 
1801 	// Pipeline layout.
1802 	const auto pipelineLayout = makePipelineLayout(vkd, device, descriptorSetLayout.get());
1803 
1804 	// Descriptor pool and set.
1805 	DescriptorPoolBuilder poolBuilder;
1806 	poolBuilder.addType(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR);
1807 	poolBuilder.addType(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 3u);
1808 	if (samplersNeeded(m_params.dataType))
1809 	{
1810 		poolBuilder.addType(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 2u);
1811 		poolBuilder.addType(VK_DESCRIPTOR_TYPE_SAMPLER, 2u);
1812 		poolBuilder.addType(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2u);
1813 	}
1814 	else if (storageImageNeeded(m_params.dataType))
1815 	{
1816 		poolBuilder.addType(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1u);
1817 	}
1818 	const auto descriptorPool = poolBuilder.build(vkd, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u);
1819 	const auto descriptorSet = makeDescriptorSet(vkd, device, descriptorPool.get(), descriptorSetLayout.get());
1820 
1821 	// Update descriptor set.
1822 	{
1823 		const VkWriteDescriptorSetAccelerationStructureKHR writeASInfo =
1824 		{
1825 			VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR,
1826 			nullptr,
1827 			1u,
1828 			topLevelAccelerationStructure.get()->getPtr(),
1829 		};
1830 
1831 		DescriptorSetUpdateBuilder updateBuilder;
1832 
1833 		const auto ds = descriptorSet.get();
1834 
1835 		const auto calleeBufferDescriptorInfo	= makeDescriptorBufferInfo(calleeBuffer.get(), 0ull, VK_WHOLE_SIZE);
1836 		const auto outputBufferDescriptorInfo	= makeDescriptorBufferInfo(outputBuffer.get(), 0ull, VK_WHOLE_SIZE);
1837 		const auto inputBufferDescriptorInfo	= makeDescriptorBufferInfo(inputBuffer.get(), 0ull, VK_WHOLE_SIZE);
1838 
1839 		updateBuilder.writeSingle(ds, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, &writeASInfo);
1840 		updateBuilder.writeSingle(ds, DescriptorSetUpdateBuilder::Location::binding(1u), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, &calleeBufferDescriptorInfo);
1841 		updateBuilder.writeSingle(ds, DescriptorSetUpdateBuilder::Location::binding(2u), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, &outputBufferDescriptorInfo);
1842 		updateBuilder.writeSingle(ds, DescriptorSetUpdateBuilder::Location::binding(3u), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, &inputBufferDescriptorInfo);
1843 
1844 		if (samplersNeeded(m_params.dataType))
1845 		{
1846 			// Update textures, samplers and combined image samplers.
1847 			std::vector<VkDescriptorImageInfo> textureDescInfos;
1848 			std::vector<VkDescriptorImageInfo> textureSamplerInfos;
1849 			std::vector<VkDescriptorImageInfo> combinedSamplerInfos;
1850 
1851 			for (size_t i = 0; i < kNumAloneImages; ++i)
1852 				textureDescInfos.push_back(makeDescriptorImageInfo(DE_NULL, textureViews[i].get(), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL));
1853 			for (size_t i = 0; i < kNumAloneSamplers; ++i)
1854 				textureSamplerInfos.push_back(makeDescriptorImageInfo(samplers[i].get(), DE_NULL, VK_IMAGE_LAYOUT_UNDEFINED));
1855 
1856 			for (size_t i = 0; i < kNumCombined; ++i)
1857 				combinedSamplerInfos.push_back(makeDescriptorImageInfo(samplers[i + kNumAloneSamplers].get(), textureViews[i + kNumAloneImages].get(), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL));
1858 
1859 			updateBuilder.writeArray(ds, DescriptorSetUpdateBuilder::Location::binding(4u), VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, kNumAloneImages, textureDescInfos.data());
1860 			updateBuilder.writeArray(ds, DescriptorSetUpdateBuilder::Location::binding(5u), VK_DESCRIPTOR_TYPE_SAMPLER, kNumAloneSamplers, textureSamplerInfos.data());
1861 			updateBuilder.writeArray(ds, DescriptorSetUpdateBuilder::Location::binding(6u), VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, kNumCombined, combinedSamplerInfos.data());
1862 		}
1863 		else if (storageImageNeeded(m_params.dataType))
1864 		{
1865 			const auto storageImageDescriptorInfo = makeDescriptorImageInfo(DE_NULL, textureViews.back().get(), VK_IMAGE_LAYOUT_GENERAL);
1866 			updateBuilder.writeSingle(ds, DescriptorSetUpdateBuilder::Location::binding(4u), VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, &storageImageDescriptorInfo);
1867 		}
1868 
1869 		updateBuilder.update(vkd, device);
1870 	}
1871 
1872 	// Create raytracing pipeline and shader binding tables.
1873 	Move<VkPipeline>				pipeline;
1874 
1875 	de::MovePtr<BufferWithMemory>	raygenShaderBindingTable;
1876 	de::MovePtr<BufferWithMemory>	missShaderBindingTable;
1877 	de::MovePtr<BufferWithMemory>	hitShaderBindingTable;
1878 	de::MovePtr<BufferWithMemory>	callableShaderBindingTable;
1879 
1880 	VkStridedDeviceAddressRegionKHR	raygenShaderBindingTableRegion		= makeStridedDeviceAddressRegionKHR(DE_NULL, 0, 0);
1881 	VkStridedDeviceAddressRegionKHR	missShaderBindingTableRegion		= makeStridedDeviceAddressRegionKHR(DE_NULL, 0, 0);
1882 	VkStridedDeviceAddressRegionKHR	hitShaderBindingTableRegion			= makeStridedDeviceAddressRegionKHR(DE_NULL, 0, 0);
1883 	VkStridedDeviceAddressRegionKHR	callableShaderBindingTableRegion	= makeStridedDeviceAddressRegionKHR(DE_NULL, 0, 0);
1884 
1885 	{
1886 		const auto rayTracingPipeline = de::newMovePtr<RayTracingPipeline>();
1887 		const auto callType = m_params.callType;
1888 
1889 		// Every case uses a ray generation shader.
1890 		rayTracingPipeline->addShader(VK_SHADER_STAGE_RAYGEN_BIT_KHR, createShaderModule(vkd, device, m_context.getBinaryCollection().get("rgen"), 0), 0);
1891 
1892 		if (callType == CallType::TRACE_RAY)
1893 		{
1894 			rayTracingPipeline->addShader(VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, createShaderModule(vkd, device, m_context.getBinaryCollection().get("chit"), 0), 1);
1895 		}
1896 		else if (callType == CallType::EXECUTE_CALLABLE)
1897 		{
1898 			rayTracingPipeline->addShader(VK_SHADER_STAGE_CALLABLE_BIT_KHR, createShaderModule(vkd, device, m_context.getBinaryCollection().get("call"), 0), 1);
1899 		}
1900 		else if (callType == CallType::REPORT_INTERSECTION)
1901 		{
1902 			rayTracingPipeline->addShader(VK_SHADER_STAGE_INTERSECTION_BIT_KHR, createShaderModule(vkd, device, m_context.getBinaryCollection().get("rint"), 0), 1);
1903 			rayTracingPipeline->addShader(VK_SHADER_STAGE_ANY_HIT_BIT_KHR, createShaderModule(vkd, device, m_context.getBinaryCollection().get("ahit"), 0), 1);
1904 		}
1905 		else
1906 		{
1907 			DE_ASSERT(false);
1908 		}
1909 
1910 		pipeline = rayTracingPipeline->createPipeline(vkd, device, pipelineLayout.get());
1911 
1912 		raygenShaderBindingTable			= rayTracingPipeline->createShaderBindingTable(vkd, device, pipeline.get(), alloc, shaderGroupHandleSize, shaderGroupBaseAlignment, 0, 1);
1913 		raygenShaderBindingTableRegion		= makeStridedDeviceAddressRegionKHR(getBufferDeviceAddress(vkd, device, raygenShaderBindingTable->get(), 0), shaderGroupHandleSize, shaderGroupHandleSize);
1914 
1915 		if (callType == CallType::EXECUTE_CALLABLE)
1916 		{
1917 			callableShaderBindingTable			= rayTracingPipeline->createShaderBindingTable(vkd, device, pipeline.get(), alloc, shaderGroupHandleSize, shaderGroupBaseAlignment, 1, 1);
1918 			callableShaderBindingTableRegion	= makeStridedDeviceAddressRegionKHR(getBufferDeviceAddress(vkd, device, callableShaderBindingTable->get(), 0), shaderGroupHandleSize, shaderGroupHandleSize);
1919 		}
1920 		else if (callType == CallType::TRACE_RAY || callType == CallType::REPORT_INTERSECTION)
1921 		{
1922 			hitShaderBindingTable			= rayTracingPipeline->createShaderBindingTable(vkd, device, pipeline.get(), alloc, shaderGroupHandleSize, shaderGroupBaseAlignment, 1, 1);
1923 			hitShaderBindingTableRegion		= makeStridedDeviceAddressRegionKHR(getBufferDeviceAddress(vkd, device, hitShaderBindingTable->get(), 0), shaderGroupHandleSize, shaderGroupHandleSize);
1924 		}
1925 		else
1926 		{
1927 			DE_ASSERT(false);
1928 		}
1929 	}
1930 
1931 	// Use ray tracing pipeline.
1932 	vkd.cmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, pipeline.get());
1933 	vkd.cmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, pipelineLayout.get(), 0u, 1u, &descriptorSet.get(), 0u, nullptr);
1934 	vkd.cmdTraceRaysKHR(cmdBuffer, &raygenShaderBindingTableRegion, &missShaderBindingTableRegion, &hitShaderBindingTableRegion, &callableShaderBindingTableRegion, 1u, 1u, 1u);
1935 
1936 	// Synchronize output and callee buffers.
1937 	const auto memBarrier = makeMemoryBarrier(VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT);
1938 	vkd.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR, VK_PIPELINE_STAGE_HOST_BIT, 0u, 1u, &memBarrier, 0u, nullptr, 0u, nullptr);
1939 
1940 	endCommandBuffer(vkd, cmdBuffer);
1941 	submitCommandsAndWait(vkd, device, queue, cmdBuffer);
1942 
1943 	// Verify output and callee buffers.
1944 	invalidateAlloc(vkd, device, outputBufferAlloc);
1945 	invalidateAlloc(vkd, device, calleeBufferAlloc);
1946 
1947 	std::map<std::string, void*> bufferPtrs;
1948 	bufferPtrs["output"] = outputBufferPtr;
1949 	bufferPtrs["callee"] = calleeBufferPtr;
1950 
1951 	for (const auto& ptr : bufferPtrs)
1952 	{
1953 		const auto& bufferName	= ptr.first;
1954 		const auto& bufferPtr	= ptr.second;
1955 
1956 		deUint32 outputVal;
1957 		deMemcpy(&outputVal, bufferPtr, sizeof(outputVal));
1958 
1959 		if (outputVal != 1u)
1960 			return tcu::TestStatus::fail("Unexpected value found in " + bufferName + " buffer: " + de::toString(outputVal));
1961 	}
1962 
1963 	return tcu::TestStatus::pass("Pass");
1964 }
1965 
1966 enum class InterfaceType
1967 {
1968 	RAY_PAYLOAD = 0,
1969 	CALLABLE_DATA,
1970 	HIT_ATTRIBUTES,
1971 	SHADER_RECORD_BUFFER_RGEN,
1972 	SHADER_RECORD_BUFFER_CALL,
1973 	SHADER_RECORD_BUFFER_MISS,
1974 	SHADER_RECORD_BUFFER_HIT,
1975 };
1976 
1977 // Separate class to ease testing pipeline interface variables.
1978 class DataSpillPipelineInterfaceTestCase : public vkt::TestCase
1979 {
1980 public:
1981 	struct TestParams
1982 	{
1983 		InterfaceType	interfaceType;
1984 	};
1985 
1986 							DataSpillPipelineInterfaceTestCase		(tcu::TestContext& testCtx, const std::string& name, const TestParams& testParams);
~DataSpillPipelineInterfaceTestCase(void)1987 	virtual					~DataSpillPipelineInterfaceTestCase		(void) {}
1988 
1989 	virtual void			initPrograms							(vk::SourceCollections& programCollection) const;
1990 	virtual TestInstance*	createInstance							(Context& context) const;
1991 	virtual void			checkSupport							(Context& context) const;
1992 
1993 private:
1994 	TestParams				m_params;
1995 };
1996 
1997 class DataSpillPipelineInterfaceTestInstance : public vkt::TestInstance
1998 {
1999 public:
2000 	using TestParams = DataSpillPipelineInterfaceTestCase::TestParams;
2001 
2002 						DataSpillPipelineInterfaceTestInstance	(Context& context, const TestParams& testParams);
~DataSpillPipelineInterfaceTestInstance(void)2003 						~DataSpillPipelineInterfaceTestInstance	(void) {}
2004 
2005 	tcu::TestStatus		iterate									(void);
2006 
2007 private:
2008 	TestParams			m_params;
2009 };
2010 
DataSpillPipelineInterfaceTestCase(tcu::TestContext& testCtx, const std::string& name, const TestParams& testParams)2011 DataSpillPipelineInterfaceTestCase::DataSpillPipelineInterfaceTestCase (tcu::TestContext& testCtx, const std::string& name, const TestParams& testParams)
2012 	: vkt::TestCase	(testCtx, name)
2013 	, m_params		(testParams)
2014 {
2015 }
2016 
createInstance(Context& context) const2017 TestInstance* DataSpillPipelineInterfaceTestCase::createInstance (Context& context) const
2018 {
2019 	return new DataSpillPipelineInterfaceTestInstance (context, m_params);
2020 }
2021 
DataSpillPipelineInterfaceTestInstance(Context& context, const TestParams& testParams)2022 DataSpillPipelineInterfaceTestInstance::DataSpillPipelineInterfaceTestInstance (Context& context, const TestParams& testParams)
2023 	: vkt::TestInstance	(context)
2024 	, m_params			(testParams)
2025 {
2026 }
2027 
checkSupport(Context& context) const2028 void DataSpillPipelineInterfaceTestCase::checkSupport (Context& context) const
2029 {
2030 	commonCheckSupport(context);
2031 }
2032 
initPrograms(vk::SourceCollections& programCollection) const2033 void DataSpillPipelineInterfaceTestCase::initPrograms (vk::SourceCollections& programCollection) const
2034 {
2035 	const vk::ShaderBuildOptions buildOptions (programCollection.usedVulkanVersion, vk::SPIRV_VERSION_1_4, 0u, true);
2036 
2037 	const std::string glslHeader =
2038 		"#version 460 core\n"
2039 		"#extension GL_EXT_ray_tracing : require\n"
2040 		;
2041 
2042 	const std::string glslBindings =
2043 		"layout(set = 0, binding = 0) uniform accelerationStructureEXT topLevelAS;\n"
2044 		"layout(set = 0, binding = 1) buffer StorageBlock { uint val[" + std::to_string(kNumStorageValues) + "]; } storageBuffer;\n"
2045 		;
2046 
2047 	if (m_params.interfaceType == InterfaceType::RAY_PAYLOAD)
2048 	{
2049 		// The closest hit shader will store 100 in the second array position.
2050 		// The ray gen shader will store 103 in the first array position using the hitValue after the traceRayExt() call.
2051 
2052 		std::ostringstream rgen;
2053 		rgen
2054 			<< glslHeader
2055 			<< "layout(location = 0) rayPayloadEXT vec3 hitValue;\n"
2056 			<< glslBindings
2057 			<< "void main()\n"
2058 			<< "{\n"
2059 			<< "  hitValue = vec3(10.0, 30.0, 60.0);\n"
2060 			<< "  traceRayEXT(topLevelAS, 0u, 0xFFu, 0, 0, 0, vec3(0.5, 0.5, 0.0), 0.0, vec3(0.0, 0.0, -1.0), 9.0, 0);\n"
2061 			<< "  storageBuffer.val[0] = uint(hitValue.x + hitValue.y + hitValue.z);\n"
2062 			<< "}\n"
2063 			;
2064 		programCollection.glslSources.add("rgen") << glu::RaygenSource(updateRayTracingGLSL(rgen.str())) << buildOptions;
2065 
2066 		std::stringstream chit;
2067 		chit
2068 			<< glslHeader
2069 			<< "layout(location = 0) rayPayloadInEXT vec3 hitValue;\n"
2070 			<< "hitAttributeEXT vec3 attribs;\n"
2071 			<< glslBindings
2072 			<< "void main()\n"
2073 			<< "{\n"
2074 			<< "  storageBuffer.val[1] = uint(hitValue.x + hitValue.y + hitValue.z);\n"
2075 			<< "  hitValue = vec3(hitValue.x + 1.0, hitValue.y + 1.0, hitValue.z + 1.0);\n"
2076 			<< "}\n"
2077 			;
2078 		programCollection.glslSources.add("chit") << glu::ClosestHitSource(updateRayTracingGLSL(chit.str())) << buildOptions;
2079 	}
2080 	else if (m_params.interfaceType == InterfaceType::CALLABLE_DATA)
2081 	{
2082 		// The callable shader shader will store 100 in the second array position.
2083 		// The ray gen shader will store 200 in the first array position using the callable data after the executeCallableEXT() call.
2084 
2085 		std::ostringstream rgen;
2086 		rgen
2087 			<< glslHeader
2088 			<< "layout(location = 0) callableDataEXT float callableData;\n"
2089 			<< glslBindings
2090 			<< "void main()\n"
2091 			<< "{\n"
2092 			<< "  callableData = 100.0;\n"
2093 			<< "  executeCallableEXT(0, 0);\n"
2094 			<< "  storageBuffer.val[0] = uint(callableData);\n"
2095 			<< "}\n"
2096 			;
2097 		programCollection.glslSources.add("rgen") << glu::RaygenSource(updateRayTracingGLSL(rgen.str())) << buildOptions;
2098 
2099 		std::ostringstream call;
2100 		call
2101 			<< glslHeader
2102 			<< "layout(location = 0) callableDataInEXT float callableData;\n"
2103 			<< glslBindings
2104 			<< "void main()\n"
2105 			<< "{\n"
2106 			<< "    storageBuffer.val[1] = uint(callableData);\n"
2107 			<< "    callableData = callableData * 2.0;\n"
2108 			<< "}\n"
2109 			;
2110 
2111 		programCollection.glslSources.add("call") << glu::CallableSource(updateRayTracingGLSL(call.str())) << buildOptions;
2112 	}
2113 	else if (m_params.interfaceType == InterfaceType::HIT_ATTRIBUTES)
2114 	{
2115 		// The ray gen shader will store value 300 in the first storage buffer position.
2116 		// The intersection shader will store value 315 in the second storage buffer position.
2117 		// The closes hit shader will store value 330 in the third storage buffer position using the hit attributes.
2118 
2119 		std::ostringstream rgen;
2120 		rgen
2121 			<< glslHeader
2122 			<< "layout(location = 0) rayPayloadEXT vec3 hitValue;\n"
2123 			<< glslBindings
2124 			<< "void main()\n"
2125 			<< "{\n"
2126 			<< "  traceRayEXT(topLevelAS, 0u, 0xFFu, 0, 0, 0, vec3(0.5, 0.5, 0.0), 0.0, vec3(0.0, 0.0, -1.0), 9.0, 0);\n"
2127 			<< "  storageBuffer.val[0] = 300u;\n"
2128 			<< "}\n"
2129 			;
2130 		programCollection.glslSources.add("rgen") << glu::RaygenSource(updateRayTracingGLSL(rgen.str())) << buildOptions;
2131 
2132 		std::stringstream rint;
2133 		rint
2134 			<< glslHeader
2135 			<< "hitAttributeEXT vec3 attribs;\n"
2136 			<< glslBindings
2137 			<< "void main()\n"
2138 			<< "{\n"
2139 			<< "  attribs = vec3(140.0, 160.0, 30.0);\n"
2140 			<< "  storageBuffer.val[1] = 315u;\n"
2141 			<< "  reportIntersectionEXT(1.0f, 0);\n"
2142 			<< "}\n"
2143 			;
2144 
2145 		programCollection.glslSources.add("rint") << glu::IntersectionSource(updateRayTracingGLSL(rint.str())) << buildOptions;
2146 
2147 		std::stringstream chit;
2148 		chit
2149 			<< glslHeader
2150 			<< "layout(location = 0) rayPayloadInEXT vec3 hitValue;\n"
2151 			<< "hitAttributeEXT vec3 attribs;\n"
2152 			<< glslBindings
2153 			<< "void main()\n"
2154 			<< "{\n"
2155 			<< "  storageBuffer.val[2] = uint(attribs.x + attribs.y + attribs.z);\n"
2156 			<< "}\n"
2157 			;
2158 		programCollection.glslSources.add("chit") << glu::ClosestHitSource(updateRayTracingGLSL(chit.str())) << buildOptions;
2159 
2160 	}
2161 	else if (m_params.interfaceType == InterfaceType::SHADER_RECORD_BUFFER_RGEN)
2162 	{
2163 		// The ray gen shader will have a uvec4 in the shader record buffer with contents 400, 401, 402, 403.
2164 		// The shader will call a callable shader indicating a position in that vec4 (0, 1, 2, 3). For example, let's use position 1.
2165 		// The callable shader will return the indicated position+1 modulo 4, so it will return 2 in our case.
2166 		// *After* returning from the callable shader, the raygen shader will use that reply to access position 2 and write a 402 in the first output buffer position.
2167 		// The callable shader will store 450 in the second output buffer position.
2168 
2169 		std::ostringstream rgen;
2170 		rgen
2171 			<< glslHeader
2172 			<< "layout(shaderRecordEXT) buffer ShaderRecordStruct {\n"
2173 			<< "  uvec4 info;\n"
2174 			<< "};\n"
2175 			<< "layout(location = 0) callableDataEXT uint callableData;\n"
2176 			<< glslBindings
2177 			<< "void main()\n"
2178 			<< "{\n"
2179 			<< "  callableData = 1u;"
2180 			<< "  executeCallableEXT(0, 0);\n"
2181 			<< "  if      (callableData == 0u) storageBuffer.val[0] = info.x;\n"
2182 			<< "  else if (callableData == 1u) storageBuffer.val[0] = info.y;\n"
2183 			<< "  else if (callableData == 2u) storageBuffer.val[0] = info.z;\n"
2184 			<< "  else if (callableData == 3u) storageBuffer.val[0] = info.w;\n"
2185 			<< "}\n"
2186 			;
2187 		programCollection.glslSources.add("rgen") << glu::RaygenSource(updateRayTracingGLSL(rgen.str())) << buildOptions;
2188 
2189 		std::ostringstream call;
2190 		call
2191 			<< glslHeader
2192 			<< "layout(location = 0) callableDataInEXT uint callableData;\n"
2193 			<< glslBindings
2194 			<< "void main()\n"
2195 			<< "{\n"
2196 			<< "    storageBuffer.val[1] = 450u;\n"
2197 			<< "    callableData = (callableData + 1u) % 4u;\n"
2198 			<< "}\n"
2199 			;
2200 
2201 		programCollection.glslSources.add("call") << glu::CallableSource(updateRayTracingGLSL(call.str())) << buildOptions;
2202 	}
2203 	else if (m_params.interfaceType == InterfaceType::SHADER_RECORD_BUFFER_CALL)
2204 	{
2205 		// Similar to the previous case, with a twist:
2206 		//   * rgen passes the vector position.
2207 		//   * call increases that by one.
2208 		//   * subcall increases again and does the modulo operation, also writing 450 in the third output buffer value.
2209 		//   * call is the one accessing the vector at the returned position, writing 403 in this case to the second output buffer value.
2210 		//   * call passes this value back doubled to rgen, which writes it to the first output buffer value (806).
2211 
2212 		std::ostringstream rgen;
2213 		rgen
2214 			<< glslHeader
2215 			<< "layout(location = 0) callableDataEXT uint callableData;\n"
2216 			<< glslBindings
2217 			<< "void main()\n"
2218 			<< "{\n"
2219 			<< "  callableData = 1u;\n"
2220 			<< "  executeCallableEXT(0, 0);\n"
2221 			<< "  storageBuffer.val[0] = callableData;\n"
2222 			<< "}\n"
2223 			;
2224 		programCollection.glslSources.add("rgen") << glu::RaygenSource(updateRayTracingGLSL(rgen.str())) << buildOptions;
2225 
2226 		std::ostringstream call;
2227 		call
2228 			<< glslHeader
2229 			<< "layout(shaderRecordEXT) buffer ShaderRecordStruct {\n"
2230 			<< "  uvec4 info;\n"
2231 			<< "};\n"
2232 			<< "layout(location = 0) callableDataInEXT uint callableDataIn;\n"
2233 			<< "layout(location = 1) callableDataEXT uint callableDataOut;\n"
2234 			<< glslBindings
2235 			<< "void main()\n"
2236 			<< "{\n"
2237 			<< "  callableDataOut = callableDataIn + 1u;\n"
2238 			<< "  executeCallableEXT(1, 1);\n"
2239 			<< "  uint outputBufferValue = 777u;\n"
2240 			<< "  if      (callableDataOut == 0u) outputBufferValue = info.x;\n"
2241 			<< "  else if (callableDataOut == 1u) outputBufferValue = info.y;\n"
2242 			<< "  else if (callableDataOut == 2u) outputBufferValue = info.z;\n"
2243 			<< "  else if (callableDataOut == 3u) outputBufferValue = info.w;\n"
2244 			<< "  storageBuffer.val[1] = outputBufferValue;\n"
2245 			<< "  callableDataIn = outputBufferValue * 2u;\n"
2246 			<< "}\n"
2247 			;
2248 
2249 		programCollection.glslSources.add("call") << glu::CallableSource(updateRayTracingGLSL(call.str())) << buildOptions;
2250 
2251 		std::ostringstream subcall;
2252 		subcall
2253 			<< glslHeader
2254 			<< "layout(location = 1) callableDataInEXT uint callableData;\n"
2255 			<< glslBindings
2256 			<< "void main()\n"
2257 			<< "{\n"
2258 			<< "  callableData = (callableData + 1u) % 4u;\n"
2259 			<< "  storageBuffer.val[2] = 450u;\n"
2260 			<< "}\n"
2261 			;
2262 
2263 		programCollection.glslSources.add("subcall") << glu::CallableSource(updateRayTracingGLSL(subcall.str())) << buildOptions;
2264 	}
2265 	else if (m_params.interfaceType == InterfaceType::SHADER_RECORD_BUFFER_MISS || m_params.interfaceType == InterfaceType::SHADER_RECORD_BUFFER_HIT)
2266 	{
2267 		// Similar to the previous one, but the intermediate call shader has been replaced with a miss or closest hit shader.
2268 		// The rgen shader will communicate with the miss/chit shader using the ray payload instead of the callable data.
2269 		// Also, the initial position will be 2, so it will wrap around in this case. The numbers will also change.
2270 
2271 		std::ostringstream rgen;
2272 		rgen
2273 			<< glslHeader
2274 			<< "layout(location = 0) rayPayloadEXT uint rayPayload;\n"
2275 			<< glslBindings
2276 			<< "void main()\n"
2277 			<< "{\n"
2278 			<< "  rayPayload = 2u;\n"
2279 			<< "  traceRayEXT(topLevelAS, 0u, 0xFFu, 0, 0, 0, vec3(0.5, 0.5, 0.0), 0.0, vec3(0.0, 0.0, -1.0), 9.0, 0);\n"
2280 			<< "  storageBuffer.val[0] = rayPayload;\n"
2281 			<< "}\n"
2282 			;
2283 		programCollection.glslSources.add("rgen") << glu::RaygenSource(updateRayTracingGLSL(rgen.str())) << buildOptions;
2284 
2285 		std::ostringstream chitOrMiss;
2286 		chitOrMiss
2287 			<< glslHeader
2288 			<< "layout(shaderRecordEXT) buffer ShaderRecordStruct {\n"
2289 			<< "  uvec4 info;\n"
2290 			<< "};\n"
2291 			<< "layout(location = 0) rayPayloadInEXT uint rayPayload;\n"
2292 			<< "layout(location = 0) callableDataEXT uint callableData;\n"
2293 			<< glslBindings
2294 			<< "void main()\n"
2295 			<< "{\n"
2296 			<< "  callableData = rayPayload + 1u;\n"
2297 			<< "  executeCallableEXT(0, 0);\n"
2298 			<< "  uint outputBufferValue = 777u;\n"
2299 			<< "  if      (callableData == 0u) outputBufferValue = info.x;\n"
2300 			<< "  else if (callableData == 1u) outputBufferValue = info.y;\n"
2301 			<< "  else if (callableData == 2u) outputBufferValue = info.z;\n"
2302 			<< "  else if (callableData == 3u) outputBufferValue = info.w;\n"
2303 			<< "  storageBuffer.val[1] = outputBufferValue;\n"
2304 			<< "  rayPayload = outputBufferValue * 3u;\n"
2305 			<< "}\n"
2306 			;
2307 
2308 		if (m_params.interfaceType == InterfaceType::SHADER_RECORD_BUFFER_MISS)
2309 			programCollection.glslSources.add("miss") << glu::MissSource(updateRayTracingGLSL(chitOrMiss.str())) << buildOptions;
2310 		else if (m_params.interfaceType == InterfaceType::SHADER_RECORD_BUFFER_HIT)
2311 			programCollection.glslSources.add("chit") << glu::ClosestHitSource(updateRayTracingGLSL(chitOrMiss.str())) << buildOptions;
2312 		else
2313 			DE_ASSERT(false);
2314 
2315 		std::ostringstream call;
2316 		call
2317 			<< glslHeader
2318 			<< "layout(location = 0) callableDataInEXT uint callableData;\n"
2319 			<< glslBindings
2320 			<< "void main()\n"
2321 			<< "{\n"
2322 			<< "    storageBuffer.val[2] = 490u;\n"
2323 			<< "    callableData = (callableData + 1u) % 4u;\n"
2324 			<< "}\n"
2325 			;
2326 
2327 		programCollection.glslSources.add("call") << glu::CallableSource(updateRayTracingGLSL(call.str())) << buildOptions;
2328 	}
2329 	else
2330 	{
2331 		DE_ASSERT(false);
2332 	}
2333 }
2334 
getShaderStages(InterfaceType type_)2335 VkShaderStageFlags getShaderStages (InterfaceType type_)
2336 {
2337 	VkShaderStageFlags flags = VK_SHADER_STAGE_RAYGEN_BIT_KHR;
2338 
2339 	switch (type_)
2340 	{
2341 	case InterfaceType::HIT_ATTRIBUTES:
2342 		flags |= VK_SHADER_STAGE_INTERSECTION_BIT_KHR;
2343 		// fallthrough.
2344 	case InterfaceType::RAY_PAYLOAD:
2345 		flags |= VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR;
2346 		break;
2347 	case InterfaceType::CALLABLE_DATA:
2348 	case InterfaceType::SHADER_RECORD_BUFFER_RGEN:
2349 	case InterfaceType::SHADER_RECORD_BUFFER_CALL:
2350 		flags |= VK_SHADER_STAGE_CALLABLE_BIT_KHR;
2351 		break;
2352 	case InterfaceType::SHADER_RECORD_BUFFER_MISS:
2353 		flags |= VK_SHADER_STAGE_CALLABLE_BIT_KHR;
2354 		flags |= VK_SHADER_STAGE_MISS_BIT_KHR;
2355 		break;
2356 	case InterfaceType::SHADER_RECORD_BUFFER_HIT:
2357 		flags |= VK_SHADER_STAGE_CALLABLE_BIT_KHR;
2358 		flags |= VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR;
2359 		break;
2360 	default:
2361 		DE_ASSERT(false);
2362 		break;
2363 	}
2364 
2365 	return flags;
2366 }
2367 
2368 // Proper stage for generating default geometry.
getShaderStageForGeometry(InterfaceType type_)2369 VkShaderStageFlagBits getShaderStageForGeometry (InterfaceType type_)
2370 {
2371 	VkShaderStageFlagBits bits = VK_SHADER_STAGE_FLAG_BITS_MAX_ENUM;
2372 
2373 	switch (type_)
2374 	{
2375 	case InterfaceType::HIT_ATTRIBUTES:				bits = VK_SHADER_STAGE_INTERSECTION_BIT_KHR;	break;
2376 	case InterfaceType::RAY_PAYLOAD:				bits = VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR;		break;
2377 	case InterfaceType::CALLABLE_DATA:				bits = VK_SHADER_STAGE_CALLABLE_BIT_KHR;		break;
2378 	case InterfaceType::SHADER_RECORD_BUFFER_RGEN:	bits = VK_SHADER_STAGE_CALLABLE_BIT_KHR;		break;
2379 	case InterfaceType::SHADER_RECORD_BUFFER_CALL:	bits = VK_SHADER_STAGE_CALLABLE_BIT_KHR;		break;
2380 	case InterfaceType::SHADER_RECORD_BUFFER_MISS:	bits = VK_SHADER_STAGE_MISS_BIT_KHR;			break;
2381 	case InterfaceType::SHADER_RECORD_BUFFER_HIT:	bits = VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR;		break;
2382 	default: DE_ASSERT(false); break;
2383 	}
2384 
2385 	DE_ASSERT(bits != VK_SHADER_STAGE_FLAG_BITS_MAX_ENUM);
2386 	return bits;
2387 }
2388 
createSBTWithShaderRecord(const DeviceInterface& vkd, VkDevice device, vk::Allocator &alloc, VkPipeline pipeline, RayTracingPipeline* rayTracingPipeline, deUint32 shaderGroupHandleSize, deUint32 shaderGroupBaseAlignment, deUint32 firstGroup, deUint32 groupCount, de::MovePtr<BufferWithMemory>& shaderBindingTable, VkStridedDeviceAddressRegionKHR& shaderBindingTableRegion)2389 void createSBTWithShaderRecord (const DeviceInterface& vkd, VkDevice device, vk::Allocator &alloc,
2390 								VkPipeline pipeline, RayTracingPipeline* rayTracingPipeline,
2391 								deUint32 shaderGroupHandleSize, deUint32 shaderGroupBaseAlignment,
2392 								deUint32 firstGroup, deUint32 groupCount,
2393 								de::MovePtr<BufferWithMemory>& shaderBindingTable,
2394 								VkStridedDeviceAddressRegionKHR& shaderBindingTableRegion)
2395 {
2396 	const auto alignedSize		= de::roundUp(shaderGroupHandleSize + kShaderRecordSize, shaderGroupHandleSize);
2397 	shaderBindingTable			= rayTracingPipeline->createShaderBindingTable(vkd, device, pipeline, alloc, shaderGroupHandleSize, shaderGroupBaseAlignment, firstGroup, groupCount, 0u, 0u, MemoryRequirement::Any, 0u, 0u, kShaderRecordSize);
2398 	shaderBindingTableRegion	= makeStridedDeviceAddressRegionKHR(getBufferDeviceAddress(vkd, device, shaderBindingTable->get(), 0), alignedSize, groupCount * alignedSize);
2399 
2400 	// Fill shader record buffer data.
2401 	// Note we will only fill the first shader record after the handle.
2402 	const tcu::UVec4	shaderRecordData	(400u, 401u, 402u, 403u);
2403 	auto&				sbtAlloc			= shaderBindingTable->getAllocation();
2404 	auto*				dataPtr				= reinterpret_cast<deUint8*>(sbtAlloc.getHostPtr()) + shaderGroupHandleSize;
2405 
2406 	DE_STATIC_ASSERT(sizeof(shaderRecordData) == static_cast<size_t>(kShaderRecordSize));
2407 	deMemcpy(dataPtr, &shaderRecordData, sizeof(shaderRecordData));
2408 }
2409 
iterate(void)2410 tcu::TestStatus DataSpillPipelineInterfaceTestInstance::iterate (void)
2411 {
2412 	const auto& vki						= m_context.getInstanceInterface();
2413 	const auto	physicalDevice			= m_context.getPhysicalDevice();
2414 	const auto&	vkd						= m_context.getDeviceInterface();
2415 	const auto	device					= m_context.getDevice();
2416 	const auto	queue					= m_context.getUniversalQueue();
2417 	const auto	familyIndex				= m_context.getUniversalQueueFamilyIndex();
2418 	auto&		alloc					= m_context.getDefaultAllocator();
2419 	const auto	shaderStages			= getShaderStages(m_params.interfaceType);
2420 
2421 	// Command buffer.
2422 	const auto cmdPool		= makeCommandPool(vkd, device, familyIndex);
2423 	const auto cmdBufferPtr	= allocateCommandBuffer(vkd, device, cmdPool.get(), VK_COMMAND_BUFFER_LEVEL_PRIMARY);
2424 	const auto cmdBuffer	= cmdBufferPtr.get();
2425 
2426 	beginCommandBuffer(vkd, cmdBuffer);
2427 
2428 	// Storage buffer.
2429 	std::array<deUint32, kNumStorageValues>	storageBufferData;
2430 	const auto								storageBufferSize	= de::dataSize(storageBufferData);
2431 	const auto								storagebufferInfo	= makeBufferCreateInfo(storageBufferSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
2432 	BufferWithMemory						storageBuffer		(vkd, device, alloc, storagebufferInfo, MemoryRequirement::HostVisible);
2433 
2434 	// Zero-out buffer.
2435 	auto& storageBufferAlloc	= storageBuffer.getAllocation();
2436 	auto* storageBufferPtr		= storageBufferAlloc.getHostPtr();
2437 	deMemset(storageBufferPtr, 0, storageBufferSize);
2438 	flushAlloc(vkd, device, storageBufferAlloc);
2439 
2440 	// Acceleration structures.
2441 	de::MovePtr<BottomLevelAccelerationStructure>	bottomLevelAccelerationStructure;
2442 	de::MovePtr<TopLevelAccelerationStructure>		topLevelAccelerationStructure;
2443 
2444 	bottomLevelAccelerationStructure = makeBottomLevelAccelerationStructure();
2445 	bottomLevelAccelerationStructure->setDefaultGeometryData(getShaderStageForGeometry(m_params.interfaceType), VK_GEOMETRY_NO_DUPLICATE_ANY_HIT_INVOCATION_BIT_KHR);
2446 	bottomLevelAccelerationStructure->createAndBuild(vkd, device, cmdBuffer, alloc);
2447 
2448 	topLevelAccelerationStructure = makeTopLevelAccelerationStructure();
2449 	topLevelAccelerationStructure->setInstanceCount(1);
2450 	topLevelAccelerationStructure->addInstance(de::SharedPtr<BottomLevelAccelerationStructure>(bottomLevelAccelerationStructure.release()));
2451 	topLevelAccelerationStructure->createAndBuild(vkd, device, cmdBuffer, alloc);
2452 
2453 	// Get some ray tracing properties.
2454 	deUint32 shaderGroupHandleSize		= 0u;
2455 	deUint32 shaderGroupBaseAlignment	= 1u;
2456 	{
2457 		const auto rayTracingPropertiesKHR	= makeRayTracingProperties(vki, physicalDevice);
2458 		shaderGroupHandleSize				= rayTracingPropertiesKHR->getShaderGroupHandleSize();
2459 		shaderGroupBaseAlignment			= rayTracingPropertiesKHR->getShaderGroupBaseAlignment();
2460 	}
2461 
2462 	// Descriptor set layout.
2463 	DescriptorSetLayoutBuilder dslBuilder;
2464 	dslBuilder.addBinding(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 1u, shaderStages, nullptr);
2465 	dslBuilder.addBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1u, shaderStages, nullptr);	// Callee buffer.
2466 	const auto descriptorSetLayout = dslBuilder.build(vkd, device);
2467 
2468 	// Pipeline layout.
2469 	const auto pipelineLayout = makePipelineLayout(vkd, device, descriptorSetLayout.get());
2470 
2471 	// Descriptor pool and set.
2472 	DescriptorPoolBuilder poolBuilder;
2473 	poolBuilder.addType(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR);
2474 	poolBuilder.addType(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
2475 	const auto descriptorPool	= poolBuilder.build(vkd, device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u);
2476 	const auto descriptorSet	= makeDescriptorSet(vkd, device, descriptorPool.get(), descriptorSetLayout.get());
2477 
2478 	// Update descriptor set.
2479 	{
2480 		const VkWriteDescriptorSetAccelerationStructureKHR writeASInfo =
2481 		{
2482 			VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR,
2483 			nullptr,
2484 			1u,
2485 			topLevelAccelerationStructure.get()->getPtr(),
2486 		};
2487 
2488 		const auto	ds							= descriptorSet.get();
2489 		const auto	storageBufferDescriptorInfo	= makeDescriptorBufferInfo(storageBuffer.get(), 0ull, VK_WHOLE_SIZE);
2490 
2491 		DescriptorSetUpdateBuilder updateBuilder;
2492 		updateBuilder.writeSingle(ds, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, &writeASInfo);
2493 		updateBuilder.writeSingle(ds, DescriptorSetUpdateBuilder::Location::binding(1u), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, &storageBufferDescriptorInfo);
2494 		updateBuilder.update(vkd, device);
2495 	}
2496 
2497 	// Create raytracing pipeline and shader binding tables.
2498 	const auto						interfaceType	= m_params.interfaceType;
2499 	Move<VkPipeline>				pipeline;
2500 
2501 	de::MovePtr<BufferWithMemory>	raygenShaderBindingTable;
2502 	de::MovePtr<BufferWithMemory>	missShaderBindingTable;
2503 	de::MovePtr<BufferWithMemory>	hitShaderBindingTable;
2504 	de::MovePtr<BufferWithMemory>	callableShaderBindingTable;
2505 
2506 	VkStridedDeviceAddressRegionKHR	raygenShaderBindingTableRegion		= makeStridedDeviceAddressRegionKHR(DE_NULL, 0, 0);
2507 	VkStridedDeviceAddressRegionKHR	missShaderBindingTableRegion		= makeStridedDeviceAddressRegionKHR(DE_NULL, 0, 0);
2508 	VkStridedDeviceAddressRegionKHR	hitShaderBindingTableRegion			= makeStridedDeviceAddressRegionKHR(DE_NULL, 0, 0);
2509 	VkStridedDeviceAddressRegionKHR	callableShaderBindingTableRegion	= makeStridedDeviceAddressRegionKHR(DE_NULL, 0, 0);
2510 
2511 	{
2512 		const auto rayTracingPipeline = de::newMovePtr<RayTracingPipeline>();
2513 
2514 		// Every case uses a ray generation shader.
2515 		rayTracingPipeline->addShader(VK_SHADER_STAGE_RAYGEN_BIT_KHR, createShaderModule(vkd, device, m_context.getBinaryCollection().get("rgen"), 0), 0);
2516 
2517 		if (interfaceType == InterfaceType::RAY_PAYLOAD)
2518 		{
2519 			rayTracingPipeline->addShader(VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, createShaderModule(vkd, device, m_context.getBinaryCollection().get("chit"), 0), 1);
2520 		}
2521 		else if (interfaceType == InterfaceType::CALLABLE_DATA || interfaceType == InterfaceType::SHADER_RECORD_BUFFER_RGEN)
2522 		{
2523 			rayTracingPipeline->addShader(VK_SHADER_STAGE_CALLABLE_BIT_KHR, createShaderModule(vkd, device, m_context.getBinaryCollection().get("call"), 0), 1);
2524 		}
2525 		else if (interfaceType == InterfaceType::HIT_ATTRIBUTES)
2526 		{
2527 			rayTracingPipeline->addShader(VK_SHADER_STAGE_INTERSECTION_BIT_KHR, createShaderModule(vkd, device, m_context.getBinaryCollection().get("rint"), 0), 1);
2528 			rayTracingPipeline->addShader(VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, createShaderModule(vkd, device, m_context.getBinaryCollection().get("chit"), 0), 1);
2529 		}
2530 		else if (interfaceType == InterfaceType::SHADER_RECORD_BUFFER_CALL)
2531 		{
2532 			rayTracingPipeline->addShader(VK_SHADER_STAGE_CALLABLE_BIT_KHR, createShaderModule(vkd, device, m_context.getBinaryCollection().get("call"), 0), 1);
2533 			rayTracingPipeline->addShader(VK_SHADER_STAGE_CALLABLE_BIT_KHR, createShaderModule(vkd, device, m_context.getBinaryCollection().get("subcall"), 0), 2);
2534 		}
2535 		else if (interfaceType == InterfaceType::SHADER_RECORD_BUFFER_MISS)
2536 		{
2537 			rayTracingPipeline->addShader(VK_SHADER_STAGE_MISS_BIT_KHR, createShaderModule(vkd, device, m_context.getBinaryCollection().get("miss"), 0), 1);
2538 			rayTracingPipeline->addShader(VK_SHADER_STAGE_CALLABLE_BIT_KHR, createShaderModule(vkd, device, m_context.getBinaryCollection().get("call"), 0), 2);
2539 		}
2540 		else if (interfaceType == InterfaceType::SHADER_RECORD_BUFFER_HIT)
2541 		{
2542 			rayTracingPipeline->addShader(VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, createShaderModule(vkd, device, m_context.getBinaryCollection().get("chit"), 0), 1);
2543 			rayTracingPipeline->addShader(VK_SHADER_STAGE_CALLABLE_BIT_KHR, createShaderModule(vkd, device, m_context.getBinaryCollection().get("call"), 0), 2);
2544 		}
2545 		else
2546 		{
2547 			DE_ASSERT(false);
2548 		}
2549 
2550 		pipeline = rayTracingPipeline->createPipeline(vkd, device, pipelineLayout.get());
2551 
2552 		if (interfaceType == InterfaceType::SHADER_RECORD_BUFFER_RGEN)
2553 		{
2554 			createSBTWithShaderRecord (vkd, device, alloc, pipeline.get(), rayTracingPipeline.get(), shaderGroupHandleSize, shaderGroupBaseAlignment,
2555 									   0u, 1u, raygenShaderBindingTable, raygenShaderBindingTableRegion);
2556 		}
2557 		else
2558 		{
2559 			raygenShaderBindingTable		= rayTracingPipeline->createShaderBindingTable(vkd, device, pipeline.get(), alloc, shaderGroupHandleSize, shaderGroupBaseAlignment, 0, 1);
2560 			raygenShaderBindingTableRegion	= makeStridedDeviceAddressRegionKHR(getBufferDeviceAddress(vkd, device, raygenShaderBindingTable->get(), 0), shaderGroupHandleSize, shaderGroupHandleSize);
2561 		}
2562 
2563 
2564 		if (interfaceType == InterfaceType::CALLABLE_DATA || interfaceType == InterfaceType::SHADER_RECORD_BUFFER_RGEN)
2565 		{
2566 			callableShaderBindingTable			= rayTracingPipeline->createShaderBindingTable(vkd, device, pipeline.get(), alloc, shaderGroupHandleSize, shaderGroupBaseAlignment, 1, 1);
2567 			callableShaderBindingTableRegion	= makeStridedDeviceAddressRegionKHR(getBufferDeviceAddress(vkd, device, callableShaderBindingTable->get(), 0), shaderGroupHandleSize, shaderGroupHandleSize);
2568 		}
2569 		else if (interfaceType == InterfaceType::RAY_PAYLOAD || interfaceType == InterfaceType::HIT_ATTRIBUTES)
2570 		{
2571 			hitShaderBindingTable			= rayTracingPipeline->createShaderBindingTable(vkd, device, pipeline.get(), alloc, shaderGroupHandleSize, shaderGroupBaseAlignment, 1, 1);
2572 			hitShaderBindingTableRegion		= makeStridedDeviceAddressRegionKHR(getBufferDeviceAddress(vkd, device, hitShaderBindingTable->get(), 0), shaderGroupHandleSize, shaderGroupHandleSize);
2573 		}
2574 		else if (interfaceType == InterfaceType::SHADER_RECORD_BUFFER_CALL)
2575 		{
2576 			createSBTWithShaderRecord (vkd, device, alloc, pipeline.get(), rayTracingPipeline.get(), shaderGroupHandleSize, shaderGroupBaseAlignment,
2577 									   1u, 2u, callableShaderBindingTable, callableShaderBindingTableRegion);
2578 		}
2579 		else if (interfaceType == InterfaceType::SHADER_RECORD_BUFFER_MISS)
2580 		{
2581 			createSBTWithShaderRecord (vkd, device, alloc, pipeline.get(), rayTracingPipeline.get(), shaderGroupHandleSize, shaderGroupBaseAlignment,
2582 									   1u, 1u, missShaderBindingTable, missShaderBindingTableRegion);
2583 
2584 			// Callable shader table.
2585 			callableShaderBindingTable			= rayTracingPipeline->createShaderBindingTable(vkd, device, pipeline.get(), alloc, shaderGroupHandleSize, shaderGroupBaseAlignment, 2, 1);
2586 			callableShaderBindingTableRegion	= makeStridedDeviceAddressRegionKHR(getBufferDeviceAddress(vkd, device, callableShaderBindingTable->get(), 0), shaderGroupHandleSize, shaderGroupHandleSize);
2587 		}
2588 		else if (interfaceType == InterfaceType::SHADER_RECORD_BUFFER_HIT)
2589 		{
2590 			createSBTWithShaderRecord (vkd, device, alloc, pipeline.get(), rayTracingPipeline.get(), shaderGroupHandleSize, shaderGroupBaseAlignment,
2591 									   1u, 1u, hitShaderBindingTable, hitShaderBindingTableRegion);
2592 
2593 			// Callable shader table.
2594 			callableShaderBindingTable			= rayTracingPipeline->createShaderBindingTable(vkd, device, pipeline.get(), alloc, shaderGroupHandleSize, shaderGroupBaseAlignment, 2, 1);
2595 			callableShaderBindingTableRegion	= makeStridedDeviceAddressRegionKHR(getBufferDeviceAddress(vkd, device, callableShaderBindingTable->get(), 0), shaderGroupHandleSize, shaderGroupHandleSize);
2596 		}
2597 		else
2598 		{
2599 			DE_ASSERT(false);
2600 		}
2601 	}
2602 
2603 	// Use ray tracing pipeline.
2604 	vkd.cmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, pipeline.get());
2605 	vkd.cmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, pipelineLayout.get(), 0u, 1u, &descriptorSet.get(), 0u, nullptr);
2606 	vkd.cmdTraceRaysKHR(cmdBuffer, &raygenShaderBindingTableRegion, &missShaderBindingTableRegion, &hitShaderBindingTableRegion, &callableShaderBindingTableRegion, 1u, 1u, 1u);
2607 
2608 	// Synchronize output and callee buffers.
2609 	const auto memBarrier = makeMemoryBarrier(VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT);
2610 	vkd.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR, VK_PIPELINE_STAGE_HOST_BIT, 0u, 1u, &memBarrier, 0u, nullptr, 0u, nullptr);
2611 
2612 	endCommandBuffer(vkd, cmdBuffer);
2613 	submitCommandsAndWait(vkd, device, queue, cmdBuffer);
2614 
2615 	// Verify storage buffer.
2616 	invalidateAlloc(vkd, device, storageBufferAlloc);
2617 	deMemcpy(storageBufferData.data(), storageBufferPtr, storageBufferSize);
2618 
2619 	// These values must match what the shaders store.
2620 	std::vector<deUint32> expectedData;
2621 	if (interfaceType == InterfaceType::RAY_PAYLOAD)
2622 	{
2623 		expectedData.push_back(103u);
2624 		expectedData.push_back(100u);
2625 	}
2626 	else if (interfaceType == InterfaceType::CALLABLE_DATA)
2627 	{
2628 		expectedData.push_back(200u);
2629 		expectedData.push_back(100u);
2630 	}
2631 	else if (interfaceType == InterfaceType::HIT_ATTRIBUTES)
2632 	{
2633 		expectedData.push_back(300u);
2634 		expectedData.push_back(315u);
2635 		expectedData.push_back(330u);
2636 	}
2637 	else if (interfaceType == InterfaceType::SHADER_RECORD_BUFFER_RGEN)
2638 	{
2639 		expectedData.push_back(402u);
2640 		expectedData.push_back(450u);
2641 	}
2642 	else if (interfaceType == InterfaceType::SHADER_RECORD_BUFFER_CALL)
2643 	{
2644 		expectedData.push_back(806u);
2645 		expectedData.push_back(403u);
2646 		expectedData.push_back(450u);
2647 	}
2648 	else if (interfaceType == InterfaceType::SHADER_RECORD_BUFFER_MISS || interfaceType == InterfaceType::SHADER_RECORD_BUFFER_HIT)
2649 	{
2650 		expectedData.push_back(1200u);
2651 		expectedData.push_back( 400u);
2652 		expectedData.push_back( 490u);
2653 	}
2654 	else
2655 	{
2656 		DE_ASSERT(false);
2657 	}
2658 
2659 	size_t pos;
2660 	for (pos = 0u; pos < expectedData.size(); ++pos)
2661 	{
2662 		const auto& stored		= storageBufferData.at(pos);
2663 		const auto& expected	= expectedData.at(pos);
2664 		if (stored != expected)
2665 		{
2666 			std::ostringstream msg;
2667 			msg << "Unexpected output value found at position " << pos << " (expected " << expected << " but got " << stored << ")";
2668 			return tcu::TestStatus::fail(msg.str());
2669 		}
2670 	}
2671 
2672 	// Expect zeros in unused positions, as filled on the host.
2673 	for (; pos < storageBufferData.size(); ++pos)
2674 	{
2675 		const auto& stored = storageBufferData.at(pos);
2676 		if (stored != 0u)
2677 		{
2678 			std::ostringstream msg;
2679 			msg << "Unexpected output value found at position " << pos << " (expected 0 but got " << stored << ")";
2680 			return tcu::TestStatus::fail(msg.str());
2681 		}
2682 	}
2683 
2684 	return tcu::TestStatus::pass("Pass");
2685 }
2686 
2687 } // anonymous namespace
2688 
createDataSpillTests(tcu::TestContext& testCtx)2689 tcu::TestCaseGroup*	createDataSpillTests(tcu::TestContext& testCtx)
2690 {
2691 	// Ray tracing tests for data spilling and unspilling around shader calls
2692 	de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "data_spill"));
2693 
2694 	struct
2695 	{
2696 		CallType callType;
2697 		const char* name;
2698 	} callTypes[] =
2699 	{
2700 		{ CallType::EXECUTE_CALLABLE,		"execute_callable"		},
2701 		{ CallType::TRACE_RAY,				"trace_ray"				},
2702 		{ CallType::REPORT_INTERSECTION,	"report_intersection"	},
2703 	};
2704 
2705 	struct
2706 	{
2707 		DataType dataType;
2708 		const char* name;
2709 	} dataTypes[] =
2710 	{
2711 		{ DataType::INT32,				"int32"			},
2712 		{ DataType::UINT32,				"uint32"		},
2713 		{ DataType::INT64,				"int64"			},
2714 		{ DataType::UINT64,				"uint64"		},
2715 		{ DataType::INT16,				"int16"			},
2716 		{ DataType::UINT16,				"uint16"		},
2717 		{ DataType::INT8,				"int8"			},
2718 		{ DataType::UINT8,				"uint8"			},
2719 		{ DataType::FLOAT32,			"float32"		},
2720 		{ DataType::FLOAT64,			"float64"		},
2721 		{ DataType::FLOAT16,			"float16"		},
2722 		{ DataType::STRUCT,				"struct"		},
2723 		{ DataType::SAMPLER,			"sampler"		},
2724 		{ DataType::IMAGE,				"image"			},
2725 		{ DataType::SAMPLED_IMAGE,		"combined"		},
2726 		{ DataType::PTR_IMAGE,			"ptr_image"		},
2727 		{ DataType::PTR_SAMPLER,		"ptr_sampler"	},
2728 		{ DataType::PTR_SAMPLED_IMAGE,	"ptr_combined"	},
2729 		{ DataType::PTR_TEXEL,			"ptr_texel"		},
2730 		{ DataType::OP_NULL,			"op_null"		},
2731 		{ DataType::OP_UNDEF,			"op_undef"		},
2732 	};
2733 
2734 	struct
2735 	{
2736 		VectorType vectorType;
2737 		const char* prefix;
2738 	} vectorTypes[] =
2739 	{
2740 		{ VectorType::SCALAR,	""		},
2741 		{ VectorType::V2,		"v2"	},
2742 		{ VectorType::V3,		"v3"	},
2743 		{ VectorType::V4,		"v4"	},
2744 		{ VectorType::A5,		"a5"	},
2745 	};
2746 
2747 	for (int callTypeIdx = 0; callTypeIdx < DE_LENGTH_OF_ARRAY(callTypes); ++callTypeIdx)
2748 	{
2749 		const auto& entryCallTypes = callTypes[callTypeIdx];
2750 
2751 		de::MovePtr<tcu::TestCaseGroup> callTypeGroup(new tcu::TestCaseGroup(testCtx, entryCallTypes.name));
2752 		for (int dataTypeIdx = 0; dataTypeIdx < DE_LENGTH_OF_ARRAY(dataTypes); ++dataTypeIdx)
2753 		{
2754 			const auto& entryDataTypes = dataTypes[dataTypeIdx];
2755 
2756 			for (int vectorTypeIdx = 0; vectorTypeIdx < DE_LENGTH_OF_ARRAY(vectorTypes); ++vectorTypeIdx)
2757 			{
2758 				const auto& entryVectorTypes = vectorTypes[vectorTypeIdx];
2759 
2760 				if ((samplersNeeded(entryDataTypes.dataType)
2761 					 || storageImageNeeded(entryDataTypes.dataType)
2762 					 || entryDataTypes.dataType == DataType::STRUCT
2763 					 || entryDataTypes.dataType == DataType::OP_NULL
2764 					 || entryDataTypes.dataType == DataType::OP_UNDEF)
2765 					&& entryVectorTypes.vectorType != VectorType::SCALAR)
2766 				{
2767 					continue;
2768 				}
2769 
2770 				DataSpillTestCase::TestParams params;
2771 				params.callType		= entryCallTypes.callType;
2772 				params.dataType		= entryDataTypes.dataType;
2773 				params.vectorType	= entryVectorTypes.vectorType;
2774 
2775 				const auto testName = std::string(entryVectorTypes.prefix) + entryDataTypes.name;
2776 
2777 				callTypeGroup->addChild(new DataSpillTestCase(testCtx, testName, params));
2778 			}
2779 		}
2780 
2781 		group->addChild(callTypeGroup.release());
2782 	}
2783 
2784 	// Pipeline interface tests.
2785 	de::MovePtr<tcu::TestCaseGroup> pipelineInterfaceGroup(new tcu::TestCaseGroup(testCtx, "pipeline_interface", "Test data spilling and unspilling of pipeline interface variables"));
2786 
2787 	struct
2788 	{
2789 		InterfaceType	interfaceType;
2790 		const char*		name;
2791 	} interfaceTypes[] =
2792 	{
2793 		{ InterfaceType::RAY_PAYLOAD,				"ray_payload"				},
2794 		{ InterfaceType::CALLABLE_DATA,				"callable_data"				},
2795 		{ InterfaceType::HIT_ATTRIBUTES,			"hit_attributes"			},
2796 		{ InterfaceType::SHADER_RECORD_BUFFER_RGEN,	"shader_record_buffer_rgen"	},
2797 		{ InterfaceType::SHADER_RECORD_BUFFER_CALL,	"shader_record_buffer_call"	},
2798 		{ InterfaceType::SHADER_RECORD_BUFFER_MISS,	"shader_record_buffer_miss"	},
2799 		{ InterfaceType::SHADER_RECORD_BUFFER_HIT,	"shader_record_buffer_hit"	},
2800 	};
2801 
2802 	for (int idx = 0; idx < DE_LENGTH_OF_ARRAY(interfaceTypes); ++idx)
2803 	{
2804 		const auto&										entry	= interfaceTypes[idx];
2805 		DataSpillPipelineInterfaceTestCase::TestParams	params;
2806 
2807 		params.interfaceType = entry.interfaceType;
2808 
2809 		pipelineInterfaceGroup->addChild(new DataSpillPipelineInterfaceTestCase(testCtx, entry.name, params));
2810 	}
2811 
2812 	group->addChild(pipelineInterfaceGroup.release());
2813 
2814 	return group.release();
2815 }
2816 
2817 } // RayTracing
2818 } // vkt
2819 
2820