Пример #1
0
        public void Recreate()
        {
            // TODO: Reuse the same VkCommandPool only for transfer, compute and graphics use an independent one per thread

            switch (Type)
            {
            case CommandBufferType.Generic:
                cmd_command_pool = NativeDevice.create_command_pool(NativeDevice.GraphicsFamily);
                break;

            case CommandBufferType.AsyncGraphics:
                cmd_command_pool = NativeDevice.create_command_pool(NativeDevice.GraphicsFamily);
                break;

            case CommandBufferType.AsyncCompute:
                cmd_command_pool = NativeDevice.create_command_pool(NativeDevice.ComputeFamily);
                break;

            case CommandBufferType.AsyncTransfer:
                cmd_command_pool = NativeDevice.transfer_cmd_pool;
                break;

            case CommandBufferType.Count:
                cmd_command_pool = NativeDevice.create_command_pool(NativeDevice.GraphicsFamily);
                break;
            }

            handle = NativeDevice.create_command_buffer_primary(cmd_command_pool);
        }
Пример #2
0
        public TransferManager(GraphicsDevice graphics)
        {
            Graphics = graphics;
            Buffer   = new((ulong)INITIAL_HOST_SIZE.B);
            Buffer.CanDestroyImmediately = true;             // Safe to do since all operations with this are synchronous

            // Create command objects
            VkCommandPoolCreateInfo      cpci = new(VkCommandPoolCreateFlags.Transient, Graphics.GraphicsQueue.FamilyIndex);
            VulkanHandle <VkCommandPool> poolHandle;

            Graphics.VkDevice.CreateCommandPool(&cpci, null, &poolHandle)
            .Throw("Failed to create command pool for transfer");
            _pool = new(poolHandle, Graphics.VkDevice);
            VkCommandBufferAllocateInfo    cbai = new(_pool, VkCommandBufferLevel.Primary, 1);
            VulkanHandle <VkCommandBuffer> cmdHandle;

            Graphics.VkDevice.AllocateCommandBuffers(&cbai, &cmdHandle)
            .Throw("Failed to allocate command buffer for transfer");
            _cmd = new(cmdHandle, _pool);
            VkFenceCreateInfo      fci = new(VkFenceCreateFlags.NoFlags);
            VulkanHandle <VkFence> fenceHandle;

            Graphics.VkDevice.CreateFence(&fci, null, &fenceHandle)
            .Throw("Failed to create fence for transfer");
            _fence = new(fenceHandle, Graphics.VkDevice);
        }
Пример #3
0
 private VulkanBuffer(VkDevice device, VkCommandPool commandPool, VkBuffer buffer, VkDeviceMemory memory, int count)
 {
     Buffer           = buffer;
     Memory           = memory;
     Count            = count;
     this.device      = device;
     this.commandPool = commandPool;
 }
Пример #4
0
        void CreateCommandPool()
        {
            var info = new VkCommandPoolCreateInfo();

            info.queueFamilyIndex = graphicsIndex;

            commandPool = new VkCommandPool(device, info);
        }
Пример #5
0
        void CreateCommandPool()
        {
            var info = new VkCommandPoolCreateInfo();

            info.queueFamilyIndex = graphicsIndex;
            info.flags            = VkCommandPoolCreateFlags.ResetCommandBufferBit;

            commandPool = new VkCommandPool(device, info);
        }
Пример #6
0
        private void DisposeVulkanCommandPool(VkCommandPool vulkanCommandPool)
        {
            _state.AssertDisposing();

            if (vulkanCommandPool != VK_NULL_HANDLE)
            {
                vkDestroyCommandPool(VulkanGraphicsDevice.VulkanDevice, vulkanCommandPool, pAllocator: null);
            }
        }
