2017-02-15 23:41:50 +00:00
|
|
|
# encoding=utf-8
|
|
|
|
# Copyright © 2017 Intel Corporation
|
|
|
|
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
|
2017-07-18 11:06:43 +01:00
|
|
|
"""Create enum to string functions for vulkan using vk.xml."""
|
2017-02-15 23:41:50 +00:00
|
|
|
|
2017-02-28 00:24:41 +00:00
|
|
|
import argparse
|
2017-02-15 23:41:50 +00:00
|
|
|
import os
|
|
|
|
import textwrap
|
2020-06-05 08:46:10 +01:00
|
|
|
import xml.etree.ElementTree as et
|
2017-02-15 23:41:50 +00:00
|
|
|
|
|
|
|
from mako.template import Template
|
|
|
|
|
|
|
|
COPYRIGHT = textwrap.dedent(u"""\
|
|
|
|
* Copyright © 2017 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.""")
|
|
|
|
|
|
|
|
C_TEMPLATE = Template(textwrap.dedent(u"""\
|
|
|
|
/* Autogenerated file -- do not edit
|
|
|
|
* generated by ${file}
|
|
|
|
*
|
|
|
|
${copyright}
|
|
|
|
*/
|
|
|
|
|
2019-03-05 10:38:14 +00:00
|
|
|
#include <string.h>
|
2017-02-15 23:41:50 +00:00
|
|
|
#include <vulkan/vulkan.h>
|
2017-08-16 00:48:38 +01:00
|
|
|
#include <vulkan/vk_android_native_buffer.h>
|
2020-12-22 21:05:54 +00:00
|
|
|
#include <vulkan/vk_layer.h>
|
2017-02-15 23:41:50 +00:00
|
|
|
#include "util/macros.h"
|
|
|
|
#include "vk_enum_to_str.h"
|
|
|
|
|
|
|
|
% for enum in enums:
|
|
|
|
|
2019-03-17 19:26:07 +00:00
|
|
|
% if enum.guard:
|
|
|
|
#ifdef ${enum.guard}
|
|
|
|
% endif
|
2017-09-15 15:10:54 +01:00
|
|
|
const char *
|
|
|
|
vk_${enum.name[2:]}_to_str(${enum.name} input)
|
|
|
|
{
|
2021-04-18 10:45:01 +01:00
|
|
|
switch((int64_t)input) {
|
2020-11-27 03:41:32 +00:00
|
|
|
% for v in sorted(enum.values.keys()):
|
|
|
|
case ${v}:
|
|
|
|
return "${enum.values[v]}";
|
|
|
|
% endfor
|
|
|
|
default:
|
|
|
|
unreachable("Undefined enum value.");
|
2017-02-15 23:41:50 +00:00
|
|
|
}
|
2017-09-15 15:10:54 +01:00
|
|
|
}
|
2019-03-17 19:26:07 +00:00
|
|
|
|
|
|
|
% if enum.guard:
|
|
|
|
#endif
|
|
|
|
% endif
|
2019-03-05 10:38:14 +00:00
|
|
|
%endfor
|
|
|
|
|
2019-02-25 16:43:15 +00:00
|
|
|
size_t vk_structure_type_size(const struct VkBaseInStructure *item)
|
|
|
|
{
|
2020-11-27 03:41:32 +00:00
|
|
|
switch((int)item->sType) {
|
2019-02-25 16:43:15 +00:00
|
|
|
% for struct in structs:
|
|
|
|
% if struct.extension is not None and struct.extension.define is not None:
|
|
|
|
#ifdef ${struct.extension.define}
|
|
|
|
case ${struct.stype}: return sizeof(${struct.name});
|
|
|
|
#endif
|
|
|
|
% else:
|
|
|
|
case ${struct.stype}: return sizeof(${struct.name});
|
|
|
|
% endif
|
|
|
|
%endfor
|
2020-12-22 21:05:54 +00:00
|
|
|
case VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO: return sizeof(VkLayerInstanceCreateInfo);
|
|
|
|
case VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO: return sizeof(VkLayerDeviceCreateInfo);
|
2020-11-27 03:41:32 +00:00
|
|
|
default:
|
|
|
|
unreachable("Undefined struct type.");
|
2019-02-25 16:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-05 10:38:14 +00:00
|
|
|
"""),
|
2017-02-15 23:41:50 +00:00
|
|
|
output_encoding='utf-8')
|
|
|
|
|
|
|
|
H_TEMPLATE = Template(textwrap.dedent(u"""\
|
|
|
|
/* Autogenerated file -- do not edit
|
|
|
|
* generated by ${file}
|
|
|
|
*
|
|
|
|
${copyright}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MESA_VK_ENUM_TO_STR_H
|
|
|
|
#define MESA_VK_ENUM_TO_STR_H
|
|
|
|
|
|
|
|
#include <vulkan/vulkan.h>
|
2017-08-16 00:48:38 +01:00
|
|
|
#include <vulkan/vk_android_native_buffer.h>
|
2017-02-15 23:41:50 +00:00
|
|
|
|
2019-01-22 17:36:56 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
vulkan: enum generator: generate extension number defines
New extensions can introduce additional enums. Most of the new enums
will have disjoint numbers from the initial enums. For example new
formats introduced by VK_IMG_format_pvrtc :
VK_FORMAT_ASTC_10x8_UNORM_BLOCK = 177,
VK_FORMAT_ASTC_10x8_SRGB_BLOCK = 178,
VK_FORMAT_ASTC_10x10_UNORM_BLOCK = 179,
VK_FORMAT_ASTC_10x10_SRGB_BLOCK = 180,
VK_FORMAT_ASTC_12x10_UNORM_BLOCK = 181,
VK_FORMAT_ASTC_12x10_SRGB_BLOCK = 182,
VK_FORMAT_ASTC_12x12_UNORM_BLOCK = 183,
VK_FORMAT_ASTC_12x12_SRGB_BLOCK = 184,
VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG = 1000054000,
VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG = 1000054001,
VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG = 1000054002,
VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG = 1000054003,
VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG = 1000054004,
VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG = 1000054005,
VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG = 1000054006,
VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG = 1000054007,
It's obvious we can't have a single table for handling those anymore.
Fortunately the enum values actually contain the number of the
extension that introduced the new enums. So we can build an
indirection table off the extension number and then index by
subtracting the first enum of the the format enum value.
This change makes the extension number available in the generated enum
code.
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
2017-09-15 15:10:57 +01:00
|
|
|
% for ext in extensions:
|
|
|
|
#define _${ext.name}_number (${ext.number})
|
|
|
|
% endfor
|
|
|
|
|
2017-02-15 23:41:50 +00:00
|
|
|
% for enum in enums:
|
2019-03-17 19:26:07 +00:00
|
|
|
% if enum.guard:
|
|
|
|
#ifdef ${enum.guard}
|
|
|
|
% endif
|
2017-09-15 15:10:54 +01:00
|
|
|
const char * vk_${enum.name[2:]}_to_str(${enum.name} input);
|
2019-03-17 19:26:07 +00:00
|
|
|
% if enum.guard:
|
|
|
|
#endif
|
|
|
|
% endif
|
2017-02-15 23:41:50 +00:00
|
|
|
% endfor
|
|
|
|
|
2019-02-25 16:43:15 +00:00
|
|
|
size_t vk_structure_type_size(const struct VkBaseInStructure *item);
|
|
|
|
|
2019-01-22 17:36:56 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
|
|
|
|
2017-02-15 23:41:50 +00:00
|
|
|
#endif"""),
|
|
|
|
output_encoding='utf-8')
|
|
|
|
|
|
|
|
|
2017-09-15 15:10:56 +01:00
|
|
|
class NamedFactory(object):
|
2017-02-15 23:41:50 +00:00
|
|
|
"""Factory for creating enums."""
|
|
|
|
|
|
|
|
def __init__(self, type_):
|
|
|
|
self.registry = {}
|
|
|
|
self.type = type_
|
|
|
|
|
2017-09-15 15:10:56 +01:00
|
|
|
def __call__(self, name, **kwargs):
|
2017-02-15 23:41:50 +00:00
|
|
|
try:
|
|
|
|
return self.registry[name]
|
|
|
|
except KeyError:
|
2017-09-15 15:10:56 +01:00
|
|
|
n = self.registry[name] = self.type(name, **kwargs)
|
2017-02-15 23:41:50 +00:00
|
|
|
return n
|
|
|
|
|
2017-09-21 16:20:55 +01:00
|
|
|
def get(self, name):
|
|
|
|
return self.registry.get(name)
|
|
|
|
|
2017-02-15 23:41:50 +00:00
|
|
|
|
vulkan: enum generator: generate extension number defines
New extensions can introduce additional enums. Most of the new enums
will have disjoint numbers from the initial enums. For example new
formats introduced by VK_IMG_format_pvrtc :
VK_FORMAT_ASTC_10x8_UNORM_BLOCK = 177,
VK_FORMAT_ASTC_10x8_SRGB_BLOCK = 178,
VK_FORMAT_ASTC_10x10_UNORM_BLOCK = 179,
VK_FORMAT_ASTC_10x10_SRGB_BLOCK = 180,
VK_FORMAT_ASTC_12x10_UNORM_BLOCK = 181,
VK_FORMAT_ASTC_12x10_SRGB_BLOCK = 182,
VK_FORMAT_ASTC_12x12_UNORM_BLOCK = 183,
VK_FORMAT_ASTC_12x12_SRGB_BLOCK = 184,
VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG = 1000054000,
VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG = 1000054001,
VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG = 1000054002,
VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG = 1000054003,
VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG = 1000054004,
VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG = 1000054005,
VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG = 1000054006,
VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG = 1000054007,
It's obvious we can't have a single table for handling those anymore.
Fortunately the enum values actually contain the number of the
extension that introduced the new enums. So we can build an
indirection table off the extension number and then index by
subtracting the first enum of the the format enum value.
This change makes the extension number available in the generated enum
code.
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
2017-09-15 15:10:57 +01:00
|
|
|
class VkExtension(object):
|
|
|
|
"""Simple struct-like class representing extensions"""
|
|
|
|
|
2019-03-05 15:57:34 +00:00
|
|
|
def __init__(self, name, number=None, define=None):
|
vulkan: enum generator: generate extension number defines
New extensions can introduce additional enums. Most of the new enums
will have disjoint numbers from the initial enums. For example new
formats introduced by VK_IMG_format_pvrtc :
VK_FORMAT_ASTC_10x8_UNORM_BLOCK = 177,
VK_FORMAT_ASTC_10x8_SRGB_BLOCK = 178,
VK_FORMAT_ASTC_10x10_UNORM_BLOCK = 179,
VK_FORMAT_ASTC_10x10_SRGB_BLOCK = 180,
VK_FORMAT_ASTC_12x10_UNORM_BLOCK = 181,
VK_FORMAT_ASTC_12x10_SRGB_BLOCK = 182,
VK_FORMAT_ASTC_12x12_UNORM_BLOCK = 183,
VK_FORMAT_ASTC_12x12_SRGB_BLOCK = 184,
VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG = 1000054000,
VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG = 1000054001,
VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG = 1000054002,
VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG = 1000054003,
VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG = 1000054004,
VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG = 1000054005,
VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG = 1000054006,
VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG = 1000054007,
It's obvious we can't have a single table for handling those anymore.
Fortunately the enum values actually contain the number of the
extension that introduced the new enums. So we can build an
indirection table off the extension number and then index by
subtracting the first enum of the the format enum value.
This change makes the extension number available in the generated enum
code.
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
2017-09-15 15:10:57 +01:00
|
|
|
self.name = name
|
|
|
|
self.number = number
|
2019-03-05 15:57:34 +00:00
|
|
|
self.define = define
|
vulkan: enum generator: generate extension number defines
New extensions can introduce additional enums. Most of the new enums
will have disjoint numbers from the initial enums. For example new
formats introduced by VK_IMG_format_pvrtc :
VK_FORMAT_ASTC_10x8_UNORM_BLOCK = 177,
VK_FORMAT_ASTC_10x8_SRGB_BLOCK = 178,
VK_FORMAT_ASTC_10x10_UNORM_BLOCK = 179,
VK_FORMAT_ASTC_10x10_SRGB_BLOCK = 180,
VK_FORMAT_ASTC_12x10_UNORM_BLOCK = 181,
VK_FORMAT_ASTC_12x10_SRGB_BLOCK = 182,
VK_FORMAT_ASTC_12x12_UNORM_BLOCK = 183,
VK_FORMAT_ASTC_12x12_SRGB_BLOCK = 184,
VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG = 1000054000,
VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG = 1000054001,
VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG = 1000054002,
VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG = 1000054003,
VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG = 1000054004,
VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG = 1000054005,
VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG = 1000054006,
VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG = 1000054007,
It's obvious we can't have a single table for handling those anymore.
Fortunately the enum values actually contain the number of the
extension that introduced the new enums. So we can build an
indirection table off the extension number and then index by
subtracting the first enum of the the format enum value.
This change makes the extension number available in the generated enum
code.
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
2017-09-15 15:10:57 +01:00
|
|
|
|
|
|
|
|
2017-02-15 23:41:50 +00:00
|
|
|
class VkEnum(object):
|
|
|
|
"""Simple struct-like class representing a single Vulkan Enum."""
|
|
|
|
|
|
|
|
def __init__(self, name, values=None):
|
|
|
|
self.name = name
|
2019-02-25 16:43:15 +00:00
|
|
|
self.extension = None
|
2017-09-21 16:20:55 +01:00
|
|
|
# Maps numbers to names
|
|
|
|
self.values = values or dict()
|
2017-09-21 16:26:06 +01:00
|
|
|
self.name_to_value = dict()
|
2019-03-17 19:26:07 +00:00
|
|
|
self.guard = None
|
2019-06-26 19:35:54 +01:00
|
|
|
self.name_to_alias_list = {}
|
2017-09-21 16:20:55 +01:00
|
|
|
|
|
|
|
def add_value(self, name, value=None,
|
2019-06-26 19:35:54 +01:00
|
|
|
extnum=None, offset=None, alias=None,
|
2017-09-21 16:20:55 +01:00
|
|
|
error=False):
|
2019-06-26 19:35:54 +01:00
|
|
|
if alias is not None:
|
|
|
|
assert value is None and offset is None
|
|
|
|
if alias not in self.name_to_value:
|
|
|
|
# We don't have this alias yet. Just record the alias and
|
|
|
|
# we'll deal with it later.
|
|
|
|
alias_list = self.name_to_alias_list.get(alias, [])
|
|
|
|
alias_list.append(name);
|
|
|
|
return
|
|
|
|
|
|
|
|
# Use the value from the alias
|
|
|
|
value = self.name_to_value[alias]
|
|
|
|
|
2017-09-21 16:26:06 +01:00
|
|
|
assert value is not None or extnum is not None
|
2017-09-21 16:20:55 +01:00
|
|
|
if value is None:
|
2017-09-21 16:26:06 +01:00
|
|
|
value = 1000000000 + (extnum - 1) * 1000 + offset
|
2017-09-21 16:20:55 +01:00
|
|
|
if error:
|
|
|
|
value = -value
|
|
|
|
|
2017-09-21 16:26:06 +01:00
|
|
|
self.name_to_value[name] = value
|
2017-09-21 16:20:55 +01:00
|
|
|
if value not in self.values:
|
|
|
|
self.values[value] = name
|
2017-09-21 16:26:06 +01:00
|
|
|
elif len(self.values[value]) > len(name):
|
|
|
|
self.values[value] = name
|
2017-02-15 23:41:50 +00:00
|
|
|
|
2019-06-26 19:35:54 +01:00
|
|
|
# Now that the value has been fully added, resolve aliases, if any.
|
|
|
|
if name in self.name_to_alias_list:
|
|
|
|
for alias in self.name_to_alias_list[name]:
|
|
|
|
add_value(alias, value)
|
|
|
|
del self.name_to_alias_list[name]
|
|
|
|
|
2018-01-24 03:43:00 +00:00
|
|
|
def add_value_from_xml(self, elem, extension=None):
|
2019-02-25 16:43:15 +00:00
|
|
|
self.extension = extension
|
2018-01-24 03:43:00 +00:00
|
|
|
if 'value' in elem.attrib:
|
|
|
|
self.add_value(elem.attrib['name'],
|
2018-07-06 11:48:23 +01:00
|
|
|
value=int(elem.attrib['value'], base=0))
|
2017-09-21 16:26:06 +01:00
|
|
|
elif 'alias' in elem.attrib:
|
2019-06-26 19:35:54 +01:00
|
|
|
self.add_value(elem.attrib['name'], alias=elem.attrib['alias'])
|
2018-01-24 03:43:00 +00:00
|
|
|
else:
|
|
|
|
error = 'dir' in elem.attrib and elem.attrib['dir'] == '-'
|
2017-09-21 16:26:06 +01:00
|
|
|
if 'extnumber' in elem.attrib:
|
|
|
|
extnum = int(elem.attrib['extnumber'])
|
|
|
|
else:
|
|
|
|
extnum = extension.number
|
2018-01-24 03:43:00 +00:00
|
|
|
self.add_value(elem.attrib['name'],
|
2017-09-21 16:26:06 +01:00
|
|
|
extnum=extnum,
|
2018-01-24 03:43:00 +00:00
|
|
|
offset=int(elem.attrib['offset']),
|
|
|
|
error=error)
|
|
|
|
|
2019-03-17 19:26:07 +00:00
|
|
|
def set_guard(self, g):
|
|
|
|
self.guard = g
|
|
|
|
|
2017-02-15 23:41:50 +00:00
|
|
|
|
2019-03-05 10:38:14 +00:00
|
|
|
class VkCommand(object):
|
|
|
|
"""Simple struct-like class representing a single Vulkan command"""
|
|
|
|
|
|
|
|
def __init__(self, name, device_entrypoint=False):
|
|
|
|
self.name = name
|
|
|
|
self.device_entrypoint = device_entrypoint
|
|
|
|
self.extension = None
|
|
|
|
|
|
|
|
|
2019-02-25 16:43:15 +00:00
|
|
|
class VkChainStruct(object):
|
|
|
|
"""Simple struct-like class representing a single Vulkan struct identified with a VkStructureType"""
|
|
|
|
def __init__(self, name, stype):
|
|
|
|
self.name = name
|
|
|
|
self.stype = stype
|
|
|
|
self.extension = None
|
|
|
|
|
|
|
|
|
|
|
|
def struct_get_stype(xml_node):
|
|
|
|
for member in xml_node.findall('./member'):
|
|
|
|
name = member.findall('./name')
|
|
|
|
if len(name) > 0 and name[0].text == "sType":
|
|
|
|
return member.get('values')
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2021-01-23 17:47:35 +00:00
|
|
|
def parse_xml(enum_factory, ext_factory, struct_factory, filename):
|
vulkan: enum generator: generate extension number defines
New extensions can introduce additional enums. Most of the new enums
will have disjoint numbers from the initial enums. For example new
formats introduced by VK_IMG_format_pvrtc :
VK_FORMAT_ASTC_10x8_UNORM_BLOCK = 177,
VK_FORMAT_ASTC_10x8_SRGB_BLOCK = 178,
VK_FORMAT_ASTC_10x10_UNORM_BLOCK = 179,
VK_FORMAT_ASTC_10x10_SRGB_BLOCK = 180,
VK_FORMAT_ASTC_12x10_UNORM_BLOCK = 181,
VK_FORMAT_ASTC_12x10_SRGB_BLOCK = 182,
VK_FORMAT_ASTC_12x12_UNORM_BLOCK = 183,
VK_FORMAT_ASTC_12x12_SRGB_BLOCK = 184,
VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG = 1000054000,
VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG = 1000054001,
VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG = 1000054002,
VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG = 1000054003,
VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG = 1000054004,
VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG = 1000054005,
VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG = 1000054006,
VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG = 1000054007,
It's obvious we can't have a single table for handling those anymore.
Fortunately the enum values actually contain the number of the
extension that introduced the new enums. So we can build an
indirection table off the extension number and then index by
subtracting the first enum of the the format enum value.
This change makes the extension number available in the generated enum
code.
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
2017-09-15 15:10:57 +01:00
|
|
|
"""Parse the XML file. Accumulate results into the factories.
|
2017-02-15 23:41:50 +00:00
|
|
|
|
|
|
|
This parser is a memory efficient iterative XML parser that returns a list
|
|
|
|
of VkEnum objects.
|
|
|
|
"""
|
|
|
|
|
2017-09-21 16:05:25 +01:00
|
|
|
xml = et.parse(filename)
|
|
|
|
|
|
|
|
for enum_type in xml.findall('./enums[@type="enum"]'):
|
|
|
|
enum = enum_factory(enum_type.attrib['name'])
|
|
|
|
for value in enum_type.findall('./enum'):
|
2018-01-24 03:43:00 +00:00
|
|
|
enum.add_value_from_xml(value)
|
2017-09-21 16:05:25 +01:00
|
|
|
|
2017-09-21 16:26:06 +01:00
|
|
|
for value in xml.findall('./feature/require/enum[@extends]'):
|
|
|
|
enum = enum_factory.get(value.attrib['extends'])
|
|
|
|
if enum is not None:
|
|
|
|
enum.add_value_from_xml(value)
|
|
|
|
|
2019-02-25 16:43:15 +00:00
|
|
|
for struct_type in xml.findall('./types/type[@category="struct"]'):
|
|
|
|
name = struct_type.attrib['name']
|
|
|
|
stype = struct_get_stype(struct_type)
|
|
|
|
if stype is not None:
|
|
|
|
struct_factory(name, stype=stype)
|
|
|
|
|
2019-03-05 15:57:34 +00:00
|
|
|
platform_define = {}
|
|
|
|
for platform in xml.findall('./platforms/platform'):
|
|
|
|
name = platform.attrib['name']
|
|
|
|
define = platform.attrib['protect']
|
|
|
|
platform_define[name] = define
|
|
|
|
|
2017-09-21 16:05:25 +01:00
|
|
|
for ext_elem in xml.findall('./extensions/extension[@supported="vulkan"]'):
|
2019-03-07 13:45:14 +00:00
|
|
|
define = None
|
2019-03-05 10:38:14 +00:00
|
|
|
if "platform" in ext_elem.attrib:
|
2019-03-05 15:57:34 +00:00
|
|
|
define = platform_define[ext_elem.attrib['platform']]
|
2017-09-21 16:20:55 +01:00
|
|
|
extension = ext_factory(ext_elem.attrib['name'],
|
2019-03-05 10:38:14 +00:00
|
|
|
number=int(ext_elem.attrib['number']),
|
2019-03-05 15:57:34 +00:00
|
|
|
define=define)
|
2017-09-21 16:20:55 +01:00
|
|
|
|
|
|
|
for value in ext_elem.findall('./require/enum[@extends]'):
|
|
|
|
enum = enum_factory.get(value.attrib['extends'])
|
2018-01-24 03:43:00 +00:00
|
|
|
if enum is not None:
|
|
|
|
enum.add_value_from_xml(value, extension)
|
2019-02-25 16:43:15 +00:00
|
|
|
for t in ext_elem.findall('./require/type'):
|
|
|
|
struct = struct_factory.get(t.attrib['name'])
|
|
|
|
if struct is not None:
|
|
|
|
struct.extension = extension
|
2017-09-21 16:20:55 +01:00
|
|
|
|
2019-03-17 19:26:07 +00:00
|
|
|
if define:
|
|
|
|
for value in ext_elem.findall('./require/type[@name]'):
|
|
|
|
enum = enum_factory.get(value.attrib['name'])
|
|
|
|
if enum is not None:
|
|
|
|
enum.set_guard(define)
|
|
|
|
|
2017-02-15 23:41:50 +00:00
|
|
|
|
|
|
|
def main():
|
2017-02-28 00:24:41 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
2017-08-16 00:34:20 +01:00
|
|
|
parser.add_argument('--xml', required=True,
|
|
|
|
help='Vulkan API XML files',
|
|
|
|
action='append',
|
|
|
|
dest='xml_files')
|
2017-02-28 00:24:41 +00:00
|
|
|
parser.add_argument('--outdir',
|
|
|
|
help='Directory to put the generated files in',
|
|
|
|
required=True)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2017-09-15 15:10:56 +01:00
|
|
|
enum_factory = NamedFactory(VkEnum)
|
vulkan: enum generator: generate extension number defines
New extensions can introduce additional enums. Most of the new enums
will have disjoint numbers from the initial enums. For example new
formats introduced by VK_IMG_format_pvrtc :
VK_FORMAT_ASTC_10x8_UNORM_BLOCK = 177,
VK_FORMAT_ASTC_10x8_SRGB_BLOCK = 178,
VK_FORMAT_ASTC_10x10_UNORM_BLOCK = 179,
VK_FORMAT_ASTC_10x10_SRGB_BLOCK = 180,
VK_FORMAT_ASTC_12x10_UNORM_BLOCK = 181,
VK_FORMAT_ASTC_12x10_SRGB_BLOCK = 182,
VK_FORMAT_ASTC_12x12_UNORM_BLOCK = 183,
VK_FORMAT_ASTC_12x12_SRGB_BLOCK = 184,
VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG = 1000054000,
VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG = 1000054001,
VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG = 1000054002,
VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG = 1000054003,
VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG = 1000054004,
VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG = 1000054005,
VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG = 1000054006,
VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG = 1000054007,
It's obvious we can't have a single table for handling those anymore.
Fortunately the enum values actually contain the number of the
extension that introduced the new enums. So we can build an
indirection table off the extension number and then index by
subtracting the first enum of the the format enum value.
This change makes the extension number available in the generated enum
code.
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
2017-09-15 15:10:57 +01:00
|
|
|
ext_factory = NamedFactory(VkExtension)
|
2019-02-25 16:43:15 +00:00
|
|
|
struct_factory = NamedFactory(VkChainStruct)
|
2017-08-16 00:34:20 +01:00
|
|
|
for filename in args.xml_files:
|
2021-01-23 17:47:35 +00:00
|
|
|
parse_xml(enum_factory, ext_factory, struct_factory, filename)
|
2017-09-15 15:10:56 +01:00
|
|
|
enums = sorted(enum_factory.registry.values(), key=lambda e: e.name)
|
vulkan: enum generator: generate extension number defines
New extensions can introduce additional enums. Most of the new enums
will have disjoint numbers from the initial enums. For example new
formats introduced by VK_IMG_format_pvrtc :
VK_FORMAT_ASTC_10x8_UNORM_BLOCK = 177,
VK_FORMAT_ASTC_10x8_SRGB_BLOCK = 178,
VK_FORMAT_ASTC_10x10_UNORM_BLOCK = 179,
VK_FORMAT_ASTC_10x10_SRGB_BLOCK = 180,
VK_FORMAT_ASTC_12x10_UNORM_BLOCK = 181,
VK_FORMAT_ASTC_12x10_SRGB_BLOCK = 182,
VK_FORMAT_ASTC_12x12_UNORM_BLOCK = 183,
VK_FORMAT_ASTC_12x12_SRGB_BLOCK = 184,
VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG = 1000054000,
VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG = 1000054001,
VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG = 1000054002,
VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG = 1000054003,
VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG = 1000054004,
VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG = 1000054005,
VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG = 1000054006,
VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG = 1000054007,
It's obvious we can't have a single table for handling those anymore.
Fortunately the enum values actually contain the number of the
extension that introduced the new enums. So we can build an
indirection table off the extension number and then index by
subtracting the first enum of the the format enum value.
This change makes the extension number available in the generated enum
code.
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
2017-09-15 15:10:57 +01:00
|
|
|
extensions = sorted(ext_factory.registry.values(), key=lambda e: e.name)
|
2019-02-25 16:43:15 +00:00
|
|
|
structs = sorted(struct_factory.registry.values(), key=lambda e: e.name)
|
2017-08-16 00:34:20 +01:00
|
|
|
|
2017-02-28 00:24:41 +00:00
|
|
|
for template, file_ in [(C_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.c')),
|
|
|
|
(H_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.h'))]:
|
2017-02-15 23:41:50 +00:00
|
|
|
with open(file_, 'wb') as f:
|
|
|
|
f.write(template.render(
|
|
|
|
file=os.path.basename(__file__),
|
2017-09-15 15:10:55 +01:00
|
|
|
enums=enums,
|
vulkan: enum generator: generate extension number defines
New extensions can introduce additional enums. Most of the new enums
will have disjoint numbers from the initial enums. For example new
formats introduced by VK_IMG_format_pvrtc :
VK_FORMAT_ASTC_10x8_UNORM_BLOCK = 177,
VK_FORMAT_ASTC_10x8_SRGB_BLOCK = 178,
VK_FORMAT_ASTC_10x10_UNORM_BLOCK = 179,
VK_FORMAT_ASTC_10x10_SRGB_BLOCK = 180,
VK_FORMAT_ASTC_12x10_UNORM_BLOCK = 181,
VK_FORMAT_ASTC_12x10_SRGB_BLOCK = 182,
VK_FORMAT_ASTC_12x12_UNORM_BLOCK = 183,
VK_FORMAT_ASTC_12x12_SRGB_BLOCK = 184,
VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG = 1000054000,
VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG = 1000054001,
VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG = 1000054002,
VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG = 1000054003,
VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG = 1000054004,
VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG = 1000054005,
VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG = 1000054006,
VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG = 1000054007,
It's obvious we can't have a single table for handling those anymore.
Fortunately the enum values actually contain the number of the
extension that introduced the new enums. So we can build an
indirection table off the extension number and then index by
subtracting the first enum of the the format enum value.
This change makes the extension number available in the generated enum
code.
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
2017-09-15 15:10:57 +01:00
|
|
|
extensions=extensions,
|
2019-02-25 16:43:15 +00:00
|
|
|
structs=structs,
|
2019-05-03 12:31:01 +01:00
|
|
|
copyright=COPYRIGHT))
|
2017-02-15 23:41:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|