mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-19 21:28:50 +00:00
c/main: Make more use of string list for device ext
This commit is contained in:
parent
f34816872c
commit
ce6339e237
|
@ -1231,7 +1231,7 @@ vk_check_extension(struct vk_bundle *vk, VkExtensionProperties *props, uint32_t
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fill_in_has_extensions(struct vk_bundle *vk, const char **device_extensions, uint32_t device_extension_count)
|
fill_in_has_extensions(struct vk_bundle *vk, const char *const *device_extensions, uint32_t device_extension_count)
|
||||||
{
|
{
|
||||||
// beginning of GENERATED extension code - do not modify - used by scripts
|
// beginning of GENERATED extension code - do not modify - used by scripts
|
||||||
// Reset before filling out.
|
// Reset before filling out.
|
||||||
|
@ -1299,12 +1299,9 @@ vk_get_device_ext_props(struct vk_bundle *vk,
|
||||||
static bool
|
static bool
|
||||||
vk_build_device_extensions(struct vk_bundle *vk,
|
vk_build_device_extensions(struct vk_bundle *vk,
|
||||||
VkPhysicalDevice physical_device,
|
VkPhysicalDevice physical_device,
|
||||||
const char *const *required_device_extensions,
|
struct u_string_list *required_device_ext_list,
|
||||||
uint32_t required_device_extension_count,
|
struct u_string_list *optional_device_ext_list,
|
||||||
const char *const *optional_device_extensions,
|
struct u_string_list **out_device_ext_list)
|
||||||
uint32_t optional_device_extension_count,
|
|
||||||
const char ***out_device_extensions,
|
|
||||||
uint32_t *out_device_extension_count)
|
|
||||||
{
|
{
|
||||||
VkExtensionProperties *props = NULL;
|
VkExtensionProperties *props = NULL;
|
||||||
uint32_t prop_count = 0;
|
uint32_t prop_count = 0;
|
||||||
|
@ -1312,27 +1309,35 @@ vk_build_device_extensions(struct vk_bundle *vk,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t max_exts = required_device_extension_count + optional_device_extension_count;
|
uint32_t required_device_ext_count = u_string_list_get_size(required_device_ext_list);
|
||||||
|
const char *const *required_device_exts = u_string_list_get_data(required_device_ext_list);
|
||||||
|
|
||||||
const char **device_extensions = U_TYPED_ARRAY_CALLOC(const char *, max_exts);
|
// error out if we don't support one of the required extensions
|
||||||
|
for (uint32_t i = 0; i < required_device_ext_count; i++) {
|
||||||
for (uint32_t i = 0; i < required_device_extension_count; i++) {
|
const char *ext = required_device_exts[i];
|
||||||
const char *ext = required_device_extensions[i];
|
|
||||||
if (!vk_check_extension(vk, props, prop_count, ext)) {
|
if (!vk_check_extension(vk, props, prop_count, ext)) {
|
||||||
U_LOG_E("VkPhysicalDevice does not support required extension %s", ext);
|
U_LOG_E("VkPhysicalDevice does not support required extension %s", ext);
|
||||||
free(props);
|
free(props);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
U_LOG_T("Using required device ext %s", ext);
|
U_LOG_T("Using required device ext %s", ext);
|
||||||
device_extensions[i] = ext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t device_extension_count = required_device_extension_count;
|
|
||||||
for (uint32_t i = 0; i < optional_device_extension_count; i++) {
|
*out_device_ext_list = u_string_list_create_from_list(required_device_ext_list);
|
||||||
const char *ext = optional_device_extensions[i];
|
|
||||||
|
|
||||||
|
uint32_t optional_device_ext_count = u_string_list_get_size(optional_device_ext_list);
|
||||||
|
const char *const *optional_device_exts = u_string_list_get_data(optional_device_ext_list);
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < optional_device_ext_count; i++) {
|
||||||
|
const char *ext = optional_device_exts[i];
|
||||||
if (vk_check_extension(vk, props, prop_count, ext)) {
|
if (vk_check_extension(vk, props, prop_count, ext)) {
|
||||||
U_LOG_D("Using optional device ext %s", ext);
|
U_LOG_D("Using optional device ext %s", ext);
|
||||||
device_extensions[device_extension_count++] = ext;
|
int added = u_string_list_append_unique(*out_device_ext_list, ext);
|
||||||
|
if (added == 0) {
|
||||||
|
U_LOG_W("Duplicate device extension %s not added twice", ext);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
U_LOG_T("NOT using optional device ext %s", ext);
|
U_LOG_T("NOT using optional device ext %s", ext);
|
||||||
continue;
|
continue;
|
||||||
|
@ -1340,12 +1345,11 @@ vk_build_device_extensions(struct vk_bundle *vk,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill this out here.
|
// Fill this out here.
|
||||||
fill_in_has_extensions(vk, device_extensions, device_extension_count);
|
fill_in_has_extensions(vk, u_string_list_get_data(*out_device_ext_list),
|
||||||
|
u_string_list_get_size(*out_device_ext_list));
|
||||||
|
|
||||||
free(props);
|
free(props);
|
||||||
|
|
||||||
*out_device_extensions = device_extensions;
|
|
||||||
*out_device_extension_count = device_extension_count;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1455,10 +1459,8 @@ vk_create_device(struct vk_bundle *vk,
|
||||||
int forced_index,
|
int forced_index,
|
||||||
bool only_compute,
|
bool only_compute,
|
||||||
VkQueueGlobalPriorityEXT global_priority,
|
VkQueueGlobalPriorityEXT global_priority,
|
||||||
const char *const *required_device_extensions,
|
struct u_string_list *required_device_ext_list,
|
||||||
size_t required_device_extension_count,
|
struct u_string_list *optional_device_ext_list,
|
||||||
const char *const *optional_device_extensions,
|
|
||||||
size_t optional_device_extension_count,
|
|
||||||
const struct vk_device_features *optional_device_features)
|
const struct vk_device_features *optional_device_features)
|
||||||
{
|
{
|
||||||
VkResult ret;
|
VkResult ret;
|
||||||
|
@ -1468,11 +1470,9 @@ vk_create_device(struct vk_bundle *vk,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char **device_extensions;
|
struct u_string_list *device_ext_list = NULL;
|
||||||
uint32_t device_extension_count;
|
if (!vk_build_device_extensions(vk, vk->physical_device, required_device_ext_list, optional_device_ext_list,
|
||||||
if (!vk_build_device_extensions(vk, vk->physical_device, required_device_extensions,
|
&device_ext_list)) {
|
||||||
required_device_extension_count, optional_device_extensions,
|
|
||||||
optional_device_extension_count, &device_extensions, &device_extension_count)) {
|
|
||||||
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1548,8 +1548,8 @@ vk_create_device(struct vk_bundle *vk,
|
||||||
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
||||||
.queueCreateInfoCount = 1,
|
.queueCreateInfoCount = 1,
|
||||||
.pQueueCreateInfos = &queue_create_info,
|
.pQueueCreateInfos = &queue_create_info,
|
||||||
.enabledExtensionCount = device_extension_count,
|
.enabledExtensionCount = u_string_list_get_size(device_ext_list),
|
||||||
.ppEnabledExtensionNames = device_extensions,
|
.ppEnabledExtensionNames = u_string_list_get_data(device_ext_list),
|
||||||
.pEnabledFeatures = &enabled_features,
|
.pEnabledFeatures = &enabled_features,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1568,7 +1568,7 @@ vk_create_device(struct vk_bundle *vk,
|
||||||
|
|
||||||
ret = vk->vkCreateDevice(vk->physical_device, &device_create_info, NULL, &vk->device);
|
ret = vk->vkCreateDevice(vk->physical_device, &device_create_info, NULL, &vk->device);
|
||||||
|
|
||||||
free(device_extensions);
|
u_string_list_destroy(&device_ext_list);
|
||||||
|
|
||||||
if (ret != VK_SUCCESS) {
|
if (ret != VK_SUCCESS) {
|
||||||
VK_DEBUG(vk, "vkCreateDevice: %s (%d)", vk_result_string(ret), ret);
|
VK_DEBUG(vk, "vkCreateDevice: %s (%d)", vk_result_string(ret), ret);
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "xrt/xrt_vulkan_includes.h"
|
#include "xrt/xrt_vulkan_includes.h"
|
||||||
#include "xrt/xrt_handles.h"
|
#include "xrt/xrt_handles.h"
|
||||||
#include "util/u_logging.h"
|
#include "util/u_logging.h"
|
||||||
|
#include "util/u_string_list.h"
|
||||||
#include "os/os_threading.h"
|
#include "os/os_threading.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -433,10 +434,8 @@ vk_create_device(struct vk_bundle *vk,
|
||||||
int forced_index,
|
int forced_index,
|
||||||
bool only_compute,
|
bool only_compute,
|
||||||
VkQueueGlobalPriorityEXT global_priorty,
|
VkQueueGlobalPriorityEXT global_priorty,
|
||||||
const char *const *required_device_extensions,
|
struct u_string_list *required_device_ext_list,
|
||||||
size_t required_device_extension_count,
|
struct u_string_list *optional_device_ext_list,
|
||||||
const char *const *optional_device_extensions,
|
|
||||||
size_t optional_device_extension_count,
|
|
||||||
const struct vk_device_features *optional_device_features);
|
const struct vk_device_features *optional_device_features);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -893,18 +893,27 @@ compositor_check_vulkan_caps(struct comp_compositor *c)
|
||||||
|
|
||||||
bool use_compute = c->settings.use_compute;
|
bool use_compute = c->settings.use_compute;
|
||||||
|
|
||||||
|
struct u_string_list *required_device_ext_list =
|
||||||
|
u_string_list_create_with_capacity(ARRAY_SIZE(required_device_extensions));
|
||||||
|
append_all(c, required_device_ext_list, required_device_extensions, ARRAY_SIZE(required_device_extensions));
|
||||||
|
|
||||||
|
struct u_string_list *optional_device_ext_list =
|
||||||
|
u_string_list_create_with_capacity(ARRAY_SIZE(optional_device_extensions));
|
||||||
|
append_all(c, optional_device_ext_list, optional_device_extensions, ARRAY_SIZE(optional_device_extensions));
|
||||||
|
|
||||||
// follow same device selection logic as subsequent calls
|
// follow same device selection logic as subsequent calls
|
||||||
ret = vk_create_device( //
|
ret = vk_create_device( //
|
||||||
temp_vk, //
|
temp_vk, //
|
||||||
c->settings.selected_gpu_index, //
|
c->settings.selected_gpu_index, //
|
||||||
use_compute, // compute_only
|
use_compute, // compute_only
|
||||||
VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT, // global_priority
|
VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT, // global_priority
|
||||||
required_device_extensions, //
|
required_device_ext_list, //
|
||||||
ARRAY_SIZE(required_device_extensions), //
|
optional_device_ext_list, //
|
||||||
optional_device_extensions, //
|
|
||||||
ARRAY_SIZE(optional_device_extensions), //
|
|
||||||
NULL); // optional_device_features
|
NULL); // optional_device_features
|
||||||
|
|
||||||
|
u_string_list_destroy(&required_device_ext_list);
|
||||||
|
u_string_list_destroy(&optional_device_ext_list);
|
||||||
|
|
||||||
if (ret != VK_SUCCESS) {
|
if (ret != VK_SUCCESS) {
|
||||||
CVK_ERROR(c, "vk_create_device", "Failed to create VkDevice.", ret);
|
CVK_ERROR(c, "vk_create_device", "Failed to create VkDevice.", ret);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -171,10 +171,8 @@ create_device(struct vk_bundle *vk, const struct comp_vulkan_arguments *vk_args)
|
||||||
vk_args->selected_gpu_index, //
|
vk_args->selected_gpu_index, //
|
||||||
only_compute_queue, // compute_only
|
only_compute_queue, // compute_only
|
||||||
prios[i], // global_priority
|
prios[i], // global_priority
|
||||||
u_string_list_get_data(vk_args->required_device_extensions), //
|
vk_args->required_device_extensions, //
|
||||||
u_string_list_get_size(vk_args->required_device_extensions), //
|
vk_args->optional_device_extensions, //
|
||||||
u_string_list_get_data(vk_args->optional_device_extensions), //
|
|
||||||
u_string_list_get_size(vk_args->optional_device_extensions), //
|
|
||||||
&device_features); // optional_device_features
|
&device_features); // optional_device_features
|
||||||
|
|
||||||
// All ok!
|
// All ok!
|
||||||
|
|
Loading…
Reference in a new issue