示例#1
0
        private void CreateInstance()
        {
            var enabledLayers = new List <string>();

            //VK_LAYER_LUNARG_api_dump
            //VK_LAYER_LUNARG_standard_validation

            void AddAvailableLayer(string layerName)
            {
                if (Instance.EnumerateLayerProperties().Any(x => x.LayerName == layerName))
                {
                    enabledLayers.Add(layerName);
                }
            }

            AddAvailableLayer("VK_LAYER_LUNARG_standard_validation");

            this.instance = Instance.Create(
                enabledLayers.ToArray(),
                Glfw3.GetRequiredInstanceExtensions().Append(ExtExtensions.DebugReport).ToArray(),
                applicationInfo: new ApplicationInfo
            {
                ApplicationName    = "Hello Triangle",
                ApplicationVersion = new Version(1, 0, 0),
                EngineName         = "SharpVk",
                EngineVersion      = new Version(0, 4, 1),
                ApiVersion         = new Version(1, 0, 0)
            });

            instance.CreateDebugReportCallback(DebugReportDelegate, DebugReportFlags.Error | DebugReportFlags.Warning);
        }
示例#2
0
        private void CreateInstance()
        {
            var enabledLayers = new List <string>();

            if (Instance.EnumerateLayerProperties().Any(x => x.LayerName == "VK_LAYER_LUNARG_standard_validation"))
            {
                enabledLayers.Add("VK_LAYER_LUNARG_standard_validation");
            }

            var glfwExtensions = Glfw3.GetRequiredInstanceExtensions();

            this.instance = Instance.Create(
                enabledLayers.ToArray(),
                glfwExtensions.Append(ExtExtensions.DebugReport).ToArray(),
                applicationInfo: new ApplicationInfo
            {
                ApplicationName    = "Vertex Buffers",
                ApplicationVersion = new Version(1, 0, 0),
                EngineName         = "SharpVk",
                EngineVersion      = new Version(0, 4, 0),
                ApiVersion         = new Version(1, 0, 0)
            });

            instance.CreateDebugReportCallback(DebugReportDelegate, DebugReportFlags.Error | DebugReportFlags.Warning | DebugReportFlags.Information | DebugReportFlags.Debug);
        }
示例#3
0
        /// <summary>
        /// Create the minimum vulkan objects to quickly start a new application. The folowing objects are created:
        /// - Vulkan Instance with extensions present in the `EnabledInstanceExtensions` property.
        /// - Vulkan Surface for the GLFW native window.
        /// - Vulkan device for the selected physical one with configured enabledFeatures and extensions present in `EnabledDeviceExtensions` list. Selection of the default physical device
        ///   may be replaced by the `selectPhysicalDevice` method override.
        /// - Create a default Graphic Queue with presentable support. The default queue creation may be customized by overriding the `createQueues` method.
        /// - Default vulkan Swapchain creation. Some swapchain's parameters are controled through static fields of the `SwapChain` class (ex: `SwapChain.PREFERED_FORMAT`).
        /// - Create a default command pool for the `presentQueue` family index.
        /// - Create an empty command buffer collection (`cmds`).
        /// - Create one unsignaled vulkan semaphore (named `drawComplete` per swapchain image used to control presentation submission to the graphic queue.
        /// - Create a signaled vulkan fence (`drawFence`). (TODO: improve this.
        /// With all these objects, vulkan application programming startup is reduced to the minimal.
        /// </summary>
        protected virtual void initVulkan()
        {
            List <string> instExts = new List <string> (Glfw3.GetRequiredInstanceExtensions());

            if (EnabledInstanceExtensions != null)
            {
                instExts.AddRange(EnabledInstanceExtensions);
            }

            instance = new Instance(instExts.ToArray());

            hSurf = instance.CreateSurface(hWin);

            selectPhysicalDevice();

            VkPhysicalDeviceFeatures enabledFeatures = default;

            configureEnabledFeatures(phy.Features, ref enabledFeatures);

            //First create the c# device class
            dev = new Device(phy);
            dev.debugUtilsEnabled = instance.debugUtilsEnabled;            //store a boolean to prevent testing against the extension string presence.

            //create queue class
            createQueues();

            //activate the device to have effective queues created accordingly to what's available
            dev.Activate(enabledFeatures, EnabledDeviceExtensions);

            swapChain = new SwapChain(presentQueue as PresentQueue, Width, Height, SwapChain.PREFERED_FORMAT,
                                      VSync ? VkPresentModeKHR.FifoKHR : VkPresentModeKHR.ImmediateKHR);
            swapChain.Activate();

            Width  = swapChain.Width;
            Height = swapChain.Height;

            cmdPool = new CommandPool(dev, presentQueue.qFamIndex, VkCommandPoolCreateFlags.ResetCommandBuffer);

            cmds         = new PrimaryCommandBuffer[swapChain.ImageCount];
            drawComplete = new VkSemaphore[swapChain.ImageCount];
            drawFence    = new Fence(dev, true, "draw fence");

            for (int i = 0; i < swapChain.ImageCount; i++)
            {
                drawComplete[i] = dev.CreateSemaphore();
                drawComplete[i].SetDebugMarkerName(dev, "Semaphore DrawComplete" + i);
            }

            cmdPool.SetName("main CmdPool");
        }
