[Mesa-dev] [PATCH 05/15] vulkan: enum generator: generate extension number defines

Lionel Landwerlin lionel.g.landwerlin at intel.com
Mon Sep 18 14:58:21 UTC 2017


No, this is all I had.
Tables of tables formats are just in anv : 
https://github.com/djdeath/mesa/commit/b40dd5245cdaa5d686b8494f0e8c784b2eea4211#diff-8d7721e9d80d390ff503d2c3b4e1adc5L274

On 18/09/17 15:48, Jason Ekstrand wrote:
> Did you have a patch to the enum generator to actually generate the 
> table of tables for the formats?  I don't see that in ithe series.
>
> On Mon, Sep 18, 2017 at 7:46 AM, Jason Ekstrand <jason at jlekstrand.net 
> <mailto:jason at jlekstrand.net>> wrote:
>
>     On Fri, Sep 15, 2017 at 7:10 AM, Lionel Landwerlin
>     <lionel.g.landwerlin at intel.com
>     <mailto:lionel.g.landwerlin at intel.com>> wrote:
>
>         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 at intel.com
>         <mailto:lionel.g.landwerlin at intel.com>>
>         ---
>          src/vulkan/util/gen_enum_to_str.py | 23 +++++++++++++++++++++--
>          1 file changed, 21 insertions(+), 2 deletions(-)
>
>         diff --git a/src/vulkan/util/gen_enum_to_str.py
>         b/src/vulkan/util/gen_enum_to_str.py
>         index 28bfbfde235..06d625d9ac8 100644
>         --- a/src/vulkan/util/gen_enum_to_str.py
>         +++ b/src/vulkan/util/gen_enum_to_str.py
>         @@ -91,6 +91,10 @@ H_TEMPLATE = Template(textwrap.dedent(u"""\
>
>              #include <vulkan/vulkan.h>
>
>         +    % for ext in extensions:
>         +    #define _${ext.name <http://ext.name>}_number (${ext.number})
>
>
>     I was about to say that this is already in the Vulkan headers but
>     then I looked and it isn't. :-(
>
>         +    % endfor
>         +
>              % for enum in enums:
>              const char * vk_${enum.name
>         <http://enum.name>[2:]}_to_str(${enum.name <http://enum.name>}
>         input);
>              % endfor
>         @@ -113,6 +117,14 @@ class NamedFactory(object):
>                  return n
>
>
>         +class VkExtension(object):
>         +    """Simple struct-like class representing extensions"""
>         +
>         +    def __init__(self, name, number):
>         + self.name <http://self.name> = name
>         +        self.number = number
>         +
>         +
>          class VkEnum(object):
>              """Simple struct-like class representing a single Vulkan
>         Enum."""
>
>         @@ -121,6 +133,7 @@ class VkEnum(object):
>                  self.values = values or []
>
>
>         +
>
>
>     Extra newline.  Other than, LGTM
>
>          def xml_parser(filename):
>              """Parse the XML file and return parsed data.
>
>         @@ -128,6 +141,7 @@ def xml_parser(filename):
>              of VkEnum objects.
>              """
>              enum_factory = NamedFactory(VkEnum)
>         +    ext_factory = NamedFactory(VkExtension)
>
>              with open(filename, 'rb') as f:
>                  context = iter(et.iterparse(f, events=('start', 'end')))
>         @@ -144,6 +158,8 @@ def xml_parser(filename):
>                              enum = enum_factory(elem.attrib['name'])
>          enum.values.extend([e.attrib['name'] for e in elem
>                                                  if e.tag == 'enum'])
>         +            elif event == 'start' and elem.tag == 'extension':
>         +                ext_factory(elem.attrib['name'],
>         int(elem.attrib['number']))
>                      elif event == 'end' and elem.tag == 'extension':
>                          if elem.attrib['supported'] != 'vulkan':
>                              continue
>         @@ -153,7 +169,8 @@ def xml_parser(filename):
>
>                      root.clear()
>
>         -    return enum_factory.registry.values()
>         +    return (enum_factory.registry.values(),
>         +            ext_factory.registry.values())
>
>
>          def main():
>         @@ -165,14 +182,16 @@ def main():
>
>              args = parser.parse_args()
>
>         -    enums = xml_parser(args.xml)
>         +    enums, extensions = xml_parser(args.xml)
>              enums.sort(key=lambda e: e.name <http://e.name>)
>         +    extensions.sort(key=lambda e: e.number)
>              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'))]:
>                  with open(file_, 'wb') as f:
>                      f.write(template.render(
>                          file=os.path.basename(__file__),
>                          enums=enums,
>         +                extensions=extensions,
>                          copyright=COPYRIGHT))
>
>
>         --
>         2.14.1
>
>         _______________________________________________
>         mesa-dev mailing list
>         mesa-dev at lists.freedesktop.org
>         <mailto:mesa-dev at lists.freedesktop.org>
>         https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>         <https://lists.freedesktop.org/mailman/listinfo/mesa-dev>
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170918/1d603ea8/attachment-0001.html>


More information about the mesa-dev mailing list