示例#1
0
        public static VulkanVersion FromSpec(VulkanSpecification spec, string versionName, IEnumerable <ExtensionDefinition> extensions)
        {
            VulkanVersion version = new VulkanVersion();

            version.Constants    = spec.Constants;
            version.FuncPointers = spec.FuncPointers;
            version.Handles      = spec.Handles;
            version.Unions       = spec.Unions;
            version.Structs      = spec.Structs;
            version.Enums        = spec.Enums;

            for (int i = 0; i < spec.Features.Count; i++)
            {
                FeatureDefinition feature = spec.Features[i];

                // Extend Enums
                foreach (var enumType in feature.Enums)
                {
                    if (enumType.Extends != null & enumType.Alias == null)
                    {
                        string name           = enumType.Extends;
                        var    enumDefinition = spec.Enums.Find(c => c.Name == name);

                        EnumValue newValue = new EnumValue();
                        newValue.Name  = enumType.Name;
                        newValue.Value = int.Parse(enumType.Value);
                        enumDefinition.Values.Add(newValue);
                    }
                }

                // Add commands
                foreach (var command in feature.Commands)
                {
                    string name = command;
                    if (spec.Alias.TryGetValue(name, out string alias))
                    {
                        name = alias;
                    }

                    var commandDefinition = spec.Commands.Find(c => c.Prototype.Name == name);
                    version.Commands.Add(commandDefinition);
                }

                if (feature.Name == versionName)
                {
                    break;
                }
            }

            foreach (var extension in extensions)
            {
                // Extend Enums
                foreach (var enumType in extension.Enums)
                {
                    if (enumType.Extends != null & enumType.Alias == null)
                    {
                        string name           = enumType.Extends;
                        var    enumDefinition = spec.Enums.Find(c => c.Name == name);


                        if (!enumDefinition.Values.Exists(e => e.Name == enumType.Name))
                        {
                            EnumValue newValue = new EnumValue();
                            newValue.Name  = enumType.Name;
                            newValue.Value = int.Parse(enumType.Value);
                            enumDefinition.Values.Add(newValue);
                        }
                    }
                }

                // Add commands
                foreach (var command in extension.Commands)
                {
                    string name = command;
                    if (spec.Alias.TryGetValue(name, out string alias))
                    {
                        name = alias;
                    }

                    var commandDefinition = spec.Commands.Find(c => c.Prototype.Name == name);

                    if (!version.Commands.Exists(c => c.Prototype.Name == name))
                    {
                        version.Commands.Add(commandDefinition);
                    }
                }
            }

            return(version);
        }