Пример #7
0
        public static void vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, int commandBufferCount, VkCommandBuffer[] pCommandBuffers)
        {
            VkPreconditions.CheckNull(device, nameof(device));
            VkPreconditions.CheckNull(commandPool, nameof(commandPool));
            VkPreconditions.CheckNull(pCommandBuffers, nameof(pCommandBuffers));
            VkPreconditions.CheckRange(commandBufferCount, 0, pCommandBuffers.Length, nameof(commandBufferCount));

            GetDevice(device).FreeCommandBuffers(commandPool, commandBufferCount, pCommandBuffers);
        }
Пример #8
0
        private void CreateCommandPool()
        {
            VkCommandPoolCreateInfo cmdPoolInfo = new VkCommandPoolCreateInfo();

            cmdPoolInfo.sType            = CommandPoolCreateInfo;
            cmdPoolInfo.queueFamilyIndex = Swapchain.QueueNodeIndex;
            cmdPoolInfo.flags            = VkCommandPoolCreateFlagBits.ResetCommandBuffer;
            VkCommandPool pool;

            vkCreateCommandPool(device, &cmdPoolInfo, null, &pool);
            this._cmdPool = pool;
        }
Пример #9
0
        public static VkCommandBufferAllocateInfo CommandBufferAllocateInfo(
            VkCommandPool commandPool,
            VkCommandBufferLevel level,
            uint bufferCount)
        {
            VkCommandBufferAllocateInfo commandBufferAllocateInfo = new VkCommandBufferAllocateInfo();

            commandBufferAllocateInfo.sType              = VkStructureType.CommandBufferAllocateInfo;
            commandBufferAllocateInfo.commandPool        = commandPool;
            commandBufferAllocateInfo.level              = level;
            commandBufferAllocateInfo.commandBufferCount = bufferCount;
            return(commandBufferAllocateInfo);
        }
Пример #10
0
        public static void AllocateCommandBuffers(VkCommandPool cmdPool, VkCommandBufferLevel level, uint count, VkCommandBuffer *cmdBuffers)
        {
            VkCommandBufferAllocateInfo cmdBufAllocateInfo = new VkCommandBufferAllocateInfo
            {
                sType = VkStructureType.CommandBufferAllocateInfo
            };

            cmdBufAllocateInfo.commandPool        = cmdPool;
            cmdBufAllocateInfo.level              = level;
            cmdBufAllocateInfo.commandBufferCount = count;

            VulkanUtil.CheckResult(vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, cmdBuffers));
        }
Пример #11
0
        private void CreateCommandPool()
        {
            var indices = new QueueFamilyIndices(vkPhysicalDevice, vkSurface);

            var poolInfo = new VkCommandPoolCreateInfo()
            {
                sType            = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
                queueFamilyIndex = (uint)indices.GraphicsFamily,
                flags            = 0,
            };

            VkCommandPool newCommandPool;
            var           result = VulkanNative.vkCreateCommandPool(vkDevice, &poolInfo, null, &newCommandPool);

            vkCommandPool = newCommandPool;
            Helpers.CheckErrors(result);
        }
Пример #12
0
        public static int CreateCommandPool(VkCommandPoolCreateFlags flags)
        {
            VkCommandPoolCreateInfo createInfo = VkCommandPoolCreateInfo.New();

            createInfo.flags            = flags;
            createInfo.queueFamilyIndex = graphicsQueueFamily;

            VkCommandPool pool = VkCommandPool.Null;

            if (vkCreateCommandPool(device, &createInfo, null, &pool) != VkResult.Success)
            {
                throw new System.Exception("Failed to create commandpool");
            }

            Guid guid = Guid.NewGuid();
            int  id   = guid.GetHashCode();

            pools[id] = pool;
            return(id);
        }
Пример #13
0
        public void Recreate()
        {
            QueueFamilyProperties = new List <VkQueueFamilyProperties>();


            InitializePlatformDevice();


            NativeSwapChain = new GraphicsSwapChain(this);


            NativeCommandPool = CreateCommandPool();


            NativeCommandBufferPrimary = CreateCommandBufferPrimary();


            NativeCommandList = new CommandList(this);


            NativeCommandBufferSecondary = CreateCommandBufferSecondary();
        }
