]> O.S.I.I.S - jp/vke.net.git/commitdiff
test vk.net ptr proxies
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 4 Dec 2021 19:52:08 +0000 (20:52 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 4 Dec 2021 19:52:08 +0000 (20:52 +0100)
15 files changed:
vke/src/ShaderInfo.cs
vke/src/SpecializationConstant.cs
vke/src/base/CommandBuffer.cs
vke/src/base/DescriptorPool.cs
vke/src/base/DescriptorSetWrites.cs
vke/src/base/Device.cs
vke/src/base/FrameBuffer.cs
vke/src/base/GraphicPipeline.cs
vke/src/base/GraphicPipelineConfig.cs
vke/src/base/Instance.cs
vke/src/base/PipelineLayout.cs
vke/src/base/Queue.cs
vke/src/base/RenderPass.cs
vke/src/base/SubPass.cs
vke/vke.csproj

index ba3c9c1e194ec030069f4e1954dce0ec420ca137..10291a18a09342c2d813ce6b3a479f464fca016a 100644 (file)
@@ -58,12 +58,11 @@ namespace vke {
                /// destroyed on Dispose.
                /// </summary>
                public ShaderInfo (VkShaderStageFlags stageFlags, VkShaderModule module, SpecializationInfo specializationInfo = null, string entryPoint = "main") {
-                       EntryPoint = new FixedUtf8String (entryPoint);
-
                        info.stage = stageFlags;
-                       info.pName = EntryPoint;
+                       info.pName = entryPoint;
                        info.module = module;
-                       info.pSpecializationInfo = (specializationInfo == null) ? IntPtr.Zero : specializationInfo.InfosPtr;
+                       if (specializationInfo != null)
+                               info.pSpecializationInfo =  specializationInfo.infos;
                }
 
                #region IDisposable Support
@@ -71,7 +70,7 @@ namespace vke {
 
                protected virtual void Dispose (bool disposing) {
                        if (!disposedValue) {
-                               if (disposing) 
+                               if (disposing)
                                        EntryPoint.Dispose ();
                                else
                                        System.Diagnostics.Debug.WriteLine ("VKE ShaderInfo disposed by finalizer");
index 66b1619ab7abd7ca1a1ab7c5129fddc844708f6e..a2a095ee8ba486a92122264828042fe2ffafdd5a 100644 (file)
@@ -51,9 +51,8 @@ namespace vke {
                IntPtr pData;
                VkSpecializationMapEntry[] entries;
 
-               VkSpecializationInfo infos;
+               public VkSpecializationInfo infos;
 
-               public IntPtr InfosPtr { get; private set; }
 
                #region CTOR
                public SpecializationInfo (params SpecializationConstant[] constants) {
@@ -73,17 +72,15 @@ namespace vke {
                        }
 
                        infos = new VkSpecializationInfo {
-                               mapEntryCount = (uint)constants.Length,
-                               pMapEntries = entries.Pin (),
+                               pMapEntries = entries,
                                pData = pData,
                                dataSize = (UIntPtr)totSize
                        };
-                       InfosPtr = infos.Pin ();
                }
                #endregion
 
                public void Dispose () {
-                       infos.Unpin ();
+                       infos.Dispose();
                        Marshal.FreeHGlobal (pData);
                        entries.Unpin ();
                }
index 0eef206aa6395f920a2454fe0522b3b1eec435c8..6c45cc0e3444c75bd5d00043d44b935ccbb9f062 100644 (file)
@@ -21,9 +21,9 @@ namespace vke {
                        inheri.queryFlags = queryFlags;
                        inheri.pipelineStatistics = statFlags;
                        VkCommandBufferBeginInfo cmdBufInfo = new VkCommandBufferBeginInfo (usage);
-                       cmdBufInfo.pInheritanceInfo = inheri.Pin ();
+                       cmdBufInfo.pInheritanceInfo = inheri;
                        Utils.CheckResult (vkBeginCommandBuffer (handle, ref cmdBufInfo));
-                       inheri.Unpin ();
+                       cmdBufInfo.Dispose();
                }
        }
        public class PrimaryCommandBuffer : CommandBuffer {
@@ -38,27 +38,15 @@ namespace vke {
                /// <param name="fence">Fence.</param>
                public void Submit (VkQueue queue, VkSemaphore wait = default, VkSemaphore signal = default, Fence fence = null) {
                        VkSubmitInfo submit_info = VkSubmitInfo.New ();
+                       submit_info.pWaitDstStageMask = VkPipelineStageFlags.ColorAttachmentOutput;
+                       if (signal != VkSemaphore.Null)
+                               submit_info.pSignalSemaphores = signal;
+                       if (wait != VkSemaphore.Null)
+                               submit_info.pWaitSemaphores = wait;
+                       submit_info.pCommandBuffers = handle;
 
-                       IntPtr dstStageMask = Marshal.AllocHGlobal (sizeof (uint));
-                       Marshal.WriteInt32 (dstStageMask, (int)VkPipelineStageFlags.ColorAttachmentOutput);
-
-                       using (PinnedObjects pctx = new PinnedObjects ()) {
-                               submit_info.pWaitDstStageMask = dstStageMask;
-                               if (signal != VkSemaphore.Null) {
-                                       submit_info.signalSemaphoreCount = 1;
-                                       submit_info.pSignalSemaphores = signal.Pin (pctx);
-                               }
-                               if (wait != VkSemaphore.Null) {
-                                       submit_info.waitSemaphoreCount = 1;
-                                       submit_info.pWaitSemaphores = wait.Pin (pctx);
-                               }
-
-                               submit_info.commandBufferCount = 1;
-                               submit_info.pCommandBuffers = handle.Pin (pctx);
-
-                               Utils.CheckResult (vkQueueSubmit (queue, 1, ref submit_info, fence));
-                       }
-                       Marshal.FreeHGlobal (dstStageMask);
+                       Utils.CheckResult (vkQueueSubmit (queue, 1, ref submit_info, fence));
+                       submit_info.Dispose();
                }
                /// <summary>
                /// Put the command buffer in the recording state.
index 4cbafd9ddc2b6716eea321a04df7db96922d8199..b832f6a28760ff4646cc537779337352b7bd2bad 100644 (file)
@@ -23,7 +23,7 @@ namespace vke {
                /// </summary>
                /// <param name="device">the logical device that create the pool.</param>
                /// <param name="maxSets">maximum number of descriptor sets that can be allocated from the pool</param>
-               public DescriptorPool (Device device, uint maxSets = 1) : base (device) {            
+               public DescriptorPool (Device device, uint maxSets = 1) : base (device) {
             MaxSets = maxSets;
         }
                /// <summary>
@@ -37,19 +37,18 @@ namespace vke {
 
                        PoolSizes.AddRange (poolSizes);
 
-            Activate ();            
+            Activate ();
         }
                #endregion
 
                public sealed override void Activate () {
-                       if (state != ActivableState.Activated) {            
+                       if (state != ActivableState.Activated) {
                                VkDescriptorPoolCreateInfo info = VkDescriptorPoolCreateInfo.New();
-                               info.poolSizeCount = (uint)PoolSizes.Count;
-                               info.pPoolSizes = PoolSizes.Pin ();
+                               info.pPoolSizes = PoolSizes;
                                info.maxSets = MaxSets;
 
                                Utils.CheckResult (vkCreateDescriptorPool (Dev.Handle, ref info, IntPtr.Zero, out handle));
-                               PoolSizes.Unpin ();
+                               info.Dispose();
                        }
                        base.Activate ();
                }
@@ -66,12 +65,11 @@ namespace vke {
         public void Allocate (DescriptorSet descriptorSet) {
             VkDescriptorSetAllocateInfo allocInfo = VkDescriptorSetAllocateInfo.New();
             allocInfo.descriptorPool = handle;
-            allocInfo.descriptorSetCount = (uint)descriptorSet.descriptorSetLayouts.Count;
-            allocInfo.pSetLayouts = descriptorSet.descriptorSetLayouts.Pin();
+            allocInfo.pSetLayouts = descriptorSet.descriptorSetLayouts;
 
             Utils.CheckResult (vkAllocateDescriptorSets (Dev.Handle, ref allocInfo, out descriptorSet.handle));
 
-                       descriptorSet.descriptorSetLayouts.Unpin ();
+                       allocInfo.Dispose();
         }
         public void FreeDescriptorSet (params DescriptorSet[] descriptorSets) {
             if (descriptorSets.Length == 1) {
index 604f7182a8d08cb655ca850fa4f23ef3bbd96517..59d7a408aebc9bffce92a54ba6387bbae3897f5b 100644 (file)
@@ -116,15 +116,14 @@ namespace vke {
                                                        descPtrArray.Add (descriptors[i].Pin (pinCtx));
                                                        i++;
                                                }
-                                               pDescriptors = descPtrArray.Pin (pinCtx);
                                        } else {
                                                pDescriptors = descriptors[i].Pin (pinCtx);
                                                i++;
                                        }
-                                       if (descriptors[firstDescriptor] is VkDescriptorBufferInfo)
+                                       /*if (descriptors[firstDescriptor] is VkDescriptorBufferInfo)
                                                wds.pBufferInfo = pDescriptors;
                                        else if (descriptors[firstDescriptor] is VkDescriptorImageInfo)
-                                               wds.pImageInfo = pDescriptors;
+                                               wds.pImageInfo = pDescriptors;*/
 
                                        WriteDescriptorSets[wdsPtr] = wds;
                                        wdsPtr++;
@@ -156,10 +155,11 @@ namespace vke {
                                                pDescriptors = descriptors[i].Pin (pinCtx);
                                                i++;
                                        }
+                                       /*
                                        if (descriptors[firstDescriptor] is VkDescriptorBufferInfo)
                                                wds.pBufferInfo = pDescriptors;
                                        else if (descriptors[firstDescriptor] is VkDescriptorImageInfo)
-                                               wds.pImageInfo = pDescriptors;
+                                               wds.pImageInfo = pDescriptors;*/
 
                                        WriteDescriptorSets[wdsPtr] = wds;
                                        wdsPtr++;
@@ -190,7 +190,7 @@ namespace vke {
             wds.descriptorCount = binding.descriptorCount;
             wds.dstBinding = binding.binding;
             wds.dstSet = destSet.handle;
-            wds.pBufferInfo = descriptor.Pin ();
+            wds.pBufferInfo = descriptor;
 
                        WriteDescriptorSets.Add (wds);
         }
@@ -202,7 +202,7 @@ namespace vke {
             wds.descriptorCount = binding.descriptorCount;
             wds.dstBinding = binding.binding;
             wds.dstSet = destSet.handle;
-            wds.pImageInfo = descriptor.Pin ();
+            wds.pImageInfo = descriptor;
 
             WriteDescriptorSets.Add (wds);
         }
index cb96241227fba0c81a2c2cd5a82491823f7c43ab..4288cc17285126c0cf9a67302006473b76c9676a 100644 (file)
@@ -75,9 +75,8 @@ namespace vke {
                        }
 
                        VkDeviceCreateInfo deviceCreateInfo = VkDeviceCreateInfo.New ();
-                       deviceCreateInfo.queueCreateInfoCount = (uint)qInfos.Count;
-                       deviceCreateInfo.pQueueCreateInfos = qInfos.Pin ();
-                       deviceCreateInfo.pEnabledFeatures = enabledFeatures.Pin ();
+                       deviceCreateInfo.pQueueCreateInfos = qInfos;
+                       deviceCreateInfo.pEnabledFeatures = enabledFeatures;
 
                        if (deviceExtensions.Count > 0) {
                                deviceCreateInfo.enabledExtensionCount = (uint)deviceExtensions.Count;
@@ -85,8 +84,9 @@ namespace vke {
                        }
 
                        Utils.CheckResult (vkCreateDevice (phy.Handle, ref deviceCreateInfo, IntPtr.Zero, out dev));
-                       qInfos.Unpin ();
-                       enabledFeatures.Unpin ();
+
+                       deviceCreateInfo.Dispose();
+
                        foreach (List<float> fa in prioritiesLists)
                                fa.Unpin ();
 
index 5885024d4f470a3cfde49ac25cf11befa9e48147..5cb9332dd345ed7a6c656ada1ab01ceae2dba71c 100644 (file)
@@ -87,15 +87,15 @@ namespace vke {
                public sealed override void Activate () {
                        if (state != ActivableState.Activated) {
                                VkImageView[] views = attachments.Select (a => a.Descriptor.imageView).ToArray ();
-                               createInfo.attachmentCount = (uint)views.Length;
-                               createInfo.pAttachments = views.Pin ();
+                               createInfo.pAttachments = views;
 
                                if (PNext != null)
                                        createInfo.pNext = PNext.GetPointer();
 
                                Utils.CheckResult (vkCreateFramebuffer (renderPass.Dev.Handle, ref createInfo, IntPtr.Zero, out handle));
 
-                               views.Unpin ();
+                               createInfo.Dispose();
+
                                if (PNext != null)
                                        PNext.ReleasePointer ();
 
index dc68c3db88c9aed8f2587687e149ea2809cfdd20..88c5fc7e63c08e1400c84fbd5b6af61d4ad7352d 100644 (file)
@@ -57,54 +57,49 @@ namespace vke {
                                        colorBlendInfo.logicOpEnable = cfg.ColorBlendLogicOpEnable;
                                        colorBlendInfo.logicOp = cfg.ColorBlendLogicOp;
                                        colorBlendInfo.blendConstants = cfg.ColorBlendConstants;
-                                       colorBlendInfo.attachmentCount = (uint)cfg.blendAttachments.Count;
-                                       colorBlendInfo.pAttachments = cfg.blendAttachments.Pin (pctx);
+                                       colorBlendInfo.pAttachments = cfg.blendAttachments;
 
                                        VkPipelineDynamicStateCreateInfo dynStatesInfo = VkPipelineDynamicStateCreateInfo.New ();
-                                       dynStatesInfo.dynamicStateCount = (uint)cfg.dynamicStates.Count;
-                                       dynStatesInfo.pDynamicStates = cfg.dynamicStates.Cast<int> ().ToArray ().Pin (pctx);
+                                       dynStatesInfo.pDynamicStates = cfg.dynamicStates;
 
                                        VkPipelineVertexInputStateCreateInfo vertInputInfo = VkPipelineVertexInputStateCreateInfo.New ();
-                                       vertInputInfo.vertexBindingDescriptionCount = (uint)cfg.vertexBindings.Count;
-                                       vertInputInfo.pVertexBindingDescriptions = cfg.vertexBindings.Pin (pctx);
-                                       vertInputInfo.vertexAttributeDescriptionCount = (uint)cfg.vertexAttributes.Count;
-                                       vertInputInfo.pVertexAttributeDescriptions = cfg.vertexAttributes.Pin (pctx);
+                                       vertInputInfo.pVertexBindingDescriptions = cfg.vertexBindings;
+                                       vertInputInfo.pVertexAttributeDescriptions = cfg.vertexAttributes;
 
                                        VkPipelineViewportStateCreateInfo viewportState = VkPipelineViewportStateCreateInfo.New ();
                                        if (cfg.Viewports.Count > 0) {
-                                               viewportState.viewportCount = (uint)cfg.Viewports.Count;
-                                               viewportState.pViewports = cfg.Viewports.Pin (pctx);
+                                               viewportState.pViewports = cfg.Viewports;
                                        } else
                                                viewportState.viewportCount = 1;
 
                                        if (cfg.Scissors.Count > 0) {
-                                               viewportState.scissorCount = (uint)cfg.Scissors.Count;
-                                               viewportState.pScissors = cfg.Scissors.Pin (pctx);
+                                               viewportState.pScissors = cfg.Scissors;
                                        } else
                                                viewportState.scissorCount = 1;
 
                                        VkGraphicsPipelineCreateInfo info = VkGraphicsPipelineCreateInfo.New ();
                                        info.renderPass = RenderPass.handle;
                                        info.layout = Layout.handle;
-                                       info.pVertexInputState = vertInputInfo.Pin (pctx);
-                                       info.pInputAssemblyState = cfg.inputAssemblyState.Pin (pctx);
-                                       info.pRasterizationState = cfg.rasterizationState.Pin (pctx);
-                                       info.pColorBlendState = colorBlendInfo.Pin (pctx);
-                                       info.pMultisampleState = cfg.multisampleState.Pin (pctx);
-                                       info.pViewportState = viewportState.Pin (pctx);
-                                       info.pDepthStencilState = cfg.depthStencilState.Pin (pctx);
-                                       info.pDynamicState = dynStatesInfo.Pin (pctx);
-                                       info.stageCount = (uint)cfg.Shaders.Count;
-                                       info.pStages = shaderStages.Pin (pctx);
+                                       info.pVertexInputState = vertInputInfo;
+                                       info.pInputAssemblyState = cfg.inputAssemblyState;
+                                       info.pRasterizationState = cfg.rasterizationState;
+                                       info.pColorBlendState = colorBlendInfo;
+                                       info.pMultisampleState = cfg.multisampleState;
+                                       info.pViewportState = viewportState;
+                                       info.pDepthStencilState = cfg.depthStencilState;
+                                       info.pDynamicState = dynStatesInfo;
+                                       info.pStages = shaderStages;
                                        info.subpass = cfg.SubpassIndex;
 
                                        if (enableTesselation) {
                                                VkPipelineTessellationStateCreateInfo tessellationInfo = VkPipelineTessellationStateCreateInfo.New();
                                                tessellationInfo.patchControlPoints = cfg.TessellationPatchControlPoints;
-                                               info.pTessellationState = tessellationInfo.Pin (pctx);
+                                               info.pTessellationState = tessellationInfo;
                                        }
 
                                        Utils.CheckResult (vkCreateGraphicsPipelines (Dev.Handle, Cache == null ? VkPipelineCache.Null : Cache.handle, 1, ref info, IntPtr.Zero, out handle));
+
+                                       info.Dispose ();
                                }
                        }
                        base.Activate ();
index 1269f5c80470bec8b96f0cd96e9424359ad0fd3a..97be93be3726e6bf695878b913921a9dce60beea 100644 (file)
@@ -37,21 +37,21 @@ namespace vke {
                public VkPipelineBindPoint bindPoint = VkPipelineBindPoint.Graphics;
                public VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = VkPipelineInputAssemblyStateCreateInfo.New ();
                public VkPipelineRasterizationStateCreateInfo rasterizationState = VkPipelineRasterizationStateCreateInfo.New ();
-               public IList<VkViewport> Viewports = new List<VkViewport> ();
-               public IList<VkRect2D> Scissors = new List<VkRect2D> ();
+               public List<VkViewport> Viewports = new List<VkViewport> ();
+               public List<VkRect2D> Scissors = new List<VkRect2D> ();
                public VkPipelineDepthStencilStateCreateInfo depthStencilState = VkPipelineDepthStencilStateCreateInfo.New ();
                public VkPipelineMultisampleStateCreateInfo multisampleState = VkPipelineMultisampleStateCreateInfo.New ();
-               public IList<VkPipelineColorBlendAttachmentState> blendAttachments = new List<VkPipelineColorBlendAttachmentState> ();
-               public IList<VkDynamicState> dynamicStates = new List<VkDynamicState> ();
-               public IList<VkVertexInputBindingDescription> vertexBindings = new List<VkVertexInputBindingDescription> ();
-               public IList<VkVertexInputAttributeDescription> vertexAttributes = new List<VkVertexInputAttributeDescription> ();
+               public List<VkPipelineColorBlendAttachmentState> blendAttachments = new List<VkPipelineColorBlendAttachmentState> ();
+               public List<VkDynamicState> dynamicStates = new List<VkDynamicState> ();
+               public List<VkVertexInputBindingDescription> vertexBindings = new List<VkVertexInputBindingDescription> ();
+               public List<VkVertexInputAttributeDescription> vertexAttributes = new List<VkVertexInputAttributeDescription> ();
                /// <summary>
                /// List of ShaderInfo's used to in this pipeline configuration. Those shaders have to be Disposed
                /// after pipeline creation from this configuration. The 'DisposeShaders' helper method with clear the list.
                /// To replace a single shader between two use of this configuration object to create two different pipelines, use
                /// the 'ReplaceShader' helper method to automatically dispose the replace shader.
                /// </summary>
-               public IList<ShaderInfo> Shaders = new List<ShaderInfo> ();
+               public List<ShaderInfo> Shaders = new List<ShaderInfo> ();
                public VkBool32 ColorBlendLogicOpEnable = false;
                public VkLogicOp ColorBlendLogicOp;
                public Vector4 ColorBlendConstants;
index 430196370f83782114ba1fc03706bc2f5d7fcad0..420aca404e52e91704c0abeb9ad227dc05c2580b 100644 (file)
@@ -86,7 +86,7 @@ namespace vke {
                                };
 
                                VkInstanceCreateInfo instanceCreateInfo = VkInstanceCreateInfo.New ();
-                               instanceCreateInfo.pApplicationInfo = appInfo.Pin (pctx);
+                               instanceCreateInfo.pApplicationInfo = appInfo;
 
                                if (instanceExtensions.Count > 0) {
                                        instanceCreateInfo.enabledExtensionCount = (uint)instanceExtensions.Count;
index 206a0efc536c049d75d00e804a53b8d1fd677915..42a0975561cbdf28743f24c34083053c7975ec12 100644 (file)
@@ -20,7 +20,7 @@ namespace vke {
 
                #region CTORS
                public PipelineLayout (Device device) : base (device) { }
-               public PipelineLayout (Device device, VkPushConstantRange pushConstantRange, params DescriptorSetLayout[] descriptorSetLayouts) 
+               public PipelineLayout (Device device, VkPushConstantRange pushConstantRange, params DescriptorSetLayout[] descriptorSetLayouts)
                : this (device, descriptorSetLayouts) {
                        PushConstantRanges.Add (pushConstantRange);
                }
@@ -31,38 +31,34 @@ namespace vke {
                }
                public PipelineLayout (Device device, params DescriptorSetLayout[] descriptorSetLayouts)
                        :this (device) {
-            
+
                        if (descriptorSetLayouts.Length > 0)
                                DescriptorSetLayouts.AddRange (descriptorSetLayouts);
         }
                #endregion
 
-               public void AddPushConstants (params VkPushConstantRange[] pushConstantRanges) { 
+               public void AddPushConstants (params VkPushConstantRange[] pushConstantRanges) {
                        foreach (VkPushConstantRange pcr in pushConstantRanges)
                                PushConstantRanges.Add (pcr);
                }
 
                public override void Activate () {
                        if (state != ActivableState.Activated) {
-                               foreach (DescriptorSetLayout dsl in DescriptorSetLayouts) 
+                               foreach (DescriptorSetLayout dsl in DescriptorSetLayouts)
                                        dsl.Activate ();
                                VkPipelineLayoutCreateInfo info = VkPipelineLayoutCreateInfo.New();
                                VkDescriptorSetLayout[] dsls = DescriptorSetLayouts.Select (dsl => dsl.handle).ToArray ();
 
                                if (dsls.Length > 0) {
-                                       info.setLayoutCount = (uint)dsls.Length;
-                                       info.pSetLayouts = dsls.Pin ();
+                                       info.pSetLayouts = dsls;
                                }
                                if (PushConstantRanges.Count > 0) {
-                                       info.pushConstantRangeCount = (uint)PushConstantRanges.Count;
-                                       info.pPushConstantRanges = PushConstantRanges.Pin();
+                                       info.pPushConstantRanges = PushConstantRanges;
                                }
                                Utils.CheckResult (vkCreatePipelineLayout (Dev.Handle, ref info, IntPtr.Zero, out handle));
 
-                               if (dsls.Length > 0)
-                                       dsls.Unpin ();
-                               if (PushConstantRanges.Count > 0)
-                                       PushConstantRanges.Unpin ();
+                               info.Dispose();
+
                        }
                        base.Activate ();
                }
@@ -75,8 +71,8 @@ namespace vke {
                protected override void Dispose (bool disposing) {
                        if (state == ActivableState.Activated) {
                                if (disposing) {
-                                       foreach (DescriptorSetLayout dsl in DescriptorSetLayouts) 
-                                               dsl.Dispose ();                                 
+                                       foreach (DescriptorSetLayout dsl in DescriptorSetLayouts)
+                                               dsl.Dispose ();
                                } else
                                        System.Diagnostics.Debug.WriteLine ("VKE Activable PipelineLayout disposed by finalizer");
 
index bdcab881e3cfec9b3a5a480ac09db4a705864b89..fd4bbaaa8d97243cdf7e4fdab504db2be33cc056 100644 (file)
@@ -8,77 +8,72 @@ using static Vulkan.Vk;
 
 namespace vke {
 
-    public class PresentQueue : Queue {
-        public readonly VkSurfaceKHR Surface;
-
-        public PresentQueue (Device _dev, VkQueueFlags requestedFlags, VkSurfaceKHR _surface, float _priority = 0.0f) {
-            dev = _dev;
-            priority = _priority;
-            Surface = _surface;
-
-            qFamIndex = searchQFamily (requestedFlags);
-            dev.queues.Add (this);
-        }
-
-        uint searchQFamily (VkQueueFlags requestedFlags) {
-            //search for dedicated Q
-            for (uint i = 0; i < dev.phy.QueueFamilies.Length; i++) {
-                if (dev.phy.QueueFamilies[i].queueFlags == requestedFlags && dev.phy.GetPresentIsSupported (i, Surface))
-                    return i;
-            }
-            //search Q having flags
-            for (uint i = 0; i < dev.phy.QueueFamilies.Length; i++) {
-                if ((dev.phy.QueueFamilies[i].queueFlags & requestedFlags) == requestedFlags && dev.phy.GetPresentIsSupported (i, Surface))
-                    return i;
-            }
-
-            throw new Exception (string.Format ("No Queue with flags {0} found", requestedFlags));
-        }
-
-        public void Present (VkPresentInfoKHR present) {
-            Utils.CheckResult (vkQueuePresentKHR (handle, ref present));
-        }
-        public void Present (SwapChain swapChain, VkSemaphore wait) {
-            VkPresentInfoKHR present = VkPresentInfoKHR.New();
-
-            uint idx = swapChain.currentImageIndex;
-            VkSwapchainKHR sc = swapChain.Handle;
-            present.swapchainCount = 1;
-            present.pSwapchains = sc.Pin();
-            present.waitSemaphoreCount = 1;
-            present.pWaitSemaphores = wait.Pin();
-            present.pImageIndices = idx.Pin();
-
-            vkQueuePresentKHR (handle, ref present);
-
-                       sc.Unpin ();
-                       wait.Unpin ();
-                       idx.Unpin ();
-        }
-    }
-
-    public class Queue {
-
-        protected VkQueue handle;
-        internal Device dev;
+       public class PresentQueue : Queue {
+               public readonly VkSurfaceKHR Surface;
+
+               public PresentQueue (Device _dev, VkQueueFlags requestedFlags, VkSurfaceKHR _surface, float _priority = 0.0f) {
+                       dev = _dev;
+                       priority = _priority;
+                       Surface = _surface;
+
+                       qFamIndex = searchQFamily (requestedFlags);
+                       dev.queues.Add (this);
+               }
+
+               uint searchQFamily (VkQueueFlags requestedFlags) {
+                       //search for dedicated Q
+                       for (uint i = 0; i < dev.phy.QueueFamilies.Length; i++) {
+                               if (dev.phy.QueueFamilies[i].queueFlags == requestedFlags && dev.phy.GetPresentIsSupported (i, Surface))
+                                       return i;
+                       }
+                       //search Q having flags
+                       for (uint i = 0; i < dev.phy.QueueFamilies.Length; i++) {
+                               if ((dev.phy.QueueFamilies[i].queueFlags & requestedFlags) == requestedFlags && dev.phy.GetPresentIsSupported (i, Surface))
+                                       return i;
+                       }
+
+                       throw new Exception (string.Format ("No Queue with flags {0} found", requestedFlags));
+               }
+
+               public void Present (VkPresentInfoKHR present) {
+                       Utils.CheckResult (vkQueuePresentKHR (handle, ref present));
+               }
+               public void Present (SwapChain swapChain, VkSemaphore wait) {
+                       VkPresentInfoKHR present = VkPresentInfoKHR.New();
+
+                       uint idx = swapChain.currentImageIndex;
+                       VkSwapchainKHR sc = swapChain.Handle;
+                       present.pSwapchains = sc;
+                       present.pWaitSemaphores = wait;
+
+                       vkQueuePresentKHR (handle, ref present);
+
+                       present.Dispose();
+               }
+       }
+
+       public class Queue {
+
+               protected VkQueue handle;
+               internal Device dev;
                public Device Dev => dev;
 
-        VkQueueFlags flags => dev.phy.QueueFamilies[qFamIndex].queueFlags;
-        public uint qFamIndex;
-        public uint index;//index in queue family
-        public float priority;
-        public VkQueue Handle => handle;
-
-        protected Queue () { }
-        public Queue (Device _dev, VkQueueFlags requestedFlags, float _priority = 0.0f) {
-            dev = _dev;
-            priority = _priority;
-
-            qFamIndex = searchQFamily (requestedFlags);
-            dev.queues.Add (this);
-        }
-        public CommandPool CreateCommandPool (VkCommandPoolCreateFlags flags = 0)
-            => new CommandPool (dev, qFamIndex, flags);
+               VkQueueFlags flags => dev.phy.QueueFamilies[qFamIndex].queueFlags;
+               public uint qFamIndex;
+               public uint index;//index in queue family
+               public float priority;
+               public VkQueue Handle => handle;
+
+               protected Queue () { }
+               public Queue (Device _dev, VkQueueFlags requestedFlags, float _priority = 0.0f) {
+                       dev = _dev;
+                       priority = _priority;
+
+                       qFamIndex = searchQFamily (requestedFlags);
+                       dev.queues.Add (this);
+               }
+               public CommandPool CreateCommandPool (VkCommandPoolCreateFlags flags = 0)
+                       => new CommandPool (dev, qFamIndex, flags);
                /// <summary>
                /// End command recording, submit, and wait queue idle
                /// </summary>
@@ -89,30 +84,30 @@ namespace vke {
                        if (freeCommandBuffer)
                                cmd.Free ();
                }
-        public void Submit (PrimaryCommandBuffer cmd, VkSemaphore wait = default, VkSemaphore signal = default, Fence fence = null) {
-            cmd.Submit (handle, wait, signal, fence);
-        }
-        public void WaitIdle () {
-            Utils.CheckResult (vkQueueWaitIdle (handle));
-        }
-
-        uint searchQFamily (VkQueueFlags requestedFlags) {
-            //search for dedicated Q
-            for (uint i = 0; i < dev.phy.QueueFamilies.Length; i++) {
-                if (dev.phy.QueueFamilies[i].queueFlags == requestedFlags)
-                    return i;
-            }
-            //search Q having flags
-            for (uint i = 0; i < dev.phy.QueueFamilies.Length; i++) {
-                if ((dev.phy.QueueFamilies[i].queueFlags & requestedFlags) == requestedFlags)
-                    return i;
-            }
-
-            throw new Exception (string.Format ("No Queue with flags {0} found", requestedFlags));
-        }
-
-        internal void updateHandle () {
-            vkGetDeviceQueue (Dev.Handle, qFamIndex, index, out handle);
-        }
-    }
+               public void Submit (PrimaryCommandBuffer cmd, VkSemaphore wait = default, VkSemaphore signal = default, Fence fence = null) {
+                       cmd.Submit (handle, wait, signal, fence);
+               }
+               public void WaitIdle () {
+                       Utils.CheckResult (vkQueueWaitIdle (handle));
+               }
+
+               uint searchQFamily (VkQueueFlags requestedFlags) {
+                       //search for dedicated Q
+                       for (uint i = 0; i < dev.phy.QueueFamilies.Length; i++) {
+                               if (dev.phy.QueueFamilies[i].queueFlags == requestedFlags)
+                                       return i;
+                       }
+                       //search Q having flags
+                       for (uint i = 0; i < dev.phy.QueueFamilies.Length; i++) {
+                               if ((dev.phy.QueueFamilies[i].queueFlags & requestedFlags) == requestedFlags)
+                                       return i;
+                       }
+
+                       throw new Exception (string.Format ("No Queue with flags {0} found", requestedFlags));
+               }
+
+               internal void updateHandle () {
+                       vkGetDeviceQueue (Dev.Handle, qFamIndex, index, out handle);
+               }
+       }
 }
index be3278117237233e2c4cb7e90b20cb9fb63329b8..27d86873140551461f5c54084ba35cab0cac660b 100644 (file)
@@ -105,12 +105,9 @@ namespace vke {
                                        spDescs.Add (sp.SubpassDescription);
 
                                VkRenderPassCreateInfo renderPassInfo = VkRenderPassCreateInfo.New();
-                               renderPassInfo.attachmentCount = (uint)attachments.Count;
-                               renderPassInfo.pAttachments = attachments.Pin ();
-                               renderPassInfo.subpassCount = (uint)spDescs.Count;
-                               renderPassInfo.pSubpasses = spDescs.Pin ();
-                               renderPassInfo.dependencyCount = (uint)dependencies.Count;
-                               renderPassInfo.pDependencies = dependencies.Pin ();
+                               renderPassInfo.pAttachments = attachments;
+                               renderPassInfo.pSubpasses = spDescs;
+                               renderPassInfo.pDependencies = dependencies;
                                if (PNext != null)
                                        renderPassInfo.pNext = PNext.GetPointer ();
 
@@ -121,9 +118,8 @@ namespace vke {
 
                                if (PNext != null)
                                        PNext.ReleasePointer ();
-                               attachments.Unpin ();
-                               spDescs.Unpin ();
-                               dependencies.Unpin ();
+
+                               renderPassInfo.Dispose ();
                        }
                        base.Activate ();
                }
@@ -207,8 +203,7 @@ namespace vke {
                        info.renderPass = handle;
                        info.renderArea.extent.width = width;
                        info.renderArea.extent.height = height;
-                       info.clearValueCount = (uint)ClearValues.Count;
-                       info.pClearValues = ClearValues.Pin ();
+                       info.pClearValues = ClearValues;
                        info.framebuffer = frameBuffer.handle;
 
                        vkCmdBeginRenderPass (cmd.Handle, ref info, contents);
index a7b511d926724c9849c2b0e5638b05b972f48e77..828e5a6bf7e4078431c7fe57f25c75b9de07ff4c 100644 (file)
@@ -16,7 +16,7 @@ namespace vke {
         public SubPass () {
         }
                public SubPass (params VkImageLayout[] layouts) {
-                       for (uint i = 0; i < layouts.Length; i++) 
+                       for (uint i = 0; i < layouts.Length; i++)
                                AddColorReference (i, layouts[i]);
                }
 
@@ -54,33 +54,30 @@ namespace vke {
                 VkSubpassDescription subpassDescription = new VkSubpassDescription ();
                 subpassDescription.pipelineBindPoint = VkPipelineBindPoint.Graphics;
                 if (colorRefs.Count > 0) {
-                    subpassDescription.colorAttachmentCount = (uint)colorRefs.Count;
-                    subpassDescription.pColorAttachments = colorRefs.Pin(); ; 
+                    subpassDescription.pColorAttachments = colorRefs;
                 }
                 if (inputRefs.Count > 0) {
-                    subpassDescription.inputAttachmentCount = (uint)inputRefs.Count;
-                    subpassDescription.pInputAttachments = inputRefs.Pin (); ;
+                    subpassDescription.pInputAttachments = inputRefs; ;
                 }
                 if (preservedRefs.Count > 0) {
-                    subpassDescription.preserveAttachmentCount = (uint)preservedRefs.Count;
                     subpassDescription.pPreserveAttachments = preservedRefs.Pin (); ;
                 }
                                if (resolveRefs.Count > 0)
-                                       subpassDescription.pResolveAttachments = resolveRefs.Pin ();
+                                       subpassDescription.pResolveAttachments = resolveRefs;
 
                                if (DepthReference.HasValue)
-                    subpassDescription.pDepthStencilAttachment = DepthReference.Value.Pin();
+                    subpassDescription.pDepthStencilAttachment = DepthReference.Value;
 
                 return subpassDescription;
-            }        
+            }
         }
 
                internal void UnpinLists () {
-                       if (colorRefs.Count > 0) 
-                               colorRefs.Unpin (); 
-                       if (inputRefs.Count > 0)                        
+                       if (colorRefs.Count > 0)
+                               colorRefs.Unpin ();
+                       if (inputRefs.Count > 0)
                                inputRefs.Unpin ();
-                       if (preservedRefs.Count > 0) 
+                       if (preservedRefs.Count > 0)
                                preservedRefs.Unpin ();
                        if (resolveRefs.Count > 0)
                                resolveRefs.Unpin ();
index 1bc09be89272f06933d4276a67be453f152a1c05..eff1a3432836eb1fde4ecdf09a74603cae867943 100644 (file)
@@ -48,7 +48,7 @@
 
        <ItemGroup>
                <PackageReference Include="SpirVTasks" Version="$(SpirVTasksPackageVersion)" />
-               <PackageReference Include="Vulkan" Version="0.3.0-beta" />
+               <PackageReference Include="Vulkan" Version="0.4.0-beta" />
                <PackageReference Include="shaderc.net" Version="0.1.0" />
                <PackageReference Include="glfw-sharp" Version="0.2.14" />
        </ItemGroup>