From 8b336c944bb0caa5fa92b2f6429f18d5071c32d4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Sat, 20 Nov 2021 04:01:45 +0100 Subject: [PATCH] EnabledLayers[] overridable property in VkWindow, instance ctor with layers, phy.GetToolsProperty --- Directory.Build.props | 2 +- vke/src/VkWindow.cs | 7 ++++++- vke/src/base/Instance.cs | 27 ++++++++++++++++++++------- vke/src/base/PhysicalDevice.cs | 16 ++++++++++++++++ 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 8d90c98..a4f0fb4 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,7 +4,7 @@ $(SolutionDir)build\$(Configuration)\ 0.1.45 $(SpirVTasksReleaseVersion) - 0.2.3 + 0.2.4 $(VkeReleaseVersion)-beta true false diff --git a/vke/src/VkWindow.cs b/vke/src/VkWindow.cs index 2db417d..65dd3dd 100644 --- a/vke/src/VkWindow.cs +++ b/vke/src/VkWindow.cs @@ -52,6 +52,11 @@ namespace vke { uint frameCount; Stopwatch frameChrono; + /// + /// Override this property to change the list of enabled instance extensions + /// + public virtual string[] EnabledLayers => null; + /// /// Override this property to change the list of enabled instance extensions /// @@ -142,7 +147,7 @@ namespace vke { if (EnabledInstanceExtensions != null) instExts.AddRange (EnabledInstanceExtensions); - instance = new Instance (instExts.ToArray()); + instance = new Instance (EnabledLayers, instExts.ToArray()); hSurf = instance.CreateSurface (hWin); diff --git a/vke/src/base/Instance.cs b/vke/src/base/Instance.cs index b4fdc70..ec372b0 100644 --- a/vke/src/base/Instance.cs +++ b/vke/src/base/Instance.cs @@ -14,8 +14,10 @@ namespace vke { /// public class Instance : IDisposable { /// If true, the VK_LAYER_KHRONOS_validation layer is loaded at startup; + [Obsolete("use constructor with layers as 1st argument, vkWindow implement overridable `EnabledLayers`")] public static bool VALIDATION; /// If true, the VK_LAYER_RENDERDOC_Capture layer is loaded at startup; + [Obsolete("use constructor with layers as 1st argument, vkWindow implement overridable `EnabledLayers`")] public static bool RENDER_DOC_CAPTURE; public static uint VK_MAJOR = 1; @@ -42,7 +44,15 @@ namespace vke { /// Create a new vulkan instance with enabled extensions given as argument. /// /// List of extension to enable if supported - public Instance (params string[] extensions) { + public Instance (params string[] extensions) : this (null, extensions) {} + + /// + /// Create a new vulkan instance with enabled layers and extensions given as arguments. + /// + /// if not null, load layers in order, else use `VALIDATION` and `RENDER_DOC_CAPTURE` + /// static variables to enable corresponding extensions + /// List of extension to enable if supported + public Instance (string[] layers, params string[] extensions) { List instanceExtensions = new List (); List enabledLayerNames = new List (); @@ -58,12 +68,15 @@ namespace vke { Console.WriteLine ($"Vulkan initialisation: Unsupported extension: {extensions [i]}"); } - - if (VALIDATION) - enabledLayerNames.Add (strValidationLayer.Pin (pctx)); - if (RENDER_DOC_CAPTURE) - enabledLayerNames.Add (strRenderDocLayer.Pin (pctx)); - + if (layers != null) { + for (int i = 0; i < layers.Length; i++) + enabledLayerNames.Add (layers[i].Pin (pctx)); + } else { + if (VALIDATION) + enabledLayerNames.Add (strValidationLayer.Pin (pctx)); + if (RENDER_DOC_CAPTURE) + enabledLayerNames.Add (strRenderDocLayer.Pin (pctx)); + } VkApplicationInfo appInfo = new VkApplicationInfo () { sType = VkStructureType.ApplicationInfo, diff --git a/vke/src/base/PhysicalDevice.cs b/vke/src/base/PhysicalDevice.cs index 91645b4..aaf3ff2 100644 --- a/vke/src/base/PhysicalDevice.cs +++ b/vke/src/base/PhysicalDevice.cs @@ -157,5 +157,21 @@ namespace vke { vkGetPhysicalDeviceFormatProperties (phy, format, out VkFormatProperties properties); return properties; } + public VkPhysicalDeviceToolPropertiesEXT[] GetToolProperties () { + Utils.CheckResult (vkGetPhysicalDeviceToolPropertiesEXT (phy , out uint count, IntPtr.Zero)); + int sizeStruct = Marshal.SizeOf (); + IntPtr ptrTools = Marshal.AllocHGlobal (sizeStruct * (int)count); + Utils.CheckResult (vkGetPhysicalDeviceToolPropertiesEXT (phy , out count, ptrTools)); + + VkPhysicalDeviceToolPropertiesEXT[] result = new VkPhysicalDeviceToolPropertiesEXT[count]; + IntPtr tmp = ptrTools; + for (int i = 0; i < count; i++) { + result[i] = Marshal.PtrToStructure (tmp); + tmp += sizeStruct; + } + + Marshal.FreeHGlobal (ptrTools); + return result; + } } } -- 2.47.3