Skip to content

Commit

Permalink
use int/uint to store enum values in structs to be able to blit them …
Browse files Browse the repository at this point in the history
…with ms .net, and add a public property for fetching them with conversion
  • Loading branch information
jpbruyere committed Jan 27, 2020
1 parent 0a17e83 commit 378953c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
36 changes: 18 additions & 18 deletions VK/Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ public VkImageSubresourceRange (
public partial struct VkDescriptorSetLayoutBinding {
public VkDescriptorSetLayoutBinding (uint _binding, VkShaderStageFlags _stageFlags, VkDescriptorType _descriptorType, uint _descriptorCount = 1) {
binding = _binding;
descriptorType = _descriptorType;
this._descriptorType = (int)_descriptorType;
descriptorCount = _descriptorCount;
stageFlags = _stageFlags;
pImmutableSamplers = (IntPtr)0;
}
}
public partial struct VkDescriptorSetLayoutCreateInfo {
public VkDescriptorSetLayoutCreateInfo (VkDescriptorSetLayoutCreateFlags flags, uint bindingCount, IntPtr pBindings) {
sType = VkStructureType.DescriptorSetLayoutCreateInfo;
this._sType = (int)VkStructureType.DescriptorSetLayoutCreateInfo;
pNext = IntPtr.Zero;
this.flags = flags;
this.bindingCount = bindingCount;
Expand All @@ -98,21 +98,21 @@ public partial struct VkVertexInputBindingDescription {
public VkVertexInputBindingDescription (uint _binding, uint _stride, VkVertexInputRate _inputRate = VkVertexInputRate.Vertex) {
binding = _binding;
stride = _stride;
inputRate = _inputRate;
this._inputRate = (int)_inputRate;
}
}

public partial struct VkVertexInputAttributeDescription {
public VkVertexInputAttributeDescription (uint _binding, uint _location, VkFormat _format, uint _offset = 0) {
location = _location;
binding = _binding;
format = _format;
this._format = (int)_format;
offset = _offset;
}
public VkVertexInputAttributeDescription (uint _location, VkFormat _format, uint _offset = 0) {
location = _location;
binding = 0;
format = _format;
this._format = (int)_format;
offset = _offset;
}
}
Expand All @@ -126,12 +126,12 @@ public VkPipelineColorBlendAttachmentState (VkBool32 blendEnable,
VkBlendOp alphaBlendOp = VkBlendOp.Add,
VkColorComponentFlags colorWriteMask = VkColorComponentFlags.R | VkColorComponentFlags.G | VkColorComponentFlags.B | VkColorComponentFlags.A) {
this.blendEnable = blendEnable;
this.srcColorBlendFactor = srcColorBlendFactor;
this.dstColorBlendFactor = dstColorBlendFactor;
this.colorBlendOp = colorBlendOp;
this.srcAlphaBlendFactor = srcAlphaBlendFactor;
this.dstAlphaBlendFactor = dstAlphaBlendFactor;
this.alphaBlendOp = alphaBlendOp;
this._srcColorBlendFactor = (int)srcColorBlendFactor;
this._dstColorBlendFactor = (int)dstColorBlendFactor;
this._colorBlendOp = (int)colorBlendOp;
this._srcAlphaBlendFactor = (int)srcAlphaBlendFactor;
this._dstAlphaBlendFactor = (int)dstAlphaBlendFactor;
this._alphaBlendOp = (int)alphaBlendOp;
this.colorWriteMask = colorWriteMask;
}
}
Expand All @@ -144,7 +144,7 @@ public VkPushConstantRange (VkShaderStageFlags stageFlags, uint size, uint offse
}
public partial struct VkCommandBufferBeginInfo {
public VkCommandBufferBeginInfo (VkCommandBufferUsageFlags usage = (VkCommandBufferUsageFlags)0) {
sType = VkStructureType.CommandBufferBeginInfo;
this._sType = (int)VkStructureType.CommandBufferBeginInfo;
pNext = pInheritanceInfo = IntPtr.Zero;
flags = usage;
}
Expand All @@ -162,33 +162,33 @@ public static VkQueryPoolCreateInfo New (VkQueryType queryType,
}
public partial struct VkDebugMarkerObjectNameInfoEXT {
public VkDebugMarkerObjectNameInfoEXT (VkDebugReportObjectTypeEXT objectType, ulong handle) {
sType = VkStructureType.DebugMarkerObjectNameInfoEXT;
this._sType = (int)VkStructureType.DebugMarkerObjectNameInfoEXT;
pNext = IntPtr.Zero;
this.objectType = objectType;
this._objectType = (int)objectType;
_object = handle;
pObjectName = IntPtr.Zero;
}
}
public partial struct VkDebugUtilsObjectNameInfoEXT {
public VkDebugUtilsObjectNameInfoEXT(VkObjectType objectType, ulong handle)
{
sType = VkStructureType.DebugUtilsObjectNameInfoEXT;
this._sType = (int)VkStructureType.DebugUtilsObjectNameInfoEXT;
pNext = IntPtr.Zero;
this.objectType = objectType;
this._objectType = (int)objectType;
objectHandle = handle;
pObjectName = IntPtr.Zero;
}
}
public partial struct VkDescriptorPoolSize {
public VkDescriptorPoolSize (VkDescriptorType descriptorType, uint count = 1) {
type = descriptorType;
this._type = (int)descriptorType;
descriptorCount = count;
}
}
public unsafe partial struct VkAttachmentReference {
public VkAttachmentReference (uint attachment, VkImageLayout layout) {
this.attachment = attachment;
this.layout = layout;
this._layout = (int)layout;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions VK/vulkan.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>

<AssemblyVersion>0.2.0</AssemblyVersion>
<AssemblyVersion>0.2.1</AssemblyVersion>
<AssemblyName>VK</AssemblyName>
<Description>Low level vulkan bindings for .net</Description>
<Product>VK</Product>
Expand Down Expand Up @@ -60,4 +60,4 @@
</Exec>
</Target>

</Project>
</Project>
4 changes: 1 addition & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ image:
- Visual Studio 2019
- Ubuntu


build:
verbosity: minimal

Expand Down Expand Up @@ -35,8 +34,7 @@ for:
- wget -qO - http://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo apt-key add -
- sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-bionic.list https://packages.lunarg.com/vulkan/lunarg-vulkan-bionic.list
- sudo apt -qq update
- sudo apt -y install vulkan-sdk
- glslc --version
- sudo apt -y install vulkan-sdk
build_script:
- dotnet build /p:Configuration=Release

21 changes: 18 additions & 3 deletions vk.generator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,24 @@ static void gen_struct (IndentedTextWriter tw, StructDef sd) {
tw.WriteLine ($"/// <summary> {mb.comment} </summary>");

string typeStr;

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
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;

if (sd.category == TypeCategories.union)
Expand Down Expand Up @@ -1130,8 +1145,8 @@ public static void readFeature (XmlNode nFeat) {
} else if (f.Name == "remove") {
Console.ForegroundColor = ConsoleColor.DarkBlue;
Console.WriteLine ($"feature remove: {f.OuterXml}");
} else
Debugger.Break ();
}// else
//Debugger.Break ();
}

features.Add (fd);
Expand Down

0 comments on commit 378953c

Please sign in to comment.