|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Text; |
| 3 | +using System.Xml.Linq; |
| 4 | + |
| 5 | +namespace BulkanGen |
| 6 | +{ |
| 7 | + public class CommandDefinition |
| 8 | + { |
| 9 | + public Proto Prototype; |
| 10 | + public List<Param> Parameters = new List<Param>(); |
| 11 | + public string[] Queues; |
| 12 | + public string RenderPass; |
| 13 | + public string[] CmdBufferLevel; |
| 14 | + public string Pipeline; |
| 15 | + public string[] SuccessCodes; |
| 16 | + public string[] ErrorCodes; |
| 17 | + public string Comment; |
| 18 | + |
| 19 | + public static CommandDefinition FromXML(XElement elem) |
| 20 | + { |
| 21 | + CommandDefinition command = new CommandDefinition(); |
| 22 | + |
| 23 | + command.SuccessCodes = elem.Attribute("successcodes")?.Value.Split(','); |
| 24 | + command.ErrorCodes = elem.Attribute("errorcodes")?.Value.Split(','); |
| 25 | + command.Queues = elem.Attribute("queues")?.Value.Split(','); |
| 26 | + command.RenderPass = elem.Attribute("renderpass")?.Value; |
| 27 | + command.Pipeline = elem.Attribute("pipeline")?.Value; |
| 28 | + command.CmdBufferLevel = elem.Attribute("cmdbufferlevel")?.Value.Split(','); |
| 29 | + command.Comment = elem.Attribute("comment")?.Value; |
| 30 | + |
| 31 | + var proto = elem.Element("proto"); |
| 32 | + |
| 33 | + if (proto != null) |
| 34 | + { |
| 35 | + command.Prototype = new Proto |
| 36 | + { |
| 37 | + Name = proto.Element("name").Value, |
| 38 | + Type = proto.Element("type").Value, |
| 39 | + }; |
| 40 | + } |
| 41 | + |
| 42 | + var parameters = elem.Elements("param"); |
| 43 | + foreach (var param in parameters) |
| 44 | + { |
| 45 | + command.Parameters.Add(Param.FromXML(param)); |
| 46 | + } |
| 47 | + |
| 48 | + return command; |
| 49 | + } |
| 50 | + |
| 51 | + public string GetParametersSignature(VulkanSpecification spec, bool useTypes = true) |
| 52 | + { |
| 53 | + StringBuilder signature = new StringBuilder(); |
| 54 | + foreach (var p in Parameters) |
| 55 | + { |
| 56 | + string convertedType = Helpers.GetPrettyEnumName(Helpers.ConvertToBeefType(p.Type, p.PointerLevel, spec)); |
| 57 | + string convertedName = Helpers.ValidatedName(p.Name); |
| 58 | + |
| 59 | + if (useTypes) |
| 60 | + signature.Append($"{convertedType} "); |
| 61 | + |
| 62 | + signature.Append($"{convertedName}, "); |
| 63 | + } |
| 64 | + |
| 65 | + signature.Length -= 2; |
| 66 | + |
| 67 | + return signature.ToString(); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + public class Proto |
| 72 | + { |
| 73 | + public string Type; |
| 74 | + public string Name; |
| 75 | + } |
| 76 | + |
| 77 | + public class Param |
| 78 | + { |
| 79 | + public string Type; |
| 80 | + public string Name; |
| 81 | + public int PointerLevel; |
| 82 | + public bool IsOptional; |
| 83 | + public string Externsync; |
| 84 | + public string Len; |
| 85 | + public bool IsNoautovalidity; |
| 86 | + |
| 87 | + internal static Param FromXML(XElement elem) |
| 88 | + { |
| 89 | + Param p = new Param(); |
| 90 | + p.Type = elem.Element("type").Value; |
| 91 | + p.Name = elem.Element("name").Value; |
| 92 | + p.Externsync = elem.Attribute("externsync")?.Value; |
| 93 | + p.Len = elem.Attribute("len")?.Value; |
| 94 | + p.IsNoautovalidity = elem.Attribute("noautovalidity")?.Value == "true"; |
| 95 | + p.IsOptional = elem.Attribute("optional")?.Value == "true"; |
| 96 | + |
| 97 | + if (elem.Value.Contains($"{p.Type}**") || elem.Value.Contains($"{p.Type}* const*")) |
| 98 | + { |
| 99 | + p.PointerLevel = 2; |
| 100 | + } |
| 101 | + else if (elem.Value.Contains($"{p.Type}*")) |
| 102 | + { |
| 103 | + p.PointerLevel = 1; |
| 104 | + } |
| 105 | + |
| 106 | + return p; |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments