aboutsummaryrefslogtreecommitdiffstatsci
path: root/vke/src/PipelineLayout.cs
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2019-04-05 14:13:20 +0200
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2019-04-05 14:13:20 +0200
commit04d94de392b6e5ca4f82acc233df7b3f97abca36 (patch)
tree27df9645ea97cf36c99cb4f8ed5f347cc00cb458 /vke/src/PipelineLayout.cs
parent7d305b07ccaeb2a8cd342e3395db46f2f8fffade (diff)
Activable pattern wip
Diffstat (limited to 'vke/src/PipelineLayout.cs')
-rw-r--r--vke/src/PipelineLayout.cs74
1 files changed, 25 insertions, 49 deletions
diff --git a/vke/src/PipelineLayout.cs b/vke/src/PipelineLayout.cs
index 68f7d4b..c1afc79 100644
--- a/vke/src/PipelineLayout.cs
+++ b/vke/src/PipelineLayout.cs
@@ -30,18 +30,13 @@ using Vulkan;
using static Vulkan.VulkanNative;
namespace VKE {
-
- public class PipelineLayout : IDisposable {
- internal uint references;
+ public sealed class PipelineLayout : Activable {
internal VkPipelineLayout handle;
- internal Device dev;
public List<DescriptorSetLayout> DescriptorSetLayouts = new List<DescriptorSetLayout> ();
- public NativeList<VkPushConstantRange> PushConstantRanges = new NativeList<VkPushConstantRange> ();
+ public List<VkPushConstantRange> PushConstantRanges = new List<VkPushConstantRange> ();
- public PipelineLayout (Device device) {
- dev = device;
- }
+ public PipelineLayout (Device device) : base (device) { }
public PipelineLayout (Device device, VkPushConstantRange pushConstantRange, params DescriptorSetLayout[] descriptorSetLayouts)
: this (device, descriptorSetLayouts) {
PushConstantRanges.Add (pushConstantRange);
@@ -61,52 +56,33 @@ namespace VKE {
foreach (VkPushConstantRange pcr in pushConstantRanges)
PushConstantRanges.Add (pcr);
}
- public PipelineLayout Activate () {
- if (isDisposed) {
- isDisposed = false;
- GC.ReRegisterForFinalize (this);
- PushConstantRanges = new NativeList<VkPushConstantRange> ();
- }
- 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 ();
- }
- if (PushConstantRanges.Count > 0) {
- info.pushConstantRangeCount = (uint)PushConstantRanges.Count;
- info.pPushConstantRanges = PushConstantRanges.Data;
+ public override void Activate () {
+ if (state != ActivableState.Activated) {
+ 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 ();
+ }
+ if (PushConstantRanges.Count > 0) {
+ info.pushConstantRangeCount = (uint)PushConstantRanges.Count;
+ info.pPushConstantRanges = PushConstantRanges.Pin();
+ }
+ Utils.CheckResult (vkCreatePipelineLayout (dev.VkDev, ref info, IntPtr.Zero, out handle));
+ dsls.Unpin ();
+ PushConstantRanges.Unpin ();
}
- Utils.CheckResult (vkCreatePipelineLayout (dev.VkDev, ref info, IntPtr.Zero, out handle));
- dsls.Unpin ();
- return this;
+ base.Activate ();
}
#region IDisposable Support
- private bool isDisposed = false; // Pour détecter les appels redondants
-
- protected virtual void Dispose (bool disposing) {
- if (!isDisposed) {
- if (disposing) {
- PushConstantRanges.Dispose ();
- } else
- System.Diagnostics.Debug.WriteLine ("One Pipeline layout was not disposed");
-
+ protected override void Dispose (bool disposing) {
+ if (!disposing)
+ System.Diagnostics.Debug.WriteLine ("VKE Activable PipelineLayout disposed by finalizer");
+ if (state == ActivableState.Activated)
vkDestroyPipelineLayout (dev.VkDev, handle, IntPtr.Zero);
- isDisposed = true;
- }
- }
-
- ~PipelineLayout() {
- Dispose(false);
- }
- public void Dispose () {
- if (references>0)
- references--;
- if (references>0)
- return;
- Dispose (true);
- GC.SuppressFinalize(this);
+ base.Dispose (disposing);
}
#endregion
}