1#ifndef HALIDE_RUNTIME_VULKAN_EXTENSIONS_H
2#define HALIDE_RUNTIME_VULKAN_EXTENSIONS_H
38void vk_set_layer_names_internal(
const char *n) {
48const char *vk_get_layer_names_internal(
void *
user_context) {
50 const char *value =
getenv(
"HL_VK_LAYERS");
51 if (value ==
nullptr) {
52 value =
getenv(
"VK_INSTANCE_LAYERS");
54 vk_set_layer_names_internal(value);
59void vk_set_extension_names_internal(
const char *n) {
69const char *vk_get_extension_names_internal(
void *
user_context) {
71 const char *name =
getenv(
"HL_VK_EXTENSIONS");
72 vk_set_extension_names_internal(name);
77void vk_set_device_type_internal(
const char *n) {
87const char *vk_get_device_type_internal(
void *
user_context) {
89 const char *name =
getenv(
"HL_VK_DEVICE_TYPE");
90 vk_set_device_type_internal(name);
95void vk_set_build_options_internal(
const char *n) {
105const char *vk_get_build_options_internal(
void *
user_context) {
107 const char *name =
getenv(
"HL_VK_BUILD_OPTIONS");
108 vk_set_build_options_internal(name);
113void vk_set_alloc_config_internal(
const char *n) {
123const char *vk_get_alloc_config_internal(
void *
user_context) {
125 const char *name =
getenv(
"HL_VK_ALLOC_CONFIG");
126 vk_set_alloc_config_internal(name);
140 const char *required_ext_table[] = {VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME};
141 const uint32_t required_ext_count =
sizeof(required_ext_table) /
sizeof(required_ext_table[0]);
142 ext_table.
fill(
user_context, (
const char **)required_ext_table, required_ext_count);
143 return required_ext_count;
147 const char *optional_ext_table[] = {VK_EXT_DEBUG_UTILS_EXTENSION_NAME};
148 const uint32_t optional_ext_count =
sizeof(optional_ext_table) /
sizeof(optional_ext_table[0]);
149 ext_table.
fill(
user_context, (
const char **)optional_ext_table, optional_ext_count);
150 return optional_ext_count;
155 PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties = (PFN_vkEnumerateInstanceExtensionProperties)
156 vkGetInstanceProcAddr(
nullptr,
"vkEnumerateInstanceExtensionProperties");
158 if (vkEnumerateInstanceExtensionProperties ==
nullptr) {
159 debug(
user_context) <<
"Vulkan: Missing vkEnumerateInstanceExtensionProperties proc address! Invalid loader?!\n";
163 debug(
user_context) <<
"Vulkan: Checking vkEnumerateInstanceExtensionProperties for extensions ...\n";
166 vkEnumerateInstanceExtensionProperties(
nullptr, &avail_ext_count,
nullptr);
168 if (avail_ext_count) {
170 config.
entry_size =
sizeof(VkExtensionProperties);
176 vkEnumerateInstanceExtensionProperties(
nullptr,
177 &avail_ext_count,
static_cast<VkExtensionProperties *
>(extension_properties.
data()));
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";
185 for (
uint32_t n = 0; n < avail_ext_count; ++n) {
186 const VkExtensionProperties *properties =
static_cast<const VkExtensionProperties *
>(extension_properties[n]);
190 debug(
user_context) <<
"Vulkan: vkEnumerateInstanceExtensionProperties found " << avail_ext_count <<
" extensions ...\n";
191 return avail_ext_count;
195 const char *required_ext_table[] = {
196 VK_KHR_8BIT_STORAGE_EXTENSION_NAME,
197 VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_EXTENSION_NAME};
198 const uint32_t required_ext_count =
sizeof(required_ext_table) /
sizeof(required_ext_table[0]);
199 ext_table.
fill(
user_context, (
const char **)required_ext_table, required_ext_count);
200 return required_ext_count;
204 const char *optional_ext_table[] = {
205 "VK_KHR_portability_subset",
206 VK_KHR_MAINTENANCE_5_EXTENSION_NAME,
207 VK_KHR_16BIT_STORAGE_EXTENSION_NAME,
208 VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME,
209 VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME};
210 const uint32_t optional_ext_count =
sizeof(optional_ext_table) /
sizeof(optional_ext_table[0]);
211 ext_table.
fill(
user_context, (
const char **)optional_ext_table, optional_ext_count);
212 return optional_ext_count;
216 debug(
user_context) <<
"vk_get_supported_device_extensions\n";
217 if (vkEnumerateDeviceExtensionProperties ==
nullptr) {
218 debug(
user_context) <<
"Vulkan: Missing vkEnumerateDeviceExtensionProperties proc address! Invalid loader?!\n";
222 debug(
user_context) <<
"Vulkan: Checking vkEnumerateDeviceExtensionProperties for extensions ...\n";
225 vkEnumerateDeviceExtensionProperties(physical_device,
nullptr, &avail_ext_count,
nullptr);
226 if (avail_ext_count > 0) {
228 config.
entry_size =
sizeof(VkExtensionProperties);
234 vkEnumerateDeviceExtensionProperties(physical_device,
nullptr,
235 &avail_ext_count,
static_cast<VkExtensionProperties *
>(extension_properties.
data()));
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";
243 for (
uint32_t n = 0; n < avail_ext_count; ++n) {
244 const VkExtensionProperties *properties =
static_cast<const VkExtensionProperties *
>(extension_properties[n]);
249 debug(
user_context) <<
"Vulkan: vkEnumerateDeviceExtensionProperties found " << avail_ext_count <<
" extensions ...\n";
250 return avail_ext_count;
253bool vk_validate_required_extension_support(
void *
user_context,
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";
288 vk_set_layer_names_internal(n);
298 vk_set_extension_names_internal(n);
308 vk_set_device_type_internal(n);
318 vk_set_build_options_internal(n);
328 vk_set_alloc_config_internal(n);
void resize(void *user_context, size_t entry_count, bool realloc=true)
size_t parse(void *user_context, const char *str, const char *delim)
void assign(void *user_context, size_t index, const char *str, size_t length=0)
void resize(void *user_context, size_t capacity)
void fill(void *user_context, const char **array, size_t count)
bool contains(const char *str) const
WEAK bool layer_names_initialized
WEAK ScopedSpinLock::AtomicFlag alloc_config_lock
WEAK char build_options[1024]
WEAK char layer_names[1024]
WEAK bool build_options_initialized
WEAK ScopedSpinLock::AtomicFlag extension_names_lock
WEAK bool device_type_initialized
WEAK bool alloc_config_initialized
WEAK ScopedSpinLock::AtomicFlag layer_names_lock
WEAK ScopedSpinLock::AtomicFlag build_options_lock
WEAK char alloc_config[1024]
WEAK char device_type[256]
WEAK bool extension_names_initialized
WEAK ScopedSpinLock::AtomicFlag device_type_lock
WEAK char extension_names[1024]
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
unsigned __INT32_TYPE__ uint32_t
char * getenv(const char *)
uint32_t minimum_capacity
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)