Código de C/Visual C - 04 - Vulkan - Command buffer

Requerimientos

Librerías y drivers vulkan

1.0

Actualizado el 10 de Octubre del 2017 (Publicado el 18 de Agosto del 2017)gráfica de visualizaciones de la versión: 1.0
919 visualizaciones desde el 18 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#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;
 
    //command_buffer
    VkCommandPool                     cmd_pool;
    VkCommandBuffer                   cmd_bufs[1];
}INST;
 
VkResult init_instance(INST* info);
VkResult enum_devices(INST* info);
VkResult crea_dispositivo(INST* info);
VkResult cmd_buffer(INST* info);
 
int main(){
    INST info;
    VkResult res;
 
    res = init_instance(         &info  );
    res = enum_devices(          &info  );
    res = crea_dispositivo(      &info  );
    res = cmd_buffer(            &info  );
 
    if(res == VK_SUCCESS){
        printf("Se creó el Buffer\n");
    }else{
        printf("Error con el Buffer\n");
    }
 
    vkFreeCommandBuffers(info.device,info.cmd_pool,1,info.cmd_bufs);
    vkDestroyCommandPool(info.device,info.cmd_pool,NULL);
    free(info.queue_props);
    free(info.physical_devices);
    vkDestroyInstance(info.inst,NULL);
 
    return 0;
}
 
VkResult cmd_buffer(INST* info){
    VkCommandPoolCreateInfo cmd_pool_info = {};
    VkResult res;
 
    cmd_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
    cmd_pool_info.pNext = NULL;
    cmd_pool_info.queueFamilyIndex = info->queue_info.queueFamilyIndex;
    cmd_pool_info.flags = 0;
 
    res = vkCreateCommandPool(info->device,&cmd_pool_info,NULL,&info->cmd_pool);
 
    VkCommandBufferAllocateInfo cmd = {};
    cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
    cmd.pNext = NULL;
    cmd.commandPool = info->cmd_pool;
    cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
    cmd.commandBufferCount = 1;
 
    VkCommandBuffer info_cmd;
    res = vkAllocateCommandBuffers(info->device,&cmd,&info_cmd);
 
    info->cmd_bufs[0] = info_cmd;
    return res;
}
 
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);
 
    bool found = false;
    for(unsigned int i = 0; i < info->gpu_count; i++){
        if(info->queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT){
            info->queue_info.queueFamilyIndex = i;
            found = true;
            break;
        }
    }
 
    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...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s4121