Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 63 additions & 12 deletions cube-vksc/cube.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ struct demo {
bool use_break;
bool suppress_popups;
bool force_errors;
bool prefer_native_display_mode;

VkDebugUtilsMessengerEXT dbg_messenger;

Expand Down Expand Up @@ -1223,7 +1224,15 @@ static void demo_prepare_buffers(struct demo *demo) {
};
uint32_t i;
err = pfnCreateSwapchainKHR(demo->device, &swapchain_ci, NULL, &demo->swapchain);
assert(!err);
if (err) {
if (demo->wsi_platform == WSI_PLATFORM_DISPLAY) {
ERR_EXIT("vkCreateSwapchainKHR failed.\n\n"
"Some implementations only support swapchain creation at the display's\n"
"native panel resolution. Try running with --native-resolution.\n",
"vkCreateSwapchainKHR Failure");
}
ERR_EXIT("vkCreateSwapchainKHR failed.\n", "vkCreateSwapchainKHR Failure");
}

err = pfnGetSwapchainImagesKHR(demo->device, demo->swapchain, &demo->swapchainImageCount, NULL);
assert(!err);
Expand Down Expand Up @@ -2434,7 +2443,7 @@ static VkResult demo_create_display_surface(struct demo *demo) {
uint32_t plane_count;
VkDisplayPropertiesKHR display_props;
VkDisplayModeKHR mode;
VkDisplayModePropertiesKHR mode_props;
VkDisplayModePropertiesKHR mode_props = {0};
VkDisplayPlanePropertiesKHR plane_props[MAX_DISPLAY_PLANE_COUNT];
VkBool32 found_plane = VK_FALSE;
uint32_t plane_index;
Expand All @@ -2449,11 +2458,11 @@ static VkResult demo_create_display_surface(struct demo *demo) {
demo->display = display_props.display;

#ifdef VK_USE_PLATFORM_WIN32_KHR
// If we can, and need to, acquire the display if supported
if (demo->VK_NV_acquire_winrt_display_supported && demo->wsi_platform != WSI_PLATFORM_DISPLAY) {
// Acquire the display so the swapchain can be created on it.
if (demo->VK_NV_acquire_winrt_display_supported && demo->wsi_platform == WSI_PLATFORM_DISPLAY) {
err = pfnAcquireWinrtDisplayNV(demo->gpu, demo->display);
if (err != VK_SUCCESS) {
ERR_EXIT("Failed to get acqurie display", "vkAcquireWinrtDisplayNV Failure");
ERR_EXIT("Failed to acquire display", "vkAcquireWinrtDisplayNV Failure");
}
}
#endif
Expand All @@ -2468,10 +2477,48 @@ static VkResult demo_create_display_surface(struct demo *demo) {
exit(1);
}

mode_count = 1;
err = vkGetDisplayModePropertiesKHR(demo->gpu, demo->display, &mode_count, &mode_props);
assert(!err || (err == VK_INCOMPLETE));
// By default use the first enumerated mode. Pass --native-resolution to
// select the mode matching the display's native panel resolution instead,
// preferring the highest refresh rate among native-resolution modes (some
// implementations only support swapchain creation at the display's
// highest native rate).
uint32_t total_mode_count = mode_count;

#define MAX_DISPLAY_MODE_COUNT 256
{
VkDisplayModePropertiesKHR all_modes[MAX_DISPLAY_MODE_COUNT];
uint32_t mode_cnt = total_mode_count < MAX_DISPLAY_MODE_COUNT ? total_mode_count : MAX_DISPLAY_MODE_COUNT;
err = vkGetDisplayModePropertiesKHR(demo->gpu, demo->display, &mode_cnt, all_modes);
assert(!err || (err == VK_INCOMPLETE));

if (demo->prefer_native_display_mode) {
// --native-resolution: find the native-panel-resolution mode with
// the highest refresh rate.
VkExtent2D native_res = display_props.physicalResolution;
bool found = false;
for (uint32_t mi = 0; mi < mode_cnt; mi++) {
VkExtent2D r = all_modes[mi].parameters.visibleRegion;
if (r.width != native_res.width || r.height != native_res.height) continue;
if (!found || all_modes[mi].parameters.refreshRate > mode_props.parameters.refreshRate) {
mode_props = all_modes[mi];
found = true;
}
}
if (!found) {
fprintf(stderr, "Warning: --native-resolution: no mode matching native resolution "
"%ux%u found, falling back to mode[0].\n",
native_res.width, native_res.height);
mode_props = all_modes[0];
}
} else {
// Default: use mode[0].
mode_props = all_modes[0];
}
}
#undef MAX_DISPLAY_MODE_COUNT

if (demo->width != -1 && demo->height != -1) {
// User specified a resolution — try to find or create that mode.
VkDisplayModeCreateInfoKHR mode_create_info;
mode_create_info.sType = VK_STRUCTURE_TYPE_DISPLAY_MODE_CREATE_INFO_KHR;
mode_create_info.pNext = NULL;
Expand All @@ -2481,11 +2528,10 @@ static VkResult demo_create_display_surface(struct demo *demo) {
mode_create_info.parameters.refreshRate = mode_props.parameters.refreshRate;
err = vkCreateDisplayModeKHR(demo->gpu, demo->display, &mode_create_info, NULL, &mode);
assert(!err);
}
else {
} else {
mode = mode_props.displayMode;
demo->width = mode_props.parameters.visibleRegion.width;
demo->height = mode_props.parameters.visibleRegion.height;
demo->width = (int32_t)mode_props.parameters.visibleRegion.width;
demo->height = (int32_t)mode_props.parameters.visibleRegion.height;
}

// Get the list of planes
Expand Down Expand Up @@ -3359,6 +3405,10 @@ static void demo_init(struct demo *demo, int argc, char **argv) {
demo->suppress_popups = true;
continue;
}
if (strcmp(argv[i], "--native-resolution") == 0) {
demo->prefer_native_display_mode = true;
continue;
}
if (strcmp(argv[i], "--incremental_present") == 0) {
demo->VK_KHR_incremental_present_enabled = true;
continue;
Expand Down Expand Up @@ -3418,6 +3468,7 @@ static void demo_init(struct demo *demo, int argc, char **argv) {
"\t[--width <width>] [--height <height>]\n"
"\t[--force_errors]\n"
"\t[--wsi <%s>]\n"
"\t[--native-resolution]\n"
"\t<present_mode_enum>\n"
"\t\tVK_PRESENT_MODE_IMMEDIATE_KHR = %d\n"
"\t\tVK_PRESENT_MODE_MAILBOX_KHR = %d\n"
Expand Down
6 changes: 3 additions & 3 deletions cube-vksc/cube.pc.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@
"pNext": "NULL",
"flags": 0,
"viewportCount": 1,
"pViewports": [],
"pViewports": "NULL",
"scissorCount": 1,
"pScissors": []
"pScissors": "NULL"
},
"pRasterizationState": {
"sType": "VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO",
Expand Down Expand Up @@ -234,7 +234,7 @@
"srcAlphaBlendFactor": "VK_BLEND_FACTOR_ZERO",
"dstAlphaBlendFactor": "VK_BLEND_FACTOR_ZERO",
"alphaBlendOp": "VK_BLEND_OP_ADD",
"colorWriteMask": "0xf"
"colorWriteMask": "VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I looked into the history of this. Apparently the 0xf format (while allowed by the legacy invalid JSON schema), was never accepted even by the legacy parser, but the legacy generator did produce it, so I think this part is a legitimate fix for remnants of the legacy tooling.

}
],
"blendConstants": [
Expand Down
2 changes: 1 addition & 1 deletion cube-vksc/pipeline_cache.h

Large diffs are not rendered by default.

Loading