The open source OpenXR runtime
0
fork

Configure Feed

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

comp: Choose best mode for direct mode by default

Best mode means: first maximize the rendered pixels, then maximize the refresh rate.

authored by

Christoph Haag and committed by
Lubosz Sarnecki
36d6b71e 7207c509

+51 -3
+51 -3
src/xrt/compositor/main/comp_window_direct_mode.cpp
··· 383 383 comp_window_direct_flush(struct comp_window *w) 384 384 {} 385 385 386 + static int 387 + choose_best_vk_mode_auto(struct comp_window_direct *w, 388 + VkDisplayModePropertiesKHR *mode_properties, 389 + int mode_count) 390 + { 391 + struct 392 + { 393 + uint16_t width = 0; 394 + uint16_t height = 0; 395 + float refresh = 0; 396 + int index = 0; 397 + } best_mode; 398 + 399 + // First priority: choose mode that maximizes rendered pixels. 400 + // Second priority: choose mode with highest refresh rate. 401 + for (int i = 0; i < mode_count; i++) { 402 + VkDisplayModePropertiesKHR props = mode_properties[i]; 403 + uint16_t width = props.parameters.visibleRegion.width; 404 + uint16_t height = props.parameters.visibleRegion.height; 405 + float refresh = (float)props.parameters.refreshRate / 1000.; 406 + COMP_DEBUG(w->base.c, "Available Vk direct mode %d: %dx%d@%.2f", 407 + i, width, height, refresh); 408 + 409 + int max_pixels = best_mode.width * best_mode.height; 410 + int pixels = width * height; 411 + if (pixels > max_pixels) { 412 + best_mode.index = i; 413 + best_mode.width = width; 414 + best_mode.height = height; 415 + best_mode.refresh = refresh; 416 + } else if (pixels == max_pixels && 417 + refresh > best_mode.refresh) { 418 + best_mode.index = i; 419 + /* update dims because it might be rotated */ 420 + best_mode.width = width; 421 + best_mode.height = height; 422 + best_mode.refresh = refresh; 423 + } 424 + } 425 + COMP_DEBUG(w->base.c, "Auto choosing Vk direct mode %d: %dx%d@%.2f", 426 + best_mode.index, best_mode.width, best_mode.height, 427 + best_mode.refresh); 428 + return best_mode.index; 429 + } 430 + 386 431 static VkDisplayModeKHR 387 432 comp_window_direct_get_primary_display_mode(struct comp_window_direct *w, 388 433 VkDisplayKHR display) ··· 414 459 return nullptr; 415 460 } 416 461 417 - VkDisplayModePropertiesKHR props = mode_properties[0]; 462 + int chosen_mode = 463 + choose_best_vk_mode_auto(w, mode_properties, mode_count); 464 + VkDisplayModePropertiesKHR props = mode_properties[chosen_mode]; 418 465 419 - COMP_DEBUG(w->base.c, "found display mode %d %d", 466 + COMP_DEBUG(w->base.c, "found display mode %dx%d@%.2f", 420 467 props.parameters.visibleRegion.width, 421 - props.parameters.visibleRegion.height); 468 + props.parameters.visibleRegion.height, 469 + (float)props.parameters.refreshRate / 1000.); 422 470 423 471 delete[] mode_properties; 424 472