summaryrefslogtreecommitdiff
path: root/src/device.h
blob: 05bdbc1213cc3f8766c0a6373e336f00530977bb (plain)
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
#ifndef DEVICE_H
#define DEVICE_H

#include <stdint.h>
#include <stdbool.h>
#include <vulkan/vulkan.h>

#include "common.h"

// from vulkan source
#define MAKE_VERSION(major, minor, patch) \
    ((((u32)(major)) << 22U) | (((u32)(minor)) << 12U) | ((u32)(patch)))

typedef uint32_t u32;

typedef struct device {
    VkInstance instance;
    VkDebugUtilsMessengerEXT debug_messenger;
    
    VkPhysicalDevice physical_device;    
    VkDevice logical_device;
    
    VkQueue graphics_queue;
    VkQueue present_queue;

    VkSurfaceKHR surface;
    
    struct swap_chain {
        VkSwapchainKHR swap_chain;
        
        VkImage *images;
        VkImageView *image_views;
        u32 nimages;

        VkFormat image_format;
        VkExtent2D extent;
    } swap_chain;

    struct pipeline {
        VkRenderPass render_pass;
        VkPipelineLayout layout;
        VkPipeline pipeline;
    } pipeline;

} * device_t;

struct device_info {
    char *name;
    u32 version;
    
    const char* const* extensions;
    u32 ext_count;

    int (*surface_func)(VkInstance instance, VkSurfaceKHR *surface);
};

device_t device_create(struct device_info *info);
void device_destroy(device_t device);

#endif