]> O.S.I.I.S - jp/vke.net.git/commitdiff
update nuget versions, destroy/recreate swapchain semaphore, comments v0.2.0-beta
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 27 Feb 2021 12:51:17 +0000 (13:51 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 27 Feb 2021 12:51:17 +0000 (13:51 +0100)
addons/EnvironmentPipeline/EnvironmentPipeline.cs
samples/DistanceFieldFontTest/Program.cs
samples/Triangle/main.cs
samples/deferred/DeferredPbrRenderer.cs
vke/src/SpecializationConstant.cs
vke/src/base/FrameBuffer.cs
vke/src/base/GraphicPipeline.cs
vke/src/base/Pipeline.cs
vke/src/base/PipelineCache.cs
vke/src/base/SwapChain.cs
vke/vke.csproj

index 87fc744cb0117b71bdad539a01a6e60531c9bbb9..ec56cb07e35ba14deeccf6bb72505a65f73b091d 100644 (file)
@@ -17,6 +17,23 @@ namespace vke.Environment {
                public EnvironmentCube (string cubemapPath, PipelineLayout plLayout, Queue staggingQ, RenderPass renderPass, PipelineCache cache = null)
                : base (renderPass, cache, "EnvCube pipeline") {
 
+                       using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, renderPass.Samples, false)) {
+                               cfg.RenderPass = renderPass;
+                               cfg.Layout = plLayout;
+                               cfg.AddVertexBinding (0, 3 * sizeof (float));
+                               cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat);
+                               cfg.AddShaders (
+                                       new ShaderInfo (Dev, VkShaderStageFlags.Vertex, "#EnvironmentPipeline.skybox.vert.spv"),
+                                       new ShaderInfo (Dev, VkShaderStageFlags.Fragment, STR_FRAG_PATH)
+                               );
+
+                               cfg.multisampleState.rasterizationSamples = Samples;
+
+                               layout = cfg.Layout;
+
+                               init (cfg);
+                       }
+
                        using (CommandPool cmdPool = new CommandPool (staggingQ.Dev, staggingQ.index)) {
 
                                vboSkybox = new GPUBuffer<float> (staggingQ, cmdPool, VkBufferUsageFlags.VertexBuffer, box_vertices);
@@ -28,23 +45,6 @@ namespace vke.Environment {
                                cubemap.SetName ("skybox Texture");
                                cubemap.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal;
 
-                               using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, renderPass.Samples, false)) {
-                                       cfg.RenderPass = renderPass;
-                                       cfg.Layout = plLayout;
-                                       cfg.AddVertexBinding (0, 3 * sizeof (float));
-                                       cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat);
-                                       cfg.AddShaders (
-                                               new ShaderInfo (Dev, VkShaderStageFlags.Vertex, "#EnvironmentPipeline.skybox.vert.spv"),
-                                               new ShaderInfo (Dev, VkShaderStageFlags.Fragment, STR_FRAG_PATH)
-                                       );
-
-                                       cfg.multisampleState.rasterizationSamples = Samples;
-
-                                       layout = cfg.Layout;
-
-                                       init (cfg);
-                               }
-
                                generateBRDFLUT (staggingQ, cmdPool);
                                generateCubemaps (staggingQ, cmdPool);
                        }
index e54f56925e79f698b791e9a6a9aee8c541d5cd03..8de28a8f190714444e738f9925094d88379f645d 100644 (file)
@@ -82,23 +82,24 @@ namespace DistanceFieldFontTest {
                                new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Vertex, VkDescriptorType.UniformBuffer),
                                new VkDescriptorSetLayoutBinding (1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler));
 
-                       GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount4, false);
+                       using (GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount4, false)) {
 
-                       cfg.Layout = new PipelineLayout (dev, dsLayout);
-                       cfg.Layout.AddPushConstants (new VkPushConstantRange (VkShaderStageFlags.Fragment, (uint)Marshal.SizeOf<Vector4> () * 2));
+                               cfg.Layout = new PipelineLayout (dev, dsLayout);
+                               cfg.Layout.AddPushConstants (new VkPushConstantRange (VkShaderStageFlags.Fragment, (uint)Marshal.SizeOf<Vector4> () * 2));
 
-                       cfg.RenderPass = new RenderPass (dev, swapChain.ColorFormat, cfg.Samples);
+                               cfg.RenderPass = new RenderPass (dev, swapChain.ColorFormat, cfg.Samples);
 
-                       cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState (
-                               true, VkBlendFactor.One, VkBlendFactor.OneMinusSrcAlpha, VkBlendOp.Add, VkBlendFactor.One, VkBlendFactor.Zero);
+                               cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState (
+                                       true, VkBlendFactor.One, VkBlendFactor.OneMinusSrcAlpha, VkBlendOp.Add, VkBlendFactor.One, VkBlendFactor.Zero);
 
-                       cfg.AddVertexBinding (0, 5 * sizeof (float));
-                       cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat);
+                               cfg.AddVertexBinding (0, 5 * sizeof (float));
+                               cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat);
 
