aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2021-12-01 18:46:52 +0100
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2021-12-01 18:46:52 +0100
commit4a39db4c1d61907188a411d4db73033f77fc4813 (patch)
tree6e273b3cfb3cbb6732c3e7801d5f71a5d84c39ee
parentf9f1d0b1f9a7b14d1e2479af2ed2968b78c56a9a (diff)
Vulkan-Docs as submodule, netcoreapp3.1 for tools
-rw-r--r--.gitignore1
-rw-r--r--.gitmodules3
-rw-r--r--Directory.Build.props8
-rw-r--r--FUNDING.yml1
m---------Vulkan-Docs0
-rwxr-xr-xclean.sh2
-rw-r--r--vk.generator/Program.cs2309
-rw-r--r--vk.generator/vk.generator.csproj8
-rw-r--r--vk.net.sln9
-rw-r--r--vk.rewrite/vk.rewrite.csproj6
-rw-r--r--vulkan/BindingsHelpers.cs (renamed from VK/BindingsHelpers.cs)0
-rw-r--r--vulkan/CalliRewriteAttribute.cs (renamed from VK/CalliRewriteAttribute.cs)0
-rw-r--r--vulkan/Commands.cs (renamed from VK/Commands.cs)0
-rw-r--r--vulkan/Delegates.cs (renamed from VK/Delegates.cs)0
-rw-r--r--vulkan/ExternalTypes.cs (renamed from VK/ExternalTypes.cs)0
-rw-r--r--vulkan/Kernel32.cs (renamed from VK/Kernel32.cs)0
-rw-r--r--vulkan/Libdl.cs (renamed from VK/Libdl.cs)0
-rw-r--r--vulkan/Structs.cs (renamed from VK/Structs.cs)0
-rw-r--r--vulkan/Utils.cs (renamed from VK/Utils.cs)0
-rw-r--r--vulkan/Version.cs (renamed from VK/Version.cs)0
-rw-r--r--vulkan/VkBool32.cs (renamed from VK/VkBool32.cs)0
-rw-r--r--vulkan/VkExtent2D.cs (renamed from VK/VkExtent2D.cs)0
-rw-r--r--vulkan/VkOffset2D.cs (renamed from VK/VkOffset2D.cs)0
-rw-r--r--vulkan/VkRect2D.cs (renamed from VK/VkRect2D.cs)0
-rw-r--r--vulkan/vk.net-128.png (renamed from VK/vk.net-128.png)bin4502 -> 4502 bytes
-rw-r--r--vulkan/vk.net-64.png (renamed from VK/vk.net-64.png)bin2263 -> 2263 bytes
-rw-r--r--vulkan/vulkan.csproj59
27 files changed, 1218 insertions, 1188 deletions
diff --git a/.gitignore b/.gitignore
index 4803fb0..57d44d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+.vscode
.vs
build/
packages/
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..079a887
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "Vulkan-Docs"]
+ path = Vulkan-Docs
+ url = https://github.com/KhronosGroup/Vulkan-Docs.git
diff --git a/Directory.Build.props b/Directory.Build.props
index d6e4484..a15e6fa 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -8,12 +8,8 @@
<Authors>Jean-Philippe Bruyère</Authors>
<Copyright></Copyright>
<Company></Company>
-
- <IntermediateOutputPath>$(SolutionDir)build\obj\$(Configuration)\</IntermediateOutputPath>
- <OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
- <LangVersion>7.2</LangVersion>
- <ToolsFramework>net472</ToolsFramework>
-
+ <ToolsFramework>netcoreapp3.1</ToolsFramework>
+
</PropertyGroup>
</Project>
diff --git a/FUNDING.yml b/FUNDING.yml
new file mode 100644
index 0000000..253a06e
--- /dev/null
+++ b/FUNDING.yml
@@ -0,0 +1 @@
+custom: "https://www.paypal.me/GrandTetraSoftware"
diff --git a/Vulkan-Docs b/Vulkan-Docs
new file mode 160000
+Subproject d70e01c0be7b8a7d20b186b30b29a75b18bba75
diff --git a/clean.sh b/clean.sh
deleted file mode 100755
index d39df8f..0000000
--- a/clean.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/bash
-rm -fr build && find . -iname bin -o -iname obj | xargs rm -rf
diff --git a/vk.generator/Program.cs b/vk.generator/Program.cs
index 326196d..2cc3094 100644
--- a/vk.generator/Program.cs
+++ b/vk.generator/Program.cs
@@ -10,1343 +10,1312 @@ using System.Xml;
using System.Linq;
using System.Net;
-namespace vk.generator
-{
+namespace vk.generator {
- #region ExtensionsMethods
- public static class ExtensionsMethods
- {
- public static string RemoveTagsAndFlagsSuffix (this string s) {
- if (string.IsNullOrEmpty (s))
- return s;
- string tmp = s.Replace ("Flags", "");
- foreach (string tag in Generator.tags) {
- if (tmp.EndsWith (tag, StringComparison.Ordinal)) {
- tmp = tmp.Remove (tmp.Length - tag.Length);
- break;
- }
- }
- return tmp;
- }
- public static string RemoveCommonLeadingPart (this string s, string other) {
- string tmp = "";
- string tmp2 = other.Replace ("Flags", "");
+ #region ExtensionsMethods
+ public static class ExtensionsMethods {
+ public static string RemoveTagsAndFlagsSuffix(this string s) {
+ if (string.IsNullOrEmpty(s))
+ return s;
+ string tmp = s.Replace("Flags", "");
+ foreach (string tag in Generator.tags) {
+ if (tmp.EndsWith(tag, StringComparison.Ordinal)) {
+ tmp = tmp.Remove(tmp.Length - tag.Length);
+ break;
+ }
+ }
+ return tmp;
+ }
+ public static string RemoveCommonLeadingPart (this string s, string other) {
+ string tmp = "";
+ string tmp2 = other.Replace ("Flags", "");
- foreach (string tag in Generator.tags) {
- if (tmp2.EndsWith (tag, StringComparison.Ordinal)) {
- tmp2 = tmp2.Remove (tmp2.Length - tag.Length);
- break;
- }
- }
+ foreach (string tag in Generator.tags) {
+ if (tmp2.EndsWith (tag, StringComparison.Ordinal)) {
+ tmp2 = tmp2.Remove (tmp2.Length - tag.Length);
+ break;
+ }
+ }
- for (int i = 0; i < tmp2.Length; i++) {
- if (s[i] != tmp2[i]) {
- tmp = s.Substring (i);
- break;
- }
- }
- if (string.IsNullOrEmpty (tmp))
- tmp = s.Substring (tmp2.Length);
- if (char.IsNumber (tmp[0])) {
- tmp2 = tmp2.Replace ("Type", "");
- return
- tmp2.Substring (2) + tmp;
- }
- return tmp;
- }
+ for (int i = 0; i < tmp2.Length; i++) {
+ if (s[i] != tmp2[i]) {
+ tmp = s.Substring (i);
+ break;
+ }
+ }
+ if (string.IsNullOrEmpty (tmp))
+ tmp = s.Substring (tmp2.Length);
+ if (char.IsNumber (tmp[0])) {
+ tmp2 = tmp2.Replace ("Type", "");
+ return
+ tmp2.Substring (2) + tmp;
+ }
+ return tmp;
+ }
- public static string ConvertUnderscoredUpperCasedNameToCamelCase (this string name) {
- string[] tmp = name.Split ('_');
- List<string> result = new List<string> ();
- for (int i = 0; i < tmp.Length; i++) {
- string s = tmp[i];
- if (s == "BIT")
- continue;
- if ((i == tmp.Length - 1 && Generator.tags.Contains (s)) || (char.IsDigit (s[0]) && s.Substring (1) == "D"))
- result.Add (s);
- else
- result.Add (s[0] + s.Substring (1).ToLower ());
- }
- return result.Aggregate ((a, b) => a + b);
- }
- public static string[] SplitCamelCased (this string cc) {
- List<string> result = new List<string> ();
+ public static string ConvertUnderscoredUpperCasedNameToCamelCase (this string name) {
+ string[] tmp = name.Split ('_');
+ List<string> result = new List<string> ();
+ for (int i = 0; i < tmp.Length; i++) {
+ string s = tmp[i];
+ if (s == "BIT")
+ continue;
+ if ((i == tmp.Length - 1 && Generator.tags.Contains (s)) || (char.IsDigit (s[0]) && s.Substring (1) == "D"))
+ result.Add (s);
+ else
+ result.Add (s[0] + s.Substring (1).ToLower ());
+ }
+ return result.Aggregate ((a, b) => a + b);
+ }
+ public static string[] SplitCamelCased (this string cc) {
+ List<string> result = new List<string> ();
- string tmp = "";
- for (int i = 0; i < cc.Length; i++) {
- if (char.IsUpper (cc[i])) {
- if (!string.IsNullOrEmpty (tmp))
- result.Add (tmp);
- tmp = "" + cc[i];
- } else
- tmp += cc[i];
- }
- if (!string.IsNullOrEmpty (tmp))
- result.Add (tmp);
- return result.ToArray ();
- }
- }
- #endregion
- /// <summary>
- /// Code produced by this generator is greatly inspired from the work of https://github.com/mellinoe, but the generator
- /// has been recreated from scratch to be more like a simple functional parser easyer to tweak.
- /// </summary>
- public class Generator
- {
- const int extBase = 1000000000;
- const int extBlockSize = 1000;
- /// <summary> Main namespace for generated code. </summary>
- public const string vknamespace = "Vulkan";
- /// <summary> Static class encapsulating constants and methods </summary>
- public const string vkCommonCmdClassName = "Vk";
- /// <summary> Headers for generated c# files</summary>
- public const string heading = "/* autogenerated with http://github.com/jpbruyere/vk.net */";
- /// <summary> using to include in every generated c# files</summary>
- public static string[] defaultUsings = { "System" };
- /* credit to https://github.com/mellinoe for this list*/
- public static Dictionary<string, string> knownTypes = new Dictionary<string, string> {
- {"uint8_t", "byte"},
- {"char", "byte"},
- {"uint16_t", "ushort"},
- {"uint32_t", "uint"},
- {"uint64_t", "ulong"},
- {"int16_t", "short"},
- {"int32_t", "int"},
- {"int64_t", "long"},
- {"size_t", "UIntPtr"},
- {"VkSampleMask", "uint"},
- {"VkDeviceSize", "ulong"},
- {"VkDeviceAddress", "ulong"},
+ string tmp = "";
+ for (int i = 0; i < cc.Length; i++) {
+ if (char.IsUpper (cc[i])) {
+ if (!string.IsNullOrEmpty (tmp))
+ result.Add (tmp);
+ tmp = "" + cc[i];
+ } else
+ tmp += cc[i];
+ }
+ if (!string.IsNullOrEmpty (tmp))
+ result.Add (tmp);
+ return result.ToArray ();
+ }
+ }
+ #endregion
+ /// <summary>
+ /// Code produced by this generator is greatly inspired from the work of https://github.com/mellinoe, but the generator
+ /// has been recreated from scratch to be more like a simple functional parser easyer to tweak.
+ /// </summary>
+ public class Generator {
+ const int extBase = 1000000000;
+ const int extBlockSize = 1000;
+ /// <summary> Main namespace for generated code. </summary>
+ public const string vknamespace = "Vulkan";
+ /// <summary> Static class encapsulating constants and methods </summary>
+ public const string vkCommonCmdClassName = "Vk";
+ /// <summary> Headers for generated c# files</summary>
+ public const string heading = "/* autogenerated with http://github.com/jpbruyere/vk.net */";
+ /// <summary> using to include in every generated c# files</summary>
+ public static string[] defaultUsings = { "System" };
+ /* credit to https://github.com/mellinoe for this list*/
+ public static Dictionary<string, string> knownTypes = new Dictionary<string, string> {
+ {"uint8_t", "byte"},
+ {"int8_t", "byte"},
+ {"char", "byte"},
+ {"uint16_t", "ushort"},
+ {"uint32_t", "uint"},
+ {"uint64_t", "ulong"},
+ {"int16_t", "short"},
+ {"int32_t", "int"},
+ {"int64_t", "long"},
+ {"size_t", "UIntPtr"},
+ {"VkSampleMask", "uint"},
+ {"VkDeviceSize", "ulong"},
+ {"VkDeviceAddress", "ulong"},
- {"HMONITOR", "IntPtr"},
+ {"HMONITOR", "IntPtr"},
- { "DWORD", "uint" },
+ { "DWORD", "uint" },
- { "ANativeWindow", "Android.ANativeWindow" },
+ { "ANativeWindow", "Android.ANativeWindow" },
- { "MirConnection", "Mir.MirConnection" },
- { "MirSurface", "Mir.MirSurface" },
+ { "MirConnection", "Mir.MirConnection" },
+ { "MirSurface", "Mir.MirSurface" },
- { "wl_display", "Wayland.wl_display" },
- { "wl_surface", "Wayland.wl_surface" },
+ { "wl_display", "Wayland.wl_display" },
+ { "wl_surface", "Wayland.wl_surface" },
- { "Display", "Xlib.Display" },
- { "Window", "Xlib.Window" },
- { "VisualID", "Xlib.VisualID" },
- { "RROutput", "IntPtr" },
+ { "Display", "Xlib.Display" },
+ { "Window", "Xlib.Window" },
+ { "VisualID", "Xlib.VisualID" },
+ { "RROutput", "IntPtr" },
- { "HINSTANCE", "Win32.HINSTANCE" },
- { "HWND", "Win32.HWND" },
- { "HANDLE", "Win32.HANDLE" },
- { "SECURITY_ATTRIBUTES", "Win32.SECURITY_ATTRIBUTES" },
- { "LPCWSTR", "IntPtr" },
+ { "HINSTANCE", "Win32.HINSTANCE" },
+ { "HWND", "Win32.HWND" },
+ { "HANDLE", "Win32.HANDLE" },
+ { "SECURITY_ATTRIBUTES", "Win32.SECURITY_ATTRIBUTES" },
+ { "LPCWSTR", "IntPtr" },
- { "xcb_connection_t", "Xcb.xcb_connection_t" },
- { "xcb_window_t", "Xcb.xcb_window_t" },
- { "xcb_visualid_t", "Xcb.xcb_visualid_t" },
+ { "xcb_connection_t", "Xcb.xcb_connection_t" },
+ { "xcb_window_t", "Xcb.xcb_window_t" },
+ { "xcb_visualid_t", "Xcb.xcb_visualid_t" },
//those are not checked, just putted there for compiling
{ "GgpFrameToken", "uint" }, //cant find header to check length
{ "zx_handle_t", "ulong" },
- { "GgpStreamDescriptor", "ulong" },
- { "PFN_vkVoidFunction","IntPtr" },
- { "AHardwareBuffer", "Android.ANativeWindow" },//must be corrected
+ { "GgpStreamDescriptor", "ulong" },
+ { "PFN_vkVoidFunction","IntPtr" },
+ { "AHardwareBuffer", "Android.ANativeWindow" },//must be corrected
{ "IDirectFB","IntPtr" },
- { "IDirectFBSurface","IntPtr" },
+ { "IDirectFBSurface","IntPtr" },
- };
+ { "_screen_window","IntPtr" },
+ { "StdVideoH265ProfileIdc","IntPtr" },
+ { "StdVideoH264ProfileIdc","IntPtr" },
+ { "VkRemoteAddressNV","IntPtr" },
+ };
- static string[] skipEnums = { "VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES2_EXT", "VK_PIPELINE_CREATE_DISPATCH_BASE" };
+ static string[] skipEnums = { "VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES2_EXT", "VK_PIPELINE_CREATE_DISPATCH_BASE" };
- static Dictionary<string, string[]> paramTypeAliases = new Dictionary<string, string[]> {
- { "void*", new string[] {"IntPtr"} },
- { "char*", new string[] {"string"} }
- };
+ static Dictionary<string, string[]> paramTypeAliases = new Dictionary<string, string[]> {
+ { "void*", new string[] {"IntPtr"} },
+ { "char*", new string[] {"string"} }
+ };
- public static Dictionary<string, string> aliases = new Dictionary<string, string> ();
- static void AddAlias (string from, string to) {
- if (to == "VkFlags")//dont alias to VkFlags
- return;
- if (aliases.ContainsKey (from))
- Console.WriteLine ($"aliases list constains already an alias for: {from}");
- else
- aliases.Add (from, to);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine ($"adding alias {from} -> {to}");
- Console.ForegroundColor = ConsoleColor.Gray;
- }
+ public static Dictionary<string, string> aliases = new Dictionary<string, string> ();
+ static void AddAlias (string from, string to) {
+ if (to == "VkFlags")//dont alias to VkFlags
+ return;
+ if (aliases.ContainsKey (from))
+ Console.WriteLine ($"aliases list constains already an alias for: {from}");
+ else
+ aliases.Add (from, to);
+ Console.ForegroundColor = ConsoleColor.Green;
+ Console.WriteLine ($"adding alias {from} -> {to}");
+ Console.ForegroundColor = ConsoleColor.Gray;
+ }
- enum EnumTypes { bitmask, @enum };
- enum ExtensionType { None, Device, Instance }
- enum TypeCategories { none, basetype, bitmask, define, @enum, funcpointer, group, handle, include, @struct, @union };
+ enum EnumTypes { bitmask, @enum };
+ enum ExtensionType { None, Device, Instance }
+ enum TypeCategories {none, basetype, bitmask, define, @enum, funcpointer, group, handle, include, @struct, @union };
- //function pointers to retrieve before any other vulkan api call.
- //those command should not move in other iface than common to be preload by normal dyn load
- static string[] preloadedCommands = {
- "vkCreateInstance",
- "vkDestroyInstance",
- "vkGetDeviceProcAddr",
- "vkGetInstanceProcAddr",
- "vkEnumerateInstanceExtensionProperties",
- "vkEnumerateInstanceLayerProperties",
- "vkEnumerateInstanceVersion"};
+ //function pointers to retrieve before any other vulkan api call.
+ //those command should not move in other iface than common to be preload by normal dyn load
+ static string[] preloadedCommands = {
+ "vkCreateInstance",
+ "vkDestroyInstance",
+ "vkGetDeviceProcAddr",
+ "vkGetInstanceProcAddr",
+ "vkEnumerateInstanceExtensionProperties",
+ "vkEnumerateInstanceLayerProperties",
+ "vkEnumerateInstanceVersion"};
static string[] reservedNames = { "event", "object" };
- static Dictionary<string, ParamDef> paramsDefs = new Dictionary<string, ParamDef> ();
+ static Dictionary<string, ParamDef> paramsDefs = new Dictionary<string, ParamDef> ();
- public static List<string> tags = new List<string> ();
+ public static List<string> tags = new List<string> ();
- class Definition
- {
- public List<string> definedBy = new List<string> ();
- protected string name;
- public string comment;
- public override string ToString () => this.GetType ().Name + ":" + name;
+ class Definition {
+ public List<string> definedBy = new List<string>();
+ protected string name;
+ public string comment;
+ public override string ToString () => this.GetType ().Name + ":" + name;
- public string Name {
- get { return reservedNames.Contains (name) ? "_" + name : name; }
- set { name = value; }
- }
- public virtual string CSName {
- get {
- string tmp = name.Replace ("FlagBits", "Flags");
- while (Generator.aliases.ContainsKey (tmp)) //recurse in aliases
- tmp = Generator.aliases[tmp];
+ public string Name {
+ get { return reservedNames.Contains (name) ? "_" + name : name; }
+ set { name = value; }
+ }
+ public virtual string CSName {
+ get {
+ string tmp = name.Replace ("FlagBits", "Flags");
+ while (Generator.aliases.ContainsKey (tmp)) //recurse in aliases
+ tmp = Generator.aliases[tmp];
- return (Generator.knownTypes.ContainsKey (tmp) ? Generator.knownTypes[tmp] : tmp);
- }
- }
- }
+ return (Generator.knownTypes.ContainsKey (tmp) ? Generator.knownTypes[tmp] : tmp);
+ }
+ }
+ }
- class StructDef : TypeDef
- {
- public List<MemberDef> members = new List<MemberDef> ();
- }
- class TypeDef : Definition
- {
- public TypeCategories category;
- public string baseType;
- public string require;
- }
- class EnumDef : Definition
- {
- //public string require;
- public EnumTypes type;
- public int start;
- public int end;
- public string vendor;
+ class StructDef : TypeDef {
+ public List<MemberDef> members = new List<MemberDef> ();
+ }
+ class TypeDef : Definition {
+ public TypeCategories category;
+ public string baseType;
+ public string require;
+ }
+ class EnumDef : Definition {
+ //public string require;
+ public EnumTypes type;
+ public int start;
+ public int end;
+ public string vendor;
- public List<EnumerantValue> values = new List<EnumerantValue> ();
- }
- class HandleDef : TypeDef
- {
- public string parent;
- public bool nonDispatchable => baseType == "VK_DEFINE_NON_DISPATCHABLE_HANDLE";
- }
- class ParamDef : Definition
- {
- public string txtbefore;
- public string txtafter;
+ public List<EnumerantValue> values = new List<EnumerantValue> ();
+ }
+ class HandleDef : TypeDef {
+ public string parent;
+ public bool nonDispatchable => baseType == "VK_DEFINE_NON_DISPATCHABLE_HANDLE";
+ }
+ class ParamDef : Definition {
+ public string txtbefore;
+ public string txtafter;
- public static ParamDef parse (XmlNode n) {
- XmlNode t = n["type"];
- ParamDef tmp = new ParamDef ();
- tmp.name = t.InnerText;
- if (t.PreviousSibling?.NodeType == XmlNodeType.Text)
- tmp.txtbefore = t.PreviousSibling.Value;
- if (t.NextSibling?.NodeType == XmlNodeType.Text)
- tmp.txtafter = t.NextSibling.Value;
+ public static ParamDef parse (XmlNode n) {
+ XmlNode t = n["type"];
+ ParamDef tmp = new ParamDef ();
+ tmp.name = t.InnerText;
+ if (t.PreviousSibling?.NodeType == XmlNodeType.Text)
+ tmp.txtbefore = t.PreviousSibling.Value;
+ if (t.NextSibling?.NodeType == XmlNodeType.Text)
+ tmp.txtafter = t.NextSibling.Value;
- if (paramsDefs.ContainsKey (tmp.FullCTypeDecl))
- return paramsDefs[tmp.FullCTypeDecl];
+ if (paramsDefs.ContainsKey (tmp.FullCTypeDecl))
+ return paramsDefs[tmp.FullCTypeDecl];
- paramsDefs.Add (tmp.FullCTypeDecl, tmp);
+ paramsDefs.Add (tmp.FullCTypeDecl, tmp);
- return tmp;
- }
+ return tmp;
+ }
- public string FullCTypeDecl => txtbefore + name + txtafter;
- public int IndirectionLevel {
- get {
- if (string.IsNullOrEmpty (txtafter))
- return 0;
- int i = 0;
- foreach (char c in txtafter) {
- if (c == '*')
- i++;
- }
- return i;
- }
- }
- public bool IsStruct => string.IsNullOrEmpty (txtbefore) ? false : txtbefore.Contains ("struct");
- public bool IsConst => string.IsNullOrEmpty (txtbefore) ? false : txtbefore.Contains ("const");
- public override string ToString () => FullCTypeDecl;
- }
- class MemberDef : Definition
- {
- public ParamDef typedef;
+ public string FullCTypeDecl => txtbefore + name + txtafter;
+ public int IndirectionLevel {
+ get {
+ if (string.IsNullOrEmpty (txtafter))
+ return 0;
+ int i = 0;
+ foreach (char c in txtafter) {
+ if (c == '*')
+ i++;
+ }
+ return i;
+ }
+ }
+ public bool IsStruct => string.IsNullOrEmpty (txtbefore) ? false : txtbefore.Contains ("struct");
+ public bool IsConst => string.IsNullOrEmpty (txtbefore) ? false : txtbefore.Contains ("const");
+ public override string ToString () => FullCTypeDecl;
+ }
+ class MemberDef : Definition {
+ public ParamDef typedef;
- public bool isReadOnly;
- public bool optional;
- public bool externsync;
- public bool nullTerminated;
- public string lenMember;
- public string defaultValue;
- public string fixedArray;
+ public bool isReadOnly;
+ public bool optional;
+ public bool externsync;
+ public bool nullTerminated;
+ public string lenMember;
+ public string defaultValue;
+ public string fixedArray;
- public override string ToString () => string.Format ($"memberdef: {typedef.FullCTypeDecl} {name}");
- }
+ public override string ToString () => string.Format ($"memberdef: {typedef.FullCTypeDecl} {name}");
+ }
- class EnumerantValue : Definition, IEquatable<EnumerantValue>
- {//name is not yet converted to csname!!
- public string unusedComment;
- public string extends;
- public string value;
- public bool isAlias;
- public override string ToString () => string.Format ($"{name} = {value}");
- public override string CSName => throw new NotImplementedException (); //name.ConvertUnderscoredUpperCasedNameToCamelCase ();
+ class EnumerantValue : Definition, IEquatable<EnumerantValue>{//name is not yet converted to csname!!
+ public string unusedComment;
+ public string extends;
+ public string value;
+ public bool isAlias;
+ public override string ToString () => string.Format ($"{name} = {value}");
+ public override string CSName => throw new NotImplementedException (); //name.ConvertUnderscoredUpperCasedNameToCamelCase ();
- public string GetCSName (string containingType = null) {
- return GetCSName (name, containingType);
- // name.ConvertUnderscoredUpperCasedNameToCamelCase ().RemoveCommonLeadingPart (containingType.CSName);
- }
- public static string GetCSName (string value, string containingType) {
- string ccValue = value.ConvertUnderscoredUpperCasedNameToCamelCase ();
- string cType = containingType?.RemoveTagsAndFlagsSuffix ();
- return containingType == null || (ccValue.Length > cType.Length && cType != ccValue.Substring (0, cType.Length)) ?
- ccValue.StartsWith ("Vk", StringComparison.Ordinal) ? ccValue.Substring (2) : ccValue :
- ccValue.RemoveCommonLeadingPart (containingType);
- }
+ public string GetCSName (string containingType = null) {
+ return GetCSName (name, containingType);
+ // name.ConvertUnderscoredUpperCasedNameToCamelCase ().RemoveCommonLeadingPart (containingType.CSName);
+ }
+ public static string GetCSName (string value, string containingType) {
+ string ccValue = value.ConvertUnderscoredUpperCasedNameToCamelCase();
+ string cType = containingType?.RemoveTagsAndFlagsSuffix();
+ return containingType == null || (ccValue.Length > cType.Length && cType != ccValue.Substring(0, cType.Length)) ?
+ ccValue.StartsWith("Vk", StringComparison.Ordinal) ? ccValue.Substring(2) : ccValue :
+ ccValue.RemoveCommonLeadingPart (containingType);
+ }
- public bool Equals (EnumerantValue other) {
- return name == other.name;
- }
- public override bool Equals (object obj) {
- if (obj == null) return false;
- return name == (obj as EnumerantValue).name;
- }
- public override int GetHashCode () {
- return value.GetHashCode ();
- }
- }
+ public bool Equals (EnumerantValue other) {
+ return name == other.name;
+ }
+ public override bool Equals(object obj){
+ if(obj == null) return false;
+ return name == (obj as EnumerantValue).name;
+ }
+ public override int GetHashCode(){
+ return value.GetHashCode();
+ }
+ }
- class FuncpointerDef : TypeDef
- {
- public ParamDef returnType;
- public List<MemberDef> parameters = new List<MemberDef> ();
- }
- class CommandDef : FuncpointerDef
- {
- public string alias;
- public string successCodes;
- public string errorcodes;
- }
+ class FuncpointerDef : TypeDef {
+ public ParamDef returnType;
+ public List<MemberDef> parameters = new List<MemberDef> ();
+ }
+ class CommandDef : FuncpointerDef {
+ public string alias;
+ public string successCodes;
+ public string errorcodes;
+ }
- static List<TypeDef> types = new List<TypeDef> ();
- static List<EnumDef> enums = new List<EnumDef> ();
- static List<CommandDef> commands = new List<CommandDef> ();
- static List<EnumerantValue> extends = new List<EnumerantValue> ();
- static List<EnumerantValue> Constants = new List<EnumerantValue> ();
+ static List<TypeDef> types = new List<TypeDef> ();
+ static List<EnumDef> enums = new List<EnumDef> ();
+ static List<CommandDef> commands = new List<CommandDef> ();
+ static List<EnumerantValue> extends = new List<EnumerantValue> ();
+ static List<EnumerantValue> Constants = new List<EnumerantValue> ();
- class InterfaceDef : Definition
- {
- public int number;
- }
- class FeatureDef : InterfaceDef
- {
- public string api;
- public int major;
- public int minor;
- }
- class ExtensionDef : InterfaceDef
- {
- public ExtensionType type;
- public string supported;
- public string[] requires;
- }
+ class InterfaceDef : Definition {
+ public int number;
+ }
+ class FeatureDef : InterfaceDef {
+ public string api;
+ public int major;
+ public int minor;
+ }
+ class ExtensionDef : InterfaceDef {
+ public ExtensionType type;
+ public string supported;
+ public string[] requires;
+ }
- static List<FeatureDef> features = new List<FeatureDef> ();
- static List<ExtensionDef> extensions = new List<ExtensionDef> ();
+ static List<FeatureDef> features = new List<FeatureDef> ();
+ static List<ExtensionDef> extensions = new List<ExtensionDef> ();
- #region code generation
- static void writePreamble (IndentedTextWriter tw, params string[] additionalUsings) {
- tw.WriteLine (heading);
- foreach (string @using in defaultUsings)
- tw.WriteLine ($"using {@using};");
- foreach (string @using in additionalUsings)
- tw.WriteLine ($"using {@using};");
- tw.WriteLine ($"namespace {vknamespace} {{");
- }
+ #region code generation
+ static void writePreamble (IndentedTextWriter tw, params string[] additionalUsings) {
+ tw.WriteLine (heading);
+ foreach (string @using in defaultUsings)
+ tw.WriteLine ($"using {@using};");
+ foreach (string @using in additionalUsings)
+ tw.WriteLine ($"using {@using};");
+ tw.WriteLine ($"namespace {vknamespace} {{");
+ }
- static void writeStructNew (IndentedTextWriter tw, StructDef sd) {
- MemberDef md = sd.members.Where (mb => mb.Name == "sType").First ();
- TypeDef sType = types.Where (
- edd => edd.category == TypeCategories.@enum && edd.Name == md.typedef.Name).First ();
+ static void writeStructNew (IndentedTextWriter tw, StructDef sd) {
+ MemberDef md = sd.members.Where (mb => mb.Name == "sType").First ();
+ TypeDef sType = types.Where (
+ edd => edd.category == TypeCategories.@enum && edd.Name == md.typedef.Name).First ();
- tw.WriteLine ($"public static {sd.Name} New () {{");
- tw.Indent++;
+ tw.WriteLine ($"public static {sd.Name} New () {{");
+ tw.Indent++;
- tw.WriteLine ($"return new {sd.Name} {{");
- tw.Indent++;
+ tw.WriteLine ($"return new {sd.Name} {{");
+ tw.Indent++;
- tw.WriteLine ($"sType = {sType.CSName}.{EnumerantValue.GetCSName (md.defaultValue, sType.CSName)},");
- tw.WriteLine ($"pNext = IntPtr.Zero");
- tw.Indent--;
- tw.WriteLine (@"};");
- tw.Indent--;
- tw.WriteLine (@"}");
+ tw.WriteLine ($"sType = {sType.CSName}.{EnumerantValue.GetCSName (md.defaultValue, sType.CSName)},");
+ tw.WriteLine ($"pNext = IntPtr.Zero");
+ tw.Indent--;
+ tw.WriteLine (@"};");
+ tw.Indent--;
+ tw.WriteLine (@"}");
- tw.WriteLine ($"public {sd.Name} (IntPtr pNext) : this () {{");
- tw.Indent++;
+ tw.WriteLine ($"public {sd.Name} (IntPtr pNext) : this () {{");
+ tw.Indent++;
- tw.WriteLine ($"sType = {sType.CSName}.{EnumerantValue.GetCSName (md.defaultValue, sType.CSName)};");
- tw.WriteLine ($"this.pNext = pNext;");
+ tw.WriteLine ($"sType = {sType.CSName}.{EnumerantValue.GetCSName (md.defaultValue, sType.CSName)};");
+ tw.WriteLine ($"this.pNext = pNext;");
- tw.Indent--;
- tw.WriteLine (@"}");
- }
- static string[] valueTypes = { "byte", "int", "uint", "float", "ushort", "ulong" };
- static void gen_struct (IndentedTextWriter tw, StructDef sd) {
- if (sd.category == TypeCategories.union)
- tw.WriteLine ($"[StructLayout(LayoutKind.Explicit)]");
- else
- tw.WriteLine ($"[StructLayout(LayoutKind.Sequential)]");
- tw.WriteLine ($"public unsafe partial struct {sd.Name} {{");
- tw.Indent++;
- foreach (MemberDef mb in sd.members) {
- if (!string.IsNullOrEmpty (mb.comment))
- tw.WriteLine ($"/// <summary> {mb.comment} </summary>");
+ tw.Indent--;
+ tw.WriteLine (@"}");
+ }
+ static string[] valueTypes = { "byte", "int", "uint", "float", "ushort", "ulong" };
+ static void gen_struct (IndentedTextWriter tw, StructDef sd) {
+ if (sd.category == TypeCategories.union)
+ tw.WriteLine($"[StructLayout(LayoutKind.Explicit)]");
+ else
+ tw.WriteLine ($"[StructLayout(LayoutKind.Sequential)]");
+ tw.WriteLine ($"public unsafe partial struct {sd.Name} {{");
+ tw.Indent++;
+ foreach (MemberDef mb in sd.members) {
+ if (!string.IsNullOrEmpty (mb.comment))
+ tw.WriteLine ($"/// <summary> {mb.comment} </summary>");
- string typeStr;
+ string typeStr;
- EnumDef ed = enums.FirstOrDefault (e => e.Name == mb.typedef.Name);
+ EnumDef ed = enums.FirstOrDefault (e => e.Name == mb.typedef.Name);
- if (mb.typedef.IndirectionLevel > 0 || mb.typedef.Name.StartsWith ("PFN_", StringComparison.Ordinal))
- typeStr = "IntPtr";
- else if (ed != null) {
- //enums has to be stored in struct as int or uint for enums are not yet blittable in ms .NET
- typeStr = ed.type == EnumTypes.@enum ? "int" : "uint";
- tw.WriteLine ($"{typeStr} _{mb.Name};");
- tw.WriteLine ($"public {mb.typedef.CSName} {mb.Name} {{");
- tw.Indent++;
- tw.WriteLine ($"get => ({mb.typedef.CSName})_{mb.Name};");
- tw.WriteLine ($"set {{ _{mb.Name} = ({typeStr})value; }}");
- tw.Indent--;
- tw.WriteLine (@"}");
+ if (mb.typedef.IndirectionLevel > 0 || mb.typedef.Name.StartsWith ("PFN_", StringComparison.Ordinal))
+ typeStr = "IntPtr";
+ else if (ed != null) {
+ //enums has to be stored in struct as int or uint for enums are not yet blittable in ms .NET
+ typeStr = ed.type == EnumTypes.@enum ? "int" : "uint";
+ tw.WriteLine ($"{typeStr} _{mb.Name};");
+ tw.WriteLine ($"public {mb.typedef.CSName} {mb.Name} {{");
+ tw.Indent++;
+ tw.WriteLine ($"get => ({mb.typedef.CSName})_{mb.Name};");
+ tw.WriteLine ($"set {{ _{mb.Name} = ({typeStr})value; }}");
+ tw.Indent--;
+ tw.WriteLine (@"}");
- continue;
- } else
- typeStr = mb.typedef.CSName;
+ continue;
+ } else
+ typeStr = mb.typedef.CSName;
- if (sd.category == TypeCategories.union)
- tw.WriteLine ($"[FieldOffset(0)]");
+ if (sd.category == TypeCategories.union)
+ tw.WriteLine($"[FieldOffset(0)]");
- if (!string.IsNullOrEmpty (mb.fixedArray)) {
- int dim = 0;
- string[] dims = mb.fixedArray.Split (new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
- if (valueTypes.Contains (typeStr)) {
- if (mb.typedef.Name == "char") {
- if (dims.Length != 1)
- throw new NotImplementedException ("multi dimentional char* array not implemented");
- string strSize = int.TryParse (dims[0], out dim) ? dim.ToString () : $"(int)Vk.{EnumerantValue.GetCSName (dims[0], null)}";
- tw.WriteLine ($"fixed {typeStr} _{mb.Name}[{strSize}];");
- tw.WriteLine ($"public string {mb.Name} {{");
- tw.Indent++;
- tw.WriteLine ($"get {{");
- tw.Indent++;
- tw.WriteLine ($"fixed ({typeStr}* tmp = _{mb.Name})");
- tw.Indent++;
- tw.WriteLine ($"return System.Text.Encoding.UTF8.GetString (tmp, {strSize});");
- //tw.WriteLine ($"set {{ _{mb.Name} = ({typeStr})value; }}");
- tw.Indent -= 2;
- tw.WriteLine (@"}");
- tw.Indent--;
- tw.WriteLine (@"}");
- } else if (dims.Length == 1) {
- string strSize = int.TryParse (dims[0], out dim) ? dim.ToString () : $"(int)Vk.{EnumerantValue.GetCSName (dims[0], null)}";
- tw.WriteLine ($"public fixed {typeStr} {mb.Name}[{strSize}];");
- } else {
- int totSize = 1;
- for (int i = 0; i < dims.Length; i++) {
- if (!int.TryParse (dims[i], out dim))
- throw new NotImplementedException ("Only integer value accepted for multi dimentional arrays");
- totSize *= dim;
- }
- tw.WriteLine ($"fixed {typeStr} _{mb.Name}[{totSize}];");
+ if (!string.IsNullOrEmpty (mb.fixedArray)) {
+ int dim = 0;
+ string[] dims = mb.fixedArray.Split (new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
+ if (valueTypes.Contains (typeStr)) {
+ if (mb.typedef.Name == "char") {
+ if (dims.Length != 1)
+ throw new NotImplementedException ("multi dimentional char* array not implemented");
+ string strSize = int.TryParse (dims[0], out dim) ? dim.ToString () : $"(int)Vk.{EnumerantValue.GetCSName (dims[0], null)}";
+ tw.WriteLine ($"fixed {typeStr} _{mb.Name}[{strSize}];");
+ tw.WriteLine ($"public string {mb.Name} {{");
+ tw.Indent++;
+ tw.WriteLine ($"get {{");
+ tw.Indent++;
+ tw.WriteLine ($"fixed ({typeStr}* tmp = _{mb.Name})");
+ tw.Indent++;
+ tw.WriteLine ($"return System.Text.Encoding.UTF8.GetString (tmp, {strSize});");
+ //tw.WriteLine ($"set {{ _{mb.Name} = ({typeStr})value; }}");
+ tw.Indent -= 2;
+ tw.WriteLine (@"}");
+ tw.Indent--;
+ tw.WriteLine (@"}");
+ } else if (dims.Length == 1) {
+ string strSize = int.TryParse (dims[0], out dim) ? dim.ToString () : $"(int)Vk.{EnumerantValue.GetCSName (dims[0], null)}";
+ tw.WriteLine ($"public fixed {typeStr} {mb.Name}[{strSize}];");
+ } else {
+ int totSize = 1;
+ for (int i = 0; i < dims.Length; i++) {
+ if (!int.TryParse (dims[i], out dim))
+ throw new NotImplementedException ("Only integer value accepted for multi dimentional arrays");
+ totSize *= dim;
+ }
+ tw.WriteLine ($"fixed {typeStr} _{mb.Name}[{totSize}];");
- }
- continue;
- }
- if (dims.Length != 1)
- throw new NotImplementedException ("multi dimentional array not implemented");
- if (int.TryParse (dims[0], out dim)) {
- for (int i = 0; i < dim; i++) {
- tw.WriteLine ($"public {typeStr} {mb.Name}_{i};");
- }
- } else {
- tw.WriteLine ($"[MarshalAs (UnmanagedType.ByValArray, SizeConst = (int)Vk.{EnumerantValue.GetCSName (dims[0], null)})]");
- tw.WriteLine ($"public {typeStr}[] {mb.Name};");
- }
- continue;
- }
- tw.WriteLine ($"public {typeStr} {mb.Name};");
- }
+ }
+ continue;
+ }
+ if (dims.Length != 1)
+ throw new NotImplementedException ("multi dimentional array not implemented");
+ if (int.TryParse (dims[0], out dim)) {
+ for (int i = 0; i < dim; i++) {
+ tw.WriteLine ($"public {typeStr} {mb.Name}_{i};");
+ }
+ } else {
+ tw.WriteLine ($"[MarshalAs (UnmanagedType.ByValArray, SizeConst = (int)Vk.{EnumerantValue.GetCSName(dims[0], null)})]");
+ tw.WriteLine ($"public {typeStr}[] {mb.Name};");
+ }
+ continue;
+ }
+ tw.WriteLine ($"public {typeStr} {mb.Name};");
+ }
- if (sd.members.Any (mb => mb.Name == "sType" && !string.IsNullOrEmpty (mb.defaultValue)))
- writeStructNew (tw, sd); ;
+ if (sd.members.Any (mb => mb.Name == "sType" && !string.IsNullOrEmpty (mb.defaultValue)))
+ writeStructNew (tw, sd); ;
- tw.Indent--;
- tw.WriteLine (@"}");
- }
+ tw.Indent--;
+ tw.WriteLine (@"}");
+ }
- static void gen_structs (string englobingStaticClass) {
- using (StreamWriter sr = new StreamWriter ($"structs_{englobingStaticClass}_gen.cs", false, System.Text.Encoding.UTF8)) {
- using (IndentedTextWriter tw = new IndentedTextWriter (sr)) {
- writePreamble (tw, "System.Runtime.InteropServices");
- tw.Indent++;
+ static void gen_structs (string englobingStaticClass) {
+ using (StreamWriter sr = new StreamWriter (targetPath($"structs_{englobingStaticClass}"), false, System.Text.Encoding.UTF8)) {
+ using (IndentedTextWriter tw = new IndentedTextWriter (sr)) {
+ writePreamble (tw, "System.Runtime.InteropServices");
+ tw.Indent++;
- foreach (StructDef sd in types.OfType<StructDef> ())
- gen_struct (tw, sd);
+ foreach (StructDef sd in types.OfType<StructDef> ())
+ gen_struct (tw, sd);
- tw.Indent--;
- tw.WriteLine (@"}");
- }
- }
- }
- /* credit to https://github.com/mellinoe for the handle structs*/
- static void write_empty_enum_as_struct (IndentedTextWriter tw, EnumDef enumType) {
- tw.WriteLine (@"[DebuggerDisplay(""{DebuggerDisplay,nq}"")]");
- tw.WriteLine ($"public struct {enumType.CSName} : IEquatable<{enumType.CSName}>");
- tw.WriteLine (@"{");
- tw.Indent++;
+ tw.Indent--;
+ tw.WriteLine (@"}");
+ }
+ }
+ }
+ /* credit to https://github.com/mellinoe for the handle structs*/
+ static void write_empty_enum_as_struct (IndentedTextWriter tw, EnumDef enumType) {
+ tw.WriteLine (@"[DebuggerDisplay(""{DebuggerDisplay,nq}"")]");
+ tw.WriteLine ($"public struct {enumType.CSName} : IEquatable<{enumType.CSName}>");
+ tw.WriteLine (@"{");
+ tw.Indent++;
- string hType = "uint";
+ string hType = "uint";
- tw.WriteLine ($"public readonly {hType} Value;");
- tw.WriteLine ($"public {enumType.CSName}({hType} existingHandle) {{ Value = existingHandle; }}");
- tw.WriteLine ($"public static {enumType.CSName} Null => new {enumType.CSName}(0);");
- tw.WriteLine ($"public static implicit operator {enumType.CSName}({hType} flags) => new {enumType.CSName}(flags);");
- tw.WriteLine ($"public static bool operator ==({enumType.CSName} left, {enumType.CSName} right) => left.Value == right.Value;");
- tw.WriteLine ($"public static bool operator !=({enumType.CSName} left, {enumType.CSName} right) => left.Value != right.Value;");
- tw.WriteLine ($"public static bool operator ==({enumType.CSName} left, {hType} right) => left.Value == right;");
- tw.WriteLine ($"public static bool operator !=({enumType.CSName} left, {hType} right) => left.Value != right;");
- tw.WriteLine ($"public bool Equals({enumType.CSName} h) => Value == h.Value;");
- tw.WriteLine ($"public override bool Equals(object obj) => obj is {enumType.CSName} h && Equals(h);");
- tw.WriteLine ($"public override int GetHashCode() => Value.GetHashCode();");
- tw.WriteLine ($"private string DebuggerDisplay => string.Format(\"{enumType.CSName} [0x{{0}}]\", Value.ToString(\"X\"));");
+ tw.WriteLine ($"public readonly {hType} Value;");
+ tw.WriteLine ($"public {enumType.CSName}({hType} existingHandle) {{ Value = existingHandle; }}");
+ tw.WriteLine ($"public static {enumType.CSName} Null => new {enumType.CSName}(0);");
+ tw.WriteLine ($"public static implicit operator {enumType.CSName}({hType} flags) => new {enumType.CSName}(flags);");
+ tw.WriteLine ($"public static bool operator ==({enumType.CSName} left, {enumType.CSName} right) => left.Value == right.Value;");
+ tw.WriteLine ($"public static bool operator !=({enumType.CSName} left, {enumType.CSName} right) => left.Value != right.Value;");
+ tw.WriteLine ($"public static bool operator ==({enumType.CSName} left, {hType} right) => left.Value == right;");
+ tw.WriteLine ($"public static bool operator !=({enumType.CSName} left, {hType} right) => left.Value != right;");
+ tw.WriteLine ($"public bool Equals({enumType.CSName} h) => Value == h.Value;");
+ tw.WriteLine ($"public override bool Equals(object obj) => obj is {enumType.CSName} h && Equals(h);");
+ tw.WriteLine ($"public override int GetHashCode() => Value.GetHashCode();");
+ tw.WriteLine ($"private string DebuggerDisplay => string.Format(\"{enumType.CSName} [0x{{0}}]\", Value.ToString(\"X\"));");
- tw.Indent--;
- tw.WriteLine (@"}");
- }
+ tw.Indent--;
+ tw.WriteLine (@"}");
+ }
- static void gen_enum_value (IndentedTextWriter tw, string enumName, EnumerantValue ev) {
- if (!string.IsNullOrEmpty (ev.comment))
- tw.WriteLine ($"/// <summary> {ev.comment} </summary>");
- if (!string.IsNullOrEmpty (ev.unusedComment))
- tw.WriteLine ($"[Obsolete(\"{ev.unusedComment}\"]");
+ static void gen_enum_value (IndentedTextWriter tw, string enumName, EnumerantValue ev) {
+ if (!string.IsNullOrEmpty (ev.comment))
+ tw.WriteLine ($"/// <summary> {ev.comment} </summary>");
+ if (!string.IsNullOrEmpty (ev.unusedComment))
+ tw.WriteLine ($"[Obsolete(\"{ev.unusedComment}\"]");
- uint v;
- string vName = ev.GetCSName (enumName);
+ uint v;
+ string vName = ev.GetCSName (enumName);
- if (uint.TryParse (ev.value, out v))
- tw.WriteLine ($"{vName,-50} = 0x{v.ToString ("X8")},");
- else if (ev.isAlias) {
- string alias = EnumerantValue.GetCSName (ev.value, enumName);
- tw.WriteLine ($"{vName,-50} = {alias,10},");
- } else
- tw.WriteLine ($"{vName,-50} = {ev.value,10},");
- }
- static void gen_enums (string englobingStaticClass) {
- using (StreamWriter sr = new StreamWriter ($"enums_{englobingStaticClass}_gen.cs", false, System.Text.Encoding.UTF8)) {
- using (IndentedTextWriter tw = new IndentedTextWriter (sr)) {
- writePreamble (tw, "System.Diagnostics");
- tw.Indent++;
+ if (uint.TryParse (ev.value, out v))
+ tw.WriteLine ($"{vName,-50} = 0x{v.ToString ("X8")},");
+ else if (ev.isAlias) {
+ string alias = EnumerantValue.GetCSName (ev.value, enumName);
+ tw.WriteLine ($"{vName,-50} = {alias,10},");
+ } else
+ tw.WriteLine ($"{vName,-50} = {ev.value,10},");
+ }
+ static void gen_enums (string englobingStaticClass) {
+ using (StreamWriter sr = new StreamWriter (targetPath($"enums_{englobingStaticClass}"), false, System.Text.Encoding.UTF8)) {
+ using (IndentedTextWriter tw = new IndentedTextWriter (sr)) {
+ writePreamble (tw, "System.Diagnostics");
+ tw.Indent++;
- //add uint alias for all type bitmask without flagbits enum
- foreach (TypeDef tdbm in types.Where (t => t.category == TypeCategories.bitmask && string.IsNullOrEmpty (t.require)))
- AddAlias (tdbm.Name, "uint");
+ //add uint alias for all type bitmask without flagbits enum
+ foreach (TypeDef tdbm in types.Where (t => t.category == TypeCategories.bitmask && string.IsNullOrEmpty (t.require)))
+ AddAlias (tdbm.Name, "uint");
- foreach (EnumDef ed in enums.Where (e => e.definedBy.Count () == 0)) {
- //search type
- TypeDef td = ed.type == EnumTypes.@enum ?
- types.Where (t => t.Name == ed.Name).FirstOrDefault () :
- types.Where (t => t.require == ed.Name).FirstOrDefault ();
+ foreach (EnumDef ed in enums.Where(e=>e.definedBy.Count()==0)) {
+ //search type
+ TypeDef td = ed.type == EnumTypes.@enum ?
+ types.Where(t=>t.Name == ed.Name).FirstOrDefault() :
+ types.Where(t=>t.require == ed.Name).FirstOrDefault();
- if (td == null) {
- AddAlias (ed.Name, "uint");
- continue;
- }
+ if (td == null) {
+ AddAlias (ed.Name, "uint");
+ continue;
+ }
- if (!string.IsNullOrEmpty (ed?.comment))
- tw.WriteLine ($"/// <summary> {ed.comment} </summary>");
- if (ed?.type == EnumTypes.bitmask) {
- tw.WriteLine (@"[Flags]");
- tw.WriteLine ($"public enum {td.CSName} : uint {{");
- } else
- tw.WriteLine ($"public enum {td.CSName} {{");
+ if (!string.IsNullOrEmpty (ed?.comment))
+ tw.WriteLine ($"/// <summary> {ed.comment} </summary>");
+ if (ed?.type == EnumTypes.bitmask) {
+ tw.WriteLine (@"[Flags]");
+ tw.WriteLine ($"public enum {td.CSName} : uint {{");
+ } else
+ tw.WriteLine ($"public enum {td.CSName} {{");
- tw.Indent++;
+ tw.Indent++;
- foreach (EnumerantValue ev in ed.values.OrderBy (aa => aa.isAlias))
- gen_enum_value (tw, td.CSName, ev);
+ foreach (EnumerantValue ev in ed.values.OrderBy(aa => aa.isAlias))
+ gen_enum_value (tw, td.CSName, ev);
- IEnumerable<EnumerantValue> ext = extends.Where (e => e.extends == ed.Name);
- foreach (EnumerantValue ev in ext.OrderBy (aa => aa.isAlias))
- gen_enum_value (tw, td.CSName, ev);
+ IEnumerable<EnumerantValue> ext = extends.Where (e => e.extends == ed.Name);
+ foreach (EnumerantValue ev in ext.OrderBy(aa => aa.isAlias))
+ gen_enum_value (tw, td.CSName, ev);
- tw.Indent--;
- tw.WriteLine (@"}");
- }
+ tw.Indent--;
+ tw.WriteLine (@"}");
+ }
- tw.Indent--;
- tw.WriteLine (@"}");
- }
- }
- }
- static void gen_extensions () {
- using (StreamWriter sr = new StreamWriter ("extensions_gen.cs", false, System.Text.Encoding.UTF8)) {
- using (IndentedTextWriter tw = new IndentedTextWriter (sr)) {
- writePreamble (tw);
- tw.Indent++;
+ tw.Indent--;
+ tw.WriteLine (@"}");
+ }
+ }
+ }
+ static void gen_extensions () {
+ using (StreamWriter sr = new StreamWriter (targetPath ("extensions"), false, System.Text.Encoding.UTF8)) {
+ using (IndentedTextWriter tw = new IndentedTextWriter (sr)) {
+ writePreamble (tw);
+ tw.Indent++;
- tw.WriteLine (@"public static class Ext {");
- tw.Indent++;
+ tw.WriteLine (@"public static class Ext {");
+ tw.Indent++;
- tw.WriteLine (@"public static class I {");
- tw.Indent++;
- foreach (ExtensionDef ed in extensions.Where (e => e.type == ExtensionType.Instance)) {
- tw.WriteLine ($"public static readonly string {ed.Name,-50} = \"{ed.Name}\";");
- }
- tw.Indent--;
- tw.WriteLine (@"}");
+ tw.WriteLine (@"public static class I {");
+ tw.Indent++;
+ foreach (ExtensionDef ed in extensions.Where (e => e.type == ExtensionType.Instance)) {
+ tw.WriteLine ($"public static readonly string {ed.Name,-50} = \"{ed.Name}\";");
+ }
+ tw.Indent--;
+ tw.WriteLine (@"}");
- tw.WriteLine (@"public static class D {");
- tw.Indent++;
- foreach (ExtensionDef ed in extensions.Where (e => e.type == ExtensionType.Device)) {
- tw.WriteLine ($"public static readonly string {ed.Name,-50} = \"{ed.Name}\";");
- }
- tw.Indent--;
- tw.WriteLine (@"}");
+ tw.WriteLine (@"public static class D {");
+ tw.Indent++;
+ foreach (ExtensionDef ed in extensions.Where (e => e.type == ExtensionType.Device)) {
+ tw.WriteLine ($"public static readonly string {ed.Name,-50} = \"{ed.Name}\";");
+ }
+ tw.Indent--;
+ tw.WriteLine (@"}");
- tw.Indent--;
- tw.WriteLine (@"}");
+ tw.Indent--;
+ tw.WriteLine (@"}");
- tw.Indent--;
- tw.WriteLine (@"}");
- }
- }
- }
- static void gen_funcptrs (string englobingStaticClass) {
- using (StreamWriter sr = new StreamWriter ($"funcptrs_{englobingStaticClass}_gen.cs", false, System.Text.Encoding.UTF8)) {
- using (IndentedTextWriter tw = new IndentedTextWriter (sr)) {
- writePreamble (tw);
- tw.Indent++;
+ tw.Indent--;
+ tw.WriteLine (@"}");
+ }
+ }
+ }
+ static void gen_funcptrs (string englobingStaticClass) {
+ using (StreamWriter sr = new StreamWriter ($"funcptrs_{englobingStaticClass}_gen.cs", false, System.Text.Encoding.UTF8)) {
+ using (IndentedTextWriter tw = new IndentedTextWriter (sr)) {
+ writePreamble (tw);
+ tw.Indent++;
- foreach (FuncpointerDef fp in types.OfType<FuncpointerDef> ())
- tw.WriteLine ($"public delegate {fp.returnType.CSName} {fp.Name} ();");
+ foreach (FuncpointerDef fp in types.OfType<FuncpointerDef>())
+ tw.WriteLine ($"public delegate {fp.returnType.CSName} {fp.Name} ();");
- tw.Indent--;
- tw.WriteLine (@"}");
- }
- }
- }
- static void gen_handle (IndentedTextWriter tw, HandleDef hd) {
- tw.WriteLine (@"[DebuggerDisplay(""{DebuggerDisplay,nq}"")]");
- tw.WriteLine ($"public struct {hd.CSName} : IEquatable<{hd.CSName}>");
- tw.WriteLine (@"{");
- tw.Indent++;
- string hType = hd.nonDispatchable ? "ulong" : "IntPtr";
+ tw.Indent--;
+ tw.WriteLine (@"}");
+ }
+ }
+ }
+ static void gen_handle (IndentedTextWriter tw, HandleDef hd) {
+ tw.WriteLine (@"[DebuggerDisplay(""{DebuggerDisplay,nq}"")]");
+ tw.WriteLine ($"public struct {hd.CSName} : IEquatable<{hd.CSName}>");
+ tw.WriteLine (@"{");
+ tw.Indent++;
+ string hType = hd.nonDispatchable ? "ulong" : "IntPtr";
- tw.WriteLine ($"public readonly {hType} Handle;");
- tw.WriteLine ($"public {hd.CSName}({hType} existingHandle) {{ Handle = existingHandle; }}");
- tw.WriteLine ($"public static {hd.CSName} Null => new {hd.CSName}({(hd.nonDispatchable ? "0" : "IntPtr.Zero")});");
- tw.WriteLine ($"public static implicit operator {hd.CSName}({hType} handle) => new {hd.CSName}(handle);");
- tw.WriteLine ($"public static bool operator ==({hd.CSName} left, {hd.CSName} right) => left.Handle == right.Handle;");
- tw.WriteLine ($"public static bool operator !=({hd.CSName} left, {hd.CSName} right) => left.Handle != right.Handle;");
- tw.WriteLine ($"public static bool operator ==({hd.CSName} left, {hType} right) => left.Handle == right;");
- tw.WriteLine ($"public static bool operator !=({hd.CSName} left, {hType} right) => left.Handle != right;");
- tw.WriteLine ($"public bool Equals({hd.CSName} h) => Handle == h.Handle;");
- tw.WriteLine ($"public override bool Equals(object obj) => obj is {hd.CSName} h && Equals(h);");
- tw.WriteLine ($"public override int GetHashCode() => Handle.GetHashCode();");
- tw.WriteLine ($"private string DebuggerDisplay => string.Format(\"{hd.CSName} [0x{{0}}]\", Handle.ToString(\"X\"));");
+ tw.WriteLine ($"public readonly {hType} Handle;");
+ tw.WriteLine ($"public {hd.CSName}({hType} existingHandle) {{ Handle = existingHandle; }}");
+ tw.WriteLine ($"public static {hd.CSName} Null => new {hd.CSName}({(hd.nonDispatchable ? "0" : "IntPtr.Zero")});");
+ tw.WriteLine ($"public static implicit operator {hd.CSName}({hType} handle) => new {hd.CSName}(handle);");
+ tw.WriteLine ($"public static bool operator ==({hd.CSName} left, {hd.CSName} right) => left.Handle == right.Handle;");
+ tw.WriteLine ($"public static bool operator !=({hd.CSName} left, {hd.CSName} right) => left.Handle != right.Handle;");
+ tw.WriteLine ($"public static bool operator ==({hd.CSName} left, {hType} right) => left.Handle == right;");
+ tw.WriteLine ($"public static bool operator !=({hd.CSName} left, {hType} right) => left.Handle != right;");
+ tw.WriteLine ($"public bool Equals({hd.CSName} h) => Handle == h.Handle;");
+ tw.WriteLine ($"public override bool Equals(object obj) => obj is {hd.CSName} h && Equals(h);");
+ tw.WriteLine ($"public override int GetHashCode() => Handle.GetHashCode();");
+ tw.WriteLine ($"private string DebuggerDisplay => string.Format(\"{hd.CSName} [0x{{0}}]\", Handle.ToString(\"X\"));");
- tw.Indent--;
- tw.WriteLine (@"}");
- }
- static void gen_handles (string englobingStaticClass) {
- using (StreamWriter sr = new StreamWriter ($"handles_{englobingStaticClass}_gen.cs", false, System.Text.Encoding.UTF8)) {
- using (IndentedTextWriter tw = new IndentedTextWriter (sr)) {
- writePreamble (tw, "System.Diagnostics");
- tw.Indent++;
+ tw.Indent--;
+ tw.WriteLine (@"}");
+ }
+ static void gen_handles (string englobingStaticClass) {
+ using (StreamWriter sr = new StreamWriter (targetPath($"handles_{englobingStaticClass}"), false, System.Text.Encoding.UTF8)) {
+ using (IndentedTextWriter tw = new IndentedTextWriter (sr)) {
+ writePreamble (tw, "System.Diagnostics");
+ tw.Indent++;
- foreach (HandleDef hd in types.OfType<HandleDef> ())//.Where(t=>t.definedBy.Count == 0))
- gen_handle (tw, hd);
+ foreach (HandleDef hd in types.OfType<HandleDef> ())//.Where(t=>t.definedBy.Count == 0))
+ gen_handle (tw, hd);
- tw.Indent--;
- tw.WriteLine (@"}");
- }
- }
- }
+ tw.Indent--;
+ tw.WriteLine (@"}");
+ }
+ }
+ }
- static void gen_constant_value (IndentedTextWriter tw, EnumerantValue cd) {
- if (string.IsNullOrEmpty (cd.value)) {
- Console.ForegroundColor = ConsoleColor.DarkRed;
- Console.WriteLine ("no value for constant: " + cd);
- return;
- }
- string pTrims = cd.value.Replace ("(", "");
- pTrims = pTrims.Replace (")", "");
+ static void gen_constant_value (IndentedTextWriter tw, EnumerantValue cd) {
+ if (string.IsNullOrEmpty (cd.value)) {
+ Console.ForegroundColor = ConsoleColor.DarkRed;
+ Console.WriteLine ("no value for constant: " + cd);
+ return;
+ }
+ string pTrims = cd.value.Replace ("(", "");
+ pTrims = pTrims.Replace (")", "");
- int i = pTrims.Length;
- while (i > 1 && char.IsLetter (pTrims[i - 1]))
- i--;
+ int i = pTrims.Length;
+ while (i > 1 && char.IsLetter (pTrims[i-1]))
+ i--;
- switch (pTrims.Substring (i).ToLower ()) {
- case "u":
- tw.WriteLine ($"{"public const uint " + cd.GetCSName (),-50} = {cd.value};");
- break;
- case "ull":
- tw.WriteLine ($"{"public const ulong " + cd.GetCSName (),-50} = ({pTrims.Remove (pTrims.Length - 1)});");
- break;
- case "f":
- tw.WriteLine ($"{"public const float " + cd.GetCSName (),-50} = {cd.value};");
- break;
- default:
- tw.WriteLine ($"{"public const uint " + cd.GetCSName (),-50} = {cd.value};");
- break;
- }
- }
- static void gen_constants (string englobingStaticClass) {
- using (StreamWriter sr = new StreamWriter ($"constants_{englobingStaticClass}_gen.cs", false, System.Text.Encoding.UTF8)) {
- using (IndentedTextWriter tw = new IndentedTextWriter (sr)) {
- writePreamble (tw);
- tw.Indent++;
+ switch (pTrims.Substring(i).ToLower()) {
+ case "u":
+ tw.WriteLine ($"{"public const uint " + cd.GetCSName (),-50} = {cd.value};");
+ break;
+ case "ull":
+ tw.WriteLine ($"{"public const ulong " + cd.GetCSName (),-50} = ({pTrims.Remove(pTrims.Length-1)});");
+ break;
+ case "f":
+ tw.WriteLine ($"{"public const float " + cd.GetCSName (),-50} = {cd.value};");
+ break;
+ default:
+ tw.WriteLine ($"{"public const uint " + cd.GetCSName (),-50} = {cd.value};");
+ break;
+ }
+ }
+ static void gen_constants (string englobingStaticClass) {
+ using (StreamWriter sr = new StreamWriter (targetPath($"constants_{englobingStaticClass}"), false, System.Text.Encoding.UTF8)) {
+ using (IndentedTextWriter tw = new IndentedTextWriter (sr)) {
+ writePreamble (tw);
+ tw.Indent++;
- tw.WriteLine ($"public static partial class {englobingStaticClass} {{");
- tw.Indent++;
+ tw.WriteLine ($"public static partial class {englobingStaticClass} {{");
+ tw.Indent++;
- foreach (EnumerantValue cd in Constants)
- gen_constant_value (tw, cd);
+ foreach (EnumerantValue cd in Constants)
+ gen_constant_value (tw, cd);
- tw.Indent--;
- tw.WriteLine (@"}");
+ tw.Indent--;
+ tw.WriteLine (@"}");
- tw.Indent--;
- tw.WriteLine (@"}");
- }
- }
- }
+ tw.Indent--;
+ tw.WriteLine (@"}");
+ }
+ }
+ }
- static string getDefaultParamSig (MemberDef md, bool isLast) {
- switch (md.typedef.IndirectionLevel) {
- case 0:
- return (string.Format ($"{md.typedef.CSName} {md.Name}{(isLast ? ", " : ")")}"));
- case 1:
- return (string.Format ($"IntPtr {md.Name}{(isLast ? ", " : ")")}"));
- case 2:
- return (string.Format ($"ref IntPtr {md.Name}{(isLast ? ", " : ")")}"));
- }
- return null;
- }
- static string getByRefParamSig (MemberDef md, bool isLast) {
- string typeName = md.typedef.CSName == "void" ? "IntPtr" : md.typedef.CSName;
- switch (md.typedef.IndirectionLevel) {
- case 1:
- return md.typedef.IsConst ?
- (string.Format ($"ref {typeName} {md.Name}{(isLast ? ", " : ")")}")) :
- (string.Format ($"out {typeName} {md.Name}{(isLast ? ", " : ")")}"));
- case 2:
- return md.typedef.IsConst ?
- string.Format ($"ref IntPtr {md.Name}{(isLast ? ", " : ")")}") :
- string.Format ($"out IntPtr {md.Name}{(isLast ? ", " : ")")}");
- }
- return null;
- }
+ static string getDefaultParamSig (MemberDef md, bool isLast) {
+ switch (md.typedef.IndirectionLevel) {
+ case 0:
+ return (string.Format ($"{md.typedef.CSName} {md.Name}{(isLast ? ", " : ")")}"));
+ case 1:
+ return (string.Format ($"IntPtr {md.Name}{(isLast ? ", " : ")")}"));
+ case 2:
+ return (string.Format ($"ref IntPtr {md.Name}{(isLast ? ", " : ")")}"));
+ }
+ return null;
+ }
+ static string getByRefParamSig (MemberDef md, bool isLast) {
+ string typeName = md.typedef.CSName == "void" ? "IntPtr" : md.typedef.CSName;
+ switch (md.typedef.IndirectionLevel) {
+ case 1:
+ return md.typedef.IsConst ?
+ (string.Format ($"ref {typeName} {md.Name}{(isLast ? ", " : ")")}")) :
+ (string.Format ($"out {typeName} {md.Name}{(isLast ? ", " : ")")}"));
+ case 2:
+ return md.typedef.IsConst ?
+ string.Format ($"ref IntPtr {md.Name}{(isLast ? ", " : ")")}") :
+ string.Format ($"out IntPtr {md.Name}{(isLast ? ", " : ")")}");
+ }
+ return null;
+ }
- static void writeCmd (IndentedTextWriter tw, string sig) {
- tw.WriteLine (@"[CalliRewrite]");
- tw.Write ($"public static {sig}");
- tw.WriteLine (@" => throw new NotImplementedException();");
- }
- static void gen_command (IndentedTextWriter tw, CommandDef cd) {
- if (!string.IsNullOrEmpty (cd.alias)) {
- Console.ForegroundColor = ConsoleColor.DarkGray;
- Console.WriteLine ("TODO:command generator: is alias: " + cd);
- return;
- }
- tw.WriteLine ($"internal static IntPtr {cd.CSName}_ptr;");
+ static void writeCmd (IndentedTextWriter tw, string sig) {
+ tw.WriteLine (@"[CalliRewrite]");
+ tw.Write ($"public static {sig}");
+ tw.WriteLine (@" => throw new NotImplementedException();");
+ }
+ static void gen_command (IndentedTextWriter tw, CommandDef cd) {
+ if (!string.IsNullOrEmpty (cd.alias)) {
+ Console.ForegroundColor = ConsoleColor.DarkGray;
+ Console.WriteLine ("TODO:command generator: is alias: " + cd);
+ return;
+ }
+ tw.WriteLine ($"internal static IntPtr {cd.CSName}_ptr;");
- List<string> signatures = new List<string> () { "" };
+ List<string> signatures = new List<string> () { "" };
- //if (cd.Name == "vkRegisterObjectsNVX")
- //Debugger.Break ();
+ //if (cd.Name == "vkRegisterObjectsNVX")
+ //Debugger.Break ();
- for (int i = 0; i < cd.parameters.Count; i++) {
- MemberDef md = cd.parameters[i];
- List<string> typeSigs = new List<string> () { getDefaultParamSig (md, i < cd.parameters.Count - 1) };
- if (md.typedef.IndirectionLevel == 1 && md.typedef.Name != "void")
- typeSigs.Add (getByRefParamSig (md, i < cd.parameters.Count - 1));
+ for (int i = 0; i < cd.parameters.Count; i++) {
+ MemberDef md = cd.parameters[i];
+ List<string> typeSigs = new List<string> () { getDefaultParamSig (md, i < cd.parameters.Count - 1) };
+ if (md.typedef.IndirectionLevel == 1 && md.typedef.Name != "void")
+ typeSigs.Add (getByRefParamSig (md, i < cd.parameters.Count - 1));
- string[] prevSigs = new string[signatures.Count];
- Array.Copy (signatures.ToArray (), prevSigs, prevSigs.Length);
- signatures.Clear ();
- for (int s = 0; s < prevSigs.Length; s++) {
- signatures.Add (prevSigs[s] + typeSigs[0]);
- for (int st = 1; st < typeSigs.Count; st++) {
- signatures.Add (prevSigs[s] + typeSigs[st]);
- }
- }
- }
+ string[] prevSigs = new string[signatures.Count];
+ Array.Copy (signatures.ToArray (), prevSigs, prevSigs.Length);
+ signatures.Clear ();
+ for (int s = 0; s < prevSigs.Length; s++) {
+ signatures.Add (prevSigs[s] + typeSigs[0]);
+ for (int st = 1; st < typeSigs.Count; st++) {
+ signatures.Add (prevSigs[s] + typeSigs[st]);
+ }
+ }
+ }
- foreach (string sig in signatures)
- writeCmd (tw, string.Format ($"{cd.returnType.CSName} {cd.Name} ({sig}"));
+ foreach (string sig in signatures)
+ writeCmd (tw, string.Format ($"{cd.returnType.CSName} {cd.Name} ({sig}"));
- tw.WriteLine ();
- }
- static void gen_commands (string englobingStaticClass) {
- using (StreamWriter sr = new StreamWriter ($"commands_{englobingStaticClass}_gen.cs", false, System.Text.Encoding.UTF8)) {
- using (IndentedTextWriter tw = new IndentedTextWriter (sr)) {
- writePreamble (tw, vknamespace + ".Generator");
- tw.Indent++;
+ tw.WriteLine ();
+ }
+ static void gen_commands (string englobingStaticClass) {
+ using (StreamWriter sr = new StreamWriter (targetPath ($"commands_{englobingStaticClass}"), false, System.Text.Encoding.UTF8)) {
+ using (IndentedTextWriter tw = new IndentedTextWriter (sr)) {
+ writePreamble (tw, vknamespace + ".Generator");
+ tw.Indent++;
- tw.WriteLine ($"public static partial class {englobingStaticClass} {{");
- tw.Indent++;
+ tw.WriteLine ($"public static partial class {englobingStaticClass} {{");
+ tw.Indent++;
- //func pointers and signature
- foreach (CommandDef cd in commands)
- gen_command (tw, cd);
+ //func pointers and signature
+ foreach (CommandDef cd in commands)
+ gen_command (tw, cd);
- #region Function pointers loading (os, inst and dev)
- //norml dyn loading function
+ #region Function pointers loading (os, inst and dev)
+ //norml dyn loading function
- tw.WriteLine (@"internal static void LoadFunctionPointers() {");
- tw.Indent++;
- foreach (string preloadCmd in preloadedCommands) {
- tw.WriteLine ($"{preloadCmd}_ptr = Vk.s_nativeLib.LoadFunctionPointer(\"{preloadCmd}\");");
- }
- //tw.WriteLine (@"Console.WriteLine (""preload function pointer ok."");");
+ tw.WriteLine (@"internal static void LoadFunctionPointers() {");
+ tw.Indent++;
+ foreach (string preloadCmd in preloadedCommands) {
+ tw.WriteLine ($"{preloadCmd}_ptr = Vk.s_nativeLib.LoadFunctionPointer(\"{preloadCmd}\");");
+ }
+ //tw.WriteLine (@"Console.WriteLine (""preload function pointer ok."");");
- tw.Indent--;
- tw.WriteLine (@"}");
+ tw.Indent--;
+ tw.WriteLine (@"}");
- //load instance func pointers
- tw.WriteLine ($"public static void LoadInstanceFunctionPointers (VkInstance inst) {{");
- tw.Indent++;
- foreach (CommandDef cd in commands) {//.Where (cmd=>cmd.definedBy.Count == 0)) {
- if (!string.IsNullOrEmpty (cd.alias))
- continue;
- if (preloadedCommands.Contains (cd.Name))
- continue;
- tw.WriteLine ($"{cd.Name + "_ptr",-54} = LoadingUtils.GetDelegate (inst, \"{cd.Name}\");");
- }
+ //load instance func pointers
+ tw.WriteLine ($"public static void LoadInstanceFunctionPointers (VkInstance inst) {{");
+ tw.Indent++;
+ foreach (CommandDef cd in commands){//.Where (cmd=>cmd.definedBy.Count == 0)) {
+ if (!string.IsNullOrEmpty (cd.alias))
+ continue;
+ if (preloadedCommands.Contains (cd.Name))
+ continue;
+ tw.WriteLine ($"{cd.Name + "_ptr",-54} = LoadingUtils.GetDelegate (inst, \"{cd.Name}\");");
+ }
- tw.Indent--;
- tw.WriteLine (@"}");
- tw.WriteLine ();
- //load device func pointers
- tw.WriteLine ($"public static void LoadDeviceFunctionPointers (VkDevice dev) {{");
- tw.Indent++;
- foreach (CommandDef cd in commands) {//.Where (cmd=>cmd.definedBy.Count == 0)) {
- if (!string.IsNullOrEmpty (cd.alias))
- continue;
- if (preloadedCommands.Contains (cd.Name))
- continue;
- tw.WriteLine ($"LoadingUtils.GetDelegate (dev, \"{cd.Name + "\",",-54} ref {cd.Name + "_ptr"});");
- }
+ tw.Indent--;
+ tw.WriteLine (@"}");
+ tw.WriteLine ();
+ //load device func pointers
+ tw.WriteLine ($"public static void LoadDeviceFunctionPointers (VkDevice dev) {{");
+ tw.Indent++;
+ foreach (CommandDef cd in commands){//.Where (cmd=>cmd.definedBy.Count == 0)) {
+ if (!string.IsNullOrEmpty (cd.alias))
+ continue;
+ if (preloadedCommands.Contains (cd.Name))
+ continue;
+ tw.WriteLine ($"LoadingUtils.GetDelegate (dev, \"{cd.Name + "\",",-54} ref {cd.Name + "_ptr"});");
+ }
- tw.Indent--;
- tw.WriteLine (@"}");
- #endregion
+ tw.Indent--;
+ tw.WriteLine (@"}");
+ #endregion
- tw.Indent--;
- tw.WriteLine (@"}");
+ tw.Indent--;
+ tw.WriteLine (@"}");
- tw.Indent--;
- tw.WriteLine (@"}");
- }
- }
- }
- #endregion
+ tw.Indent--;
+ tw.WriteLine (@"}");
+ }
+ }
+ }
+ #endregion
- #region vk.xml parsing
- static void readType (XmlNode nType) {
+ #region vk.xml parsing
+ static void readType (XmlNode nType) {
- if (nType.Attributes["alias"] != null) {
- aliases.Add (nType.Attributes["name"].Value, nType.Attributes["alias"].Value);
- return;
- }
+ if (nType.Attributes ["alias"] != null) {
+ aliases.Add (nType.Attributes["name"].Value, nType.Attributes["alias"].Value);
+ return;
+ }
- TypeCategories category = TypeCategories.none;
- if (nType.Attributes["category"] != null)
- category = (TypeCategories)Enum.Parse (typeof (TypeCategories), nType.Attributes["category"].Value, true);
- switch (category) {
- case TypeCategories.none:
- return;
- case TypeCategories.basetype:
- types.Add (new TypeDef
- {
- category = category,
- Name = nType["name"].InnerText,
- baseType = nType["type"]?.InnerText
- });
- break;
- case TypeCategories.bitmask:
- TypeDef ed = new TypeDef
- {
- category = category,
- Name = nType["name"].InnerText
- };
- if (nType.Attributes["requires"] == null)
- ed.baseType = nType["type"].InnerXml;
- else
- ed.require = nType.Attributes["requires"].Value;
- types.Add (ed);
- break;
- case TypeCategories.handle:
- types.Add (new HandleDef
- {
- category = category,
- Name = nType["name"].InnerText,
- baseType = nType["type"]?.InnerText,
- parent = nType.Attributes["parent"]?.Value
- });
- break;
- case TypeCategories.funcpointer:
- FuncpointerDef fp = new FuncpointerDef
- {
- category = category,
- Name = nType["name"].InnerText
- };
- string returnTypeStr = nType.InnerText.Substring (8);//trim leading typedef
- returnTypeStr = returnTypeStr.Remove (returnTypeStr.IndexOf ('(')).Trim ();
- switch (returnTypeStr) {
- case "void":
- fp.returnType = new ParamDef () { Name = "void" };
- break;
- case "void*":
- fp.returnType = new ParamDef () { Name = "IntPtr" };
- break;
- default:
- fp.returnType = new ParamDef () { Name = returnTypeStr };
- break;
- }
- types.Add (fp);
- break;
- case TypeCategories.@enum:
- types.Add (new TypeDef
- {
- category = category,
- Name = nType.Attributes["name"].Value,
- });
- break;
- case TypeCategories.define:
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine (nType.InnerXml);
- break;
- case TypeCategories.include:
- case TypeCategories.group:
- Console.ForegroundColor = ConsoleColor.DarkMagenta;
- Console.WriteLine ($"Unprocessed type category {category}: {nType.OuterXml}");
- Console.ForegroundColor = ConsoleColor.Gray;
- break;
- case TypeCategories.union:
- case TypeCategories.@struct:
- StructDef sd = new StructDef
- {
- Name = nType.Attributes["name"].Value,
- category = category,
- };
- string nextComment = "";
- foreach (XmlNode m in nType.ChildNodes) {
- if ((m.NodeType == XmlNodeType.Comment)) {
- nextComment = m.InnerText;
- continue;
- }
- if ((m.NodeType != XmlNodeType.Element)) {
- Console.WriteLine ($"expecting element, having {m.NodeType}: {m.OuterXml}");
- continue;
- }
- switch (m.Name) {
- case "comment":
- break;
- case "member":
- MemberDef md = parseMember (m);
- md.comment = nextComment;
- nextComment = "";
- sd.members.Add (md);
- break;
- default:
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine ($"unknown element in struct def : {m.OuterXml}");
- Console.ForegroundColor = ConsoleColor.Gray;
- break;
- }
- }
- types.Add (sd);
- break;
- default:
- Console.ForegroundColor = ConsoleColor.DarkMagenta;
- Console.WriteLine ($"Unprocessed type: {nType.OuterXml}");
- Console.ForegroundColor = ConsoleColor.Gray;
- break;
- }
- }
- public static void readEnum (XmlNode nEnum) {
- if (nEnum.Attributes["name"]?.Value == "API Constants") {
- //constants
- foreach (XmlNode c in nEnum.ChildNodes) {
- if (c.Name != "enum")
- throw new Exception ("unexpected element in enums");
- if (c.Attributes["alias"] != null) {
- aliases.Add (c.Attributes["name"].Value, c.Attributes["alias"].Value);
- continue;
- }
+ TypeCategories category = TypeCategories.none;
+ if (nType.Attributes["category"] != null)
+ category = (TypeCategories)Enum.Parse (typeof (TypeCategories), nType.Attributes["category"].Value, true);
+ switch (category) {
+ case TypeCategories.none:
+ return;
+ case TypeCategories.basetype:
+ types.Add (new TypeDef {
+ category = category,
+ Name = nType["name"].InnerText,
+ baseType = nType["type"]?.InnerText
+ });
+ break;
+ case TypeCategories.bitmask:
+ TypeDef ed = new TypeDef {
+ category = category,
+ Name = nType["name"].InnerText
+ };
+ if (nType.Attributes ["requires"] == null)
+ ed.baseType = nType["type"].InnerXml;
+ else
+ ed.require = nType.Attributes["requires"].Value;
+ types.Add (ed);
+ break;
+ case TypeCategories.handle:
+ types.Add (new HandleDef {
+ category = category,
+ Name = nType["name"].InnerText,
+ baseType = nType["type"]?.InnerText,
+ parent = nType.Attributes["parent"]?.Value
+ });
+ break;
+ case TypeCategories.funcpointer:
+ FuncpointerDef fp = new FuncpointerDef {
+ category = category,
+ Name = nType["name"].InnerText
+ };
+ string returnTypeStr = nType.InnerText.Substring(8);//trim leading typedef
+ returnTypeStr = returnTypeStr.Remove (returnTypeStr.IndexOf ('(')).Trim();
+ switch (returnTypeStr) {
+ case "void":
+ fp.returnType = new ParamDef () { Name = "void" };
+ break;
+ case "void*":
+ fp.returnType = new ParamDef () { Name = "IntPtr" };
+ break;
+ default:
+ fp.returnType = new ParamDef () { Name = returnTypeStr };
+ break;
+ }
+ types.Add (fp);
+ break;
+ case TypeCategories.@enum:
+ types.Add (new TypeDef {
+ category = category,
+ Name = nType.Attributes["name"].Value,
+ });
+ break;
+ case TypeCategories.define:
+ Console.ForegroundColor = ConsoleColor.Cyan;
+ Console.WriteLine (nType.InnerXml);
+ break;
+ case TypeCategories.include:
+ case TypeCategories.group:
+ Console.ForegroundColor = ConsoleColor.DarkMagenta;
+ Console.WriteLine($"Unprocessed type category {category}: {nType.OuterXml}");
+ Console.ForegroundColor = ConsoleColor.Gray;
+ break;
+ case TypeCategories.union:
+ case TypeCategories.@struct:
+ StructDef sd = new StructDef {
+ Name = nType.Attributes["name"].Value,
+ category = category,
+ };
- Constants.Add (new EnumerantValue
- {
- Name = c.Attributes["name"].Value,
- value = c.Attributes["value"].Value,
- comment = c.Attributes["comment"]?.Value
- });
- }
- return;
- }
- EnumDef ed = new EnumDef
- {
- type = (EnumTypes)Enum.Parse (typeof (EnumTypes), nEnum.Attributes["type"].Value, true),
- Name = nEnum.Attributes["name"].Value
- };
+ foreach (XmlNode m in nType.ChildNodes) {
+ if ((m.NodeType != XmlNodeType.Element)) {
+ Console.WriteLine ($"expecting element, having {m.NodeType}: {m.OuterXml}");
+ continue;
+ }
+ switch (m.Name) {
+ case "comment":
+ break;
+ case "member":
+ sd.members.Add (parseMember (m));
+ break;
+ default:
+ Console.ForegroundColor = ConsoleColor.Red;
+ Console.WriteLine ($"unknown element in struct def : {m.OuterXml}");
+ Console.ForegroundColor = ConsoleColor.Gray;
+ break;
+ }
+ }
+ types.Add (sd);
+ break;
+ default:
+ Console.ForegroundColor = ConsoleColor.DarkMagenta;
+ Console.WriteLine ($"Unprocessed type: {nType.OuterXml}");
+ Console.ForegroundColor = ConsoleColor.Gray;
+ break;
+ }
+ }
+ public static void readEnum (XmlNode nEnum) {
+ if (nEnum.Attributes ["name"]?.Value == "API Constants") {
+ //constants
+ foreach (XmlNode c in nEnum.ChildNodes) {
+ if (c.Name != "enum")
+ throw new Exception ("unexpected element in enums");
+ if (c.Attributes ["alias"] != null) {
+ aliases.Add (c.Attributes["name"].Value, c.Attributes["alias"].Value);
+ continue;
+ }
- EnumerantValue ev = new EnumerantValue ();
- foreach (XmlNode p in nEnum.ChildNodes) {
- if (p.Name == "comment" || p.NodeType == XmlNodeType.Comment) {
- ev.comment = p.InnerXml;
- continue;
- }
+ Constants.Add (new EnumerantValue {
+ Name = c.Attributes["name"].Value,
+ value = c.Attributes["value"].Value,
+ comment = c.Attributes["comment"]?.Value
+ });
+ }
+ return;
+ }
+ EnumDef ed = new EnumDef {
+ type = (EnumTypes)Enum.Parse (typeof (EnumTypes), nEnum.Attributes["type"].Value, true),
+ Name = nEnum.Attributes["name"].Value
+ };
- if (p.Name == "unused") {
- ev.unusedComment = p.InnerXml;
- continue;
- }
+ foreach (XmlNode p in nEnum.ChildNodes) {
+ EnumerantValue ev = new EnumerantValue ();
+ if (p.Name == "comment" || p.NodeType == XmlNodeType.Comment) {
+ ev.comment = p.InnerXml;
+ continue;
+ }
- ev.Name = p.Attributes["name"].Value;
- ev.comment = p.Attributes["comment"]?.Value;
+ if (p.Name == "unused") {
+ ev.unusedComment = p.InnerXml;
+ continue;
+ }
+ //cs names generate same output
+ //TODO: removed suffix could be saved to be appened if alias csname is not unique
+ if (p.Attributes["name"].Value == "VK_SURFACE_COUNTER_VBLANK_EXT" ||
+ p.Attributes["name"].Value == "VK_PERFORMANCE_COUNTER_DESCRIPTION_PERFORMANCE_IMPACTING_KHR" ||
+ p.Attributes["name"].Value == "VK_PERFORMANCE_COUNTER_DESCRIPTION_CONCURRENTLY_IMPACTED_KHR") {
+ Console.WriteLine ($"Discarded Enum Value:{ed.Name}->{p.Attributes["name"].Value}");
+ continue;
+ }
- if (p.Attributes["alias"] != null) {
- ev.isAlias = true;
- ev.value = p.Attributes["alias"].Value;
- } else if (ed.type == EnumTypes.bitmask) {
- if (p.Attributes["bitpos"] != null)
- ev.value = (1u << int.Parse (p.Attributes["bitpos"].Value)).ToString ();
- else
- ev.value = p.Attributes["value"]?.Value;
- } else
- ev.value = p.Attributes["value"].Value;
+ ev.Name = p.Attributes["name"].Value;
+ ev.comment = p.Attributes["comment"]?.Value;
- ed.values.Add (ev);
- ev = new EnumerantValue ();
- }
+ if (p.Attributes["alias"] != null) {
+ ev.isAlias = true;
+ ev.value = p.Attributes["alias"].Value;
+ }else if(ed.type == EnumTypes.bitmask) {
+ if (p.Attributes["bitpos"] != null)
+ ev.value = (1u << int.Parse (p.Attributes["bitpos"].Value)).ToString ();
+ else
+ ev.value = p.Attributes["value"]?.Value;
+ } else
+ ev.value = p.Attributes["value"].Value;
- enums.Add (ed);
- }
+ ed.values.Add (ev);
+ }
- static void parseRequirements (InterfaceDef iface, XmlNode requirements) {
- if (requirements.Attributes["comment"]?.Value == "API constants") {
- //CONSTANTS
- foreach (XmlNode req in requirements.ChildNodes) {
- switch (req.Name) {
- case "enum":
- EnumerantValue ev = Constants.Where (v => v.Name == req.Attributes["name"].Value).First ();
- ev.definedBy.Add (iface.Name);
- break;
- default:
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine ($"unhandle requirement tag in constants defs: {req.Attributes["name"].Value}");
- break;
- }
- }
- return;
- }
+ enums.Add (ed);
+ }
- foreach (XmlNode req in requirements.ChildNodes) {
- switch (req.Name) {
- case "type":
- switch (requirements.Attributes["comment"]?.Value) {
- case "Header boilerplate":
- break;
- case "API version":
- break;
- default:
- TypeDef tdef = types.Where (td => td.Name == req.Attributes["name"].Value).FirstOrDefault ();
- if (tdef == null) {
- if (aliases.ContainsKey (req.Attributes["name"].Value))
- tdef = types.Where (td => td.Name == aliases[req.Attributes["name"].Value]).FirstOrDefault ();
- if (tdef == null) {
- Console.ForegroundColor = ConsoleColor.DarkRed;
- Console.WriteLine ($"iface type not found: {req.Attributes["name"].Value}");
- break;
- }
- }
- tdef.definedBy.Add (iface.Name);
- break;
- }
- break;
- case "command":
- if (preloadedCommands.Contains (req.Attributes["name"].Value))//dont move those func
- continue;
- try {
- CommandDef cd = commands.Where (e => e.Name == req.Attributes["name"].Value).First ();
- cd.definedBy.Add (iface.Name);
- } catch {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine ($"extension command not found: {req.Attributes["name"].Value}");
- }
- break;
- case "enum":
- string eName = req.Attributes["name"].Value;
- if (skipEnums.Contains (eName))
- continue;
- if (aliases.ContainsKey (eName))
- eName = aliases[eName];
- EnumerantValue ev = extends.Where (e => e.Name == eName).FirstOrDefault ();
- if (ev != null) {
- ev.definedBy.Add (iface.Name);
- continue;
- }
- if (req.Attributes["value"] != null) {
- extends.Add (new EnumerantValue
- {
- Name = eName,
- definedBy = new List<string> { iface.Name },
- extends = req.Attributes["extends"]?.Value,
- value = req.Attributes["value"].Value
- });
- } else if (req.Attributes["bitpos"] != null) {
- extends.Add (new EnumerantValue
- {
- Name = eName,
- definedBy = new List<string> { iface.Name },
- extends = req.Attributes["extends"]?.Value,
- value = (1u << int.Parse (req.Attributes["bitpos"].Value)).ToString ()
- });
- } else if (req.Attributes["alias"] != null) {
- extends.Add (new EnumerantValue
- {
- Name = eName,
- definedBy = new List<string> { iface.Name },
- isAlias = true,
- extends = req.Attributes["extends"]?.Value,
- value = req.Attributes["alias"].Value
- });
- } else if (req.Attributes["offset"] != null) {
- int offset = 0, extnumber = 0;
- int.TryParse (req.Attributes["offset"].Value, out offset);
- if (req.Attributes["extnumber"] != null)
- int.TryParse (req.Attributes["extnumber"].Value, out extnumber);
- int eval = extBase;
- if (extnumber > 0)
- eval += offset + (extnumber - 1) * extBlockSize;
- else
- eval += offset + (iface.number - 1) * extBlockSize;
+ static void parseRequirements (InterfaceDef iface, XmlNode requirements) {
+ if (requirements.Attributes["comment"]?.Value == "API constants") {
+ //CONSTANTS
+ foreach (XmlNode req in requirements.ChildNodes) {
+ switch (req.Name) {
+ case "enum":
+ EnumerantValue ev = Constants.Where (v => v.Name == req.Attributes["name"].Value).First ();
+ ev.definedBy.Add (iface.Name);
+ break;
+ default:
+ Console.ForegroundColor = ConsoleColor.Red;
+ Console.WriteLine ($"unhandle requirement tag in constants defs: {req.Attributes["name"].Value}");
+ break;
+ }
+ }
+ return;
+ }
- if (req.Attributes["dir"] != null)
- eval = -eval;
+ foreach (XmlNode req in requirements.ChildNodes) {
+ switch (req.Name) {
+ case "type":
+ switch (requirements.Attributes["comment"]?.Value) {
+ case "Header boilerplate":
+ break;
+ case "API version":
+ break;
+ default:
+ TypeDef tdef = types.Where (td => td.Name == req.Attributes["name"].Value).FirstOrDefault ();
+ if (tdef != null) {
+ tdef.definedBy.Add (iface.Name);
+ }else{
+ Console.ForegroundColor = ConsoleColor.DarkRed;
+ Console.WriteLine ($"iface type not found: {req.Attributes["name"].Value}");
+ }
+ break;
+ }
+ break;
+ case "command":
+ if (preloadedCommands.Contains (req.Attributes["name"].Value))//dont move those func
+ continue;
+ try {
+ CommandDef cd = commands.Where (e => e.Name == req.Attributes["name"].Value).First ();
+ cd.definedBy.Add (iface.Name);
+ } catch {
+ Console.ForegroundColor = ConsoleColor.Red;
+ Console.WriteLine ($"extension command not found: {req.Attributes["name"].Value}");
+ }
+ break;
+ case "enum":
+ string eName = req.Attributes["name"].Value;
+ if (skipEnums.Contains (eName))
+ continue;
+ EnumerantValue ev = extends.Where (e => e.Name == eName).FirstOrDefault ();
+ if (ev != null) {
+ ev.definedBy.Add (iface.Name);
+ continue;
+ }
+ if (req.Attributes["value"] != null) {
+ extends.Add (new EnumerantValue {
+ Name = eName,
+ definedBy = new List<string> { iface.Name },
+ extends = req.Attributes["extends"]?.Value,
+ value = req.Attributes["value"].Value
+ });
+ } else if (req.Attributes["bitpos"] != null) {
+ extends.Add (new EnumerantValue {
+ Name = eName,
+ definedBy = new List<string> { iface.Name },
+ extends = req.Attributes["extends"]?.Value,
+ value = (1u << int.Parse (req.Attributes["bitpos"].Value)).ToString ()
+ });
+ } else if (req.Attributes["alias"] != null) {
+ extends.Add (new EnumerantValue {
+ Name = eName,
+ definedBy = new List<string> { iface.Name },
+ isAlias = true,
+ extends = req.Attributes["extends"]?.Value,
+ value = req.Attributes["alias"].Value
+ });
+ } else if (req.Attributes["offset"] != null) {
+ int offset = 0, extnumber = 0;
+ int.TryParse (req.Attributes["offset"].Value, out offset);
+ if (req.Attributes["extnumber"] != null)
+ int.TryParse (req.Attributes["extnumber"].Value, out extnumber);
+ int eval = extBase;
+ if (extnumber > 0)
+ eval += offset + (extnumber - 1) * extBlockSize;
+ else
+ eval += offset + (iface.number - 1) * extBlockSize;
- extends.Add (new EnumerantValue
- {
- Name = eName,
- definedBy = new List<string> { iface.Name },
- extends = req.Attributes["extends"]?.Value,
- value = eval.ToString ()
- });
- } else //constant
- Constants.Add (new EnumerantValue
- {
- Name = eName,
- definedBy = new List<string> { iface.Name },
- extends = req.Attributes["extends"]?.Value,
- });
- break;
- default:
- Console.ForegroundColor = ConsoleColor.DarkRed;
- Console.WriteLine ($"unknown req: {req.OuterXml}");
- break;
- }
- }
- }
+ if (req.Attributes["dir"] != null)
+ eval = -eval;
- public static void readExtension (XmlNode nExt) {
- ExtensionDef ext = new ExtensionDef ();
- ext.Name = nExt.Attributes["name"].Value;
- if (nExt.Attributes["number"] != null)
- ext.number = int.Parse (nExt.Attributes["number"].Value);
- if (nExt.Attributes["requires"] != null)
- ext.requires = nExt.Attributes["requires"].Value.Split (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- if (nExt.Attributes["supported"] != null)
- ext.supported = nExt.Attributes["supported"].Value;
- if (nExt.Attributes["type"] != null)
- ext.type = (ExtensionType)Enum.Parse (typeof (ExtensionType), nExt.Attributes["type"].Value, true);
+ extends.Add (new EnumerantValue {
+ Name = eName,
+ definedBy = new List<string> { iface.Name },
+ extends = req.Attributes["extends"]?.Value,
+ value = eval.ToString ()
+ });
+ } else //constant
+ Constants.Add (new EnumerantValue {
+ Name = eName,
+ definedBy = new List<string> { iface.Name },
+ extends = req.Attributes["extends"]?.Value,
+ });
+ break;
+ default:
+ Console.ForegroundColor = ConsoleColor.DarkRed;
+ Console.WriteLine ($"unknown req: {req.OuterXml}");
+ break;
+ }
+ }
+ }
- foreach (XmlNode n in nExt.ChildNodes) {
- if (n.Name == "require") {
- parseRequirements (ext, n);
- } else if (n.Name == "remove") {
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine ($"extension remove: {n.OuterXml}");
- } else
- Debugger.Break ();
- }
+ public static void readExtension (XmlNode nExt) {
+ ExtensionDef ext = new ExtensionDef ();
+ ext.Name = nExt.Attributes["name"].Value;
+ if (nExt.Attributes["number"] != null)
+ ext.number = int.Parse (nExt.Attributes["number"].Value);
+ if (nExt.Attributes["requires"] != null)
+ ext.requires = nExt.Attributes["requires"].Value.Split (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
+ if (nExt.Attributes["supported"] != null)
+ ext.supported = nExt.Attributes["supported"].Value;
+ if (nExt.Attributes["type"] != null)
+ ext.type = (ExtensionType)Enum.Parse (typeof (ExtensionType), nExt.Attributes["type"].Value, true);
- extensions.Add (ext);
- }
+ foreach (XmlNode n in nExt.ChildNodes) {
+ if (n.Name == "require") {
+ parseRequirements (ext, n);
+ } else if (n.Name == "remove") {
+ Console.ForegroundColor = ConsoleColor.Blue;
+ Console.WriteLine ($"extension remove: {n.OuterXml}");
+ } else
+ Debugger.Break ();
+ }
- public static void readFeature (XmlNode nFeat) {
- FeatureDef fd = new FeatureDef ();
- fd.number = 1;
- fd.Name = nFeat.Attributes["name"].Value;
- fd.api = nFeat.Attributes["api"].Value;
- string[] version = nFeat.Attributes["number"].Value.Split ('.');
- fd.major = int.Parse (version[0]);
- fd.minor = int.Parse (version[1]);
- fd.comment = nFeat.Attributes["comment"]?.Value;
+ extensions.Add (ext);
+ }
- foreach (XmlNode f in nFeat.ChildNodes) {
- if (f.Name == "require") {
- parseRequirements (fd, f);
- } else if (f.Name == "remove") {
- Console.ForegroundColor = ConsoleColor.DarkBlue;
- Console.WriteLine ($"feature remove: {f.OuterXml}");
- }// else
- //Debugger.Break ();
- }
+ public static void readFeature (XmlNode nFeat) {
+ FeatureDef fd = new FeatureDef ();
+ fd.number = 1;
+ fd.Name = nFeat.Attributes["name"].Value;
+ fd.api = nFeat.Attributes["api"].Value;
+ string[] version = nFeat.Attributes["number"].Value.Split ('.');
+ fd.major = int.Parse (version[0]);
+ fd.minor = int.Parse (version[1]);
+ fd.comment = nFeat.Attributes["comment"]?.Value;
- features.Add (fd);
- }
+ foreach (XmlNode f in nFeat.ChildNodes) {
+ if (f.Name == "require") {
+ parseRequirements (fd, f);
+ } else if (f.Name == "remove") {
+ Console.ForegroundColor = ConsoleColor.DarkBlue;
+ Console.WriteLine ($"feature remove: {f.OuterXml}");
+ }// else
+ //Debugger.Break ();
+ }
+ features.Add (fd);
+ }
- static MemberDef parseMember (XmlNode np) {
- MemberDef md = new MemberDef () { typedef = ParamDef.parse (np) };
- if (np.Attributes["optional"] != null)
- md.optional = true;
- md.lenMember = np.Attributes["len"]?.Value;
- md.defaultValue = np.Attributes["values"]?.Value;
- md.optional = np.Attributes["optional"] != null;//could handle both case
- md.externsync = np.Attributes["externsync"] != null;
+ static MemberDef parseMember (XmlNode np) {
+ MemberDef md = new MemberDef () { typedef = ParamDef.parse (np) };
+ if (np.Attributes["optional"] != null)
+ md.optional = true;
- md.Name = np["name"].InnerText;
- if (reservedNames.Contains (md.Name))
- md.Name = "_" + md.Name;
+ md.lenMember = np.Attributes["len"]?.Value;
+ md.defaultValue = np.Attributes["values"]?.Value;
+ md.optional = np.Attributes["optional"] != null;//could handle both case
+ md.externsync = np.Attributes["externsync"] != null;
- XmlNode ns = np["name"].NextSibling;
- if (ns?.NodeType == XmlNodeType.Text && ns.Value.StartsWith ("[", StringComparison.Ordinal)) {
- if (np["enum"] != null) {
- md.fixedArray = np["enum"].InnerXml;
- } else
- md.fixedArray = ns.Value;
- }
+ md.Name = np["name"].InnerText;
+ if (reservedNames.Contains (md.Name))
+ md.Name = "_" + md.Name;
+ XmlNode ns = np["name"].NextSibling;
+ if (ns?.NodeType == XmlNodeType.Text && ns.Value.StartsWith ("[",StringComparison.Ordinal)) {
+ if (np["enum"] != null) {
+ md.fixedArray = np["enum"].InnerXml;
+ } else
+ md.fixedArray = ns.Value;
+ }
- md.comment = np["comment"]?.InnerText;
- return md;
- }
+ md.comment = np["comment"]?.InnerText;
- public static void readCommand (XmlNode ncmd) {
- CommandDef cd = new CommandDef ();
+ return md;
+ }
- if (ncmd.Attributes["alias"] != null) {
- cd.Name = ncmd.Attributes["name"].Value;
- cd.alias = ncmd.Attributes["alias"].Value;
- } else {
- cd.successCodes = ncmd.Attributes["successcodes"]?.Value;
- cd.errorcodes = ncmd.Attributes["errorcodes"]?.Value;
+ public static void readCommand (XmlNode ncmd) {
+ CommandDef cd = new CommandDef ();
- XmlNode n = ncmd["proto"];
- cd.returnType = ParamDef.parse (n);
- cd.Name = n["name"].InnerText;
- n = n.NextSibling;
- while (n != null) {
- if (n.Name == "param")
- cd.parameters.Add (parseMember (n));
- else if (n.Name == "implicitexternsyncparams")
- cd.comment = n.InnerText;
+ if (ncmd.Attributes ["alias"] != null) {
+ cd.Name = ncmd.Attributes ["name"].Value;
+ cd.alias = ncmd.Attributes["alias"].Value;
+ } else {
+ cd.successCodes = ncmd.Attributes["successcodes"]?.Value;
+ cd.errorcodes = ncmd.Attributes["errorcodes"]?.Value;
- n = n.NextSibling;
- }
- }
- commands.Add (cd);
- }
- #endregion
+ XmlNode n = ncmd["proto"];
+ cd.returnType = ParamDef.parse (n);
+ cd.Name = n["name"].InnerText;
+ n = n.NextSibling;
+ while (n != null) {
+ if (n.Name == "param")
+ cd.parameters.Add (parseMember (n));
+ else if (n.Name == "implicitexternsyncparams")
+ cd.comment = n.InnerText;
- const string vkxmlUrl = "https://raw.githubusercontent.com/KhronosGroup/Vulkan-Docs/master/xml/vk.xml";
- const string vkxmlLocal = "vk.xml";
+ n = n.NextSibling;
+ }
+ }
+ commands.Add (cd);
+ }
+ #endregion
- public static void Main (string[] args) {
- Console.WriteLine ("Http query for: " + vkxmlUrl);
- DateTime lastModifiedLocal = DateTime.MinValue;
- if (File.Exists (vkxmlLocal))
- lastModifiedLocal = File.GetLastWriteTime (vkxmlLocal);
+ const string vkxmlLocal = "Vulkan-Docs/xml/vk.xml";
+ const string targetDir = "build/generated";
+ static string targetPath (string fileName) =>
+ Path.Combine (targetDir, $"{fileName}_gen.cs");
- WebClient webCli = new WebClient ();
- HttpWebRequest request = WebRequest.Create (vkxmlUrl) as HttpWebRequest;
- HttpWebResponse response = request.GetResponse () as HttpWebResponse;
- if (response.StatusCode == HttpStatusCode.OK) {
- if (DateTime.Compare (lastModifiedLocal, response.LastModified) == 0)
- Console.WriteLine (vkxmlLocal + "is up to date");
- else {
- Console.WriteLine ("Downloading " + vkxmlUrl + " ...");
- webCli.DownloadFile (vkxmlUrl, vkxmlLocal);
- }
- }
+ static void printError (string errString) {
+ Console.ForegroundColor = ConsoleColor.Red;
+ Console.WriteLine (errString);
+ Console.ResetColor();
+ }
- XmlDocument doc = new XmlDocument ();
- doc.Load (vkxmlLocal);
+ public static void Main (string[] args) {
- foreach (XmlNode p in doc.GetElementsByTagName ("tags").Item (0))
- tags.Add (p.Attributes["name"].Value.ToString ());
+ if (!File.Exists(vkxmlLocal)) {
+ printError ($"[GEN] {Path.Combine (Directory.GetCurrentDirectory(),vkxmlLocal)} not found.");
+ return;
+ }
- foreach (XmlNode p in doc.GetElementsByTagName ("types").Item (0))
- readType (p);
+ XmlDocument doc = new XmlDocument();
+ doc.Load(vkxmlLocal);
- XmlNodeList enumsNL = doc.GetElementsByTagName ("enums");
- for (int i = 0; i < enumsNL.Count; i++)
- readEnum (enumsNL.Item (i));
+ foreach (XmlNode p in doc.GetElementsByTagName("tags").Item(0))
+ tags.Add(p.Attributes["name"].Value.ToString());
- foreach (XmlNode e in doc.GetElementsByTagName ("commands").Item (0)) {
- if (e.Name == "command")
- readCommand (e);
- else
- Console.WriteLine ($"commands: {e.OuterXml}");
- }
+ foreach (XmlNode p in doc.GetElementsByTagName("types").Item(0))
+ readType(p);
- foreach (XmlNode e in doc.GetElementsByTagName ("extensions").Item (0)) {
- if (e.Name == "extension")
- readExtension (e);
- else
- Console.WriteLine ($"extension: {e.OuterXml}");
- }
+ XmlNodeList enumsNL = doc.GetElementsByTagName("enums");
+ for (int i = 0; i < enumsNL.Count; i++)
+ readEnum(enumsNL.Item(i));
- XmlNodeList featuresNL = doc.GetElementsByTagName ("feature");
- for (int i = 0; i < featuresNL.Count; i++)
- readFeature (featuresNL.Item (i));
+ foreach (XmlNode e in doc.GetElementsByTagName("commands").Item(0)) {
+ if (e.Name == "command")
+ readCommand(e);
+ else
+ Console.WriteLine($"commands: {e.OuterXml}");
+ }
+ foreach (XmlNode e in doc.GetElementsByTagName("extensions").Item(0)) {
+ if (e.Name == "extension")
+ readExtension(e);
+ else
+ Console.WriteLine($"extension: {e.OuterXml}");
+ }
- gen_constants ("Vk");
- gen_enums ("Vk");
- gen_structs ("Vk");
- gen_commands ("Vk");
- gen_handles ("Vk");
- //gen_funcptrs ("Vk");
+ XmlNodeList featuresNL = doc.GetElementsByTagName("feature");
+ for (int i = 0; i < featuresNL.Count; i++)
+ readFeature(featuresNL.Item(i));
- gen_extensions ();
- }
- }
+ gen_constants ("Vk");
+ gen_enums ("Vk");
+ gen_structs ("Vk");
+ gen_commands ("Vk");
+ gen_handles ("Vk");
+ //gen_funcptrs ("Vk");
+
+ gen_extensions ();
+
+ return;
+ }
+
+ }
}
diff --git a/vk.generator/vk.generator.csproj b/vk.generator/vk.generator.csproj
index 85c38d8..91e902b 100644
--- a/vk.generator/vk.generator.csproj
+++ b/vk.generator/vk.generator.csproj
@@ -1,13 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFrameworks>$(ToolsFramework)</TargetFrameworks>
+ <TargetFramework>$(ToolsFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
- <ItemGroup>
- <None Update="vk.xml">
- <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
- </ItemGroup>
+
</Project>
diff --git a/vk.net.sln b/vk.net.sln
index d3f3dda..62cfa5f 100644
--- a/vk.net.sln
+++ b/vk.net.sln
@@ -2,7 +2,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vk.generator", "vk.generator\vk.generator.csproj", "{B105512C-9461-4802-B299-A6E7A29CDAEE}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vulkan", "VK\vulkan.csproj", "{37D01BE5-5FE2-4742-BD5B-5D2C25FCF146}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vulkan", "vulkan\vulkan.csproj", "{37D01BE5-5FE2-4742-BD5B-5D2C25FCF146}"
+ ProjectSection(ProjectDependencies) = postProject
+ {B105512C-9461-4802-B299-A6E7A29CDAEE} = {AB8DF076-E252-4FDF-BCD4-9503851BB9A0}
+ {5EC0F6C6-74C9-4509-8AC8-FAE3574AF5C7} = {5EC0F6C6-74C9-4509-8AC8-FAE3574AF5C7}
+ EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vk.rewrite", "vk.rewrite\vk.rewrite.csproj", "{5EC0F6C6-74C9-4509-8AC8-FAE3574AF5C7}"
EndProject
@@ -27,6 +31,9 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
EndGlobalSection
+ GlobalSection(ProjectDependencies) = postSolution
+ {37D01BE5-5FE2-4742-BD5B-5D2C25FCF146} = {B105512C-9461-4802-B299-A6E7A29CDAEE}
+ EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
Policies = $0
$0.TextStylePolicy = $1
diff --git a/vk.rewrite/vk.rewrite.csproj b/vk.rewrite/vk.rewrite.csproj
index 2246148..8808b12 100644
--- a/vk.rewrite/vk.rewrite.csproj
+++ b/vk.rewrite/vk.rewrite.csproj
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFrameworks>$(ToolsFramework)</TargetFrameworks>
+ <TargetFramework>$(ToolsFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="Mono.Cecil" Version="0.11.2" />
+ <PackageReference Include="Mono.Cecil" Version="0.11.4" />
</ItemGroup>
-
+
</Project>
diff --git a/VK/BindingsHelpers.cs b/vulkan/BindingsHelpers.cs
index 60a4ae2..60a4ae2 100644
--- a/VK/BindingsHelpers.cs
+++ b/vulkan/BindingsHelpers.cs
diff --git a/VK/CalliRewriteAttribute.cs b/vulkan/CalliRewriteAttribute.cs
index c30a22c..c30a22c 100644
--- a/VK/CalliRewriteAttribute.cs
+++ b/vulkan/CalliRewriteAttribute.cs
diff --git a/VK/Commands.cs b/vulkan/Commands.cs
index e25eee0..e25eee0 100644
--- a/VK/Commands.cs
+++ b/vulkan/Commands.cs
diff --git a/VK/Delegates.cs b/vulkan/Delegates.cs
index f400aca..f400aca 100644
--- a/VK/Delegates.cs
+++ b/vulkan/Delegates.cs
diff --git a/VK/ExternalTypes.cs b/vulkan/ExternalTypes.cs
index dfde870..dfde870 100644
--- a/VK/ExternalTypes.cs
+++ b/vulkan/ExternalTypes.cs
diff --git a/VK/Kernel32.cs b/vulkan/Kernel32.cs
index 7154319..7154319 100644
--- a/VK/Kernel32.cs
+++ b/vulkan/Kernel32.cs
diff --git a/VK/Libdl.cs b/vulkan/Libdl.cs
index ffd278b..ffd278b 100644
--- a/VK/Libdl.cs
+++ b/vulkan/Libdl.cs
diff --git a/VK/Structs.cs b/vulkan/Structs.cs
index 899562e..899562e 100644
--- a/VK/Structs.cs
+++ b/vulkan/Structs.cs
diff --git a/VK/Utils.cs b/vulkan/Utils.cs
index cd2b3ee..cd2b3ee 100644
--- a/VK/Utils.cs
+++ b/vulkan/Utils.cs
diff --git a/VK/Version.cs b/vulkan/Version.cs
index ab73511..ab73511 100644
--- a/VK/Version.cs
+++ b/vulkan/Version.cs
diff --git a/VK/VkBool32.cs b/vulkan/VkBool32.cs
index f424a4b..f424a4b 100644
--- a/VK/VkBool32.cs
+++ b/vulkan/VkBool32.cs
diff --git a/VK/VkExtent2D.cs b/vulkan/VkExtent2D.cs
index 3a32769..3a32769 100644
--- a/VK/VkExtent2D.cs
+++ b/vulkan/VkExtent2D.cs
diff --git a/VK/VkOffset2D.cs b/vulkan/VkOffset2D.cs
index 3e762a0..3e762a0 100644
--- a/VK/VkOffset2D.cs
+++ b/vulkan/VkOffset2D.cs
diff --git a/VK/VkRect2D.cs b/vulkan/VkRect2D.cs
index 5e332c4..5e332c4 100644
--- a/VK/VkRect2D.cs
+++ b/vulkan/VkRect2D.cs
diff --git a/VK/vk.net-128.png b/vulkan/vk.net-128.png
index 781ac00..781ac00 100644
--- a/VK/vk.net-128.png
+++ b/vulkan/vk.net-128.png
Binary files differ
diff --git a/VK/vk.net-64.png b/vulkan/vk.net-64.png
index 97922b0..97922b0 100644
--- a/VK/vk.net-64.png
+++ b/vulkan/vk.net-64.png
Binary files differ
diff --git a/vulkan/vulkan.csproj b/vulkan/vulkan.csproj
new file mode 100644
index 0000000..337aca0
--- /dev/null
+++ b/vulkan/vulkan.csproj
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project Sdk="Microsoft.NET.Sdk">
+ <PropertyGroup>
+ <TargetFrameworks>netstandard2.0</TargetFrameworks>
+
+ <AssemblyVersion>0.2.5</AssemblyVersion>
+ <AssemblyName>Vulkan</AssemblyName>
+ <PackageVersion>$(AssemblyVersion)-beta</PackageVersion>
+
+ <Description>Low level vulkan bindings for .net</Description>
+ <Product>Vulkan</Product>
+ <PackageLicence>MIT</PackageLicence>
+ <PackageId>Vulkan</PackageId>
+ <PackageTags>C# vulkan net binding</PackageTags>
+ <PackageLicenseExpression>MIT</PackageLicenseExpression>
+ <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
+ <PackageProjectUrl>https://github.com/jpbruyere/vk.net/blob/master/README.md</PackageProjectUrl>
+ <Icon>vk.net-64.png</Icon>
+ <PackageIcon>vk.net-64.png</PackageIcon>
+ <SynchReleaseVersion>false</SynchReleaseVersion>
+ <PackageReleaseNotes>
+
+ </PackageReleaseNotes>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <Content Include="vk.net-64.png" Pack="true" PackagePath="" />
+ </ItemGroup>
+
+ <Target Name="generate" BeforeTargets="BeforeCompile">
+ <MakeDir Directories="$(SolutionDir)build/generated" />
+ <Exec Condition="$(OS) == 'Windows_NT'"
+ Command="$(SolutionDir)vk.generator/bin/$(Configuration)/$(ToolsFramework)/vk.generator.exe"
+ WorkingDirectory="$(SolutionDir)">
+ <Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
+ </Exec>
+ <Exec Condition="$(OS) != 'Windows_NT'"
+ Command="$(SolutionDir)vk.generator/bin/$(Configuration)/$(ToolsFramework)/vk.generator"
+ WorkingDirectory="$(SolutionDir)">
+ <Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
+ </Exec>
+ <CreateItem Include="$(SolutionDir)build/generated/*.cs">
+ <Output TaskParameter="Include" ItemName="Compile" />
+ </CreateItem>
+ </Target>
+
+ <Target Name="rewrite" AfterTargets="CoreBuild">
+ <Exec Condition="$(OS) == 'Windows_NT'" ConsoleToMSBuild="true" EchoOff="true"
+ Command="$(SolutionDir)vk.rewrite/bin/$(Configuration)/$(ToolsFramework)/vk.rewrite.exe $(TargetPath)" >
+ <Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
+ </Exec>
+ <Exec Condition="$(OS) != 'Windows_NT'" ConsoleToMSBuild="true" EchoOff="true"
+ Command="$(SolutionDir)vk.rewrite/bin/$(Configuration)/$(ToolsFramework)/vk.rewrite $(TargetPath)">
+ <Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
+ </Exec>
+ </Target>
+
+</Project>