Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public static ExtensionDefinition FromXML(XElement elem)
        {
            ExtensionDefinition extension = new ExtensionDefinition();

            extension.Name          = elem.Attribute("name").Value;
            extension.Number        = int.Parse(elem.Attribute("number").Value);
            extension.Type          = elem.Attribute("type")?.Value;
            extension.Requires      = elem.Attribute("requires")?.Value.Split(',');
            extension.Author        = elem.Attribute("author")?.Value;
            extension.Contact       = elem.Attribute("contact")?.Value;
            extension.Platform      = elem.Attribute("platform")?.Value;
            extension.Supported     = elem.Attribute("supported")?.Value;
            extension.IsProvisional = elem.Attribute("provisional")?.Value == "true";
            extension.Comment       = elem.Attribute("comment")?.Value;
            string sortString = elem.Attribute("sortorder")?.Value;

            if (sortString != null)
            {
                extension.SortOrder = int.Parse(sortString);
            }

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

            if (requires != null)
            {
                var enums = requires.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 offset    = int.Parse(offsetString);
                            int direction = 1;
                            if (e.Attribute("dir")?.Value == "-")
                            {
                                direction = -1;
                            }

                            int value = direction * (1000000000 + (extension.Number - 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;
                            }
                        }

                        extension.Enums.Add(new EnumExtension()
                        {
                            Extends = extends, Name = enumName, Value = valueString, Alias = alias
                        });
                    }
                    else
                    {
                        ConstantExtension constant = new ConstantExtension();
                        constant.Name  = enumName;
                        constant.Alias = e.Attribute("alias")?.Value;
                        string rawValue = e.Attribute("value")?.Value;
                        if (rawValue != null)
                        {
                            constant.Value = FilterString(rawValue);
                        }

                        extension.Constants.Add(constant);
                    }
                }

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

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

            return(extension);
        }