Пример #14
0
        public unsafe CommandPool(QueueFamily queueFamily)
        {
            _queueFamily = queueFamily;
            _device      = queueFamily.Device;
            var createInfo = new VkCommandPoolCreateInfo
            {
                sType            = VkStructureType.CommandPoolCreateInfo,
                flags            = VkCommandPoolCreateFlags.ResetCommandBuffer,
                queueFamilyIndex = queueFamily.Index
            };

            VkCommandPool commandPool;

            if (VulkanNative.vkCreateCommandPool(
                    queueFamily.Device.Handle,
                    &createInfo,
                    null,
                    &commandPool
                    ) != VkResult.Success)
            {
                throw new System.Exception("failed to create command pool on device");
            }
            _handle = commandPool;
        }
Пример #15
0
 public static void vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, VkCommandBuffer commandBuffer)
 {
     vkFreeCommandBuffers(device, commandPool, 1u, &commandBuffer);
 }
Пример #16
0
 public abstract void DestroyCommandPool(VkCommandPool commandPool);
Пример #17
0
 public abstract VkResult CreateCommandPool(VkCommandPoolCreateInfo commandPoolCreateInfo, out VkCommandPool commandPool);
Пример #18
0
 public abstract void FreeCommandBuffers(VkCommandPool commandPool, int commandBufferCount, VkCommandBuffer[] pCommandBuffers);
Пример #19
0
        public static VkResult vkCreateCommandPool(VkDevice device, VkCommandPoolCreateInfo poolCreateInfo, VkAllocationCallbacks pAllocator, out VkCommandPool commandPool)
        {
            VkPreconditions.CheckNull(device, nameof(device));

            return(GetDevice(device).CreateCommandPool(poolCreateInfo, out commandPool));
        }
Пример #20
0
 public static extern void FreeCommandBuffers(
     VkDevice device,
     VkCommandPool commandPool,
     uint commandBufferCount,
     IntPtr pCommandBuffers
     );
Пример #21
0
        public static void vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, VkAllocationCallbacks pAllocator)
        {
            VkPreconditions.CheckNull(device, nameof(device));

            GetDevice(device).DestroyCommandPool(commandPool);
        }
Пример #22
0
 public static extern void DestroyCommandPool(
     VkDevice device,
     VkCommandPool commandPool,
     IntPtr pAllocator
     );
Пример #23
0
 public static extern VkResult ResetCommandPool(
     VkDevice device,
     VkCommandPool commandPool,
     VkCommandPoolResetFlags flags
     );