示例#2
0
        public static VulkanSpecification FromFile(string xmlFile)
        {
            XDocument           file = XDocument.Load(xmlFile);
            VulkanSpecification spec = new VulkanSpecification();

            var registry = file.Element("registry");

            // Platforms
            var platforms = registry.Element("platforms").Elements("platform");

            foreach (var platform in platforms)
            {
                spec.Platforms.Add(PlatformDefinition.FromXML(platform));
            }

            // Tags
            var tags = registry.Element("tags").Elements("tag");

            foreach (var tag in tags)
            {
                spec.Tags.Add(TagDefinition.FromXML(tag));
            }

            // Constants
            var constants = (registry.Elements("enums").Where(e => e.Attribute("name").Value == "API Constants")).Elements("enum");

            foreach (var c in constants)
            {
                spec.Constants.Add(ConstantDefinition.FromXML(c));
            }

            // Enums
            var enums = registry.Elements("enums").Where(e => e.Attribute("type")?.Value == "enum" || e.Attribute("type")?.Value == "bitmask");

            foreach (var e in enums)
            {
                spec.Enums.Add(EnumDefinition.FromXML(e));
            }

            var types = registry.Elements("types");

            // FuncPointers
            var funcPointers = types.Elements("type").Where(f => f.Attribute("category")?.Value == "funcpointer");

            foreach (var func in funcPointers)
            {
                spec.FuncPointers.Add(FuncpointerDefinition.FromXML(func));
            }

            // Alias
            spec.Alias = types.Elements("type").Where(a => a.Attribute("alias") != null)
                         .ToDictionary(
                a => a.Attribute("name").Value,
                a => a.Attribute("alias").Value);

            // Command Alias
            var commandAlias = registry.Element("commands").Elements("command").Where(c => c.Attribute("alias") != null);

            foreach (var c in commandAlias)
            {
                spec.Alias.Add(c.Attribute("name").Value, c.Attribute("alias").Value);
            }

            // Structs
            var structs = types.Elements("type").Where(s => s.Attribute("category")?.Value == "struct" && s.Attribute("alias") == null);

            foreach (var s in structs)
            {
                spec.Structs.Add(StructureDefinition.FromXML(s));
            }

            // Unions
            var unions = types.Elements("type").Where(u => u.Attribute("category")?.Value == "union");

            foreach (var u in unions)
            {
                spec.Unions.Add(StructureDefinition.FromXML(u));
            }

            // TypeDef
            var typeDefs = types.Elements("type").Where(t => t.Value.Contains("typedef") && t.Attribute("category")?.Value == "bitmask");

            foreach (var type in typeDefs)
            {
                spec.TypeDefs.Add(TypedefDefinition.FromXML(type));
            }

            // BaseTypes
            spec.BaseTypes = types.Elements("type").Where(bt => bt.Attribute("category")?.Value == "basetype")
                             .ToDictionary(
                bt => bt.Element("name").Value,
                bt => bt.Element("type")?.Value);

            // Handles
            var handles = types.Elements("type").Where(h => h.Attribute("category")?.Value == "handle");

            foreach (var h in handles)
            {
                spec.Handles.Add(HandleDefinition.FromXML(h));
            }

            // Commands
            var commands = registry.Element("commands").Elements("command").Where(c => c.Attribute("alias") == null);

            foreach (var command in commands)
            {
                spec.Commands.Add(CommandDefinition.FromXML(command));
            }

            // Features
            var features = registry.Elements("feature");

            foreach (var feature in features)
            {
                spec.Features.Add(FeatureDefinition.FromXML(feature));
            }

            // Extensions
            var extensions = registry.Element("extensions").Elements("extension");

            foreach (var extension in extensions)
            {
                spec.Extensions.Add(ExtensionDefinition.FromXML(extension));
            }

            return(spec);
        }
示例#3
0
        public static FeatureDefinition FromXML(XElement elem)
        {
            FeatureDefinition feature = new FeatureDefinition();

            feature.Name    = elem.Attribute("name").Value;
            feature.Number  = elem.Attribute("number").Value;
            feature.Api     = elem.Attribute("api").Value;
            feature.Comment = elem.Attribute("comment")?.Value;

            var requires = elem.Elements("require");

            foreach (var require in requires)
            {
                var enums = require.Elements("enum");
                foreach (var e in enums)
                {
                    string enumName = e.Attribute("name").Value;
                    string extends  = e.Attribute("extends")?.Value;
                    if (extends != null)
                    {
                        string valueString;
                        string alias        = null;
                        string offsetString = e.Attribute("offset")?.Value;
                        if (offsetString != null)
                        {
                            int extNumber = int.Parse(e.Attribute("extnumber").Value);
                            int offset    = int.Parse(offsetString);
                            int direction = 1;
                            if (e.Attribute("dir")?.Value == "-")
                            {
                                direction = -1;
                            }

                            int value = direction * (1000000000 + (extNumber - 1) * 1000 + offset);
                            valueString = value.ToString();
                        }
                        else
                        {
                            string bitPosString = e.Attribute("bitpos")?.Value;
                            if (bitPosString != null)
                            {
                                int shift = int.Parse(bitPosString);
                                valueString = (1 << shift).ToString();
                            }
                            else
                            {
                                alias       = e.Attribute("alias")?.Value;
                                valueString = e.Attribute("value")?.Value;
                            }
                        }

                        feature.Enums.Add(new EnumFeature()
                        {
                            Extends = extends, Name = enumName, Value = valueString, Alias = alias
                        });
                    }
                    else
                    {
                        ConstantFeature constant = new ConstantFeature();
                        constant.Name  = enumName;
                        constant.Alias = e.Attribute("alias")?.Value;
                        constant.Value = e.Attribute("value")?.Value;

                        feature.Constants.Add(constant);
                    }
                }

                var types = require.Elements("type");
                foreach (var t in types)
                {
                    string name = t.Attribute("name").Value;
                    feature.Types.Add(name);
                }

                var commands = require.Elements("command");
                foreach (var command in commands)
                {
                    string name = command.Attribute("name").Value;
                    feature.Commands.Add(name);
                }
            }

            return(feature);
        }