163 lines
4.7 KiB
C
163 lines
4.7 KiB
C
// vim:fileencoding=utf-8:foldmethod=marker
|
|
|
|
#include "vulkan/vulkan_profiles.h"
|
|
#include <vulkan/vk_enum_string_helper.h>
|
|
#include <volk/volk.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main(void) {
|
|
VkResult result = VK_SUCCESS;
|
|
|
|
result = volkInitialize();
|
|
if (result != VK_SUCCESS) {
|
|
fprintf(stderr, "ERROR: %s", string_VkResult(result));
|
|
return 1;
|
|
}
|
|
|
|
VkBool32 supported = VK_FALSE;
|
|
|
|
VpProfileProperties profile = {
|
|
.profileName = VP_KHR_ROADMAP_2022_NAME,
|
|
.specVersion = VP_KHR_ROADMAP_2022_SPEC_VERSION,
|
|
};
|
|
result = vpGetInstanceProfileSupport(NULL, &profile, &supported);
|
|
if (result != VK_SUCCESS) {
|
|
fprintf(stderr, "ERROR: %s\n", string_VkResult(result));
|
|
return 3;
|
|
} else if (!supported) {
|
|
fprintf(stderr, "Profile not supported at instance level\n");
|
|
return 4;
|
|
}
|
|
|
|
VkApplicationInfo app_info = {
|
|
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
|
.apiVersion = VP_KHR_ROADMAP_2022_MIN_API_VERSION,
|
|
};
|
|
VkInstanceCreateInfo instance_info = {
|
|
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
|
.pApplicationInfo = &app_info,
|
|
};
|
|
VpInstanceCreateInfo vp_instance_info = {
|
|
.pCreateInfo = &instance_info,
|
|
.enabledFullProfileCount = 1,
|
|
.pEnabledFullProfiles = &profile,
|
|
};
|
|
|
|
VkInstance instance = VK_NULL_HANDLE;
|
|
result = vpCreateInstance(&vp_instance_info, NULL, &instance);
|
|
if (result != VK_SUCCESS) {
|
|
fprintf(stderr, "ERROR: %s\n", string_VkResult(result));
|
|
return 5;
|
|
}
|
|
|
|
volkLoadInstance(instance);
|
|
|
|
VkPhysicalDevice physical_device = VK_NULL_HANDLE;
|
|
unsigned int count = 0;
|
|
result = vkEnumeratePhysicalDevices(instance, &count, NULL);
|
|
if (result != VK_SUCCESS) {
|
|
fprintf(stderr, "ERROR: %s\n", string_VkResult(result));
|
|
return 6;
|
|
}
|
|
|
|
VkPhysicalDevice physical_devices[32] = {0};
|
|
result = vkEnumeratePhysicalDevices(instance, &count, physical_devices);
|
|
if (result != VK_SUCCESS) {
|
|
fprintf(stderr, "ERROR: %s\n", string_VkResult(result));
|
|
return 7;
|
|
}
|
|
|
|
int index = -1;
|
|
for (int i = 0; i < count; ++i) {
|
|
VkPhysicalDeviceProperties2 base_properties = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 };
|
|
vkGetPhysicalDeviceProperties2(physical_devices[i], &base_properties);
|
|
switch (base_properties.properties.deviceType) {
|
|
case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: {
|
|
if (base_properties.properties.apiVersion >= VP_KHR_ROADMAP_2022_MIN_API_VERSION) {
|
|
index = i;
|
|
}
|
|
} break;
|
|
case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: {
|
|
if (base_properties.properties.apiVersion >= VP_KHR_ROADMAP_2022_MIN_API_VERSION) {
|
|
index = i;
|
|
}
|
|
} break;
|
|
default: continue;
|
|
}
|
|
}
|
|
|
|
if (index == -1) {
|
|
fprintf(stderr, "Failed to find physical device\n");
|
|
return 8;
|
|
}
|
|
|
|
physical_device = physical_devices[index];
|
|
|
|
result = vpGetPhysicalDeviceProfileSupport(instance, physical_device, &profile, &supported);
|
|
if (result != VK_SUCCESS) {
|
|
fprintf(stderr, "ERROR: %s\n", string_VkResult(result));
|
|
return 8;
|
|
} else if (!supported) {
|
|
fprintf(stderr, "Profile not supported at physical device level\n");
|
|
return 9;
|
|
}
|
|
|
|
unsigned int queue_family_count;
|
|
vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &queue_family_count, NULL);
|
|
if (queue_family_count == 0) {
|
|
fprintf(stderr, "Couldn't find queue families");
|
|
return 10;
|
|
}
|
|
|
|
VkQueueFamilyProperties queue_families_properties[64] = {0};
|
|
vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &queue_family_count, queue_families_properties);
|
|
|
|
int queue_family_index = -1;
|
|
for (unsigned int i = 0; i < queue_family_count; ++i) {
|
|
if ((queue_families_properties[i].queueFlags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT)) != 0) {
|
|
queue_family_index = i;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (queue_family_index == -1) {
|
|
fprintf(stderr, "Couldn't find suitable queue family");
|
|
return 11;
|
|
}
|
|
|
|
float queue_priority = 1.0f;
|
|
VkDeviceQueueCreateInfo device_queue_create_info = {
|
|
.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
|
|
.queueCount = 1,
|
|
.queueFamilyIndex = queue_family_index,
|
|
.pQueuePriorities = &queue_priority,
|
|
};
|
|
|
|
VkDeviceCreateInfo device_create_info = {
|
|
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
|
.queueCreateInfoCount = 1,
|
|
.pQueueCreateInfos = &device_queue_create_info,
|
|
};
|
|
|
|
VpDeviceCreateInfo vp_device_create_info = {
|
|
.pCreateInfo = &device_create_info,
|
|
.enabledFullProfileCount = 1,
|
|
.pEnabledFullProfiles = &profile,
|
|
};
|
|
|
|
VkDevice device = VK_NULL_HANDLE;
|
|
result = vpCreateDevice(physical_device, &vp_device_create_info, NULL, &device);
|
|
if (result != VK_SUCCESS) {
|
|
fprintf(stderr, "ERROR: %s\n", string_VkResult(result));
|
|
return 12;
|
|
}
|
|
|
|
volkLoadDevice(device);
|
|
|
|
// NOTE (Abdelrahman): Fake render loop
|
|
while (1) {}
|
|
|
|
return 0;
|
|
}
|