• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2017 Google Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Utilities for Vulkan SPIR-V assembly tests
22  *//*--------------------------------------------------------------------*/
23 
24 #include "vktSpvAsmUtils.hpp"
25 
26 #include "deMemory.h"
27 #include "deSTLUtil.hpp"
28 #include "vkQueryUtil.hpp"
29 #include "vkRefUtil.hpp"
30 #include "vkPlatform.hpp"
31 
32 #include <limits>
33 
34 namespace vkt
35 {
36 namespace SpirVAssembly
37 {
38 
39 using namespace vk;
40 
toString() const41 std::string VariableLocation::toString() const
42 {
43 	return "set_" + de::toString(set) + "_binding_" + de::toString(binding);
44 }
45 
toDescription() const46 std::string VariableLocation::toDescription() const
47 {
48 	return "Set " + de::toString(set) + " and Binding " + de::toString(binding);
49 }
50 
51 #define IS_CORE_FEATURE_AVAILABLE(CHECKED, AVAILABLE, FEATURE)	\
52 	if ((CHECKED.FEATURE != DE_FALSE) && (AVAILABLE.FEATURE == DE_FALSE)) { *missingFeature = #FEATURE; return false; }
53 
isCoreFeaturesSupported(const Context & context,const vk::VkPhysicalDeviceFeatures & toCheck,const char ** missingFeature)54 bool isCoreFeaturesSupported (const Context&						context,
55 							  const vk::VkPhysicalDeviceFeatures&	toCheck,
56 							  const char**							missingFeature)
57 {
58 	const VkPhysicalDeviceFeatures&	availableFeatures	= context.getDeviceFeatures();
59 
60 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, robustBufferAccess)
61 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, fullDrawIndexUint32)
62 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, imageCubeArray)
63 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, independentBlend)
64 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, geometryShader)
65 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, tessellationShader)
66 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, sampleRateShading)
67 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, dualSrcBlend)
68 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, logicOp)
69 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, multiDrawIndirect)
70 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, drawIndirectFirstInstance)
71 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, depthClamp)
72 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, depthBiasClamp)
73 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, fillModeNonSolid)
74 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, depthBounds)
75 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, wideLines)
76 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, largePoints)
77 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, alphaToOne)
78 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, multiViewport)
79 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, samplerAnisotropy)
80 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, textureCompressionETC2)
81 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, textureCompressionASTC_LDR)
82 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, textureCompressionBC)
83 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, occlusionQueryPrecise)
84 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, pipelineStatisticsQuery)
85 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, vertexPipelineStoresAndAtomics)
86 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, fragmentStoresAndAtomics)
87 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderTessellationAndGeometryPointSize)
88 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderImageGatherExtended)
89 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderStorageImageExtendedFormats)
90 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderStorageImageMultisample)
91 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderStorageImageReadWithoutFormat)
92 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderStorageImageWriteWithoutFormat)
93 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderUniformBufferArrayDynamicIndexing)
94 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderSampledImageArrayDynamicIndexing)
95 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderStorageBufferArrayDynamicIndexing)
96 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderStorageImageArrayDynamicIndexing)
97 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderClipDistance)
98 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderCullDistance)
99 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderFloat64)
100 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderInt64)
101 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderInt16)
102 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderResourceResidency)
103 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, shaderResourceMinLod)
104 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, sparseBinding)
105 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, sparseResidencyBuffer)
106 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, sparseResidencyImage2D)
107 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, sparseResidencyImage3D)
108 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, sparseResidency2Samples)
109 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, sparseResidency4Samples)
110 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, sparseResidency8Samples)
111 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, sparseResidency16Samples)
112 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, sparseResidencyAliased)
113 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, variableMultisampleRate)
114 	IS_CORE_FEATURE_AVAILABLE(toCheck, availableFeatures, inheritedQueries)
115 
116 	return true;
117 }
118 
119 #define IS_AVAIL(EXT_NAME, FEATURE)	\
120 	if (toCheck.FEATURE && !extensionFeatures.FEATURE) { *missingFeature = EXT_NAME #FEATURE; return false; }
121 
isFloat16Int8FeaturesSupported(const Context & context,const vk::VkPhysicalDeviceShaderFloat16Int8Features & toCheck,const char ** missingFeature)122 bool isFloat16Int8FeaturesSupported(const Context& context, const vk::VkPhysicalDeviceShaderFloat16Int8Features& toCheck, const char **missingFeature)
123 {
124 	const VkPhysicalDeviceShaderFloat16Int8Features& extensionFeatures = context.getShaderFloat16Int8Features();
125 
126 	IS_AVAIL("ShaderFloat16Int8.", shaderFloat16);
127 	IS_AVAIL("ShaderFloat16Int8.", shaderInt8);
128 
129 	return true;
130 }
131 
is8BitStorageFeaturesSupported(const Context & context,const vk::VkPhysicalDevice8BitStorageFeatures & toCheck,const char ** missingFeature)132 bool is8BitStorageFeaturesSupported(const Context& context, const vk::VkPhysicalDevice8BitStorageFeatures& toCheck, const char **missingFeature)
133 {
134 	const VkPhysicalDevice8BitStorageFeaturesKHR& extensionFeatures = context.get8BitStorageFeatures();
135 
136 	IS_AVAIL("8BitStorage.", storageBuffer8BitAccess);
137 	IS_AVAIL("8BitStorage.", uniformAndStorageBuffer8BitAccess);
138 	IS_AVAIL("8BitStorage.", storagePushConstant8);
139 
140 	return true;
141 }
142 
is16BitStorageFeaturesSupported(const Context & context,const vk::VkPhysicalDevice16BitStorageFeatures & toCheck,const char ** missingFeature)143 bool is16BitStorageFeaturesSupported(const Context& context, const vk::VkPhysicalDevice16BitStorageFeatures& toCheck, const char **missingFeature)
144 {
145 	const VkPhysicalDevice16BitStorageFeatures& extensionFeatures = context.get16BitStorageFeatures();
146 
147 	IS_AVAIL("16BitStorage.", storageBuffer16BitAccess);
148 	IS_AVAIL("16BitStorage.", uniformAndStorageBuffer16BitAccess);
149 	IS_AVAIL("16BitStorage.", storagePushConstant16);
150 	IS_AVAIL("16BitStorage.", storageInputOutput16);
151 
152 	return true;
153 }
154 
isVariablePointersFeaturesSupported(const Context & context,const vk::VkPhysicalDeviceVariablePointersFeatures & toCheck,const char ** missingFeature)155 bool isVariablePointersFeaturesSupported(const Context& context, const vk::VkPhysicalDeviceVariablePointersFeatures& toCheck, const char **missingFeature)
156 {
157 	const VkPhysicalDeviceVariablePointersFeatures& extensionFeatures = context.getVariablePointersFeatures();
158 
159 	IS_AVAIL("VariablePointers.", variablePointersStorageBuffer);
160 	IS_AVAIL("VariablePointers.", variablePointers);
161 
162 	return true;
163 }
164 
isVulkanMemoryModelFeaturesSupported(const Context & context,const vk::VkPhysicalDeviceVulkanMemoryModelFeatures & toCheck,const char ** missingFeature)165 bool isVulkanMemoryModelFeaturesSupported(const Context& context, const vk::VkPhysicalDeviceVulkanMemoryModelFeatures& toCheck, const char **missingFeature)
166 {
167 	const VkPhysicalDeviceVulkanMemoryModelFeaturesKHR& extensionFeatures = context.getVulkanMemoryModelFeatures();
168 
169 	IS_AVAIL("VulkanMemoryModel.", vulkanMemoryModel);
170 	IS_AVAIL("VulkanMemoryModel.", vulkanMemoryModelDeviceScope);
171 	IS_AVAIL("VulkanMemoryModel.", vulkanMemoryModelAvailabilityVisibilityChains);
172 
173 	return true;
174 }
175 
isIntegerDotProductFeaturesSupported(const Context & context,const vk::VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR & toCheck,const char ** missingFeature)176 bool isIntegerDotProductFeaturesSupported(const Context& context, const vk::VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR& toCheck, const char **missingFeature)
177 {
178 	const VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR& extensionFeatures = context.getShaderIntegerDotProductFeatures();
179 
180 	IS_AVAIL("ShaderIntegerDotProduct.", shaderIntegerDotProduct);
181 
182 	return true;
183 }
184 
185 #undef IS_AVAIL
186 
isFloatControlsFeaturesSupported(const Context & context,const vk::VkPhysicalDeviceFloatControlsProperties & toCheck,const char ** missingFeature)187 bool isFloatControlsFeaturesSupported (const Context& context, const vk::VkPhysicalDeviceFloatControlsProperties& toCheck, const char **missingFeature)
188 {
189 	// if all flags are set to false then no float control features are actualy requested by the test
190 	if ((toCheck.shaderSignedZeroInfNanPreserveFloat16 ||
191 		 toCheck.shaderSignedZeroInfNanPreserveFloat32 ||
192 		 toCheck.shaderSignedZeroInfNanPreserveFloat64 ||
193 		 toCheck.shaderDenormPreserveFloat16 ||
194 		 toCheck.shaderDenormPreserveFloat32 ||
195 		 toCheck.shaderDenormPreserveFloat64 ||
196 		 toCheck.shaderDenormFlushToZeroFloat16 ||
197 		 toCheck.shaderDenormFlushToZeroFloat32 ||
198 		 toCheck.shaderDenormFlushToZeroFloat64 ||
199 		 toCheck.shaderRoundingModeRTEFloat16 ||
200 		 toCheck.shaderRoundingModeRTEFloat32 ||
201 		 toCheck.shaderRoundingModeRTEFloat64 ||
202 		 toCheck.shaderRoundingModeRTZFloat16 ||
203 		 toCheck.shaderRoundingModeRTZFloat32 ||
204 		 toCheck.shaderRoundingModeRTZFloat64) == false)
205 		return true;
206 
207 	*missingFeature = "Float controls properties";
208 
209 	// return false when float control features are requested and proper extension is not supported
210 	if (!context.isDeviceFunctionalitySupported("VK_KHR_shader_float_controls"))
211 		return false;
212 
213 	// perform query to get supported float control properties
214    vk::VkPhysicalDeviceFloatControlsProperties refControls;
215 	{
216 		refControls.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES_KHR;
217 		refControls.pNext = DE_NULL;
218 
219 		VkPhysicalDeviceProperties2 deviceProperties;
220 		deviceProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
221 		deviceProperties.pNext = &refControls;
222 
223 		const VkPhysicalDevice			physicalDevice		= context.getPhysicalDevice();
224 		const vk::InstanceInterface&	instanceInterface	= context.getInstanceInterface();
225 
226 		instanceInterface.getPhysicalDeviceProperties2(physicalDevice, &deviceProperties);
227 	}
228 
229 	using FCIndependence = VkShaderFloatControlsIndependence;
230 	FCIndependence fcInd32		= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY_KHR;
231 	FCIndependence fcIndAll		= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL_KHR;
232 	FCIndependence fcIndNone	= VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE_KHR;
233 
234 	bool requiredDenormBehaviorNotSupported =
235 		((toCheck.denormBehaviorIndependence == fcIndAll) && (refControls.denormBehaviorIndependence != fcIndAll)) ||
236 		((toCheck.denormBehaviorIndependence == fcInd32)  && (refControls.denormBehaviorIndependence == fcIndNone));
237 
238 	bool requiredRoundingModeNotSupported =
239 		((toCheck.roundingModeIndependence == fcIndAll) && (refControls.roundingModeIndependence != fcIndAll)) ||
240 		((toCheck.roundingModeIndependence == fcInd32)  && (refControls.roundingModeIndependence == fcIndNone));
241 
242 	// check if flags needed by the test are not supported by the device
243 	bool requiredFeaturesNotSupported =
244 		requiredDenormBehaviorNotSupported ||
245 		requiredRoundingModeNotSupported ||
246 		(toCheck.shaderDenormFlushToZeroFloat16			&& !refControls.shaderDenormFlushToZeroFloat16) ||
247 		(toCheck.shaderDenormPreserveFloat16			&& !refControls.shaderDenormPreserveFloat16) ||
248 		(toCheck.shaderRoundingModeRTEFloat16			&& !refControls.shaderRoundingModeRTEFloat16) ||
249 		(toCheck.shaderRoundingModeRTZFloat16			&& !refControls.shaderRoundingModeRTZFloat16) ||
250 		(toCheck.shaderSignedZeroInfNanPreserveFloat16	&& !refControls.shaderSignedZeroInfNanPreserveFloat16) ||
251 		(toCheck.shaderDenormFlushToZeroFloat32			&& !refControls.shaderDenormFlushToZeroFloat32) ||
252 		(toCheck.shaderDenormPreserveFloat32			&& !refControls.shaderDenormPreserveFloat32) ||
253 		(toCheck.shaderRoundingModeRTEFloat32			&& !refControls.shaderRoundingModeRTEFloat32) ||
254 		(toCheck.shaderRoundingModeRTZFloat32			&& !refControls.shaderRoundingModeRTZFloat32) ||
255 		(toCheck.shaderSignedZeroInfNanPreserveFloat32	&& !refControls.shaderSignedZeroInfNanPreserveFloat32) ||
256 		(toCheck.shaderDenormFlushToZeroFloat64			&& !refControls.shaderDenormFlushToZeroFloat64) ||
257 		(toCheck.shaderDenormPreserveFloat64			&& !refControls.shaderDenormPreserveFloat64) ||
258 		(toCheck.shaderRoundingModeRTEFloat64			&& !refControls.shaderRoundingModeRTEFloat64) ||
259 		(toCheck.shaderRoundingModeRTZFloat64			&& !refControls.shaderRoundingModeRTZFloat64) ||
260 		(toCheck.shaderSignedZeroInfNanPreserveFloat64	&& !refControls.shaderSignedZeroInfNanPreserveFloat64);
261 
262 	// we checked if required features are not supported - we need to
263 	// negate the result to know if all required features are available
264 	return !requiredFeaturesNotSupported;
265 }
266 
isVulkanFeaturesSupported(const Context & context,const VulkanFeatures & requested,const char ** missingFeature)267 bool isVulkanFeaturesSupported(const Context& context, const VulkanFeatures& requested, const char **missingFeature)
268 {
269 	if (!isCoreFeaturesSupported(context, requested.coreFeatures, missingFeature))
270 		return false;
271 
272 	if (!is8BitStorageFeaturesSupported(context, requested.ext8BitStorage, missingFeature))
273 		return false;
274 
275 	if (!is16BitStorageFeaturesSupported(context, requested.ext16BitStorage, missingFeature))
276 		return false;
277 
278 	if (!isVariablePointersFeaturesSupported(context, requested.extVariablePointers, missingFeature))
279 		return false;
280 
281 	if (!isFloat16Int8FeaturesSupported(context, requested.extFloat16Int8, missingFeature))
282 		return false;
283 
284 	if (!isVulkanMemoryModelFeaturesSupported(context, requested.extVulkanMemoryModel, missingFeature))
285 		return false;
286 
287 	if (!isFloatControlsFeaturesSupported(context, requested.floatControlsProperties, missingFeature))
288 		return false;
289 
290 	if (!isIntegerDotProductFeaturesSupported(context, requested.extIntegerDotProduct, missingFeature))
291 		return false;
292 
293 	return true;
294 }
295 
getMinRequiredVulkanVersion(const SpirvVersion version)296 deUint32 getMinRequiredVulkanVersion (const SpirvVersion version)
297 {
298 	switch(version)
299 	{
300 	case SPIRV_VERSION_1_0:
301 		return VK_API_VERSION_1_0;
302 	case SPIRV_VERSION_1_1:
303 	case SPIRV_VERSION_1_2:
304 	case SPIRV_VERSION_1_3:
305 	case SPIRV_VERSION_1_4:
306 		return VK_API_VERSION_1_1;
307 	case SPIRV_VERSION_1_5:
308 		return VK_API_VERSION_1_2;
309 	default:
310 		DE_ASSERT(0);
311 	}
312 	return 0u;
313 }
314 
getVulkanName(const deUint32 version)315 std::string	getVulkanName (const deUint32 version)
316 {
317 	return std::string(version == VK_API_VERSION_1_1 ? "1.1" : "1.0");
318 }
319 
320 // Generate and return 64-bit integers.
321 //
322 // Expected count to be at least 16.
getInt64s(de::Random & rnd,const deUint32 count)323 std::vector<deInt64> getInt64s (de::Random& rnd, const deUint32 count)
324 {
325 	std::vector<deInt64> data;
326 
327 	data.reserve(count);
328 
329 	// Make sure we have boundary numbers.
330 	data.push_back(deInt64(0x0000000000000000));  // 0
331 	data.push_back(deInt64(0x0000000000000001));  // 1
332 	data.push_back(deInt64(0x000000000000002a));  // 42
333 	data.push_back(deInt64(0x000000007fffffff));  // 2147483647
334 	data.push_back(deInt64(0x0000000080000000));  // 2147483648
335 	data.push_back(deInt64(0x00000000ffffffff));  // 4294967295
336 	data.push_back(deInt64(0x0000000100000000));  // 4294967296
337 	data.push_back(deInt64(0x7fffffffffffffff));  // 9223372036854775807
338 	data.push_back(deInt64(0x8000000000000000));  // -9223372036854775808
339 	data.push_back(deInt64(0x8000000000000001));  // -9223372036854775807
340 	data.push_back(deInt64(0xffffffff00000000));  // -4294967296
341 	data.push_back(deInt64(0xffffffff00000001));  // -4294967295
342 	data.push_back(deInt64(0xffffffff80000000));  // -2147483648
343 	data.push_back(deInt64(0xffffffff80000001));  // -2147483647
344 	data.push_back(deInt64(0xffffffffffffffd6));  // -42
345 	data.push_back(deInt64(0xffffffffffffffff));  // -1
346 
347 	DE_ASSERT(count >= data.size());
348 
349 	for (deUint32 numNdx = static_cast<deUint32>(data.size()); numNdx < count; ++numNdx)
350 		data.push_back(static_cast<deInt64>(rnd.getUint64()));
351 
352 	return data;
353 }
354 
355 // Generate and return 32-bit integers.
356 //
357 // Expected count to be at least 16.
getInt32s(de::Random & rnd,const deUint32 count)358 std::vector<deInt32> getInt32s (de::Random& rnd, const deUint32 count)
359 {
360 	std::vector<deInt32> data;
361 
362 	data.reserve(count);
363 
364 	// Make sure we have boundary numbers.
365 	data.push_back(deInt32(0x00000000));  // 0
366 	data.push_back(deInt32(0x00000001));  // 1
367 	data.push_back(deInt32(0x0000002a));  // 42
368 	data.push_back(deInt32(0x00007fff));  // 32767
369 	data.push_back(deInt32(0x00008000));  // 32768
370 	data.push_back(deInt32(0x0000ffff));  // 65535
371 	data.push_back(deInt32(0x00010000));  // 65536
372 	data.push_back(deInt32(0x7fffffff));  // 2147483647
373 	data.push_back(deInt32(0x80000000));  // -2147483648
374 	data.push_back(deInt32(0x80000001));  // -2147483647
375 	data.push_back(deInt32(0xffff0000));  // -65536
376 	data.push_back(deInt32(0xffff0001));  // -65535
377 	data.push_back(deInt32(0xffff8000));  // -32768
378 	data.push_back(deInt32(0xffff8001));  // -32767
379 	data.push_back(deInt32(0xffffffd6));  // -42
380 	data.push_back(deInt32(0xffffffff));  // -1
381 
382 	DE_ASSERT(count >= data.size());
383 
384 	for (deUint32 numNdx = static_cast<deUint32>(data.size()); numNdx < count; ++numNdx)
385 		data.push_back(static_cast<deInt32>(rnd.getUint32()));
386 
387 	return data;
388 }
389 
390 // Generate and return 16-bit integers.
391 //
392 // Expected count to be at least 8.
getInt16s(de::Random & rnd,const deUint32 count)393 std::vector<deInt16> getInt16s (de::Random& rnd, const deUint32 count)
394 {
395 	std::vector<deInt16> data;
396 
397 	data.reserve(count);
398 
399 	// Make sure we have boundary numbers.
400 	data.push_back(deInt16(0x0000));  // 0
401 	data.push_back(deInt16(0x0001));  // 1
402 	data.push_back(deInt16(0x002a));  // 42
403 	data.push_back(deInt16(0x7fff));  // 32767
404 	data.push_back(deInt16(0x8000));  // -32868
405 	data.push_back(deInt16(0x8001));  // -32767
406 	data.push_back(deInt16(0xffd6));  // -42
407 	data.push_back(deInt16(0xffff));  // -1
408 
409 	DE_ASSERT(count >= data.size());
410 
411 	for (deUint32 numNdx = static_cast<deUint32>(data.size()); numNdx < count; ++numNdx)
412 		data.push_back(static_cast<deInt16>(rnd.getUint16()));
413 
414 	return data;
415 }
416 
417 // Generate and return 8-bit integers.
418 //
419 // Expected count to be at least 8.
getInt8s(de::Random & rnd,const deUint32 count)420 std::vector<deInt8> getInt8s (de::Random& rnd, const deUint32 count)
421 {
422 	std::vector<deInt8> data;
423 
424 	data.reserve(count);
425 
426 	// Make sure we have boundary numbers.
427 	data.push_back(deInt8(0x00));  // 0
428 	data.push_back(deInt8(0x01));  // 1
429 	data.push_back(deInt8(0x2a));  // 42
430 	data.push_back(deInt8(0x7f));  // 127
431 	data.push_back(deInt8(0x80));  // -128
432 	data.push_back(deInt8(0x81));  // -127
433 	data.push_back(deInt8(0xd6));  // -42
434 	data.push_back(deInt8(0xff));  // -1
435 
436 	DE_ASSERT(count >= data.size());
437 
438 	for (deUint32 numNdx = static_cast<deUint32>(data.size()); numNdx < count; ++numNdx)
439 		data.push_back(static_cast<deInt8>(rnd.getUint8()));
440 
441 	return data;
442 }
443 
444 // IEEE-754 floating point numbers:
445 // +--------+------+----------+-------------+
446 // | binary | sign | exponent | significand |
447 // +--------+------+----------+-------------+
448 // | 64-bit |  1   |    11    |     52      |
449 // +--------+------+----------+-------------+
450 // | 32-bit |  1   |    8     |     23      |
451 // +--------+------+----------+-------------+
452 // | 16-bit |  1   |    5     |     10      |
453 // +--------+------+----------+-------------+
454 //
455 // 64-bit floats:
456 //
457 // (0x3FD2000000000000: 0.28125: with exact match in 16-bit normalized)
458 // (0x3F10060000000000: exact half way within two 16-bit normalized; round to zero: 0x0401)
459 // (0xBF10060000000000: exact half way within two 16-bit normalized; round to zero: 0x8402)
460 // (0x3F100C0000000000: not exact half way within two 16-bit normalized; round to zero: 0x0403)
461 // (0xBF100C0000000000: not exact half way within two 16-bit normalized; round to zero: 0x8404)
462 
463 // Generate and return 64-bit floats
464 //
465 // The first 24 number pairs are manually picked, while the rest are randomly generated.
466 // Expected count to be at least 24 (numPicks).
getFloat64s(de::Random & rnd,deUint32 count)467 std::vector<double> getFloat64s (de::Random& rnd, deUint32 count)
468 {
469 	std::vector<double> float64;
470 
471 	float64.reserve(count);
472 
473 	if (count >= 24)
474 	{
475 		// Zero
476 		float64.push_back(0.f);
477 		float64.push_back(-0.f);
478 		// Infinity
479 		float64.push_back(std::numeric_limits<double>::infinity());
480 		float64.push_back(-std::numeric_limits<double>::infinity());
481 		// SNaN
482 		float64.push_back(std::numeric_limits<double>::signaling_NaN());
483 		float64.push_back(-std::numeric_limits<double>::signaling_NaN());
484 		// QNaN
485 		float64.push_back(std::numeric_limits<double>::quiet_NaN());
486 		float64.push_back(-std::numeric_limits<double>::quiet_NaN());
487 
488 		// Denormalized 64-bit float matching 0 in 16-bit
489 		float64.push_back(ldexp((double)1.f, -1023));
490 		float64.push_back(-ldexp((double)1.f, -1023));
491 
492 		// Normalized 64-bit float matching 0 in 16-bit
493 		float64.push_back(ldexp((double)1.f, -100));
494 		float64.push_back(-ldexp((double)1.f, -100));
495 		// Normalized 64-bit float with exact denormalized match in 16-bit
496 		float64.push_back(bitwiseCast<double>(deUint64(0x3B0357C299A88EA8)));
497 		float64.push_back(bitwiseCast<double>(deUint64(0xBB0357C299A88EA8)));
498 
499 		// Normalized 64-bit float with exact normalized match in 16-bit
500 		float64.push_back(ldexp((double)1.f, -14));  // 2e-14: minimum 16-bit positive normalized
501 		float64.push_back(-ldexp((double)1.f, -14)); // 2e-14: maximum 16-bit negative normalized
502 		// Normalized 64-bit float falling above half way within two 16-bit normalized
503 		float64.push_back(bitwiseCast<double>(deUint64(0x3FD2000000000000)));
504 		float64.push_back(bitwiseCast<double>(deUint64(0xBFD2000000000000)));
505 		// Normalized 64-bit float falling exact half way within two 16-bit normalized
506 		float64.push_back(bitwiseCast<double>(deUint64(0x3F100C0000000000)));
507 		float64.push_back(bitwiseCast<double>(deUint64(0xBF100C0000000000)));
508 		// Some number
509 		float64.push_back((double)0.28125f);
510 		float64.push_back((double)-0.28125f);
511 		// Normalized 64-bit float matching infinity in 16-bit
512 		float64.push_back(ldexp((double)1.f, 100));
513 		float64.push_back(-ldexp((double)1.f, 100));
514 	}
515 
516 	const deUint32		numPicks	= static_cast<deUint32>(float64.size());
517 
518 	DE_ASSERT(count >= numPicks);
519 	count -= numPicks;
520 
521 	for (deUint32 numNdx = 0; numNdx < count; ++numNdx)
522 	{
523 		double randValue = rnd.getDouble();
524 		float64.push_back(randValue);
525 	}
526 
527 	return float64;
528 }
529 
530 // IEEE-754 floating point numbers:
531 // +--------+------+----------+-------------+
532 // | binary | sign | exponent | significand |
533 // +--------+------+----------+-------------+
534 // | 16-bit |  1   |    5     |     10      |
535 // +--------+------+----------+-------------+
536 // | 32-bit |  1   |    8     |     23      |
537 // +--------+------+----------+-------------+
538 //
539 // 16-bit floats:
540 //
541 // 0   000 00   00 0000 0001 (0x0001: 2e-24:         minimum positive denormalized)
542 // 0   000 00   11 1111 1111 (0x03ff: 2e-14 - 2e-24: maximum positive denormalized)
543 // 0   000 01   00 0000 0000 (0x0400: 2e-14:         minimum positive normalized)
544 //
545 // 32-bit floats:
546 //
547 // 0   011 1110 1   001 0000 0000 0000 0000 0000 (0x3e900000: 0.28125: with exact match in 16-bit normalized)
548 // 0   011 1000 1   000 0000 0011 0000 0000 0000 (0x38803000: exact half way within two 16-bit normalized; round to zero: 0x0401)
549 // 1   011 1000 1   000 0000 0011 0000 0000 0000 (0xb8803000: exact half way within two 16-bit normalized; round to zero: 0x8402)
550 // 0   011 1000 1   000 0000 1111 1111 0000 0000 (0x3880ff00: not exact half way within two 16-bit normalized; round to zero: 0x0403)
551 // 1   011 1000 1   000 0000 1111 1111 0000 0000 (0xb880ff00: not exact half way within two 16-bit normalized; round to zero: 0x8404)
552 
553 // Generate and return 32-bit floats
554 //
555 // The first 24 number pairs are manually picked, while the rest are randomly generated.
556 // Expected count to be at least 24 (numPicks).
getFloat32s(de::Random & rnd,deUint32 count)557 std::vector<float> getFloat32s (de::Random& rnd, deUint32 count)
558 {
559 	std::vector<float> float32;
560 
561 	float32.reserve(count);
562 
563 	// Zero
564 	float32.push_back(0.f);
565 	float32.push_back(-0.f);
566 	// Infinity
567 	float32.push_back(std::numeric_limits<float>::infinity());
568 	float32.push_back(-std::numeric_limits<float>::infinity());
569 	// SNaN
570 	float32.push_back(std::numeric_limits<float>::signaling_NaN());
571 	float32.push_back(-std::numeric_limits<float>::signaling_NaN());
572 	// QNaN
573 	float32.push_back(std::numeric_limits<float>::quiet_NaN());
574 	float32.push_back(-std::numeric_limits<float>::quiet_NaN());
575 
576 	// Denormalized 32-bit float matching 0 in 16-bit
577 	float32.push_back(deFloatLdExp(1.f, -127));
578 	float32.push_back(-deFloatLdExp(1.f, -127));
579 
580 	// Normalized 32-bit float matching 0 in 16-bit
581 	float32.push_back(deFloatLdExp(1.f, -100));
582 	float32.push_back(-deFloatLdExp(1.f, -100));
583 	// Normalized 32-bit float with exact denormalized match in 16-bit
584 	float32.push_back(deFloatLdExp(1.f, -24));  // 2e-24: minimum 16-bit positive denormalized
585 	float32.push_back(-deFloatLdExp(1.f, -24)); // 2e-24: maximum 16-bit negative denormalized
586 	// Normalized 32-bit float with exact normalized match in 16-bit
587 	float32.push_back(deFloatLdExp(1.f, -14));  // 2e-14: minimum 16-bit positive normalized
588 	float32.push_back(-deFloatLdExp(1.f, -14)); // 2e-14: maximum 16-bit negative normalized
589 	// Normalized 32-bit float falling above half way within two 16-bit normalized
590 	float32.push_back(bitwiseCast<float>(deUint32(0x3880ff00)));
591 	float32.push_back(bitwiseCast<float>(deUint32(0xb880ff00)));
592 	// Normalized 32-bit float falling exact half way within two 16-bit normalized
593 	float32.push_back(bitwiseCast<float>(deUint32(0x38803000)));
594 	float32.push_back(bitwiseCast<float>(deUint32(0xb8803000)));
595 	// Some number
596 	float32.push_back(0.28125f);
597 	float32.push_back(-0.28125f);
598 	// Normalized 32-bit float matching infinity in 16-bit
599 	float32.push_back(deFloatLdExp(1.f, 100));
600 	float32.push_back(-deFloatLdExp(1.f, 100));
601 
602 	const deUint32		numPicks	= static_cast<deUint32>(float32.size());
603 
604 	DE_ASSERT(count >= numPicks);
605 	count -= numPicks;
606 
607 	for (deUint32 numNdx = 0; numNdx < count; ++numNdx)
608 		float32.push_back(rnd.getFloat());
609 
610 	return float32;
611 }
612 
613 // IEEE-754 floating point numbers:
614 // +--------+------+----------+-------------+
615 // | binary | sign | exponent | significand |
616 // +--------+------+----------+-------------+
617 // | 16-bit |  1   |    5     |     10      |
618 // +--------+------+----------+-------------+
619 // | 32-bit |  1   |    8     |     23      |
620 // +--------+------+----------+-------------+
621 //
622 // 16-bit floats:
623 //
624 // 0   000 00   00 0000 0001 (0x0001: 2e-24:         minimum positive denormalized)
625 // 0   000 00   11 1111 1111 (0x03ff: 2e-14 - 2e-24: maximum positive denormalized)
626 // 0   000 01   00 0000 0000 (0x0400: 2e-14:         minimum positive normalized)
627 //
628 // 0   000 00   00 0000 0000 (0x0000: +0)
629 // 0   111 11   00 0000 0000 (0x7c00: +Inf)
630 // 0   000 00   11 1111 0000 (0x03f0: +Denorm)
631 // 0   000 01   00 0000 0001 (0x0401: +Norm)
632 // 0   111 11   00 0000 1111 (0x7c0f: +SNaN)
633 // 0   111 11   00 1111 0000 (0x7c0f: +QNaN)
634 
635 // Generate and return 16-bit floats and their corresponding 32-bit values.
636 //
637 // The first 14 number pairs are manually picked, while the rest are randomly generated.
638 // Expected count to be at least 14 (numPicks).
getFloat16s(de::Random & rnd,deUint32 count)639 std::vector<deFloat16> getFloat16s (de::Random& rnd, deUint32 count)
640 {
641 	std::vector<deFloat16> float16;
642 
643 	float16.reserve(count);
644 
645 	// Zero
646 	float16.push_back(deUint16(0x0000));
647 	float16.push_back(deUint16(0x8000));
648 	// Infinity
649 	float16.push_back(deUint16(0x7c00));
650 	float16.push_back(deUint16(0xfc00));
651 	// SNaN
652 	float16.push_back(deUint16(0x7c0f));
653 	float16.push_back(deUint16(0xfc0f));
654 	// QNaN
655 	float16.push_back(deUint16(0x7cf0));
656 	float16.push_back(deUint16(0xfcf0));
657 
658 	// Denormalized
659 	float16.push_back(deUint16(0x03f0));
660 	float16.push_back(deUint16(0x83f0));
661 	// Normalized
662 	float16.push_back(deUint16(0x0401));
663 	float16.push_back(deUint16(0x8401));
664 	// Some normal number
665 	float16.push_back(deUint16(0x14cb));
666 	float16.push_back(deUint16(0x94cb));
667 
668 	const deUint32		numPicks	= static_cast<deUint32>(float16.size());
669 
670 	DE_ASSERT(count >= numPicks);
671 	count -= numPicks;
672 
673 	for (deUint32 numIdx = 0; numIdx < count; ++numIdx)
674 		float16.push_back(rnd.getUint16());
675 
676 	return float16;
677 }
678 
getOpCapabilityShader()679 std::string getOpCapabilityShader()
680 {
681 	return	"OpCapability Shader\n";
682 }
683 
getUnusedEntryPoint()684 std::string getUnusedEntryPoint()
685 {
686 	return	"OpEntryPoint Vertex %unused_func \"unused_func\"\n";
687 }
688 
getUnusedDecorations(const VariableLocation & location)689 std::string getUnusedDecorations(const VariableLocation& location)
690 {
691 	return	"OpMemberDecorate %UnusedBufferType 0 Offset 0\n"
692             "OpMemberDecorate %UnusedBufferType 1 Offset 4\n"
693             "OpDecorate %UnusedBufferType BufferBlock\n"
694             "OpDecorate %unused_buffer DescriptorSet " + de::toString(location.set) + "\n"
695             "OpDecorate %unused_buffer Binding " + de::toString(location.binding) + "\n";
696 }
697 
getUnusedTypesAndConstants()698 std::string getUnusedTypesAndConstants()
699 {
700 	return	"%c_f32_101 = OpConstant %f32 101\n"
701 			"%c_i32_201 = OpConstant %i32 201\n"
702 			"%UnusedBufferType = OpTypeStruct %f32 %i32\n"
703 			"%unused_ptr_Uniform_UnusedBufferType = OpTypePointer Uniform %UnusedBufferType\n"
704 			"%unused_ptr_Uniform_float = OpTypePointer Uniform %f32\n"
705 			"%unused_ptr_Uniform_int = OpTypePointer Uniform %i32\n";
706 }
707 
getUnusedBuffer()708 std::string getUnusedBuffer()
709 {
710 	return	"%unused_buffer = OpVariable %unused_ptr_Uniform_UnusedBufferType Uniform\n";
711 }
712 
getUnusedFunctionBody()713 std::string getUnusedFunctionBody()
714 {
715 	return	"%unused_func = OpFunction %void None %voidf\n"
716 			"%unused_func_label = OpLabel\n"
717 			"%unused_out_float_ptr = OpAccessChain %unused_ptr_Uniform_float %unused_buffer %c_i32_0\n"
718             "OpStore %unused_out_float_ptr %c_f32_101\n"
719 			"%unused_out_int_ptr = OpAccessChain %unused_ptr_Uniform_int %unused_buffer %c_i32_1\n"
720             "OpStore %unused_out_int_ptr %c_i32_201\n"
721             "OpReturn\n"
722             "OpFunctionEnd\n";
723 }
724 
725 } // SpirVAssembly
726 } // vkt
727