The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

c/main: Use more enumeration helpers

+55 -54
+32 -29
src/xrt/compositor/main/comp_window_direct.c
··· 79 79 { 80 80 struct vk_bundle *vk = get_vk(cts); 81 81 struct comp_target *ct = &cts->base; 82 - uint32_t mode_count; 82 + VkDisplayModePropertiesKHR *mode_properties = NULL; 83 + uint32_t mode_count = 0; 83 84 VkResult ret; 84 85 85 - ret = vk->vkGetDisplayModePropertiesKHR(vk->physical_device, display, &mode_count, NULL); 86 + // Get plane properties 87 + ret = vk_enumerate_display_mode_properties( // 88 + vk, // 89 + vk->physical_device, // 90 + display, // 91 + &mode_count, // 92 + &mode_properties); // 86 93 if (ret != VK_SUCCESS) { 87 - COMP_ERROR(ct->c, "vkGetDisplayModePropertiesKHR: %s", vk_result_string(ret)); 94 + COMP_ERROR(ct->c, "vk_enumerate_display_mode_properties: %s", vk_result_string(ret)); 88 95 return VK_NULL_HANDLE; 89 96 } 90 97 91 - COMP_DEBUG(ct->c, "Found %d modes", mode_count); 92 98 93 - VkDisplayModePropertiesKHR *mode_properties = U_TYPED_ARRAY_CALLOC(VkDisplayModePropertiesKHR, mode_count); 94 - ret = vk->vkGetDisplayModePropertiesKHR(vk->physical_device, display, &mode_count, mode_properties); 95 - if (ret != VK_SUCCESS) { 96 - COMP_ERROR(ct->c, "vkGetDisplayModePropertiesKHR: %s", vk_result_string(ret)); 97 - free(mode_properties); 98 - return VK_NULL_HANDLE; 99 - } 99 + /* 100 + * Debug information. 101 + */ 100 102 103 + COMP_DEBUG(ct->c, "Found %d modes", mode_count); 101 104 print_modes(ct, mode_properties, mode_count); 102 105 106 + 107 + /* 108 + * Select the mode. 109 + */ 103 110 104 111 int chosen_mode = 0; 105 112 ··· 157 164 uint32_t height) 158 165 { 159 166 struct vk_bundle *vk = get_vk(cts); 167 + VkDisplayPlanePropertiesKHR *plane_properties = NULL; 168 + uint32_t plane_property_count = 0; 169 + VkResult ret; 160 170 161 171 // Get plane properties 162 - uint32_t plane_property_count; 163 - VkResult ret = 164 - vk->vkGetPhysicalDeviceDisplayPlanePropertiesKHR(vk->physical_device, &plane_property_count, NULL); 165 - if (ret != VK_SUCCESS) { 166 - COMP_ERROR(cts->base.c, "vkGetPhysicalDeviceDisplayPlanePropertiesKHR: %s", vk_result_string(ret)); 167 - return ret; 168 - } 169 - 170 - COMP_DEBUG(cts->base.c, "Found %d plane properties.", plane_property_count); 171 - 172 - VkDisplayPlanePropertiesKHR *plane_properties = 173 - U_TYPED_ARRAY_CALLOC(VkDisplayPlanePropertiesKHR, plane_property_count); 174 - 175 - ret = vk->vkGetPhysicalDeviceDisplayPlanePropertiesKHR(vk->physical_device, &plane_property_count, 176 - plane_properties); 172 + ret = vk_enumerate_physical_display_plane_properties( // 173 + vk, // 174 + vk->physical_device, // 175 + &plane_property_count, // 176 + &plane_properties); // 177 177 if (ret != VK_SUCCESS) { 178 - COMP_ERROR(cts->base.c, "vkGetPhysicalDeviceDisplayPlanePropertiesKHR: %s", vk_result_string(ret)); 179 - free(plane_properties); 180 - return ret; 178 + COMP_ERROR(cts->base.c, "vk_enumerate_physical_display_plane_properties: %s", vk_result_string(ret)); 179 + return VK_ERROR_INITIALIZATION_FAILED; 181 180 } 182 181 182 + // Select the plane. 183 + //! @todo actually select the plane. 183 184 uint32_t plane_index = 0; 184 185 186 + // Select the mode. 185 187 VkDisplayModeKHR display_mode = comp_window_direct_get_primary_display_mode(cts, display); 186 188 189 + // We need the capabilities of the selected plane. 187 190 VkDisplayPlaneCapabilitiesKHR plane_caps; 188 191 vk->vkGetDisplayPlaneCapabilitiesKHR(vk->physical_device, display_mode, plane_index, &plane_caps); 189 192
+11 -13
src/xrt/compositor/main/comp_window_direct_nvidia.c
··· 177 177 { 178 178 struct comp_window_direct_nvidia *w_direct = (struct comp_window_direct_nvidia *)ct; 179 179 struct vk_bundle *vk = get_vk(ct); 180 + VkDisplayPropertiesKHR *display_props = NULL; 181 + uint32_t display_count = 0; 182 + VkResult ret; 180 183 181 184 if (vk->instance == VK_NULL_HANDLE) { 182 185 COMP_ERROR(ct->c, "Vulkan not initialized before NVIDIA init!"); 183 186 return false; 184 187 } 185 188 186 - 187 189 if (!comp_window_direct_connect(&w_direct->base, &w_direct->dpy)) { 188 190 return false; 189 191 } 190 192 191 193 // find our display using nvidia allowlist, enumerate its modes, and 192 194 // pick the best one get a list of attached displays 193 - uint32_t display_count; 194 - if (vk->vkGetPhysicalDeviceDisplayPropertiesKHR(vk->physical_device, &display_count, NULL) != VK_SUCCESS) { 195 - COMP_ERROR(ct->c, "Failed to get vulkan display count"); 195 + 196 + ret = vk_enumerate_physical_device_display_properties( // 197 + vk, // 198 + vk->physical_device, // 199 + &display_count, // 200 + &display_props); // 201 + if (ret != VK_SUCCESS) { 202 + COMP_ERROR(ct->c, "vk_enumerate_physical_device_display_properties: %s", vk_result_string(ret)); 196 203 return false; 197 204 } 198 205 199 206 if (display_count == 0) { 200 207 COMP_ERROR(ct->c, "NVIDIA: No Vulkan displays found."); 201 - return false; 202 - } 203 - 204 - struct VkDisplayPropertiesKHR *display_props = U_TYPED_ARRAY_CALLOC(VkDisplayPropertiesKHR, display_count); 205 - 206 - if (display_props && vk->vkGetPhysicalDeviceDisplayPropertiesKHR(vk->physical_device, &display_count, 207 - display_props) != VK_SUCCESS) { 208 - COMP_ERROR(ct->c, "Failed to get display properties"); 209 - free(display_props); 210 208 return false; 211 209 } 212 210
+12 -12
src/xrt/compositor/main/comp_window_vk_display.c
··· 160 160 { 161 161 struct comp_window_vk_display *w_direct = (struct comp_window_vk_display *)ct; 162 162 struct vk_bundle *vk = get_vk(ct); 163 + VkDisplayPropertiesKHR *display_props = NULL; 164 + uint32_t display_count = 0; 165 + VkResult ret; 163 166 164 167 if (vk->instance == VK_NULL_HANDLE) { 165 168 COMP_ERROR(ct->c, "Vulkan not initialized before vk display init!"); 166 169 return false; 167 170 } 168 171 169 - uint32_t display_count; 170 - if (vk->vkGetPhysicalDeviceDisplayPropertiesKHR(vk->physical_device, &display_count, NULL) != VK_SUCCESS) { 171 - COMP_ERROR(ct->c, "Failed to get vulkan display count"); 172 + // Get a list of attached displays. 173 + ret = vk_enumerate_physical_device_display_properties( // 174 + vk, // 175 + vk->physical_device, // 176 + &display_count, // 177 + &display_props); // 178 + if (ret != VK_SUCCESS) { 179 + CVK_ERROR(ct->c, "vk_enumerate_physical_device_display_properties", "Failed to get display properties", 180 + ret); 172 181 return false; 173 182 } 174 183 175 184 if (display_count == 0) { 176 185 COMP_ERROR(ct->c, "No Vulkan displays found."); 177 - return false; 178 - } 179 - 180 - struct VkDisplayPropertiesKHR *display_props = U_TYPED_ARRAY_CALLOC(VkDisplayPropertiesKHR, display_count); 181 - 182 - if (display_props && vk->vkGetPhysicalDeviceDisplayPropertiesKHR(vk->physical_device, &display_count, 183 - display_props) != VK_SUCCESS) { 184 - COMP_ERROR(ct->c, "Failed to get display properties"); 185 - free(display_props); 186 186 return false; 187 187 } 188 188