Código de C/Visual C - 03 - Vulkan - Creando dispositivo

03 - Vulkan - Creando dispositivográfica de visualizaciones


C/Visual C

Actualizado el 12 de Agosto del 2017 por Ulises (Publicado el 11 de Agosto del 2017)
70 visualizaciones desde el 11 de Agosto del 2017

Requerimientos

Librerías y drivers vulkan

1.0

Publicado el 11 de Agosto del 2017gráfica de visualizaciones de la versión: 1.0
70 visualizaciones desde el 11 de Agosto del 2017
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#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
 

Comentar la versión: 1.0

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios

http://lwp-l.com/s4109