Halide 20.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
vulkan_extensions.h
Go to the documentation of this file.
1#ifndef HALIDE_RUNTIME_VULKAN_EXTENSIONS_H
2#define HALIDE_RUNTIME_VULKAN_EXTENSIONS_H
3
4#include "vulkan_internal.h"
5
6// --------------------------------------------------------------------------
7
8namespace Halide {
9namespace Runtime {
10namespace Internal {
11namespace Vulkan {
12
13// --------------------------------------------------------------------------
14
15WEAK char layer_names[1024];
18
22
23WEAK char device_type[256];
26
30
31WEAK char alloc_config[1024];
34
35// --------------------------------------------------------------------------
36namespace {
37
38void vk_set_layer_names_internal(const char *n) {
39 if (n) {
40 size_t buffer_size = sizeof(layer_names) / sizeof(layer_names[0]);
42 } else {
43 layer_names[0] = 0;
44 }
46}
47
50 const char *value = getenv("HL_VK_LAYERS");
51 if (value == nullptr) {
52 value = getenv("VK_INSTANCE_LAYERS");
53 }
55 }
56 return layer_names;
57}
58
59void vk_set_extension_names_internal(const char *n) {
60 if (n) {
61 size_t buffer_size = sizeof(extension_names) / sizeof(extension_names[0]);
63 } else {
64 extension_names[0] = 0;
65 }
67}
68
71 const char *name = getenv("HL_VK_EXTENSIONS");
73 }
74 return extension_names;
75}
76
77void vk_set_device_type_internal(const char *n) {
78 if (n) {
79 size_t buffer_size = sizeof(device_type) / sizeof(device_type[0]);
81 } else {
82 device_type[0] = 0;
83 }
85}
86
89 const char *name = getenv("HL_VK_DEVICE_TYPE");
91 }
92 return device_type;
93}
94
95void vk_set_build_options_internal(const char *n) {
96 if (n) {
97 size_t buffer_size = sizeof(build_options) / sizeof(build_options[0]);
99 } else {
100 build_options[0] = 0;
101 }
103}
104
107 const char *name = getenv("HL_VK_BUILD_OPTIONS");
109 }
110 return build_options;
111}
112
113void vk_set_alloc_config_internal(const char *n) {
114 if (n) {
115 size_t buffer_size = sizeof(alloc_config) / sizeof(alloc_config[0]);
117 } else {
118 alloc_config[0] = 0;
119 }
121}
122
125 const char *name = getenv("HL_VK_ALLOC_CONFIG");
127 }
128 return alloc_config;
129}
130
131// --------------------------------------------------------------------------
132
137}
138
143 return required_ext_count;
144}
145
150 return optional_ext_count;
151}
152
154
156 vkGetInstanceProcAddr(nullptr, "vkEnumerateInstanceExtensionProperties");
157
159 debug(user_context) << "Vulkan: Missing vkEnumerateInstanceExtensionProperties proc address! Invalid loader?!\n";
160 return 0;
161 }
162
163 debug(user_context) << "Vulkan: Checking vkEnumerateInstanceExtensionProperties for extensions ...\n";
164
167
168 if (avail_ext_count) {
170 config.entry_size = sizeof(VkExtensionProperties);
172
175
178
179 for (uint32_t n = 0; n < avail_ext_count; ++n) {
180 const VkExtensionProperties *properties = static_cast<const VkExtensionProperties *>(extension_properties[n]);
181 debug(user_context) << " [" << n << "]: " << properties->extensionName << "\n";
182 }
183
185 for (uint32_t n = 0; n < avail_ext_count; ++n) {
186 const VkExtensionProperties *properties = static_cast<const VkExtensionProperties *>(extension_properties[n]);
187 ext_table.assign(user_context, n, properties->extensionName);
188 }
189 }
190 debug(user_context) << "Vulkan: vkEnumerateInstanceExtensionProperties found " << avail_ext_count << " extensions ...\n";
191 return avail_ext_count;
192}
193
195 const char *required_ext_table[] = {
200 return required_ext_count;
201}
202
204 const char *optional_ext_table[] = {
205 "VK_KHR_portability_subset", //< necessary for running under Molten (aka Vulkan on Mac)
212 return optional_ext_count;
213}
214
216 debug(user_context) << "vk_get_supported_device_extensions\n";
218 debug(user_context) << "Vulkan: Missing vkEnumerateDeviceExtensionProperties proc address! Invalid loader?!\n";
219 return 0;
220 }
221
222 debug(user_context) << "Vulkan: Checking vkEnumerateDeviceExtensionProperties for extensions ...\n";
223
225 vkEnumerateDeviceExtensionProperties(physical_device, nullptr, &avail_ext_count, nullptr);
226 if (avail_ext_count > 0) {
228 config.entry_size = sizeof(VkExtensionProperties);
230
233
234 vkEnumerateDeviceExtensionProperties(physical_device, nullptr,
236
237 for (uint32_t n = 0; n < avail_ext_count; ++n) {
238 const VkExtensionProperties *properties = static_cast<const VkExtensionProperties *>(extension_properties[n]);
239 debug(user_context) << " [" << n << "]: " << properties->extensionName << "\n";
240 }
241
243 for (uint32_t n = 0; n < avail_ext_count; ++n) {
244 const VkExtensionProperties *properties = static_cast<const VkExtensionProperties *>(extension_properties[n]);
245 ext_table.assign(user_context, n, properties->extensionName);
246 }
247 }
248
249 debug(user_context) << "Vulkan: vkEnumerateDeviceExtensionProperties found " << avail_ext_count << " extensions ...\n";
250 return avail_ext_count;
251}
252
256 debug(user_context) << "Vulkan: Validating " << uint32_t(required_extensions.size()) << " extensions ...\n";
257 bool validated = true;
258 for (uint32_t n = 0; n < required_extensions.size(); ++n) {
259 const char *extension = required_extensions[n];
260 if (!supported_extensions.contains(extension)) {
261 debug(user_context) << "Vulkan: Missing required extension: '" << extension << "'!\n";
262 validated = false;
263 }
264 }
265 return validated;
266}
267
268// --------------------------------------------------------------------------
269
270} // namespace
271} // namespace Vulkan
272} // namespace Internal
273} // namespace Runtime
274} // namespace Halide
275
276// --------------------------------------------------------------------------
277
279
280// --------------------------------------------------------------------------
281
282extern "C" {
283
284// --------------------------------------------------------------------------
285
288 vk_set_layer_names_internal(n);
289}
290
293 return vk_get_layer_names_internal(user_context);
294}
295
298 vk_set_extension_names_internal(n);
299}
300
303 return vk_get_extension_names_internal(user_context);
304}
305
308 vk_set_device_type_internal(n);
309}
310
313 return vk_get_device_type_internal(user_context);
314}
315
318 vk_set_build_options_internal(n);
319}
320
323 return vk_get_build_options_internal(user_context);
324}
325
328 vk_set_alloc_config_internal(n);
329}
330
333 return vk_get_alloc_config_internal(user_context);
334}
335
336// --------------------------------------------------------------------------
337
338} // extern "C"
339
340#endif // HALIDE_RUNTIME_VULKAN_EXTENSIONS_H
WEAK ScopedSpinLock::AtomicFlag alloc_config_lock
WEAK ScopedSpinLock::AtomicFlag extension_names_lock
WEAK ScopedSpinLock::AtomicFlag layer_names_lock
WEAK ScopedSpinLock::AtomicFlag build_options_lock
WEAK ScopedSpinLock::AtomicFlag device_type_lock
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
unsigned __INT32_TYPE__ uint32_t
#define WEAK
char * getenv(const char *)
bool contains(int32_t x) const
Test if the interval contains a particular value.
static size_t copy_up_to(char *dst, const char *src, size_t max_chars)
WEAK void halide_vulkan_set_layer_names(const char *n)
WEAK void halide_vulkan_set_build_options(const char *n)
WEAK void halide_vulkan_set_extension_names(const char *n)
WEAK void halide_vulkan_set_device_type(const char *n)
WEAK const char * halide_vulkan_get_alloc_config(void *user_context)
WEAK const char * halide_vulkan_get_layer_names(void *user_context)
WEAK void halide_vulkan_set_alloc_config(const char *n)
WEAK const char * halide_vulkan_get_build_options(void *user_context)
WEAK const char * halide_vulkan_get_extension_names(void *user_context)
WEAK const char * halide_vulkan_get_device_type(void *user_context)
#define HL_VK_ENV_DELIM
void * user_context