c/main: Use more enumeration helpers

This commit is contained in:
Jakob Bornecrantz 2023-08-25 14:27:51 +01:00
parent e37041cc61
commit e95b6932eb
3 changed files with 56 additions and 55 deletions

View file

@ -79,28 +79,35 @@ comp_window_direct_get_primary_display_mode(struct comp_target_swapchain *cts, V
{
struct vk_bundle *vk = get_vk(cts);
struct comp_target *ct = &cts->base;
uint32_t mode_count;
VkDisplayModePropertiesKHR *mode_properties = NULL;
uint32_t mode_count = 0;
VkResult ret;
ret = vk->vkGetDisplayModePropertiesKHR(vk->physical_device, display, &mode_count, NULL);
// Get plane properties
ret = vk_enumerate_display_mode_properties( //
vk, //
vk->physical_device, //
display, //
&mode_count, //
&mode_properties); //
if (ret != VK_SUCCESS) {
COMP_ERROR(ct->c, "vkGetDisplayModePropertiesKHR: %s", vk_result_string(ret));
COMP_ERROR(ct->c, "vk_enumerate_display_mode_properties: %s", vk_result_string(ret));
return VK_NULL_HANDLE;
}
/*
* Debug information.
*/
COMP_DEBUG(ct->c, "Found %d modes", mode_count);
VkDisplayModePropertiesKHR *mode_properties = U_TYPED_ARRAY_CALLOC(VkDisplayModePropertiesKHR, mode_count);
ret = vk->vkGetDisplayModePropertiesKHR(vk->physical_device, display, &mode_count, mode_properties);
if (ret != VK_SUCCESS) {
COMP_ERROR(ct->c, "vkGetDisplayModePropertiesKHR: %s", vk_result_string(ret));
free(mode_properties);
return VK_NULL_HANDLE;
}
print_modes(ct, mode_properties, mode_count);
/*
* Select the mode.
*/
int chosen_mode = 0;
int desired_mode = ct->c->settings.desired_mode;
@ -157,33 +164,29 @@ comp_window_direct_create_surface(struct comp_target_swapchain *cts,
uint32_t height)
{
struct vk_bundle *vk = get_vk(cts);
VkDisplayPlanePropertiesKHR *plane_properties = NULL;
uint32_t plane_property_count = 0;
VkResult ret;
// Get plane properties
uint32_t plane_property_count;
VkResult ret =
vk->vkGetPhysicalDeviceDisplayPlanePropertiesKHR(vk->physical_device, &plane_property_count, NULL);
ret = vk_enumerate_physical_display_plane_properties( //
vk, //
vk->physical_device, //
&plane_property_count, //
&plane_properties); //
if (ret != VK_SUCCESS) {
COMP_ERROR(cts->base.c, "vkGetPhysicalDeviceDisplayPlanePropertiesKHR: %s", vk_result_string(ret));
return ret;
}
COMP_DEBUG(cts->base.c, "Found %d plane properties.", plane_property_count);
VkDisplayPlanePropertiesKHR *plane_properties =
U_TYPED_ARRAY_CALLOC(VkDisplayPlanePropertiesKHR, plane_property_count);
ret = vk->vkGetPhysicalDeviceDisplayPlanePropertiesKHR(vk->physical_device, &plane_property_count,
plane_properties);
if (ret != VK_SUCCESS) {
COMP_ERROR(cts->base.c, "vkGetPhysicalDeviceDisplayPlanePropertiesKHR: %s", vk_result_string(ret));
free(plane_properties);
return ret;
COMP_ERROR(cts->base.c, "vk_enumerate_physical_display_plane_properties: %s", vk_result_string(ret));
return VK_ERROR_INITIALIZATION_FAILED;
}
// Select the plane.
//! @todo actually select the plane.
uint32_t plane_index = 0;
// Select the mode.
VkDisplayModeKHR display_mode = comp_window_direct_get_primary_display_mode(cts, display);
// We need the capabilities of the selected plane.
VkDisplayPlaneCapabilitiesKHR plane_caps;
vk->vkGetDisplayPlaneCapabilitiesKHR(vk->physical_device, display_mode, plane_index, &plane_caps);

View file

@ -177,22 +177,29 @@ comp_window_direct_nvidia_init(struct comp_target *ct)
{
struct comp_window_direct_nvidia *w_direct = (struct comp_window_direct_nvidia *)ct;
struct vk_bundle *vk = get_vk(ct);
VkDisplayPropertiesKHR *display_props = NULL;
uint32_t display_count = 0;
VkResult ret;
if (vk->instance == VK_NULL_HANDLE) {
COMP_ERROR(ct->c, "Vulkan not initialized before NVIDIA init!");
return false;
}
if (!comp_window_direct_connect(&w_direct->base, &w_direct->dpy)) {
return false;
}
// find our display using nvidia allowlist, enumerate its modes, and
// pick the best one get a list of attached displays
uint32_t display_count;
if (vk->vkGetPhysicalDeviceDisplayPropertiesKHR(vk->physical_device, &display_count, NULL) != VK_SUCCESS) {
COMP_ERROR(ct->c, "Failed to get vulkan display count");
ret = vk_enumerate_physical_device_display_properties( //
vk, //
vk->physical_device, //
&display_count, //
&display_props); //
if (ret != VK_SUCCESS) {
COMP_ERROR(ct->c, "vk_enumerate_physical_device_display_properties: %s", vk_result_string(ret));
return false;
}
@ -201,15 +208,6 @@ comp_window_direct_nvidia_init(struct comp_target *ct)
return false;
}
struct VkDisplayPropertiesKHR *display_props = U_TYPED_ARRAY_CALLOC(VkDisplayPropertiesKHR, display_count);
if (display_props && vk->vkGetPhysicalDeviceDisplayPropertiesKHR(vk->physical_device, &display_count,
display_props) != VK_SUCCESS) {
COMP_ERROR(ct->c, "Failed to get display properties");
free(display_props);
return false;
}
/// @todo what if we have multiple allowlisted HMD displays connected?
for (uint32_t i = 0; i < display_count; i++) {
struct VkDisplayPropertiesKHR disp = *(display_props + i);

View file

@ -160,15 +160,24 @@ comp_window_vk_display_init(struct comp_target *ct)
{
struct comp_window_vk_display *w_direct = (struct comp_window_vk_display *)ct;
struct vk_bundle *vk = get_vk(ct);
VkDisplayPropertiesKHR *display_props = NULL;
uint32_t display_count = 0;
VkResult ret;
if (vk->instance == VK_NULL_HANDLE) {
COMP_ERROR(ct->c, "Vulkan not initialized before vk display init!");
return false;
}
uint32_t display_count;
if (vk->vkGetPhysicalDeviceDisplayPropertiesKHR(vk->physical_device, &display_count, NULL) != VK_SUCCESS) {
COMP_ERROR(ct->c, "Failed to get vulkan display count");
// Get a list of attached displays.
ret = vk_enumerate_physical_device_display_properties( //
vk, //
vk->physical_device, //
&display_count, //
&display_props); //
if (ret != VK_SUCCESS) {
CVK_ERROR(ct->c, "vk_enumerate_physical_device_display_properties", "Failed to get display properties",
ret);
return false;
}
@ -177,15 +186,6 @@ comp_window_vk_display_init(struct comp_target *ct)
return false;
}
struct VkDisplayPropertiesKHR *display_props = U_TYPED_ARRAY_CALLOC(VkDisplayPropertiesKHR, display_count);
if (display_props && vk->vkGetPhysicalDeviceDisplayPropertiesKHR(vk->physical_device, &display_count,
display_props) != VK_SUCCESS) {
COMP_ERROR(ct->c, "Failed to get display properties");
free(display_props);
return false;
}
if (ct->c->settings.vk_display > (int)display_count) {
COMP_ERROR(ct->c, "Requested display %d, but only %d found.", ct->c->settings.vk_display,
display_count);