Esempio n. 1
0
        public void Build(int device_index, CommandQueueKind queue)
        {
            if (!locked)
            {
                unsafe
                {
                    var devInfo = GraphicsDevice.GetDeviceInfo(device_index);
                    queueFamily = queue switch
                    {
                        CommandQueueKind.Graphics => devInfo.GraphicsFamily,
                        CommandQueueKind.Compute => devInfo.ComputeFamily,
                        CommandQueueKind.Transfer => devInfo.TransferFamily,
                        CommandQueueKind.Present => devInfo.PresentFamily,
                        _ => throw new Exception("Unknown command queue type.")
                    };
                    queueFam = queue switch
                    {
                        CommandQueueKind.Graphics => devInfo.GraphicsQueue,
                        CommandQueueKind.Compute => devInfo.ComputeQueue,
                        CommandQueueKind.Transfer => devInfo.TransferQueue,
                        CommandQueueKind.Present => devInfo.PresentQueue,
                        _ => throw new Exception("Unknown command queue type.")
                    };

                    var poolInfo = new VkCommandPoolCreateInfo()
                    {
                        sType            = VkStructureType.StructureTypeCommandPoolCreateInfo,
                        queueFamilyIndex = queueFamily,
                        flags            = Transient ? VkCommandPoolCreateFlags.CommandPoolCreateTransientBit : VkCommandPoolCreateFlags.CommandPoolCreateResetCommandBufferBit,
                    };

                    IntPtr commandPoolPtr_l = IntPtr.Zero;
                    if (vkCreateCommandPool(devInfo.Device, poolInfo.Pointer(), null, &commandPoolPtr_l) != VkResult.Success)
                    {
                        throw new Exception("Failed to create command pool.");
                    }
                    hndl  = commandPoolPtr_l;
                    devID = device_index;

                    if (GraphicsDevice.EnableValidation && Name != null)
                    {
                        var objName = new VkDebugUtilsObjectNameInfoEXT()
                        {
                            sType        = VkStructureType.StructureTypeDebugUtilsObjectNameInfoExt,
                            pObjectName  = Name,
                            objectType   = VkObjectType.ObjectTypeCommandPool,
                            objectHandle = (ulong)hndl
                        };
                        GraphicsDevice.SetDebugUtilsObjectNameEXT(GraphicsDevice.GetDeviceInfo(devID).Device, objName.Pointer());
                    }
                }
                locked = true;
            }
            else
            {
                throw new Exception("CommandPool is locked.");
            }
        }
        internal static uint GetFamilyIndex(int devID, CommandQueueKind queue)
        {
            var devInfo = GetDeviceInfo(devID);

            return(queue switch
            {
                CommandQueueKind.Graphics => devInfo.GraphicsFamily,
                CommandQueueKind.Compute => devInfo.ComputeFamily,
                CommandQueueKind.Transfer => devInfo.TransferFamily,
                CommandQueueKind.Present => devInfo.PresentFamily,
                CommandQueueKind.Ignored => Vk.VkQueueFamilyIgnored,
                _ => throw new Exception("Unknown command queue type.")
            });
Esempio n. 3
0
        internal GpuQueue(CommandQueueKind queue_kind, IntPtr hndl, uint family, int device_index)
        {
            QueueKind   = queue_kind;
            Handle      = hndl;
            Family      = family;
            DeviceIndex = device_index;

            if (GraphicsDevice.EnableValidation)
            {
                var objName = new VkDebugUtilsObjectNameInfoEXT()
                {
                    sType        = VkStructureType.StructureTypeDebugUtilsObjectNameInfoExt,
                    pObjectName  = $"{QueueKind.ToString()}_{family}",
                    objectType   = VkObjectType.ObjectTypeQueue,
                    objectHandle = (ulong)hndl
                };

                var p = objName.Pointer();
                GraphicsDevice.SetDebugUtilsObjectNameEXT(GraphicsDevice.GetDeviceInfo(device_index).Device, p);
            }
        }