Exemplo n.º 1
0
        public void InitVulkan()
        {
            this.createVulkanInstance();

            if (this.validationLayersEnabled)
            {
                this.debugCallbacks.ForEach((DebugCallbackData callbackData) => {
                    callbackData.wrapper = VkHelper.RegisterDebugReportCallback(this.Instance,
                                                                                callbackData.flags, callbackData.callback);
                });
            }

            this.Window.CreateVulkanSurface();

            this.PhysicalDevice = VkHelper.SelectPhysicalDevice(this.Instance, this.physicalDeviceChecks);

            this.createLogicalDevice();

            this.createShaderModules();

            this.GraphicsQueue = this.Device.GetQueue(this.vkQueueFamilies.GraphicsFamily.Value, 0);
            this.TransferQueue = this.GraphicsQueue;
            this.PresentQueue  = this.Device.GetQueue(this.vkQueueFamilies.PresentFamily.Value, 0);

            this.createGraphicsCommandPool();
            this.createTransferCommandPool();

            this.createVertexBuffer();
            this.createIndexBuffer();

            this.createDescriptorSetLayout();
            this.createPipelineWrapper();

            this.createSyncObjects();
        }
Exemplo n.º 2
0
        public static bool CheckPhysicalDeviceQueueFamilySupport(Vk.PhysicalDevice device,
                                                                 Vk.QueueFlags flags, Vk.SurfaceKhr surface, out QueueFamilyIndices queueFamilies)
        {
            Vk.QueueFamilyProperties[] props = device.GetQueueFamilyProperties();
            queueFamilies = new QueueFamilyIndices();

            for (uint i = 0; i < props.Length; i++)
            {
                Vk.QueueFamilyProperties family = props[i];
                if (family.QueueCount > 0)
                {
                    if (family.QueueFlags.HasFlag(flags))
                    {
                        queueFamilies.GraphicsFamily = i;
                    }

                    if (device.GetSurfaceSupportKHR(i, surface))
                    {
                        queueFamilies.PresentFamily = i;
                    }

                    if (queueFamilies.AllFamiliesExist())
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        public Vk.Device Create(Vk.PhysicalDevice physicalDevice)
        {
            Vk.DeviceCreateInfo deviceInfo = new Vk.DeviceCreateInfo();

            deviceInfo.QueueCreateInfos     = this.queueInfos.ToArray();
            deviceInfo.QueueCreateInfoCount = (uint)this.queueInfos.Count;

            deviceInfo.EnabledFeatures = this.deviceFeatures;

            if (this.extensions.Count != 0)
            {
                deviceInfo.EnabledExtensionNames = this.extensions.ToArray();
            }

            deviceInfo.EnabledExtensionCount = (uint)this.extensions.Count;

            if (this.validationLayers.Count != 0)
            {
                deviceInfo.EnabledLayerNames = this.validationLayers.ToArray();
            }

            deviceInfo.EnabledLayerCount = (uint)this.validationLayers.Count;

            return(physicalDevice.CreateDevice(deviceInfo));
        }
Exemplo n.º 4
0
        public static SwapchainSupportDetails QuerySwapchainSupport(Vk.PhysicalDevice device, Vk.SurfaceKhr surface)
        {
            SwapchainSupportDetails support = new SwapchainSupportDetails();

            support.capabilities = device.GetSurfaceCapabilitiesKHR(surface);
            support.formats      = device.GetSurfaceFormatsKHR(surface);
            support.presentModes = device.GetSurfacePresentModesKHR(surface);

            return(support);
        }
Exemplo n.º 5
0
        public static bool CheckDeviceExtensionSupport(Vk.PhysicalDevice device, IEnumerable <string> extensions)
        {
            Vk.ExtensionProperties[] props = device.EnumerateDeviceExtensionProperties();

            return(extensions.All <string>((string requiredExtension) =>
                                           props.Any <Vk.ExtensionProperties>((Vk.ExtensionProperties extension) =>
                                                                              extension.ExtensionName.Equals(requiredExtension)
                                                                              )
                                           ));
        }
Exemplo n.º 6
0
        public static uint FindMemoryType(uint typeFilter, Vk.PhysicalDevice physicalDevice,
                                          Vk.MemoryPropertyFlags properties)
        {
            var memProps = physicalDevice.GetMemoryProperties();

            for (int i = 0; i < memProps.MemoryTypeCount; i++)
            {
                bool bitFieldSet   = (typeFilter & (1 << i)) != 0;
                bool hasProperties = (memProps.MemoryTypes[i].PropertyFlags & properties) == properties;
                if (bitFieldSet && hasProperties)
                {
                    return((uint)i);
                }
            }

            throw new System.Exception("Failed to find suitable memory type!");
        }
Exemplo n.º 7
0
 public SwapchainSupportDetails QuerySwapchainSupport(Vk.PhysicalDevice device) =>
 VkHelper.QuerySwapchainSupport(device, this.Window.VulkanSurface);
Exemplo n.º 8
0
 public bool EnsureQueueFamilySupport(Vk.PhysicalDevice device, Vk.QueueFlags family) =>
 VkHelper.CheckPhysicalDeviceQueueFamilySupport(device,
                                                family, this.Window.VulkanSurface, out this.vkQueueFamilies);