From: Jean-Philippe Bruyère Date: Sat, 27 Feb 2021 12:51:17 +0000 (+0100) Subject: update nuget versions, destroy/recreate swapchain semaphore, comments X-Git-Tag: v0.2.0-beta X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=5daa786399f3cd791d08532ceb0eaf72fd844785;p=jp%2Fvke.net.git update nuget versions, destroy/recreate swapchain semaphore, comments --- diff --git a/addons/EnvironmentPipeline/EnvironmentPipeline.cs b/addons/EnvironmentPipeline/EnvironmentPipeline.cs index 87fc744..ec56cb0 100644 --- a/addons/EnvironmentPipeline/EnvironmentPipeline.cs +++ b/addons/EnvironmentPipeline/EnvironmentPipeline.cs @@ -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 (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); } diff --git a/samples/DistanceFieldFontTest/Program.cs b/samples/DistanceFieldFontTest/Program.cs index e54f569..8de28a8 100644 --- a/samples/DistanceFieldFontTest/Program.cs +++ b/samples/DistanceFieldFontTest/Program.cs @@ -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 () * 2)); + cfg.Layout = new PipelineLayout (dev, dsLayout); + cfg.Layout.AddPushConstants (new VkPushConstantRange (VkShaderStageFlags.Fragment, (uint)Marshal.SizeOf () * 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 diff --git a/samples/Triangle/main.cs b/samples/Triangle/main.cs index 34387f4..46a5c6f 100644 --- a/samples/Triangle/main.cs +++ b/samples/Triangle/main.cs @@ -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 (); } diff --git a/samples/deferred/DeferredPbrRenderer.cs b/samples/deferred/DeferredPbrRenderer.cs index e9b1b65..9a898a4 100644 --- a/samples/deferred/DeferredPbrRenderer.cs +++ b/samples/deferred/DeferredPbrRenderer.cs @@ -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); } diff --git a/vke/src/SpecializationConstant.cs b/vke/src/SpecializationConstant.cs index b434bcb..66b1619 100644 --- a/vke/src/SpecializationConstant.cs +++ b/vke/src/SpecializationConstant.cs @@ -11,17 +11,9 @@ namespace vke { /// Hold shader specialization constant value and type /// public class SpecializationConstant : 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 (); - 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); } /// diff --git a/vke/src/base/FrameBuffer.cs b/vke/src/base/FrameBuffer.cs index 82f214e..a6220c5 100644 --- a/vke/src/base/FrameBuffer.cs +++ b/vke/src/base/FrameBuffer.cs @@ -19,9 +19,11 @@ namespace vke { public List attachments = new List (); VkFramebufferCreateInfo createInfo = VkFramebufferCreateInfo.New (); - + /// Framebuffer width. public uint Width => createInfo.width; + /// Framebuffer height. public uint Height => createInfo.height; + /// Framebuffer layers count. public uint Layers => createInfo.layers; protected override VkDebugUtilsObjectNameInfoEXT DebugUtilsInfo @@ -40,7 +42,8 @@ namespace vke { /// Render pass. /// Width. /// Height. - /// 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. public FrameBuffer (RenderPass _renderPass, uint _width, uint _height, params Image[] views) : this (_renderPass, _width, _height) { for (int i = 0; i < views.Length; i++) { diff --git a/vke/src/base/GraphicPipeline.cs b/vke/src/base/GraphicPipeline.cs index 81da69c..dafacab 100644 --- a/vke/src/base/GraphicPipeline.cs +++ b/vke/src/base/GraphicPipeline.cs @@ -24,7 +24,7 @@ namespace vke { RenderPass = renderPass; } /// - /// Create a new Pipeline with supplied RenderPass + /// Create a new Pipeline with supplied configuration /// 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) { diff --git a/vke/src/base/Pipeline.cs b/vke/src/base/Pipeline.cs index 8b34025..3461eca 100644 --- a/vke/src/base/Pipeline.cs +++ b/vke/src/base/Pipeline.cs @@ -6,27 +6,61 @@ using Vulkan; using static Vulkan.Vk; namespace vke { + /// + /// Abstract base classe for vulkan pipelines. + /// public abstract class Pipeline : Activable { protected VkPipeline handle; protected PipelineLayout layout; protected PipelineCache Cache; + /// + /// Vulkan handle of the pipeline. + /// public VkPipeline Handle => handle; + /// + /// Pipeline layout, activated on pipeline activation. + /// 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 + /*/// + /// PipelineCache and PipelineLayout will also be activated if present. + /// + public override void Activate () { + Cache?.Activate (); + layout?.Activate (); + base.Activate (); + }*/ + /// + /// Bind Pipeline command call + /// + /// Recording command buffer public abstract void Bind (CommandBuffer cmd); + /// + /// + /// + /// Recording command buffer + /// + /// first descriptor set to bind public abstract void BindDescriptorSet (CommandBuffer cmd, DescriptorSet dset, uint firstSet = 0); + /// + /// + /// + /// Recording command buffer + /// a blittable object that contains the data to push + /// + /// byte offset public void PushConstant (CommandBuffer cmd, object obj, int rangeIndex = 0, uint offset = 0) { cmd.PushConstant (layout, layout.PushConstantRanges[rangeIndex].stageFlags, obj, offset); } diff --git a/vke/src/base/PipelineCache.cs b/vke/src/base/PipelineCache.cs index 51545c1..4abd45f 100644 --- a/vke/src/base/PipelineCache.cs +++ b/vke/src/base/PipelineCache.cs @@ -26,7 +26,7 @@ namespace vke { /// public static bool SaveOnDispose; /// - /// If true, cache will be restore on activation + /// If true, cache will be restored on activation /// 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); - + /// + /// Delete pipeline backend file from disk if file exist. + /// public void Delete () { string path = Path.Combine (globalConfigPath, cacheFile); if (File.Exists (path)) File.Delete (path); } - + /// + /// Save pipeline cache on disk in the user/.config/application directory. + /// public void Save () { if (state != ActivableState.Activated) return; diff --git a/vke/src/base/SwapChain.cs b/vke/src/base/SwapChain.cs index dba30fd..33f890e 100644 --- a/vke/src/base/SwapChain.cs +++ b/vke/src/base/SwapChain.cs @@ -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 { /// 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) diff --git a/vke/vke.csproj b/vke/vke.csproj index 734c8c5..fb73c03 100644 --- a/vke/vke.csproj +++ b/vke/vke.csproj @@ -49,9 +49,9 @@ - + - +