diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-12-02 20:12:08 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-12-02 20:12:08 +0100 |
| commit | baf18112ce9f7807a6364243399566f18a240b8f (patch) | |
| tree | 41a853f86335c1e96305a3e1a2bffe3320e51880 | |
| parent | 7c27042d45798225306dfbc677640ea2701f8e1a (diff) | |
tests vkcolorvalue
| -rw-r--r-- | tests/Program.cs | 26 | ||||
| -rw-r--r-- | tests/tests.csproj | 2 | ||||
| -rw-r--r-- | vk.generator/Program.cs | 38 | ||||
| -rw-r--r-- | vulkan/Structs.cs | 101 | ||||
| -rw-r--r-- | vulkan/vulkan.csproj | 2 |
5 files changed, 130 insertions, 39 deletions
diff --git a/tests/Program.cs b/tests/Program.cs index dcbdd2a..6bd6dcf 100644 --- a/tests/Program.cs +++ b/tests/Program.cs @@ -1,12 +1,34 @@ using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Text; using Vulkan; using static Vulkan.Vk; using Version = Vulkan.Version; namespace tests { + [StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)] + public struct NewStuff + { + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)Vulkan.Vk.UuidSize)] + public StringBuilder name; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4*16)] + public float[,] calibrate; + + [MarshalAs(UnmanagedType.R4)] + public float DMTI; + + [MarshalAs(UnmanagedType.R4)] + public float DMTII; + + // Etc + } + class Program { + static void Main(string[] args) { VkInstance instance; @@ -16,6 +38,10 @@ namespace tests //ai.apiVersion = new Version (1,0,0); //ai.applicationVersion = new Version (1,0,0); + + VkClearColorValue clear = new VkClearColorValue(255,0,0); + clear.float32.a = 210; + using (PinnedObjects pi = new PinnedObjects()) { ci.pApplicationInfo = ai.Pin(pi); diff --git a/tests/tests.csproj b/tests/tests.csproj index ed261c9..84eb5ae 100644 --- a/tests/tests.csproj +++ b/tests/tests.csproj @@ -2,7 +2,7 @@ <PropertyGroup> <OutputType>Exe</OutputType> - <TargetFramework>netcoreapp3.1</TargetFramework> + <TargetFramework>net6</TargetFramework> </PropertyGroup> <ItemGroup> diff --git a/vk.generator/Program.cs b/vk.generator/Program.cs index a7c5419..cccc762 100644 --- a/vk.generator/Program.cs +++ b/vk.generator/Program.cs @@ -161,12 +161,25 @@ namespace vk.generator { { "VkRemoteAddressNV","IntPtr" }, }; + static string[] reservedNames = { "event", "object" }; static string[] skipEnums = { "VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES2_EXT", "VK_PIPELINE_CREATE_DISPATCH_BASE" }; + static string[] skipGenStruct = { "VkClearColorValue" }; + static Dictionary<string, string[]> paramTypeAliases = new Dictionary<string, string[]> { { "void*", new string[] {"IntPtr"} }, { "char*", new string[] {"string"} } }; + //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"}; public static Dictionary<string, string> aliases = new Dictionary<string, string> (); static void AddAlias (string from, string to) { @@ -185,18 +198,7 @@ namespace vk.generator { 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"}; - static string[] reservedNames = { "event", "object" }; static Dictionary<string, ParamDef> paramsDefs = new Dictionary<string, ParamDef> (); @@ -406,9 +408,9 @@ namespace vk.generator { rp.writeSummaryAndRemarks (tw); if (sd.category == TypeCategories.union) - tw.WriteLine($"[StructLayout(LayoutKind.Explicit)]"); + tw.WriteLine($"[StructLayout(LayoutKind.Explicit, Pack = 1, CharSet = CharSet.Ansi)]"); else - tw.WriteLine ($"[StructLayout(LayoutKind.Sequential)]"); + tw.WriteLine ($"[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]"); tw.WriteLine ($"public unsafe partial struct {sd.Name} {{"); tw.Indent++; foreach (MemberDef mb in sd.members) { @@ -505,8 +507,11 @@ namespace vk.generator { writePreamble (tw, "System.Runtime.InteropServices"); tw.Indent++; - foreach (StructDef sd in types.OfType<StructDef> ()) + foreach (StructDef sd in types.OfType<StructDef> ()) { + if (skipGenStruct.Contains (sd.Name)) + continue; gen_struct (tw, sd); + } tw.Indent--; tw.WriteLine (@"}"); @@ -1282,9 +1287,7 @@ namespace vk.generator { } #endregion - /// <summary> - /// this is a summary #ref:string - /// </summary> + #region VulkanDoc refpages parsing struct refPage { public string bief; public string description; @@ -1475,6 +1478,7 @@ namespace vk.generator { } return true; } + #endregion const string vkrefsdir = "Vulkan-Docs/gen/refpage"; const string targetDir = "build/generated"; static string targetPath (string fileName) => diff --git a/vulkan/Structs.cs b/vulkan/Structs.cs index 899562e..660778f 100644 --- a/vulkan/Structs.cs +++ b/vulkan/Structs.cs @@ -14,34 +14,95 @@ namespace Vulkan { } } - public unsafe partial struct VkClearColorValue { + [StructLayout(LayoutKind.Explicit, Pack = 1, CharSet = CharSet.Ansi, Size = 16)] + public struct VkClearColorValue { + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct _Float32 { + public float r; + public float g; + public float b; + public float a; + } + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct _Int32 { + public int r; + public int g; + public int b; + public int a; + } + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct _UInt32 { + public uint r; + public uint g; + public uint b; + public uint a; + } + [FieldOffset(0)] + public _Float32 float32; + [FieldOffset(0)] + public _Int32 int32; + [FieldOffset(0)] + public _UInt32 uint32; public VkClearColorValue (float r, float g, float b, float a = 1.0f) : this () { - fixed (float* tmp = float32) { - tmp[0] = r; - tmp[1] = g; - tmp[2] = b; - tmp[3] = a; - } + float32.r = r; + float32.g = g; + float32.b = b; + float32.a = a; } public VkClearColorValue (int r, int g, int b, int a = 255) : this () { - fixed (int* tmp = int32) { - tmp[0] = r; - tmp[1] = g; - tmp[2] = b; - tmp[3] = a; - } + int32.r = r; + int32.g = g; + int32.b = b; + int32.a = a; } public VkClearColorValue (uint r, uint g, uint b, uint a = 255) : this () { - fixed (uint* tmp = uint32) { - tmp[0] = r; - tmp[1] = g; - tmp[2] = b; - tmp[3] = a; - } + uint32.r = r; + uint32.g = g; + uint32.b = b; + uint32.a = a; } - } + } + + /*[StructLayout(LayoutKind.Explicit, Pack = 1)] + public struct VkClearColorValue { + [FieldOffset(0)]public float float32_r; + [FieldOffset(1)]public float float32_g; + [FieldOffset(2)]public float float32_b; + [FieldOffset(3)]public float float32_a; + [FieldOffset(0)]public int int32_r; + [FieldOffset(1)]public int int32_g; + [FieldOffset(2)]public int int32_b; + [FieldOffset(3)]public int int32_a; + [FieldOffset(0)]public uint uint32_r; + [FieldOffset(1)]public uint uint32_g; + [FieldOffset(2)]public uint uint32_b; + [FieldOffset(3)]public uint uint32_a; + public float[] ToFloats => new float[] {float32_r, float32_g, float32_b, float32_a}; + public float[] ToInts => new float[] {int32_r, int32_g, int32_b, int32_a}; + public float[] ToUInts => new float[] {uint32_r, uint32_g, uint32_b, uint32_a}; + public VkClearColorValue (float r, float g, float b, float a = 1.0f) : this () { + float32_r = r; + float32_g = g; + float32_b = b; + float32_a = a; + } + + public VkClearColorValue (int r, int g, int b, int a = 255) : this () { + int32_r = r; + int32_g = g; + int32_b = b; + int32_a = a; + } + + public VkClearColorValue (uint r, uint g, uint b, uint a = 255) : this () { + uint32_r = r; + uint32_g = g; + uint32_b = b; + uint32_a = a; + } + }*/ public partial struct VkClearDepthStencilValue { public VkClearDepthStencilValue(float depth, uint stencil) diff --git a/vulkan/vulkan.csproj b/vulkan/vulkan.csproj index a93dee5..528c8c3 100644 --- a/vulkan/vulkan.csproj +++ b/vulkan/vulkan.csproj @@ -3,7 +3,7 @@ <PropertyGroup> <TargetFrameworks>netstandard2.0</TargetFrameworks> - <AssemblyVersion>0.2.5</AssemblyVersion> + <AssemblyVersion>0.3.0</AssemblyVersion> <AssemblyName>Vulkan</AssemblyName> <PackageVersion>$(AssemblyVersion)-beta</PackageVersion> |