03 - Vulkan - Creando dispositivo
C/Visual C
1.248 visualizaciones desde el 11 de Agosto del 2017
#include <stdio.h>
#include <stdlib.h>
#include <vulkan/vulkan.h>
#define APP_NAME "app vulkan"
typedef struct{
VkApplicationInfo app_info;
VkInstanceCreateInfo inst_info;
VkInstance inst;
//enumeración de dispositivos
VkPhysicalDevice* physical_devices;
uint32_t gpu_count;
//crea_dispositivo
VkDeviceQueueCreateInfo queue_info;
VkQueueFamilyProperties* queue_props;
VkDeviceCreateInfo device_info;
VkDevice device;
}INST;
VkResult init_instance(INST* info);
VkResult enum_devices(INST* info);
VkResult crea_dispositivo(INST* info);
int main(){
INST info;
VkResult res;
res = init_instance( &info );
res = enum_devices( &info );
res = crea_dispositivo( &info );
if(res == VK_SUCCESS){
printf("Se creó el dispositivo\n");
}else{
printf("Error con el dispositivo\n");
}
free(info.queue_props);
free(info.physical_devices);
vkDestroyInstance(info.inst,NULL);
return 0;
}
VkResult crea_dispositivo(INST* info){
VkResult res;
vkGetPhysicalDeviceQueueFamilyProperties(info->physical_devices[0],&info->gpu_count,NULL);
info->queue_props = (VkQueueFamilyProperties *)malloc(sizeof(VkQueueFamilyProperties) * info->gpu_count);
vkGetPhysicalDeviceQueueFamilyProperties(info->physical_devices[0],&info->gpu_count,info->queue_props);
float queue_priorities[1] = {0.0};
info->queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
info->queue_info.pNext = NULL;
info->queue_info.queueCount = 1;
info->queue_info.pQueuePriorities = queue_priorities;
info->device_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
info->device_info.pNext = NULL;
info->device_info.queueCreateInfoCount = 1;
info->device_info.pQueueCreateInfos = &info->queue_info;
info->device_info.enabledExtensionCount = 0;
info->device_info.ppEnabledExtensionNames = NULL;
info->device_info.enabledLayerCount = 0;
info->device_info.ppEnabledLayerNames = NULL;
info->device_info.pEnabledFeatures = NULL;
res = vkCreateDevice(info->physical_devices[0],&info->device_info,NULL,&info->device);
return res;
}
VkResult enum_devices(INST *info){
VkResult res;
info->gpu_count = 0;
res = vkEnumeratePhysicalDevices(info->inst,&info->gpu_count,NULL);
if(info->gpu_count > 0){
info->physical_devices = (VkPhysicalDevice* )malloc(sizeof(VkPhysicalDevice) * info->gpu_count);
res = vkEnumeratePhysicalDevices(info->inst,&info->gpu_count,info->physical_devices);
}
return res;
}
VkResult init_instance(INST *info){
VkResult res;
//información de la aplicación
info->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
info->app_info.pNext = NULL;
info->app_info.pApplicationName = APP_NAME;
info->app_info.applicationVersion = 1;
info->app_info.pEngineName = APP_NAME;
info->app_info.engineVersion = 1;
info->app_info.apiVersion = VK_API_VERSION_1_0;
//información de la instamcia
info->inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
info->inst_info.pNext = NULL;
info->inst_info.flags = 0;
info->inst_info.pApplicationInfo = &info->app_info;
info->inst_info.enabledExtensionCount = 0;
info->inst_info.ppEnabledExtensionNames = NULL;
info->inst_info.enabledLayerCount = 0;
info->inst_info.ppEnabledLayerNames = NULL;
res = vkCreateInstance(&info->inst_info,NULL,&info->inst);
return res;
}
Comentarios sobre la versión: 1.0 (0)
No hay comentarios