Пример #24
0
        public Triangle()
        {
            InitializeComponent();
            InitializeVulkan();
            _Bitmap = new Bitmap(640, 480);

            _Framebuffer = new Framebuffer(_Device, 640, 480);

            VkPipelineLayout dummyLayout = _Device.CreatePipelineLayout(VkPipelineLayoutCreateFlag.NONE, null, null);

            _VertexShader   = _Device.CreateShaderModule(VkShaderModuleCreateFlag.NONE, System.IO.File.ReadAllBytes("./Shaders/vertexShader.spv"));
            _FramgemtShader = _Device.CreateShaderModule(VkShaderModuleCreateFlag.NONE, System.IO.File.ReadAllBytes("./Shaders/fragmentShader.spv"));


            _GraphicsPipeline = new Pipeline(_Framebuffer, dummyLayout, _VertexShader, "main", _FramgemtShader, "main");

            // Finally we will need a fence for our submission in order to wait on it
            _Fence = _Device.CreateFence(VkFenceCreateFlag.NONE);

            // VkBuffer indexBuffer = _Device.CreateBuffer(0, 3 * sizeof(Int32), VkBufferUsageFlag.VK_BUFFER_USAGE_INDEX_BUFFER, VkSharingMode.VK_SHARING_MODE_CONCURRENT, new VkQueueFamilyProperties[] { _Queue.Family });
            // VkBuffer vertexBuffer = _Device.CreateBuffer(0, 3 * sizeof(float), VkBufferUsageFlag.VK_BUFFER_USAGE_VERTEX_BUFFER, VkSharingMode.VK_SHARING_MODE_CONCURRENT, new VkQueueFamilyProperties[] { _Queue.Family });


            // Now we need to create a command buffer and we will fill it with a single command:
            //   Fill the image with the color (0.1f, 0.75f, 1.0f, 1.0f) which is a Sky blue.
            VkClearValue.VkClearColorValue.Float color = new VkClearValue.VkClearColorValue.Float();
            color.float32[0] = 0.1f; color.float32[1] = 0.75f; color.float32[2] = 1.0f; color.float32[3] = 1.0f;
            VkCommandPool Pool = _Device.CreateCommandPool(VkCommandPoolCreateFlag.NONE, _Queue.Family);

            _CommandBuffer = Pool.AllocateCommandBuffer(VkCommandBufferLevel.VK_COMMAND_BUFFER_LEVEL_PRIMARY);
            _CommandBuffer.Begin(VkCommandBufferUsageFlag.NONE);
            _CommandBuffer.CmdBeginRenderPass(_Framebuffer.RenderPass,
                                              new VkRect2D(0, 0, (uint)640, (uint)480),
                                              _Framebuffer.GetFramebuffer(),
                                              new VkClearValue[] { color },
                                              VkSubpassContents.VK_SUBPASS_CONTENTS_INLINE);

            _GraphicsPipeline.BindPipeline(_CommandBuffer);
            _CommandBuffer.CmdDraw(3, 1, 0, 0);
            _CommandBuffer.CmdEndRenderPass();
            _CommandBuffer.cmdCopyImageToBuffer(_Framebuffer.FrameBufferColor,
                                                VkImageLayout.VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
                                                _Framebuffer._TransferBuffer,
                                                new VkBufferImageCopy[]
            {
                new VkBufferImageCopy()
                {
                    bufferImageHeight = (uint)_Framebuffer.Height,
                    bufferOffset      = 0,
                    bufferRowLength   = (uint)_Framebuffer.Width,
                    imageExtent       = new VkExtent3D()
                    {
                        depth = 1, width = (uint)_Framebuffer.Width, height = (uint)_Framebuffer.Height
                    },
                    imageSubresource = new VkImageSubresourceLayers()
                    {
                        aspectMask = VkImageAspectFlag.VK_IMAGE_ASPECT_COLOR_BIT, baseArrayLayer = 0, layerCount = 1, mipLevel = 0
                    }
                }
            });
            _CommandBuffer.End();
        }
Пример #25
0
 public static extern VkResult CreateCommandPool(
     VkDevice device,
     ref VkCommandPoolCreateInfo pCreateInfo,
     IntPtr pAllocator,
     out VkCommandPool pCommandPool
     );
Пример #26
0
 public override VkResult CreateCommandPool(VkCommandPoolCreateInfo commandPoolCreateInfo, out VkCommandPool commandPool)
 {
     throw new NotImplementedException();
 }
Пример #27
0
 public override void FreeCommandBuffers(VkCommandPool commandPool, int commandBufferCount, VkCommandBuffer[] pCommandBuffers)
 {
     throw new NotImplementedException();
 }
Пример #28
0
 public override void DestroyCommandPool(VkCommandPool commandPool)
 {
     throw new NotImplementedException();
 }
Пример #29
0
 public CommandBufferPool(uint queue, VkCommandPoolCreateFlags commandPoolCreateFlags)
 {
     QueueIndex = queue;
     cmdPool    = Device.CreateCommandPool(queue, commandPoolCreateFlags);
 }
Пример #30
0
        public static VkResult vkCreateCommandPool(VkDevice device, VkCommandPoolCreateFlags flags, uint queueFamilyIndex, out VkCommandPool commandPool)
        {
            VkCommandPoolCreateInfo createInfo = new VkCommandPoolCreateInfo
            {
                sType            = VkStructureType.CommandPoolCreateInfo,
                flags            = flags,
                queueFamilyIndex = queueFamilyIndex
            };

            return(vkCreateCommandPool(device, &createInfo, null, out commandPool));
        }