Skip to content

Commit 76c5430

Browse files
committed
Bulkan - Beef Vulkan bindings generator
0 parents  commit 76c5430

22 files changed

+36226
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
\.vs/
2+
3+
*.suo
4+
*.user
5+
bin
6+
obj
7+
packages

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "Bulkan"]
2+
path = Bulkan
3+
url = [email protected]:jayrulez/Bulkan.git

Bulkan

Submodule Bulkan added at e092218

BulkanGen/BulkanGen.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31912.275
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BulkanGen", "BulkanGen\BulkanGen.csproj", "{6662194B-5765-4700-9884-1F8D39EAE1A3}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{6662194B-5765-4700-9884-1F8D39EAE1A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{6662194B-5765-4700-9884-1F8D39EAE1A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{6662194B-5765-4700-9884-1F8D39EAE1A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{6662194B-5765-4700-9884-1F8D39EAE1A3}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {0B8FFAD1-76B0-4E90-AD7E-2E36B603784B}
24+
EndGlobalSection
25+
EndGlobal

BulkanGen/BulkanGen/BulkanGen.csproj

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
}
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System.Xml.Linq;
2+
3+
namespace BulkanGen
4+
{
5+
public enum ConstantType
6+
{
7+
None,
8+
UInt32,
9+
UInt64,
10+
Float32,
11+
String
12+
}
13+
14+
public class ConstantDefinition
15+
{
16+
public string Name;
17+
public string Value;
18+
public string Alias;
19+
public ConstantType Type;
20+
public string Comment;
21+
22+
public static ConstantType ParseType(string value)
23+
{
24+
if (value.StartsWith('"'))
25+
{
26+
return ConstantType.String;
27+
}
28+
else if (value.EndsWith("f") || value.EndsWith("F"))
29+
{
30+
return ConstantType.Float32;
31+
}
32+
else if (value.EndsWith("ULL)"))
33+
{
34+
return ConstantType.UInt64;
35+
}
36+
else
37+
{
38+
return ConstantType.UInt32;
39+
}
40+
}
41+
42+
public static ConstantDefinition FromXML(XElement elem)
43+
{
44+
ConstantDefinition constant = new ConstantDefinition();
45+
constant.Name = elem.Attribute("name").Value;
46+
constant.Comment = elem.Attribute("comment")?.Value;
47+
constant.Alias = elem.Attribute("alias")?.Value;
48+
49+
if (constant.Alias == null)
50+
{
51+
constant.Value = elem.Attribute("value").Value;
52+
constant.Type = ParseType(constant.Value);
53+
}
54+
55+
return constant;
56+
}
57+
58+
public static object NormalizeValue(string value)
59+
{
60+
return value.Replace("ULL", "UL");
61+
}
62+
}
63+
}

BulkanGen/BulkanGen/EnumDefinition.cs

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System.Collections.Generic;
2+
using System.Xml.Linq;
3+
4+
namespace BulkanGen
5+
{
6+
public enum EnumType
7+
{
8+
Enum,
9+
Bitmask,
10+
}
11+
12+
public class EnumDefinition
13+
{
14+
public string Name;
15+
public EnumType Type;
16+
public List<EnumValue> Values = new List<EnumValue>();
17+
18+
public static EnumDefinition FromXML(XElement elem)
19+
{
20+
EnumDefinition enums = new EnumDefinition();
21+
enums.Name = elem.Attribute("name").Value;
22+
enums.Type = elem.Attribute("type").Value == "enum" ? EnumType.Enum : EnumType.Bitmask;
23+
var values = elem.Elements("enum");
24+
foreach (var v in values)
25+
{
26+
enums.Values.Add(EnumValue.FromXML(v));
27+
}
28+
29+
return enums;
30+
}
31+
}
32+
33+
public class EnumValue
34+
{
35+
public string Name;
36+
public string Alias;
37+
public int Value;
38+
public string Comment;
39+
40+
internal static EnumValue FromXML(XElement elem)
41+
{
42+
EnumValue enumValue = new EnumValue();
43+
enumValue.Name = elem.Attribute("name").Value;
44+
enumValue.Comment = elem.Attribute("comment")?.Value;
45+
enumValue.Alias = elem.Attribute("alias")?.Value;
46+
47+
string valueString = elem.Attribute("value")?.Value;
48+
if (valueString != null)
49+
{
50+
if (valueString.StartsWith("0x"))
51+
{
52+
valueString = valueString.Substring(2);
53+
enumValue.Value = int.Parse(valueString, System.Globalization.NumberStyles.HexNumber);
54+
}
55+
else
56+
{
57+
enumValue.Value = int.Parse(valueString);
58+
}
59+
}
60+
else if (enumValue.Alias == null)
61+
{
62+
string bitpos = elem.Attribute("bitpos").Value;
63+
enumValue.Value = 1 << int.Parse(bitpos);
64+
}
65+
66+
//Console.WriteLine($"{enumValue.Name}:{valueString}:{enumValue.Value}");
67+
68+
return enumValue;
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)