public int Score(VulkanPhysicalDevice myDevice, SurfaceKHR mySurface) { mySurface.SurfaceCapabilities = myDevice.GetSurfaceCapabilitiesKHR(mySurface); var result = GetDefaultSurfaceFormat(myDevice.GetSurfaceFormatsKHR(mySurface)); mySurface.SelectedSurfaceFormat = result.GetValueOrDefault(); int returnVal = -1; if (result.HasValue) { for (int i = 0; i < myDevice.QueueFamilyProperties.Length; i++) { if ((myDevice.QueueFamilyProperties[i].QueueFlags & QueueFlags.Graphics) == QueueFlags.Graphics) { if (myDevice.GetSurfaceSupportKHR((uint)i, mySurface)) { returnVal = 100; break; } } } } return(returnVal); }
public unsafe VulkanPhysicalDevice[] GetPhysicalDevices(Predicate <VulkanPhysicalDevice>?suitability) { suitability ??= _ => true; uint deviceCount = 0u; VK.EnumeratePhysicalDevices(_VKInstance, &deviceCount, Span <PhysicalDevice> .Empty); Span <PhysicalDevice> physicalDevices = stackalloc PhysicalDevice[(int)deviceCount]; VK.EnumeratePhysicalDevices(_VKInstance, &deviceCount, physicalDevices); VulkanPhysicalDevice[] tempSuitable = ArrayPool <VulkanPhysicalDevice> .Shared.Rent((int)deviceCount); int index = 0; foreach (PhysicalDevice physicalDevice in physicalDevices) { VulkanPhysicalDevice vulkanPhysicalDevice = new VulkanPhysicalDevice(VK, new VulkanContext { Instance = this }, physicalDevice); if (suitability(vulkanPhysicalDevice)) { tempSuitable[index] = vulkanPhysicalDevice; index += 1; } } VulkanPhysicalDevice[] finalSuitable = tempSuitable[..index];
public Image(VulkanPhysicalDevice myDevice, ImageCreateInfo pCreateInfo, AllocationCallbacks pAllocator = null) { this.Device = myDevice; Result result; unsafe { fixed(UInt64 *ptrpImage = &this.m) { result = Interop.NativeMethods.vkCreateImage(myDevice.LogicalDevice.m, pCreateInfo != null ? pCreateInfo.m : (Interop.ImageCreateInfo *) default(IntPtr), pAllocator != null ? pAllocator.m : null, ptrpImage); } if (result != Result.Success) { throw new ResultException(result); } } MemoryRequirements myRequirements = GetImageMemoryRequirements(); MemoryAllocateInfo MemInfo = new MemoryAllocateInfo(); MemInfo.AllocationSize = myRequirements.Size; MemInfo.MemoryTypeIndex = myDevice.GetMemoryIndexFromProperty(myRequirements.MemoryTypeBits, MemoryPropertyFlags.DeviceLocal); deviceMemory = new DeviceMemory(myDevice.LogicalDevice, MemInfo); BindImageMemory(deviceMemory, 0); }
public VulkanLogicalDevice(VulkanPhysicalDevice selectedPhysicalDevice) { myAssociatedDevice = selectedPhysicalDevice; selectedPhysicalDevice.LogicalDevice = this; QueueManager = new DeviceQueueManager(selectedPhysicalDevice, this); var DeviceCreateInfo = new Interop.DeviceCreateInfo { EnabledExtensionNames = new string[] { "VK_KHR_swapchain", }, QueueCreateInfos = QueueManager.GetDeviceQueueCreateArray()// new Interop.DeviceQueueCreateInfo[] { GraphicsQueueInfo, ComputeQueueInfo } }; unsafe { Interop.Result result; fixed(IntPtr *ptrpDevice = &this.m) { result = Interop.Interop.NativeMethods.vkCreateDevice(selectedPhysicalDevice.m, DeviceCreateInfo.m, null, ptrpDevice); } if (result != Interop.Result.Success) { throw new Interop.ResultException(result); } } DeviceCreateInfo.Dispose(); }
public unsafe VertexBuffer(T[] myManagedArray, VulkanPhysicalDevice myDevice, uint[] QueueFamilyIndices, SharingMode myMode = SharingMode.Exclusive, AllocationCallbacks pAllocator = null) { int mySize = Marshal.SizeOf(typeof(T)); BufferCreateInfo myBuffer = new BufferCreateInfo { Size = myManagedArray.Length * mySize, Usage = BufferUsageFlags.VertexBuffer, SharingMode = myMode, QueueFamilyIndices = QueueFamilyIndices }; CreateBuffer(myDevice, myBuffer, pAllocator); CopyFromMemory <T>(myManagedArray); }
public VulkanCompute(VulkanLogicalDevice selectedLogicalGraphicsDevice, DescriptorSetPoolManager myDescriptorPoolComputeManager, VulkanPhysicalDevice selectedPhysicalGraphicsDevice, Engine.Renderer.Vulkan.Queue myComputeQueue) { this.selectedLogicalGraphicsDevice = selectedLogicalGraphicsDevice; this.myDescriptorPoolComputeManager = myDescriptorPoolComputeManager; this.selectedPhysicalGraphicsDevice = selectedPhysicalGraphicsDevice; this.myComputeQueue = myComputeQueue; FenceCreateInfo fenceInfo = new FenceCreateInfo(); myComputeFence = selectedLogicalGraphicsDevice.CreateFence(fenceInfo); }
/* public Vulkan.Buffer CreateUniformBuffer() * { * var uniformBufferData = new AreaUniformBuffer * { * width = SurfaceCapabilities.CurrentExtent.Width, * height = SurfaceCapabilities.CurrentExtent.Height * }; * * return CreateBuffer(uniformBufferData, BufferUsageFlags.UniformBuffer, typeof(AreaUniformBuffer)); * } * private Vulkan.Buffer CreateBuffer( object values, BufferUsageFlags usageFlags, System.Type type) * { * var array = values as System.Array; * var length = (array != null) ? array.Length : 1; * var size = System.Runtime.InteropServices.Marshal.SizeOf(type) * length; * var createBufferInfo = new BufferCreateInfo * { * Size = size, * Usage = usageFlags, * SharingMode = SharingMode.Exclusive, * QueueFamilyIndices = new uint[] { 0 } * }; * return CreateBufferBufferCreateInfoCanBeSet(values, type, length, size, createBufferInfo); * } * * private Vulkan.Buffer CreateBufferBufferCreateInfoCanBeSet(object values, Type type, int length, int size, BufferCreateInfo createBufferInfo) * { * var buffer = LogicalDevice.CreateBuffer(createBufferInfo); * var memoryReq = LogicalDevice.GetBufferMemoryRequirements(buffer); * var allocInfo = new MemoryAllocateInfo { AllocationSize = memoryReq.Size }; * var memoryProperties = myPhysicalDevice.GetMemoryProperties(); * bool heapIndexSet = false; * var memoryTypes = memoryProperties.MemoryTypes; * * for (uint i = 0; i < memoryProperties.MemoryTypeCount; i++) * { * if (((memoryReq.MemoryTypeBits >> (int)i) & 1) == 1 && * (memoryTypes[i].PropertyFlags & MemoryPropertyFlags.HostVisible) == MemoryPropertyFlags.HostVisible) * { * allocInfo.MemoryTypeIndex = i; * heapIndexSet = true; * } * } * * if (!heapIndexSet) * allocInfo.MemoryTypeIndex = memoryProperties.MemoryTypes[0].HeapIndex; * * var deviceMemory = LogicalDevice.AllocateMemory(allocInfo); * var memPtr = LogicalDevice.MapMemory(deviceMemory, 0, size, 0); * * if (type == typeof(float)) * System.Runtime.InteropServices.Marshal.Copy(values as float[], 0, memPtr, length); * else if (type == typeof(short)) * System.Runtime.InteropServices.Marshal.Copy(values as short[], 0, memPtr, length); * else if (type == typeof(AreaUniformBuffer)) * System.Runtime.InteropServices.Marshal.StructureToPtr(values, memPtr, false); * * LogicalDevice.UnmapMemory(deviceMemory); * LogicalDevice.BindBufferMemory(buffer, deviceMemory, 0); * * return buffer; * } * VertextBuffer VertBuffer = */ public unsafe VulkanBuffer(VulkanPhysicalDevice myDevice, BufferCreateInfo createBufferInfo, AllocationCallbacks pAllocator = null) //Tested { if (myDevice == null) { throw new VULKANDEVICE_NO_ACTIVE_DEVICE(); } this.Allocator = pAllocator; this.myActiveDevice = myDevice; CreateBuffer(myDevice, createBufferInfo, pAllocator); }
public unsafe PresentModeKHR[] GetPhysicalDeviceSurfacePresentModes(VulkanPhysicalDevice physicalDevice, SurfaceKHR surface) { uint presentationCount = 0u; GetPhysicalDeviceSurfacePresentModes(physicalDevice, surface, &presentationCount, (PresentModeKHR *)null !); if (presentationCount is 0u) { return(Array.Empty <PresentModeKHR>()); } PresentModeKHR *presentModesPointer = stackalloc PresentModeKHR[(int)presentationCount]; GetPhysicalDeviceSurfacePresentModes(physicalDevice, surface, &presentationCount, presentModesPointer); PresentModeKHR[] presentModes = new PresentModeKHR[presentationCount]; new Span <PresentModeKHR>(presentModesPointer, (int)presentationCount).CopyTo(presentModes); return(presentModes); }
public unsafe SurfaceFormatKHR[] GetPhysicalDeviceSurfaceFormats(VulkanPhysicalDevice physicalDevice, SurfaceKHR surface) { uint formatsCount = 0u; GetPhysicalDeviceSurfaceFormats(physicalDevice, surface, &formatsCount, (SurfaceFormatKHR *)null !); if (formatsCount is 0u) { return(Array.Empty <SurfaceFormatKHR>()); } SurfaceFormatKHR *surfaceFormatsPointer = stackalloc SurfaceFormatKHR[(int)formatsCount]; GetPhysicalDeviceSurfaceFormats(physicalDevice, surface, &formatsCount, surfaceFormatsPointer); SurfaceFormatKHR[] surfaceFormats = new SurfaceFormatKHR[formatsCount]; new Span <SurfaceFormatKHR>(surfaceFormatsPointer, (int)formatsCount).CopyTo(surfaceFormats); return(surfaceFormats); }
public VulkanPhysicalDevice[] EnumeratePhysicalDevices() { Result result; unsafe { UInt32 pPhysicalDeviceCount; result = Interop.NativeMethods.vkEnumeratePhysicalDevices(this.m, &pPhysicalDeviceCount, null); if (result != Result.Success) { throw new ResultException(result); } if (pPhysicalDeviceCount <= 0) { throw new VULKAN_NO_HARDWARE_SUPPORTED_DEVICES(); } int size = Marshal.SizeOf(typeof(IntPtr)); var refpPhysicalDevices = new NativeReference((int)(size * pPhysicalDeviceCount)); var ptrpPhysicalDevices = refpPhysicalDevices.Handle; result = Interop.NativeMethods.vkEnumeratePhysicalDevices(this.m, &pPhysicalDeviceCount, (IntPtr *)ptrpPhysicalDevices); if (result != Result.Success) { throw new ResultException(result); } if (pPhysicalDeviceCount <= 0) { return(null); } var arr = new VulkanPhysicalDevice[pPhysicalDeviceCount]; for (int i = 0; i < pPhysicalDeviceCount; i++) { arr[i] = new VulkanPhysicalDevice(((IntPtr *)ptrpPhysicalDevices)[i]); } return(arr); } }
protected unsafe void CreateBuffer(VulkanPhysicalDevice myDevice, BufferCreateInfo createBufferInfo, AllocationCallbacks pAllocator = null) { if (myDevice == null) { throw new VULKANDEVICE_NO_ACTIVE_DEVICE(); } this.Allocator = pAllocator; this.myActiveDevice = myDevice; SizeOfInternalStructure = createBufferInfo.Size; Result result; fixed(UInt64 *ptrpBuffer = &this.m) { result = Interop.NativeMethods.vkCreateBuffer(myDevice.LogicalDevice.m, createBufferInfo != null ? createBufferInfo.m : (Interop.BufferCreateInfo *) default(IntPtr), pAllocator != null ? pAllocator.m : null, ptrpBuffer); } if (result != Result.Success) { throw new ResultException(result); } }
//TODO: eventually expand this public DeviceQueueManager(VulkanPhysicalDevice selectedPhysicalDevice, VulkanLogicalDevice vulkanLogicalDevice) { var Properties = selectedPhysicalDevice.QueueFamilyProperties; if (Properties == null) { throw new Exception("Unable to find queue family properties!"); } // myDeviceCreateQueues = new Interop.DeviceQueueCreateInfo[Properties.Length]; #if DEBUG Debug.WriteLine("Expected number of Queues to Create: " + Properties.Length); #endif for (int index = 0; index < Properties.Length; index++) { var A = Properties[index]; QueueManagerItem myValue; SharedQueueItem myNewQueueItem = new SharedQueueItem((uint)index, A.QueueCount, vulkanLogicalDevice, A.MinImageTransferGranularity, A.TimestampValidBits); foreach (Interop.QueueFlags G in Enum.GetValues(typeof(Interop.QueueFlags))) { if ((A.QueueFlags & G) == G) { //TODO: one main graphics queue restriction? { } if (!myQueueLookup.TryGetValue(G, out myValue)) { myValue = new QueueManagerItem(); myQueueLookup[G] = myValue; } myValue.AddQueue(myNewQueueItem); } } } }
public int Score(VulkanPhysicalDevice myDevice) { return(100); }
public DescriptorSetLayout(VulkanPhysicalDevice myVulkanDevice) : this(myVulkanDevice.LogicalDevice) { }