コード例 #1
0
        private Device CreateLogicalDevice(out Queue GraphicsQueue, out Queue PresentQueue)
        {
            var   queueInfos    = stackalloc DeviceQueueCreateInfo[2];
            uint  infoCount     = 1;
            float queuePriority = 1f;

            queueInfos[0] = new DeviceQueueCreateInfo(queueFamilyIndex: (uint)this.QueueIndices.GraphicsFamily, queueCount: 1, pQueuePriorities: &queuePriority);

            if (this.QueueIndices.GraphicsFamily != this.QueueIndices.PresentFamily)
            {
                infoCount = 2;

                queueInfos[1] = new DeviceQueueCreateInfo(queueFamilyIndex: (uint)this.QueueIndices.PresentFamily, queueCount: 1, pQueuePriorities: &queuePriority);
            }

            PhysicalDeviceFeatures features = default;

            using var extensionNames = SilkMarshal.StringArrayToMemory(RequiredDeviceExtensions);

            PhysicalDeviceSeparateDepthStencilLayoutsFeatures depthStencilFeature = new PhysicalDeviceSeparateDepthStencilLayoutsFeatures
            {
                SType = StructureType.PhysicalDeviceSeparateDepthStencilLayoutsFeatures,
                SeparateDepthStencilLayouts = true
            };

            DeviceCreateInfo createInfo = new DeviceCreateInfo
            {
                SType = StructureType.DeviceCreateInfo,
                //PNext = &depthStencilFeature,
                QueueCreateInfoCount    = infoCount,
                PQueueCreateInfos       = queueInfos,
                EnabledExtensionCount   = (uint)RequiredDeviceExtensions.Length,
                PpEnabledExtensionNames = (byte **)extensionNames,
                PEnabledFeatures        = &features
            };

            Device device;
            var    res = VkApi.CreateDevice(this.PhysicalDevice, &createInfo, null, &device);

            if (res != Result.Success)
            {
                throw new VMASharp.VulkanResultException("Logical Device Creation Failed!", res);
            }

            Queue queue = default;

            VkApi.GetDeviceQueue(device, (uint)this.QueueIndices.GraphicsFamily, 0, &queue);

            GraphicsQueue = queue;

            if (this.QueueIndices.GraphicsFamily != this.QueueIndices.PresentFamily)
            {
                queue = default;
                VkApi.GetDeviceQueue(device, (uint)this.QueueIndices.PresentFamily, 0, &queue);
            }

            PresentQueue = queue;

            return(device);
        }
コード例 #2
0
        private Instance CreateInstance()
        {
            using var appName    = SilkMarshal.StringToMemory("Hello Cube");
            using var engineName = SilkMarshal.StringToMemory("Custom Engine");

            var appInfo = new ApplicationInfo
                          (
                pApplicationName: (byte *)appName,
                applicationVersion: new Version32(0, 0, 1),
                pEngineName: (byte *)engineName,
                engineVersion: new Version32(0, 0, 1),
                apiVersion: Vk.Version11
                          );

            List <string> extensions = new List <string>(GetWindowExtensions())
            {
                Debugging.DebugExtensionString
            };

            string[] layers = new string[] { "VK_LAYER_KHRONOS_validation" };

            using var extList   = SilkMarshal.StringArrayToMemory(extensions);
            using var layerList = SilkMarshal.StringArrayToMemory(layers);

            var instInfo = new InstanceCreateInfo(pApplicationInfo: &appInfo,
                                                  enabledLayerCount: (uint)layers.Length,
                                                  ppEnabledLayerNames: (byte **)layerList,
                                                  enabledExtensionCount: (uint)extensions.Count,
                                                  ppEnabledExtensionNames: (byte **)extList);

            Instance inst;
            var      res = VkApi.CreateInstance(&instInfo, null, &inst);

            if (res != Result.Success)
            {
                throw new VMASharp.VulkanResultException("Instance Creation Failed", res);
            }

            return(inst);
        }