Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vkcube and vkcubepp: Check if GPU support the surface #1047

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Changes from 1 commit
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
36 changes: 33 additions & 3 deletions cube/cube.c
Original file line number Diff line number Diff line change
Expand Up @@ -4143,7 +4143,10 @@ static void demo_init_vk(struct demo *demo) {
}

volkLoadInstance(demo->inst);
}

static void demo_select_physical_device(struct demo* demo) {
Copy link
Contributor Author

@water-chika water-chika Nov 5, 2024

Choose a reason for hiding this comment

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

Seperate physical device selection to a function because we need to create surface between creating instance and selecting physical device.

VkResult err;
/* Make initial call to query gpu_count, then second call for gpu info */
uint32_t gpu_count = 0;
err = vkEnumeratePhysicalDevices(demo->inst, &gpu_count, NULL);
Expand Down Expand Up @@ -4188,7 +4191,10 @@ static void demo_init_vk(struct demo *demo) {
for (uint32_t i = 0; i < gpu_count; i++) {
vkGetPhysicalDeviceProperties(physical_devices[i], &physicalDeviceProperties);
assert(physicalDeviceProperties.deviceType <= VK_PHYSICAL_DEVICE_TYPE_CPU);
count_device_type[physicalDeviceProperties.deviceType]++;
VkBool32 supported = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check if GPU support the surface

vkGetPhysicalDeviceSurfaceSupportKHR(physical_devices[i], 0, demo->surface, &supported);
if (supported)
count_device_type[physicalDeviceProperties.deviceType]++;
}

VkPhysicalDeviceType search_for_device_type = VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU;
Expand Down Expand Up @@ -4298,6 +4304,24 @@ static void demo_init_vk(struct demo *demo) {
}

if (demo->validate) {
/*
* This is info for a temp callback to use during CreateInstance.
* After the instance is created, we use the instance-based
* function to register the final callback.
*/
VkDebugUtilsMessengerCreateInfoEXT dbg_messenger_create_info;
// VK_EXT_debug_utils style
dbg_messenger_create_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
dbg_messenger_create_info.pNext = NULL;
dbg_messenger_create_info.flags = 0;
dbg_messenger_create_info.messageSeverity =
VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
dbg_messenger_create_info.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
dbg_messenger_create_info.pfnUserCallback = debug_messenger_callback;
dbg_messenger_create_info.pUserData = demo;

err = vkCreateDebugUtilsMessengerEXT(demo->inst, &dbg_messenger_create_info, NULL, &demo->dbg_messenger);
switch (err) {
case VK_SUCCESS:
Expand Down Expand Up @@ -4492,8 +4516,6 @@ static VkSurfaceFormatKHR pick_surface_format(const VkSurfaceFormatKHR *surfaceF
static void demo_init_vk_swapchain(struct demo *demo) {
VkResult U_ASSERT_ONLY err;

demo_create_surface(demo);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move demo_create_surface to time between demo_init and demo_select_physical_device.


// Iterate over each queue to learn whether it supports presenting:
VkBool32 *supportsPresent = (VkBool32 *)malloc(demo->queue_family_count * sizeof(VkBool32));
for (uint32_t i = 0; i < demo->queue_family_count; i++) {
Expand Down Expand Up @@ -4868,6 +4890,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine,
demo.connection = hInstance;
strncpy(demo.name, "Vulkan Cube", APP_NAME_STR_LEN);
demo_create_window(&demo);
demo_create_surface(&demo);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let demo_create_surface after demo_create_window

demo_select_physical_device(&demo);
demo_init_vk_swapchain(&demo);

demo_prepare(&demo);
Expand Down Expand Up @@ -4906,6 +4930,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine,
#if defined(VK_USE_PLATFORM_METAL_EXT)
static void demo_main(struct demo *demo, void *caMetalLayer, int argc, const char *argv[]) {
demo_init(demo, argc, (char **)argv);
demo_create_surface(demo);
demo_select_physical_device(demo);
demo->caMetalLayer = caMetalLayer;
demo_init_vk_swapchain(demo);
demo_prepare(demo);
Expand Down Expand Up @@ -4959,6 +4985,8 @@ static void processCommand(struct android_app *app, int32_t cmd) {
for (int i = 0; i < argc; i++) free(argv[i]);

demo.window = (void *)app->window;
demo_create_surface(&demo);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let demo_create_surface after demo.window is inited.

demo_select_physical_device(&demo);
demo_init_vk_swapchain(&demo);
demo_prepare(&demo);
initialized = true;
Expand Down Expand Up @@ -5044,6 +5072,8 @@ int main(int argc, char **argv) {
break;
#endif
}
demo_create_surface(&demo);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let demo_create_surface after window is created

demo_select_physical_device(&demo);

demo_init_vk_swapchain(&demo);

Expand Down
Loading