1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2015 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 Vulkan test case base classes
22 *//*--------------------------------------------------------------------*/
23
24 #include "vktTestCase.hpp"
25 #include "vktCustomInstancesDevices.hpp"
26
27 #include "vkRef.hpp"
28 #include "vkRefUtil.hpp"
29 #include "vkQueryUtil.hpp"
30 #include "vkDeviceUtil.hpp"
31 #include "vkMemUtil.hpp"
32 #include "vkPlatform.hpp"
33 #include "vkDebugReportUtil.hpp"
34 #include "vkDeviceFeatures.hpp"
35 #include "vkDeviceProperties.hpp"
36
37 #include "tcuCommandLine.hpp"
38 #include "tcuTestLog.hpp"
39
40 #include "deSTLUtil.hpp"
41 #include "deMemory.h"
42
43 #include <set>
44
45 namespace vkt
46 {
47
48 // Default device utilities
49
50 using std::vector;
51 using std::string;
52 using std::set;
53 using namespace vk;
54
55 namespace
56 {
57
filterExtensions(const vector<VkExtensionProperties> & extensions)58 vector<string> filterExtensions (const vector<VkExtensionProperties>& extensions)
59 {
60 vector<string> enabledExtensions;
61 bool khrBufferDeviceAddress = false;
62
63 const char* extensionGroups[] =
64 {
65 "VK_KHR_",
66 "VK_EXT_",
67 "VK_KHX_",
68 "VK_NV_cooperative_matrix",
69 "VK_EXT_extended_dynamic_state2",
70 "VK_NV_ray_tracing",
71 "VK_NV_inherited_viewport_scissor",
72 "VK_NV_mesh_shader",
73 "VK_AMD_mixed_attachment_samples",
74 "VK_AMD_shader_fragment_mask",
75 "VK_AMD_buffer_marker",
76 "VK_AMD_shader_explicit_vertex_parameter",
77 "VK_AMD_shader_image_load_store_lod",
78 "VK_AMD_shader_trinary_minmax",
79 "VK_AMD_texture_gather_bias_lod",
80 "VK_ANDROID_external_memory_android_hardware_buffer",
81 "VK_VALVE_mutable_descriptor_type",
82 };
83
84 for (size_t extNdx = 0; extNdx < extensions.size(); extNdx++)
85 {
86 if (deStringEqual(extensions[extNdx].extensionName, "VK_KHR_buffer_device_address"))
87 {
88 khrBufferDeviceAddress = true;
89 break;
90 }
91 }
92
93 for (size_t extNdx = 0; extNdx < extensions.size(); extNdx++)
94 {
95 const auto& extName = extensions[extNdx].extensionName;
96
97 // Skip enabling VK_KHR_pipeline_library unless needed.
98 if (deStringEqual(extName, "VK_KHR_pipeline_library"))
99 continue;
100
101 // VK_EXT_buffer_device_address is deprecated and must not be enabled if VK_KHR_buffer_device_address is enabled
102 if (khrBufferDeviceAddress && deStringEqual(extName, "VK_EXT_buffer_device_address"))
103 continue;
104
105 for (int extGroupNdx = 0; extGroupNdx < DE_LENGTH_OF_ARRAY(extensionGroups); extGroupNdx++)
106 {
107 if (deStringBeginsWith(extName, extensionGroups[extGroupNdx]))
108 enabledExtensions.push_back(extName);
109 }
110 }
111
112 return enabledExtensions;
113 }
114
addExtensions(const vector<string> & a,const vector<const char * > & b)115 vector<string> addExtensions (const vector<string>& a, const vector<const char*>& b)
116 {
117 vector<string> res (a);
118
119 for (vector<const char*>::const_iterator bIter = b.begin(); bIter != b.end(); ++bIter)
120 {
121 if (!de::contains(res.begin(), res.end(), string(*bIter)))
122 res.push_back(string(*bIter));
123 }
124
125 return res;
126 }
127
removeExtensions(const vector<string> & a,const vector<const char * > & b)128 vector<string> removeExtensions (const vector<string>& a, const vector<const char*>& b)
129 {
130 vector<string> res;
131 set<string> removeExts (b.begin(), b.end());
132
133 for (vector<string>::const_iterator aIter = a.begin(); aIter != a.end(); ++aIter)
134 {
135 if (!de::contains(removeExts, *aIter))
136 res.push_back(*aIter);
137 }
138
139 return res;
140 }
141
addCoreInstanceExtensions(const vector<string> & extensions,deUint32 instanceVersion)142 vector<string> addCoreInstanceExtensions (const vector<string>& extensions, deUint32 instanceVersion)
143 {
144 vector<const char*> coreExtensions;
145 getCoreInstanceExtensions(instanceVersion, coreExtensions);
146 return addExtensions(extensions, coreExtensions);
147 }
148
addCoreDeviceExtensions(const vector<string> & extensions,deUint32 instanceVersion)149 vector<string> addCoreDeviceExtensions(const vector<string>& extensions, deUint32 instanceVersion)
150 {
151 vector<const char*> coreExtensions;
152 getCoreDeviceExtensions(instanceVersion, coreExtensions);
153 return addExtensions(extensions, coreExtensions);
154 }
155
getTargetInstanceVersion(const PlatformInterface & vkp)156 deUint32 getTargetInstanceVersion (const PlatformInterface& vkp)
157 {
158 deUint32 version = pack(ApiVersion(1, 0, 0));
159
160 if (vkp.enumerateInstanceVersion(&version) != VK_SUCCESS)
161 TCU_THROW(InternalError, "Enumerate instance version error");
162 return version;
163 }
164
determineDeviceVersions(const PlatformInterface & vkp,deUint32 apiVersion,const tcu::CommandLine & cmdLine)165 std::pair<deUint32, deUint32> determineDeviceVersions(const PlatformInterface& vkp, deUint32 apiVersion, const tcu::CommandLine& cmdLine)
166 {
167 Move<VkInstance> preinstance = createDefaultInstance(vkp, apiVersion);
168 InstanceDriver preinterface (vkp, preinstance.get());
169
170 const vector<VkPhysicalDevice> devices = enumeratePhysicalDevices(preinterface, preinstance.get());
171 deUint32 lowestDeviceVersion = 0xFFFFFFFFu;
172 for (deUint32 deviceNdx = 0u; deviceNdx < devices.size(); ++deviceNdx)
173 {
174 const VkPhysicalDeviceProperties props = getPhysicalDeviceProperties(preinterface, devices[deviceNdx]);
175 if (props.apiVersion < lowestDeviceVersion)
176 lowestDeviceVersion = props.apiVersion;
177 }
178
179 const vk::VkPhysicalDevice choosenDevice = chooseDevice(preinterface, *preinstance, cmdLine);
180 const VkPhysicalDeviceProperties props = getPhysicalDeviceProperties(preinterface, choosenDevice);
181 const deUint32 choosenDeviceVersion = props.apiVersion;
182
183 return std::make_pair(choosenDeviceVersion, lowestDeviceVersion);
184 }
185
186
createInstance(const PlatformInterface & vkp,deUint32 apiVersion,const vector<string> & enabledExtensions,DebugReportRecorder * recorder)187 Move<VkInstance> createInstance (const PlatformInterface& vkp, deUint32 apiVersion, const vector<string>& enabledExtensions, DebugReportRecorder* recorder)
188 {
189 const bool isValidationEnabled = (recorder != nullptr);
190 vector<const char*> enabledLayers;
191
192 // \note Extensions in core are not explicitly enabled even though
193 // they are in the extension list advertised to tests.
194 vector<const char*> coreExtensions;
195 getCoreInstanceExtensions(apiVersion, coreExtensions);
196 const auto nonCoreExtensions = removeExtensions(enabledExtensions, coreExtensions);
197
198 if (isValidationEnabled)
199 {
200 if (!isDebugReportSupported(vkp))
201 TCU_THROW(NotSupportedError, "VK_EXT_debug_report is not supported");
202
203 enabledLayers = vkt::getValidationLayers(vkp);
204 if (enabledLayers.empty())
205 TCU_THROW(NotSupportedError, "No validation layers found");
206 }
207
208 return createDefaultInstance(vkp, apiVersion, vector<string>(begin(enabledLayers), end(enabledLayers)), nonCoreExtensions, recorder);
209 }
210
findQueueFamilyIndexWithCaps(const InstanceInterface & vkInstance,VkPhysicalDevice physicalDevice,VkQueueFlags requiredCaps)211 static deUint32 findQueueFamilyIndexWithCaps (const InstanceInterface& vkInstance, VkPhysicalDevice physicalDevice, VkQueueFlags requiredCaps)
212 {
213 const vector<VkQueueFamilyProperties> queueProps = getPhysicalDeviceQueueFamilyProperties(vkInstance, physicalDevice);
214
215 for (size_t queueNdx = 0; queueNdx < queueProps.size(); queueNdx++)
216 {
217 if ((queueProps[queueNdx].queueFlags & requiredCaps) == requiredCaps)
218 return (deUint32)queueNdx;
219 }
220
221 TCU_THROW(NotSupportedError, "No matching queue found");
222 }
223
createDefaultDevice(const PlatformInterface & vkp,VkInstance instance,const InstanceInterface & vki,VkPhysicalDevice physicalDevice,const deUint32 apiVersion,deUint32 queueIndex,deUint32 sparseQueueIndex,const VkPhysicalDeviceFeatures2 & enabledFeatures,const vector<string> & enabledExtensions,const tcu::CommandLine & cmdLine)224 Move<VkDevice> createDefaultDevice (const PlatformInterface& vkp,
225 VkInstance instance,
226 const InstanceInterface& vki,
227 VkPhysicalDevice physicalDevice,
228 const deUint32 apiVersion,
229 deUint32 queueIndex,
230 deUint32 sparseQueueIndex,
231 const VkPhysicalDeviceFeatures2& enabledFeatures,
232 const vector<string>& enabledExtensions,
233 const tcu::CommandLine& cmdLine)
234 {
235 VkDeviceQueueCreateInfo queueInfo[2];
236 VkDeviceCreateInfo deviceInfo;
237 vector<const char*> enabledLayers;
238 vector<const char*> extensionPtrs;
239 const float queuePriority = 1.0f;
240 const deUint32 numQueues = (enabledFeatures.features.sparseBinding && (queueIndex != sparseQueueIndex)) ? 2 : 1;
241
242 deMemset(&queueInfo, 0, sizeof(queueInfo));
243 deMemset(&deviceInfo, 0, sizeof(deviceInfo));
244
245 if (cmdLine.isValidationEnabled())
246 {
247 enabledLayers = vkt::getValidationLayers(vki, physicalDevice);
248 if (enabledLayers.empty())
249 TCU_THROW(NotSupportedError, "No validation layers found");
250 }
251
252 // \note Extensions in core are not explicitly enabled even though
253 // they are in the extension list advertised to tests.
254 vector<const char*> coreExtensions;
255 getCoreDeviceExtensions(apiVersion, coreExtensions);
256 vector<string> nonCoreExtensions(removeExtensions(enabledExtensions, coreExtensions));
257
258 extensionPtrs.resize(nonCoreExtensions.size());
259
260 for (size_t ndx = 0; ndx < nonCoreExtensions.size(); ++ndx)
261 extensionPtrs[ndx] = nonCoreExtensions[ndx].c_str();
262
263 queueInfo[0].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
264 queueInfo[0].pNext = DE_NULL;
265 queueInfo[0].flags = (VkDeviceQueueCreateFlags)0u;
266 queueInfo[0].queueFamilyIndex = queueIndex;
267 queueInfo[0].queueCount = 1u;
268 queueInfo[0].pQueuePriorities = &queuePriority;
269
270 if (numQueues > 1)
271 {
272 queueInfo[1].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
273 queueInfo[1].pNext = DE_NULL;
274 queueInfo[1].flags = (VkDeviceQueueCreateFlags)0u;
275 queueInfo[1].queueFamilyIndex = sparseQueueIndex;
276 queueInfo[1].queueCount = 1u;
277 queueInfo[1].pQueuePriorities = &queuePriority;
278 }
279
280 // VK_KHR_get_physical_device_properties2 is used if enabledFeatures.pNext != 0
281 deviceInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
282 deviceInfo.pNext = enabledFeatures.pNext ? &enabledFeatures : DE_NULL;
283 deviceInfo.queueCreateInfoCount = numQueues;
284 deviceInfo.pQueueCreateInfos = queueInfo;
285 deviceInfo.enabledExtensionCount = (deUint32)extensionPtrs.size();
286 deviceInfo.ppEnabledExtensionNames = (extensionPtrs.empty() ? DE_NULL : &extensionPtrs[0]);
287 deviceInfo.enabledLayerCount = (deUint32)enabledLayers.size();
288 deviceInfo.ppEnabledLayerNames = (enabledLayers.empty() ? DE_NULL : enabledLayers.data());
289 deviceInfo.pEnabledFeatures = enabledFeatures.pNext ? DE_NULL : &enabledFeatures.features;
290
291 return createDevice(vkp, instance, vki, physicalDevice, &deviceInfo);
292 }
293
294 } // anonymous
295
296 class DefaultDevice
297 {
298 public:
299 DefaultDevice (const PlatformInterface& vkPlatform, const tcu::CommandLine& cmdLine);
300 ~DefaultDevice (void);
301
getInstance(void) const302 VkInstance getInstance (void) const { return *m_instance; }
getInstanceInterface(void) const303 const InstanceInterface& getInstanceInterface (void) const { return m_instanceInterface; }
getMaximumFrameworkVulkanVersion(void) const304 deUint32 getMaximumFrameworkVulkanVersion (void) const { return m_maximumFrameworkVulkanVersion; }
getAvailableInstanceVersion(void) const305 deUint32 getAvailableInstanceVersion (void) const { return m_availableInstanceVersion; }
getUsedInstanceVersion(void) const306 deUint32 getUsedInstanceVersion (void) const { return m_usedInstanceVersion; }
getInstanceExtensions(void) const307 const vector<string>& getInstanceExtensions (void) const { return m_instanceExtensions; }
308
getPhysicalDevice(void) const309 VkPhysicalDevice getPhysicalDevice (void) const { return m_physicalDevice; }
getDeviceVersion(void) const310 deUint32 getDeviceVersion (void) const { return m_deviceVersion; }
311
isDeviceFeatureInitialized(VkStructureType sType) const312 bool isDeviceFeatureInitialized (VkStructureType sType) const { return m_deviceFeatures.isDeviceFeatureInitialized(sType); }
getDeviceFeatures(void) const313 const VkPhysicalDeviceFeatures& getDeviceFeatures (void) const { return m_deviceFeatures.getCoreFeatures2().features; }
getDeviceFeatures2(void) const314 const VkPhysicalDeviceFeatures2& getDeviceFeatures2 (void) const { return m_deviceFeatures.getCoreFeatures2(); }
getVulkan11Features(void) const315 const VkPhysicalDeviceVulkan11Features& getVulkan11Features (void) const { return m_deviceFeatures.getVulkan11Features(); }
getVulkan12Features(void) const316 const VkPhysicalDeviceVulkan12Features& getVulkan12Features (void) const { return m_deviceFeatures.getVulkan12Features(); }
317
318 #include "vkDeviceFeaturesForDefaultDeviceDefs.inl"
319
isDevicePropertyInitialized(VkStructureType sType) const320 bool isDevicePropertyInitialized (VkStructureType sType) const { return m_deviceProperties.isDevicePropertyInitialized(sType); }
getDeviceProperties(void) const321 const VkPhysicalDeviceProperties& getDeviceProperties (void) const { return m_deviceProperties.getCoreProperties2().properties; }
getDeviceProperties2(void) const322 const VkPhysicalDeviceProperties2& getDeviceProperties2 (void) const { return m_deviceProperties.getCoreProperties2(); }
getDeviceVulkan11Properties(void) const323 const VkPhysicalDeviceVulkan11Properties& getDeviceVulkan11Properties (void) const { return m_deviceProperties.getVulkan11Properties(); }
getDeviceVulkan12Properties(void) const324 const VkPhysicalDeviceVulkan12Properties& getDeviceVulkan12Properties (void) const { return m_deviceProperties.getVulkan12Properties(); }
325
326 #include "vkDevicePropertiesForDefaultDeviceDefs.inl"
327
getDevice(void) const328 VkDevice getDevice (void) const { return *m_device; }
getDeviceInterface(void) const329 const DeviceInterface& getDeviceInterface (void) const { return m_deviceInterface; }
getDeviceExtensions(void) const330 const vector<string>& getDeviceExtensions (void) const { return m_deviceExtensions; }
getUsedApiVersion(void) const331 deUint32 getUsedApiVersion (void) const { return m_usedApiVersion; }
getUniversalQueueFamilyIndex(void) const332 deUint32 getUniversalQueueFamilyIndex (void) const { return m_universalQueueFamilyIndex; }
333 VkQueue getUniversalQueue (void) const;
getSparseQueueFamilyIndex(void) const334 deUint32 getSparseQueueFamilyIndex (void) const { return m_sparseQueueFamilyIndex; }
335 VkQueue getSparseQueue (void) const;
336
hasDebugReportRecorder(void) const337 bool hasDebugReportRecorder (void) const { return m_debugReportRecorder.get() != nullptr; }
getDebugReportRecorder(void) const338 vk::DebugReportRecorder& getDebugReportRecorder (void) const { return *m_debugReportRecorder.get(); }
339
340 private:
341 using DebugReportRecorderPtr = de::UniquePtr<vk::DebugReportRecorder>;
342 using DebugReportCallbackPtr = vk::Move<VkDebugReportCallbackEXT>;
343
344 const deUint32 m_maximumFrameworkVulkanVersion;
345 const deUint32 m_availableInstanceVersion;
346 const deUint32 m_usedInstanceVersion;
347
348 const std::pair<deUint32, deUint32> m_deviceVersions;
349 const deUint32 m_usedApiVersion;
350
351 const DebugReportRecorderPtr m_debugReportRecorder;
352 const vector<string> m_instanceExtensions;
353 const Unique<VkInstance> m_instance;
354 const InstanceDriver m_instanceInterface;
355 const DebugReportCallbackPtr m_debugReportCallback;
356
357 const VkPhysicalDevice m_physicalDevice;
358 const deUint32 m_deviceVersion;
359
360 const vector<string> m_deviceExtensions;
361 const DeviceFeatures m_deviceFeatures;
362
363 const deUint32 m_universalQueueFamilyIndex;
364 const deUint32 m_sparseQueueFamilyIndex;
365 const DeviceProperties m_deviceProperties;
366
367 const Unique<VkDevice> m_device;
368 const DeviceDriver m_deviceInterface;
369 };
370
371 namespace
372 {
373
sanitizeApiVersion(deUint32 v)374 deUint32 sanitizeApiVersion(deUint32 v)
375 {
376 return VK_MAKE_VERSION(VK_API_VERSION_MAJOR(v), VK_API_VERSION_MINOR(v), 0 );
377 }
378
createDebugReportRecorder(const vk::PlatformInterface & vkp,bool printValidationErrors)379 de::MovePtr<vk::DebugReportRecorder> createDebugReportRecorder (const vk::PlatformInterface& vkp, bool printValidationErrors)
380 {
381 if (isDebugReportSupported(vkp))
382 return de::MovePtr<vk::DebugReportRecorder>(new vk::DebugReportRecorder(printValidationErrors));
383 else
384 TCU_THROW(NotSupportedError, "VK_EXT_debug_report is not supported");
385 }
386
387 } // anonymous
388
DefaultDevice(const PlatformInterface & vkPlatform,const tcu::CommandLine & cmdLine)389 DefaultDevice::DefaultDevice (const PlatformInterface& vkPlatform, const tcu::CommandLine& cmdLine)
390 : m_maximumFrameworkVulkanVersion (VK_API_MAX_FRAMEWORK_VERSION)
391 , m_availableInstanceVersion (getTargetInstanceVersion(vkPlatform))
392 , m_usedInstanceVersion (sanitizeApiVersion(deMinu32(m_availableInstanceVersion, m_maximumFrameworkVulkanVersion)))
393 , m_deviceVersions (determineDeviceVersions(vkPlatform, m_usedInstanceVersion, cmdLine))
394 , m_usedApiVersion (sanitizeApiVersion(deMinu32(m_usedInstanceVersion, m_deviceVersions.first)))
395
396 , m_debugReportRecorder (cmdLine.isValidationEnabled()
397 ? createDebugReportRecorder(vkPlatform, cmdLine.printValidationErrors())
398 : de::MovePtr<vk::DebugReportRecorder>())
399 , m_instanceExtensions (addCoreInstanceExtensions(filterExtensions(enumerateInstanceExtensionProperties(vkPlatform, DE_NULL)), m_usedApiVersion))
400 , m_instance (createInstance(vkPlatform, m_usedApiVersion, m_instanceExtensions, m_debugReportRecorder.get()))
401
402 , m_instanceInterface (vkPlatform, *m_instance)
403 , m_debugReportCallback (cmdLine.isValidationEnabled()
404 ? m_debugReportRecorder->createCallback(m_instanceInterface, m_instance.get())
405 : DebugReportCallbackPtr())
406 , m_physicalDevice (chooseDevice(m_instanceInterface, *m_instance, cmdLine))
407 , m_deviceVersion (getPhysicalDeviceProperties(m_instanceInterface, m_physicalDevice).apiVersion)
408
409 , m_deviceExtensions (addCoreDeviceExtensions(filterExtensions(enumerateDeviceExtensionProperties(m_instanceInterface, m_physicalDevice, DE_NULL)), m_usedApiVersion))
410 , m_deviceFeatures (m_instanceInterface, m_usedApiVersion, m_physicalDevice, m_instanceExtensions, m_deviceExtensions)
411 , m_universalQueueFamilyIndex (findQueueFamilyIndexWithCaps(m_instanceInterface, m_physicalDevice, VK_QUEUE_GRAPHICS_BIT|VK_QUEUE_COMPUTE_BIT))
412 , m_sparseQueueFamilyIndex (m_deviceFeatures.getCoreFeatures2().features.sparseBinding ? findQueueFamilyIndexWithCaps(m_instanceInterface, m_physicalDevice, VK_QUEUE_SPARSE_BINDING_BIT) : 0)
413 , m_deviceProperties (m_instanceInterface, m_usedApiVersion, m_physicalDevice, m_instanceExtensions, m_deviceExtensions)
414 , m_device (createDefaultDevice(vkPlatform, *m_instance, m_instanceInterface, m_physicalDevice, m_usedApiVersion, m_universalQueueFamilyIndex, m_sparseQueueFamilyIndex, m_deviceFeatures.getCoreFeatures2(), m_deviceExtensions, cmdLine))
415 , m_deviceInterface (vkPlatform, *m_instance, *m_device)
416 {
417 DE_ASSERT(m_deviceVersions.first == m_deviceVersion);
418 }
419
~DefaultDevice(void)420 DefaultDevice::~DefaultDevice (void)
421 {
422 }
423
getUniversalQueue(void) const424 VkQueue DefaultDevice::getUniversalQueue (void) const
425 {
426 return getDeviceQueue(m_deviceInterface, *m_device, m_universalQueueFamilyIndex, 0);
427 }
428
getSparseQueue(void) const429 VkQueue DefaultDevice::getSparseQueue (void) const
430 {
431 if (!m_deviceFeatures.getCoreFeatures2().features.sparseBinding)
432 TCU_THROW(NotSupportedError, "Sparse binding not supported.");
433
434 return getDeviceQueue(m_deviceInterface, *m_device, m_sparseQueueFamilyIndex, 0);
435 }
436
437 namespace
438 {
439 // Allocator utilities
440
createAllocator(DefaultDevice * device)441 vk::Allocator* createAllocator (DefaultDevice* device)
442 {
443 const VkPhysicalDeviceMemoryProperties memoryProperties = vk::getPhysicalDeviceMemoryProperties(device->getInstanceInterface(), device->getPhysicalDevice());
444
445 // \todo [2015-07-24 jarkko] support allocator selection/configuration from command line (or compile time)
446 return new SimpleAllocator(device->getDeviceInterface(), device->getDevice(), memoryProperties);
447 }
448
449 } // anonymous
450
451 // Context
452
Context(tcu::TestContext & testCtx,const vk::PlatformInterface & platformInterface,vk::BinaryCollection & progCollection)453 Context::Context (tcu::TestContext& testCtx,
454 const vk::PlatformInterface& platformInterface,
455 vk::BinaryCollection& progCollection)
456 : m_testCtx (testCtx)
457 , m_platformInterface (platformInterface)
458 , m_progCollection (progCollection)
459 , m_device (new DefaultDevice(m_platformInterface, testCtx.getCommandLine()))
460 , m_allocator (createAllocator(m_device.get()))
461 , m_resultSetOnValidation (false)
462 {
463 }
464
~Context(void)465 Context::~Context (void)
466 {
467 }
468
getMaximumFrameworkVulkanVersion(void) const469 deUint32 Context::getMaximumFrameworkVulkanVersion (void) const { return m_device->getMaximumFrameworkVulkanVersion(); }
getAvailableInstanceVersion(void) const470 deUint32 Context::getAvailableInstanceVersion (void) const { return m_device->getAvailableInstanceVersion(); }
getInstanceExtensions(void) const471 const vector<string>& Context::getInstanceExtensions (void) const { return m_device->getInstanceExtensions(); }
getInstance(void) const472 vk::VkInstance Context::getInstance (void) const { return m_device->getInstance(); }
getInstanceInterface(void) const473 const vk::InstanceInterface& Context::getInstanceInterface (void) const { return m_device->getInstanceInterface(); }
getPhysicalDevice(void) const474 vk::VkPhysicalDevice Context::getPhysicalDevice (void) const { return m_device->getPhysicalDevice(); }
getDeviceVersion(void) const475 deUint32 Context::getDeviceVersion (void) const { return m_device->getDeviceVersion(); }
getDeviceFeatures(void) const476 const vk::VkPhysicalDeviceFeatures& Context::getDeviceFeatures (void) const { return m_device->getDeviceFeatures(); }
getDeviceFeatures2(void) const477 const vk::VkPhysicalDeviceFeatures2& Context::getDeviceFeatures2 (void) const { return m_device->getDeviceFeatures2(); }
getDeviceVulkan11Features(void) const478 const vk::VkPhysicalDeviceVulkan11Features& Context::getDeviceVulkan11Features (void) const { return m_device->getVulkan11Features(); }
getDeviceVulkan12Features(void) const479 const vk::VkPhysicalDeviceVulkan12Features& Context::getDeviceVulkan12Features (void) const { return m_device->getVulkan12Features(); }
480
isDeviceFunctionalitySupported(const std::string & extension) const481 bool Context::isDeviceFunctionalitySupported (const std::string& extension) const
482 {
483 // check if extension was promoted to core
484 deUint32 apiVersion = getUsedApiVersion();
485 if (isCoreDeviceExtension(apiVersion, extension))
486 {
487 if (apiVersion < VK_MAKE_VERSION(1, 2, 0))
488 {
489 // Check feature bits in extension-specific structures.
490 if (extension == "VK_KHR_multiview")
491 return !!m_device->getMultiviewFeatures().multiview;
492 if (extension == "VK_KHR_variable_pointers")
493 return !!m_device->getVariablePointersFeatures().variablePointersStorageBuffer;
494 if (extension == "VK_KHR_sampler_ycbcr_conversion")
495 return !!m_device->getSamplerYcbcrConversionFeatures().samplerYcbcrConversion;
496 if (extension == "VK_KHR_shader_draw_parameters")
497 return !!m_device->getShaderDrawParametersFeatures().shaderDrawParameters;
498 }
499 else
500 {
501 // Check feature bits using the new Vulkan 1.2 structures.
502 const auto& vk11Features = m_device->getVulkan11Features();
503 if (extension == "VK_KHR_multiview")
504 return !!vk11Features.multiview;
505 if (extension == "VK_KHR_variable_pointers")
506 return !!vk11Features.variablePointersStorageBuffer;
507 if (extension == "VK_KHR_sampler_ycbcr_conversion")
508 return !!vk11Features.samplerYcbcrConversion;
509 if (extension == "VK_KHR_shader_draw_parameters")
510 return !!vk11Features.shaderDrawParameters;
511
512 const auto& vk12Features = m_device->getVulkan12Features();
513 if (extension == "VK_KHR_timeline_semaphore")
514 return !!vk12Features.timelineSemaphore;
515 if (extension == "VK_KHR_buffer_device_address")
516 return !!vk12Features.bufferDeviceAddress;
517 if (extension == "VK_EXT_descriptor_indexing")
518 return !!vk12Features.descriptorIndexing;
519 if (extension == "VK_KHR_draw_indirect_count")
520 return !!vk12Features.drawIndirectCount;
521 if (extension == "VK_KHR_sampler_mirror_clamp_to_edge")
522 return !!vk12Features.samplerMirrorClampToEdge;
523 if (extension == "VK_EXT_sampler_filter_minmax")
524 return !!vk12Features.samplerFilterMinmax;
525 if (extension == "VK_EXT_shader_viewport_index_layer")
526 return !!vk12Features.shaderOutputViewportIndex && !!vk12Features.shaderOutputLayer;
527 }
528
529 // No feature flags to check.
530 return true;
531 }
532
533 // check if extension is on the list of extensions for current device
534 const auto& extensions = getDeviceExtensions();
535 if (de::contains(extensions.begin(), extensions.end(), extension))
536 {
537 if (extension == "VK_KHR_timeline_semaphore")
538 return !!getTimelineSemaphoreFeatures().timelineSemaphore;
539 if (extension == "VK_KHR_synchronization2")
540 return !!getSynchronization2Features().synchronization2;
541 if (extension == "VK_EXT_extended_dynamic_state")
542 return !!getExtendedDynamicStateFeaturesEXT().extendedDynamicState;
543 if (extension == "VK_EXT_shader_demote_to_helper_invocation")
544 return !!getShaderDemoteToHelperInvocationFeaturesEXT().shaderDemoteToHelperInvocation;
545 if (extension == "VK_KHR_workgroup_memory_explicit_layout")
546 return !!getWorkgroupMemoryExplicitLayoutFeatures().workgroupMemoryExplicitLayout;
547
548 return true;
549 }
550
551 return false;
552 }
553
isInstanceFunctionalitySupported(const std::string & extension) const554 bool Context::isInstanceFunctionalitySupported(const std::string& extension) const
555 {
556 // NOTE: current implementation uses isInstanceExtensionSupported but
557 // this will change when some instance extensions will be promoted to the
558 // core; don't use isInstanceExtensionSupported directly, use this method instead
559 return isInstanceExtensionSupported(getUsedApiVersion(), getInstanceExtensions(), extension);
560 }
561
562 #include "vkDeviceFeaturesForContextDefs.inl"
563
getDeviceProperties(void) const564 const vk::VkPhysicalDeviceProperties& Context::getDeviceProperties (void) const { return m_device->getDeviceProperties(); }
getDeviceProperties2(void) const565 const vk::VkPhysicalDeviceProperties2& Context::getDeviceProperties2 (void) const { return m_device->getDeviceProperties2(); }
getDeviceVulkan11Properties(void) const566 const vk::VkPhysicalDeviceVulkan11Properties& Context::getDeviceVulkan11Properties (void) const { return m_device->getDeviceVulkan11Properties(); }
getDeviceVulkan12Properties(void) const567 const vk::VkPhysicalDeviceVulkan12Properties& Context::getDeviceVulkan12Properties (void) const { return m_device->getDeviceVulkan12Properties(); }
568
569 #include "vkDevicePropertiesForContextDefs.inl"
570
getDeviceExtensions(void) const571 const vector<string>& Context::getDeviceExtensions (void) const { return m_device->getDeviceExtensions(); }
getDevice(void) const572 vk::VkDevice Context::getDevice (void) const { return m_device->getDevice(); }
getDeviceInterface(void) const573 const vk::DeviceInterface& Context::getDeviceInterface (void) const { return m_device->getDeviceInterface(); }
getUniversalQueueFamilyIndex(void) const574 deUint32 Context::getUniversalQueueFamilyIndex (void) const { return m_device->getUniversalQueueFamilyIndex(); }
getUniversalQueue(void) const575 vk::VkQueue Context::getUniversalQueue (void) const { return m_device->getUniversalQueue(); }
getSparseQueueFamilyIndex(void) const576 deUint32 Context::getSparseQueueFamilyIndex (void) const { return m_device->getSparseQueueFamilyIndex(); }
getSparseQueue(void) const577 vk::VkQueue Context::getSparseQueue (void) const { return m_device->getSparseQueue(); }
getDefaultAllocator(void) const578 vk::Allocator& Context::getDefaultAllocator (void) const { return *m_allocator; }
getUsedApiVersion(void) const579 deUint32 Context::getUsedApiVersion (void) const { return m_device->getUsedApiVersion(); }
contextSupports(const deUint32 majorNum,const deUint32 minorNum,const deUint32 patchNum) const580 bool Context::contextSupports (const deUint32 majorNum, const deUint32 minorNum, const deUint32 patchNum) const
581 { return m_device->getUsedApiVersion() >= VK_MAKE_VERSION(majorNum, minorNum, patchNum); }
contextSupports(const ApiVersion version) const582 bool Context::contextSupports (const ApiVersion version) const
583 { return m_device->getUsedApiVersion() >= pack(version); }
contextSupports(const deUint32 requiredApiVersionBits) const584 bool Context::contextSupports (const deUint32 requiredApiVersionBits) const
585 { return m_device->getUsedApiVersion() >= requiredApiVersionBits; }
isDeviceFeatureInitialized(vk::VkStructureType sType) const586 bool Context::isDeviceFeatureInitialized (vk::VkStructureType sType) const
587 { return m_device->isDeviceFeatureInitialized(sType); }
isDevicePropertyInitialized(vk::VkStructureType sType) const588 bool Context::isDevicePropertyInitialized (vk::VkStructureType sType) const
589 { return m_device->isDevicePropertyInitialized(sType); }
590
requireDeviceFunctionality(const std::string & required) const591 bool Context::requireDeviceFunctionality (const std::string& required) const
592 {
593 if (!isDeviceFunctionalitySupported(required))
594 TCU_THROW(NotSupportedError, required + " is not supported");
595
596 return true;
597 }
598
requireInstanceFunctionality(const std::string & required) const599 bool Context::requireInstanceFunctionality (const std::string& required) const
600 {
601 if (!isInstanceFunctionalitySupported(required))
602 TCU_THROW(NotSupportedError, required + " is not supported");
603
604 return true;
605 }
606
607 struct DeviceCoreFeaturesTable
608 {
609 const char* featureName;
610 const deUint32 featureArrayIndex;
611 const deUint32 featureArrayOffset;
612 };
613
614 #define DEVICE_CORE_FEATURE_OFFSET(FEATURE_FIELD_NAME) DE_OFFSET_OF(VkPhysicalDeviceFeatures, FEATURE_FIELD_NAME)
615 #define DEVICE_CORE_FEATURE_ENTRY(BITNAME, FIELDNAME) { #FIELDNAME, BITNAME, DEVICE_CORE_FEATURE_OFFSET(FIELDNAME) }
616
617 const DeviceCoreFeaturesTable deviceCoreFeaturesTable[] =
618 {
619 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_ROBUST_BUFFER_ACCESS , robustBufferAccess ),
620 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_FULL_DRAW_INDEX_UINT32 , fullDrawIndexUint32 ),
621 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_IMAGE_CUBE_ARRAY , imageCubeArray ),
622 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_INDEPENDENT_BLEND , independentBlend ),
623 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_GEOMETRY_SHADER , geometryShader ),
624 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_TESSELLATION_SHADER , tessellationShader ),
625 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SAMPLE_RATE_SHADING , sampleRateShading ),
626 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_DUAL_SRC_BLEND , dualSrcBlend ),
627 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_LOGIC_OP , logicOp ),
628 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_MULTI_DRAW_INDIRECT , multiDrawIndirect ),
629 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_DRAW_INDIRECT_FIRST_INSTANCE , drawIndirectFirstInstance ),
630 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_DEPTH_CLAMP , depthClamp ),
631 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_DEPTH_BIAS_CLAMP , depthBiasClamp ),
632 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_FILL_MODE_NON_SOLID , fillModeNonSolid ),
633 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_DEPTH_BOUNDS , depthBounds ),
634 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_WIDE_LINES , wideLines ),
635 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_LARGE_POINTS , largePoints ),
636 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_ALPHA_TO_ONE , alphaToOne ),
637 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_MULTI_VIEWPORT , multiViewport ),
638 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SAMPLER_ANISOTROPY , samplerAnisotropy ),
639 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_TEXTURE_COMPRESSION_ETC2 , textureCompressionETC2 ),
640 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_TEXTURE_COMPRESSION_ASTC_LDR , textureCompressionASTC_LDR ),
641 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_TEXTURE_COMPRESSION_BC , textureCompressionBC ),
642 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_OCCLUSION_QUERY_PRECISE , occlusionQueryPrecise ),
643 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_PIPELINE_STATISTICS_QUERY , pipelineStatisticsQuery ),
644 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_VERTEX_PIPELINE_STORES_AND_ATOMICS , vertexPipelineStoresAndAtomics ),
645 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_FRAGMENT_STORES_AND_ATOMICS , fragmentStoresAndAtomics ),
646 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_TESSELLATION_AND_GEOMETRY_POINT_SIZE , shaderTessellationAndGeometryPointSize ),
647 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_IMAGE_GATHER_EXTENDED , shaderImageGatherExtended ),
648 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_STORAGE_IMAGE_EXTENDED_FORMATS , shaderStorageImageExtendedFormats ),
649 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_STORAGE_IMAGE_MULTISAMPLE , shaderStorageImageMultisample ),
650 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_STORAGE_IMAGE_READ_WITHOUT_FORMAT , shaderStorageImageReadWithoutFormat ),
651 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_STORAGE_IMAGE_WRITE_WITHOUT_FORMAT , shaderStorageImageWriteWithoutFormat ),
652 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_UNIFORM_BUFFER_ARRAY_DYNAMIC_INDEXING , shaderUniformBufferArrayDynamicIndexing ),
653 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_SAMPLED_IMAGE_ARRAY_DYNAMIC_INDEXING , shaderSampledImageArrayDynamicIndexing ),
654 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_STORAGE_BUFFER_ARRAY_DYNAMIC_INDEXING , shaderStorageBufferArrayDynamicIndexing ),
655 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_STORAGE_IMAGE_ARRAY_DYNAMIC_INDEXING , shaderStorageImageArrayDynamicIndexing ),
656 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_CLIP_DISTANCE , shaderClipDistance ),
657 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_CULL_DISTANCE , shaderCullDistance ),
658 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_FLOAT64 , shaderFloat64 ),
659 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_INT64 , shaderInt64 ),
660 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_INT16 , shaderInt16 ),
661 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_RESOURCE_RESIDENCY , shaderResourceResidency ),
662 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SHADER_RESOURCE_MIN_LOD , shaderResourceMinLod ),
663 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SPARSE_BINDING , sparseBinding ),
664 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SPARSE_RESIDENCY_BUFFER , sparseResidencyBuffer ),
665 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SPARSE_RESIDENCY_IMAGE2D , sparseResidencyImage2D ),
666 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SPARSE_RESIDENCY_IMAGE3D , sparseResidencyImage3D ),
667 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SPARSE_RESIDENCY2_SAMPLES , sparseResidency2Samples ),
668 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SPARSE_RESIDENCY4_SAMPLES , sparseResidency4Samples ),
669 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SPARSE_RESIDENCY8_SAMPLES , sparseResidency8Samples ),
670 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SPARSE_RESIDENCY16_SAMPLES , sparseResidency16Samples ),
671 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_SPARSE_RESIDENCY_ALIASED , sparseResidencyAliased ),
672 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_VARIABLE_MULTISAMPLE_RATE , variableMultisampleRate ),
673 DEVICE_CORE_FEATURE_ENTRY(DEVICE_CORE_FEATURE_INHERITED_QUERIES , inheritedQueries ),
674 };
675
requireDeviceCoreFeature(const DeviceCoreFeature requiredFeature)676 bool Context::requireDeviceCoreFeature (const DeviceCoreFeature requiredFeature)
677 {
678 const vk::VkPhysicalDeviceFeatures& featuresAvailable = getDeviceFeatures();
679 const vk::VkBool32* featuresAvailableArray = (vk::VkBool32*)(&featuresAvailable);
680 const deUint32 requiredFeatureIndex = static_cast<deUint32>(requiredFeature);
681
682 DE_ASSERT(requiredFeatureIndex * sizeof(vk::VkBool32) < sizeof(featuresAvailable));
683 DE_ASSERT(deviceCoreFeaturesTable[requiredFeatureIndex].featureArrayIndex * sizeof(vk::VkBool32) == deviceCoreFeaturesTable[requiredFeatureIndex].featureArrayOffset);
684
685 if (featuresAvailableArray[requiredFeatureIndex] == DE_FALSE)
686 TCU_THROW(NotSupportedError, "Requested core feature is not supported: " + std::string(deviceCoreFeaturesTable[requiredFeatureIndex].featureName));
687
688 return true;
689 }
690
isExtendedStorageFormat(VkFormat format)691 static bool isExtendedStorageFormat (VkFormat format)
692 {
693 switch(format)
694 {
695 case VK_FORMAT_R8G8B8A8_UNORM:
696 case VK_FORMAT_R8G8B8A8_SNORM:
697 case VK_FORMAT_R8G8B8A8_UINT:
698 case VK_FORMAT_R8G8B8A8_SINT:
699 case VK_FORMAT_R32_UINT:
700 case VK_FORMAT_R32_SINT:
701 case VK_FORMAT_R32_SFLOAT:
702 case VK_FORMAT_R32G32_UINT:
703 case VK_FORMAT_R32G32_SINT:
704 case VK_FORMAT_R32G32_SFLOAT:
705 case VK_FORMAT_R32G32B32A32_UINT:
706 case VK_FORMAT_R32G32B32A32_SINT:
707 case VK_FORMAT_R32G32B32A32_SFLOAT:
708 case VK_FORMAT_R16G16B16A16_UINT:
709 case VK_FORMAT_R16G16B16A16_SINT:
710 case VK_FORMAT_R16G16B16A16_SFLOAT:
711 case VK_FORMAT_R16G16_SFLOAT:
712 case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
713 case VK_FORMAT_R16_SFLOAT:
714 case VK_FORMAT_R16G16B16A16_UNORM:
715 case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
716 case VK_FORMAT_R16G16_UNORM:
717 case VK_FORMAT_R8G8_UNORM:
718 case VK_FORMAT_R16_UNORM:
719 case VK_FORMAT_R8_UNORM:
720 case VK_FORMAT_R16G16B16A16_SNORM:
721 case VK_FORMAT_R16G16_SNORM:
722 case VK_FORMAT_R8G8_SNORM:
723 case VK_FORMAT_R16_SNORM:
724 case VK_FORMAT_R8_SNORM:
725 case VK_FORMAT_R16G16_SINT:
726 case VK_FORMAT_R8G8_SINT:
727 case VK_FORMAT_R16_SINT:
728 case VK_FORMAT_R8_SINT:
729 case VK_FORMAT_A2B10G10R10_UINT_PACK32:
730 case VK_FORMAT_R16G16_UINT:
731 case VK_FORMAT_R8G8_UINT:
732 case VK_FORMAT_R16_UINT:
733 case VK_FORMAT_R8_UINT:
734 return true;
735 default:
736 return false;
737 }
738 }
739
isDepthFormat(VkFormat format)740 static bool isDepthFormat (VkFormat format)
741 {
742 switch(format)
743 {
744 case VK_FORMAT_D16_UNORM:
745 case VK_FORMAT_X8_D24_UNORM_PACK32:
746 case VK_FORMAT_D32_SFLOAT:
747 case VK_FORMAT_D16_UNORM_S8_UINT:
748 case VK_FORMAT_D24_UNORM_S8_UINT:
749 case VK_FORMAT_D32_SFLOAT_S8_UINT:
750 return true;
751 default:
752 return false;
753 }
754 }
755
getRequiredFormatProperties(const vk::VkFormat & format) const756 vk::VkFormatProperties3KHR Context::getRequiredFormatProperties(const vk::VkFormat& format) const
757 {
758 vk::VkFormatProperties3KHR p;
759 p.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3_KHR;
760 p.pNext = DE_NULL;
761
762 vk::VkFormatProperties properties;
763 getInstanceInterface().getPhysicalDeviceFormatProperties(getPhysicalDevice(), format, &properties);
764 p.linearTilingFeatures = properties.linearTilingFeatures;
765 p.optimalTilingFeatures = properties.optimalTilingFeatures;
766 p.bufferFeatures = properties.bufferFeatures;
767
768 const vk::VkPhysicalDeviceFeatures& featuresAvailable = getDeviceFeatures();
769 if (isExtendedStorageFormat(format) && featuresAvailable.shaderStorageImageReadWithoutFormat)
770 {
771 if (p.linearTilingFeatures & VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT_KHR)
772 p.linearTilingFeatures |= VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT_KHR;
773 if (p.optimalTilingFeatures & VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT_KHR)
774 p.optimalTilingFeatures |= VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT_KHR;
775 }
776 if (isExtendedStorageFormat(format) && featuresAvailable.shaderStorageImageWriteWithoutFormat)
777 {
778 if (p.linearTilingFeatures & VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT_KHR)
779 p.linearTilingFeatures |= VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT_KHR;
780 if (p.optimalTilingFeatures & VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT_KHR)
781 p.optimalTilingFeatures |= VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT_KHR;
782 }
783 if (isDepthFormat(format) && (p.linearTilingFeatures & (VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT_KHR)))
784 p.linearTilingFeatures |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_DEPTH_COMPARISON_BIT_KHR;
785 if (isDepthFormat(format) && (p.optimalTilingFeatures & (VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT_KHR)))
786 p.optimalTilingFeatures |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_DEPTH_COMPARISON_BIT_KHR;
787
788 return p;
789 }
790
getFormatProperties(const vk::VkFormat & format) const791 vk::VkFormatProperties3KHR Context::getFormatProperties(const vk::VkFormat& format) const
792 {
793 if (isDeviceFunctionalitySupported(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME)) // "VK_KHR_format_feature_flags2"
794 {
795 vk::VkFormatProperties3KHR p;
796 p.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3_KHR;
797 p.pNext = DE_NULL;
798
799 vk::VkFormatProperties2 properties;
800 properties.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2;
801 properties.pNext = &p;
802
803 getInstanceInterface().getPhysicalDeviceFormatProperties2(getPhysicalDevice(), format, &properties);
804 return p;
805 }
806 else
807 return Context::getRequiredFormatProperties(format);
808 }
809
getInstanceProcAddr()810 void* Context::getInstanceProcAddr ()
811 {
812 return (void*)m_platformInterface.getGetInstanceProcAddr();
813 }
814
isBufferDeviceAddressSupported(void) const815 bool Context::isBufferDeviceAddressSupported(void) const
816 {
817 return isDeviceFunctionalitySupported("VK_KHR_buffer_device_address") ||
818 isDeviceFunctionalitySupported("VK_EXT_buffer_device_address");
819 }
820
hasDebugReportRecorder() const821 bool Context::hasDebugReportRecorder () const
822 {
823 return m_device->hasDebugReportRecorder();
824 }
825
getDebugReportRecorder() const826 vk::DebugReportRecorder& Context::getDebugReportRecorder () const
827 {
828 return m_device->getDebugReportRecorder();
829 }
830
831 // TestCase
832
initPrograms(SourceCollections &) const833 void TestCase::initPrograms (SourceCollections&) const
834 {
835 }
836
checkSupport(Context &) const837 void TestCase::checkSupport (Context&) const
838 {
839 }
840
delayedInit(void)841 void TestCase::delayedInit (void)
842 {
843 }
844
collectAndReportDebugMessages(vk::DebugReportRecorder & debugReportRecorder,Context & context)845 void collectAndReportDebugMessages(vk::DebugReportRecorder &debugReportRecorder, Context& context)
846 {
847 using DebugMessages = vk::DebugReportRecorder::MessageList;
848
849 const DebugMessages& messages = debugReportRecorder.getMessages();
850 tcu::TestLog& log = context.getTestContext().getLog();
851
852 if (messages.size() > 0)
853 {
854 const tcu::ScopedLogSection section (log, "DebugMessages", "Debug Messages");
855 int numErrors = 0;
856
857 for (const auto& msg : messages)
858 {
859 if (msg.shouldBeLogged())
860 log << tcu::TestLog::Message << msg << tcu::TestLog::EndMessage;
861
862 if (msg.isError())
863 numErrors += 1;
864 }
865
866 debugReportRecorder.clearMessages();
867
868 if (numErrors > 0)
869 {
870 string errorMsg = de::toString(numErrors) + " API usage errors found";
871 context.resultSetOnValidation(true);
872 context.getTestContext().setTestResult(QP_TEST_RESULT_INTERNAL_ERROR, errorMsg.c_str());
873 }
874 }
875 }
876
877 } // vkt
878