diff options
| -rw-r--r-- | samples/create_device/Program.cs | 41 | ||||
| -rw-r--r-- | samples/select_physical_dev/Program.cs | 8 | ||||
| -rw-r--r-- | vk.generator/Program.cs | 16 | ||||
| -rw-r--r-- | vulkan/PNext.cs | 46 | ||||
| -rw-r--r-- | vulkan/vulkan.csproj | 2 |
5 files changed, 100 insertions, 13 deletions
diff --git a/samples/create_device/Program.cs b/samples/create_device/Program.cs index 3daca81..b2c0f5a 100644 --- a/samples/create_device/Program.cs +++ b/samples/create_device/Program.cs @@ -3,34 +3,54 @@ using Vulkan; using static Vulkan.Vk; using static Vulkan.Utils; using System.Linq; +using System.Runtime.InteropServices; namespace tests -{ +{ class Program { static void Main(string[] args) { VkInstance inst; - using (VkApplicationInfo ai = new VkApplicationInfo ()) { - using (VkInstanceCreateInfo ci = new VkInstanceCreateInfo {pApplicationInfo = ai}){ - CheckResult (vkCreateInstance (ci, IntPtr.Zero, out inst)); + using (VkApplicationInfo ai = new VkApplicationInfo ( + new Vulkan.Version(1,2,0), + new Vulkan.Version(1,2,0), + new Vulkan.Version(1,3,0) + )) { + + using (PinnedObjects po = new PinnedObjects()) { + IntPtr[] instanceExts = {Ext.I.VK_KHR_get_physical_device_properties2.Pin(po)}; + IntPtr[] layers = {"VK_LAYER_KHRONOS_validation".Pin(po)}; + using (VkInstanceCreateInfo ci = new VkInstanceCreateInfo { + pApplicationInfo = ai, + enabledExtensionCount = 1, + enabledLayerCount = 1, + ppEnabledExtensionNames = instanceExts.Pin(po), + ppEnabledLayerNames = layers.Pin(po)}){ + CheckResult (vkCreateInstance (ci, IntPtr.Zero, out inst)); + } } } Vk.LoadInstanceFunctionPointers (inst); + CheckResult (vkEnumerateInstanceVersion(out uint apiVersion)); + + Console.WriteLine ($"Vulkan api version: {(Vulkan.Version)apiVersion})"); + + if (!TryGetPhysicalDevice (inst, VkPhysicalDeviceType.DiscreteGpu, out VkPhysicalDevice phy)) if (!TryGetPhysicalDevice (inst, VkPhysicalDeviceType.IntegratedGpu, out phy)) if (!TryGetPhysicalDevice (inst, VkPhysicalDeviceType.Cpu, out phy)) throw new Exception ("no suitable physical device found"); - foreach (VkPhysicalDeviceToolPropertiesEXT toolProp in GetToolProperties(phy)) { + foreach (VkPhysicalDeviceToolProperties toolProp in GetToolProperties(phy)) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine ($"Enabled Tool: {toolProp.name}({toolProp.version})"); Console.ResetColor (); } - + vkGetPhysicalDeviceQueueFamilyProperties (phy, out uint queueFamilyCount, IntPtr.Zero); VkQueueFamilyProperties[] qFamProps = new VkQueueFamilyProperties[queueFamilyCount]; vkGetPhysicalDeviceQueueFamilyProperties (phy, out queueFamilyCount, qFamProps.Pin()); @@ -42,6 +62,14 @@ namespace tests uint qFamIndex = (uint)qFamProps.Select((qFam, index) => (qFam, index)) .First (qfp=>qfp.qFam.queueFlags.HasFlag (VkQueueFlags.Graphics)).index; + + VkPhysicalDeviceProperties2 phyProps2 = VkPhysicalDeviceProperties2.New; + using (var vk11 = new PNext<VkPhysicalDeviceVulkan11Properties>()) { + phyProps2.pNext = vk11; + vkGetPhysicalDeviceProperties2(phy, ref phyProps2); + Console.WriteLine($"SupportedStages: {vk11.Val.subgroupSupportedStages}" ); + } + VkDevice dev = default; float[] priorities = {0}; using (VkDeviceQueueCreateInfo qInfo = new VkDeviceQueueCreateInfo (qFamIndex,1,priorities)) { @@ -51,6 +79,7 @@ namespace tests CheckResult (vkCreateDevice (phy, deviceCreateInfo, IntPtr.Zero, out dev)); } } + vkGetDeviceQueue (dev, qFamIndex, 0, out VkQueue gQ); vkDestroyDevice (dev, IntPtr.Zero); diff --git a/samples/select_physical_dev/Program.cs b/samples/select_physical_dev/Program.cs index e20193b..59ab23e 100644 --- a/samples/select_physical_dev/Program.cs +++ b/samples/select_physical_dev/Program.cs @@ -8,12 +8,16 @@ namespace tests { class Program { - + delegate void del(IntPtr phy, ref VkPhysicalDeviceFeatures2 vdf); + delegate void del2(IntPtr phy, IntPtr vdf); static void Main(string[] args) { VkInstance inst; - using (VkApplicationInfo ai = new VkApplicationInfo ()) { + using (VkApplicationInfo ai = new VkApplicationInfo ( + new Vulkan.Version(1,2,0), + new Vulkan.Version(1,2,0), + new Vulkan.Version(1,3,0))) { using (VkInstanceCreateInfo ci = new VkInstanceCreateInfo {pApplicationInfo = ai}){ CheckResult (vkCreateInstance (ci, IntPtr.Zero, out inst)); } diff --git a/vk.generator/Program.cs b/vk.generator/Program.cs index 3b2dba9..1d51b53 100644 --- a/vk.generator/Program.cs +++ b/vk.generator/Program.cs @@ -293,6 +293,7 @@ namespace vk.generator { class StructDef : TypeDef { public string structextends; public List<MemberDef> members = new List<MemberDef> (); + public override bool HasSType => category == TypeCategories.@struct && members.Any (mb => mb.Name == "sType"); public override bool tryGetSize(out int size) { size = 0; int alignment = 1; @@ -372,6 +373,7 @@ namespace vk.generator { } public bool IsValueType => csValueTypes.Contains (CSName); public bool IsEnum => category == TypeCategories.bitmask || category == TypeCategories.@enum; + public virtual bool HasSType => false; public string enumDefName => IsEnum ? requires == null ? bitvalues == null ? name : bitvalues : requires : null; public EnumDef enumDef { get { @@ -915,10 +917,10 @@ namespace vk.generator { mdSType.defaultValue == null ? null : structTypeEnum.AllValues.FirstOrDefault(st=>st.Name == mdSType.defaultValue); string csStructName = evSType == null ? null : $"{structTypeEnum.CSName}.{evSType.CSName}"; -#if AUTO_SET_STYPE +//#if AUTO_SET_STYPE if (csStructName!=null) tw.WriteLine ($"[StructureType ({evSType.value})]"); -#endif +//#endif getStructurePtrProxies (sd, out IEnumerable<string> ptrProxies, out IEnumerable<string> utf8StringPointers); @@ -928,6 +930,10 @@ namespace vk.generator { tw.WriteLine ($"public partial struct {sd.Name} : IDisposable {{"); tw.Indent++; + + /*if (csStructName != null) + tw.WriteLine ($"internal const int vkType = {evSType.value};");*/ + foreach (MemberDef mb in sd.members) { if (hasDoc) @@ -1396,7 +1402,7 @@ namespace vk.generator { string typeName = td.CSName; switch (md.paramDef.IndirectionLevel) { case 1: - return md.paramDef.IsConst ? + return md.paramDef.IsConst || td.HasSType ? string.Format ($"ref {typeName} {md.Name}{(isLast ? ", " : ")")}") : string.Format ($"out {typeName} {md.Name}{(isLast ? ", " : ")")}"); case 2: @@ -1414,7 +1420,9 @@ namespace vk.generator { case 1: return md.paramDef.IsConst ? string.Format ($"[Pin]{typeName} {md.Name}{(isLast ? ", " : ")")}") : - string.Format ($"out {typeName} {md.Name}{(isLast ? ", " : ")")}"); + td.HasSType ? + string.Format ($"ref {typeName} {md.Name}{(isLast ? ", " : ")")}") : + string.Format ($"out {typeName} {md.Name}{(isLast ? ", " : ")")}"); case 2: return md.paramDef.IsConst ? string.Format ($"[Pin]IntPtr {md.Name}{(isLast ? ", " : ")")}") : diff --git a/vulkan/PNext.cs b/vulkan/PNext.cs new file mode 100644 index 0000000..783e757 --- /dev/null +++ b/vulkan/PNext.cs @@ -0,0 +1,46 @@ +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +// +// Copyright (c) 2022 JP Bruyère +using System; +using System.Linq; +using System.Runtime.InteropServices; + +namespace Vulkan +{ + /// <summary> + /// Helper class to construct pnext chain + /// </summary> + public class PNext<T> : IDisposable where T : struct + { + IntPtr handle; + /// <summary> + /// Allocate on HGlobal a new structure of type T, ensure instance is Disposed. + /// </summary> + public PNext () { + init(); + } + /// <summary> + /// Allocate on HGlobal a new structure of type T and set the pNext field, + /// ensure instance is Disposed. + /// </summary> + public PNext (IntPtr pNext) { + init(); + Marshal.WriteIntPtr(handle + 4, pNext); + } + void init() { + handle = Marshal.AllocHGlobal(Marshal.SizeOf<T>()); + Type t = typeof(T); + StructureTypeAttribute st = (StructureTypeAttribute)t.GetCustomAttributes(typeof(StructureTypeAttribute), false).FirstOrDefault(); + Marshal.WriteInt32(handle, st.StructureType); + } + /// <summary> + /// Get value of T + /// </summary> + public T Val => Marshal.PtrToStructure<T> (handle); + public static implicit operator IntPtr(PNext<T> pn) => pn.handle; + public void Dispose() + { + Marshal.FreeHGlobal(handle); + } + } +} diff --git a/vulkan/vulkan.csproj b/vulkan/vulkan.csproj index f90c5cb..209502d 100644 --- a/vulkan/vulkan.csproj +++ b/vulkan/vulkan.csproj @@ -3,7 +3,7 @@ <PropertyGroup> <TargetFrameworks>netstandard2.1</TargetFrameworks> - <AssemblyVersion>0.4.2</AssemblyVersion> + <AssemblyVersion>0.5.0</AssemblyVersion> <AssemblyName>Vulkan</AssemblyName> <PackageVersion>$(AssemblyVersion)</PackageVersion> |