summaryrefslogtreecommitdiffstats
path: root/src/vulkan/utils_gen.c.j2
blob: 6db0454e15a087193e5a302041da70d2f88b673b (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
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
#define VK_ENABLE_BETA_EXTENSIONS
#include "vulkan/utils.h"

const char *vk_res_str(VkResult res)
{
    switch (res) {
{% for res in vkresults %}
    case {{ res }}: return "{{ res }}";
{% endfor %}

    default: return "unknown error";
    }
}

const char *vk_fmt_name(VkFormat fmt)
{
    switch (fmt) {
{% for fmt in vkformats %}
    case {{ fmt }}: return "{{ fmt }}";
{% endfor %}

    default: return "unknown format";
    }
}

const char *vk_csp_name(VkColorSpaceKHR csp)
{
    switch (csp) {
{% for csp in vkspaces %}
    case {{ csp }}: return "{{ csp }}";
{% endfor %}

    default: return "unknown color space";
    }
}

const char *vk_handle_name(VkExternalMemoryHandleTypeFlagBitsKHR handle)
{
    switch (handle) {
{% for handle in vkhandles %}
    case {{ handle }}: return "{{ handle }}";
{% endfor %}

    default: return "unknown handle type";
    }
}

const char *vk_alpha_mode(VkCompositeAlphaFlagsKHR alpha)
{
    switch (alpha) {
{% for mode in vkalphas %}
    case {{ mode }}: return "{{ mode }}";
{% endfor %}

    default: return "unknown alpha mode";
    }
}

const char *vk_surface_transform(VkSurfaceTransformFlagsKHR tf)
{
    switch (tf) {
{% for tf in vktransforms %}
    case {{ tf }}: return "{{ tf }}";
{% endfor %}

    default: return "unknown surface transform";
    }
}


const char *vk_obj_type(VkObjectType obj)
{
    switch (obj) {
{% for obj in vkobjects %}
    case {{ obj.enum }}: return "{{ obj.name }}";
{% endfor %}

    default: return "unknown object";
    }
}

size_t vk_struct_size(VkStructureType stype)
{
    switch (stype) {
{% for struct in vkstructs %}
    case {{ struct.stype }}: return sizeof({{ struct.name }});
{% endfor %}

    default: return 0;
    }
}

uint32_t vk_ext_promoted_ver(const char *extension)
{
{% for ext in vkexts %}
{%  if ext.promoted_ver %}
    if (!strcmp(extension, "{{ ext.name }}"))
        return {{ ext.promoted_ver }};
{%  endif %}
{% endfor %}
    return 0;
}

void vk_features_normalize(void *alloc, const VkPhysicalDeviceFeatures2 *fin,
                           uint32_t api_ver, VkPhysicalDeviceFeatures2 *out)
{
    for (const VkBaseInStructure *in = (void *) fin; in; in = in->pNext) {
        switch (in->sType) {
        default: break;
{% for fs in vkfeatures %}
        case {{ fs.stype }}: {
            const {{ fs.name }} *i = (const void *) in;
{% for f in fs.features %}
            if (i->{{ f.name }}) {
{% for r in f.replacements %}
{% if r.core_ver %}
               if (!api_ver || api_ver >= {{ r.core_ver }})
{% elif r.max_ver %}
               if (!api_ver || api_ver < {{ r.max_ver }})
{% endif %}
{% if fs.is_base %}
                out->{{ f.name }} = true;
{% else %}
                (({{ r.name }} *) vk_chain_alloc(alloc, out, {{ r.stype }}))->{{ f.name }} = true;
{% endif %}
{% endfor %}
            }
{% endfor %}
            break;
        }
{% endfor %}
        }
    }
}

const VkAccessFlags2 vk_access_read = {{ '0x%x' % vkaccess.read }}LLU;
const VkAccessFlags2 vk_access_write = {{ '0x%x' % vkaccess.write }}LLU;