1 /*-------------------------------------------------------------------------
2 * Vulkan CTS Framework
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 Instance and device initialization utilities.
22 *//*--------------------------------------------------------------------*/
23
24 #include "vkDeviceUtil.hpp"
25 #include "vkQueryUtil.hpp"
26 #include "vkRefUtil.hpp"
27 #include "vkApiVersion.hpp"
28
29 #include "tcuCommandLine.hpp"
30
31 #include "qpInfo.h"
32
33 namespace vk
34 {
35
36 using std::vector;
37 using std::string;
38
createDefaultInstance(const PlatformInterface & vkPlatform,const vector<string> & enabledLayers,const vector<string> & enabledExtensions,const VkAllocationCallbacks * pAllocator)39 Move<VkInstance> createDefaultInstance (const PlatformInterface& vkPlatform,
40 const vector<string>& enabledLayers,
41 const vector<string>& enabledExtensions,
42 const VkAllocationCallbacks* pAllocator)
43 {
44 vector<const char*> layerNamePtrs (enabledLayers.size());
45 vector<const char*> extensionNamePtrs (enabledExtensions.size());
46 const deUint32 apiVersion = pack(ApiVersion(1, 0, 0));
47
48 const struct VkApplicationInfo appInfo =
49 {
50 VK_STRUCTURE_TYPE_APPLICATION_INFO,
51 DE_NULL,
52 "deqp", // pAppName
53 qpGetReleaseId(), // appVersion
54 "deqp", // pEngineName
55 qpGetReleaseId(), // engineVersion
56 apiVersion // apiVersion
57 };
58 const struct VkInstanceCreateInfo instanceInfo =
59 {
60 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
61 DE_NULL,
62 (VkInstanceCreateFlags)0,
63 &appInfo,
64 (deUint32)layerNamePtrs.size(),
65 layerNamePtrs.empty() ? DE_NULL : &layerNamePtrs[0],
66 (deUint32)extensionNamePtrs.size(),
67 extensionNamePtrs.empty() ? DE_NULL : &extensionNamePtrs[0],
68 };
69
70 for (size_t ndx = 0; ndx < enabledLayers.size(); ++ndx)
71 layerNamePtrs[ndx] = enabledLayers[ndx].c_str();
72
73 for (size_t ndx = 0; ndx < enabledExtensions.size(); ++ndx)
74 extensionNamePtrs[ndx] = enabledExtensions[ndx].c_str();
75
76 return createInstance(vkPlatform, &instanceInfo, pAllocator);
77 }
78
createDefaultInstance(const PlatformInterface & vkPlatform)79 Move<VkInstance> createDefaultInstance (const PlatformInterface& vkPlatform)
80 {
81 return createDefaultInstance(vkPlatform, vector<string>(), vector<string>(), DE_NULL);
82 }
83
chooseDevice(const InstanceInterface & vkInstance,VkInstance instance,const tcu::CommandLine & cmdLine)84 VkPhysicalDevice chooseDevice (const InstanceInterface& vkInstance, VkInstance instance, const tcu::CommandLine& cmdLine)
85 {
86 const vector<VkPhysicalDevice> devices = enumeratePhysicalDevices(vkInstance, instance);
87
88 if (devices.empty())
89 TCU_THROW(NotSupportedError, "No Vulkan devices available");
90
91 if (!de::inBounds(cmdLine.getVKDeviceId(), 1, (int)devices.size()+1))
92 TCU_THROW(InternalError, "Invalid --deqp-vk-device-id");
93
94 return devices[(size_t)(cmdLine.getVKDeviceId()-1)];
95 }
96
97 } // vk
98