diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2020-12-30 00:28:48 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2020-12-30 00:28:48 +0100 |
| commit | 4fe1d54ef30f34647b90af406850fecda91469dc (patch) | |
| tree | e1c1479fc4f06abf1cd88712c2b8be1d7d7dedf0 | |
| parent | 9d5d1022cf3a99b0e594d92d4c296bd35060ae7b (diff) | |
modified fixed arrays to handle multi dims for VkTransformMatrixKHR
| -rw-r--r-- | VK/Structs.cs | 19 | ||||
| -rw-r--r-- | VK/vulkan.csproj | 2 | ||||
| -rw-r--r-- | vk.generator/Program.cs | 63 | ||||
| -rw-r--r-- | vk.rewrite/Program.cs | 36 |
4 files changed, 74 insertions, 46 deletions
diff --git a/VK/Structs.cs b/VK/Structs.cs index c725de0..899562e 100644 --- a/VK/Structs.cs +++ b/VK/Structs.cs @@ -192,14 +192,19 @@ namespace Vulkan { } } /// <summary> - /// 3X4 ROW Major affine transformation matrix + /// 3x4 row-major affine transformation matrix. /// </summary> - [StructLayout (LayoutKind.Sequential)] - public struct VkTransformMatrixKHR { - [MarshalAs (UnmanagedType.ByValArray, SizeConst = 48)] float[] values; - public float this[int row, int col] { - get => values[row * 3 + col]; - set => values[row * 3 + col] = value; + public unsafe partial struct VkTransformMatrixKHR + { + public float this [int row, int column] { + get { + fixed (float* tmp = _matrix) + return tmp[row * 3 + column]; + } + set { + fixed (float* tmp = _matrix) + tmp[row * 3 + column] = value; + } } } } diff --git a/VK/vulkan.csproj b/VK/vulkan.csproj index ddf811c..43601d4 100644 --- a/VK/vulkan.csproj +++ b/VK/vulkan.csproj @@ -3,7 +3,7 @@ <PropertyGroup> <TargetFrameworks>netstandard2.0</TargetFrameworks> - <AssemblyVersion>0.2.3</AssemblyVersion> + <AssemblyVersion>0.2.5</AssemblyVersion> <AssemblyName>VK</AssemblyName> <Description>Low level vulkan bindings for .net</Description> <Product>VK</Product> diff --git a/vk.generator/Program.cs b/vk.generator/Program.cs index e69b2ca..a22bcec 100644 --- a/vk.generator/Program.cs +++ b/vk.generator/Program.cs @@ -150,10 +150,12 @@ namespace vk.generator { { "PFN_vkVoidFunction","IntPtr" }, { "AHardwareBuffer", "Android.ANativeWindow" },//must be corrected - }; + { "IDirectFB","IntPtr" }, + { "IDirectFBSurface","IntPtr" }, + + }; - static string[] skipEnums = { "VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES2_EXT", "VK_PIPELINE_CREATE_DISPATCH_BASE" }; - static string[] skipStruct = { "VkTransformMatrixKHR" }; + 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"} }, @@ -258,9 +260,7 @@ namespace vk.generator { return tmp; } - public string FullCTypeDecl { - get { return txtbefore + name + txtafter; } - } + public string FullCTypeDecl => txtbefore + name + txtafter; public int IndirectionLevel { get { if (string.IsNullOrEmpty (txtafter)) @@ -273,15 +273,9 @@ namespace vk.generator { return i; } } - public bool IsStruct { - get { return string.IsNullOrEmpty (txtbefore) ? false : txtbefore.Contains ("struct"); } - } - public bool IsConst { - get { return string.IsNullOrEmpty (txtbefore) ? false : txtbefore.Contains ("const"); } - } - public override string ToString () { - return FullCTypeDecl; - } + 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; @@ -294,9 +288,7 @@ namespace vk.generator { public string defaultValue; public string fixedArray; - public override string ToString () { - return 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!! @@ -439,9 +431,12 @@ namespace vk.generator { if (!string.IsNullOrEmpty (mb.fixedArray)) { int dim = 0; + string[] dims = mb.fixedArray.Split (new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries); if (valueTypes.Contains (typeStr)) { - string strSize = int.TryParse (mb.fixedArray, out dim) ? dim.ToString() : $"(int)Vk.{EnumerantValue.GetCSName (mb.fixedArray, null)}"; 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++; @@ -451,20 +446,33 @@ namespace vk.generator { tw.Indent++; tw.WriteLine ($"return System.Text.Encoding.UTF8.GetString (tmp, {strSize});"); //tw.WriteLine ($"set {{ _{mb.Name} = ({typeStr})value; }}"); - tw.Indent-=2; + tw.Indent -= 2; tw.WriteLine (@"}"); tw.Indent--; tw.WriteLine (@"}"); - } else + } 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 (int.TryParse (mb.fixedArray, out dim)) { + 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(mb.fixedArray,null)})]"); + tw.WriteLine ($"[MarshalAs (UnmanagedType.ByValArray, SizeConst = (int)Vk.{EnumerantValue.GetCSName(dims[0], null)})]"); tw.WriteLine ($"public {typeStr}[] {mb.Name};"); } continue; @@ -485,11 +493,8 @@ namespace vk.generator { writePreamble (tw, "System.Runtime.InteropServices"); tw.Indent++; - foreach (StructDef sd in types.OfType<StructDef> ()) { - if (skipStruct.Contains (sd.Name)) - continue; - gen_struct (tw, sd); - } + foreach (StructDef sd in types.OfType<StructDef> ()) + gen_struct (tw, sd); tw.Indent--; tw.WriteLine (@"}"); @@ -1201,7 +1206,7 @@ namespace vk.generator { if (np["enum"] != null) { md.fixedArray = np["enum"].InnerXml; } else - md.fixedArray = ns.Value.Substring(1, ns.InnerText.Length-2); + md.fixedArray = ns.Value; } diff --git a/vk.rewrite/Program.cs b/vk.rewrite/Program.cs index 93101b9..db41bab 100644 --- a/vk.rewrite/Program.cs +++ b/vk.rewrite/Program.cs @@ -88,9 +88,13 @@ namespace Vk.Rewrite List<VariableDefinition> stringParams = new List<VariableDefinition>(); for (int i = 0; i < method.Parameters.Count; i++) { + EmitLoadArgument (il, i, method.Parameters); + TypeReference parameterType = method.Parameters[i].ParameterType; - EmitLoadArgument (il, i, method.Parameters); - TypeReference parameterType = method.Parameters[i].ParameterType; + if (parameterType.IsGenericInstance) { + if (parameterType.Name == "Nullable`1") + System.Diagnostics.Debugger.Break (); + } if (parameterType.FullName == "System.String") { @@ -100,7 +104,15 @@ namespace Vk.Rewrite il.Emit(OpCodes.Stloc, variableDef); il.Emit(OpCodes.Ldloc, variableDef); stringParams.Add(variableDef); - } + } + else if (parameterType.IsByReference) + { + VariableDefinition byRefVariable = new VariableDefinition(new PinnedType(parameterType)); + method.Body.Variables.Add(byRefVariable); + il.Emit(OpCodes.Stloc, byRefVariable); + il.Emit(OpCodes.Ldloc, byRefVariable); + il.Emit(OpCodes.Conv_I); + } } FieldDefinition field = method.DeclaringType.Fields.SingleOrDefault(fd => fd.Name == method.Name + "_ptr"); @@ -111,16 +123,22 @@ namespace Vk.Rewrite il.Emit(OpCodes.Ldsfld, field); CallSite callSite = new CallSite(method.ReturnType) {CallingConvention = MethodCallingConvention.StdCall}; - + foreach (ParameterDefinition pd in method.Parameters) { + TypeReference parameterType; - if (pd.ParameterType.FullName == "System.String") - callSite.Parameters.Add (new ParameterDefinition (pd.Name, pd.Attributes, s_stringHandleRef)); - else - callSite.Parameters.Add (pd); - } + if (pd.ParameterType.IsByReference) + parameterType = new PointerType(pd.ParameterType.GetElementType()); + else if (pd.ParameterType.FullName == "System.String") + parameterType = s_stringHandleRef; + else + parameterType = pd.ParameterType; + + ParameterDefinition calliPD = new ParameterDefinition(pd.Name, pd.Attributes, parameterType); + callSite.Parameters.Add(calliPD); + } il.Emit(OpCodes.Calli, callSite); foreach (VariableDefinition stringVar in stringParams) |