示例#4
0
        private void CreateInstance()
        {
            var enabledLayers = new List <string>();

            if (Instance.EnumerateLayerProperties().Any(x => x.LayerName == "VK_LAYER_LUNARG_standard_validation"))
            {
                enabledLayers.Add("VK_LAYER_LUNARG_standard_validation");
            }

            var glfwExtensions = Glfw3.GetRequiredInstanceExtensions();

            this.instance = Instance.Create(enabledLayers.ToArray(), glfwExtensions.Concat(new[] { ExtExtensions.DebugReport }).ToArray(), InstanceCreateFlags.None,
                                            new ApplicationInfo
            {
                ApplicationName    = "Tectonic",
                ApplicationVersion = new SharpVk.Version(1, 0, 0),
                EngineName         = "Tectonic",
                ApiVersion         = new SharpVk.Version(1, 0, 0)
            });

            this.reportCallback = this.instance.CreateDebugReportCallback(this.debugReportDelegate, DebugReportFlags.Error | DebugReportFlags.Warning);
        }
示例#5
0
        public void CreateInstance()
        {
            var enabledLayers = new List <string>();

            //VK_LAYER_LUNARG_api_dump
            //VK_LAYER_LUNARG_standard_validation
            var prop = Instance.EnumerateLayerProperties();

            void AddAvailableLayer(string layerName, LayerProperties[] prop)
            {
                if (prop.Any(x => x.LayerName == layerName))
                {
                    enabledLayers.Add(layerName);
                }
            }

#if DEBUG
            AddAvailableLayer("VK_LAYER_LUNARG_standard_validation", prop);
#if APIDUMP
            AddAvailableLayer("VK_LAYER_LUNARG_api_dump", prop);
#endif
#endif

            this.instance = Instance.Create(
                enabledLayers.ToArray(),
                Glfw3.GetRequiredInstanceExtensions().Append(ExtExtensions.DebugReport).ToArray(),
                applicationInfo: new ApplicationInfo {
                ApplicationName    = "Hello Triangle",
                ApplicationVersion = new SharpVk.Version(1, 0, 0),
                EngineName         = "SharpVk",
                EngineVersion      = new SharpVk.Version(0, 4, 1),
                ApiVersion         = new SharpVk.Version(1, 0, 0)
            });

            instance.CreateDebugReportCallback(helper.DebugReport, DebugReportFlags.Error | DebugReportFlags.Warning);
        }
示例#6
0
        private unsafe void Run()
        {
            var extensions = Instance.EnumerateExtensionProperties(null);

            var instance = Instance.Create(null, Glfw3.GetRequiredInstanceExtensions());

            var device = instance.EnumeratePhysicalDevices().First().CreateDevice(new DeviceQueueCreateInfo {
                QueueFamilyIndex = 0, QueuePriorities = new[] { 0f }
            }, null, null);

            device.GetQueue(0, 0);

            try
            {
                Glfw3.Init();

                using (var window = new Window(1920, 1080, "Test"))
                {
                    SetCallbacks(window);

                    while (!window.ShouldClose)
                    {
                        Glfw3.PollEvents();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
            finally
            {
                Glfw3.Terminate();
            }
        }