1 #ifndef HALIDE_RUNTIME_VULKAN_EXTENSIONS_H
2 #define HALIDE_RUNTIME_VULKAN_EXTENSIONS_H
38 void vk_set_layer_names_internal(
const char *n) {
48 const 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);
59 void vk_set_extension_names_internal(
const char *n) {
69 const char *vk_get_extension_names_internal(
void *user_context) {
71 const char *name =
getenv(
"HL_VK_EXTENSIONS");
72 vk_set_extension_names_internal(name);
77 void vk_set_device_type_internal(
const char *n) {
87 const 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);
95 void vk_set_build_options_internal(
const char *n) {
105 const 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);
113 void vk_set_alloc_config_internal(
const char *n) {
123 const 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);
135 const char *
layer_names = vk_get_layer_names_internal(user_context);
140 const char *required_ext_table[] = {
"VK_KHR_get_physical_device_properties2"};
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;
146 uint32_t vk_get_supported_instance_extensions(
void *user_context,
StringTable &ext_table) {
152 debug(user_context) <<
"Vulkan: Missing vkEnumerateInstanceExtensionProperties proc address! Invalid loader?!\n";
158 debug(user_context) <<
"Vulkan: vkEnumerateInstanceExtensionProperties found " << avail_ext_count <<
" extensions ...\n";
160 if (avail_ext_count) {
165 BlockStorage extension_properties(user_context, config);
166 extension_properties.
resize(user_context, avail_ext_count);
171 for (
uint32_t n = 0; n < avail_ext_count; ++n) {
173 debug(user_context) <<
" extension: " << properties->
extensionName <<
"\n";
176 ext_table.
resize(user_context, avail_ext_count);
177 for (
uint32_t n = 0; n < avail_ext_count; ++n) {
183 return avail_ext_count;
187 const char *required_ext_table[] = {
"VK_KHR_8bit_storage",
"VK_KHR_storage_buffer_storage_class"};
188 const uint32_t required_ext_count =
sizeof(required_ext_table) /
sizeof(required_ext_table[0]);
189 ext_table.
fill(user_context, (
const char **)required_ext_table, required_ext_count);
190 return required_ext_count;
194 const char *optional_ext_table[] = {
195 "VK_KHR_portability_subset",
196 "VK_KHR_16bit_storage",
197 "VK_KHR_shader_float16_int8",
198 "VK_KHR_shader_float_controls"};
199 const uint32_t optional_ext_count =
sizeof(optional_ext_table) /
sizeof(optional_ext_table[0]);
201 ext_table.
resize(user_context, optional_ext_count);
202 for (
uint32_t n = 0; n < optional_ext_count; ++n) {
203 ext_table.
assign(user_context, n, optional_ext_table[n]);
205 return optional_ext_count;
208 uint32_t vk_get_supported_device_extensions(
void *user_context, VkPhysicalDevice physical_device,
StringTable &ext_table) {
209 debug(user_context) <<
"vk_get_supported_device_extensions\n";
211 debug(user_context) <<
"Vulkan: Missing vkEnumerateDeviceExtensionProperties proc address! Invalid loader?!\n";
217 debug(user_context) <<
"Vulkan: vkEnumerateDeviceExtensionProperties found " << avail_ext_count <<
" extensions ...\n";
219 if (avail_ext_count > 0) {
224 BlockStorage extension_properties(user_context, config);
225 extension_properties.
resize(user_context, avail_ext_count);
230 for (
uint32_t n = 0; n < avail_ext_count; ++n) {
232 debug(user_context) <<
" extension: " << properties->
extensionName <<
"\n";
235 ext_table.
resize(user_context, avail_ext_count);
236 for (
uint32_t n = 0; n < avail_ext_count; ++n) {
242 return avail_ext_count;
245 bool vk_validate_required_extension_support(
void *user_context,
248 bool validated =
true;
249 for (
uint32_t n = 0; n < required_extensions.
size(); ++n) {
250 const char *extension = required_extensions[n];
251 if (!supported_extensions.
contains(extension)) {
252 debug(user_context) <<
"Vulkan: Missing required extension: '" << extension <<
"'! \n";
279 vk_set_layer_names_internal(n);
284 return vk_get_layer_names_internal(user_context);
289 vk_set_extension_names_internal(n);
294 return vk_get_extension_names_internal(user_context);
299 vk_set_device_type_internal(n);
304 return vk_get_device_type_internal(user_context);
309 vk_set_build_options_internal(n);
314 return vk_get_build_options_internal(user_context);
319 vk_set_alloc_config_internal(n);
324 return vk_get_alloc_config_internal(user_context);
331 #endif // HALIDE_RUNTIME_VULKAN_EXTENSIONS_H