]> O.S.I.I.S - jp/vke.net.git/commitdiff
vk.net default_ctor_stype_structs ok, no leak, vk.net commit=db77286
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 6 Dec 2021 19:43:53 +0000 (20:43 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 6 Dec 2021 19:43:53 +0000 (20:43 +0100)
13 files changed:
samples/ClearScreen/main.cs
samples/common/SampleBase.cs
vke/src/ExtensionMethods.cs
vke/src/ShaderInfo.cs
vke/src/base/Device.cs
vke/src/base/Fence.cs
vke/src/base/Image.cs
vke/src/base/Instance.cs
vke/src/base/PhysicalDevice.cs
vke/src/base/Queue.cs
vke/src/base/RenderPass.cs
vke/src/base/SubPass.cs
vke/src/base/SwapChain.cs

index caf5cbc14aeda66e80189a0bbb0ce0c330bc4365..f5edebd33a89e20adc4908e416bfc34fc19f8b20 100644 (file)
@@ -1,6 +1,7 @@
 // Copyright (c) 2019  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
 // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+using System;
 using vke;
 using Vulkan;
 
@@ -24,7 +25,6 @@ namespace ClearScreen {
                //bound to it, and a draw and present semaphore to sync the rendering.
                protected override void initVulkan () {
                        base.initVulkan ();
-
                        //there are several method to clear the screen with vulkan. One is to
                        //use the renderpass CLEAR load operation so that attachment layout transitioning
                        //is handled automatically by the render pass.
index 2104a6984682beab6af65f2ee1cc7fea5e7b778f..959d8215cd2b19cc605104efb17edc22d5f49dfb 100644 (file)
@@ -6,7 +6,7 @@ namespace vke
        public abstract class SampleBase : VkWindow {
                public SampleBase (string name = "VkWindow", uint _width = 800, uint _height = 600, bool vSync = false) :
                        base (name, _width, _height, vSync){}
-               protected override void initVulkan()
+               /*protected override void initVulkan()
                {
                        base.initVulkan();
 #if DEBUG
@@ -16,6 +16,6 @@ namespace vke
                                Console.ResetColor ();
                        }
 #endif
-               }
+               }*/
        }
 }
index 972932f34f7f7b70c17b3dc2ba0266c0a1a169d7..6c94a664279567f31d792c14548414429e92790a 100644 (file)
@@ -87,7 +87,7 @@ namespace vke {
                #region shaderc
 
 
-               public static ShaderInfo CreateShaderInfo (this shaderc.Compiler comp, Device dev, string shaderPath, shaderc.ShaderKind shaderKind,
+               /*public static ShaderInfo CreateShaderInfo (this shaderc.Compiler comp, Device dev, string shaderPath, shaderc.ShaderKind shaderKind,
                        SpecializationInfo specializationInfo = null, string entryPoint = "main") {
 
                        using (shaderc.Result res = comp.Compile (shaderPath, shaderKind)) {
@@ -96,7 +96,7 @@ namespace vke {
                                VkShaderStageFlags stageFlags = Utils.ShaderKindToStageFlag (shaderKind);
                                return new ShaderInfo (dev, stageFlags, res.CodePointer, (UIntPtr)res.CodeLength, specializationInfo, entryPoint);
                        }
-               }
+               }*/
                #endregion
 
                #region temp
index 9e12500a5d801c13718fe44f0a3165a7638bb731..c3fcea1cf4cd5d874a53ab20720271f840e2bee7 100644 (file)
@@ -15,7 +15,7 @@ namespace vke {
                public VkShaderStageFlags Stage => info.stage;
                public VkPipelineShaderStageCreateInfo Info => info;
 
-               public void RecreateModule(IntPtr code, UIntPtr codeSize) {
+               public void RecreateModule(uint[] code, UIntPtr codeSize) {
                        if (dev == null)
                                throw new Exception ("[ShaderInfo]Trying to recreate unowned shader module.");
                        dev.DestroyShaderModule (info.module);
@@ -32,7 +32,7 @@ namespace vke {
                /// <param name="codeSize">Code size in byte</param>
                /// <param name="specializationInfo">Specialization info.</param>
                /// <param name="entryPoint">shader entry point</param>
-               public ShaderInfo (Device dev, VkShaderStageFlags stageFlags, IntPtr code, UIntPtr codeSize, SpecializationInfo specializationInfo = null, string entryPoint = "main"):
+               public ShaderInfo (Device dev, VkShaderStageFlags stageFlags, uint[] code, UIntPtr codeSize, SpecializationInfo specializationInfo = null, string entryPoint = "main"):
                        this(stageFlags, dev.CreateShaderModule (code, codeSize), specializationInfo, entryPoint) {
                        this.dev = dev;//keep dev for destroying module created in this CTOR
                }
@@ -72,6 +72,7 @@ namespace vke {
                                        System.Diagnostics.Debug.WriteLine ("VKE ShaderInfo disposed by finalizer");
 
                                dev?.DestroyShaderModule (info.module);
+                               info.Dispose();
 
                                disposedValue = true;
                        }
index 4288cc17285126c0cf9a67302006473b76c9676a..cd471463db72ee2815cf7c8562947bec703c71b1 100644 (file)
@@ -6,6 +6,7 @@ using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Reflection;
+using System.Runtime.InteropServices;
 using Vulkan;
 using static Vulkan.Vk;
 
@@ -38,7 +39,6 @@ namespace vke {
 
                public void Activate (VkPhysicalDeviceFeatures enabledFeatures, params string[] extensions) {
                        List<VkDeviceQueueCreateInfo> qInfos = new List<VkDeviceQueueCreateInfo> ();
-                       List<List<float>> prioritiesLists = new List<List<float>> ();//store pinned lists for later unpin
 
                        foreach (IGrouping<uint, Queue> qfams in queues.GroupBy (q => q.qFamIndex)) {
                                int qTot = qfams.Count ();
@@ -60,9 +60,8 @@ namespace vke {
                                        sType = VkStructureType.DeviceQueueCreateInfo,
                                        queueCount = qCountReached ? phy.QueueFamilies[qfams.Key].queueCount : qIndex,
                                        queueFamilyIndex = qfams.Key,
-                                       pQueuePriorities = priorities.Pin ()
+                                       pQueuePriorities = priorities
                                });
-                               prioritiesLists.Add (priorities);//add for unpined
                        }
 
                        //enable only supported exceptions
@@ -86,9 +85,8 @@ namespace vke {
                        Utils.CheckResult (vkCreateDevice (phy.Handle, ref deviceCreateInfo, IntPtr.Zero, out dev));
 
                        deviceCreateInfo.Dispose();
-
-                       foreach (List<float> fa in prioritiesLists)
-                               fa.Unpin ();
+                       foreach (VkDeviceQueueCreateInfo qI in qInfos)
+                               qI.Dispose();
 
                        if (deviceExtensions.Count > 0)
                                deviceExtensions.Unpin ();
@@ -169,7 +167,7 @@ namespace vke {
                        // Iterate over all memory types available for the Device used in this example
                        for (uint i = 0; i < phy.memoryProperties.memoryTypeCount; i++) {
                                if ((typeBits & 1) == 1) {
-                                       if ((phy.memoryProperties.memoryTypes[i].propertyFlags & properties) == properties) {
+                                       if ((phy.memoryProperties.memoryTypes.AsSpan[(int)i].propertyFlags & properties) == properties) {
                                                return i;
                                        }
                                }
@@ -197,8 +195,8 @@ namespace vke {
                                using (BinaryReader br = new BinaryReader (stream)) {
                                        byte[] shaderCode = br.ReadBytes ((int)stream.Length);
                                        UIntPtr shaderSize = (UIntPtr)shaderCode.Length;
-                                       VkShaderModule shaderModule = CreateShaderModule (shaderCode.Pin (), shaderSize);
-                                       shaderCode.Unpin ();
+                                       Span<uint> tmp = MemoryMarshal.Cast<byte, uint> (shaderCode);
+                                       VkShaderModule shaderModule = CreateShaderModule (tmp.ToArray(), shaderSize);
                                        return shaderModule;
                                }
                        }
@@ -209,11 +207,12 @@ namespace vke {
                /// <param name="code">unmanaged pointer holding the spirv code. Pointer must stay valid only during
                /// the call to this method.</param>
                /// <param name="codeSize">spirv code byte size.</param>
-               public VkShaderModule CreateShaderModule (IntPtr code, UIntPtr codeSize) {
+               public VkShaderModule CreateShaderModule (uint[] code, UIntPtr codeSize) {
                        VkShaderModuleCreateInfo moduleCreateInfo = VkShaderModuleCreateInfo.New ();
                        moduleCreateInfo.codeSize = codeSize;
                        moduleCreateInfo.pCode = code;
-                       Utils.CheckResult (vkCreateShaderModule (VkDev, ref moduleCreateInfo, IntPtr.Zero, out VkShaderModule shaderModule));
+                       Utils.CheckResult (vkCreateShaderModule (Handle, ref moduleCreateInfo, IntPtr.Zero, out VkShaderModule shaderModule));
+                       moduleCreateInfo.Dispose();
                        return shaderModule;
                }
 
index 80c5a9cdea3e1514da8e023a6f777d7a64d4d6b7..ab044046f856cc2575d70bc419e03656dfa2a0a5 100644 (file)
@@ -18,7 +18,7 @@ namespace vke {
                public Fence (Device dev, bool signaled = false, string name = "fence") : base (dev, name) {
                        info.flags = signaled ? VkFenceCreateFlags.Signaled : 0;
                        Activate ();
-               }       
+               }
 
                protected override VkDebugUtilsObjectNameInfoEXT DebugUtilsInfo
                        => new VkDebugUtilsObjectNameInfoEXT (VkObjectType.Fence, handle.Handle);
index 7e41054d10a72e3bf88c8b7df2faed68ad8f1191..821053a902f6a58a08dd5d60309cede34babf1e3 100644 (file)
@@ -451,9 +451,8 @@ namespace vke {
 
                                if (info.sharingMode == VkSharingMode.Concurrent && queuesFamillies?.Length > 0) {
                                        info.queueFamilyIndexCount = (uint)queuesFamillies.Length;
-                                       info.pQueueFamilyIndices = queuesFamillies.Pin ();
+                                       info.pQueueFamilyIndices = queuesFamillies;
                                        Utils.CheckResult (vkCreateImage (Dev.Handle, ref info, IntPtr.Zero, out handle));
-                                       queuesFamillies.Unpin ();
                                } else
                                        Utils.CheckResult (vkCreateImage (Dev.Handle, ref info, IntPtr.Zero, out handle));
 
index 57611e54e7e1f3dedca51af74949abf2b51524d1..de1fe5b7144ded69a56a6c485e93075aaa07bcc7 100644 (file)
@@ -101,6 +101,9 @@ namespace vke {
                                if (result != VkResult.Success)
                                        throw new InvalidOperationException ("Could not create Vulkan instance. Error: " + result);
 
+                               instanceCreateInfo.Dispose();
+                               appInfo.Dispose();
+
                                Vk.LoadInstanceFunctionPointers (inst);
                        }
                }
index 57a50b0bea60caeb6800b23e9c1844b8d8eee6cc..1ab1d486df8323524044a57d86cfd556bf61423d 100644 (file)
@@ -77,6 +77,7 @@ namespace vke {
                        // Gather physical Device memory properties
                        IntPtr tmp = Marshal.AllocHGlobal (Marshal.SizeOf<VkPhysicalDeviceMemoryProperties> ());
                        vkGetPhysicalDeviceMemoryProperties (phy, tmp);
+
                        memoryProperties = Marshal.PtrToStructure<VkPhysicalDeviceMemoryProperties> (tmp);
                        Marshal.FreeHGlobal (tmp);
 
@@ -88,6 +89,7 @@ namespace vke {
 
                        vkGetPhysicalDeviceQueueFamilyProperties (phy, out queueFamilyCount, QueueFamilies.Pin ());
                        QueueFamilies.Unpin ();
+                       Console.WriteLine("PhysicalDeviceCollection");
 
                        HasSwapChainSupport = GetDeviceExtensionSupported (Ext.D.VK_KHR_swapchain);
                }
index e1f25620de5ef84b99d0c4790e058733d1d5f1c0..13fa8c509bccc6fd62364950ca63f4674bf3cf05 100644 (file)
@@ -44,13 +44,11 @@ namespace vke {
                        uint idx = swapChain.currentImageIndex;
                        VkSwapchainKHR sc = swapChain.Handle;
                        present.pSwapchains = sc;
-                       present.pImageIndices = idx.Pin();
+                       present.pImageIndices = idx;
                        present.pWaitSemaphores = wait;
 
                        vkQueuePresentKHR (handle, ref present);
 
-                       idx.Unpin();
-
                        present.Dispose();
                }
        }
index cd1c975ccc643b3aee57647188951bb720b69156..ea9cda9b36dcb54045c2140b4152c4e8e871cb41 100644 (file)
@@ -117,6 +117,8 @@ namespace vke {
                                        PNext.ReleasePointer ();
 
                                renderPassInfo.Dispose ();
+                               foreach (VkSubpassDescription spd in spDescs)
+                                       spd.Dispose ();
                        }
                        base.Activate ();
                }
index 828e5a6bf7e4078431c7fe57f25c75b9de07ff4c..93cb275735943a3838c138d96230582036f7a73b 100644 (file)
@@ -60,7 +60,7 @@ namespace vke {
                     subpassDescription.pInputAttachments = inputRefs; ;
                 }
                 if (preservedRefs.Count > 0) {
-                    subpassDescription.pPreserveAttachments = preservedRefs.Pin (); ;
+                    subpassDescription.pPreserveAttachments = preservedRefs; ;
                 }
                                if (resolveRefs.Count > 0)
                                        subpassDescription.pResolveAttachments = resolveRefs;
index c07813db2f86382c653ff29093ebfeb9b9229585..d87e46177fe30303582eadcc5053439fbad22e1d 100644 (file)
@@ -99,7 +99,7 @@ namespace vke {
                /// </summary>
                public void Create () {
 
-                       Dev.WaitIdle ();                                                        
+                       Dev.WaitIdle ();
 
                        VkSurfaceCapabilitiesKHR capabilities = Dev.phy.GetSurfaceCapabilities (presentQueue.Surface);
 
@@ -128,7 +128,7 @@ namespace vke {
                        presentComplete = Dev.CreateSemaphore ();
                        presentComplete.SetDebugMarkerName (Dev, "Semaphore PresentComplete");
                        Handle = newSwapChain;
-                                                       
+
                        Utils.CheckResult (vkGetSwapchainImagesKHR (Dev.Handle, Handle, out uint imageCount, IntPtr.Zero));
                        if (imageCount == 0)
                                throw new Exception ("Swapchain image count is 0.");
@@ -175,7 +175,7 @@ namespace vke {
                        if (state == ActivableState.Activated) {
                                if (!disposing)
                                        System.Diagnostics.Debug.WriteLine ("VKE Swapchain disposed by finalizer");
-                               
+
                                _destroy ();
 
                        } else if (disposing)