// 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;
//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.
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
Console.ResetColor ();
}
#endif
- }
+ }*/
}
}
#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)) {
VkShaderStageFlags stageFlags = Utils.ShaderKindToStageFlag (shaderKind);
return new ShaderInfo (dev, stageFlags, res.CodePointer, (UIntPtr)res.CodeLength, specializationInfo, entryPoint);
}
- }
+ }*/
#endregion
#region temp
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);
/// <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
}
System.Diagnostics.Debug.WriteLine ("VKE ShaderInfo disposed by finalizer");
dev?.DestroyShaderModule (info.module);
+ info.Dispose();
disposedValue = true;
}
using System.IO;
using System.Linq;
using System.Reflection;
+using System.Runtime.InteropServices;
using Vulkan;
using static Vulkan.Vk;
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 ();
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
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 ();
// 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;
}
}
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;
}
}
/// <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;
}
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);
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));
if (result != VkResult.Success)
throw new InvalidOperationException ("Could not create Vulkan instance. Error: " + result);
+ instanceCreateInfo.Dispose();
+ appInfo.Dispose();
+
Vk.LoadInstanceFunctionPointers (inst);
}
}
// Gather physical Device memory properties
IntPtr tmp = Marshal.AllocHGlobal (Marshal.SizeOf<VkPhysicalDeviceMemoryProperties> ());
vkGetPhysicalDeviceMemoryProperties (phy, tmp);
+
memoryProperties = Marshal.PtrToStructure<VkPhysicalDeviceMemoryProperties> (tmp);
Marshal.FreeHGlobal (tmp);
vkGetPhysicalDeviceQueueFamilyProperties (phy, out queueFamilyCount, QueueFamilies.Pin ());
QueueFamilies.Unpin ();
+ Console.WriteLine("PhysicalDeviceCollection");
HasSwapChainSupport = GetDeviceExtensionSupported (Ext.D.VK_KHR_swapchain);
}
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();
}
}
PNext.ReleasePointer ();
renderPassInfo.Dispose ();
+ foreach (VkSubpassDescription spd in spDescs)
+ spd.Dispose ();
}
base.Activate ();
}
subpassDescription.pInputAttachments = inputRefs; ;
}
if (preservedRefs.Count > 0) {
- subpassDescription.pPreserveAttachments = preservedRefs.Pin (); ;
+ subpassDescription.pPreserveAttachments = preservedRefs; ;
}
if (resolveRefs.Count > 0)
subpassDescription.pResolveAttachments = resolveRefs;
/// </summary>
public void Create () {
- Dev.WaitIdle ();
+ Dev.WaitIdle ();
VkSurfaceCapabilitiesKHR capabilities = Dev.phy.GetSurfaceCapabilities (presentQueue.Surface);
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.");
if (state == ActivableState.Activated) {
if (!disposing)
System.Diagnostics.Debug.WriteLine ("VKE Swapchain disposed by finalizer");
-
+
_destroy ();
} else if (disposing)