diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-12-03 16:19:08 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-12-03 16:19:08 +0100 |
| commit | e1dbbce20040ee0340125fc39dc0af987dabe5df (patch) | |
| tree | a203aa58169f50736b54a775bf1e776344734a54 /vulkan/Structs.cs | |
| parent | baf18112ce9f7807a6364243399566f18a240b8f (diff) | |
VkTransformMatrix, log_gen, netstandard2.1
Diffstat (limited to 'vulkan/Structs.cs')
| -rw-r--r-- | vulkan/Structs.cs | 287 |
1 files changed, 146 insertions, 141 deletions
diff --git a/vulkan/Structs.cs b/vulkan/Structs.cs index 660778f..022a679 100644 --- a/vulkan/Structs.cs +++ b/vulkan/Structs.cs @@ -5,131 +5,128 @@ using System; using System.Runtime.InteropServices; -namespace Vulkan { +namespace Vulkan +{ - public partial struct VkClearValue { - public VkClearValue (float r, float g, float b) { - depthStencil = default (VkClearDepthStencilValue); - color = new VkClearColorValue (r, g, b); + public partial struct VkClearValue + { + public VkClearValue(float r, float g, float b) + { + depthStencil = default(VkClearDepthStencilValue); + color = new VkClearColorValue(r, g, b); } } - [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, Size = 16)] + public struct VkClearColorValue + { + public Span<float> floats + { + get + { + Span<VkClearColorValue> valSpan = MemoryMarshal.CreateSpan(ref this, 1); + return MemoryMarshal.Cast<VkClearColorValue, float>(valSpan); + } } - [StructLayout(LayoutKind.Sequential, Pack = 1)] - public struct _Int32 { - public int r; - public int g; - public int b; - public int a; + public Span<int> ints + { + get + { + Span<VkClearColorValue> valSpan = MemoryMarshal.CreateSpan(ref this, 1); + return MemoryMarshal.Cast<VkClearColorValue, int>(valSpan); + } } - [StructLayout(LayoutKind.Sequential, Pack = 1)] - public struct _UInt32 { - public uint r; - public uint g; - public uint b; - public uint a; + public Span<uint> uints + { + get + { + Span<VkClearColorValue> valSpan = MemoryMarshal.CreateSpan(ref this, 1); + return MemoryMarshal.Cast<VkClearColorValue, uint>(valSpan); + } } - [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 () { - float32.r = r; - float32.g = g; - float32.b = b; - float32.a = a; + public VkClearColorValue(float r, float g, float b, float a = 1.0f) : this() + { + floats[0] = r; + floats[1] = g; + floats[2] = b; + floats[3] = 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(int r, int g, int b, int a = 255) : this() + { + ints[0] = r; + ints[1] = g; + ints[2] = b; + ints[3] = 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 VkClearColorValue(uint r, uint g, uint b, uint a = 255) : this() + { + uints[0] = r; + uints[1] = g; + uints[2] = b; + uints[3] = 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; + } + /// <summary> + /// Structure specifying a 3x4 row-major affine transformation matrix. + /// </summary> + [StructLayout(LayoutKind.Sequential, Size = 48)] + public struct VkTransformMatrixKHR + { + /// <summary> + /// Get row by index. + /// </summary> + /// <returns>The span of the row.</returns> + public Span<float> this[int i] => AsSpan.Slice(i * 4, 3); + /// <summary> + /// Get the whole matrix as a single span of floats. + /// </summary> + /// <value>The span of the matrix.</value> + public Span<float> AsSpan + { + get + { + Span<VkTransformMatrixKHR> valSpan = MemoryMarshal.CreateSpan(ref this, 1); + return MemoryMarshal.Cast<VkTransformMatrixKHR, float>(valSpan); + } } + } - 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) + { + this.depth = depth; + this.stencil = stencil; } - }*/ - public partial struct VkClearDepthStencilValue - { - public VkClearDepthStencilValue(float depth, uint stencil) - { - this.depth = depth; - this.stencil = stencil; - } - } - public partial struct VkOffset3D { - public VkOffset3D (int _x = 0, int _y = 0, int _z = 0) { + } + public partial struct VkOffset3D + { + public VkOffset3D(int _x = 0, int _y = 0, int _z = 0) + { x = _x; y = _y; z = _z; } } - public partial struct VkImageSubresourceLayers { - public VkImageSubresourceLayers (VkImageAspectFlags _aspectMask = VkImageAspectFlags.Color, - uint _layerCount = 1, uint _mipLevel = 0, uint _baseArrayLayer = 0) { + public partial struct VkImageSubresourceLayers + { + public VkImageSubresourceLayers(VkImageAspectFlags _aspectMask = VkImageAspectFlags.Color, + uint _layerCount = 1, uint _mipLevel = 0, uint _baseArrayLayer = 0) + { aspectMask = _aspectMask; layerCount = _layerCount; mipLevel = _mipLevel; baseArrayLayer = _baseArrayLayer; } } - public partial struct VkImageSubresourceRange { - public VkImageSubresourceRange ( + public partial struct VkImageSubresourceRange + { + public VkImageSubresourceRange( VkImageAspectFlags aspectMask, uint baseMipLevel = 0, uint levelCount = 1, - uint baseArrayLayer = 0, uint layerCount = 1) { + uint baseArrayLayer = 0, uint layerCount = 1) + { this.aspectMask = aspectMask; this.baseMipLevel = baseMipLevel; this.levelCount = levelCount; @@ -137,8 +134,10 @@ namespace Vulkan { this.layerCount = layerCount; } } - public partial struct VkDescriptorSetLayoutBinding { - public VkDescriptorSetLayoutBinding (uint _binding, VkShaderStageFlags _stageFlags, VkDescriptorType _descriptorType, uint _descriptorCount = 1) { + public partial struct VkDescriptorSetLayoutBinding + { + public VkDescriptorSetLayoutBinding(uint _binding, VkShaderStageFlags _stageFlags, VkDescriptorType _descriptorType, uint _descriptorCount = 1) + { binding = _binding; this._descriptorType = (int)_descriptorType; descriptorCount = _descriptorCount; @@ -146,8 +145,10 @@ namespace Vulkan { pImmutableSamplers = (IntPtr)0; } } - public partial struct VkDescriptorSetLayoutCreateInfo { - public VkDescriptorSetLayoutCreateInfo (VkDescriptorSetLayoutCreateFlags flags, uint bindingCount, IntPtr pBindings) { + public partial struct VkDescriptorSetLayoutCreateInfo + { + public VkDescriptorSetLayoutCreateInfo(VkDescriptorSetLayoutCreateFlags flags, uint bindingCount, IntPtr pBindings) + { this._sType = (int)VkStructureType.DescriptorSetLayoutCreateInfo; pNext = IntPtr.Zero; this.flags = flags; @@ -155,37 +156,44 @@ namespace Vulkan { this.pBindings = pBindings; } } - public partial struct VkVertexInputBindingDescription { - public VkVertexInputBindingDescription (uint _binding, uint _stride, VkVertexInputRate _inputRate = VkVertexInputRate.Vertex) { + public partial struct VkVertexInputBindingDescription + { + public VkVertexInputBindingDescription(uint _binding, uint _stride, VkVertexInputRate _inputRate = VkVertexInputRate.Vertex) + { binding = _binding; stride = _stride; this._inputRate = (int)_inputRate; } } - public partial struct VkVertexInputAttributeDescription { - public VkVertexInputAttributeDescription (uint _binding, uint _location, VkFormat _format, uint _offset = 0) { + public partial struct VkVertexInputAttributeDescription + { + public VkVertexInputAttributeDescription(uint _binding, uint _location, VkFormat _format, uint _offset = 0) + { location = _location; binding = _binding; this._format = (int)_format; offset = _offset; } - public VkVertexInputAttributeDescription (uint _location, VkFormat _format, uint _offset = 0) { + public VkVertexInputAttributeDescription(uint _location, VkFormat _format, uint _offset = 0) + { location = _location; binding = 0; this._format = (int)_format; offset = _offset; } } - public partial struct VkPipelineColorBlendAttachmentState { - public VkPipelineColorBlendAttachmentState (VkBool32 blendEnable, + public partial struct VkPipelineColorBlendAttachmentState + { + public VkPipelineColorBlendAttachmentState(VkBool32 blendEnable, VkBlendFactor srcColorBlendFactor = VkBlendFactor.SrcAlpha, VkBlendFactor dstColorBlendFactor = VkBlendFactor.OneMinusSrcAlpha, VkBlendOp colorBlendOp = VkBlendOp.Add, VkBlendFactor srcAlphaBlendFactor = VkBlendFactor.OneMinusSrcAlpha, VkBlendFactor dstAlphaBlendFactor = VkBlendFactor.Zero, VkBlendOp alphaBlendOp = VkBlendOp.Add, - VkColorComponentFlags colorWriteMask = VkColorComponentFlags.R | VkColorComponentFlags.G | VkColorComponentFlags.B | VkColorComponentFlags.A) { + VkColorComponentFlags colorWriteMask = VkColorComponentFlags.R | VkColorComponentFlags.G | VkColorComponentFlags.B | VkColorComponentFlags.A) + { this.blendEnable = blendEnable; this._srcColorBlendFactor = (int)srcColorBlendFactor; this._dstColorBlendFactor = (int)dstColorBlendFactor; @@ -196,24 +204,30 @@ namespace Vulkan { this.colorWriteMask = colorWriteMask; } } - public partial struct VkPushConstantRange { - public VkPushConstantRange (VkShaderStageFlags stageFlags, uint size, uint offset = 0) { + public partial struct VkPushConstantRange + { + public VkPushConstantRange(VkShaderStageFlags stageFlags, uint size, uint offset = 0) + { this.stageFlags = stageFlags; this.size = size; this.offset = offset; } } - public partial struct VkCommandBufferBeginInfo { - public VkCommandBufferBeginInfo (VkCommandBufferUsageFlags usage = (VkCommandBufferUsageFlags)0) { + public partial struct VkCommandBufferBeginInfo + { + public VkCommandBufferBeginInfo(VkCommandBufferUsageFlags usage = (VkCommandBufferUsageFlags)0) + { this._sType = (int)VkStructureType.CommandBufferBeginInfo; pNext = pInheritanceInfo = IntPtr.Zero; flags = usage; } } - public partial struct VkQueryPoolCreateInfo { - public static VkQueryPoolCreateInfo New (VkQueryType queryType, - VkQueryPipelineStatisticFlags statisticFlags = (VkQueryPipelineStatisticFlags)0, uint count = 1) { - VkQueryPoolCreateInfo ret = new VkQueryPoolCreateInfo (); + public partial struct VkQueryPoolCreateInfo + { + public static VkQueryPoolCreateInfo New(VkQueryType queryType, + VkQueryPipelineStatisticFlags statisticFlags = (VkQueryPipelineStatisticFlags)0, uint count = 1) + { + VkQueryPoolCreateInfo ret = new VkQueryPoolCreateInfo(); ret.sType = VkStructureType.QueryPoolCreateInfo; ret.pipelineStatistics = statisticFlags; ret.queryType = queryType; @@ -221,8 +235,10 @@ namespace Vulkan { return ret; } } - public partial struct VkDebugMarkerObjectNameInfoEXT { - public VkDebugMarkerObjectNameInfoEXT (VkDebugReportObjectTypeEXT objectType, ulong handle) { + public partial struct VkDebugMarkerObjectNameInfoEXT + { + public VkDebugMarkerObjectNameInfoEXT(VkDebugReportObjectTypeEXT objectType, ulong handle) + { this._sType = (int)VkStructureType.DebugMarkerObjectNameInfoEXT; pNext = IntPtr.Zero; this._objectType = (int)objectType; @@ -230,7 +246,8 @@ namespace Vulkan { pObjectName = IntPtr.Zero; } } - public partial struct VkDebugUtilsObjectNameInfoEXT { + public partial struct VkDebugUtilsObjectNameInfoEXT + { public VkDebugUtilsObjectNameInfoEXT(VkObjectType objectType, ulong handle) { this._sType = (int)VkStructureType.DebugUtilsObjectNameInfoEXT; @@ -240,33 +257,21 @@ namespace Vulkan { pObjectName = IntPtr.Zero; } } - public partial struct VkDescriptorPoolSize { - public VkDescriptorPoolSize (VkDescriptorType descriptorType, uint count = 1) { + public partial struct VkDescriptorPoolSize + { + public VkDescriptorPoolSize(VkDescriptorType descriptorType, uint count = 1) + { this._type = (int)descriptorType; descriptorCount = count; } } - public unsafe partial struct VkAttachmentReference { - public VkAttachmentReference (uint attachment, VkImageLayout layout) { + public unsafe partial struct VkAttachmentReference + { + public VkAttachmentReference(uint attachment, VkImageLayout layout) + { this.attachment = attachment; this._layout = (int)layout; } - } - /// <summary> - /// 3x4 row-major affine transformation matrix. - /// </summary> - 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; - } - } } } |