1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#define LOG_TAG "vkprofiles"
#ifndef VK_USE_PLATFORM_ANDROID_KHR
#define VK_USE_PLATFORM_ANDROID_KHR
#endif
#include <string>
#include <vector>
#include <android/log.h>
#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#include "generated/vulkan_profiles.h"
#include "vkprofiles.h"
namespace android::vkprofiles {
/* Wrap vkProfileGetSupport in an anonymous namespace.
* vkProfileGetSupport only works for profiles that we explicitly add, we don't
* want a user of this library to mistakenly call with a profile that we haven't
* added.
*/
namespace {
std::string vkProfileGetSupport(const VpProfileProperties* pProfile,
const uint32_t minApiVersion) {
VkResult result = VK_SUCCESS;
VkBool32 supported = VK_FALSE;
result = vpGetInstanceProfileSupport(nullptr, pProfile, &supported);
if (result != VK_SUCCESS) {
std::string error(
"There was a failure from vpGetInstanceProfileSupport,"
" check `vkprofiles` in logcat."
" result = " +
std::to_string(result));
return error;
}
if (supported != VK_TRUE) {
std::string error(
"There was a failure from vpGetInstanceProfileSupport,"
" check `vkprofiles` in logcat."
" supported = " +
std::to_string(supported));
return error;
}
const VkApplicationInfo appInfo = {
VK_STRUCTURE_TYPE_APPLICATION_INFO,
nullptr,
"vkprofiles",
0,
"",
0,
minApiVersion,
};
VkInstanceCreateInfo instanceCreateInfo = {
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
nullptr,
0,
&appInfo,
0,
nullptr,
0,
nullptr,
};
VpInstanceCreateInfo vpInstanceCreateInfo{};
vpInstanceCreateInfo.pCreateInfo = &instanceCreateInfo;
vpInstanceCreateInfo.enabledFullProfileCount = 1;
vpInstanceCreateInfo.pEnabledFullProfiles = pProfile;
VkInstance instance = VK_NULL_HANDLE;
result = vpCreateInstance(&vpInstanceCreateInfo, nullptr, &instance);
if (result != VK_SUCCESS) {
std::string error(
"There was a failure from vpCreateInstance,"
" check `vkprofiles` in logcat."
" result = " +
std::to_string(result));
return error;
}
uint32_t count;
result = vkEnumeratePhysicalDevices(instance, &count, nullptr);
if (result != VK_SUCCESS) {
vkDestroyInstance(instance, nullptr);
std::string error(
"There was a failure from vkEnumeratePhysicalDevices,"
" check `vkprofiles` in logcat."
" result = " +
std::to_string(result));
return error;
}
std::vector<VkPhysicalDevice> devices(count, VK_NULL_HANDLE);
result = vkEnumeratePhysicalDevices(instance, &count, devices.data());
if (result != VK_SUCCESS) {
vkDestroyInstance(instance, nullptr);
std::string error(
"There was a failure from vkEnumeratePhysicalDevices (2),"
" check `vkprofiles` in logcat."
" result = " +
std::to_string(result));
return error;
}
bool onePhysicalDeviceSupports = false;
for (size_t i = 0; i < count; i++) {
result = vpGetPhysicalDeviceProfileSupport(instance, devices[i],
pProfile, &supported);
if (result != VK_SUCCESS) {
ALOGD("vpGetPhysicalDeviceProfileSupport fail, result = %d",
result);
continue;
} else if (supported != VK_TRUE) {
ALOGD("vpGetPhysicalDeviceProfileSupport fail, supported = %d",
supported);
continue;
}
onePhysicalDeviceSupports = true;
}
if (!onePhysicalDeviceSupports) {
std::string error(
"There was a failure from vpGetPhysicalDeviceProfileSupport,"
" check `vkprofiles` in logcat."
" No VkPhysicalDevice supports the profile");
return error;
}
return std::string("SUPPORTED");
}
} // anonymous namespace
std::string vkAbp2021GetSupport() {
VpProfileProperties profile{VP_ANDROID_BASELINE_2021_NAME,
VP_ANDROID_BASELINE_2021_SPEC_VERSION};
return vkProfileGetSupport(&profile,
VP_ANDROID_BASELINE_2021_MIN_API_VERSION);
}
std::string vkAbp2021CpuOnlyGetSupport() {
VpProfileProperties profile{VP_ANDROID_BASELINE_2021_CPU_ONLY_NAME,
VP_ANDROID_BASELINE_2021_CPU_ONLY_SPEC_VERSION};
return vkProfileGetSupport(&profile,
VP_ANDROID_BASELINE_2021_MIN_API_VERSION);
}
std::string vkAbp2022GetSupport() {
VpProfileProperties profile{VP_ANDROID_BASELINE_2022_NAME,
VP_ANDROID_BASELINE_2022_SPEC_VERSION};
return vkProfileGetSupport(&profile,
VP_ANDROID_BASELINE_2022_MIN_API_VERSION);
}
std::string vkVpa15GetSupport() {
VpProfileProperties profile{VP_ANDROID_15_MINIMUMS_NAME,
VP_ANDROID_15_MINIMUMS_SPEC_VERSION};
return vkProfileGetSupport(&profile,
VP_ANDROID_15_MINIMUMS_MIN_API_VERSION);
}
std::string vkVpa16GetSupport() {
VpProfileProperties profile{VP_ANDROID_16_MINIMUMS_NAME,
VP_ANDROID_16_MINIMUMS_SPEC_VERSION};
return vkProfileGetSupport(&profile,
VP_ANDROID_16_MINIMUMS_MIN_API_VERSION);
}
std::string vkProfiles() {
return "{"
"\"" + std::string(VP_ANDROID_BASELINE_2021_NAME) + "\": "
"\"" + vkAbp2021GetSupport() + "\","
"\"" + std::string(VP_ANDROID_BASELINE_2021_CPU_ONLY_NAME) + "\": "
"\"" + vkAbp2021CpuOnlyGetSupport() + "\","
"\"" + std::string(VP_ANDROID_BASELINE_2022_NAME) + "\": "
"\"" + vkAbp2022GetSupport() + "\","
"\"" + std::string(VP_ANDROID_15_MINIMUMS_NAME) + "\": "
"\"" + vkVpa15GetSupport() + "\","
"\"" + std::string(VP_ANDROID_16_MINIMUMS_NAME) + "\": "
"\"" + vkVpa16GetSupport() + "\""
"}";
}
} // namespace android::vkprofiles
|