示例#1
0
        private void createLogicalDevice()
        {
            LogicalDeviceBuilder builder = new LogicalDeviceBuilder();

            HashSet <uint> queueTypes = new HashSet <uint>(new uint[] {
                this.vkQueueFamilies.GraphicsFamily.Value,
                this.vkQueueFamilies.PresentFamily.Value
            });

            foreach (uint queueType in queueTypes)
            {
                Vk.DeviceQueueCreateInfo queueInfo = new Vk.DeviceQueueCreateInfo();
                queueInfo.QueueFamilyIndex = queueType;
                queueInfo.QueueCount       = 1;
                queueInfo.QueuePriorities  = new float[] { 1.0F };

                builder.EnableQueue(queueInfo);
            }

            builder.EnableExtensions(this.DeviceExtensions);

            if (this.validationLayersEnabled)
            {
                builder.EnableValidationLayers(this.ValidationLayers);
            }

            try {
                this.Device = builder.Create(this.PhysicalDevice);
            } catch (Vk.ResultException result) {
                throw new VkException("An error occurred while creating the logical device.", result);
            }
        }
示例#2
0
        public static Vk.ShaderModule CreateShaderModule(Vk.Device device, byte[] bytecode)
        {
            Vk.ShaderModuleCreateInfo moduleInfo = new Vk.ShaderModuleCreateInfo();
            moduleInfo.CodeBytes = bytecode;
            moduleInfo.CodeSize  = new UIntPtr((uint)bytecode.Length);

            return(device.CreateShaderModule(moduleInfo));
        }
        private static DeviceBase CreateDevice(AbstractionDesc desc, InstanceBase instance)
        {
            DeviceBase device = null;

            AdapterInfo[] adapters           = null;
            bool          createSingleDevice = false;
            var           initType           = desc.type;

            if (initType == AbstractionInitType.SingleGPU_Standard)
            {
                initType           = AbstractionInitType.SingleGPU_Standard;
                createSingleDevice = true;                // single gpu mode only
            }
            else if (initType == AbstractionInitType.MultiGPU_BestAvaliable_AFR)
            {
                if (!instance.QuerySupportedAdapters(false, out adapters))
                {
                    throw new Exception("Failed to get supported adapters");
                }
                if (adapters.Length >= 1)
                {
                    // test for linked-gpus
                    foreach (var adapter in adapters)
                    {
                        if (adapter.isPrimary && adapter.nodeCount > 1)
                        {
                            initType = AbstractionInitType.MultiGPU_LinkedNode_AFR;
                            break;
                        }
                    }

                    // test for mixed-gpu support
                    if (initType == AbstractionInitType.MultiGPU_BestAvaliable_AFR)
                    {
                        if (adapters.Length >= 2)
                        {
                            foreach (var adapter in adapters)
                            {
                                if (adapter.isPrimary)
                                {
                                    initType = AbstractionInitType.MultiGPU_MixedDevice_AFR;
                                    break;
                                }
                            }
                        }
                    }
                }

                // set to single gpu if no mGPU support found
                if (initType == AbstractionInitType.MultiGPU_BestAvaliable_AFR)
                {
                    initType           = AbstractionInitType.SingleGPU_Standard;
                    createSingleDevice = true;
                }
            }

            if (initType == AbstractionInitType.MultiGPU_LinkedNode_AFR)
            {
                if (adapters == null && !instance.QuerySupportedAdapters(false, out adapters))
                {
                    throw new Exception("Failed to get supported adapters");
                }
                bool linkedNodesFound = false;
                foreach (var adapter in adapters)
                {
                    if (adapter.isPrimary && adapter.nodeCount > 1)
                    {
                        linkedNodesFound = true;
                        break;
                    }
                }

                if (!linkedNodesFound)
                {
                    initType = AbstractionInitType.SingleGPU_Standard; // default to single gpu mode if only adapter-node found
                }
                createSingleDevice = true;                             // always create a single device
            }
            else if (initType == AbstractionInitType.MultiGPU_MixedDevice_AFR)
            {
                if (adapters == null && !instance.QuerySupportedAdapters(false, out adapters))
                {
                    throw new Exception("Failed to get supported adapters");
                }
                if (adapters.Length > 1)
                {
                    // gather all supported adapters
                    List <AdapterInfo> supportedAdapters;
                    if (desc.vendorIgnores_MixedDevices != null)
                    {
                        supportedAdapters = new List <AdapterInfo>();
                        foreach (var adapter in adapters)
                        {
                            if (!IsVendorIgnored(adapter.vendor, desc.vendorIgnores_MixedDevices))
                            {
                                supportedAdapters.Add(adapter);
                            }
                        }
                    }
                    else
                    {
                        supportedAdapters = new List <AdapterInfo>(adapters);
                    }

                    if (supportedAdapters.Count > 1)
                    {
                        device = new mGPU.Device(instance, desc.deviceType, supportedAdapters.ToArray());
                    }
                    else
                    {
                        initType           = AbstractionInitType.SingleGPU_Standard;              // default to single gpu mode if only adapter found
                        createSingleDevice = true;
                    }
                }
                else
                {
                    initType           = AbstractionInitType.SingleGPU_Standard;          // default to single gpu mode if only adapter found
                    createSingleDevice = true;
                }
            }

            // force mixed-device AFR requirements
            if (initType == AbstractionInitType.MultiGPU_MixedDevice_AFR)
            {
                desc.deviceDescD3D12.swapChainType  = SwapChainType.SingleGPU_Standard;
                desc.deviceDescVulkan.swapChainType = SwapChainType.SingleGPU_Standard;
            }

            // create single device if needed
            if (createSingleDevice)
            {
                if (instance is D3D12.Instance)
                {
                    device = new D3D12.Device((D3D12.Instance)instance, desc.deviceType);
                }
                else if (instance is Vulkan.Instance)
                {
                    device = new Vulkan.Device((Vulkan.Instance)instance, desc.deviceType);
                }
            }

            return(device);
        }
示例#4
0
 /// <summary>
 ///     Wrapper around <see cref="Vk.Device.BindImageMemory"/>
 /// </summary>
 /// <param name="device">
 ///     The Vulkan logical device which created the image and allocated
 ///     its memory.
 /// </param>
 /// <param name="offset">
 ///     The offset in the allocated memory block at which the image's data
 ///     should be written.
 /// </param>
 public void Bind(Vk.Device device, Vk.DeviceSize offset)
 {
     device.BindImageMemory(this.Image, this.Memory, offset);
 }
示例#5
0
 /// <summary>
 ///     Wrapper around <see cref="Vk.Device.DestroyBuffer"/> and
 ///     <see cref="Vk.Device.FreeMemory"/>
 /// </summary>
 /// <param name="device">
 ///     The Vulkan logical device which created the buffer and allocated
 ///     its memory.
 /// </param>
 public void Destroy(Vk.Device device)
 {
     device.DestroyBuffer(this.Buffer);
     device.FreeMemory(this.Memory);
 }
示例#6
0
 /// <summary>
 ///     Wrapper around <see cref="Vk.Device.BindBufferMemory"/>
 /// </summary>
 /// <param name="device">
 ///     The Vulkan logical device which created the buffer and allocated
 ///     its memory.
 /// </param>
 /// <param name="offset">
 ///     The offset in the allocated memory block at which the buffer's data
 ///     should be written.
 /// </param>
 public void Bind(Vk.Device device, Vk.DeviceSize offset)
 {
     device.BindBufferMemory(this.Buffer, this.Memory, offset);
 }