Skip to content

Commit

Permalink
Fix warnings and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Jan 31, 2024
1 parent 47372b3 commit bee05c3
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/Vulkan.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ void kinc_g5_internal_init() {
assert(!err);
// The device with the highest score is chosen.
float best_score = 0.0;
for (int gpu_idx = 0; gpu_idx < gpu_count; gpu_idx++) {
for (uint32_t gpu_idx = 0; gpu_idx < gpu_count; gpu_idx++) {
VkPhysicalDevice gpu = physical_devices[gpu_idx];
uint32_t queue_count = 0;
vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_count, NULL);
Expand All @@ -742,13 +742,19 @@ void kinc_g5_internal_init() {
bool can_compute = false;
for (uint32_t i = 0; i < queue_count; i++) {
VkBool32 queue_supports_present = kinc_vulkan_get_physical_device_presentation_support(gpu, i);
if(queue_supports_present) can_present = true;
if (queue_supports_present) {
can_present = true;
}
VkQueueFamilyProperties queue_properties = queue_props[i];
uint32_t flags = queue_properties.queueFlags;
if(flags & VK_QUEUE_GRAPHICS_BIT != 0) can_render = true;
if(flags & VK_QUEUE_COMPUTE_BIT != 0) can_compute = true;
if ((flags & VK_QUEUE_GRAPHICS_BIT) != 0) {
can_render = true;
}
if ((flags & VK_QUEUE_COMPUTE_BIT) != 0) {
can_compute = true;
}
}
if(!can_present || !can_render || !can_compute) {
if (!can_present || !can_render || !can_compute) {
// This device is missing required features so move on
continue;
}
Expand All @@ -758,42 +764,44 @@ void kinc_g5_internal_init() {
float score = 0.0;
VkPhysicalDeviceProperties properties;
vkGetPhysicalDeviceProperties(gpu, &properties);
switch(properties.deviceType) {
case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
score += 10;
break;
case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
score += 7;
break;
case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
score += 5;
break;
case VK_PHYSICAL_DEVICE_TYPE_OTHER:
score += 1;
break;
case VK_PHYSICAL_DEVICE_TYPE_CPU:
// CPU gets a score of zero
break;
switch (properties.deviceType) {
case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
score += 10;
break;
case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
score += 7;
break;
case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
score += 5;
break;
case VK_PHYSICAL_DEVICE_TYPE_OTHER:
score += 1;
break;
case VK_PHYSICAL_DEVICE_TYPE_CPU:
// CPU gets a score of zero
break;
}
// TODO: look into using more metrics than just the device type for scoring, eg: available memory, max texture sizes, etc.
// If this is the first usable device, skip testing against the previous best.
if(vk_ctx.gpu == VK_NULL_HANDLE || score > best_score) {
if (vk_ctx.gpu == VK_NULL_HANDLE || score > best_score) {
vk_ctx.gpu = gpu;
best_score = score;
}
}
if (vk_ctx.gpu == VK_NULL_HANDLE) {
if (headless) {
vk_ctx.gpu = physical_devices[0];
} else {
}
else {
kinc_error_message("No Vulkan device that supports presentation found");
}
}
VkPhysicalDeviceProperties properties;
vkGetPhysicalDeviceProperties(vk_ctx.gpu, &properties);
kinc_log(KINC_LOG_LEVEL_INFO, "Chosen Vulkan device: %s", properties.deviceName);
free(physical_devices);
} else {
}
else {
kinc_error_message("No Vulkan device found");
}

Expand Down

0 comments on commit bee05c3

Please sign in to comment.