-                       cfg.AddShader (dev, VkShaderStageFlags.Vertex, "#shaders.main.vert.spv");
-                       cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.main.frag.spv");
+                               cfg.AddShader (dev, VkShaderStageFlags.Vertex, "#shaders.main.vert.spv");
+                               cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.main.frag.spv");
 
-                       pipeline = new GraphicPipeline (cfg);
+                               pipeline = new GraphicPipeline (cfg);
+                       }
 
                        uboMats = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, matrices);
                        uboMats.Map ();//permanent map
index 34387f4845eb6ddf05c6547e94e3fd1a023951cf..46a5c6f8ab86daaa7526a7d9dc04b56f398120ac 100644 (file)
@@ -12,6 +12,9 @@ using Glfw;
 namespace Triangle {
        class Program : VkWindow {
                static void Main (string[] args) {
+#if DEBUG
+                       Instance.VALIDATION = true;
+#endif
                        using (Program vke = new Program ()) {
                                vke.Run ();
                        }
index e9b1b65c6744bf359c5f30c2d4f2c37d02120175..9a898a46eb5fcc3dc59464ee811bdd7abed7bef9 100644 (file)
@@ -288,7 +288,7 @@ namespace deferred {
 #if WITH_SHADOWS
                                        cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.compose_with_shadows.frag.spv", constants);
 #else
-                               cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.compose.frag.spv", constants);
+                                       cfg.AddShader (dev, VkShaderStageFlags.Fragment, "#shaders.compose.frag.spv", constants);
 #endif
                                        composePipeline = new GraphicPipeline (cfg);
                                }
index b434bcb76b3f8ad51eedaa1a1898ff1350c65f1e..66b1619ab7abd7ca1a1ab7c5129fddc844708f6e 100644 (file)
@@ -11,17 +11,9 @@ namespace vke {
        /// Hold shader specialization constant value and type
        /// </summary>
        public class SpecializationConstant<T> : SpecializationConstant {
-               T val;
-               IntPtr ptr = IntPtr.Zero;
+               T val;          
 
-        public T Value {
-                       get { return val; }
-                       set {
-                               val = value;
-                               if (ptr != IntPtr.Zero)
-                                       WriteTo (ptr);
-                       }
-        }
+        public T Value => val;        
 
                #region CTOR
                public SpecializationConstant (uint id, T value) : base(id) {            
@@ -30,9 +22,7 @@ namespace vke {
                #endregion
 
                public override uint Size => (uint)Marshal.SizeOf<T> ();
-               public unsafe override void WriteTo (IntPtr ptr) {
-                       this.ptr = ptr;
-
+               internal unsafe override void WriteTo (IntPtr ptr) {                    
                        if (typeof (T) == typeof (float)) {
                                float v = Convert.ToSingle (Value);
                                System.Buffer.MemoryCopy (&v, ptr.ToPointer (), 4, 4);
@@ -51,7 +41,7 @@ namespace vke {
                        this.id = id;
                }
                public abstract uint Size { get; }
-               public abstract void WriteTo (IntPtr ptr);
+               internal abstract void WriteTo (IntPtr ptr);
        }
 
        /// <summary>
index 82f214e1950df2cfac265adf2a1499466c7a1fe4..a6220c54704a3695e48530389c9c4eab91b5ba9d 100644 (file)
@@ -19,9 +19,11 @@ namespace vke {
 
                public List<Image> attachments = new List<Image> ();
                VkFramebufferCreateInfo createInfo = VkFramebufferCreateInfo.New ();
-
+               /// <summary>Framebuffer width.</summary>
                public uint Width => createInfo.width;
+               /// <summary>Framebuffer height.</summary>
                public uint Height => createInfo.height;
+               /// <summary>Framebuffer layers count.</summary>
                public uint Layers => createInfo.layers;
 
                protected override VkDebugUtilsObjectNameInfoEXT DebugUtilsInfo
@@ -40,7 +42,8 @@ namespace vke {
                /// <param name="_renderPass">Render pass.</param>
                /// <param name="_width">Width.</param>
                /// <param name="_height">Height.</param>
-               /// <param name="views">Views.</param>
+               /// <param name="views">Array of image views. If null and not in unused state, attachment image and view will be automatically created from the
+               /// supplied renderpass configuration.</param>
                public FrameBuffer (RenderPass _renderPass, uint _width, uint _height, params Image[] views)
                : this (_renderPass, _width, _height) {
                        for (int i = 0; i < views.Length; i++) {
index 81da69c8c21ed89d409e7e137942161d3e0bd66e..dafacab40dffa4719240c6023f37f48fbd284e35 100644 (file)
@@ -24,7 +24,7 @@ namespace vke {
                        RenderPass = renderPass;
                }
                /// <summary>
-               /// Create a new Pipeline with supplied RenderPass
+               /// Create a new Pipeline with supplied configuration
                /// </summary>
                public GraphicPipeline (GraphicPipelineConfig cfg, string name = "graphic pipeline") : this (cfg.RenderPass, cfg.Cache, name) {
                        layout = cfg.Layout;
@@ -32,9 +32,9 @@ namespace vke {
                        init (cfg);
                }
 
-               #endregion
+        #endregion
 
-               public override void Activate () => throw new NotSupportedException ("Please initialize graphic pipeline through the init method");
+        public override void Activate () => throw new NotSupportedException ("Please initialize graphic pipeline through the init method");
 
                protected void init (GraphicPipelineConfig cfg) {
                        if (state != ActivableState.Activated) {
index 8b34025b0d964e292bd90af675f5b90effeeac6c..3461eca23c71923da0caf57745b17d69de545cdf 100644 (file)
@@ -6,27 +6,61 @@ using Vulkan;
 using static Vulkan.Vk;
 
 namespace vke {
+       /// <summary>
+       /// Abstract base classe for vulkan pipelines.
+       /// </summary>
        public abstract class Pipeline : Activable {
         protected VkPipeline handle;
                protected PipelineLayout layout;
                protected PipelineCache Cache;
 
+               /// <summary>
+               /// Vulkan handle of the pipeline.
+               /// </summary>
                public VkPipeline Handle => handle;
+               /// <summary>
+               /// Pipeline layout, activated on pipeline activation.
+               /// </summary>
                public PipelineLayout Layout => layout;
 
                protected readonly VkPipelineBindPoint bindPoint;
 
+               protected override VkDebugUtilsObjectNameInfoEXT DebugUtilsInfo
+                       => new VkDebugUtilsObjectNameInfoEXT (VkObjectType.Pipeline, handle.Handle);
+
                #region CTORS
                protected Pipeline (Device dev, PipelineCache cache = null, string name = "custom pipeline") : base(dev, name) {
                        this.Cache = cache;
                }
-               #endregion
-
-               protected override VkDebugUtilsObjectNameInfoEXT DebugUtilsInfo
-                                       => new VkDebugUtilsObjectNameInfoEXT (VkObjectType.Pipeline, handle.Handle);
+        #endregion
 
+               /*/// <summary>
+               /// PipelineCache and PipelineLayout will also be activated if present.
+               /// </summary>
+        public override void Activate () {
+                       Cache?.Activate ();
+                       layout?.Activate ();
+            base.Activate ();
+        }*/
+               /// <summary>
+               /// Bind Pipeline command call
+               /// </summary>
+               /// <param name="cmd">Recording command buffer</param>
                public abstract void Bind (CommandBuffer cmd);
+               /// <summary>
+               /// 
+               /// </summary>
+               /// <param name="cmd">Recording command buffer</param>
+               /// <param name="dset"></param>
+               /// <param name="firstSet">first descriptor set to bind</param>
                public abstract void BindDescriptorSet (CommandBuffer cmd, DescriptorSet dset, uint firstSet = 0);
+               /// <summary>
+               /// 
+               /// </summary>
+               /// <param name="cmd">Recording command buffer</param>
+               /// <param name="obj">a blittable object that contains the data to push</param>
+               /// <param name="rangeIndex"></param>
+               /// <param name="offset">byte offset</param>
                public void PushConstant (CommandBuffer cmd, object obj, int rangeIndex = 0, uint offset = 0) {
                        cmd.PushConstant (layout, layout.PushConstantRanges[rangeIndex].stageFlags, obj, offset);
                }
index 51545c17efbca4af0f46cc2b9d063b869f401f9a..4abd45f7f675c97b11323b16747fcd344f19a489 100644 (file)
@@ -26,7 +26,7 @@ namespace vke {
                /// </summary>
                public static bool SaveOnDispose;
                /// <summary>
-               /// If true, cache will be restore on activation
+               /// If true, cache will be restored on activation
                /// </summary>
                public static bool LoadOnActivation;
 
@@ -34,6 +34,9 @@ namespace vke {
                readonly string globalConfigPath;
                readonly string cacheFile;
 
+               protected override VkDebugUtilsObjectNameInfoEXT DebugUtilsInfo
+                       => new VkDebugUtilsObjectNameInfoEXT (VkObjectType.PipelineCache, handle.Handle);
+
                #region CTOR
                public PipelineCache (Device dev, string cacheFile = "pipelines.bin", string name = "pipeline cache") : base(dev, name) {
                        string configRoot = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.UserProfile), ".config");
@@ -71,16 +74,17 @@ namespace vke {
                        }
                        base.Activate ();
                }
-
-               protected override VkDebugUtilsObjectNameInfoEXT DebugUtilsInfo
-                                       => new VkDebugUtilsObjectNameInfoEXT (VkObjectType.PipelineCache, handle.Handle);
-
+               /// <summary>
+               /// Delete pipeline backend file from disk if file exist.
+               /// </summary>
                public void Delete () {
                        string path = Path.Combine (globalConfigPath, cacheFile);
                        if (File.Exists (path))
                                File.Delete (path);
                }
-
+               /// <summary>
+               /// Save pipeline cache on disk in the user/.config/application directory.
+               /// </summary>
                public void Save () {
                        if (state != ActivableState.Activated)
                                return;
index dba30fd94e4c697e6b05cfb8d072690309d3c213..33f890e0ec0b76fa55f163c8d6cb8f7cbdab9bbe 100644 (file)
@@ -90,8 +90,6 @@ namespace vke {
                }
                public override void Activate () {
                        if (state != ActivableState.Activated) {
-                               presentComplete = Dev.CreateSemaphore ();
-                               presentComplete.SetDebugMarkerName (Dev, "Semaphore PresentComplete");
                                Create ();
                        }
                        base.Activate ();
@@ -101,7 +99,7 @@ namespace vke {
                /// </summary>
                public void Create () {
 
-                       Dev.WaitIdle ();
+                       Dev.WaitIdle ();                                                        
 
                        VkSurfaceCapabilitiesKHR capabilities = Dev.phy.GetSurfaceCapabilities (presentQueue.Surface);
 
@@ -126,6 +124,9 @@ namespace vke {
 
                        if (Handle.Handle != 0)
                                _destroy ();
+
+                       presentComplete = Dev.CreateSemaphore ();
+                       presentComplete.SetDebugMarkerName (Dev, "Semaphore PresentComplete");
                        Handle = newSwapChain;
                                                        
                        Utils.CheckResult (vkGetSwapchainImagesKHR (Dev.VkDev, Handle, out uint imageCount, IntPtr.Zero));
@@ -162,6 +163,7 @@ namespace vke {
                        for (int i = 0; i < ImageCount; i++)
                                images[i].Dispose ();
                        vkDestroySwapchainKHR (Dev.VkDev, Handle, IntPtr.Zero);
+                       Dev.DestroySemaphore (presentComplete);
                }
 
                public override string ToString () {
@@ -173,8 +175,7 @@ namespace vke {
                        if (state == ActivableState.Activated) {
                                if (!disposing)
                                        System.Diagnostics.Debug.WriteLine ("VKE Swapchain disposed by finalizer");
-
-                               Dev.DestroySemaphore (presentComplete);
+                               
                                _destroy ();
 
                        } else if (disposing)
index 734c8c58999af7baf8cd5d77dba0c89b2de11bbe..fb73c03b59890a19f3096c69ed440841d98fb239 100644 (file)
@@ -49,9 +49,9 @@
 
        <ItemGroup>
                <PackageReference Include="SpirVTasks" Version="$(SpirVTasksPackageVersion)" />
-               <PackageReference Include="Vulkan" Version="0.2.3-beta" />
+               <PackageReference Include="Vulkan" Version="0.2.4" />
                <PackageReference Include="shaderc.net" Version="0.1.0" />
-               <PackageReference Include="glfw-sharp" Version="0.2.10-beta" />
+               <PackageReference Include="glfw-sharp" Version="0.2.12-beta" />
        </ItemGroup>
        
        <ItemGroup>