Beispiel #1
0
        public static VulkanSpecification LoadFromXmlStream(Stream specFileStream)
        {
            var spec     = XDocument.Load(specFileStream);
            var registry = spec.Element("registry");
            var commands = registry.Element("commands");

            CommandDefinition[] commandDefinitions = commands.Elements("command")
                                                     .Select(commandx => CommandDefinition.CreateFromXml(commandx)).ToArray();

            ConstantDefinition[] constantDefinitions = registry.Elements("enums")
                                                       .Where(enumx => enumx.Attribute("name").Value == "API Constants")
                                                       .SelectMany(enumx => enumx.Elements("enum"))
                                                       .Select(enumxx => ConstantDefinition.CreateFromXml(enumxx)).ToArray();

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

            TypedefDefinition[] typedefDefinitions = types.Elements("type").Where(xe => xe.Value.Contains("typedef") && xe.HasCategoryAttribute("bitmask"))
                                                     .Select(xe2 => TypedefDefinition.CreateFromXml(xe2)).ToArray();

            EnumDefinition[] enumDefinitions = registry.Elements("enums")
                                               .Where(enumx => enumx.GetTypeAttributeOrNull() == "enum" || enumx.GetTypeAttributeOrNull() == "bitmask")
                                               .Select(enumx => EnumDefinition.CreateFromXml(enumx)).ToArray();

            StructureDefinition[] structures = types.Elements("type").Where(typex => typex.HasCategoryAttribute("struct"))
                                               .Select(typex => StructureDefinition.CreateFromXml(typex)).ToArray();

            StructureDefinition[] unions =
                types.Elements("type")
                .Where(typex => typex.HasCategoryAttribute("union"))
                .Select(typex => StructureDefinition.CreateFromXml(typex)).ToArray();

            HandleDefinition[] handles = types.Elements("type").Where(typex => typex.HasCategoryAttribute("handle"))
                                         .Select(typex => HandleDefinition.CreateFromXml(typex)).ToArray();

            Dictionary <string, string> baseTypes = types.Elements("type").Where(typex => typex.HasCategoryAttribute("basetype"))
                                                    .ToDictionary(
                typex => typex.GetNameElement(),
                typex => typex.Element("type").Value);

            baseTypes["VkBool32"] = "Bool32";

            ExtensionDefinition[] extensions = registry.Element("extensions").Elements("extension")
                                               .Select(ExtensionDefinition.CreateFromXml).ToArray();

            FeatureDefinition[] features = registry.Elements("feature")
                                           .Select(FeatureDefinition.CreateFromXml)
                                           .ToArray();

            return(new VulkanSpecification(
                       commandDefinitions,
                       constantDefinitions,
                       typedefDefinitions,
                       enumDefinitions,
                       structures,
                       unions,
                       handles,
                       baseTypes,
                       extensions,
                       features));
        }
        public static VulkanSpecification LoadFromXmlStream(Stream specFileStream)
        {
            var spec               = XDocument.Load(specFileStream);
            var registry           = spec.Element("registry");
            var commands           = registry.Element("commands");
            var commandDefinitions = commands.Elements("command")
                                     .Select(commandx => CommandDefinition.CreateFromXml(commandx)).ToArray();

            var constantDefinitions = registry.Elements("enums")
                                      .Where(enumx => enumx.Attribute("name").Value == "API Constants")
                                      .SelectMany(enumx => enumx.Elements("enum"))
                                      .Select(enumxx => ConstantDefinition.CreateFromXml(enumxx)).ToArray();

            var types = registry.Elements("types");
            var typedefDefinitions = types.Elements("type").Where(xe => xe.Value.Contains("typedef") && xe.HasCategoryAttribute("bitmask"))
                                     .Select(xe2 => TypedefDefinition.CreateFromXml(xe2)).ToArray();

            var enumDefinitionsNoAliases = registry.Elements("enums")
                                           .Where(enumx => enumx.GetTypeAttributeOrNull() == "enum" || enumx.GetTypeAttributeOrNull() == "bitmask")
                                           .Select(enumx => EnumDefinition.CreateFromXml(enumx))
                                           .ToArray();

            var enumDefinitions = registry.Elements("types")
                                  .Elements("type")
                                  .Where(xe => xe.HasCategoryAttribute("enum") && !(xe.Attribute("alias") is null))
                                  .Select
                                  (
                x => enumDefinitionsNoAliases.First(y => y.Name == x.Attribute("alias")?.Value)
                .Clone(x.GetNameAttribute())
                                  )
                                  .Concat(enumDefinitionsNoAliases)
                                  .ToArray();

            var structures = types.Elements("type").Where(typex => typex.HasCategoryAttribute("struct"))
                             .Select(typex => StructureDefinition.CreateFromXml(typex)).ToArray();

            var unions =
                types.Elements("type")
                .Where(typex => typex.HasCategoryAttribute("union"))
                .Select(typex => StructureDefinition.CreateFromXml(typex)).ToArray();

            var handles = types.Elements("type").Where(typex => typex.HasCategoryAttribute("handle"))
                          .Select(typex => HandleDefinition.CreateFromXml(typex)).ToArray();

            var baseTypes = types.Elements("type").Where(typex => typex.HasCategoryAttribute("basetype"))
                            .ToDictionary(
                typex => typex.GetNameElement(),
                typex => typex.Element("type")?.Value ?? "IntPtr");

            baseTypes["VkBool32"] = "Bool32";

            var extensions = registry.Element("extensions").Elements("extension")
                             .Select(ExtensionDefinition.CreateFromXml).ToArray();

            var features = registry.Elements("feature")
                           .Select(FeatureDefinition.CreateFromXml)
                           .ToArray();

            return(new VulkanSpecification(
                       commandDefinitions,
                       constantDefinitions,
                       typedefDefinitions,
                       enumDefinitions,
                       structures,
                       unions,
                       handles,
                       baseTypes,
                       extensions,
                       features));
        }